You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package CMTD::Helpers;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use utf8;
|
|
|
|
|
|
|
|
use Mojo::Base 'Mojolicious::Plugin';
|
|
|
|
|
|
|
|
sub register {
|
|
|
|
my ($self, $app) = @_;
|
|
|
|
|
|
|
|
$app->helper(referrer => sub {
|
|
|
|
my ($c) = @_;
|
|
|
|
my $url = $c->req->headers->referrer ||
|
|
|
|
$c->req->param('url');
|
|
|
|
return $url;
|
|
|
|
});
|
|
|
|
|
|
|
|
$app->helper(pageid => sub {
|
|
|
|
my ($c, $url) = @_;
|
|
|
|
return unless $url;
|
|
|
|
|
|
|
|
my $u = Mojo::URL->new($url);
|
|
|
|
my $site = $u->host;
|
|
|
|
my $path = $u->path;
|
|
|
|
$path =~ s{^/+}{}o;
|
|
|
|
$path =~ s{/+$}{}o;
|
|
|
|
$path =~ y{/.}{-}s;
|
|
|
|
$path =~ s<\.[a-z0-9]{2,4}$><>io;
|
|
|
|
my $md5 = md5_sum($path);
|
|
|
|
|
|
|
|
return {site => $site, pid => $md5, path => $path};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|