Example #1
0
 static function init($context)
 {
     if ($context !== 'rebuild') {
         return false;
     }
     self::$conf = gb::data('plugins/' . gb_filenoext(basename(__FILE__)), array('classname' => 'codeblock', 'tabsize' => 2, 'pygmentize' => 'pygmentize'));
     gb_cfilter::add('body.html', array(__CLASS__, 'filter'), 0);
     return true;
 }
Example #2
0
 static function init($context)
 {
     if ($context === 'rebuild') {
         gb::observe('did-parse-object-meta', array(__CLASS__, 'check_content'));
         gb_cfilter::add('body.html', array(__CLASS__, 'escape_php'), 0);
         gb_cfilter::add('body.html', array(__CLASS__, 'unescape_php'), 9000);
         return true;
     } elseif ($context === 'request') {
         gb::add_filter('post-body', array(__CLASS__, 'eval_body'));
         return true;
     }
 }
Example #3
0
 static function init($context)
 {
     $default_conf = array('api_key' => '', 'delete_spam' => true);
     self::$conf = gb::data('plugins/' . gb_filenoext(basename(__FILE__)), $default_conf);
     if (!self::$key) {
         self::$key = self::$conf['api_key'];
     }
     if (!self::$key) {
         gb::log(LOG_WARNING, 'akismet not loaded since "api_key" is not set in %s', self::$conf->file);
         return false;
     }
     if ($context === 'admin') {
         gb_cfilter::add('pre-comment', array(__CLASS__, 'check_comment'));
         return true;
     }
     return false;
 }
Example #4
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;
     }
Example #5
0
 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;
 }
Example #6
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');
Example #7
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';
     }
 }
Example #8
0
 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);
 }
Example #9
0
function gb_filter_post_reload_comment(GBComment $comment)
{
    $comment->body = gb_cfilter::apply('sanitize-comment', $comment->body);
    return $comment;
}