//----------------------------------------------------------------------
// Just like [[livearchive_live]], just add the count of entries of each category
// Usage: [[livearchive_live_ex]]
// Author: ch.linghu
//----------------------------------------------------------------------
function snippet_livearchive_list_ex ($filename="", $format="", $weblog="", $template="") {
global $Weblogs, $Current_weblog, $Cfg, $Paths, $allcats;
if ($filename == "") { $filename = $Paths['pivot_url']."archive.php"; }
if ($format == "") {
$format = "%cat% (%entriescount%)
";
}
$allcats = cfg_cats();
if ($weblog == "current") {
$cats = find_cats_in_weblog($Current_weblog);
$weblog = $Current_weblog;
} else if ( ($weblog != "") && (isset($Weblogs[$weblog])) ) {
$cats = find_cats_in_weblog($weblog);
} else {
// use all cats..
$cats = cfg_getarray('cats');
}
#---------------by ch.linghu: Count the entries in category
$myDb = new db();
$entries_array = $myDb->getlist_range("0000-00-00-00-00", "2099-01-01-00-00","","", FALSE);
#---------------
usort($cats, "category_simplesort");
foreach ($cats as $cat) {
// skip cat if it's 'not-public'.
if ($allcats[$cat]['hidden'] == 1) { continue; }
// skip if name is empty
if ($cat == "") { continue; }
// skip cat if it doesn't exist anymore
if (!isset($allcats[$cat])) { continue; }
#----------------by ch.linghu: Count the entries in category
$entries_count=0;
$temp="";
foreach($entries_array as $entry)
{
// Only list published entries, not timed posts or held entreis
if (strcmp($entry['status'], 'publish') != 0)
continue; // skip to next entry
// Only consider entries posted to the requested category
if (in_array($cat, $entry['category']))
$entries_count++;
}
#------------------
$my_output = $format;
$my_output = str_replace('%file%', $filename, $my_output);
$my_output = str_replace('%catid%', para_category($cat), $my_output);
$my_output = str_replace('%cat%', encode_text($cat), $my_output);
$my_output = str_replace('%weblogid%', para_weblog($weblog), $my_output);
$my_output = str_replace('%weblog%', $Weblogs[$weblog]['name'], $my_output);
$my_output = str_replace('%template%', $template, $my_output);
$my_output = str_replace('%entriescount%', $entries_count, $my_output);
$output .= $my_output;
}
return $output;
}
?>