www-apps/pmwiki - cookbook - rssfeeddisplay, minor fixes in other recipes
[anomen-overlay.git] / www-apps / pmwiki / cookbook / CachedNumberOfArticles / noa.php
blobb4dc3d2c98951b1f308339ed9cd95726bd5ec706
1 <?php if (!defined('PmWiki')) exit();
3 /*
4 CachedNumberOfArticles script adds support for printing number of pages in wiki
5 - add (:numberofarticles:) tag functionality
6 - this version uses WikiDir->ls() to obtin number of articles
8 Copyright 2006-2011 Anomen (ludek_h@seznam.cz)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published
11 by the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
15 $RecipeInfo['CachedNumberOfArticles']['Version'] = '2011-10-13';
17 Markup('numberofarticles','inline','/\(:numberofarticles(\s+refresh)?\s*:\)/e',
18 "Keep(getNumArticles('$1'))");
20 $NOAFile = "$WorkDir/.noa";
22 function refreshNumArticles()
24 global $NOAFile;
25 global $WikiDir;
27 $count = count($WikiDir->ls());
29 $f = fopen($NOAFile, 'w');
30 fwrite($f, $count);
31 fclose($f);
33 return "<!--fresh-->$count\n";
36 function getNumArticles($refresh)
38 global $NOAFile;
39 $content = array();
41 if (!empty($refresh)) {
42 return refreshNumArticles();
44 } else if (FALSE === ($content = @file($NOAFile))) {
45 return refreshNumArticles();
47 } else {
48 return implode('', $content);