/** * function get_subcategory_data() * * Get a hierarchical list of categories * * @param integer $parent * @param string $ident * */ function get_subcategory_data($parent, $ident = '') { global $CONFIG, $CAT_LIST; if ($CONFIG['categories_alpha_sort'] == 1) { $sort_query = 'name'; } else { $sort_query = 'pos'; } $sql = "SELECT cid, name, description " . "FROM {$CONFIG['TABLE_CATEGORIES']} " . "WHERE parent = '{$parent}' " . "ORDER BY {$sort_query}"; $result = cpg_db_query($sql); if (($cat_count = mysql_num_rows($result)) > 0) { $rowset = cpg_db_fetch_rowset($result); $pos = 0; foreach ($rowset as $subcat) { if ($pos > 0) { $CAT_LIST[$subcat['cid']] = array('cid' => $subcat['cid'], 'parent' => $parent, 'pos' => $pos++, 'prev' => $prev_cid, 'cat_count' => $cat_count, 'name' => $ident . $subcat['name']); $CAT_LIST[$last_index]['next'] = $subcat['cid']; } else { $CAT_LIST[$subcat['cid']] = array('cid' => $subcat['cid'], 'parent' => $parent, 'pos' => $pos++, 'cat_count' => $cat_count, 'name' => $ident . $subcat['name']); } $last_index = $prev_cid = $subcat['cid']; // $last_index = count($CAT_LIST) -1; get_subcategory_data($subcat['cid'], $ident . ' '); // Note: API category list depends on these 's } } }
/** * function api_cat_list() * * Geta hierarchical list of categories, in XML * */ function api_cat_list() { global $CONFIG, $CAT_LIST; $superCage = Inspekt::makeSuperCage(); $cat = 0; if ($superCage->post->getInt('catid')) { $cat = $superCage->post->getInt('catid'); } get_subcategory_data($cat); echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"; echo "<cat_list>\n"; $catlevels = array(); // Loop through the category list and store the parent of each one in an array foreach ($CAT_LIST as $category) { // get_subcategory_data() prints ' ' three times for each level of depth of categories $catlevels[] = substr_count($category['name'], 'nbsp;') / 3; } // Loop through again, printing out the list of categories $count = 0; // The iteration of the loop $level = 0; // How many levels deep in the hierarchy a category is $indent2 = ''; // The spacing for closing tags foreach ($CAT_LIST as $category) { $level = $catlevels[$count]; $indent = ''; for ($i = 0; $i < $level; $i++) { $indent .= ' '; } $previous = $catlevels[$count - 1]; $current = $catlevels[$count]; if ($previous == $current && $count > 0) { $indent2 = substr($indent2, 1); // 1 less leading space for each closing tag in a series echo $indent2 . "</category>\n"; } else { if ($previous > $current) { for ($j = 0; $j <= $previous - $current; $j++) { $indent2 = substr($indent2, 1); echo $indent2 . "</category>\n"; } } } $name = preg_replace("/(( ){3})+/", "", $category['name']); // Clean up the name text echo $indent . '<category id="' . $category['cid'] . "\" name=\"" . $name . "\">\n"; $indent2 .= ' '; // 1 more leading space for each <category> element $count++; } // The final (set of) closing tag(s) if ($count > 0) { for ($i = 0; $i <= $level; $i++) { $indent2 = substr($indent2, 1); echo $indent2 . "</category>\n"; } } echo "</cat_list>"; }
cpg_die(ERROR, $lang_catmgr_php['usergal_cat_ro'], __FILE__, __LINE__); } if (!mysql_num_rows($result)) { cpg_die(ERROR, $lang_catmgr_php['unknown_cat'], __FILE__, __LINE__); } $del_category = mysql_fetch_array($result); $parent = $del_category['parent']; $result = cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET parent='{$parent}' WHERE parent = '{$cid}'"); $result = cpg_db_query("UPDATE {$CONFIG['TABLE_ALBUMS']} SET category='{$parent}' WHERE category = '{$cid}'"); $result = cpg_db_query("DELETE FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid='{$cid}' LIMIT 1"); //delete from categorymap cpg_db_query("DELETE FROM {$CONFIG['TABLE_CATMAP']} WHERE cid='{$cid}'"); break; } fix_cat_table(); get_subcategory_data(0); if ($CONFIG['categories_alpha_sort'] != 1) { update_cat_order(); } pageheader($lang_catmgr_php['manage_cat']); echo <<<EOT <script language="javascript" type="text/javascript"> function confirmDel(catName) { return confirm("{$lang_catmgr_php['confirm_delete']} (" + catName + ") ?"); } function build(target, category){ if (target.length > 1) return;