OSDN Git Service

MERGE: リビジョン1873〜1893。skinnable-masterのマージ
[nucleus-jp/nucleus-next.git] / nucleus / libs / showlist.php
1 <?php
2 /*
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4  * Copyright (C) 2002-2009 The Nucleus Group
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  * (see nucleus/documentation/index.html#license for more info)
11  */
12 /**
13  * Functions to create lists of things inside the admin are
14  *
15  * @license http://nucleuscms.org/license.txt GNU General Public License
16  * @copyright Copyright (C) 2002-2009 The Nucleus Group
17  * @version $Id: showlist.php 1886 2012-06-17 08:27:27Z sakamocchi $
18  */
19
20
21 // can take either an array of objects, or an SQL query
22 function showlist($query, $type, $vars, $template_name = '')
23 {
24         $contents = '';
25         
26         /* count */
27         if ( is_string($query) )
28         {
29                 $resource = DB::getResult($query);
30         }
31         else
32         {
33                 $resource = $query;
34         }
35         
36         /* HEAD */
37         $contents .= call_user_func("listplug_{$type}", $vars, 'HEAD', $template_name);
38         
39         /* BODY */
40         foreach ( $resource as $row )
41         {
42                 $vars['current'] = $row;
43                 $contents .= call_user_func("listplug_{$type}", $vars, 'BODY', $template_name);
44         }
45         
46         /* FOOT */
47         $contents .= call_user_func("listplug_{$type}", $vars, 'FOOT', $template_name);
48         
49         /* close SQL resource */
50         if ( is_string($query) )
51         {
52                 $resource->closeCursor();
53         }
54         
55         return $contents;
56 }
57
58 function listplug_select($vars, $type, $template_name = '')
59 {
60         global $manager;
61         
62         $templates = array();
63         if ( !empty($template_name) )
64         {
65                 $templates =& $manager->getTemplate($template_name);
66         }
67         
68         switch( $type )
69         {
70                 case 'HEAD':
71                         if ( !array_key_exists('SHOWLIST_LISTPLUG_SELECT_HEAD', $templates) || empty($templates['SHOWLIST_LISTPLUG_SELECT_HEAD']) )
72                         {
73                                 $template = "<select name=\"<%name%>\" tabindex=\"<%tabindex%>\" <%javascript%>>\n"
74                                           . "<%extraoption%>\n";
75                         }
76                         else
77                         {
78                                 $template = $templates['SHOWLIST_LISTPLUG_SELECT_HEAD'];
79                         }
80                         $data = array(
81                                 'name'                  => $vars['name'],
82                                 'tabindex'              => $vars['tabindex'],
83                                 'javascript'    => !array_key_exists('javascript', $vars) ? '' : $vars['javascript'],
84                                 'extraoption'   => !array_key_exists('extra', $vars) ? '' : "<option value=\"\">{$vars['extra']}</option>"
85                         );
86                         break;
87                 case 'BODY':
88                         $current = $vars['current'];
89                         if ( !array_key_exists('SHOWLIST_LISTPLUG_SELECT_BODY', $templates) || empty($templates['SHOWLIST_LISTPLUG_SELECT_BODY']) )
90                         {
91                                 $template = "<option value=\"<%value%>\" <%selected%> title=\"<%title%>\"><%option%></option>\n";
92                         }
93                         else
94                         {
95                                 $template = $templates['SHOWLIST_LISTPLUG_SELECT_BODY'];
96                         }
97                         $data = array(
98                                 'value'         => Entity::hsc($current['value']),
99                                 'selected'      => ($vars['selected'] == $current['value']) ? 'selected="selected"' : '',
100                         );
101                         if ( array_key_exists('shorten', $vars) && $vars['shorten'] > 0 )
102                         {
103                                 $data['title'] = Entity::hsc($current['text']);
104                                 $data['option'] = Entity::hsc(Entity::shorten($current['text'], $vars['shorten'], $vars['shortenel']));
105                         }
106                         else
107                         {
108                                 $data['title'] = '';
109                         }
110                         $data['option'] = Entity::hsc($current['text']);
111                         break;
112                 case 'FOOT':
113                         if ( !array_key_exists('SHOWLIST_LISTPLUG_SELECT_FOOT', $templates) || empty($templates['SHOWLIST_LISTPLUG_SELECT_FOOT']) )
114                         {
115                                 $template = "</select>\n";
116                         }
117                         else
118                         {
119                                 $template = $templates['SHOWLIST_LISTPLUG_SELECT_FOOT'];
120                         }
121                         $data = array();
122                         break;
123         }
124         
125         return Template::fill($template, $data);
126 }
127
128 function listplug_table($vars, $type, $template_name = '')
129 {
130         global $manager;
131         
132         $templates = array();
133         if ( !empty($template_name) )
134         {
135                 $templates =& $manager->getTemplate($template_name);
136         }
137         
138         switch( $type )
139         {
140                 case 'HEAD':
141                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_HEAD', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_HEAD']) )
142                         {
143                                 $template = "<table frame=\"box\" rules=\"all\" summary=\"{$vars['content']}\">\n"
144                                           . "<thead>\n"
145                                           . "<tr>\n"
146                                           . "<%typehead%>\n"
147                                           . "</tr>\n"
148                                           . "</thead>\n"
149                                           . "<tbody>\n";
150                         }
151                         else
152                         {
153                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_HEAD'];
154                         }
155                         $data = array(
156                                 'summary'       =>      $vars['content'],
157                                 'typehead' => call_user_func("listplug_table_" . $vars['content'] , $vars, 'HEAD', $template_name)
158                         );
159                         break;
160                 case 'BODY':
161                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_BODY', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_BODY']) )
162                         {
163                                 $template = "<tr onmouseover=\"focusRow(this);\" onmouseout=\"blurRow(this);\">\n"
164                                           . "<%typebody%>\n"
165                                           . "</tr>\n";
166                         }
167                         else
168                         {
169                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_BODY'];
170                         }
171                         // tabletype specific thingies
172                         $data = array(
173                                 'typebody' => call_user_func("listplug_table_" . $vars['content'] , $vars, 'BODY', $template_name)
174                         );
175                         break;
176                 case 'FOOT':
177                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_FOOT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_FOOT']) )
178                         {
179                                 $template = "<%typefoot%>\n"
180                                           . "</tbody>\n"
181                                           . "</table>\n";
182                         }
183                         else
184                         {
185                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_FOOT'];
186                         }
187                         // tabletype specific thingies
188                         $data = array(
189                                 'typefoot' => call_user_func("listplug_table_" . $vars['content'] , $vars, 'FOOT', $template_name)
190                         );
191                         break;
192         }
193         
194         return Template::fill($template, $data);
195 }
196
197 function listplug_table_memberlist($vars, $type, $template_name = '')
198 {
199         global $manager;
200         
201         $templates = array();
202         if ( !empty($template_name) )
203         {
204                 $templates =& $manager->getTemplate($template_name);
205         }
206         
207         switch( $type )
208         {
209                 case 'HEAD':
210                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_MEMBLIST_HEAD', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_MEMBLIST_HEAD']) )
211                         {
212                                 $template = "<th><%colmembername%></th>\n"
213                                           . "<th><%colmemberrname%></th>\n"
214                                           . "<th><%colmemberurl%></th>\n"
215                                           . "<th><%colmemberadmin%><%helplink(superadmin)%></th>\n"
216                                           . "<th><%colmemberlogin%><%helplink(canlogin)%></th>\n"
217                                           . "<th colspan=\"2\"><%colactions%></th>\n";
218                         }
219                         else
220                         {
221                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_MEMBLIST_HEAD'];
222                         }
223                         $data = array(
224                                 'colmembername'         => _LIST_MEMBER_NAME,
225                                 'colmemberrname'        => _LIST_MEMBER_RNAME,
226                                 'colmemberurl'          => _LIST_MEMBER_URL,
227                                 'colmemberadmin'        => _LIST_MEMBER_ADMIN,
228                                 'colmemberlogin'        => _LIST_MEMBER_LOGIN,
229                                 'colactions'            => _LISTS_ACTIONS,
230                         );
231                         break;
232                 case 'BODY':
233                         $current = $vars['current'];
234                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_MEMBLIST_BODY', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_MEMBLIST_BODY']) )
235                         {
236                                 $template = "<td>\n"
237                                           . "<input type=\"checkbox\" id=\"batch<%id%>\" name=\"batch[<%id%>]\" value=\"<%memberid%>\" />\n"
238                                           . "<label for=\"batch<%id%>\">\n"
239                                           . "<a href=\"mailto:<%mailaddress%>\" tabindex=\"<%tabindex%>\"><%name%></a>\n"
240                                           . "</label>\n</td>\n"
241                                           . "<td><%realname%></td>\n"
242                                           . "<td><a href=\"<%url%>\" tabindex=\"<%tabindex%>\"><%url%></a></td>\n"
243                                           . "<td><%admin%></td>\n"
244                                           . "<td><%login%></td>\n"
245                                           . "<td><a href=\"index.php?action=memberedit&amp;memberid=<%memberid%>\" tabindex=\"<%tabindex%>\"><%editbtn%></a></td>\n"
246                                           . "<td><a href=\"index.php?action=memberdelete&amp;memberid=<%memberid%>\" tabindex=\"<%tabindex%>\"><%deletebtn%></a></td>\n";
247                         }
248                         else
249                         {
250                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_MEMBLIST_BODY'];
251                         }
252                         $data = array(
253                                 'id'                    => listplug_nextBatchId(),
254                                 'memberid'              => $current['mnumber'],
255                                 'mailaddress'   => Entity::hsc($current['memail']),
256                                 'tabindex'              => $vars['tabindex'],
257                                 'name'                  => Entity::hsc($current['mname']),
258                                 'realname'              => Entity::hsc($current['mrealname']),
259                                 'url'                   => Entity::hsc($current['murl']),
260                                 'admin'                 => $current['madmin'] ? _YES : _NO,
261                                 'login'                 => $current['mcanlogin'] ? _YES : _NO,
262                                 'editbtn'               => _LISTS_EDIT,
263                                 'deletebtn'             => _LISTS_DELETE,
264                         );
265                         break;
266                 case 'FOOT':
267                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_MEMBLIST_FOOT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_MEMBLIST_FOOT']) )
268                         {
269                                 $template = "";
270                         }
271                         else
272                         {
273                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_MEMBLIST_FOOT'];
274                         }
275                         $data = array();
276                         break;
277         }
278         return Template::fill($template, $data);
279 }
280
281 function listplug_table_teamlist($vars, $type, $template_name = '')
282 {
283         global $manager;
284         
285         $templates = array();
286         if ( !empty($template_name) )
287         {
288                 $templates =& $manager->getTemplate($template_name);
289         }
290         
291         switch( $type )
292         {
293                 case 'HEAD':
294                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_TEAMLIST_HEAD', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_TEAMLIST_HEAD']) )
295                         {
296                                 $template = "<th><%colmembername%></th>\n"
297                                           . "<th><%colmemberrname%></th>\n"
298                                           . "<th><%colteamadmin%><%helplink(teamadmin)%></th>\n"
299                                           . "<th colspan=\"2\"><%colactions%></th>\n";
300                         }
301                         else
302                         {
303                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_TEAMLIST_HEAD'];
304                         }
305                         $data = array(
306                                 'colmembername'         => _LIST_MEMBER_NAME,
307                                 'colmemberrname'        => _LIST_MEMBER_RNAME,
308                                 'colteamadmin'          => _LIST_TEAM_ADMIN,
309                                 'colactions'            => _LISTS_ACTIONS,
310                         );
311                         break;
312                 case 'BODY':
313                         $current = $vars['current'];
314                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_TEAMLIST_BODY', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_TEAMLIST_BODY']) )
315                         {
316                                 $template = "<td>\n"
317                                           . "<input type=\"checkbox\" id=\"batch<%id%>\" name=\"batch[<%id%>]\" value=\"<%memberid%>\" />\n"
318                                           . "<label for=\"batch<%id%>\">\n"
319                                           . "<a href=\"mailto:<%mailaddress%>\" tabindex=\"<%tabindex%>\"><%name%></a>\n"
320                                           . "</label>\n</td>\n"
321                                           . "<td><%realname%></td>\n"
322                                           . "<td><%admin%></td>\n"
323                                           . "<td><a href=\"index.php?action=teamdelete&amp;memberid=<%memberid%>&amp;blogid=<%blogid%>\" tabindex=\"<%tabindex%>\"><%deletebtn%></a></td>\n"
324                                           . "<td><a href=\"<%chadminurl%>\" tabindex=\"<%tabindex%>\"><%chadminbtn%></a></td>\n";
325                         }
326                         else
327                         {
328                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_TEAMLIST_BODY'];
329                         }
330                         $url  = 'index.php?action=teamchangeadmin&memberid=' . intval($current['tmember']) . '&blogid=' . intval($current['tblog']);
331                         $url  = $manager->addTicketToUrl($url);
332                         $data = array(
333                                         'id'                    => listplug_nextBatchId(),
334                                         'memberid'              => $current['tmember'],
335                                         'mailaddress'   => Entity::hsc($current['memail']),
336                                         'tabindex'              => $vars['tabindex'],
337                                         'name'                  => Entity::hsc($current['mname']),
338                                         'realname'              => Entity::hsc($current['mrealname']),
339                                         'admin'                 => ($current['tadmin'] ? _YES : _NO),
340                                         'blogid'                => $current['tblog'],
341                                         'deletebtn'             => '<%text(_LISTS_DELETE)%>',
342                                         'chadminurl'    => Entity::hsc($url),
343                                         'chadminbtn'    => '<%text(_LIST_TEAM_CHADMIN)%>'
344                         );
345                         break;
346                 case 'FOOT':
347                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_TEAMLIST_FOOT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_TEAMLIST_FOOT']) )
348                         {
349                                 $template = "";
350                         }
351                         else
352                         {
353                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_TEAMLIST_FOOT'];
354                         }
355                         $data = array();
356                         break;
357         }
358         return Template::fill($template, $data);
359 }
360
361 function listplug_table_pluginlist($vars, $type, $template_name = '')
362 {
363         static $plugins = array();
364         global $manager;
365         
366         $templates = array();
367         if ( !empty($template_name) )
368         {
369                 $templates =& $manager->getTemplate($template_name);
370         }
371         
372         switch( $type )
373         {
374                 case 'HEAD':
375                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HEAD', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HEAD']) )
376                         {
377                                 $template = "<th><%colinfo%></th>\n"
378                                           . "<th><%coldesc%></th>\n"
379                                           . "<th colspan=\"2\"><%colactions%></th>\n";
380                         }
381                         else
382                         {
383                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HEAD'];
384                         }
385                         $data = array(
386                                 'colinfo'    => _LISTS_INFO,
387                                 'coldesc'    => _LISTS_DESC,
388                                 'colactions' => _LISTS_ACTIONS,
389                         );
390                         break;
391                 case 'BODY':
392                         $current = $vars['current'];
393                         
394                         $plug =& $manager->getPlugin($current['pfile']);
395                         if ( $plug )
396                         {
397                                 if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_BODY', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_BODY']) )
398                                 {
399                                         $template = "<td>\n"
400                                                   . "<strong><%plugname%></strong><br />\n"
401                                                   . "<%autherlabel%> <%plugauther%><br />\n"
402                                                   . "<%versionlabel%> <%plugversion%><br />\n"
403                                                   . "<%pluggeturl%><br />\n"
404                                                   . "</td>\n"
405                                                   . "<td>\n"
406                                                   . "<%desclabel%><br /><%plugdesc%>\n"
407                                                   . "<%eventlist%>\n"
408                                                   . "<%needupdate%>\n"
409                                                   . "<%dependlist%>\n"
410                                                   . "<%depreqlist%>\n"
411                                                   . "</td>\n";
412                                 }
413                                 else
414                                 {
415                                         $template = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_BODY'];
416                                 }
417                                 $data = array(
418                                         'plugname'              => Entity::hsc($plug->getName()),
419                                         'autherlabel'   => _LIST_PLUGS_AUTHOR,
420                                         'plugauther'    => Entity::hsc($plug->getAuthor()),
421                                         'versionlabel'  => _LIST_PLUGS_VER,
422                                         'plugversion'   => Entity::hsc($plug->getVersion()),
423                                         'tabindex'              => $vars['tabindex'],
424                                         'desclabel'             => _LIST_PLUGS_DESC,
425                                         'plugdesc'              => Entity::hen($plug->getDescription()),
426                                 );
427                                 if ( $plug->getURL() )
428                                 {
429                                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_GURL', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_GURL']) )
430                                         {
431                                                 $subTpl = "<a href=\"<%plugurl%>\" tabindex=\"<%tabindex%>\"><%plugsite%></a>";
432                                         }
433                                         else
434                                         {
435                                                 $subTpl = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_GURL'];
436                                         }
437                                         $subData = array(
438                                                 'plugurl'       => Entity::hsc($plug->getURL()),
439                                                 'tabindex'      => $vars['tabindex'],
440                                                 'plugsite'      => _LIST_PLUGS_SITE,
441                                         );
442                                         $data['pluggeturl'] = Template::fill($subTpl, $subData);
443                                 }
444                                 else
445                                 {
446                                         $data['pluggeturl'] = '';
447                                 }
448                                 if ( count($plug->getEventList()) > 0 )
449                                 {
450                                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLUGEVENTLIST', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGEVENTLIST']) )
451                                         {
452                                                 $subTpl = "<br /><br /><%evntlstlbl%><br /><%eventlist%>";
453                                         }
454                                         else
455                                         {
456                                                 $subTpl = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGEVENTLIST'];
457                                         }
458                                         $subData = array(
459                                                 'evntlstlbl'    => _LIST_PLUGS_SUBS,
460                                                 'eventlist'             => Entity::hsc(implode(', ', $plug->getEventList())),
461                                         );
462                                         $data['eventlist'] = Template::fill($subTpl, $subData);
463                                 }
464                                 else
465                                 {
466                                         $data['eventlist'] = '';
467                                 }
468                                 if ( !$plug->subscribtionListIsUptodate() )
469                                 {
470                                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLUGNEDUPDATE', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGNEDUPDATE']) )
471                                         {
472                                                 $subTpl = "<br /><br /><strong><%updatealert%></strong>";
473                                         }
474                                         else
475                                         {
476                                                 $subTpl = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGNEDUPDATE'];
477                                         }
478                                         $subData = array(
479                                                 'updatealert' => _LIST_PLUG_SUBS_NEEDUPDATE,
480                                         );
481                                         $data['needupdate'] = Template::fill($subTpl, $subData);
482                                 }
483                                 else
484                                 {
485                                         $data['needupdate'] = '';
486                                 }
487                                 if ( count($plug->getPluginDep() ) > 0)
488                                 {
489                                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPEND', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPEND']) )
490                                         {
491                                                 $subTpl = "<br /><br /><%deplistlbl%><br /><%dependlist%>";
492                                         }
493                                         else
494                                         {
495                                                 $subTpl = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPEND'];
496                                         }
497                                         $subData = array(
498                                                 'deplistlbl' => _LIST_PLUGS_DEP,
499                                                 'dependlist' => Entity::hsc(implode(', ', $plug->getPluginDep())),
500                                         );
501                                         $data['dependlist'] = Template::fill($subTpl, $subData);
502                                 }
503                                 else
504                                 {
505                                         $data['dependlist'] = '';
506                                 }
507                                 /* check dependency */
508                                 if ( empty($plugins) )
509                                 {
510                                         $plugins = DB::getResult('SELECT pfile FROM ' . sql_table('plugin'));
511                                 }
512                                 $req = array();
513                                 foreach ( $plugins as $plugin )
514                                 {
515                                         $preq =& $manager->getPlugin($plugin['pfile']);
516                                         if ( $preq )
517                                         {
518                                                 $depList = $preq->getPluginDep();
519                                                 foreach ( $depList as $depName )
520                                                 {
521                                                         if ( $current['pfile'] == $depName )
522                                                         {
523                                                                 $req[] = $plugin['pfile'];
524                                                         }
525                                                 }
526                                         }
527                                 }
528                                 
529                                 if ( count($req) > 0 )
530                                 {
531                                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPREQ', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPREQ']) )
532                                         {
533                                                 $subTpl = "<br /><br /><%deprlstlbl%><br /><%depreqlist%>";
534                                         }
535                                         else
536                                         {
537                                                 $subTpl = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPREQ'];
538                                         }
539                                         $subData = array(
540                                                 'deprlstlbl' => _LIST_PLUGS_DEPREQ,
541                                                 'depreqlist' => Entity::hsc(implode(', ', $req)),
542                                         );
543                                         $data['depreqlist'] = Template::fill($subTpl, $subData);
544                                 }
545                                 else
546                                 {
547                                         $data['depreqlist'] = '';
548                                 }
549                         }
550                         else
551                         {
552                                 if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLUGLISTFALSE', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLISTFALSE']) )
553                                 {
554                                         $template = "<td colspan=\"2\"><%noplugalert%></td>\n";
555                                 }
556                                 else
557                                 {
558                                         $template = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGLISTFALSE'];
559                                 }
560                                 $data = array(
561                                         'noplugalert' => sprintf(_PLUGINFILE_COULDNT_BELOADED, Entity::hsc($current['pfile'])),
562                                 );
563                         }
564                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ACTN', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ACTN']) )
565                         {
566                                 $template .= "<td>\n"
567                                            . "<a href=\"<%actionupurl%>\" tabindex=\"<%tabindex%>\"><%actionuptxt%></a><br />\n"
568                                            . "<a href=\"<%actiondownurl%>\" tabindex=\"<%tabindex%>\"><%actiondowntxt%></a><br />\n"
569                                            . "<a href=\"<%actuninsturl%>\" tabindex=\"<%tabindex%>\"><%actuninsttxt%></a><br />"
570                                            . "<%plugadminurl%>\n"
571                                            . "<%plughelpurl%>\n"
572                                            . "<%plugoptsetting%>\n"
573                                            . "</td>\n";
574                         }
575                         else
576                         {
577                                 $template .= $templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ACTN'];
578                         }
579                         
580                         $baseUrl        = 'index.php?plugid=' . $current['pid'] . '&action=';
581                         $upUrl          = $manager->addTicketToUrl($baseUrl . 'pluginup');
582                         $downUrl        = $manager->addTicketToUrl($baseUrl . 'plugindown');
583                         
584                         $data['actionuptxt']    = _LIST_PLUGS_UP;
585                         $data['actionupurl']    = Entity::hsc($upUrl);
586                         $data['actiondowntxt']  = _LIST_PLUGS_DOWN;
587                         $data['actiondownurl']  = Entity::hsc($downUrl);
588                         $data['actuninsttxt']   = _LIST_PLUGS_UNINSTALL;
589                         $data['actuninsturl']   = 'index.php?action=plugindelete&amp;plugid=' . $current['pid'];
590                         
591                         if ( $plug && ($plug->hasAdminArea() > 0) )
592                         {
593                                 if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ADMN', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ADMN']) )
594                                 {
595                                         $subTpl = "<a href=\"<%actadminurl%>\" tabindex=\"<%tabindex%>\"><%actadmintxt%></a><br />\n";
596                                 }
597                                 else
598                                 {
599                                         $subTpl = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ADMN'];
600                                 }
601                                 $subData = array(
602                                         'actadminurl'   => Entity::hsc($plug->getAdminURL()),
603                                         'tabindex'              => $vars['tabindex'],
604                                         'actadmintxt'   => _LIST_PLUGS_ADMIN,
605                                 );
606                                 $data['plugadminurl'] = Template::fill($subTpl, $subData);
607                         }
608                         else
609                         {
610                                 $data['plugadminurl'] = '';
611                         }
612                         if ( $plug && ($plug->supportsFeature('HelpPage') > 0) )
613                         {
614                                 if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HELP', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HELP']) )
615                                 {
616                                         $subTpl = "<a href=\"<%acthelpurl%>\" tabindex=\"<%tabindex%>\"><%acthelptxt%></a><br />\n";
617                                 }
618                                 else
619                                 {
620                                         $subTpl = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HELP'];
621                                 }
622                                 $subData = array(
623                                         'acthelpurl'    => 'index.php?action=pluginhelp&amp;plugid=' . $current['pid'],
624                                         'tabindex'              => $vars['tabindex'],
625                                         'acthelptxt'    => _LIST_PLUGS_HELP,
626                                 );
627                                 $data['plughelpurl'] = Template::fill($subTpl, $subData);
628                         }
629                         else
630                         {
631                                 $data['plughelpurl'] = '';
632                         }
633                         $optQuery = 'SELECT '
634                                   . '    COUNT(*) AS result '
635                                   . 'FROM '
636                                   .      sql_table('plugin_option_desc') . ' '
637                                   . 'WHERE '
638                                   . '    ocontext = "global" '
639                                   . 'AND opid     = %d';
640                         $pOptions = DB::getValue(sprintf($optQuery, $current['pid']));
641                         if ( $pOptions > 0 )
642                         {
643                                 if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLUGOPTSETURL', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGOPTSETURL']) )
644                                 {
645                                         $subTpl = "<a href=\"<%actoptionurl%>\" tabindex=\"<%tabindex%>\"><%actoptiontxt%></a>\n";
646                                 }
647                                 else
648                                 {
649                                         $subTpl = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGOPTSETURL'];
650                                 }
651                                 $subData = array(
652                                         'actoptionurl'  => 'index.php?action=pluginoptions&amp;plugid=' . $current['pid'],
653                                         'tabindex'              => $vars['tabindex'],
654                                         'actoptiontxt'  => _LIST_PLUGS_OPTIONS,
655                                 );
656                                 $data['plugoptsetting'] = Template::fill($subTpl, $subData);
657                         }
658                         else
659                         {
660                                 $data['plugoptsetting'] = '';
661                         }
662                         break;
663                 case 'FOOT':
664                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLUGLIST_FOOT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_FOOT']) )
665                         {
666                                 $template = "";
667                         }
668                         else
669                         {
670                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_FOOT'];
671                         }
672                         $data = array();
673                         break;
674         }
675         return Template::fill($template, $data);
676 }
677
678 function listplug_table_plugoptionlist($vars, $type, $template_name = '')
679 {
680         global $manager;
681         
682         $templates = array();
683         if ( !empty($template_name) )
684         {
685                 $templates =& $manager->getTemplate($template_name);
686         }
687         
688         switch( $type )
689         {
690                 case 'HEAD':
691                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_POPTLIST_HEAD', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_POPTLIST_HEAD']) )
692                         {
693                                 $template = "<th><%colinfo%></th>\n"
694                                           . "<th><%colvalue%></th>\n";
695                         }
696                         else
697                         {
698                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_POPTLIST_HEAD'];
699                         }
700                         $data = array(
701                                 'colinfo'       => _LISTS_INFO,
702                                 'colvalue'      => _LISTS_VALUE,
703                         );
704                         break;
705                 case 'BODY':
706                         $current = $vars['current'];
707                         $template = listplug_plugOptionRow($current, $template_name);
708                         $data = array();
709                         break;
710                 case 'FOOT':
711                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_POPTLIST_FOOT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_POPTLIST_FOOT']) )
712                         {
713                                 $template = "<tr>\n"
714                                           . "<th colspan=\"2\"><%savetext%></th>\n"
715                                           . "</tr>\n"
716                                           . "<tr>\n"
717                                           . "<td><%savetext%></td>\n"
718                                           . "<td><input type=\"submit\" value=\"<%savetext%>\" /></td>\n"
719                                           . "</tr>\n";
720                         }
721                         else
722                         {
723                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_POPTLIST_FOOT'];
724                         }
725                         $data = array(
726                                 'savetext' => _PLUGS_SAVE,
727                         );
728                         break;
729         }
730         
731         return Template::fill($template, $data);
732 }
733
734 function listplug_plugOptionRow($current, $template_name = '')
735 {
736         global $manager;
737         
738         $templates = array();
739         if ( !empty($template_name) )
740         {
741                 $templates =& $manager->getTemplate($template_name);
742         }
743         
744         $varname = "plugoption[{$current['oid']}][{$current['contextid']}]";
745         
746         // retreive the optionmeta
747         $meta = NucleusPlugin::getOptionMeta($current['typeinfo']);
748         
749         // only if it is not a hidden option write the controls to the page
750         if ( in_array('access', $meta) && $meta['access'] == 'hidden' )
751         {
752                 return false;
753         }
754         else
755         {
756                 if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_POPTLIST_BODY', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_POPTLIST_BODY']) )
757                 {
758                         $template = "<td><%description%></td>\n"
759                                   . "<td>\n";
760                 }
761                 else
762                 {
763                         $template = $templates['SHOWLIST_LISTPLUG_TABLE_POPTLIST_BODY'];
764                 }
765                 
766                 $data = array();
767                 
768                 switch($current['type'])
769                 {
770                         case 'yesno':
771                                 $template .= listplug_input_yesno($varname, $current['value'], 0, 'yes', 'no', _YES, _NO, 0, $template_name, 1);
772                                 break;
773                         case 'password':
774                                 if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OPWORD', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OPWORD']) )
775                                 {
776                                         $template .= "<input type=\"password\" size=\"40\" maxlength=\"128\" name=\"<%varname%>\" value=\"<%value%>\" />\n";
777                                 }
778                                 else
779                                 {
780                                         $template .= $templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OPWORD'];
781                                 }
782                                 $data = array(
783                                         'varname'       => Entity::hsc($varname),
784                                         'value'         => Entity::hsc($current['value']),
785                                 );
786                                 break;
787                         case 'select':
788                                 if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEP', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEP']) )
789                                 {
790                                         $template .= "<select name=\"<%varname%>\">\n";
791                                 }
792                                 else
793                                 {
794                                         $template .= $templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEP'];
795                                 }
796                                 if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEO', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEO']) )
797                                 {
798                                         $subTpl = "<option value=\"<%value%>\"<%selected%>><%optname%></option>\n";
799                                 }
800                                 else
801                                 {
802                                         $subTpl = $templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEO'];
803                                 }
804                                 $options = NucleusPlugin::getOptionSelectValues($current['typeinfo']);
805                                 $options = preg_split('#\|#', $options);
806                                 
807                                 for ( $i=0; $i<(count($options)-1); $i+=2 )
808                                 {
809                                         $name   = $options[$i];
810                                         $value  = $options[$i+1];
811                                         if ( defined($name) )
812                                         {
813                                                 $name = constant($name);
814                                         }
815                                         
816                                         $subData = array(
817                                                 'optname'       => Entity::hsc($name),
818                                                 'value'         => Entity::hsc($value)
819                                         );
820                                         if ($value != $current['value'])
821                                         {
822                                                 $subData['selected'] = '';
823                                         }
824                                         else
825                                         {
826                                                 $subData['selected'] = ' selected="selected"';
827                                         }
828                                         $template .= Template::fill($subTpl, $subData);
829                                 }
830                                 if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEC', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEC']) )
831                                 {
832                                         $template .= "</select>\n";
833                                 }
834                                 else
835                                 {
836                                         $template .= $templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEC'];
837                                 }
838                                 $data['varname'] = Entity::hsc($varname);
839                                 break;
840                         case 'textarea':
841                                 if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OTAREA', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OTAREA']) )
842                                 {
843                                         $template .= "<textarea class=\"pluginoption\" cols=\"30\" rows=\"5\" name=\"<%varname%>\"<%readonly%>><%value%></textarea>\n";
844                                 }
845                                 else
846                                 {
847                                         $template .= $templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OTAREA'];
848                                 }
849                                 $data = array(
850                                         'varname'       => Entity::hsc($varname),
851                                         'value'         => Entity::hsc($current['value'])
852                                 );
853                                 if ( !array_key_exists('access', $current) || $current['access'] != 'readonly')
854                                 {
855                                         $data['readonly'] = '';
856                                 }
857                                 else
858                                 {
859                                         $data['readonly'] = ' readonly="readonly"';
860                                 }
861                                 break;
862                         case 'text':
863                         default:
864                                 if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OITEXT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OITEXT']) )
865                                 {
866                                         $template .= "<input type=\"text\" size=\"40\" maxlength=\"128\" name=\"<%varname%>\" value=\"<%value%>\"<%datatype%><%readonly%> />\n";
867                                 }
868                                 else
869                                 {
870                                         $template .= $templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OITEXT'];
871                                 }
872                                 $data = array(
873                                         'varname'       => Entity::hsc($varname),
874                                         'value'         => Entity::hsc($current['value'])
875                                 );
876                                 if ( !array_key_exists('datatype', $current) || $current['datatype'] != 'numerical')
877                                 {
878                                         $data['datatype'] = '';
879                                 }
880                                 else
881                                 {
882                                         $data['datatype'] = ' onkeyup="checkNumeric(this)" onblur="checkNumeric(this)"';
883                                 }
884                                 if ( !array_key_exists('access', $current) || $current['access'] != 'readonly')
885                                 {
886                                         $data['readonly'] = '';
887                                 }
888                                 else
889                                 {
890                                         $data['readonly'] = ' readonly="readonly"';
891                                 }
892                 }
893                 
894                 if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLUGOPTN_FOOT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGOPTN_FOOT']) )
895                 {
896                         $template .= "<%extra%></td>\n";
897                 }
898                 else
899                 {
900                         $template .= $templates['SHOWLIST_LISTPLUG_TABLE_PLUGOPTN_FOOT'];
901                 }
902                 
903                 if ( !array_key_exists('extra', $current) )
904                 {
905                         $data['extra'] = '';
906                 }
907                 else
908                 {
909                         $data['extra'] = Entity::hsc($current['extra']);
910                 }
911                 
912                 if ( !array_key_exists('description', $current) )
913                 {
914                         $data['description'] = Entity::hsc($current['name']);
915                 }
916                 else if ( !defined($current['description']) )
917                 {
918                         $data['description'] = Entity::hsc($current['description']);
919                 }
920                 else
921                 {
922                         $data['description'] = Entity::hsc(constant($current['description']));
923                 }
924         }
925         return Template::fill($template, $data, 1);
926 }
927
928 /**
929  * listplug_templateEditRow()
930  * 
931  * @param       array   $content                content of target template
932  * @param       string  $desc                   description of target template
933  * @param       string  $name                   name of target template
934  * @param       string  $help                   help text
935  * @param       integer $tabindex               a number for tab index
936  * @param       boolean $big                    large or small textarea
937  * @param       array   $template_name  name of template for filling
938  * @return      void
939  */
940 function listplug_templateEditRow($content, $desc, $name, $help = '', $tabindex = 0, $big = 0, $template_name = '')
941 {
942         global $manager;
943         
944         static $count = 0;
945         
946         $tmplt = array();
947         $base  = array();
948         
949         $templates = array();
950         if ( $template_name )
951         {
952                 $templates =& $manager->getTemplate($template_name);
953         }
954         
955         $data = array(
956                 'description'   => $desc,
957                 'help'                  => empty($help) ? '' : helpHtml('template' . $help),
958                 'count'                 => $count++,
959                 'name'                  => $name,
960                 'tabindex'              => $tabindex,
961                 'rows'                  => $big ? 10 : 5,
962         );
963         
964         $message = '';
965         
966         /* row head */
967         if ( !array_key_exists('TEMPLATE_EDIT_ROW_HEAD', $templates) || empty($tmplt['TEMPLATE_EDIT_ROW_HEAD']) )
968         {
969                 $template = "<tr>\n"
970                           . "<td><%description%><%help%></td>\n"
971                           . "<td id=\"td<%count%>\">\n"
972                           . "<textarea class=\"templateedit\" name=\"<%name%>\" tabindex=\"<%tabindex%>\" cols=\"50\" rows=\"<%rows%>\" id=\"textarea<%count%>\">";
973         }
974         else
975         {
976                 $template = $tmplt['TEMPLATE_EDIT_ROW_HEAD'];
977         }
978         $message .= TEMPLATE::fill($template, $data);
979         
980         /* row content */
981         $message .= ENTITY::hsc($content);
982         
983         /* row tail */
984         if ( !array_key_exists('TEMPLATE_EDIT_ROW_TAIL', $templates) || empty($tmplt['TEMPLATE_EDIT_ROW_TAIL']) )
985         {
986                 $template = "</textarea>\n"
987                           . "</td>\n"
988                           . "</tr>\n";
989         }
990         else
991         {
992                 $template = $tmplt['TEMPLATE_EDIT_ROW_TAIL'];
993         }
994         $message .= TEMPLATE::fill($template, $data);
995         
996         return $message;
997 }
998
999 function listplug_table_itemlist($vars, $type, $template_name = '')
1000 {
1001         global $manager;
1002         
1003         $cssclass  = '';
1004         
1005         $templates = array();
1006         if ( !empty($template_name) )
1007         {
1008                 $templates =& $manager->getTemplate($template_name);
1009         }
1010         
1011         switch( $type )
1012         {
1013                 case 'HEAD':
1014                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_ITEMLIST_HEAD', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_ITEMLIST_HEAD']) )
1015                         {
1016                                 $template = "<th><%colinfo%></th>\n"
1017                                           . "<th><%colcontent%></th>\n"
1018                                           . "<th style=\"white-space:nowrap\"><%colaction%></th>\n";
1019                         }
1020                         else
1021                         {
1022                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_ITEMLIST_HEAD'];
1023                         }
1024                         $data = array(
1025                                 'colinfo'               => _LIST_ITEM_INFO,
1026                                 'colcontent'    => _LIST_ITEM_CONTENT,
1027                                 'colaction'             => _LISTS_ACTIONS
1028                         );
1029                         break;
1030                 case 'BODY':
1031                         $current = $vars['current'];
1032                         // string -> unix timestamp
1033                         $current['itime'] = strtotime($current['itime']);
1034                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_ITEMLIST_BODY', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_ITEMLIST_BODY']) )
1035                         {
1036                                 $template = "<td<%cssclass%>>\n"
1037                                           . "<%bshortlabel%> <%bshortnameval%><br />\n"
1038                                           . "<%categorylabel%> <%categorynameval%><br />\n"
1039                                           . "<%authorlabel%> <%authornameval%><br />\n"
1040                                           . "<%itemdatelabel%> <%itemdateval%><br />\n"
1041                                           . "<%itemtimelabel%> <%itemtimeval%>\n"
1042                                           . "</td>\n"
1043                                           . "<td<%cssclass%>>\n"
1044                                           . "<input type=\"checkbox\" id=\"batch<%batchid%>\" name=\"batch[<%batchid%>]\" value=\"<%itemid%>\" />\n"
1045                                           . "<label for=\"batch<%batchid%>\"><b><%itemtitle%></b></label><br />\n"
1046                                           . "<%itembody%>\n"
1047                                           . "</td>\n"
1048                                           . "<td<%cssclass%>>\n"
1049                                           . "<a href=\"index.php?action=itemedit&amp;itemid=<%itemid%>\"><%editbtn%></a><br />\n"
1050                                           . "<a href=\"index.php?action=itemmove&amp;itemid=<%itemid%>\"><%movebtn%></a><br />\n"
1051                                           . "<a href=\"index.php?action=itemdelete&amp;itemid=<%itemid%>\"><%delbtn%></a><br />\n"
1052                                           . "<%camount%>\n"
1053                                           . "</td>\n";
1054                         }
1055                         else
1056                         {
1057                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_ITEMLIST_BODY'];
1058                         }
1059                         $cssclass  = '';
1060                         
1061                         if ( $current['idraft'] == 1 )
1062                         {
1063                                 $cssclass = ' class="draft"';
1064                         }
1065                         
1066                         // (can't use offset time since offsets might vary between blogs)
1067                         if ( $current['itime'] > $vars['now'] )
1068                         {
1069                                 $cssclass = ' class="future"';
1070                         }
1071                         $body = strip_tags($current['ibody']);
1072                         $data = array(
1073                                 'cssclass'                      => $cssclass,
1074                                 'bshortlabel'           => _LIST_ITEM_BLOG,
1075                                 'bshortnameval'         => Entity::hsc($current['bshortname']),
1076                                 'categorylabel'         => _LIST_ITEM_CAT,
1077                                 'categorynameval'       => Entity::hsc($current['cname']),
1078                                 'authorlabel'           => _LIST_ITEM_AUTHOR,
1079                                 'authornameval'         => Entity::hsc($current['mname']),
1080                                 'itemdatelabel'         => _LIST_ITEM_DATE,
1081                                 'itemdateval'           => date("Y-m-d",$current['itime']),
1082                                 'itemdatelabel'         => _LIST_ITEM_TIME,
1083                                 'itemdateval'           => date("H:i",$current['itime']),
1084                                 'batchid'                       => listplug_nextBatchId(),
1085                                 'itemid'                        => $current['inumber'],
1086                                 'itemtitle'                     => Entity::hsc(strip_tags($current['ititle'])),
1087                                 'itembody'                      => Entity::hsc(Entity::shorten($body, 300, '...')),
1088                                 'editbtn'                       => _LISTS_EDIT,
1089                                 'movebtn'                       => _LISTS_MOVE,
1090                                 'delbtn'                        => _LISTS_DELETE,
1091                         );
1092                         // evaluate amount of comments for the item
1093                         $comment = new Comments($current['inumber']);
1094                         $camount = $comment->amountComments();
1095                         if ( $camount > 0 )
1096                         {
1097                                 $data['camount'] = "<a href=\"index.php?action=itemcommentlist&amp;itemid={$current['inumber']}\">(" . sprintf(_LIST_ITEM_COMMENTS, $comment->amountComments()) . ")</a><br />\n";
1098                         }
1099                         else
1100                         {
1101                                 $data['camount'] = _LIST_ITEM_NOCONTENT . "<br />\n";
1102                         }
1103                         break;
1104                 case 'FOOT':
1105                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_ITEMLIST_FOOT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_ITEMLIST_FOOT']) )
1106                         {
1107                                 $template = "\n";
1108                         }
1109                         else
1110                         {
1111                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_ITEMLIST_FOOT'];
1112                         }
1113                         $data = array();
1114                         break;
1115         }
1116         return Template::fill($template, $data);
1117 }
1118
1119 // for batch operations: generates the index numbers for checkboxes
1120 function listplug_nextBatchId()
1121 {
1122         static $id = 0;
1123         return $id++;
1124 }
1125
1126 function listplug_table_commentlist($vars, $type, $template_name = '')
1127 {
1128         global $manager;
1129         
1130         $templates = array();
1131         if ( !empty($template_name) )
1132         {
1133                 $templates =& $manager->getTemplate($template_name);
1134         }
1135         
1136         switch( $type )
1137         {
1138                 case 'HEAD':
1139                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_CMNTLIST_HEAD', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_CMNTLIST_HEAD']) )
1140                         {
1141                                 $template = "<th><%colinfo%></th>\n"
1142                                           . "<th><%colcontent%></th>\n"
1143                                           . "<th colspan=\"3\"><%colaction%></th>\n";
1144                         }
1145                         else
1146                         {
1147                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_CMNTLIST_HEAD'];
1148                         }
1149                         $data = array(
1150                                 'colinfo'               => _LISTS_INFO,
1151                                 'colcontent'    => _LIST_COMMENT,
1152                                 'colaction'             => _LISTS_ACTIONS
1153                         );
1154                         break;
1155                 case 'BODY':
1156                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_CMNTLIST_BODY', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_CMNTLIST_BODY']) )
1157                         {
1158                                 $template = "<td><%commentdate%><br /><%commentator%><br /><%commentsite%><br /><%commentmail%><br /></td>\n"
1159                                           . "<td>\n"
1160                                           . "<input type=\"checkbox\" id=\"batch<%batchid%>\" name=\"batch[<%batchid%>]\" value=\"<%commentid%>\" />"
1161                                           . "<label for=\"batch<%batchid%>\"><%commentbody%></label>\n"
1162                                           . "</td>\n"
1163                                           . "<td style=\"white-space:nowrap\">\n"
1164                                           . "<a href=\"index.php?action=commentedit&amp;commentid=<%commentid%>\"><%editbtn%></a>\n"
1165                                           . "</td>\n"
1166                                           . "<td style=\"white-space:nowrap\">\n"
1167                                           . "<a href=\"index.php?action=commentdelete&amp;commentid=<%commentid%>\"><%delbtn%></a>\n"
1168                                           . "</td>\n"
1169                                           . "<%addbanlist%>";
1170                         }
1171                         else
1172                         {
1173                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_CMNTLIST_BODY'];
1174                         }
1175                         $current = $vars['current'];
1176                         $body = strip_tags($current['cbody']);
1177                         $data = array(
1178                                 'commentdate'   => date("Y-m-d@H:i", strtotime($current['ctime'])),
1179                                 'batchid'               => listplug_nextBatchId(),
1180                                 'commentid'             => $current['cnumber'],
1181                                 'commentbody'   => Entity::hsc(Entity::shorten($current['cbody'], 300, '...')),
1182                                 'editbtn'               => _LISTS_EDIT,
1183                                 'delbtn'                => _LISTS_DELETE,
1184                         );
1185                         if ( isset($current['mname']) )
1186                         {
1187                                 $data['commentator'] = Entity::hsc($current['mname']) . ' ' . _LIST_COMMENTS_MEMBER;
1188                         }
1189                         else
1190                         {
1191                                 $data['commentator'] = Entity::hsc($current['cuser']);
1192                         }
1193                         if ( isset($current['cmail']) && $current['cmail'] )
1194                         {
1195                                 $data['commentsite'] = Entity::hsc($current['cmail']);
1196                         }
1197                                 else
1198                         {
1199                                 $data['commentsite'] = '';
1200                         }
1201                         if ( isset($current['cemail']) && $current['cemail'] )
1202                         {
1203                                 $data['commentmail'] = Entity::hsc($current['cemail']);
1204                         }
1205                                 else
1206                         {
1207                                 $data['commentmail'] = '';
1208                         }
1209                         if ( $vars['canAddBan'] )
1210                         {
1211                                 if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_CMNTLIST_ABAN', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_CMNTLIST_ABAN']) )
1212                                 {
1213                                         $subTpl = "<td style=\"white-space:nowrap\">"
1214                                                 . "<a href=\"index.php?action=banlistnewfromitem&amp;itemid=<%itemid%>&amp;ip=<%banip%>\" title=\"<%banhost%>\"><%banbtn%></a>"
1215                                                 . "</td>\n";
1216                                 }
1217                                 else
1218                                 {
1219                                         $subTpl = $templates['SHOWLIST_LISTPLUG_TABLE_CMNTLIST_ABAN'];
1220                                 }
1221                                 $subData = array(
1222                                         'itemid'        => $current['citem'],
1223                                         'banip'         => Entity::hsc($current['cip']),
1224                                         'banbtn'        => _LIST_COMMENT_BANIP,
1225                                 );
1226                                 $data['addbanlist'] = Template::fill($subTpl, $subData);
1227                         }
1228                         break;
1229                 case 'FOOT':
1230                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_CMNTLIST_FOOT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_CMNTLIST_FOOT']) )
1231                         {
1232                                 $template = "";
1233                         }
1234                         else
1235                         {
1236                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_CMNTLIST_FOOT'];
1237                         }
1238                         $data = array();
1239                         break;
1240         }
1241         return Template::fill($template, $data);
1242 }
1243
1244 function listplug_table_bloglist($vars, $type, $template_name = '')
1245 {
1246         global $manager;
1247         
1248         $templates = array();
1249         if ( !empty($template_name) )
1250         {
1251                 $templates =& $manager->getTemplate($template_name);
1252         }
1253         
1254         switch( $type )
1255         {
1256                 case 'HEAD':
1257                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_BLOGLIST_HEAD', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_BLOGLIST_HEAD']) )
1258                         {
1259                                 $template = "<th><%blognames%></th>\n"
1260                                           . "<th colspan=\"7\"><%actionshead%></th>\n";
1261                         }
1262                         else
1263                         {
1264                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_BLOGLIST_HEAD'];
1265                         }
1266                         $data = array(
1267                                 'blognames'   => _NAME,
1268                                 'actionshead' => _LISTS_ACTIONS,
1269                         );
1270                         break;
1271                 case 'BODY':
1272                         $current = $vars['current'];
1273                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_BLOGLIST_BODY', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_BLOGLIST_BODY']) )
1274                         {
1275                                 $template = "<td title=\"blogid:<%blogid%> shortname:<%shortname%>\">\n"
1276                                           . "<a href=\"<%blogurl%>\"><img src=\"images/globe.gif\" width=\"13\" height=\"13\" alt=\"<%iconalt%>\" /></a><%blogname%></td>\n"
1277                                           . "<td><a href=\"index.php?action=createitem&amp;blogid=<%blogid%>\" title=\"<%ttaddtext%>\"><%addtext%></a></td>\n"
1278                                           . "<td><a href=\"index.php?action=itemlist&amp;blogid=<%blogid%>\" title=\"<%ttedittext%>\"><%edittext%></a></td>\n"
1279                                           . "<td><a href=\"index.php?action=blogcommentlist&amp;blogid=<%blogid%>\" title=\"<%ttcommenttext%>\"><%commenttext%></a></td>\n"
1280                                           . "<td><a href=\"index.php?action=bookmarklet&amp;blogid=<%blogid%>\" title=\"<%ttbmlettext%>\"><%bmlettext%></a></td>\n";
1281                         }
1282                         else
1283                         {
1284                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_BLOGLIST_BODY'];
1285                         }
1286                         $data = array(
1287                                 'blogid'                => $current['bnumber'],
1288                                 'shortname'             => Entity::hsc($current['bshortname']),
1289                                 'blogurl'               => $current['burl'],
1290                                 'blogname'              => Entity::hsc($current['bname']),
1291                                 'ttaddtext'             => _BLOGLIST_TT_ADD,
1292                                 'addtext'               => _BLOGLIST_ADD,
1293                                 'ttedittext'    => _BLOGLIST_TT_EDIT,
1294                                 'edittext'              => _BLOGLIST_EDIT,
1295                                 'ttcommenttext' => _BLOGLIST_TT_COMMENTS,
1296                                 'commenttext'   => _BLOGLIST_COMMENTS,
1297                                 'ttbmlettext'   => _BLOGLIST_TT_BMLET,
1298                                 'bmlettext'             => _BLOGLIST_BMLET,
1299                         );
1300                         if ( $current['tadmin'] == 1 )
1301                         {
1302                                 if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_BLIST_BD_TADM', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_BLIST_BD_TADM']) )
1303                                 {
1304                                         $template .= "<td><a href=\"index.php?action=blogsettings&amp;blogid=<%blogid%>\" title=\"<%ttsettingtext%>\"><%settingtext%></a></td>\n"
1305                                                    . "<td><a href=\"index.php?action=banlist&amp;blogid=<%blogid%>\" title=\"<%ttbanstext%>\"><%banstext%></a></td>\n";
1306                                 }
1307                                 else
1308                                 {
1309                                         $template .= $templates['SHOWLIST_LISTPLUG_TABLE_BLIST_BD_TADM'];
1310                                 }
1311                                 $data['ttsettingtext']  = _BLOGLIST_TT_SETTINGS;
1312                                 $data['settingtext']    = _BLOGLIST_SETTINGS;
1313                                 $data['ttbanstext']             = _BLOGLIST_TT_BANS;
1314                                 $data['banstext']               = _BLOGLIST_BANS;
1315                         }
1316                         
1317                         if ( $vars['superadmin'] )
1318                         {
1319                                 if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_BLIST_BD_SADM', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_BLIST_BD_TADM']) )
1320                                 {
1321                                         $template .= "<td><a href=\"index.php?action=deleteblog&amp;blogid=<%blogid%>\" title=\"<%ttdeletetext%>\"><%deletetext%></a></td>\n";
1322                                 }
1323                                 else
1324                                 {
1325                                         $template .= $templates['SHOWLIST_LISTPLUG_TABLE_BLIST_BD_SADM'];
1326                                 }
1327                                 $data['ttdeletetext']   = _BLOGLIST_TT_DELETE;
1328                                 $data['deletetext']             = _BLOGLIST_DELETE;
1329                         }
1330                         break;
1331                 case 'FOOT':
1332                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_BLOGLIST_FOOT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_BLOGLIST_FOOT']) )
1333                         {
1334                                 $template = "\n";
1335                         }
1336                         else
1337                         {
1338                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_BLOGLIST_FOOT'];
1339                         }
1340                         $data = array();
1341                         break;
1342         }
1343         return Template::fill($template, $data);
1344 }
1345
1346 function listplug_table_shortblognames($vars, $type, $template_name = '')
1347 {
1348         global $manager;
1349         
1350         $templates = array();
1351         if ( !empty($template_name) )
1352         {
1353                 $templates =& $manager->getTemplate($template_name);
1354         }
1355         
1356         switch( $type )
1357         {
1358                 case 'HEAD':
1359                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_HEAD', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_HEAD']) )
1360                         {
1361                                 $template = "<th><%colshortname%></th>\n"
1362                                           . "<th><%colblogname%></th>\n";
1363                         }
1364                         else
1365                         {
1366                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_HEAD'];
1367                         }
1368                         $data = array(
1369                                 'colshortname' => _EBLOG_SHORTNAME,
1370                                 'colblogname'  => _EBLOG_NAME,
1371                         );
1372                         break;
1373                 case 'BODY':
1374                         $current = $vars['current'];
1375                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_BODY', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_BODY']) )
1376                         {
1377                                 $template = "<td><%bshortname%></td>\n"
1378                                           . "<td><%blogname%></td>\n";
1379                         }
1380                         else
1381                         {
1382                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_BODY'];
1383                         }
1384                         $data = array(
1385                                 'bshortname' => Entity::hsc($current['bshortname']),
1386                                 'blogname'   => Entity::hsc($current['bname']),
1387                         );
1388                         break;
1389                 case 'FOOT':
1390                         $current = $vars['current'];
1391                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_FOOT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_FOOT']) )
1392                         {
1393                                 $template = "\n";
1394                         }
1395                         else
1396                         {
1397                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_FOOT'];
1398                         }
1399                         $data = array();
1400                         break;
1401         }
1402         return Template::fill($template, $data);
1403 }
1404
1405 function listplug_table_shortnames($vars, $type, $template_name = '')
1406 {
1407         global $manager;
1408         
1409         $templates = array();
1410         if ( !empty($template_name) )
1411         {
1412                 $templates =& $manager->getTemplate($template_name);
1413         }
1414         
1415         switch( $type )
1416         {
1417                 case 'HEAD':
1418                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_SHORTNAM_HEAD', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_SHORTNAM_HEAD']) )
1419                         {
1420                                 $template = "<th><%colname%></th>\n"
1421                                           . "<th><%coldesc%></th>\n";
1422                         }
1423                         else
1424                         {
1425                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_SHORTNAM_HEAD'];
1426                         }
1427                         $data = array(
1428                                 'colname' => _NAME,
1429                                 'coldesc' => _LISTS_DESC,
1430                         );
1431                         break;
1432                 case 'BODY':
1433                         $current = $vars['current'];
1434                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_SHORTNAM_BODY', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_SHORTNAM_BODY']) )
1435                         {
1436                                 $template = "<td><%name%></td>\n"
1437                                           . "<td><%desc%></td>\n";
1438                         }
1439                         else
1440                         {
1441                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_SHORTNAM_BODY'];
1442                         }
1443                         $data = array(
1444                                 'name' => Entity::hsc($current['name']),
1445                                 'desc' => Entity::hsc($current['description']),
1446                         );
1447                         break;
1448                 case 'FOOT':
1449                         $current = $vars['current'];
1450                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_SHORTNAM_FOOT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_SHORTNAM_FOOT']) )
1451                         {
1452                                 $template = "\n";
1453                         }
1454                         else
1455                         {
1456                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_SHORTNAM_FOOT'];
1457                         }
1458                         $data = array();
1459                         break;
1460         }
1461         return Template::fill($template, $data);
1462 }
1463
1464 function listplug_table_categorylist($vars, $type, $template_name = '')
1465 {
1466         global $manager;
1467         
1468         $templates = array();
1469         if ( !empty($template_name) )
1470         {
1471                 $templates =& $manager->getTemplate($template_name);
1472         }
1473         
1474         switch( $type )
1475         {
1476                 case 'HEAD':
1477                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_CATELIST_HEAD', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_CATELIST_HEAD']) )
1478                         {
1479                                 $template = "<th><%colname%></th>\n"
1480                                           . "<th><%coldesc%></th>\n"
1481                                           . "<th colspan=\"2\"><%colact%></th>\n";
1482                         }
1483                         else
1484                         {
1485                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_CATELIST_HEAD'];
1486                         }
1487                         $data = array(
1488                                 'colname' => _LISTS_NAME,
1489                                 'coldesc' => _LISTS_DESC,
1490                                 'colact'  => _LISTS_ACTIONS,
1491                         );
1492                         break;
1493                 case 'BODY':
1494                         $current = $vars['current'];
1495                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_CATELIST_BODY', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_CATELIST_BODY']) )
1496                         {
1497                                 $template = "<td>\n"
1498                                           . "<input type=\"checkbox\" id=\"batch<%batchid%>\" name=\"batch[<%batchid%>]\" value=\"<%catid%>\" />\n"
1499                                           . "<label for=\"batch<%batchid%>\"><%catname%></label>\n"
1500                                           . "</td>\n"
1501                                           . "<td><%catdesc%></td>\n"
1502                                           . "<td><a href=\"index.php?action=categoryedit&amp;blogid=<%blogid%>&amp;catid=<%catid%>\" tabindex=\"<%tabindex%>\"><%editbtn%></a></td>\n"
1503                                           . "<td><a href=\"index.php?action=categorydelete&amp;blogid=<%blogid%>&amp;catid=<%catid%>\" tabindex=\"<%tabindex%>\"><%delbtn%></a></td>\n";
1504                         }
1505                         else
1506                         {
1507                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_CATELIST_BODY'];
1508                         }
1509                         
1510                         $data = array(
1511                                 'batchid'       => listplug_nextBatchId(),
1512                                 'catid'         => intval($current['catid']),
1513                                 'catname'       => Entity::hsc($current['cname']),
1514                                 'catdesc'       => Entity::hsc($current['cdesc']),
1515                                 'blogid'        => intval($current['cblog']),
1516                                 'tabindex'      => intval($vars['tabindex']),
1517                                 'editbtn'       => _LISTS_EDIT,
1518                                 'delbtn'        => _LISTS_DELETE,
1519                         );
1520                         break;
1521                 case 'FOOT':
1522                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_CATELIST_FOOT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_CATELIST_FOOT']) )
1523                         {
1524                                 $template = "\n";
1525                         }
1526                         else
1527                         {
1528                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_CATELIST_FOOT'];
1529                         }
1530                         $data = array();
1531                         break;
1532         }
1533         return Template::fill($template, $data);
1534 }
1535
1536 function listplug_table_templatelist($vars, $type, $template_name = '')
1537 {
1538         global $manager, $CONF;
1539         
1540         $templates = array();
1541         if ( !empty($template_name) )
1542         {
1543                 $templates =& $manager->getTemplate($template_name);
1544         }
1545         
1546         switch( $type )
1547         {
1548                 case 'HEAD':
1549                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_TPLTLIST_HEAD', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_TPLTLIST_HEAD']) )
1550                         {
1551                                 $template = "<th><%colname%></th>\n"
1552                                           . "<th><%coldesc%></th>\n"
1553                                           . "<th colspan=\"3\"><%colact%></th>\n";
1554                         }
1555                         else
1556                         {
1557                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_TPLTLIST_HEAD'];
1558                         }
1559                         $data = array(
1560                                 'colname' => _LISTS_NAME,
1561                                 'coldesc' => _LISTS_DESC,
1562                                 'colact'  => _LISTS_ACTIONS,
1563                         );
1564                         break;
1565                 case 'BODY':
1566                         $current = $vars['current'];
1567                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_TPLTLIST_BODY', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_TPLTLIST_BODY']) )
1568                         {
1569                                 $template = "<td><%templatename%></td>\n"
1570                                           . "<td><%templatedesc%></td>\n"
1571                                           . "<td style=\"white-space:nowrap\">"
1572                                           . "<a href=\"<%editurl%>\" tabindex=\"<%tabindex%>\"><%editbtn%></a>\n"
1573                                           . "</td>\n"
1574                                           . "<td style=\"white-space:nowrap\">\n"
1575                                           . "<a href=\"<%cloneurl%>\" tabindex=\"<%tabindex%>\"><%clonebtn%></a>\n"
1576                                           . "</td>\n"
1577                                           . "<td style=\"white-space:nowrap\">\n"
1578                                           . "<a href=\"<%deleteurl%>\" tabindex=\"<%tabindex%>\"><%delbtn%></a>\n"
1579                                           . "</td>\n";
1580                         }
1581                         else
1582                         {
1583                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_TPLTLIST_BODY'];
1584                         }
1585                         
1586                         $data = array(
1587                                 'templatename'  => Entity::hsc($current['tdname']),
1588                                 'templatedesc'  => Entity::hsc($current['tddesc']),
1589                                 'templateid'    => (integer) $current['tdnumber'],
1590                                 'tabindex'              => (integer) $vars['tabindex'],
1591                                 
1592                                 'clonebtn'              => _LISTS_CLONE,
1593                                 'cloneaction'   => $vars['cloneaction'],
1594                                 'cloneurl'              => "{$CONF['AdminURL']}index.php?action={$vars['cloneaction']}&amp;templateid={$current['tdnumber']}",
1595                                 
1596                                 'delbtn'                => _LISTS_DELETE,
1597                                 'deleteaction'  => $vars['deleteaction'],
1598                                 'deleteurl'             => "{$CONF['AdminURL']}index.php?action={$vars['deleteaction']}&amp;templateid={$current['tdnumber']}",
1599                                 
1600                                 'editbtn'               => _LISTS_EDIT,
1601                                 'editaction'    => $vars['editaction'],
1602                                 'editurl'               => "{$CONF['AdminURL']}index.php?action={$vars['editaction']}&amp;templateid={$current['tdnumber']}"
1603                         );
1604                         break;
1605                 case 'FOOT':
1606                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_TPLTLIST_FOOT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_TPLTLIST_FOOT']) )
1607                         {
1608                                 $template = "\n";
1609                         }
1610                         else
1611                         {
1612                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_TPLTLIST_FOOT'];
1613                         }
1614                         $data = array();
1615                         break;
1616         }
1617         return Template::fill($template, $data);
1618 }
1619
1620 function listplug_table_skinlist($vars, $type, $template_name = '')
1621 {
1622         global $CONF, $DIR_SKINS, $manager;
1623         
1624         $templates = array();
1625         if ( !empty($template_name) )
1626         {
1627                 $templates =& $manager->getTemplate($template_name);
1628         }
1629         
1630         switch( $type )
1631         {
1632                 case 'HEAD':
1633                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_SKINLIST_HEAD', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_HEAD']) )
1634                         {
1635                                 $template = "<th><%colname%></th>\n"
1636                                           . "<th><%coldesc%></th>\n"
1637                                           . "<th colspan=\"3\"><%colact%></th>\n";
1638                         }
1639                         else
1640                         {
1641                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_HEAD'];
1642                         }
1643                         $data = array(
1644                                 'colname'       => _LISTS_NAME,
1645                                 'coldesc'       => _LISTS_DESC,
1646                                 'colact'        => _LISTS_ACTIONS,
1647                         );
1648                         break;
1649                 case 'BODY':
1650                         $current = $vars['current'];
1651                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_SKINLIST_BODY', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_BODY']) )
1652                         {
1653                                 $template = "<td><%skinname%><br /><br />\n"
1654                                           . "<%skintypelabel%> <%skintype%><br />\n"
1655                                           . "<%incmodelabel%> <%incmode%><br />\n"
1656                                           . "<%incpreflabel%> <%incpref%><br />\n"
1657                                           . "<%skinthumb%>"
1658                                           . "<%readme%></td>\n"
1659                                           . "<td class=\"availableSkinTypes\"><%skindesc%><%skinparts%></td>\n"
1660                                           . "<td style=\"white-space:nowrap\">"
1661                                           . "<a href=\"index.php?action=skinedit&amp;skinid=<%skinid%>\" tabindex=\"<%tabindex%>\"><%editbtn%></a>"
1662                                           . "</td>\n"
1663                                           . "<td style=\"white-space:nowrap\">"
1664                                           . "<a href=\"<%cloneurl%>\" tabindex=\"<%tabindex%>\"><%clonebtn%></a>"
1665                                           . "</td>\n"
1666                                           . "<td style=\"white-space:nowrap\">"
1667                                           . "<a href=\"index.php?action=skindelete&amp;skinid=<%skinid%>\" tabindex=\"<%tabindex%>\"><%delbtn%></a>"
1668                                           . "</td>\n";
1669                         }
1670                         else
1671                         {
1672                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_BODY'];
1673                         }
1674                         
1675                         $data = array(
1676                                 'tabindex'              => $vars['tabindex']++,
1677                                 
1678                                 'skinid'                => (integer) $current['sdnumber'],
1679                                 'skindesc'              => Entity::hsc($current['sddesc']),
1680                                 
1681                                 'skintypelabel' => _LISTS_TYPE,
1682                                 'skintype'              => Entity::hsc($current['sdtype']),
1683                                 
1684                                 'incmodelabel'  => _LIST_SKINS_INCMODE,
1685                                 'incmode'               => ($current['sdincmode'] == 'skindir') ? _PARSER_INCMODE_SKINDIR : _PARSER_INCMODE_NORMAL,
1686                                 
1687                                 'incpreflabel'  => ($current['sdincpref']) ? _SKIN_INCLUDE_PREFIX : '',
1688                                 'incpref'               => ($current['sdincpref']) ? Entity::hsc($current['sdincpref']) : '',
1689                                 
1690                                 'editbtn'               => _LISTS_EDIT,
1691                                 'editaction'    => $vars['editaction'],
1692                                 'editurl'               => "{$CONF['AdminURL']}index.php?action={$vars['editaction']}&skinid={$current['sdnumber']}",
1693                                 
1694                                 'clonebtn'              => _LISTS_CLONE,
1695                                 'cloneaction'   => $vars['cloneaction'],
1696                                 'cloneurl'              => "{$CONF['AdminURL']}index.php?action={$vars['cloneaction']}&skinid={$current['sdnumber']}",
1697                                 
1698                                 'delbtn'                => _LISTS_DELETE,
1699                                 'deleteaction'  => $vars['deleteaction'],
1700                                 'deleteurl'             => "{$CONF['AdminURL']}index.php?action={$vars['deleteaction']}&skinid={$current['sdnumber']}"
1701                         );
1702                         
1703                         if ( $current['sdnumber'] != $vars['default'] )
1704                         {
1705                                 $data['skinname'] = Entity::hsc($current['sdname']);
1706                         }
1707                         else
1708                         {
1709                                 $data['skinname'] = '<strong>' . Entity::hsc($current['sdname']) . '</strong>';
1710                         }
1711                         
1712                         // add preview image when present
1713                         if ( $current['sdincpref'] && @file_exists("{$DIR_SKINS}{$current['sdincpref']}preview.png") )
1714                         {
1715                                 $data['skinthumb'] = "<p>\n";
1716                                 
1717                                 $alternatve_text = sprintf(_LIST_SKIN_PREVIEW, $current['sdname']);
1718                                 $has_enlargement = @file_exists($DIR_SKINS . $current['sdincpref'] . 'preview-large.png');
1719                                 if ( $has_enlargement )
1720                                 {
1721                                         $data['skinthumb'] .= '<a href="' . $CONF['SkinsURL'] . Entity::hsc($current['sdincpref']) . 'preview-large.png" title="' . _LIST_SKIN_PREVIEW_VIEWLARGER . "\">\n";
1722                                 }
1723                                 $data['skinthumb'] .= '<img class="skinpreview" src="' . $CONF['SkinsURL'] . Entity::hsc($current['sdincpref']) . 'preview.png" width="100" height="75" alt="' . $alternatve_text . "\" />\n";
1724                                 if ( $has_enlargement )
1725                                 {
1726                                         $data['skinthumb'] .= "</a><br />\n";
1727                                 }
1728                                 
1729                                 if ( @file_exists("{$DIR_SKINS}{$current['sdincpref']}readme.html") )
1730                                 {
1731                                         $url = $CONF['SkinsURL'] . Entity::hsc($current['sdincpref']) . 'readme.html';
1732                                         $title = sprintf(_LIST_SKIN_README, $current['sdname']);
1733                                         $data['readme'] = "<a href=\"{$url}\" title=\"{$title}\">" . _LIST_SKIN_README_TXT . "</a>\n";
1734                                 }
1735                                 else
1736                                 {
1737                                         $data['readme'] ="";
1738                                 }
1739                                 
1740                                 $data['skinthumb'] .=  "</p>\n";
1741                         }
1742                         
1743                         $skin =& $manager->getSkin($current['sdnumber'], $vars['handler']);
1744                         $available_types = $skin->getAvailableTypes();
1745                         
1746                         $data['skinparts'] = _LIST_SKINS_DEFINED
1747                                            . "<ul>\n";
1748                         foreach ( $available_types as $type => $label )
1749                         {
1750                                 if ( $label === FALSE )
1751                                 {
1752                                         $label = ucfirst($type);
1753                                         $article = 'skinpartspecial';
1754                                 }
1755                                 else
1756                                 {
1757                                         $article = "skinpart{$type}";
1758                                 }
1759                                 $data['skinparts'] .= "<li>\n"
1760                                                    . helpHtml($article) . "\n"
1761                                                    . "<a href=\"{$CONF['AdminURL']}index.php?action={$vars['edittypeaction']}&amp;skinid={$current['sdnumber']}&amp;type={$type}\" tabindex=\"{$vars['tabindex']}\">"
1762                                                    . Entity::hsc($label)
1763                                                    . "</a>\n"
1764                                                    . "</li>\n";
1765                         }
1766                         $data['skinparts'] .= "</ul>\n";
1767                         break;
1768                 case 'FOOT':
1769                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_SKINLIST_FOOT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_FOOT']) )
1770                         {
1771                                 $template = "";
1772                         }
1773                         else
1774                         {
1775                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_FOOT'];
1776                         }
1777                         $data = array();
1778                         break;
1779         }
1780         return Template::fill($template, $data);
1781 }
1782
1783 function listplug_table_draftlist($vars, $type, $template_name = '')
1784 {
1785         global $manager;
1786         
1787         $templates = array();
1788         if ( !empty($template_name) )
1789         {
1790                 $templates =& $manager->getTemplate($template_name);
1791         }
1792         switch( $type )
1793         {
1794                 case 'HEAD':
1795                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_DRFTLIST_HEAD', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_DRFTLIST_HEAD']) )
1796                         {
1797                                 $template = "<th><%colblog%></th>\n"
1798                                           . "<th><%coldesc%></th>\n"
1799                                           . "<th colspan=\"2\"><%colact%></th>\n";
1800                         }
1801                         else
1802                         {
1803                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_DRFTLIST_HEAD'];
1804                         }
1805                         $data = array(
1806                                 'colblog'       => _LISTS_BLOG,
1807                                 'coldesc'       => _LISTS_TITLE,
1808                                 'colact'        => _LISTS_ACTIONS,
1809                         );
1810                         break;
1811                 case 'BODY':
1812                         $current = $vars['current'];
1813                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_DRFTLIST_BODY', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_DRFTLIST_BODY']) )
1814                         {
1815                                 $template = "<td><%bshortname%></td>\n"
1816                                           . "<td><%ititle%></td>\n"
1817                                           . "<td><a href=\"index.php?action=itemedit&amp;itemid=<%itemid%>\"><%editbtn%></a></td>\n"
1818                                           . "<td><a href=\"index.php?action=itemdelete&amp;itemid=<%itemid%>\"><%delbtn%></a></td>\n";
1819                         }
1820                         else
1821                         {
1822                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_DRFTLIST_BODY'];
1823                         }
1824                         $data = array(
1825                                 'bshortname'    => Entity::hsc($current['bshortname']),
1826                                 'ititle'                => Entity::hsc(strip_tags($current['ititle'])),
1827                                 'itemid'                => intval($current['inumber']),
1828                                 'editbtn'               => _LISTS_EDIT,
1829                                 'delbtn'                => _LISTS_DELETE,
1830                         );
1831                         break;
1832                 case 'FOOT':
1833                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_DRFTLIST_FOOT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_DRFTLIST_FOOT']) )
1834                         {
1835                                 $template = "\n";
1836                         }
1837                         else
1838                         {
1839                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_DRFTLIST_FOOT'];
1840                         }
1841                         $data = array();
1842                         break;
1843         }
1844         return Template::fill($template, $data);
1845 }
1846
1847 function listplug_table_otherdraftlist($vars, $type, $template_name = '')
1848 {
1849         global $manager;
1850         
1851         $templates = array();
1852         if ( !empty($template_name) )
1853         {
1854                 $templates =& $manager->getTemplate($template_name);
1855         }
1856         
1857         switch( $type )
1858         {
1859                 case 'HEAD':
1860                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_ODRFTLIST_HEAD', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_ODRFTLIST_HEAD']) )
1861                         {
1862                                 $template = "<th><%colblog%></th>\n"
1863                                           . "<th><%coldesc%></th>\n"
1864                                           . "<th><%colautr%></th>\n"
1865                                           . "<th colspan=\"2\"><%colact%></th>\n";
1866                         }
1867                         else
1868                         {
1869                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_ODRFTLIST_HEAD'];
1870                         }
1871                         $data = array(
1872                                 'colblog'       => _LISTS_BLOG,
1873                                 'coldesc'       => _LISTS_TITLE,
1874                                 'colautr'       => _LISTS_AUTHOR,
1875                                 'colact'        => _LISTS_ACTIONS,
1876                         );
1877                         break;
1878                 case 'BODY':
1879                         $current = $vars['current'];
1880                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_ODRFTLIST_BODY', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_ODRFTLIST_BODY']) )
1881                         {
1882                                 $template = "<td><%bshortname%></td>\n"
1883                                           . "<td><%ititle%></td>\n"
1884                                           . "<td><%iauthor%></td>\n"
1885                                           . "<td><a href=\"index.php?action=itemedit&amp;itemid=<%itemid%>\"><%editbtn%></a></td>\n"
1886                                           . "<td><a href=\"index.php?action=itemdelete&amp;itemid=<%itemid%>\"><%delbtn%></a></td>\n";
1887                         }
1888                         else
1889                         {
1890                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_ODRFTLIST_BODY'];
1891                         }
1892                         $data = array(
1893                                 'bshortname'    => Entity::hsc($current['bshortname']),
1894                                 'ititle'                => Entity::hsc(strip_tags($current['ititle'])),
1895                                 'iauthor'               => Entity::hsc(strip_tags($current['mname'])),
1896                                 'itemid'                => intval($current['inumber']),
1897                                 'editbtn'               => _LISTS_EDIT,
1898                                 'delbtn'                => _LISTS_DELETE,
1899                         );
1900                         break;
1901                 case 'FOOT':
1902                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_ODRFTLIST_FOOT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_ODRFTLIST_FOOT']) )
1903                         {
1904                                 $template = "\n";
1905                         }
1906                         else
1907                         {
1908                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_ODRFTLIST_FOOT'];
1909                         }
1910                         $data = array();
1911                         break;
1912         }
1913         return Template::fill($template, $data);
1914 }
1915
1916 function listplug_table_actionlist($vars, $type, $template_name = '')
1917 {
1918         global $manager;
1919         
1920         $templates = array();
1921         if ( !empty($template_name) )
1922         {
1923                 $templates =& $manager->getTemplate($template_name);
1924         }
1925         
1926         switch( $type )
1927         {
1928                 case 'HEAD':
1929                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_ACTNLIST_HEAD', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_ACTNLIST_HEAD']) )
1930                         {
1931                                 $template = "<th><%coltime%></th>\n"
1932                                           . "<th><%colmesg%></th>\n";
1933                         }
1934                         else
1935                         {
1936                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_ACTNLIST_HEAD'];
1937                         }
1938                         $data = array(
1939                                 'coltime' => _LISTS_TIME,
1940                                 'colmesg' => _LIST_ACTION_MSG,
1941                         );
1942                         break;
1943                 case 'BODY':
1944                         $current = $vars['current'];
1945                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_ACTNLIST_BODY', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_ACTNLIST_BODY']) )
1946                         {
1947                                 $template = "<td><%timestamp%></td>\n"
1948                                           . "<td><%message%></td>\n";
1949                         }
1950                         else
1951                         {
1952                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_ACTNLIST_BODY'];
1953                         }
1954                         $data = array(
1955                                 'timestamp'     => Entity::hsc($current['timestamp']),
1956                                 'message'       => Entity::hsc($current['message']),
1957                         );
1958                         break;
1959                 case 'FOOT':
1960                         $current = $vars['current'];
1961                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_ACTNLIST_FOOT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_ACTNLIST_FOOT']) )
1962                         {
1963                                 $template = "\n";
1964                         }
1965                         else
1966                         {
1967                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_ACTNLIST_FOOT'];
1968                         }
1969                         $data = array();
1970                         break;
1971         }
1972         return Template::fill($template, $data);
1973 }
1974
1975 function listplug_table_banlist($vars, $type, $template_name = '')
1976 {
1977         global $manager;
1978         
1979         $templates = array();
1980         if ( !empty($template_name) )
1981         {
1982                 $templates =& $manager->getTemplate($template_name);
1983         }
1984         
1985         switch( $type )
1986         {
1987                 case 'HEAD':
1988                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_IBANLIST_HEAD', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_IBANLIST_HEAD']) )
1989                         {
1990                                 $template = "<th><%iprange%></th>\n"
1991                                           . "<th><%reason%></th>\n"
1992                                           . "<th><%colact%></th>\n";
1993                         }
1994                         else
1995                         {
1996                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_IBANLIST_HEAD'];
1997                         }
1998                         $data = array(
1999                                 'iprange'       => _LIST_BAN_IPRANGE,
2000                                 'reason'        => _LIST_BAN_REASON,
2001                                 'colact'        => _LISTS_ACTIONS,
2002                         );
2003                         break;
2004                 case 'BODY':
2005                         $current = $vars['current'];
2006                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_IBANLIST_BODY', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_IBANLIST_BODY']) )
2007                         {
2008                                 $template = "<td><%iprange%></td>\n"
2009                                           . "<td><%reason%></td>\n"
2010                                           . "<td><a href=\"index.php?action=banlistdelete&amp;blogid=<%blogid%>&amp;iprange=<%iprange%>\"><%delbtn%></a></td>\n";
2011                         }
2012                         else
2013                         {
2014                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_IBANLIST_BODY'];
2015                         }
2016                         $data = array(
2017                                 'iprange'       => Entity::hsc($current['iprange']),
2018                                 'reason'        => Entity::hsc($current['reason']),
2019                                 'blogid'        => intval($current['blogid']),
2020                                 'delbtn'        => _LISTS_DELETE,
2021                         );
2022                         break;
2023                 case 'FOOT':
2024                         $current = $vars['current'];
2025                         if ( !array_key_exists('SHOWLIST_LISTPLUG_TABLE_IBANLIST_FOOT', $templates) || empty($templates['SHOWLIST_LISTPLUG_TABLE_IBANLIST_FOOT']) )
2026                         {
2027                                 $template = "\n";
2028                         }
2029                         else
2030                         {
2031                                 $template = $templates['SHOWLIST_LISTPLUG_TABLE_IBANLIST_FOOT'];
2032                         }
2033                         $data = array();
2034                         break;
2035         }
2036         return Template::fill($template, $data);
2037 }
2038
2039 /**
2040  * listplug_list_normalskinlist()
2041  * 
2042  * @param       array   $vars                   array for variables
2043  * @param       string  $type                   HEAD/BODY/FOOT
2044  * @param       string  $template_name  name of template
2045  * @return      string  marked-up string
2046  */
2047 function listplug_list_normalskinlist($vars, $type, $template_name = '')
2048 {
2049         global $manager, $CONF;
2050         
2051         /* available variables as a default */
2052         $data = array(
2053                 'skinid'        => (integer) $vars['skinid'],
2054                 'skinname'      => Entity::hsc($vars['skinname']),
2055         );
2056         
2057         $templates = array();
2058         if ( $template_name )
2059         {
2060                 $templates =& $manager->getTemplate($template_name);
2061         }
2062         
2063         switch ( $type )
2064         {
2065                 case 'HEAD':
2066                         if ( !array_key_exists('NORMALSKINLIST_HEAD', $templates) || empty($templates['NORMALSKINLIST_HEAD']) )
2067                         {
2068                                 $template = "<ul>\n";
2069                         }
2070                         else
2071                         {
2072                                 $template = $templates['NORMALSKINLIST_HEAD'];
2073                         }
2074                         
2075                         break;
2076                 case 'BODY':
2077                         $current = $vars['current'];
2078                         if ( !array_key_exists('NORMALSKINLIST_BODY', $templates) || empty($templates['NORMALSKINLIST_BODY']) )
2079                         {
2080                                 $template = "<li>"
2081                                           . "<a href=\"<%editurl%>\" tabindex=\"<%tabindex%>\"><%skintypename%></a>"
2082                                           . " <%help%>"
2083                                           . "</li>\n";
2084                         }
2085                         else
2086                         {
2087                                 $template = $templates['NORMALSKINLIST_BODY'];
2088                         }
2089                         
2090                         $data['tabindex']               = $vars['tabindex']++;
2091                         $data['skintype']               = $current['skintype'];
2092                         $data['skintypename']   = $current['skintypename'];
2093                         $data['editaction']             = $vars['editaction'];
2094                         $data['editurl']                = "{$CONF['AdminURL']}?action={$vars['editaction']}&amp;skinid={$vars['skinid']}&amp;type={$current['skintype']}";
2095                         /* TODO: removeaction? */
2096                         /* TODO: customHelpHtml("skinpart{$skintype}-{$template_name}") */
2097                         $data['help']                   = '';
2098                         break;
2099                 case 'FOOT':
2100                         if ( !array_key_exists('NORMALSKINLIST_FOOT', $templates) || empty($templates['NORMALSKINLIST_FOOT']) )
2101                         {
2102                                 $template = "</ul>\n";
2103                         }
2104                         else
2105                         {
2106                                 $template = $templates['NORMALSKINLIST_FOOT'];
2107                         }
2108                         
2109                         break;
2110         }
2111         
2112         return Template::fill($template, $data);
2113 }
2114
2115 /**
2116  * listplug_list_specialskinlist()
2117  * 
2118  * @param       array   $vars                   array for variables
2119  * @param       string  $type                   HEAD/BODY/FOOT
2120  * @param       string  $template_name  name of template
2121  * @return      string  marked-up string
2122  */
2123 function listplug_list_specialskinlist($vars, $type, $template_name = '')
2124 {
2125         global $manager, $CONF;
2126         
2127         /* available variables as a default */
2128         $data = array(
2129                 'skinid'        => (integer) $vars['skinid'],
2130                 'skinname'      => Entity::hsc($vars['skinname']),
2131         );
2132         
2133         /* retrieve templates */
2134         $templates = array();
2135         if ( $template_name )
2136         {
2137                 $templates =& $manager->getTemplate($template_name);
2138         }
2139         
2140         switch ( $type )
2141         {
2142                 case 'HEAD':
2143                         if ( !array_key_exists('SPECIALSKINLIST_HEAD', $templates) || empty($templates['SPECIALSKINLIST_HEAD']) )
2144                         {
2145                                 $template = "<ul>\n";
2146                         }
2147                         else
2148                         {
2149                                 $template = $templates['SPECIALSKINLIST_HEAD'];
2150                         }
2151                         break;
2152                 case 'BODY':
2153                         $current = $vars['current'];
2154                         if ( !array_key_exists('SPECIALSKINLIST_BODY', $templates) || empty($templates['SPECIALSKINLIST_BODY']) )
2155                         {
2156                                 $template = "<li>"
2157                                           . "<a href=\"<%editurl%>\" tabindex=\"<%tabindex%>\">"
2158                                           . "<%skintype%>"
2159                                           . "</a>"
2160                                           . " ("
2161                                           . "<a href=\"<%removeurl%>\" tabindex=\"<%tabindex%>\" >"
2162                                           . "<%text(_LISTS_DELETE)%>"
2163                                           . "</a>"
2164                                           . ")"
2165                                           . "</li>\n";
2166                         }
2167                         else
2168                         {
2169                                 $template = $templates['SPECIALSKINLIST_BODY'];
2170                         }
2171                         
2172                         $data['tabindex']               = (integer) $vars['tabindex']++;
2173                         $data['skintype']               = Entity::hsc($current['skintype']);
2174                         $data['skintypename']   = Entity::hsc($current['skintypename']);
2175                         $data['editaction']             = $vars['editaction'];
2176                         $data['editurl']                = "{$CONF['AdminURL']}?action={$vars['editaction']}&amp;skinid={$vars['skinid']}&amp;type={$current['skintype']}";
2177                         $data['removeaction']   = $vars['editaction'];
2178                         $data['removeurl']              = "{$CONF['AdminURL']}?action={$vars['removeaction']}&amp;skinid={$vars['skinid']}&amp;type={$current['skintype']}";
2179                         
2180                         break;
2181                 case 'FOOT':
2182                         if ( !array_key_exists('SPECIALSKINLIST_FOOT', $templates) || empty($templates['SPECIALSKINLIST_FOOT']) )
2183                         {
2184                                 $template = "</ul>\n";
2185                         }
2186                         else
2187                         {
2188                                 $template = $templates['SPECIALSKINLIST_FOOT'];
2189                         }
2190                         break;
2191         }
2192         
2193         return Template::fill($template, $data);
2194 }
2195
2196 /**
2197  * listplug_input_yesno()
2198  *
2199  * @param       string  $name                   name of input element with radio type attribute
2200  * @param       string  $checkedval             value which should be checked
2201  * @param       integer $tabindex               tabindex number
2202  * @param       string  $value1                 value of radio 1
2203  * @param       string  $value2                 value of radio 2
2204  * @param       string  $yesval                 label for yes
2205  * @param       string  $noval                  label for no
2206  * @param       boolean $isAdmin                super admin or not
2207  * @param       string  $template_name  name of template
2208  * @param       boolean $showlist               used in showlist or not
2209  * @return      string  marked-up string
2210  */
2211 function listplug_input_yesno($name, $checkedval, $tabindex = 0,
2212         $value1 = 1, $value2 = 0, $yesval = _YES, $noval = _NO,
2213         $isAdmin = 0, $template_name = '', $showlist = FALSE)
2214 {
2215         global $manager;
2216         
2217         $templates = array();
2218         if ( $template_name )
2219         {
2220                 $templates =& $manager->getTemplate($template_name);
2221         }
2222         
2223         if ( $name == 'admin' )
2224         {
2225                 if ( !array_key_exists('INPUTYESNO_TEMPLATE_ADMIN', $templates) || empty($templates['INPUTYESNO_TEMPLATE_ADMIN']) )
2226                 {
2227                         $template = "<input type=\"radio\" id=\"<%yesid%>\" name=\"<%name%>\" value=\"<%yesval%>\" <%yescheckedval%> onclick=\"selectCanLogin(true);\" />\n"
2228                                   . "<label for=\"<%yesid%>\"><%yesvaltext%></label>\n"
2229                                   . "<input type=\"radio\" id=\"<%noid%>\" name=\"<%name%>\" value=\"<%noval%>\" <%nocheckedval%> <%disabled%> onclick=\"selectCanLogin(false);\" />\n"
2230                                   . "<label for=\"<%noid%>\"><%novaltext%></label>\n";
2231                 }
2232                 else
2233                 {
2234                         $template = $templates['INPUTYESNO_TEMPLATE_ADMIN'];
2235                 }
2236         }
2237         else
2238         {
2239                 if ( array_key_exists('INPUTYESNO_TEMPLATE_NORMAL', $templates) && !empty($templates['INPUTYESNO_TEMPLATE_NORMAL']) )
2240                 {
2241                         $template = $templates['INPUTYESNO_TEMPLATE_NORMAL'];
2242                 }
2243                 else if ( $showlist && array_key_exists('SHOWLIST_LISTPLUG_TABLE_PLGOPT_OYESNO', $templates) && !empty($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OYESNO']) )
2244                 {
2245                         $template = $templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OYESNO'];
2246                 }
2247                 else
2248                 {
2249                 $template = "<input type=\"radio\" id=\"<%yesid%>\" name=\"<%name%>\" value=\"<%yesval%>\" <%yescheckedval%> />\n"
2250                           . "<label for=\"<%yesid%>\"><%yesvaltext%></label>\n"
2251                           . "<input type=\"radio\" id=\"<%noid%>\" name=\"<%name%>\" value=\"<%noval%>\" <%nocheckedval%> <%disabled%> />\n"
2252                           . "<label for=\"<%noid%>\"><%novaltext%></label>\n";
2253                 }
2254         }
2255         
2256         $id             = preg_replace('#[|]#', '-', $name);
2257         $id1    = $id . $value1;
2258         $id2    = $id . $value2;
2259         $dat = array(
2260                 'name'                  => Entity::hsc($name),
2261                 'yesval'                => Entity::hsc($value1),
2262                 'noval'                 => Entity::hsc($value2),
2263                 'yesid'                 => Entity::hsc($id1),
2264                 'noid'                  => Entity::hsc($id2),
2265                 'yesvaltext'    => $yesval,
2266                 'novaltext'             => $noval,
2267                 'yescheckedval' => ($checkedval == $value1) ? 'checked="checked" tabindex="' . $tabindex . '"': '',
2268                 'nocheckedval'  => ($checkedval != $value1) ? 'checked="checked" tabindex="' . $tabindex . '"': '',
2269                 'disabled'              => ($isAdmin && $name == 'canlogin') ? ' disabled="disabled"' : '',
2270         );
2271         
2272         return Template::fill($template, $dat);
2273 }
2274
2275 /**
2276  * listplug_batchlist()
2277  * 
2278  * @param       string          $attr   item/member/team/category/comment
2279  * @param       resource        $query  SQL resorce
2280  * @param       string          $type   type for showlist()
2281  * @param       array           $vars   array for variables
2282  */
2283 function listplug_batchlist($attr, $query, $type, $vars, $template_name)
2284 {
2285         global $manager;
2286         
2287         /* HEAD */
2288         $content = "<form method=\"post\" action=\"index.php\">\n";
2289         
2290         /* BODY */
2291         $content .= showlist($query, $type, $vars, $template_name);
2292         
2293         /* FOOT */
2294         switch ( $attr )
2295         {
2296                 case 'item':
2297                         $options = array(
2298                                 'delete'        => _BATCH_ITEM_DELETE,
2299                                 'move'          => _BATCH_ITEM_MOVE
2300                         );
2301                         break;
2302                 case 'member':
2303                         $options = array(
2304                                 'delete'        => _BATCH_MEMBER_DELETE,
2305                                 'setadmin'      => _BATCH_MEMBER_SET_ADM,
2306                                 'unsetadmin' => _BATCH_MEMBER_UNSET_ADM
2307                         );
2308                         break;
2309                 case 'team':
2310                         $options = array(
2311                                 'delete'        => _BATCH_TEAM_DELETE,
2312                                 'setadmin'      => _BATCH_TEAM_SET_ADM,
2313                                 'unsetadmin' => _BATCH_TEAM_UNSET_ADM,
2314                         );
2315                         break;
2316                 case 'category':
2317                         $options = array(
2318                                 'delete'        => _BATCH_CAT_DELETE,
2319                                 'move'          => _BATCH_CAT_MOVE,
2320                         );
2321                         break;
2322                 case 'comment':
2323                         $options = array(
2324                                 'delete'        => _BATCH_COMMENT_DELETE,
2325                         );
2326                         break;
2327                 default:
2328                         $options = array();
2329                         break;
2330         }
2331         
2332         $content .= "<p class=\"batchoperations\">\n"
2333                    . _BATCH_WITH_SEL
2334                    . "<select name=\"batchaction\">\n";
2335         
2336         foreach ( $options as $option => $label )
2337         {
2338                 $content .= "<option value=\"{$option}\">{$label}</option>\n";
2339         }
2340         $content .= "</select>\n";
2341         
2342         if ( $attr == 'team' )
2343         {
2344                 $content .= '<input type="hidden" name="blogid" value="' . intRequestVar('blogid') . '" />';
2345         }
2346         else if ( $attr == 'comment' )
2347         {
2348                 $content .= '<input type="hidden" name="itemid" value="' . intRequestVar('itemid') . '" />';
2349         }
2350         
2351         $content .= '<input type="submit" value="' . _BATCH_EXEC . '" />'
2352                    . "("
2353                    . "<a href=\"\" onclick=\"if( event &amp;&amp; event.preventDefault ) event.preventDefault(); return batchSelectAll(1); \">" . _BATCH_SELECTALL . "</a>"
2354                    . " - "
2355                    . "<a href=\"\" onclick=\"if( event &amp;&amp; event.preventDefault ) event.preventDefault(); return batchSelectAll(0); \">" . _BATCH_DESELECTALL . "</a>"
2356                    . ")\n"
2357                    . "<input type=\"hidden\" name=\"action\" value=\"batch{$attr}\" />\n"
2358                    . '<input type="hidden" name="ticket" value="' . Entity::hsc($manager->getNewTicket()) . '" />' . "\n"
2359                    . "</p>\n"
2360                    . "</form>\n";
2361         
2362         return $content;
2363 }
2364
2365 /**
2366  * listplug_navlist()
2367  * 
2368  * @param       string          $attr                   item/member/team/category/comment
2369  * @param       resource        $query                  SQL resorce
2370  * @param       string          $type                   type for showlist()
2371  * @param       array           $vars                   array for variables
2372  * @param       string          $template_name  name of template
2373  * @return      string          contents
2374  */
2375 function listplug_navlist($attribute, $query, $type, $vars, $template_name)
2376 {
2377         global $CONF;
2378         
2379         $prev = $vars['start'] - $vars['amount'];
2380         if ( $prev < $vars['minamount'] )
2381         {
2382                 $prev = $vars['minamount'];
2383         }
2384         
2385         $next = $vars['start'] + $vars['amount'];
2386         
2387         $navi = "\n";
2388         $navi .= "<table frame=\"box\" rules=\"all\" sumamry=\"navigation actions\" class=\"navigation\">\n"
2389                . "<tr>\n";
2390         $navi .= "<td>\n"
2391                . "<form method=\"post\" action=\"{$CONF['AdminURL']}\">\n"
2392                . "<input type=\"hidden\" name=\"start\" value=\"{$prev}\" />\n"
2393                . "<button type=\"submit\" name=\"action\" value=\"{$vars['action']}\">&lt; &lt; " . _LISTS_PREV . "</button>\n"
2394                . "<input type=\"hidden\" name=\"blogid\" value=\"{$vars['blogid']}\" />\n"
2395                . "<input type=\"hidden\" name=\"itemid\" value=\"{$vars['itemid']}\" />\n"
2396                . "<input type=\"hidden\" name=\"search\" value=\"{$vars['search']}\" />\n"
2397                . "<input type=\"hidden\" name=\"amount\" value=\"{$vars['amount']}\" />\n"
2398                . "</form>\n"
2399                . "</td>\n";
2400         $navi .= "<td>\n"
2401                . "<form method=\"post\" action=\"{$CONF['AdminURL']}\">\n"
2402                . "<input type=\"text\" name=\"amount\" size=\"3\" value=\"{$vars['amount']}\" />\n"
2403                . _LISTS_PERPAGE
2404                . "<input type=\"hidden\" name=\"start\" value=\"0\" />\n"
2405                . "<button type=\"submit\" name=\"action\" value=\"{$vars['action']}\">&gt; " . _LISTS_CHANGE . "</button>\n"
2406                . "<input type=\"hidden\" name=\"blogid\" value=\"{$vars['blogid']}\" />\n"
2407                . "<input type=\"hidden\" name=\"itemid\" value=\"{$vars['itemid']}\" />\n"
2408                . "<input type=\"hidden\" name=\"search\" value=\"{$vars['search']}\" />\n"
2409                . "<input type=\"hidden\" name=\"amount\" value=\"{$vars['amount']}\" />\n"
2410                . "</form>\n"
2411                . "</td>\n";
2412         $navi .= "<td>\n"
2413                . "<form method=\"post\" action=\"{$CONF['AdminURL']}\">\n"
2414                . "<input type=\"text\" name=\"search\" value=\"{$vars['search']}\" size=\"7\" />\n"
2415                . "<input type=\"hidden\" name=\"start\" value=\"0\" />\n"
2416                . "<button type=\"submit\" name=\"action\" value=\"{$vars['action']}\">&gt; " . _LISTS_SEARCH . "</button>\n"
2417                . "<input type=\"hidden\" name=\"blogid\" value=\"{$vars['blogid']}\" />\n"
2418                . "<input type=\"hidden\" name=\"itemid\" value=\"{$vars['itemid']}\" />\n"
2419                . "<input type=\"hidden\" name=\"search\" value=\"{$vars['search']}\" />\n"
2420                . "<input type=\"hidden\" name=\"amount\" value=\"{$vars['amount']}\" />\n"
2421                . "</form>\n"
2422                . "</td>\n";
2423         $navi .= "<td>\n"
2424                . "<form method=\"post\" action=\"{$CONF['AdminURL']}\">\n"
2425                . "<input type=\"hidden\" name=\"start\" value=\"{$next}\" />\n"
2426                . "<button type=\"submit\" name=\"action\" value=\"{$vars['action']}\">" . _LISTS_NEXT . "&gt; &gt; </button>\n"
2427                . "<input type=\"hidden\" name=\"blogid\" value=\"{$vars['blogid']}\" />\n"
2428                . "<input type=\"hidden\" name=\"itemid\" value=\"{$vars['itemid']}\" />\n"
2429                . "<input type=\"hidden\" name=\"search\" value=\"{$vars['search']}\" />\n"
2430                . "<input type=\"hidden\" name=\"amount\" value=\"{$vars['amount']}\" />\n"
2431                . "</form>\n"
2432                . "</td>\n";
2433         $navi .= "</tr>\n"
2434                . "</table>\n";
2435         
2436         /* HEAD */
2437         $template = $navi;
2438         
2439         /* BODY */
2440         $template .= listplug_batchlist($attribute, $query, $type, $vars, $template_name);
2441         
2442         /* FOOT */
2443         $template .= $navi;
2444         
2445         return $template;
2446 }