diff -Naur -x'*gif' -x'*CVS' -xTreeMenu.js serendipity_plugin_category_dhtml_menu_old/lang_en.inc.php serendipity_plugin_category_dhtml_menu/lang_en.inc.php --- serendipity_plugin_category_dhtml_menu_old/lang_en.inc.php 2005-11-16 11:24:12.000000000 +0000 +++ serendipity_plugin_category_dhtml_menu/lang_en.inc.php 2009-02-27 17:09:02.865415170 +0000 @@ -12,5 +12,6 @@ @define('PLUGIN_DHTMLMENU_PATH_DESC', 'The absolute (URL) path to your images directory'); @define('PLUGIN_DHTMLMENU_JSPATH', 'Path to HTMLTree.js'); @define('PLUGIN_DHTMLMENU_JSPATH_DESC', 'the absolute (url) path to your HTMLTree.js (provided with PEAR::HTML_TreeMenu).'); +@define('PLUGIN_DHTMLMENU_SHOWCOUNT', 'Show number of entries per category?'); ?> diff -Naur -x'*gif' -x'*CVS' -xTreeMenu.js serendipity_plugin_category_dhtml_menu_old/serendipity_plugin_category_dhtml_menu.php serendipity_plugin_category_dhtml_menu/serendipity_plugin_category_dhtml_menu.php --- serendipity_plugin_category_dhtml_menu_old/serendipity_plugin_category_dhtml_menu.php 2009-02-24 13:59:05.000000000 +0000 +++ serendipity_plugin_category_dhtml_menu/serendipity_plugin_category_dhtml_menu.php 2009-02-28 08:38:50.222066338 +0000 @@ -37,7 +37,7 @@ { $propbag->add('name', PLUGIN_DHTMLMENU_NAME); $propbag->add('description', PLUGIN_DHTMLMENU_NAME_DESC); - $propbag->add('configuration', array('title', 'expand_all','image_path','script_path')); + $propbag->add('configuration', array('title', 'expand_all','image_path','script_path','show_count','image')); $propbag->add('requirements', array( 'serendipity' => '0.7', 'smarty' => '2.6.7', @@ -83,6 +83,21 @@ $propbag->add('description', PLUGIN_DHTMLMENU_JSPATH_DESC); $propbag->add('default','plugins/serendipity_plugin_category_dhtml_menu/TreeMenu.js'); break; + + case 'show_count': + $propbag->add('type', 'boolean'); + $propbag->add('name', PLUGIN_DHTMLMENU_SHOWCOUNT); + $propbag->add('description', ''); + $propbag->add('default', false); + break; + + case 'image': + $propbag->add('type', 'string'); + $propbag->add('name', XML_IMAGE_TO_DISPLAY); + $propbag->add('description', XML_IMAGE_TO_DISPLAY_DESC); + $propbag->add('default', serendipity_getTemplateFile('img/xml.gif')); + break; + default: break; } @@ -121,15 +136,52 @@ $categories[$cat['categoryid']] = $cat; } + // create an array of numbers of entries per category + $cat_count = array(); + if (serendipity_db_bool($this->get_config('show_count'))) { + $cat_sql = "SELECT c.categoryid, c.category_name, count(e.id) as postings + FROM {$serendipity['dbPrefix']}entrycat ec, + {$serendipity['dbPrefix']}category c, + {$serendipity['dbPrefix']}entries e + WHERE ec.categoryid = c.categoryid + AND ec.entryid = e.id + AND e.isdraft = 'false' + " . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND e.timestamp <= " . serendipity_db_time() : '') . " + GROUP BY c.categoryid, c.category_name + ORDER BY postings DESC"; + $category_rows = serendipity_db_query($cat_sql); + if (is_array($category_rows)) { + foreach($category_rows AS $cat) { + $cat_count[$cat['categoryid']] = $cat['postings']; + } + } + + } + + $image = $this->get_config('image', serendipity_getTemplateFile('img/xml.gif')); + $image = (($image == "'none'" || $image == 'none') ? '' : $image); + // create nodes - foreach ($categories as $category) { + foreach ($categories as $cid => $cat) { if (function_exists('serendipity_categoryURL')) { - $link = serendipity_categoryURL($category, 'serendipityHTTPPath'); + $link = serendipity_categoryURL($cat, 'serendipityHTTPPath'); } else { - $link = serendipity_rewriteURL(PATH_CATEGORIES . '/' . serendipity_makePermalink(PERM_CATEGORIES, array('id' => $category[0], 'title' => $category[1])), 'serendipityHTTPPath'); + $link = serendipity_rewriteURL(PATH_CATEGORIES . '/' . serendipity_makePermalink(PERM_CATEGORIES, array('id' => $cat['categoryid'], 'title' => $cat['category_name'])), 'serendipityHTTPPath'); } - $cat_nodes[$category['categoryid']] = new HTML_TreeNode(array('text'=>$category[1],'link'=>$link)); + if (!empty($cat_count[$cat['categoryid']])) { + // $categories[$cid]['true_category_name'] = $cat['category_name']; + $cat['category_name'] .= ' (' . $cat_count[$cat['categoryid']] . ')'; + // $categories[$cid]['article_count'] = $cat_count[$cat['categoryid']]; + } + if (!empty($image)) { + $feedURL = serendipity_feedCategoryURL($cat, 'serendipityHTTPPath'); + $feed = 'XML '; + $link = ''.$cat['category_name'].''; + // work around a problem in HTML_TreeNode: when there is a href in 'text', 'link' is not converted to a link. + $cat_nodes[$cat['categoryid']] = new HTML_TreeNode(array('text'=>($feed . $link))); + }else + $cat_nodes[$cat['categoryid']] = new HTML_TreeNode(array('text'=>($feed . $cat['category_name']),'link'=>$link)); }