I'm using the "numberof" plugin right now. It is excellent bar one small issue.
When the number of pages in a given section is 0, it does not output.
This means a sentence which in markdown reads
This section has {{NUMBEROFPAGES>:this_section}} pages
If there were six pages then it would read
This section has 6 pages
If there were no pages then it would read
This section has pages
The plugin is only 40 lines long and it is my guess that when searching for pages to populate the array, if no pages are found then the array is empty and nothing gets outputted.
If I knew what I was doing I'm sure I could just pop an if statement somewhere to make it output 0 when the array is empty.
Any suggestions on how to overcome this problem would be greatly appreciated :-)
This is the numberofplugin php page which is the only functional file in the plugin.
<?php
/**
* DokuWiki Plugin numberof (Syntax Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author S.C. Yoo <dryoo@live.com>
*/
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
class syntax_plugin_numberof extends DokuWiki_Syntax_Plugin {
public function getType() { return 'substition'; }
public function getSort() { return 32; }
public function connectTo($mode) {
$this->Lexer->addSpecialPattern('\{\{NUMBEROF[^\}]*\}\}',$mode,'plugin_numberof');
}
public function handle($match, $state, $pos, Doku_Handler $handler){
global $conf;
$list = array();
$data=0;
$match=substr($match,10,-2);
$matches=explode(">",$match);
$matches[1]=str_replace(":","/",$matches[1]);
switch ($matches[0]) {
case "PAGES":
search($list,$conf['datadir'].$matches[1],array($this,'_search_count'),array('all'=>false),'');
$data = $list['file_count'];
break;
case "MEDIAS":
search($list,$conf['mediadir'].$matches[1],array($this,'_search_count'),array('all'=>true));
$data = $list['file_count'];
break;
}
return $data;
}
public function render($mode, Doku_Renderer $renderer, $data) {
if($mode != 'xhtml') return false;
$renderer->doc.= $data;
return true;
}
function _search_count(&$data,$base,$file,$type,$lvl,$opts){
if($type == 'd'){
if($data['dir_nest'] < $lvl) $data['dir_nest'] = $lvl;
$data['dir_count']++;
return true;
}
if($opts['all'] || substr($file,-4) == '.txt'){
$data['file_count']++;
}
return false;
}
}
// vim:ts=4:sw=4:et: