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_feed extends DokuWiki_Syntax_Plugin {
20        var $helper;
21		var $is_news_mgr;
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'   => '2010-03-19',
33                'name'   => 'news Plugin',
34                'desc'   => 'identifies newsfeed page',
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('~~NEWSFEED.*?~~',$mode,'plugin_news_feed');
45		}
46
47        /**
48         * Handle the match
49         */
50        function handle($match, $state, $pos, Doku_Handler $handler){
51
52            $match=substr($match,11,-2);
53			if($match) {
54			   $match = trim($match);
55               if(is_numeric($match)) {
56                   $match = array($match);
57               }
58               else if(is_string($match)) {
59                    $match = explode(';;',$match);
60                    if(count($match) == 1) {
61                       array_unshift($match,0);
62                    }
63               }
64
65			}
66            switch ($state) {
67
68			    case DOKU_LEXER_SPECIAL : return array($state, $match);
69
70            }
71
72            return false;
73        }
74
75        /**
76         * Create output
77         */
78        function render($mode, Doku_Renderer $renderer, $data) {
79		if (empty($data)) return false;
80		    global $ID;
81            if($mode == 'xhtml'){
82                if(!$this->is_manager()) {
83                     $this->helper->set_permission(2);
84                     return false;
85               }
86               $this->helper->set_permission(3);
87                list($state, $match) = $data;
88
89                switch ($state) {
90				  case DOKU_LEXER_SPECIAL :
91				  $this->helper->setUpdate($match);
92                  $metafile = $this->helper->getMetaFN('timestamp','.meta') ;
93				  io_saveFile($metafile,time());
94				  $renderer->doc .= "";
95				  break;  ;
96
97                }
98                return true;
99            }
100            return false;
101        }
102
103
104      function is_manager() {
105            global $INFO,$USERINFO;
106
107            if(!isset($USERINFO)) return false;
108            if(!$this->getConf('chkperm')) return true;  //by-pass news permission checks
109
110            $is_news_mgr = false;
111            $news_mgr = $this->getConf('mgr');
112            $admins_only =  $this->getConf('adminsonly');
113
114            if(!$news_mgr && !$admins_only) {
115                   return true;
116            }
117           else  if($INFO['isadmin']  || $INFO['ismanager'] ) {
118                   return true;
119            }
120           if(in_array(trim($news_mgr),$USERINFO['grps']) && !$admins_only) {
121                    return true;
122            }
123
124
125            return false;
126
127
128
129      }
130}
131