apply() static public method

Apply filters for $tag on $value
static public apply ( $tag, $value )
示例#1
0
             $v = $post->{$k};
             if ($v instanceof GBDateTime || $v instanceof GBAuthor) {
                 $v = strval($v);
             }
             $modified_state[$k] = $v;
         }
     }
 }
 # post-process checks before saving
 if ($modified_state) {
     $post->modified = new GBDateTime();
     if (!$post->title && !$post->slug) {
         throw new UnexpectedValueException('Both title and slug can not both be empty. Please choose a title for this post.');
     }
     if (!$post->slug) {
         $post->slug = gb_cfilter::apply('sanitize-title', $post->title);
     } elseif ($created && !$post->title) {
         $post->title = ucfirst($post->slug);
     }
 }
 # set newborn properties
 if ($created) {
     if (!$post->mimeType) {
         $post->mimeType = 'text/html';
         gb::log('did force html');
     } else {
         gb::log('mime type is %s', $post->mimeType);
     }
     if (!$post->published) {
         $post->published = $post->modified;
     }
示例#2
0
文件: markdown.php 项目: rsms/gitblog
 static function reloadExposedObject(GBExposedContent $c)
 {
     $conf = gb_filter_post_reload_content_get_conf($c);
     $conf['auto_linebreaks'] = false;
     $conf['auto_paragraphs'] = false;
     # prefix for footnotes
     $parser->fn_id_prefix = $c->domID();
     # have body?
     if ($c->body) {
         # create excerpt for GBPosts if not already set
         if (!$c->excerpt && preg_match('/<!--[ \\s\\t\\r\\n]*more[ \\s\\t\\r\\n]*--(>)/i', $c->body, $m, PREG_OFFSET_CAPTURE)) {
             $c->excerpt = substr($c->body, 0, $m[0][1]);
             $c->body = $c->excerpt . '<div id="read-more" class="post-more-anchor"></div>' . substr($c->body, $m[1][1] + 1);
         }
         $c->body = gb_cfilter::apply('body.md', $c->body);
         $c->body = gb_cfilter::apply('body.html', $c->body, $conf);
     }
     if ($c->excerpt) {
         $c->excerpt = trim($c->excerpt);
         $c->excerpt = gb_cfilter::apply('body.md', $c->excerpt);
         # assure wrapping <p>
         if (!preg_match('{^$|^<(p|ul|ol|dl|pre|blockquote)>}i', $c->excerpt)) {
             $c->excerpt = preg_replace('{\\n{2,}}', "</p>\n\n<p>", '<p>' . $c->excerpt . '</p>');
         }
         $c->excerpt = gb_cfilter::apply('body.html', $c->excerpt, $conf);
     }
     return $c;
 }
示例#3
0
    $input['author-uri'] = gb_cfilter::apply('sanitize-url', $input['author-url']);
}
# if we are logged in, use the canonical email
if (gb::$authorized) {
    $input['author-email'] = gb::$authorized->email;
}
# set author cookie
gb_author_cookie::set($input['author-email'], $input['author-name'], $input['author-uri']);
# create comment object
$comment = new GBComment(array('date' => $date->__toString(), 'ipAddress' => $_SERVER['REMOTE_ADDR'], 'email' => $input['author-email'], 'uri' => $input['author-uri'], 'name' => $input['author-name'], 'body' => $input['reply-message'], 'approved' => false, 'post' => $post));
# always approve admin comments
if (gb::$authorized) {
    $comment->approved = true;
}
# apply filters
$comment = gb_cfilter::apply('pre-comment', $comment);
# aquire referrer
$referrer = gb::referrer_url();
# append to comment db
if ($comment) {
    try {
        $cdb = $post->getCommentsDB();
        $added = $cdb->append($comment, $input['reply-to'] ? $input['reply-to'] : null);
        # duplicate?
        if ($added === false) {
            gb::log('skipped duplicate comment from ' . var_export($comment->email, 1));
            gb::event('was-duplicate-comment', $comment);
            if ($referrer) {
                $referrer->fragment = 'comments';
                $referrer['comment-status'] = 'duplicate';
                header('HTTP/1.1 304 Not Modified');
示例#4
0
 function postProcessExposedContent(GBExposedContent $obj)
 {
     # Draft objects which have never been published does not have a slug, so
     # we derive one from the title:
     if (!$obj->slug) {
         $obj->slug = gb_cfilter::apply('sanitize-title', $obj->title);
     } else {
         $obj->slug = preg_replace('/\\/+/', '-', urldecode($obj->slug));
     }
     # pathspec
     if ($obj instanceof WPPost) {
         $obj->name = 'content/posts/' . $obj->published->utcformat('%Y/%m/%d-') . $obj->slug . '.html';
     } else {
         $obj->name = 'content/pages/' . $obj->slug . '.html';
     }
 }
示例#5
0
文件: gitblog.php 项目: rsms/gitblog
 function reload($data, $commits)
 {
     parent::reload($data, $commits);
     # apply info from commits, like publish date and author
     $this->applyInfoFromCommits($commits);
     # load actual comments
     $db = new GBCommentDB();
     $db->loadString($data);
     $this->comments = $db->get();
     # apply filters
     gb_cfilter::apply('post-reload-comments', $this);
 }
示例#6
0
function gb_filter_post_reload_comment(GBComment $comment)
{
    $comment->body = gb_cfilter::apply('sanitize-comment', $comment->body);
    return $comment;
}