1<?php
2/**
3 * OrphansWanted Plugin: Display Orphans, Wanteds and Valid link information
4 *
5 * syntax ~~ORPHANSWANTED:<choice>[@<include list>][!<exclude list>]~~  <choice> :: orphans | wanted | valid | all
6 * [@<include list>] :: optional.  prefix each with @ e.g., @wiki@comments:currentyear (defaults to all namespaces if not specified)
7 * [!<exclude list>] :: optional.  prefix each with ! e.g., !wiki!comments:currentyear
8 *
9 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
10 * @author     <dae@douglasedmunds.com>
11 * @author     Andy Webber <dokuwiki at andywebber dot com>
12 * @author     Federico Ariel Castagnini
13 * @author     Cyrille37 <cyrille37@gmail.com>
14 * @author     Rik Blok <rik dot blok at ubc dot ca>
15 * @author     Christian Paul <christian at chrpaul dot de>
16 */
17
18if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
19if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
20
21/**
22 * All DokuWiki plugins to extend the parser/rendering mechanism
23 * need to inherit from this class
24 */
25class syntax_plugin_orphanswanted extends DokuWiki_Syntax_Plugin {
26
27    /**
28     * What kind of syntax are we?
29     */
30    function getType(){
31        return 'substition';
32    }
33
34    /**
35     * What about paragraphs?
36     */
37    function getPType(){
38        return 'normal';
39    }
40
41    /**
42     * Where to sort in?
43     */
44    function getSort(){
45        return 990;     // was 990
46    }
47
48
49    /**
50     * Connect pattern to lexer
51     */
52    function connectTo($mode) {
53        $this->Lexer->addSpecialPattern('~~ORPHANSWANTED:[\w:@!-]+~~', $mode, 'plugin_orphanswanted');
54    }
55
56    /**
57     * Handle the match
58     */
59    function handle($match, $state, $pos, Doku_Handler $handler){
60        $match_array = array();
61        $match = substr($match,16,-2); //strip ~~ORPHANSWANTED: from start and ~~ from end
62
63        // Wolfgang 2007-08-29 suggests commenting out the next line
64        // $match = strtolower($match);
65        //create array, using ! as separator
66        // eg: $match = 'all@includens!excludens'
67        $match_in = explode("@", $match);						// eg: $match_array = array();							$match_in = array('all', 'includens!excludens')
68        $match_ex = explode("!",array_pop($match_in));	// eg: $match_array = array();							$match_in = array('all');							$match_ex = array('includens', 'excludens')
69        array_push($match_in,array_shift($match_ex));		// eg: $match_array = array();							$match_in = array('all', 'includens');				$match_ex = array('excludens')
70        $match_array[0] = array_shift($match_in);			// eg: $match_array = array('all');					$match_in = array('includens');					$match_ex = array('excludens')
71        $match_array[1] = $match_in;								// eg: $match_array = array('all', array('includens'));														$match_ex = array('excludens')
72        $match_array[2] = $match_ex;								// eg: $match_array = array('all', array('includens'), array('excludens'))
73
74        // $match_array[0] will be orphan, wanted, valid, all, or syntax error
75        // if there are excluded namespaces, they will be in $match_array[1] .. [x]
76        // this return value appears in render() as the $data param there
77
78        return $match_array;
79    }
80
81    /**
82     * Create output
83     */
84    function render($format, Doku_Renderer $renderer, $data) {
85        global $INFO, $conf;
86        $helper = plugin_load('helper','orphanswanted');
87
88        if($format == 'xhtml') {
89            // prevent caching to ensure content is always fresh
90            $renderer->info['cache'] = false;
91
92            // $data is an array
93            // $data[1]..[x] are excluded namespaces, $data[0] is the report type
94            //handle choices
95
96            switch ($data[0]) {
97                case 'orphans':
98                    $renderer->doc .= $helper->orphan_pages($data);
99                    break;
100                case 'wanted':
101                    $renderer->doc .= $helper->wanted_pages($data);
102                    break;
103                case 'valid':
104                    $renderer->doc .= $helper->valid_pages($data);
105                    break;
106                case 'all':
107                    $renderer->doc .= $helper->all_pages($data);
108                    break;
109                default:
110                    $renderer->doc .= "ORPHANSWANTED syntax error";
111            }
112            return true;
113        }
114
115        return false;
116    }
117}
118
119//Setup VIM: ex: et ts=4 enc=utf-8 :
120