コード例 #1
0
ファイル: by.php プロジェクト: Selwyn-b/elefant
 * Displays a list of blog posts by author.
 */
$page->id = 'blog';
$page->layout = $appconf['Blog']['layout'];
require_once 'apps/blog/lib/Filters.php';
$preview_chars = (int) Appconf::blog('Blog', 'preview_chars') ? (int) Appconf::blog('Blog', 'preview_chars') : false;
$page->limit = 10;
$page->author = urldecode($this->params[0]);
if (!$page->author) {
    $this->redirect('/blog');
}
$page->num = count($this->params) > 1 && is_numeric($this->params[1]) ? $this->params[1] - 1 : 0;
$page->offset = $page->num * $page->limit;
$p = new blog\Post();
$posts = $p->by($page->author, $page->limit, $page->offset);
$page->count = $p->query()->where('published', 'yes')->where('author', $page->author)->count();
$page->last = $page->offset + count($posts);
$page->more = $page->count > $page->last ? true : false;
$page->next = $page->num + 2;
$footer = Appconf::blog('Blog', 'post_footer');
$footer_stripped = strip_tags($footer);
$footer = $footer && !empty($footer_stripped) ? $tpl->run_includes($footer) : false;
if (Appconf::blog('Blog', 'post_format') === 'markdown') {
    require_once 'apps/blog/lib/markdown.php';
}
foreach ($posts as $post) {
    $post->url = '/blog/post/' . $post->id . '/' . URLify::filter($post->title);
    $post->tag_list = strlen($post->tags) > 0 ? explode(',', $post->tags) : array();
    $post->social_buttons = $appconf['Social Buttons'];
    if (Appconf::blog('Blog', 'post_format') === 'html') {
        $post->body = $tpl->run_includes($post->body);
コード例 #2
0
ファイル: index.php プロジェクト: nathanieltite/elefant
    if (!$appconf['Custom Handlers']['blog/index']) {
        echo $this->error(404, i18n_get('Not found'), i18n_get('The page you requested could not be found.'));
        return;
    }
    $extra = count($this->params) > 0 ? '/' . $this->params[0] : '';
    echo $this->run($appconf['Custom Handlers']['blog/index'] . $extra, $data);
    return;
}
$page->layout = $appconf['Blog']['layout'];
require_once 'apps/blog/lib/Filters.php';
$page->limit = 10;
$page->num = count($this->params) > 0 && is_numeric($this->params[0]) ? $this->params[0] - 1 : 0;
$page->offset = $page->num * $page->limit;
$p = new blog\Post();
$posts = $p->latest($page->limit, $page->offset);
$page->count = $p->query()->where('published', 'yes')->count();
$page->last = $page->offset + count($posts);
$page->more = $page->count > $page->last ? true : false;
$page->next = $page->num + 2;
if (!is_array($posts) || count($posts) === 0) {
    echo '<p>' . i18n_get('No posts yet... :(') . '</p>';
    if (User::require_admin()) {
        echo '<p><a href="/blog/add">' . i18n_get('Add Blog Post') . '</a></p>';
    }
} else {
    if (User::require_admin()) {
        echo '<p><a href="/blog/add">' . i18n_get('Add Blog Post') . '</a></p>';
    }
    foreach ($posts as $post) {
        $post->url = '/blog/post/' . $post->id . '/' . URLify::filter($post->title);
        $post->tag_list = explode(',', $post->tags);
コード例 #3
0
ファイル: admin.php プロジェクト: nathanieltite/elefant
<?php

/**
 * Admin page where you can edit posts and create new ones.
 */
$page->layout = 'admin';
if (!User::require_admin()) {
    $this->redirect('/admin');
}
require_once 'apps/blog/lib/Filters.php';
$limit = 20;
$_GET['offset'] = isset($_GET['offset']) ? $_GET['offset'] : 0;
$lock = new Lock();
$posts = blog\Post::query('id, title, ts, author, published')->order('ts desc')->fetch_orig($limit, $_GET['offset']);
$count = blog\Post::query()->count();
foreach ($posts as $k => $p) {
    $posts[$k]->locked = $lock->exists('Blog', $p->id);
}
$page->title = i18n_get('Blog Posts');
echo $tpl->render('blog/admin', array('posts' => $posts, 'count' => $count, 'offset' => $_GET['offset'], 'more' => $count > $_GET['offset'] + $limit ? true : false, 'prev' => $_GET['offset'] - $limit, 'next' => $_GET['offset'] + $limit));
コード例 #4
0
ファイル: admin.php プロジェクト: Selwyn-b/elefant
// search query
$q_fields = array('title', 'author', 'tags', 'body');
$q_exact = array('author', 'published');
$m = isset($_GET['m']) ? $_GET['m'] : '';
// month query
$url = '/blog/admin?q=' . urlencode($q) . '&m=' . urlencode($m) . '&offset=%d';
$lock = new Lock();
// adds yyyy-mm range to query, called via closure
function blog_admin_where_month($q, $m)
{
    if (preg_match('/^[0-9]{4}-[0-9]{2}$/', $m)) {
        $start = $m . '-01 00:00:00';
        $end = $m . '-' . gmdate('t', strtotime($start)) . ' 23:59:59';
        $q->where('ts >= ?', $start);
        $q->and_where('ts <= ?', $end);
    } else {
        $q->where('1 = 1');
    }
}
$posts = blog\Post::query('id, title, ts, author, published, tags')->where_search($q, $q_fields, $q_exact)->and_where(function ($q) use($m) {
    blog_admin_where_month($q, $m);
})->order('ts desc')->fetch_orig($limit, $offset);
$count = blog\Post::query()->where_search($q, $q_fields, $q_exact)->and_where(function ($q) use($m) {
    blog_admin_where_month($q, $m);
})->count();
foreach ($posts as $k => $p) {
    $posts[$k]->locked = $lock->exists('Blog', $p->id);
    $posts[$k]->tags = preg_split('/, ?/', $posts[$k]->tags);
}
$page->title = __('Blog Posts');
echo $tpl->render('blog/admin', array('limit' => $limit, 'total' => $count, 'posts' => $posts, 'count' => count($posts), 'url' => $url, 'q' => $q, 'm' => $m, 'archives' => blog\Post::archive_months(false), 'months' => explode(' ', __('Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'))));
コード例 #5
0
ファイル: related.php プロジェクト: Selwyn-b/elefant
<?php

/**
 * Show related posts. Called internally by blog/post.
 */
$id = $data['id'];
$tags = explode(',', $data['tags']);
$posts = blog\Post::query('id, thumbnail, title, ts')->where('published', 'yes')->where('id != ?', $id)->and_where(function ($q) use($tags) {
    foreach ($tags as $n => $tag) {
        $tag = trim($tag);
        if ($n === 0) {
            $q->where('tags like ?', '%' . $tag . '%');
        } else {
            $q->or_where('tags like ?', '%' . $tag . '%');
        }
    }
})->order('ts', 'desc')->fetch_orig(3);
$this->run('admin/util/minimal-grid');
$page->add_script('/apps/blog/css/related.css');
echo $tpl->render('blog/related', array('posts' => $posts));
コード例 #6
0
ファイル: publish-queue.php プロジェクト: Selwyn-b/elefant
<?php

/**
 * Publish scheduled blog posts. Use via cron like this:
 *
 *     0,15,30,45 * * * * /var/www/elefant blog/publish-queue
 */
if (!$this->cli) {
    die('Must be run from the command line.');
}
$page->layout = false;
// fetch queued posts
$posts = blog\Post::query()->where('published', 'que')->where('ts <= ?', gmdate('Y-m-d H:i:s'))->fetch();
// publish posts
foreach ($posts as $post) {
    $post->published = 'yes';
    $post->put();
    Versions::add($post);
}