⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 context.pm

📁 1. 记录每个帖子的访问人情况
💻 PM
📖 第 1 页 / 共 5 页
字号:
                                                   blog_id => $blog_id })                        # FIXME this won't die to the right place                        or return $ctx->error(MT->translate(                                             "No such category '[_1]'", $_ ));                } @cats;            }            my %entries;             for my $cat (@cat_objs) {                my @place = MT::Placement->load({ category_id => $cat->id });                for my $place (@place) {                    $entries{$place->entry_id}++;                }            }            my $count = @cat_objs;            my @ids = $is_and ? grep { $entries{$_} == $count } keys %entries :                keys %entries;            $saved_entry_stash = $ctx->stash('entries') || [];            if (@$saved_entry_stash) {                my %temp = map { $_ => 1 } @ids;                @entries = grep { $temp{$_->id} } @$saved_entry_stash;            } else {                for my $entry_id (@ids) {                    my $entry = MT::Entry->load($entry_id);                    push @entries, $entry                        if $entry->status == MT::Entry::RELEASE();                }            }            $ctx->{__stash}{entries} = \@entries;            delete $args->{category};        }    }    if (my $author_name = $args->{author}) {        require MT::Author;        $author = MT::Author->load({ name => $author_name }) or            return $ctx->error(MT->translate(                                             "No such author '[_1]'", $author_name ));    }    my $no_resort = 0;    my $entries;    my ($start, $end) = ($ctx->{current_timestamp},			 $ctx->{current_timestamp_end});    $entries = force($ctx->stash('entries'));    if (!($entries && @$entries) && $start && $end) { 	@entries = MT::Entry->load({blog_id => $blog_id,				    created_on => [$start, $end]},				   {range => {created_on => 1}});	$entries = \@entries;    }    if ($entries) {        @entries = @$entries;        if (%$args) {            my $n = $args->{lastn};            ## If lastn is defined, we need to make sure that the list of            ## entries is in descending order.            if ($n) {                @entries = sort { $b->created_on cmp $a->created_on }                           @entries;            }            my $off = $args->{offset} || 0;            my($i, $j) = (0, 0);            my @tmp;            for my $e (@entries) {                next if $off && $j++ < $off;                last if $n && $i >= $n;                next unless !$cat || $e->is_in_category($cat);                next unless !$author || $e->author_id == $author->id;                push @tmp, $e;                $i++;            }            @entries = @tmp;        }    } elsif (%$args) {        my %terms = ( blog_id => $blog_id, status => MT::Entry::RELEASE() );        $terms{author_id} = $author->id if $author;        my %args;        if ($cat) {            require MT::Placement;            $args{'join'} = [ 'MT::Placement', 'entry_id',                              { category_id => $cat->id }, { unique => 1 } ];        }        if (my $last = $args->{lastn}) {            $args{'sort'} = 'created_on';            $args{direction} = 'descend';            $args{limit} = $last;            $args{offset} = $args->{offset} if $args->{offset};        } elsif (my $days = $args->{days}) {            my @ago = offset_time_list(time - 3600 * 24 * $days,                $ctx->stash('blog_id'));            my $ago = sprintf "%04d%02d%02d%02d%02d%02d",                $ago[5]+1900, $ago[4]+1, @ago[3,2,1,0];            $terms{created_on} = [ $ago ];            %args = ( range => { created_on => 1 } );        } elsif (my $n = $args->{recently_commented_on}) {            $args{'join'} = [ 'MT::Comment', 'entry_id',                { blog_id => $blog_id, visible => 1 },                { 'sort' => 'created_on',                  direction => 'descend',                  unique => 1,                  limit => $n } ];            $no_resort = 1;        }        @entries = MT::Entry->load(\%terms, \%args);    } else {        my $days = $ctx->stash('blog')->days_on_index;        my @ago = offset_time_list(time - 3600 * 24 * $days,            $ctx->stash('blog_id'));        my $ago = sprintf "%04d%02d%02d%02d%02d%02d",            $ago[5]+1900, $ago[4]+1, @ago[3,2,1,0];        @entries = MT::Entry->load({ blog_id => $blog_id,                                     created_on => [ $ago ],                                     status => MT::Entry::RELEASE() },            { range => { created_on => 1 } });    }    my $res = '';    my $tok = $ctx->stash('tokens');    my $builder = $ctx->stash('builder');    unless ($no_resort) {        my $so = $args->{sort_order} || $ctx->stash('blog')->sort_order_posts || '';        my $col = $args->{sort_by} || 'created_on';        @entries = $so eq 'ascend' ?            sort { $a->$col() cmp $b->$col() } @entries :            sort { $b->$col() cmp $a->$col() } @entries;    }    my($last_day, $next_day) = ('00000000') x 2;    my $i = 0;    for my $e (@entries) {        local $ctx->{__stash}{entry} = $e;        local $ctx->{current_timestamp} = $e->created_on;        local $ctx->{modification_timestamp} = $e->modified_on;        my $this_day = substr $e->created_on, 0, 8;        my $next_day = $this_day;        my $footer = 0;        if (defined $entries[$i+1]) {            $next_day = substr($entries[$i+1]->created_on, 0, 8);            $footer = $this_day ne $next_day;        } else { $footer++ }	my $allow_comments ||= 0;        my $out = $builder->build($ctx, $tok, {            %$cond,            DateHeader => ($this_day ne $last_day),            DateFooter => $footer,            EntryIfExtended => $e->text_more ? 1 : 0,            EntryIfAllowComments => $e->allow_comments,            EntryIfCommentsOpen => $e->allow_comments &&                $e->allow_comments eq '1',            EntryIfAllowPings => $e->allow_pings,            EntriesHeader => !$i,            EntriesFooter => !defined $entries[$i+1],        });        $last_day = $this_day;        return $ctx->error( $builder->errstr ) unless defined $out;        $res .= $out;        $i++;    }    ## Restore a saved entry stash. This is basically emulating "local",    ## which we can't use, because the local would be buried too far down    ## in a conditional.    if ($saved_entry_stash) {        if (!@$saved_entry_stash) {            delete $ctx->{__stash}{entries};        } else {            $ctx->{__stash}{entries} = $saved_entry_stash;        }    }    $res;}sub _no_entry_error {    return $_[0]->error(MT->translate(        "You used an '[_1]' tag outside of the context of an entry; " .        "perhaps you mistakenly placed it outside of an 'MTEntries' container?",        $_[1]));}sub _hdlr_entry_body {    my $arg = $_[1];    my $e = $_[0]->stash('entry')        or return $_[0]->_no_entry_error('MTEntryBody');    my $text = $e->text;    $text = '' unless defined $text;    my $convert_breaks = exists $arg->{convert_breaks} ?        $arg->{convert_breaks} :            defined $e->convert_breaks ? $e->convert_breaks :                $_[0]->stash('blog')->convert_paras;    if ($convert_breaks) {        my $filters = $e->text_filters;        push @$filters, '__default__' unless @$filters;        $text = MT->apply_text_filters($text, $filters, $_[0]);    }    return first_n_words($text, $arg->{words}) if exists $arg->{words};    $text;}sub _hdlr_entry_more {    my $arg = $_[1];    my $e = $_[0]->stash('entry')        or return $_[0]->_no_entry_error('MTEntryMore');    my $text = $e->text_more;    $text = '' unless defined $text;    my $convert_breaks = exists $arg->{convert_breaks} ?        $arg->{convert_breaks} :            defined $e->convert_breaks ? $e->convert_breaks :                $_[0]->stash('blog')->convert_paras;    if ($convert_breaks) {        my $filters = $e->text_filters;        push @$filters, '__default__' unless @$filters;        $text = MT->apply_text_filters($text, $filters, $_[0]);    }    $text;}sub _hdlr_entry_title {    my $e = $_[0]->stash('entry')        or return $_[0]->_no_entry_error('MTEntryTitle');    my $title = defined $e->title ? $e->title : '';    $title = first_n_words($e->text, 5)        if !$title && $_[1]->{generate};    $title;}sub _hdlr_entry_status {    my $e = $_[0]->stash('entry')        or return $_[0]->_no_entry_error('MTEntryStatus');    MT::Entry::status_text($e->status);}sub _hdlr_entry_date {    my $e = $_[0]->stash('entry')        or return $_[0]->_no_entry_error('MTEntryDate');    my $args = $_[1];    $args->{ts} = $e->created_on;    _hdlr_date($_[0], $args);}sub _hdlr_entry_mod_date {    my $e = $_[0]->stash('entry')        or return $_[0]->_no_entry_error('MTEntryModifiedDate');    my $args = $_[1];    $args->{ts} = $e->modified_on;    _hdlr_date($_[0], $args);}sub _hdlr_entry_flag {    my $e = $_[0]->stash('entry')        or return $_[0]->_no_entry_error('MTEntryFlag');    my $flag = $_[1]->{flag}        or return $_[0]->error(MT->translate(            'You used <$MTEntryFlag$> without a flag.' ));    my $v = $e->$flag();    ## The logic here: when we added the convert_breaks flag, we wanted it    ## to default to checked, because we added it in 2.0, and people had    ## previously been using the global convert_paras setting, so we needed    ## that to be used if it wasn't defined. So that's the reason for the    ## second test (else) (should we be looking at blog->convert_paras?).    ## When we added allow_pings, we only want this to be applied if    ## explicitly checked.    if ($flag eq 'allow_pings') {        return defined $v ? $v : 0;    } else {        return defined $v ? $v : 1;    }}sub _hdlr_entry_excerpt {    my($ctx, $args) = @_;    my $e = $ctx->stash('entry')        or return $ctx->_no_entry_error('MTEntryExcerpt');    if (my $excerpt = $e->excerpt) {        return $excerpt unless $args->{convert_breaks};        my $filters = $e->text_filters;        push @$filters, '__default__' unless @$filters;        return MT->apply_text_filters($excerpt, $filters, $ctx);    } elsif ($args->{no_generate}) {        return '';    }    my $words = $ctx->stash('blog')->words_in_excerpt;    $words = 40 unless defined $words && $words ne '';    my $excerpt = _hdlr_entry_body($ctx, { words => $words, %$args });    return '' unless $excerpt;    $excerpt . '...';}sub _hdlr_entry_keywords {    my $e = $_[0]->stash('entry')        or return $_[0]->_no_entry_error('MTEntryKeywords');    defined $e->keywords ? $e->keywords : '';}sub _hdlr_entry_author {    my $e = $_[0]->stash('entry')        or return $_[0]->_no_entry_error('MTEntryAuthor');    my $a = $e->author;    $a ? $a->name || '' : '';}sub _hdlr_entry_author_nick {    my $e = $_[0]->stash('entry')        or return $_[0]->_no_entry_error('MTEntryAuthorNickname');    my $a = $e->author;    $a ? $a->nickname || '' : '';}sub _hdlr_entry_author_email {    my $e = $_[0]->stash('entry')        or return $_[0]->_no_entry_error('MT' . $_[0]->stash('tag'));    my $a = $e->author;    return '' unless $a && defined $a->email;    $_[1] && $_[1]->{'spam_protect'} ? spam_protect($a->email) : $a->email;}sub _hdlr_entry_author_url {    my($ctx, $args) = @_;    my $e = $ctx->stash('entry')        or return $ctx->_no_entry_error('MT' . $ctx->stash('tag'));    my $a = $e->author;    $a ? $a->url || "" : "";}sub _hdlr_entry_author_link {    my($ctx, $args) = @_;    my $e = $ctx->stash('entry')        or return $ctx->_no_entry_error('MT' . $ctx->stash('tag'));    my $a = $e->author;    return '' unless $a;    my $name = $a->name || '';    my $show_email = 0;    $show_email = 1 if $args->{show_email};    my $show_url = 1 unless exists $args->{show_url} && !$args->{show_url};    if ($show_url && $a->url) {        return sprintf qq(<a target="_blank" href="%s">%s</a>), $a->url, $name;    } elsif ($show_email && $a->email) {        my $str = "mailto:" . $a->email;        $str = spam_protect($str) if $args->{'spam_protect'};        return sprintf qq(<a href="%s">%s</a>), $str, $name;    } else {        return $name;    }}sub _hdlr_entry_id {    my $args = $_[1];    my $e = $_[0]->stash('entry')        or return $_[0]->_no_entry_error('MTEntryID');    $args && $args->{pad} ? (sprintf "%06d", $e->id) : $e->id;}sub _hdlr_entry_tb_link {    my $e = $_[0]->stash('entry')        or return $_[0]->_no_entry_error('MTEntryTrackbackLink');    require MT::Trackback;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -