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 LDV::Helpers;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use utf8;
|
|
|
|
|
|
|
|
use Mojo::Base 'Mojolicious::Plugin';
|
|
|
|
|
|
|
|
use POSIX qw(strftime);
|
|
|
|
use Text::Markdown;
|
|
|
|
|
|
|
|
sub register {
|
|
|
|
my ($self, $app) = @_;
|
|
|
|
|
|
|
|
$app->helper(markdown => sub {
|
|
|
|
my ($c, $text) = @_;
|
|
|
|
my $render = Text::Markdown->new;
|
|
|
|
return $render->markdown($text);
|
|
|
|
});
|
|
|
|
|
|
|
|
$app->helper(plaintext => sub {
|
|
|
|
my ($c, $text) = @_;
|
|
|
|
$text =~ s{\r?\n}{<br/>}go;
|
|
|
|
return $text;
|
|
|
|
});
|
|
|
|
|
|
|
|
$app->helper(from_unixtime => sub {
|
|
|
|
my ($c, $unixtime) = @_;
|
|
|
|
return strftime("%Y-%m-%d %H:%M", localtime($unixtime));
|
|
|
|
});
|
|
|
|
|
|
|
|
$app->helper(access_allowed => sub {
|
|
|
|
my ($c, $level) = @_;
|
|
|
|
$level //= '';
|
|
|
|
if ($level eq 'user' and not $c->session('useruid')) {
|
|
|
|
$c->redirect_to('/user/eaccess');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|