1<?php
2    /**
3     *  newfeed plugin
4     * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
5     */
6
7    // must be run within DokuWiki
8    if(!defined('DOKU_INC')) die();
9
10    if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
11    require_once(DOKU_PLUGIN.'syntax.php');
12
13
14
15    /**
16     * All DokuWiki plugins to extend the parser/rendering mechanism
17     * need to inherit from this class
18     */
19    class syntax_plugin_news_button extends DokuWiki_Syntax_Plugin {
20        var $helper;
21
22	    function syntax_plugin_news_feed() {
23		   //$this->helper =& plugin_load('helper', 'news');
24		}
25        /**
26         * return some info
27         */
28        function getInfo(){
29            return array(
30                'author' => 'Myron Turner',
31                'email'  => 'turnermm02@shaw.ca',
32                'date'   => '2011-10-18',
33                'name'   => 'news Plugin',
34                'desc'   => 'creates newsfeed refresh button',
35                'url'    => 'http://www.mturner.org',
36            );
37        }
38
39        function getType(){ return 'substition'; }
40
41		function getSort(){ return 168; }
42
43		function connectTo($mode) {
44		    $this->Lexer->addSpecialPattern('~~NEWS_REFRESH.*?~~',$mode,'plugin_news_button');
45		}
46
47        /**
48         * Handle the match
49         */
50        function handle($match, $state, $pos, Doku_Handler $handler){
51
52	   global $USERINFO;
53	   global $ID;
54	   global $INFO;
55
56      if(!isset($USERINFO)) return false;
57	  if(isset($INFO['perm']) && $INFO['perm'] < 2) return;
58	   $match=substr($match,15,-2);
59      // msg($match);
60       $match = trim($match);
61       if($match) {
62          $title = $match;
63       }
64
65       $action =  DOKU_URL . 'newsfeed.php';
66       $button_name = $this->getLang('btn_generate');
67       $button="<form class='button' method='POST' action='$action '>";
68       $button .= "<div class='no'>";
69       //msg($match);
70       if($match) {
71           $button .= "<input type='hidden' name='title' value='$title' />";
72       }
73       $button .= "<input type='hidden' name='feed' value='refresh' /><input type='hidden' name='feed_ref' value='" . $ID. "' /><input type='submit' value='$button_name' class='button' title='refresh' /></div></form>";
74
75            switch ($state) {
76
77			    case DOKU_LEXER_SPECIAL : return array($state, $button);
78
79            }
80
81            return false;
82        }
83
84        /**
85         * Create output
86         */
87        function render($mode, Doku_Renderer $renderer, $data) {
88
89	    global $USERINFO;
90	    global $INFO;
91
92        if(!isset($USERINFO)) return false;
93        if(isset($INFO['perm']) && $INFO['perm'] < 2) return;
94
95            if($mode == 'xhtml'){
96                list($state, $button) = $data;
97                switch ($state) {
98				  case DOKU_LEXER_SPECIAL :
99				  $renderer->doc .= $button;
100				  return true;
101                }
102            }
103            return false;
104        }
105
106
107
108}
109