📄 context.pm
字号:
<p><label for="url"><MT_TRANS phrase="URL:"></label><br /><input tabindex="3" type="text" name="url" id="url" value="$comment_url" /><MT_TRANS phrase="Remember me?"><input type="radio" id="remember" name="bakecookie" /><label for="remember"><MT_TRANS phrase="Yes"></label><input type="radio" id="forget" name="bakecookie" onclick="forgetMe(this.form)" value="Forget Info" style="margin-left: 15px;" /><label for="forget"><MT_TRANS phrase="No"></label><br style="clear: both;" /></p><p><label for="text"><MT_TRANS phrase="Comments:"></label> $allow_comment_html_note<br /><textarea tabindex="4" name="text" rows="10" cols="50" id="text">$comment_text</textarea></p><div align="center"><input type="submit" name="preview" value=" <MT_TRANS phrase="Preview"> " /><input style="font-weight: bold;" type="submit" name="post" value=" <MT_TRANS phrase="Post"> " /></div></form>HTML $result .= <<HTML;<script type="text/javascript" language="javascript"><!--if (document.comments_form.email != undefined && !document.comments_form.email.value) document.comments_form.email.value = getCookie("mtcmtmail");if (document.comments_form.author != undefined && !document.comments_form.author.value) document.comments_form.author.value = getCookie("mtcmtauth");if (document.comments_form.url != undefined && !document.comments_form.url.value) document.comments_form.url.value = getCookie("mtcmthome");if (getCookie("mtcmtauth") || getCookie("mtcmthome")) { document.comments_form.bakecookie[0].checked = true;} else { document.comments_form.bakecookie[1].checked = true;}//--></script>HTML return $result; }}sub _hdlr_entry_comments { my $e = $_[0]->stash('entry') or return $_[0]->_no_entry_error('MTEntryCommentCount'); $e->comment_count;}sub _hdlr_entry_ping_count { my $e = $_[0]->stash('entry') or return $_[0]->_no_entry_error('MTEntryTrackbackCount'); $e->ping_count;}sub _hdlr_entry_previous { my($ctx, $args, $cond) = @_; my $e = $ctx->stash('entry') or return $ctx->_no_entry_error('MTEntryPrevious'); my $prev = $e->previous(1); my $res = ''; if ($prev) { my $builder = $ctx->stash('builder'); local $ctx->{__stash}->{entry} = $prev; local $ctx->{current_timestamp} = $prev->created_on; my %cond = %$cond; $cond{EntryIfAllowComments} = $prev->allow_comments; $cond{EntryIfCommentsOpen} = $prev->allow_comments && $prev->allow_comments eq '1'; $cond{EntryIfAllowPings} = $prev->allow_pings; $cond{EntryIfExtended} = $prev->text_more ? 1 : 0; my $out = $builder->build($ctx, $ctx->stash('tokens'), \%cond); return $ctx->error( $builder->errstr ) unless defined $out; $res .= $out; } $res;}sub _hdlr_entry_next { my($ctx, $args, $cond) = @_; my $e = $ctx->stash('entry') or return $ctx->_no_entry_error('MTEntryNext'); my $next = $e->next(1); my $res = ''; if ($next) { my $builder = $ctx->stash('builder'); local $ctx->{__stash}->{entry} = $next; local $ctx->{current_timestamp} = $next->created_on; my %cond = %$cond; $cond{EntryIfAllowComments} = $next->allow_comments; $cond{EntryIfCommentsOpen} = $next->allow_comments eq '1'; $cond{EntryIfAllowPings} = $next->allow_pings; $cond{EntryIfExtended} = $next->text_more ? 1 : 0; my $out = $builder->build($ctx, $ctx->stash('tokens'), \%cond); return $ctx->error( $builder->errstr ) unless defined $out; $res .= $out; } $res;}sub _hdlr_pass_tokens { my($ctx, $args, $cond) = @_; $ctx->stash('builder')->build($ctx, $ctx->stash('tokens'), $cond);}sub _hdlr_pass_tokens_else { my($ctx, $args, $cond) = @_; $ctx->stash('builder')->build($ctx, $ctx->stash('tokens_else'), $cond);}sub _hdlr_sys_date { my $args = $_[1]; my $t = time; my @ts; if ($args->{utc}) { @ts = gmtime $t; } else { @ts = offset_time_list($t, $_[0]->stash('blog_id')); } $args->{ts} = sprintf "%04d%02d%02d%02d%02d%02d", $ts[5]+1900, $ts[4]+1, @ts[3,2,1,0]; _hdlr_date($_[0], $args);}sub _hdlr_date { my $args = $_[1]; my $ts = $args->{ts} || $_[0]->{current_timestamp}; my $tag = $_[0]->stash('tag'); return $_[0]->error(MT->translate( "You used an [_1] tag without a date context set up.", "MT$tag" )) unless defined $ts; if ($args->{utc}) { my $blog = $_[0]->stash('blog'); $blog = ref $blog ? $blog : MT::Blog->load($blog); my($y, $mo, $d, $h, $m, $s) = $ts =~ /(\d\d\d\d)[^\d]?(\d\d)[^\d]?(\d\d)[^\d]?(\d\d)[^\d]?(\d\d)[^\d]?(\d\d)/; my $four_digit_offset = sprintf('%.02d%.02d', int($blog->server_offset), 60 * abs($blog->server_offset - int($blog->server_offset))); require MT::DateTime; my $tz_secs = MT::DateTime->tz_offset_as_seconds($four_digit_offset); my $ts_utc = timegm( $s, $m, $h, $d, $mo - 1, $y - 1900 ); $ts_utc -= $tz_secs; ($s, $m, $h, $d, $mo, $y) = gmtime( $ts_utc ); $y += 1900; $mo++; $ts = sprintf("%04d%02d%02d%02d%02d%02d", $y, $mo, $d, $h, $m, $s); } if (my $format = $args->{format_name}) { if ($format eq 'rfc822') { my $blog = $_[0]->stash('blog'); $blog = ref $blog ? $blog : MT::Blog->load($blog); my $so = $blog->server_offset; my $partial_hour_offset = 60 * abs($so - int($so)); my $tz = sprintf("%s%02d%02d", $so < 0 ? '-' : '+', abs($so), $partial_hour_offset); ## RFC-822 dates must be in English. $args->{'format'} = '%a, %d %b %Y %H:%M:%S ' . $tz; $args->{language} = 'en'; } } format_ts($args->{'format'}, $ts, $_[0]->stash('blog'), $args->{language});}sub _no_comment_error { return $_[0]->error(MT->translate( "You used an '[_1]' tag outside of the context of a comment; " . "perhaps you mistakenly placed it outside of an 'MTComments' " . "container?", $_[1] ));}sub _hdlr_comments { my($ctx, $args, $cond) = @_; my $blog_id = $ctx->stash('blog_id'); my @comments; my $so = $args->{sort_order} || $ctx->stash('blog')->sort_order_comments; ## If there is a "lastn" arg, then we need to check if there is an entry ## in context. If so, grab the N most recent comments for that entry; ## otherwise, grab the N most recent comments for the entire blog. if (my $n = $args->{lastn}) { if (my $e = $ctx->stash('entry')) { ## Sort in descending order, then grab the first $n ($n most ## recent) comments. my $comments = $e->comments; @comments = $so eq 'ascend' ? sort { $a->created_on <=> $b->created_on } @$comments : sort { $b->created_on <=> $a->created_on } @$comments; # filter out comments from unapproved commenters @comments = grep { $_->visible() } @comments; my $max = $n - 1 > $#comments ? $#comments : $n - 1; @comments = $so eq 'ascend' ? @comments[$#comments-$max..$#comments] : @comments[0..$max]; } else { require MT::Comment; @comments = MT::Comment->load({ blog_id => $blog_id, visible => 1 }, { 'sort' => 'created_on', direction => 'descend', limit => $n }); @comments = $so eq 'ascend' ? sort { $a->created_on <=> $b->created_on } @comments : sort { $b->created_on <=> $a->created_on } @comments; } } else { my $e = $ctx->stash('entry') or return $_[0]->_no_entry_error('MTComments'); my $comments = $e->comments; @comments = $so eq 'ascend' ? sort { $a->created_on <=> $b->created_on } @$comments : sort { $b->created_on <=> $a->created_on } @$comments; } my $html = ''; my $builder = $ctx->stash('builder'); my $tokens = $ctx->stash('tokens'); my $i = 1; @comments = grep { $_->visible() } @comments; for my $c (@comments) { $ctx->stash('comment' => $c); local $ctx->{current_timestamp} = $c->created_on; $ctx->stash('comment_order_num', $i); my $out = $builder->build($ctx, $tokens, $cond); return $ctx->error( $builder->errstr ) unless defined $out; $html .= $out; $i++; } $html;}sub _hdlr_comment_date { my $c = $_[0]->stash('comment') or return $_[0]->_no_comment_error('MTCommentDate'); my $args = $_[1]; $args->{ts} = $c->created_on; _hdlr_date($_[0], $args);}sub _hdlr_comment_id { my $args = $_[1]; my $c = $_[0]->stash('comment') or return $_[0]->_no_comment_error('MTCommentID'); $args && $args->{pad} ? (sprintf "%06d", $c->id) : $c->id;}sub _hdlr_comment_entry_id { my $args = $_[1]; my $c = $_[0]->stash('comment') or return $_[0]->_no_comment_error('MTCommentEntryID'); $args && $args->{pad} ? (sprintf "%06d", $c->entry_id) : $c->entry_id;}sub _hdlr_comment_author { sanitize_on($_[1]); my $tag = $_[0]->stash('tag'); my $c = $_[0]->stash($tag =~ /Preview/ ? 'comment_preview' : 'comment') or return $_[0]->_no_comment_error('MT' . $tag); my $a = defined $c->author ? $c->author : ''; $a ||= $_[1]{default} || ''; remove_html($a);}sub _hdlr_comment_ip { my $tag = $_[0]->stash('tag'); my $c = $_[0]->stash($tag =~ /Preview/ ? 'comment_preview' : 'comment') or return $_[0]->_no_comment_error('MT' . $tag); defined $c->ip ? $c->ip : '';}sub _hdlr_comment_author_link { #sanitize_on($_[1]); my($ctx, $args) = @_; my $tag = $ctx->stash('tag'); my $c = $ctx->stash($tag =~ /Preview/ ? 'comment_preview' : 'comment') or return $ctx->_no_comment_error('MT' . $tag); my $name = $c->author; $name = '' unless defined $name; $name ||= $_[1]{default_name}; $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 && $c->url) { my $cfg = MT::ConfigMgr->instance; my $cgi_path = $cfg->CGIPath; $cgi_path =~ s#([^/])$#$1/#; my $comment_script = $cfg->CommentScript; $name = remove_html($name); my $url = remove_html($c->url); $url =~ s/>/>/g; if ($c->id && !$args->{no_redirect}) { return sprintf(qq(<a target="_blank" title="%s" href="%s%s?__mode=red;id=%d">%s</a>), $url, $cgi_path, $comment_script, $c->id, $name); } else { # In the case of preview, show URL directly without a redirect return sprintf(qq(<a target="_blank" title="%s" href="%s">%s</a>), $url, $url, $name); } } elsif ($show_email && $c->email && MT::Util::is_valid_email($c->email)) { my $email = remove_html($c->email); my $str = "mailto:" . $email; $str = spam_protect($str) if $args->{'spam_protect'}; return sprintf qq(<a href="%s">%s</a>), $str, $name; } else { return $name; }}sub _hdlr_comment_email { sanitize_on($_[1]); my $tag = $_[0]->stash('tag'); my $c = $_[0]->stash($tag =~ /Preview/ ? 'comment_preview' : 'comment') or return $_[0]->_no_comment_error('MT' . $tag); return '' unless defined $c->email; my $email = remove_html($c->email); $_[1] && $_[1]->{'spam_protect'} ? spam_protect($email) : $email;}sub _hdlr_comment_author_identity { my ($ctx, $args) = @_; my $tag = $ctx->stash('tag'); my $cmt = $ctx->stash('comment') or return $ctx->_no_comment_error('MT' . $tag); if ($cmt->commenter_id) { my $auth = MT::Author->load($cmt->commenter_id) or return "?"; my $cfg = MT::ConfigMgr->instance(); my $link = $cfg->IdentityURL; $link =~ s@/$@@; $link .= "/" . $auth->name(); my $blog = MT::Blog->load($ctx->stash('blog_id')); my $root_url = $cfg->PublishCommenterIcon ? $blog->site_url() : ($cfg->StaticWebPath || $cfg->CGIPath) . "images"; $root_url =~ s|/$||; qq{<a class="commenter-profile" href=\"$link\"><img alt='[TypeKey Profile Page]' src='$root_url/nav-commenters.gif' /></a>}; } else { ""; }}sub _hdlr_comment_url { sanitize_on($_[1]); my $tag = $_[0]->stash('tag'); my $c = $_[0]->stash($tag =~ /Preview/ ? 'comment_preview' : 'comment') or return $_[0]->_no_comment_error('MT' . $tag); my $url = defined $c->url ? $c->url : ''; remove_html($url);}sub _hdlr_comment_body { my($ctx, $arg) = @_; sanitize_on($arg); my $tag
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -