=====Linkcount Action===== Count (and display) the number of Wikka-formatted links (##""[[http:...]]""##) in a page. Needs some optimization work. **actions/linkcount.php** %%(php) * @copyright Copyright (c) 2006, Brian Koontz * @name LinkcountAction * @package Actions * @license http://www.gnu.org/copyleft/gpl.html * @since Wikka 1.1.7 * @uses /actions/linkcount.php * @version $Id: linkcount.php,v 1.1.1.1 2006/10/07 16:30:42 brian Exp brian $ * */ // Necessary to prevent "already defined" errors when the Wikka parser // comes across a "start" or "stop" action tag include_once("actions/linkcount.inc.php"); if(!isset($vars['preformatted'])) { return; } $preformatted = $this->htmlspecialchars_ent($vars['preformatted']); $pretext = $this->htmlspecialchars_ent($vars['pretext']); $posttext = $this->htmlspecialchars_ent($vars['posttext']); if( isset($pretext) || isset($posttext)) { $pretext ? 1 : $pretext = ''; $posttext ? 1 : $posttext = ''; } else if(isset($preformatted)) { $pretext = "+++Link count: "; $posttext = " link(s)+++"; } $body = explode("\n", $this->page['body']); parse($body, $pretext, $posttext); ?> %% **actions/linkcount.inc.php** %%(php) * @copyright Copyright (c) 2006, Brian Koontz * @name LinkcountAction * @package Actions * @license http://www.gnu.org/copyleft/gpl.html * @since Wikka 1.1.7 * @uses /actions/linkcount.inc.php * @version $Id: linkcount.inc.php,v 1.1.1.1 2006/10/07 16:32:17 brian Exp brian $ * */ function parse(&$body, $pretext, $posttext) { $linkcount = 0; if(!$body) { return; } $state = null; #null, start foreach($body as $line) { switch($state) { case null: if(preg_match('/\{\{linkcount[\s]+start.*\}\}/', $line)) { $state = 'start'; } break; case 'start': if (preg_match('/\{\{linkcount[\s]+stop.*\}\}/', $line)) { $state = null; } elseif (preg_match('/\[\[http:.*\]\]/', $line)) { $linkcount++; } break; } } echo $pretext.$linkcount.$posttext; } ?> %% ---- CategoryUserContributions