1<?php
2
3
4// must be run within Dokuwiki
5if(!defined('DOKU_INC')) die();
6
7if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
8require_once DOKU_PLUGIN.'syntax.php';
9
10
11class syntax_plugin_credits extends DokuWiki_Syntax_Plugin {
12    var $plugins = array();
13    var $types = array('admin','helper','syntax','action','renderer');
14    var $keys;
15    var $show_descriptions = true;
16
17    function getType(){ return 'substition'; }
18    function getAllowedTypes() { return array(); }
19    function getSort(){ return 100; }
20
21    function connectTo($mode) {
22         $this->Lexer->addSpecialPattern('<<CREDITS:.*?>>',$mode,'plugin_credits'); }
23
24    function handle($match, $state, $pos, Doku_Handler $handler) {
25             preg_match('/<<CREDITS:(.*?)>>/', $match,$matches);
26
27             return array( $state, $matches[1]);
28   }
29
30
31  /**
32     * Create output
33     */
34    function render($mode, Doku_Renderer $renderer, $data) {
35        if($mode == 'xhtml'){
36            $this->get_plugin_array();
37            list($state, $match) = $data;
38            $match = trim($match);
39            if($match && function_exists($match)) {
40                $match($renderer,$this->plugins);
41            }
42            else {
43                 if($match == '~nodesc~') {
44                    $this->show_descriptions = false;
45                 }
46                 $this->_page($renderer);
47            }
48            return true;
49         }
50
51
52        return false;
53    }
54/*
55'text_weight'=> 'bold'
56'email_text_size'=> '90%'
57'font_family' sans-serif
58'text_size' 90%
59*/
60  function _get_configs($which) {
61    global $conf;
62    $settings = array(
63           'background_color'=>'#FFDD99', 'pop_up_color'=>'#006600', 'pop_up_weight'=>'normal',
64            'text_weight'=> 'bold','email_text_size'=> '95%','text_size'=>'90%',
65             'font_family'=>'Verdana,"Lucida Grande",Lucida,Helvetica,Arial,sans-serif',
66             'email_weight'=>'normal', 'text_color'=>'#333333', 'line_height'=>'1.25',
67             'pop_up_family' =>'Helvetica,Arial,sans-serif', 'title_string' => '<h3>Plugins</h3>',
68              'subtitle_string'=>'<b style="font-size: 125%; color:black;">Credits</b>',
69              'do_desc' => true
70            );
71    if(isset ($conf['plugin']['credits'][$which]))
72           return($conf['plugin']['credits'][$which]);
73    else  return $settings[$which];
74  }
75
76  function mouseover() {
77  $bgcolor = $this->_get_configs('background_color');
78  $text = $this->_get_configs('pop_up_color');
79  $pop_up_weight = $this->_get_configs('pop_up_weight');
80  $family = $this->_get_configs('pop_up_family');
81  $doc = '<span id="pcredit_mo" ' .
82      ' style="visibility:hidden; position:absolute; background-color: ' . $bgcolor . ';'
83      . ' font-family: ' . $family . ';'
84      . ' color: ' . $text . '; height:1em; padding:4px; white-space:nowrap; '
85      . '  font-weight:' . $pop_up_weight  . '; font-size:85%;">'
86
87  . '</span>';
88
89
90  return $doc . "\n";
91
92
93  }
94
95  function _page(&$renderer) {
96    $text_weight = $this->_get_configs('text_weight');
97    $text_size = $this->_get_configs('text_size');
98    $email_size = $this->_get_configs('email_text_size');
99    $email_weight=$this->_get_configs('email_weight');
100    $line_height=$this->_get_configs('line_height');
101    $text_color=$this->_get_configs('text_color');
102    $family=$this->_get_configs('font_family');
103    $title=$this->_get_configs('title_string');
104    $subtitle=$this->_get_configs('subtitle_string');
105
106    if(!$this->show_descriptions) {
107         $do_description = false;
108    }
109    else {
110       $do_description=$this->_get_configs('do_desc');
111    }
112
113            $renderer->doc .= $this->mouseover($renderer);
114            $renderer->doc .= "<div id='credits_d' style='margin:1em; font-size: $text_size; font-weight:$text_weight; ";
115            $renderer->doc .= "font-family: $family; line-height: $line_height; color: $text_color; '>\n";
116            $renderer->doc .= $title;
117            $renderer->doc .= $subtitle;
118            $renderer->doc .= "<br>";
119
120            $id_count = 0;
121            foreach($this->keys as $name) {
122                  $date = isset($this->plugins[$name]['date'])?$this->plugins[$name]['date']:"" ;
123                  $author = isset($this->plugins[$name]['author'])?$this->plugins[$name]['author']:"" ;
124                  if(!isset($this->plugins[$name]['email'])) {
125                      $this->plugins[$name]['email'] = str_replace(" ", "_",$author) . "@No_Email_Given";
126                  }
127                  if(isset($this->plugins[$name]['email'])) {
128                        $remainder = "";
129                        $desc = "";
130                        if($do_description) {
131                            $desc = $this->plugins[$name]['desc'];
132                        }
133                        if(!empty($desc)) {
134                            $remainder = "<br />";
135                            $remainder_id = "";
136                            if($trunc_array = $this->truncate($desc)) {
137                                 list($trunc, $rest) = $trunc_array;
138                                 $id_count++;
139                                 $remainder_id = 'remainderid_' . $id_count;
140                                 $trunc = "$trunc <a href='javascript:void 0;' "
141                                        . " onmouseout='hide_remainder(\"$remainder_id\");' "
142                                        . " onmouseover='show_remainder(\"$remainder_id\");' >"
143                                        . '&nbsp;&nbsp;->&nbsp;&nbsp;&nbsp;</a>';
144                                 $remainder = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span id = '$remainder_id' "
145                                     . "style='font-size: 90%; color: #436976;font-weight:$text_weight; font-style:normal; "
146                                     . " display:none;'>"
147                                      . $rest . '</span><br />';
148                                 $desc = $trunc;
149                            }
150                        }
151
152                        $address =credits_hide_email($this->plugins[$name]['email']);
153                        $email = "&nbsp;&nbsp;<a href='mailto:$address' "
154                        . " style='font-size: $email_size; font-weight:$email_weight;  '"
155                        . " onmouseover= 'pcredits_mouseover(event, \"${date}\", \"$remainder_id\");' "
156                        . " onmouseout= 'pcredits_mouseout(\"$remainder_id\");' "
157                        . ">$author</a>\n";
158                  }
159                  $renderer->doc .= "$name $email<br />";
160                  if(!empty($remainder)) {
161                      $renderer->doc .= "&nbsp;&nbsp;&nbsp;&nbsp;";
162                  }
163                  $renderer->doc .= "<span>$desc</span>$remainder";
164            }
165           $renderer->doc .= '</div>';
166  }
167
168  function get_plugin_array() {
169       foreach($this->types as $type) {
170           $this->store_plugins($type);
171       }
172       $this->keys = array_keys($this->plugins);
173       natcasesort($this->keys);
174  }
175
176    function store_plugins($type=""){
177        if(!$type) return;
178        $plugins = plugin_list($type);
179        foreach($plugins as $p){
180            if (!$po = plugin_load($type,$p)) continue;
181            if(!method_exists($po,'getInfo')) continue;
182            $info = $po->getInfo();
183            $this->plugins[$info['name']] = $info;
184            unset($po);
185        }
186
187
188    }
189
190    function truncate($str, $len=50) {
191        $strL = strlen($str);
192        if($strL > $len) {
193           $trunc = substr($str,0,$len);
194
195           $remainder = substr($str,$len);
196           if(strlen($remainder) < 30) {
197                  return false;
198           }
199           return(array($trunc,$remainder));
200        }
201        return false;
202    }
203}
204
205function credits_hide_email($email) {
206      $encode = '';
207      for ($x=0; $x < strlen($email); $x++) $encode .= '&#x' . bin2hex($email{$x}).';';
208      return $encode;
209}
210
211function alt_credits(&$renderer,$info) {
212
213  foreach($info as $plugin=>$items) {
214       $renderer->doc .= "$plugin<br />";
215       foreach($items as $name=>$value) {
216         if($name == 'email') $value = credits_hide_email($value);
217         $renderer->doc .= "$name: $value<br />";
218       }
219       $renderer->doc .= '<br />';
220  }
221
222}
223