Exemple #1
0
get('/category/:category', function ($category) {
    if (!login()) {
        file_cache($_SERVER['REQUEST_URI']);
    }
    $page = from($_GET, 'page');
    $page = $page ? (int) $page : 1;
    $perpage = config('category.perpage');
    if (empty($perpage)) {
        $perpage = 10;
    }
    $posts = get_category($category, $page, $perpage);
    $desc = get_category_info($category);
    if (strtolower($category) !== 'uncategorized') {
        $desc = $desc[0];
    }
    $total = get_categorycount($category);
    if (empty($posts) || $page < 1) {
        // a non-existing page
        not_found();
    }
    render('main', array('title' => $desc->title . ' - ' . blog_title(), 'description' => $desc->description, 'canonical' => $desc->url, 'page' => $page, 'posts' => $posts, 'category' => $desc, 'bodyclass' => 'incategory', 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; ' . $desc->title, 'pagination' => has_pagination($total, $perpage, $page), 'is_category' => true));
});
// Show edit the category page
get('/category/:category/edit', function ($category) {
    if (login()) {
        config('views.root', 'system/admin/views');
        $post = get_category_info($category);
        if (!$post) {
            not_found();
        }
        $post = $post[0];
    <tr>
        <td><a href="<?php 
    echo $d->url;
    ?>
" target="_blank"><?php 
    echo $d->title;
    ?>
</a></td>
        <td><?php 
    echo $d->body;
    ?>
</td>
        <td><?php 
    $total = get_draftcount($d->md) + get_categorycount($d->md);
    echo $total;
    ?>
</td>
        <td><a href="<?php 
    echo $d->url;
    ?>
/edit?destination=admin/categories">Edit</a> <?php 
    if (get_categorycount($d->md) == 0 && get_draftcount($d->md) == 0) {
        echo '<a href="' . $d->url . '/delete?destination=admin/categories">Delete</a>';
    }
    ?>
</td>
    </tr>
    <?php 
}
?>
</table>
Exemple #3
0
function category_list($custom = null)
{
    $dir = "cache/widget";
    $filename = "cache/widget/category.list.cache";
    $tmp = array();
    $cat = array();
    $list = array();
    if (is_dir($dir) === false) {
        mkdir($dir, 0775, true);
    }
    if (file_exists($filename)) {
        $cat = unserialize(file_get_contents($filename));
    } else {
        $arr = get_category_info(null);
        foreach ($arr as $a) {
            $cat[] = array($a->md, $a->title);
        }
        array_push($cat, array('uncategorized', 'Uncategorized'));
        asort($cat);
        $tmp = serialize($cat);
        file_put_contents($filename, print_r($tmp, true));
    }
    if (!empty($custom)) {
        return $cat;
    }
    echo '<ul>';
    foreach ($cat as $k => $v) {
        if (get_categorycount($v['0']) !== 0) {
            echo '<li><a href="' . site_url() . 'category/' . $v['0'] . '">' . $v['1'] . '</a></li>';
        }
    }
    echo '</ul>';
}