:name:SORT_DESC,no]] * * * * The first argument is a string where: * * %A% is * * %name% is the category name * * %a% is * * if the string is "- %A%%name%a% (%entriescount%)
" the result is: * * - category1 (4) * * - category2 (2) * * - category3 (6) * * all categoryN will be links and the number in the () is the number of * * the entries in each category * * * * The second argument can be "name" or "entriescount" and selects the * * column on which the order is based * * * * The third argument tells how to sort the column selected before. It can * * be "SORT_DESC" or "SORT_ASC". * * * * The last argument is not yet implemented * *************************************************************************** *************************************************************************** * File: snippet_categorylist.php * * Version: 2005-04-11 * *************************************************************************** * This is the main file. * *************************************************************************** */ if(!defined('INPIVOT')){ exit('not in pivot'); } // do not access this page directly /* * function: unhtmlspecialchars($string) * args: * $string: input string * * has the same funciton of html_entity_decode() */ if ((!function_exists("unhtmlspecialchars")) && (!function_exists("html_entity_decode"))) { function unhtmlspecialchars($string) { $string = str_replace ( '&', '&', $string ); $string = str_replace ( ''', '\'', $string ); $string = str_replace ( '"', '\"', $string ); $string = str_replace ( '<', '<', $string ); $string = str_replace ( '>', '>', $string ); return $string; } } /* * function: snippet_categorieslist_get_category_home($list_entries, $category) * args: * $list_entries: the list of all the entries * $category: the category * * This function checks if exists an entry that has the title equal to $category * if so, returns the code (id) of the entry */ function snippet_categorieslist_get_category_home($list_entries, $category) { $category = strtolower($category); $max = count ($list_entries); for ($i=0;$i<$max;$i++) { $title = strtolower($list_entries[$i]['title']); $title = strtolower($title); if ($title == $category) return $list_entries[$i]['code']; } return false; } /* * function snippet_categorieslist * args: * $string: this sets the format of the output rows. ie: %title% - %user% (%commcount%) %date% * $orderby: name, entriescount * $orderhow: can be SORT_DESC, SORT_ASC * * this is the main function */ function snippet_categorieslist($string="", $orderby="", $orderhow = "", $table = "") { global $Paths; $string = trim($string); $orderby = trim($orderby); $orderhow = trim($orderhow); $table = trim($table); if ($string == "") $string = "%A%%name%%a%
"; if ($orderby == "") $orderby = "name"; if ($orderhow == "") $orderhow = "SORT_ASC"; if ($table == "") $table = "no"; $number_of_entries = array(); $not_valid_categories[] = "default"; $not_valid_categories[] = "linkdump"; $to_return = ""; $valid_categories = array(); $categories_home = array(); $db = new db(); // create a new database $list_entries = $db->getlist_range("1970-01-01-00-00", "2020-12-31-23-59","","", FALSE); // Gets all entries // populate $valid_entries $max_entries = count($list_entries); for ($i=0;$i<$max_entries;$i++) { $current_entry = $list_entries[$i]; $max_categories = count($current_entry['category']); for ($j=0;$j<$max_categories;$j++) { $current_category = $current_entry['category'][$j]; $number_of_entries[$current_category]++; if (!in_array($current_category,$valid_categories)) $valid_categories[] = $current_category; } } if ($orderby == "entriescount") { if ($orderhow == "SORT_DESC") $orderhow = SORT_DESC; if ($orderhow == "SORT_ASC") $orderhow = SORT_ASC; array_multisort($number_of_entries, $orderhow, $valid_categories); } if ($orderby == "name") { if ($orderhow == "SORT_DESC") rsort ($valid_categories);; if ($orderhow == "SORT_ASC") sort ($valid_categories);; reset ($valid_catogories); } $max = count ($valid_categories); for ($i=0;$i<$max;$i++) { $current_category = $valid_categories[$i]; if ($id = snippet_categorieslist_get_category_home($list_entries, $current_category)) $array[$current_category] = $id; } $link = $Paths['host'].$Paths['pivot_url']."entry.php"; // http://www.site.com/weblog/pivot/entry.php $sub_input = array(); $sub_input[] = "%name%"; $sub_input[] = "%entriescount%"; $sub_input[] = "%A%"; $sub_input[] = "%a%"; // create the html code to be returned $max = count($valid_categories); for ($i=0;$i<$max;$i++) { $current_category = $valid_categories[$i]; if (in_array($current_category,$not_valid_categories)) continue; // if it is on the not_valid array if (!isset($array[$current_category])) continue; // if it has no entry association $code = $array[$current_category]; $sub_output = array(); $sub_output[] = ucfirst($current_category); $sub_output[] = $number_of_entries[$current_category]; $sub_output[] = ""; $sub_output[] = ""; $string_2 = str_replace($sub_input,$sub_output,$string); if (function_exists("html_entity_decode")) $string_2 = html_entity_decode($string_2); else $string_2 = unhtmlspecialchars($string_2); $to_return .= $string_2."\n"; } // return the code return $to_return; } ?>