コード例 #1
0
function smarty_block_mtifisancestor($args, $content, &$ctx, &$repeat)
{
    $localvars = array('conditional', 'else_content');
    if (!isset($content)) {
        require_once "MTUtil.php";
        $cat = get_category_context($ctx, $class);
        $ctx->localize($localvars);
        $children = $ctx->mt->db->fetch_categories(array('label' => $args['child'], 'blog_id' => $ctx->stash('blog_id'), 'show_empty' => 1));
        $ret = false;
        if ($children) {
            foreach ($children as $child) {
                if (_is_ancestor($cat, $child, $ctx)) {
                    $ret = true;
                    break;
                }
            }
            unset($child);
        }
        $ctx->stash('else_content', null);
        $ctx->stash('conditional', $ret ? 1 : 0);
    } else {
        if (!$ctx->stash('conditional')) {
            $content = $ctx->stash('else_content');
        }
        $ctx->restore($localvars);
    }
    return $content;
}
コード例 #2
0
function smarty_block_mtparentcategory($args, $content, &$ctx, &$repeat)
{
    if (!isset($content)) {
        $ctx->localize(array('category', 'conditional', 'else_content'));
        $class = isset($args) && isset($args['class']) ? $args['class'] : 'category';
        require_once "MTUtil.php";
        $cat = get_category_context($ctx, $class);
        if ($cat && $cat->category_parent) {
            if ($class == 'folder') {
                $parent_cat = $ctx->mt->db()->fetch_folder($cat->category_parent);
            } else {
                $parent_cat = $ctx->mt->db()->fetch_category($cat->category_parent);
            }
            $ctx->stash('category', $parent_cat);
        }
        $ctx->stash('conditional', isset($parent_cat));
        $ctx->stash('else_content', null);
    } else {
        if (!$ctx->stash('conditional')) {
            $content = $ctx->stash('else_content');
        }
        $ctx->restore(array('category', 'conditional', 'else_content'));
    }
    return $content;
}
コード例 #3
0
function smarty_function_mtcategorydescription($args, &$ctx)
{
    require_once "MTUtil.php";
    $cat = get_category_context($ctx);
    if (!$cat) {
        return '';
    }
    return $cat->category_description;
}
コード例 #4
0
function smarty_function_mtcategorycount($args, &$ctx)
{
    require_once "MTUtil.php";
    $category = get_category_context($ctx);
    if (!$category) {
        return '';
    }
    $count = $category->entry_count();
    return $ctx->count_format($count, $args);
}
コード例 #5
0
function smarty_block_mthasparentcategory($args, $content, &$ctx, &$repeat)
{
    if (!isset($content)) {
        $class = isset($args) && isset($args['class']) ? $args['class'] : 'category';
        require_once "MTUtil.php";
        $cat = get_category_context($ctx, $class);
        $has_parent = $cat['category_parent'];
        return $ctx->_hdlr_if($args, $content, $ctx, $repeat, $has_parent > 0 ? 1 : 0);
    } else {
        return $ctx->_hdlr_if($args, $content, $ctx, $repeat);
    }
}
コード例 #6
0
function smarty_block_mtparentcategories($args, $content, &$ctx, &$repeat)
{
    $localvars = array('_categories', 'category', '_categories_counter', 'glue', '__out');
    if (!isset($content)) {
        $ctx->localize($localvars);
        require_once "MTUtil.php";
        $class = isset($args) && isset($args['class']) ? $args['class'] : 'category';
        $cat = get_category_context($ctx, $class);
        $parents = array();
        get_parent_categories($cat, $ctx, $parents, $class);
        if (!isset($args['exclude_current'])) {
            $parents[] = $cat;
        }
        if (isset($args['glue'])) {
            $glue = $args['glue'];
        } else {
            $glue = '';
        }
        $ctx->stash('_categories', $parents);
        $ctx->stash('glue', $glue);
        $ctx->stash('__out', false);
        $counter = 0;
    } else {
        $parents = $ctx->stash('_categories');
        $counter = $ctx->stash('_categories_counter');
        $glue = $ctx->stash('glue');
        $out = $ctx->stash('__out');
    }
    if ($counter < count($parents)) {
        $ctx->stash('category', $parents[$counter]);
        $ctx->stash('_categories_counter', $counter + 1);
        $repeat = true;
        if (!empty($glue) && !empty($content)) {
            if ($out) {
                $content = $glue . $content;
            } else {
                $ctx->stash('__out', true);
            }
        }
    } else {
        if (!empty($glue) && $out && !empty($content)) {
            $content = $glue . $content;
        }
        $repeat = false;
        $glue = '';
        $ctx->restore($localvars);
    }
    return $content;
}
コード例 #7
0
function _has_sub_categories(&$ctx, $class = 'category')
{
    require_once "MTUtil.php";
    $cat = get_category_context($ctx, $class);
    $has_sub_cats = 0;
    $children = $cat->children();
    if (isset($children)) {
        $has_sub_cats = count($cat->children()) > 0;
    } else {
        $cats = $ctx->mt->db()->fetch_categories(array('blog_id' => $ctx->stash('blog_id'), 'category_id' => $cat->category_id, 'children' => 1, 'show_empty' => 1, 'class' => $class));
        if (isset($cats)) {
            $cat->children($cats);
            $has_sub_cats = count($cats) > 0;
        }
    }
    return $has_sub_cats;
}
コード例 #8
0
function _has_sub_categories(&$ctx, $class = 'category')
{
    $class = isset($args) && isset($args['class']) ? $args['class'] : 'category';
    require_once "MTUtil.php";
    $cat = get_category_context($ctx, $class);
    $has_sub_cats = 0;
    if (isset($cat['_children'])) {
        $has_sub_cats = count($cat['_children']) > 0;
    } else {
        $cats =& $ctx->mt->db->fetch_categories(array('blog_id' => $ctx->stash('blog_id'), 'category_id' => $cat['category_id'], 'children' => 1, 'show_empty' => 1, 'class' => $class));
        if (isset($cats)) {
            $cat['_children'] = $cats;
            $has_sub_cats = count($cats) > 0;
        }
    }
    return $has_sub_cats;
}
コード例 #9
0
function smarty_function_mtcategorybasename($args, &$ctx)
{
    require_once "MTUtil.php";
    $cat = get_category_context($ctx);
    if (!$cat) {
        return '';
    }
    $basename = $cat->category_basename;
    if ($sep = $args['separator']) {
        if ($sep == '-') {
            $basename = preg_replace('/_/', '-', $basename);
        } elseif ($sep == '_') {
            $basename = preg_replace('/-/', '_', $basename);
        }
    }
    return $basename;
}
コード例 #10
0
function smarty_block_mttoplevelparent($args, $content, &$ctx, &$repeat)
{
    if (!isset($content)) {
        $ctx->localize(array('category', 'conditional', 'else_content'));
        require_once "MTUtil.php";
        $cat = get_category_context($ctx);
        require_once "block.mtparentcategories.php";
        $list = array();
        get_parent_categories($cat, $ctx, $list);
        $ctx->stash('else_content', null);
        if (count($list) > 0) {
            $cat = array_pop($list);
            $ctx->stash('category', $cat);
        }
        $ctx->stash('conditional', $cat ? 1 : 0);
    } else {
        if (!$ctx->stash('conditional')) {
            $content = $ctx->stash('else_content');
        }
        $ctx->restore(array('category', 'conditional', 'else_content'));
    }
    return $content;
}