Пример #1
0
function tree_to_array($root, $table, $showRoot = TRUE)
{
    // showRoot -- Do we want to include the "root" category named "all" in our results -- all subcats WILL appear regardless
    global $db;
    $sql = 'SELECT lft, rgt FROM `' . $table . '` WHERE category__auto_id=' . $root . ';';
    $result = mysql_query($sql);
    $row = mysql_fetch_array($result);
    $right = array();
    $sql = 'SELECT * FROM `' . $table . '` WHERE lft BETWEEN ' . $row['lft'] . ' AND ' . $row['rgt'] . ' and category_enabled <> 0 ORDER BY lft ASC;';
    $result = mysql_query($sql);
    $i = 0;
    $lastspacer = 0;
    while ($row = mysql_fetch_array($result)) {
        if (count($right) > 0) {
            // check if we should remove a node from the stack
            while ($right[count($right) - 1] < $row['rgt']) {
                array_pop($right);
            }
        }
        $array[$i]['spacercount'] = count($right);
        $array[$i]['lastspacercount'] = $lastspacer;
        $array[$i]['spacerdiff'] = abs($lastspacer - count($right));
        $array[$i]['auto_id'] = $row['category__auto_id'];
        $array[$i]['name'] = $row['category_name'];
        $array[$i]['safename'] = $row['category_safe_name'];
        $array[$i]['color'] = $row['category_color'];
        $array[$i]['parent'] = $row['category_parent'];
        $array[$i]['parent_name'] = GetCatName($row['category_parent']);
        $array[$i]['subcat_count'] = GetSubCatCount($row['category__auto_id']);
        $array[$i]['parent_subcat_count'] = GetSubCatCount($row['category_parent']);
        $lastspacer = count($right);
        $i = $i + 1;
        $right[] = $row['rgt'];
    }
    if ($showRoot == FALSE) {
        $array = my_array_unset($array, 0);
    }
    return $array;
}
Пример #2
0
function do_sidebar($var_smarty, $navwhere = '')
{
    // show the categories in the sidebar
    global $db, $dblang, $globals, $the_cats;
    if ($navwhere == '') {
        global $navwhere;
    }
    // fix for 'undefined index' errors
    if (!isset($navwhere['text4'])) {
        $navwhere['text4'] = '';
    } else {
        $navwhere['text4'] = htmlspecialchars($navwhere['text4']);
    }
    if (!isset($navwhere['text3'])) {
        $navwhere['text3'] = '';
    } else {
        $navwhere['text3'] = htmlspecialchars($navwhere['text3']);
    }
    if (!isset($navwhere['text2'])) {
        $navwhere['text2'] = '';
    } else {
        $navwhere['text2'] = htmlspecialchars($navwhere['text2']);
    }
    if (!isset($navwhere['text1'])) {
        $navwhere['text1'] = '';
    } else {
        $navwhere['text1'] = htmlspecialchars($navwhere['text1']);
    }
    if (!isset($navwhere['link4'])) {
        $navwhere['link4'] = '';
    }
    if (!isset($navwhere['link3'])) {
        $navwhere['link3'] = '';
    }
    if (!isset($navwhere['link2'])) {
        $navwhere['link2'] = '';
    }
    if (!isset($navwhere['link1'])) {
        $navwhere['link1'] = '';
    }
    $var_smarty->assign('navbar_where', $navwhere);
    $var_smarty->assign('body_args', '');
    // fix for 'undefined index' errors
    $_caching = $var_smarty->cache;
    // get the current cache settings
    $var_smarty->cache = true;
    // cache has to be on otherwise is_cached will always be false
    $var_smarty->cache_lifetime = -1;
    // lifetime has to be set to something otherwise is_cached will always be false
    $thetpl = $var_smarty->get_template_vars('the_template_sidebar_modules') . '/categories.tpl';
    // check to see if the category sidebar module is already cached
    // if it is, use it
    if (isset($_GET['category'])) {
        $thecat = sanitize($_GET['category'], 3);
    } else {
        $thecat = '';
    }
    if ($var_smarty->is_cached($thetpl, 'sidebar|category|' . $thecat)) {
        $var_smarty->assign('cat_array', 'x');
        // this is needed. sidebar.tpl won't include the category module if cat_array doesnt have some data
    } else {
        if (isset($_GET['category'])) {
            $thecat = get_cached_category_data('category_safe_name', urlencode(sanitize($_GET['category'], 1)));
            $thecat = $thecat->category_name;
        }
        $var_smarty->assign('UrlMethod', urlmethod);
        foreach ($the_cats as $cat) {
            if ($cat->category_id == $thecat && $cat->category_lang == $dblang && $cat->category_parent == 0) {
                $globals['category_id'] = $cat->category_id;
                $globals['category_name'] = $cat->category_name;
            }
        }
        $pos = strrpos($_SERVER["SCRIPT_NAME"], "/");
        $script_name = substr($_SERVER["SCRIPT_NAME"], $pos + 1, 100);
        $script_name = str_replace(".php", "", $script_name);
        include_once 'dbtree.php';
        $login_user = $db->escape(sanitize($_COOKIE['mnm_user'], 3));
        if ($login_user) {
            /////// for user set category----sorojit.
            $sqlGeticategory = $db->get_var("SELECT user_categories from " . table_users . " where user_login = '******';");
            $array1 = "SELECT * from " . table_categories . " where category__auto_id in ({$sqlGeticategory})";
            $result = mysql_query($array1);
            $array = array();
            while ($row = mysql_fetch_array($result)) {
                //print_r($row);
                $row[] = $row;
            }
            $right = array();
            $array1 = "SELECT * from " . table_categories . " where category__auto_id in ({$sqlGeticategory}) ORDER BY lft";
            $result1 = mysql_query($array1);
            while ($row = mysql_fetch_object($result1)) {
                $a[] = $row;
            }
            $result = $a;
            $i = 0;
            $lastspacer = 0;
            // added @ thanks to `parterburn` - http://www.pligg.com/forum/showthread.php?t=4888
            foreach ($result as $row) {
                if (count($right) > 0) {
                    // check if we should remove a node from the stack
                    while ($right[count($right) - 1] < $row->rgt) {
                        if (array_pop($right) == NULL) {
                            break;
                            // We've reached the top of the category chain
                        }
                    }
                }
                $array[$i]['principlecat'] = $row->rgt - $row->lft - 1;
                $array[$i]['spacercount'] = count($right);
                $array[$i]['lastspacercount'] = $lastspacer;
                $array[$i]['spacerdiff'] = abs($lastspacer - count($right));
                $array[$i]['auto_id'] = $row->category__auto_id;
                $array[$i]['name'] = $row->category_name;
                $array[$i]['safename'] = $row->category_safe_name;
                if (isset($row->category_color)) {
                    $array[$i]['color'] = $row->category_color;
                }
                if (isset($row->category_parent)) {
                    $array[$i]['parent'] = $row->category_parent;
                    $array[$i]['parent_name'] = GetCatName($row->category_parent);
                    $array[$i]['parent_subcat_count'] = GetSubCatCount($row->category_parent);
                }
                $array[$i]['subcat_count'] = GetSubCatCount($row->category__auto_id);
                $lastspacer = count($right);
                $i = $i + 1;
                $right[] = $row->rgt;
            }
            ///////end of for user set category
            $var_smarty->assign('start', 0);
        } else {
            $array = tree_to_array(0, table_categories);
            $var_smarty->assign('start', 1);
        }
        $var_smarty->assign('lastspacer', 0);
        $var_smarty->assign('cat_array', $array);
        // use the 'totals' table now
        $published_count = get_story_count('published');
        $var_smarty->assign('published_count', $published_count);
        //	    $sql = "select *,  count(*) as count from " . table_links . ", " . table_categories . " where category_lang='$dblang' and category_id=link_category group by link_category ORDER BY category_name ASC";
        //		$categorylist = object_2_array($db->get_results($sql));
        //		$var_smarty->assign('categorylist', $categorylist);
        $var_smarty->assign('category_url', getmyurl('maincategory'));
    }
    $var_smarty->cache = $_caching;
    // set cache back to original value
    $vars = '';
    check_actions('do_sidebar', $vars);
    return $var_smarty;
}
Пример #3
0
function tree_to_array($root, $table, $showRoot = TRUE)
{
    // showRoot -- Do we want to include the "root" category named "all" in our results -- all subcats WILL appear regardless
    global $db;
    $row = get_cached_category_data('category__auto_id', $root);
    if (!$row) {
        $sqlfix = "UPDATE " . table_categories . " SET `category__auto_id` = '0' WHERE `category_name` = 'all' LIMIT 1;";
        $db->query($sqlfix);
        $row = $db->get_row($sql);
        if (!$row) {
            die('There is a problem with the categories table. Error CA:001.');
        }
    }
    $right = array();
    $result = get_cached_between($row->lft, $row->rgt);
    $i = 0;
    $lastspacer = 0;
    // added @ thanks to `parterburn` - http://www.pligg.com/forum/showthread.php?t=4888
    foreach ($result as $row) {
        if (count($right) > 0) {
            // check if we should remove a node from the stack
            while ($right[count($right) - 1] < $row->rgt) {
                if (array_pop($right) == NULL) {
                    break;
                    // We've reached the top of the category chain
                }
            }
        }
        $array[$i]['principlecat'] = $row->rgt - $row->lft - 1;
        $array[$i]['spacercount'] = count($right);
        $array[$i]['lastspacercount'] = $lastspacer;
        $array[$i]['spacerdiff'] = abs($lastspacer - count($right));
        $array[$i]['id'] = $row->category_id;
        $array[$i]['auto_id'] = $row->category__auto_id;
        $array[$i]['name'] = $row->category_name;
        $array[$i]['safename'] = $row->category_safe_name;
        $array[$i]['order'] = $row->category_order;
        $array[$i]['left'] = $row->lft;
        $array[$i]['right'] = $row->rgt;
        $array[$i]['leftrightdiff'] = $row->rgt - $row->lft;
        $array[$i]['authorlevel'] = $row->category_author_level;
        // DB 11/12/08
        $array[$i]['authorgroup'] = $row->category_author_group;
        /////
        if (isset($row->category_color)) {
            $array[$i]['color'] = $row->category_color;
        }
        if (isset($row->category_parent)) {
            $array[$i]['parent'] = $row->category_parent;
            $array[$i]['parent_name'] = GetCatName($row->category_parent);
            $array[$i]['parent_subcat_count'] = GetSubCatCount($row->category_parent);
        }
        $array[$i]['subcat_count'] = GetSubCatCount($row->category__auto_id);
        $lastspacer = count($right);
        $right[] = $row->rgt;
        if ($array[$i]['leftrightdiff'] != 1) {
            for ($j = 0; $j <= $array[$i]['leftrightdiff']; $j++) {
                $array[$i]['subcatalign'] = 1;
            }
        }
        $i++;
    }
    if ($showRoot == FALSE) {
        array_splice($array, 0, 1);
    }
    return $array;
}
Пример #4
0
function tree_to_array($root, $table, $showRoot = TRUE)
{
    // showRoot -- Do we want to include the "root" category named "all" in our results -- all subcats WILL appear regardless
    global $db, $cached_categories;
    $row = get_cached_category_data('category__auto_id', $root);
    if (!$row) {
        $sqlfix = "UPDATE " . table_categories . " SET `category__auto_id` = '0' WHERE `category_name` = 'all' LIMIT 1;";
        $db->query($sqlfix);
        $cached_categories = loadCategoriesForCache();
        $row = get_cached_category_data('category__auto_id', $root);
        if (!$row) {
            die('There is a problem with the categories table. Error CA:001.');
        }
    }
    $right = array();
    $left = array();
    $result = get_cached_between($row->lft, $row->rgt);
    $i = 0;
    $lastspacer = 0;
    foreach ($result as $row) {
        if (count($right) > 0) {
            // check if we should remove a node from the stack
            while ($right[count($right) - 1] < $row->rgt) {
                array_pop($left);
                if (array_pop($right) == NULL) {
                    break;
                    // We've reached the top of the category chain
                }
            }
        }
        $array[$i]['first'] = $row->lft - 1 == $left[sizeof($left) - 1];
        $array[$i]['last'] = $row->rgt + 1 == $right[sizeof($right) - 1];
        $array[$i]['principlecat'] = $row->rgt - $row->lft - 1;
        $array[$i]['spacercount'] = count($right);
        $array[$i]['lastspacercount'] = $lastspacer;
        $array[$i]['spacerdiff'] = abs($lastspacer - count($right));
        $array[$i]['id'] = $row->category_id;
        $array[$i]['auto_id'] = $row->category__auto_id;
        $array[$i]['name'] = $row->category_name;
        $array[$i]['safename'] = $row->category_safe_name;
        $array[$i]['order'] = $row->category_order;
        $array[$i]['left'] = $row->lft;
        $array[$i]['right'] = $row->rgt;
        $array[$i]['leftrightdiff'] = $row->rgt - $row->lft;
        $array[$i]['authorlevel'] = $row->category_author_level;
        $array[$i]['authorgroup'] = $row->category_author_group;
        $array[$i]['votes'] = $row->category_votes;
        $array[$i]['karma'] = $row->category_karma;
        $array[$i]['description'] = $row->category_desc;
        $array[$i]['keywords'] = $row->category_keywords;
        if (isset($row->category_color)) {
            $array[$i]['color'] = $row->category_color;
        }
        if (isset($row->category_parent)) {
            $array[$i]['parent'] = $row->category_parent;
            $array[$i]['parent_name'] = GetCatName($row->category_parent);
            $array[$i]['parent_subcat_count'] = GetSubCatCount($row->category_parent);
        }
        $array[$i]['subcat_count'] = GetSubCatCount($row->category__auto_id);
        $lastspacer = count($right);
        $right[] = $row->rgt;
        $left[] = $row->lft;
        if ($array[$i]['leftrightdiff'] != 1) {
            for ($j = 0; $j <= $array[$i]['leftrightdiff']; $j++) {
                $array[$i]['subcatalign'] = 1;
            }
        }
        $i++;
    }
    if ($showRoot == FALSE) {
        array_splice($array, 0, 1);
    }
    return $array;
}