function clearCatCache() { global $db, $cached_categories; $db->cache_dir = mnmpath . 'cache'; $db->use_disk_cache = true; $db->cache_queries = true; $db->cache_timeout = 0; $cached_categories = loadCategoriesForCache(true); $db->cache_queries = false; }
include_once mnminclude . 'define_tables.php'; // // start summarization and caching of mysql data // // added to replace 55 redundant queries with 1 // used with the following functions in /lib/link.php // function category_name() { // function category_safe_name() { // cache the data if caching is enabled if (caching == 1) { $db->cache_dir = mnmpath . 'cache'; $db->use_disk_cache = true; $db->cache_queries = true; } // if this query changes, be sure to change the 'clear the cache' code in admin_categories.php $the_cats = loadCategoriesForCache(); $cached_categories = $the_cats; $db->cache_queries = false; // a simple cache type system for the users table // used in the read() function of /libs/user.php $cached_users = array(); // a simple cache type system for the totals table // functions related to this are in /libs/html1.php $cached_totals = array(); $cached_votes = array(); $cached_links = array(); $cached_comments = array(); $cached_saved_links = array(); // // end summarization and caching of mysql data //
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; }