Dotclear

source: plugins/rateIt/inc/lib.rateit.index.php @ 1458

Revision 1458, 48.3 KB checked in by JcDenis, 14 years ago (diff)

rateIt 0.9.5:

  • Fixed erreur 1071 in some MySQL servers
  • Added type meta equal to type tag
  • Added support for plugin activityReport
  • Fixed typo
Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3# This file is part of rateIt, a plugin for Dotclear 2.
4#
5# Copyright (c) 2009 JC Denis and contributors
6# jcdenis@gdwd.com
7#
8# Licensed under the GPL version 2.0 license.
9# A copy of this license is available in LICENSE file or at
10# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11#
12# -- END LICENSE BLOCK ------------------------------------
13
14if (!defined('DC_CONTEXT_ADMIN')){return;}
15
16class rateItTabs
17{
18     private static function pictureshow($star)
19     {
20          $s = getimagesize($star['dir']);
21          return
22          '<td><div style="'.
23          '    display:block;'.
24          '    overflow:hidden;'.
25          '    text-indent:-999em;'.
26          '    margin: 0px;'.
27          '    padding: 1px;'.
28          '    background: transparent url('.$star['url'].') no-repeat 0 0;'.
29          '    width:'.$s[0].'px;'.
30          '    height:'.(floor($s[1] /3)-1).'px;'.
31          '">&nbsp;</div></td>'.
32          '<td><div style="'.
33          '    display:block;'.
34          '    overflow:hidden;'.
35          '    text-indent:-999em;'.
36          '    margin: 0px;'.
37          '    padding: 1px;'.
38          '    background: transparent url('.$star['url'].') no-repeat 0 -'.floor($s[1] /3).'px;'.
39          '    width:'.$s[0].'px;'.
40          '    height:'.(floor($s[1] /3)-1).'px;'.
41          '">&nbsp;</div></td>'.
42          '<td><div style="'.
43          '    display:block;'.
44          '    overflow:hidden;'.
45          '    text-indent:-999em;'.
46          '    margin: 0px;'.
47          '    padding: 1px;'.
48          '    background: transparent url('.$star['url'].') no-repeat 0 -'.(floor($s[1] /3) *2).'px;'.
49          '    width:'.$s[0].'px;'.
50          '    height:'.(floor($s[1] /3)-1).'px;'.
51          '">&nbsp;</div></td><td>'.$s[0].'x'.floor($s[1] /3).'</td>';
52     }
53
54     public static function requests($core)
55     {
56          $requests = new ArrayObject();
57          $requests->p_url = 'plugin.php?p=rateIt';
58
59          $requests->msg = isset($_REQUEST['done']) ? __('Configuration saved') : '';
60          $requests->img_green = '<img alt="" src="images/check-on.png" />';
61          $requests->img_red = '<img alt="" src="images/check-off.png" />';
62
63          $requests->user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : '';
64          $requests->cat_id = !empty($_GET['cat_id']) ? $_GET['cat_id'] : '';
65          $requests->status = isset($_GET['status']) ? $_GET['status'] : '';
66          $requests->selected = isset($_GET['selected']) ? $_GET['selected'] : '';
67          $requests->sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'post_dt';
68          $requests->order = !empty($_GET['order']) ? $_GET['order'] : 'desc';
69          $requests->period = !empty($_GET['period']) ? $_GET['period'] : '';
70
71          $requests->page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1;
72          $requests->nb_per_page =  30;
73          if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) {
74               $requests->nb_per_page = (integer) $_GET['nb'];
75          }
76
77          $requests->tab = isset($_REQUEST['t']) ? $_REQUEST['t'] : '';
78          if ('' == $requests->tab)
79               $requests->tab = $core->blog->settings->rateit_active ? 'resum' : 'admin';
80
81          $requests->action = isset($_POST['action']) ? $_POST['action'] : '';
82
83          $requests->id = isset($_GET['id']) ? $_GET['id'] : '';
84          if (!empty($_POST['id'])) 
85               $requests->id = $_POST['id'];
86
87          $requests->type = isset($_GET['type']) ? $_GET['type'] : '';
88          if (!empty($_POST['type'])) 
89               $requests->type = $_POST['type'];
90
91          return $requests;
92     }
93
94     public static function combos($core)
95     {
96          $combos = new ArrayObject();
97          $combos->action = array();
98          if ($core->auth->check('delete,contentadmin',$core->blog->id)) {
99               $combos->action[__('delete rating')] = 'rateit_empty';
100          }
101          if ($core->auth->check('publish,contentadmin',$core->blog->id)) {
102               $combos->action[__('publish')] = 'publish';
103               $combos->action[__('unpublish')] = 'unpublish';
104               $combos->action[__('schedule')] = 'schedule';
105               $combos->action[__('mark as pending')] = 'pending';
106               $combos->action[__('mark as selected')] = 'selected';
107               $combos->action[__('mark as unselected')] = 'unselected';
108          }
109          $combos->action[__('change category')] = 'category';
110          if ($core->auth->check('admin',$core->blog->id)) {
111               $combos->action[__('change author')] = 'author';
112          }
113          if ($core->auth->check('delete,contentadmin',$core->blog->id)) {
114               $combos->action[__('delete')] = 'delete';
115          }
116
117          $combos->categories = array('-'=>'');
118          try {
119               $categories = $core->blog->getCategories(array('post_type'=>'post'));
120          } catch (Exception $e) {
121               $core->error->add($e->getMessage());
122          }
123          while ($categories->fetch()) {
124               $combos->categories[str_repeat('&nbsp;&nbsp;',$categories->level-1).'&bull; '.
125                    html::escapeHTML($categories->cat_title)] = $categories->cat_id;
126          }
127
128          $combos->status = array('-' => '');
129          foreach ($core->blog->getAllPostStatus() as $k => $v) {
130               $status_combo[$v] = (string) $k;
131          }
132
133          $combos->selected = array(
134          '-' => '',
135          __('selected') => '1',
136          __('not selected') => '0'
137          );
138
139          $combos->sortby = array(
140          __('Date') => 'post_dt',
141          __('Votes') => 'rateit_count',
142          __('Title') => 'post_title',
143          __('Category') => 'cat_title',
144          __('Author') => 'user_id',
145          __('Status') => 'post_status',
146          __('Selected') => 'post_selected'
147          );
148
149          $combos->order = array(
150          __('Descending') => 'desc',
151          __('Ascending') => 'asc'
152          );
153
154          return $combos;
155     }
156
157     public static function params($core,$requests,$combos)
158     {
159          $params = array();
160          $params['show_filters'] = false;
161          $params['limit'] = array((($requests->page-1)*$requests->nb_per_page),$requests->nb_per_page);
162          $params['no_content'] = true;
163          $params['rateit_type'] = 'post';
164          $params['post_type'] = 'post';
165
166          if ($requests->cat_id !== '' && in_array($requests->cat_id,$combos->categories)) {
167               $params['cat_id'] = $requests->cat_id;
168               $params['show_filters'] = true;
169          }
170
171          if ($requests->status !== '' && in_array($requests->status,$combos->status)) {
172               $params['post_status'] = $requests->status;
173               $params['show_filters'] = true;
174          }
175
176          if ($requests->selected !== '' && in_array($requests->selected,$combos->selected)) {
177               $params['post_selected'] = $requests->selected;
178               $params['show_filters'] = true;
179          }
180
181          if ($requests->sortby !== '' && in_array($requests->sortby,$combos->sortby)) {
182               if ($requests->order !== '' && in_array($requests->order,$combos->order)) {
183                    $params['order'] = $requests->sortby.' '.$requests->order;
184               }   
185               if ($requests->sortby != 'post_dt' || $requests->order != 'desc') {
186                    $params['show_filters'] = true;
187               }
188          }
189          return $params;
190     }
191
192     public static function settingsTab($core,$requests,$combos)
193     {
194          if (!$core->auth->check('admin',$core->blog->id)) return;
195
196          echo '<div class="multi-part" id="admin" title="'.__('Settings').'">';
197
198          # Save admin options
199          if (!empty($_POST['save']['admin']) && isset($_POST['s'])) {
200               try {
201                    $core->blog->settings->setNamespace('rateit');
202                    $core->blog->settings->put('rateit_active',$_POST['s']['rateit_active'],'boolean','rateit plugin enabled',true,false);
203                    $core->blog->settings->put('rateit_userident',$_POST['s']['rateit_userident'],'integer','rateit use cookie and/or ip',true,false);
204                    $core->blog->settings->put('rateit_dispubjs',$_POST['s']['rateit_dispubjs'],'boolean','disable rateit public javascript',true,false);
205                    $core->blog->settings->put('rateit_dispubcss',$_POST['s']['rateit_dispubcss'],'boolean','disable rateit public css',true,false);
206                    $core->blog->settings->put('rateit_quotient',$_POST['s']['rateit_quotient'],'integer','rateit maximum note',true,false);
207                    $core->blog->settings->put('rateit_digit',$_POST['s']['rateit_digit'],'integer','rateit note digits number',true,false);
208                    $core->blog->settings->put('rateit_msgthanks',$_POST['s']['rateit_msgthanks'],'string','rateit message when voted',true,false);
209
210                    # Destination image according to libImagePath()
211                    $dest_file = DC_ROOT.'/'.$core->blog->settings->public_path.'/rateIt-default-image.png';
212
213                    # Change rate image
214                    if (isset($_POST['s']['starsimage']) && preg_match('/^star-[0-9]+.png$/',$_POST['s']['starsimage'])) {
215
216                         $source = dirname(__FILE__).'/../default-templates/img/stars/'.$_POST['s']['starsimage'];
217
218                         if (file_exists($source))
219                              file_put_contents($dest_file,file_get_contents($source));
220                    }
221                    # Upload rate image
222                    if (isset($_POST['s']['starsimage']) && $_POST['s']['starsimage'] == 'user' && $_FILES['starsuserfile']['tmp_name']) {
223
224                         if (2 == $_FILES['starsuserfile']['error'])
225                              throw new Exception(__('Maximum file size exceeded'));
226
227                         if (0 != $_FILES['starsuserfile']['error'])
228                              throw new Exception(__('Something went wrong while download file'));
229
230                         if ($_FILES['starsuserfile']['type'] != 'image/x-png')
231                              throw new Exception(__('Image must be in png format'));
232
233                         move_uploaded_file($_FILES['starsuserfile']['tmp_name'],$dest_file);
234                    }
235                    $core->blog->triggerBlog();
236                    http::redirect($requests->p_url.'&t=admin&done=1');
237               }
238               catch (Exception $e) {
239                    $core->error->add($e->getMessage());
240               }
241          }
242
243          $combo_quotient = array();
244          for($i=2;$i<21;$i++){ $combo_quotient[$i] = $i; }
245          $combo_digit = array();
246          for($i=0;$i<5;$i++){ $combo_digit[$i] = $i; }
247          $combo_userident = array(__('Ip')=>0,__('Cookie')=>2,__('Both ip and cookie')=>1);
248          # Display
249          echo 
250          '<p>'.__('Administration of options of this extension on this blog').'</p>'.
251          '<form method="post" action="'.$requests->p_url.'" enctype="multipart/form-data">'.
252          '<div class="two-cols">'.
253          '<div class="col">'.
254          '<h2>'.__('Options').'</h2>'.
255          '<table>'.
256          '<tr><th colspan="2">'.__('Extension').'</th></tr>'.
257          '<tr><td>'.__('Enable plugin').'</td><td>'.form::combo(array('s[rateit_active]'),array(__('no')=>0,__('yes')=>1),$core->blog->settings->rateit_active).'</td></tr>'.
258          '<tr><td>'.__('Disable public javascript').'</td><td>'.form::combo(array('s[rateit_dispubjs]'),array(__('no')=>0,__('yes')=>1),$core->blog->settings->rateit_dispubjs).'</td></tr>'.
259          '<tr><td>'.__('Disable public css').'</td><td>'.form::combo(array('s[rateit_dispubcss]'),array(__('no')=>0,__('yes')=>1),$core->blog->settings->rateit_dispubcss).'</td></tr>'.
260          '<tr><td>'.__('Identify users by').'*</td><td>'.form::combo(array('s[rateit_userident]'),$combo_userident,$core->blog->settings->rateit_userident).'</td></tr>'.
261          '<tr><th colspan="2">'.__('Note').'</th></tr>'.
262          '<tr><td>'.__('Note out of').'</td><td>'.form::combo(array('s[rateit_quotient]'),$combo_quotient,$core->blog->settings->rateit_quotient).'</td></tr>'.
263          '<tr><td>'.__('Number of digits').'</td><td>'.form::combo(array('s[rateit_digit]'),$combo_digit,$core->blog->settings->rateit_digit).'</td></tr>'.
264          '<tr><td>'.__('Message of thanks').'**</td><td>'.form::field(array('s[rateit_msgthanks]'),40,255,html::escapeHTML($core->blog->settings->rateit_msgthanks),'',2).'</td></tr>'.
265          '</table>'.
266          '<p class="form-note">*'.__('This disables the file "rateit.css" if you want to include your styles directly in the CSS file of the theme.').'</p>'. 
267          '<p class="form-note">**'.__('This message replaces stars, leave it empty to not replace stars').'</p>'.
268          '<p class="form-note">'.__('In order to change url of public page you can use plugin myUrlHandlers.').'</p>'.
269          '</div>'.
270          '<div class="col">'.
271          '<h2>'.__('Image').'</h2>';
272
273          $stars_rateit_files = files::scandir(dirname(__FILE__).'/../default-templates/img/stars');
274          $stars = libImagePath::getArray($core,'rateIt');
275
276          if (file_exists($stars['theme']['dir'])) {
277               echo 
278               '<p>'.__('Rating image exists on theme it will be used:').'</p>'.
279               form::hidden(array('s[starsimage]'),'theme').
280               '<table><tr><th>'.__('negative').'</th><th>'.__('positive').'</th><th>'.__('hover').'</th><th>'.__('size').'</th></tr>'.
281               '<tr>'.self::pictureshow($stars['theme']).'</tr></table>';
282          } else {
283               echo 
284               '<p>'.__('Rating image not exists on theme choose one to use:').'</p>'.
285               '<table><tr><th>&nbsp;</th><th>'.__('negative').'</th><th>'.__('positive').'</th><th>'.__('hover').'</th><th>'.__('size').'</th></tr>';
286               if (file_exists($stars['public']['dir'])) {
287                    echo 
288                    '<tr><td>'.form::radio(array('s[starsimage]'),'default',1).'</td>'.
289                    self::pictureshow($stars['public']).'</tr>';
290               }
291               elseif (file_exists($stars['module']['dir'])) {
292                    echo 
293                    '<tr><td>'.form::radio(array('s[starsimage]'),'default',1).'</td>'.
294                    self::pictureshow($stars['module']).'</tr>';
295               }
296               sort($stars_rateit_files);
297               foreach($stars_rateit_files AS $f) {
298                    if (!preg_match('/star-[0-9]+.png/',$f)) continue;
299
300                    echo 
301                    '<tr class="line"><td>'.form::radio(array('s[starsimage]'),$f).'</td>'.
302                    self::pictureshow(array(
303                         'dir'=>dirname(__FILE__).'/../default-templates/img/stars/'.$f,
304                         'url'=>'index.php?pf=rateIt/default-templates/img/stars/'.$f)
305                    ).'</tr>';
306               }
307               echo 
308               '<tr class="line"><td>'.form::radio(array('s[starsimage]'),'user').'</td>'.
309               '<td colspan="4">'.form::hidden(array('MAX_FILE_SIZE'),30000).'<input type="file" name="starsuserfile" /></td></tr>'.
310               '</table>'.
311               '<p class="form-note">'.__('Please read the README file before uploading image').'</p>';
312          }
313          echo
314          '</div>'.
315          '</div>'.
316          '<p>'.
317          form::hidden(array('p'),'rateIt').
318          form::hidden(array('t'),'admin').
319          $core->formNonce().
320          '<input type="submit" name="save[admin]" value="'.__('Save').'" /></p>'.
321          '</form>'.
322          '</div>';
323     }
324
325     public static function summaryTab($core)
326     {
327          $rateIt = new rateIt($core);
328          $rateit_types = $rateIt->getTypes();
329          $i = $total = 0;
330          $last = $sort = array();
331
332          foreach($rateit_types AS $type) {
333
334               $rs = $core->con->select(
335               'SELECT rateit_note,rateit_quotient,rateit_time,rateit_ip,rateit_id '.
336               'FROM '.$core->prefix.'rateit WHERE blog_id=\''.$core->blog->id.'\' '.
337               'AND rateit_type=\''.$core->con->escape($type).'\' '.
338               'ORDER BY rateit_time DESC '.$core->con->limit(1));
339               
340               $count = $rateIt->getCount($type);
341               $total += $count;
342
343               if ($rs->isEmpty()) {
344                    $sort[] = $i;
345                    $last[$i] = array('type' => $type,'count' => $count,
346                         'date' => '-','note' => '-','ip' => '-','id' => '-');
347                    $i++;
348               } else {
349                    $sort[] = strtotime($rs->rateit_time);
350                    $last[strtotime($rs->rateit_time)] = array(
351                         'type' => $type,
352                         'count' => $count,
353                         'date' => dt::dt2str(__('%Y-%m-%d %H:%M'),$rs->rateit_time,$core->auth->getInfo('user_tz')),
354                         'note' => ($rs->rateit_note / $rs->rateit_quotient * $core->blog->settings->rateit_quotient).'/'.$core->blog->settings->rateit_quotient,
355                         'ip' => $rs->rateit_ip,
356                         'id' => $rs->rateit_id
357                    );
358               }
359          }
360
361          echo '
362          <div class="multi-part" id="resum" title="'.__('Summary').'">
363          <p>'.sprintf(__('There is a total of %s votes on this blog.'),$total).'</p>
364          <table><tr>
365          <th colspan="2">'.__('Total').'</th>
366          <th colspan="4">'.__('Last').'</th>
367          <tr>
368          <th>'.__('Type').'</th>
369          <th>'.__('Votes').'</th>
370          <th>'.__('Date').'</th>
371          <th>'.__('Note').'</th>
372          <th>'.__('Ip').'</th>
373          <th>'.__('Id').'</th></tr>';
374          rsort($sort);
375          foreach($sort AS $k) {
376               echo 
377               '<tr class="line">'.
378               '<td class="nowrap">'.$last[$k]['type'].'</td>'.
379               '<td class="maximal">'.$last[$k]['count'].'</td>'.
380               '<td class="nowrap">'.$last[$k]['date'].'</td>'.
381               '<td class="nowrap">'.$last[$k]['note'].'</td>'.
382               '<td class="nowrap">'.$last[$k]['ip'].'</td>'.
383               '<td class="nowrap">'.$last[$k]['id'].'</td>'.
384               '</tr>';
385          }
386
387          echo '</table></div>';
388     }
389
390     public static function detailTab($core,$requests)
391     {
392          if (!$core->auth->check('usage,contentadmin',$core->blog->id) || '' == $requests->type || '' == $requests->id) return;
393
394          $rateIt = new rateIt($core);
395
396          if ($requests->action == 'rateit_del_entry' && !empty($_POST['entries'])) {
397               foreach($_POST['entries'] AS $entry) {
398                    $val = explode('|',$entry);
399                    $rateIt->del($val[0],$val[1],$val[2]);
400               }
401               http::redirect($requests->p_url.'&t=details&type='.$requests->type.'&id='.$requests->id.'&done=1');
402          }
403          $rs = $rateIt->getDetails($requests->type,$requests->id);
404
405          $lines = '';
406          while ($rs->fetch()) {
407               $lines .= 
408               '<tr class="line">'.
409               '<td class="nowrap">'.form::checkbox(array('entries[]'),$rs->rateit_type.'|'.$rs->rateit_id.'|'.$rs->rateit_ip,'','','',false).'</td>'.
410               '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$rs->rateit_time,$core->auth->getInfo('user_tz')).'</td>'.
411               '<td class="nowrap">'.$rs->rateit_note.'</td>'.
412               '<td class="nowrap">'.$rs->rateit_quotient.'</td>'.
413               '<td class="nowrap maximal">'.$rs->rateit_ip.'</td>'.
414               '<td class="nowrap">'.$rs->rateit_type.'</td>'.
415               '<td class="nowrap">'.$rs->rateit_id.'</td>'.
416               '</tr>';
417          }
418
419          echo 
420          '<div class="multi-part" id="details" title="'.__('Details').'">'.
421          '<p>'.sprintf(__('This is detailed list for rating of type "%s" and id "%s"'),$requests->type,$requests->id).'</p>'.
422          '<form action="plugin.php" method="post" id="form-details">';
423
424          if ($lines=='') {
425               echo '<p class="message">'.__('There is no rating for this request at this time').'</p>';
426          } else {
427               echo 
428               '<table class="clear"><tr>'.
429               '<th colspan="2">'.__('Date').'</th>'.
430               '<th>'.__('Note').'</th>'.
431               '<th>'.__('Quotient').'</th>'.
432               '<th>'.__('Ip').'</th>'.
433               '<th>'.__('Type').'</th>'.
434               '<th>'.__('Id').'</th>'.
435               '</tr>'.
436               $lines.
437               '</table>';
438          }
439          if ($core->auth->check('delete,contentadmin',$core->blog->id)) {
440               echo 
441               '<div class="two-cols">'.
442               '<p class="col checkboxes-helpers"></p>'.
443               '<p class="col right">'.__('Selected entries action:').' '.
444               form::combo(array('action'),array(__('delete entry') => 'rateit_del_entry')).
445               '<input type="submit" name="save" value="'.__('ok').'" />'.
446               form::hidden(array('p'),'rateIt').
447               form::hidden(array('t'),'details').
448               form::hidden(array('type'),$requests->type).
449               form::hidden(array('id'),$requests->id).
450               $core->formNonce().
451               '</p>'.
452               '</div>';
453          }
454          echo '
455          </form>
456          </div>';
457     }
458
459     public static function postTab($core,$requests,$params,$combos)
460     {
461          if (!$core->auth->check('usage,contentadmin',$core->blog->id)) return;
462
463          if ($core->auth->check('admin',$core->blog->id)
464          && !empty($_POST['save']['post']) && isset($_POST['s'])) {
465               try {
466                    $core->blog->settings->setNamespace('rateit');
467                    $core->blog->settings->put('rateit_post_active',$_POST['s']['rateit_post_active'],'boolean','Enabled post rating',true,false);
468                    $core->blog->settings->put('rateit_poststpl',$_POST['s']['rateit_poststpl'],'boolean','rateit template on post on post page',true,false);
469                    $core->blog->settings->put('rateit_homepoststpl',$_POST['s']['rateit_homepoststpl'],'boolean','rateit template on post on home page',true,false);
470                    $core->blog->settings->put('rateit_tagpoststpl',$_POST['s']['rateit_tagpoststpl'],'boolean','rateit template on post on tag page',true,false);
471                    $core->blog->settings->put('rateit_categorypoststpl',$_POST['s']['rateit_categorypoststpl'],'boolean','rateit template on post on category page',true,false);
472                    $core->blog->settings->put('rateit_categorylimitposts',$_POST['s']['rateit_categorylimitposts'],'integer','rateit limit post vote to one category',true,false);
473                    $core->blog->triggerBlog();
474                    http::redirect($requests->p_url.'&t=post&done=1');
475               }
476               catch (Exception $e) {
477                    $core->error->add($e->getMessage());
478               }
479          }
480
481          $pager_base_url = 
482          $requests->p_url.
483          '&amp;t=post'.
484          '&amp;cat_id='.$requests->cat_id.
485          '&amp;status='.$requests->status.
486          '&amp;selected='.$requests->selected.
487          '&amp;sortby='.$requests->sortby.
488          '&amp;order='.$requests->order.
489          '&amp;nb='.$requests->nb_per_page.
490          '&amp;page=%s';
491
492          try {
493               $rateIt = new rateIt($core);
494               $posts = $rateIt->getPostsByRate($params);
495               $counter = $rateIt->getPostsByRate($params,true);
496               $post_list = new rateItPostsList($core,$posts,$counter->f(0),$pager_base_url);
497          } catch (Exception $e) {
498               $core->error->add($e->getMessage());
499          }
500
501          echo '<div class="multi-part" id="post" title="'.__('Entries').'">';
502
503          if ($core->auth->check('admin',$core->blog->id)) {
504               echo 
505               '<h2 id="post-options-title">'.__('Settings for entries').'</h2>'.
506               '<div id="post-options-content">'.
507               '<form method="post" action="'.$requests->p_url.'">'.
508               '<table>'.
509               '<tr><td>'.__('Enable posts rating').'</td><td>'.form::combo(array('s[rateit_post_active]'),array(__('no')=>0,__('yes')=>1),$core->blog->settings->rateit_post_active).'</td></tr>'.
510               '<tr><td>'.__('Include on entries pages').'*</td><td>'.form::combo(array('s[rateit_poststpl]'),array(__('no')=>0,__('yes')=>1),$core->blog->settings->rateit_poststpl).'</td></tr>'.
511               '<tr><td>'.__('Include on home page').'*</td><td>'.form::combo(array('s[rateit_homepoststpl]'),array(__('no')=>0,__('yes')=>1),$core->blog->settings->rateit_homepoststpl).'</td></tr>'.
512               '<tr><td>'.__('Include on tag page').'*</td><td>'.form::combo(array('s[rateit_tagpoststpl]'),array(__('no')=>0,__('yes')=>1),$core->blog->settings->rateit_tagpoststpl).'</td></tr>'.
513               '<tr><td>'.__('Include on categories page').'*</td><td>'.form::combo(array('s[rateit_categorypoststpl]'),array(__('no')=>0,__('yes')=>1),$core->blog->settings->rateit_categorypoststpl).'</td></tr>'.
514               '<tr><td>'.__('Limit to one category').'</td><td>'.form::combo(array('s[rateit_categorylimitposts]'),$combos->categories,$core->blog->settings->rateit_categorylimitposts).'</td></tr>'.
515               '</table>'.
516               '<p>'.
517               form::hidden(array('p'),'rateIt').
518               form::hidden(array('t'),'post').
519               $core->formNonce().
520               '<input type="submit" name="save[post]" value="'.__('Save').'" /></p>'.
521               '</form>'.
522               '<p class="form-note">* '.__('To use this option you must have behavior "publicEntryAfterContent" in your theme').'</p>'.
523               '</div>';
524          }
525
526          echo 
527          '<h2 id="post-entries-title">'.__('List of entries').'</h2>'.
528          '<div id="post-entries-content">';
529
530          if ($posts->isEmpty())
531               echo '<p class="message">'.__('There is no post rating at this time').'</p>';
532          else {
533               '<p>'.__('This is the list of all entries having rating').'</p>';
534               if (!$params['show_filters']) { 
535                    echo dcPage::jsLoad('js/filter-controls.js').'<p><a id="filter-control" class="form-control" href="#">'.__('Filters').'</a></p>';
536               }
537               echo 
538               '<form action="'.$requests->p_url.'" method="get" id="filters-form">'.
539               '<fieldset><legend>'.__('Filters').'</legend>'.
540               '<div class="three-cols">'.
541               '<div class="col">'.
542               '<label>'.__('Category:').form::combo('cat_id',$combos->categories,$requests->cat_id).'</label> '.
543               '<label>'.__('Status:').form::combo('status',$combos->status,$requests->status).'</label> '.
544               '<label>'.__('Selected:').form::combo('selected',$combos->selected,$requests->selected).'</label> '.
545               '</div>'.
546               '<div class="col">'.
547               '<label>'.__('Order by:').form::combo('sortby',$combos->sortby,$requests->sortby).'</label> '.
548               '<label>'.__('Sort:').form::combo('order',$combos->order,$requests->order).'</label>'.
549               '</div>'.
550               '<div class="col">'.
551               '<p><label class="classic">'.form::field('nb',3,3,$requests->nb_per_page).' '.__('Entries per page').'</label> '.
552               '<input type="submit" value="'.__('filter').'" />'.
553               form::hidden(array('p'),'rateIt').
554               form::hidden(array('t'),'post').
555               $core->formNonce().
556               '</p>'.
557               '</div>'.
558               '</div>'.
559               '<br class="clear" />'.
560               '</fieldset>'.
561               '</form>';
562
563               $post_list->display($requests->page,$requests->nb_per_page,
564                    '<form action="posts_actions.php" method="post" id="form-actions">'.
565                    '%s'.
566                    '<div class="two-cols">'.
567                    '<p class="col checkboxes-helpers"></p>'.
568                    '<p class="col right">'.__('Selected entries action:').' '.
569                    form::combo(array('action'),$combos->action).
570                    '<input type="submit" value="'.__('ok').'" />'.
571                    form::hidden(array('cat_id'),$requests->cat_id).
572                    form::hidden(array('status'),$requests->status).
573                    form::hidden(array('selected'),$requests->selected).
574                    form::hidden(array('sortby'),$requests->sortby).
575                    form::hidden(array('order'),$requests->order).
576                    form::hidden(array('page'),$requests->page).
577                    form::hidden(array('nb'),$requests->nb_per_page).
578                    form::hidden(array('redir'),$requests->p_url.'&amp;t=post').
579                    $core->formNonce().'</p>'.
580                    '</div>'.
581                    '</form>'
582               );
583          }
584          echo '</div></div>';
585     }
586
587     public static function categoryTab($core,$requests)
588     {
589          try {
590               $rateIt = new rateIt($core);
591               $categories = $core->blog->getCategories(array('post_type'=>'post'));
592          } catch (Exception $e) {
593               $core->error->add($e->getMessage());
594          }
595
596          if (isset($_POST['action']) && $_POST['action'] == 'rateit_cat_empty' && isset($_POST['entries'])) {
597               foreach($_POST['entries'] as $cat_id) {
598                    $rateIt->del('category',$cat_id);
599               }
600          }
601
602          if ($core->auth->check('admin',$core->blog->id)
603          && isset($_POST['action']) && $_POST['action'] == 'rateit_cat_active') {
604               $core->blog->settings->setNameSpace('rateit');
605               $core->blog->settings->put('rateit_category_active',true,'boolean','rateit category addon enabled',true,false);
606               $core->blog->triggerBlog();
607               http::redirect('plugin.php?p=rateIt&t=category');
608          }
609
610          if ($core->auth->check('admin',$core->blog->id)
611          && isset($_POST['action']) && $_POST['action'] == 'rateit_cat_unactive') {
612               $core->blog->settings->setNameSpace('rateit');
613               $core->blog->settings->put('rateit_category_active',false,'boolean','rateit category addon enabled',true,false);
614               $core->blog->triggerBlog();
615               http::redirect('plugin.php?p=rateIt&t=category');
616          }
617
618          echo '<div class="multi-part" id="category" title="'.__('Categories').'">';
619
620          if ($core->auth->check('admin',$core->blog->id)
621          && !$core->blog->settings->rateit_category_active) {
622               echo
623               '<form action="plugin.php" method="post" id="form-categories-active"><p>'.
624               '<input type="submit" name="save_category" value="'.__('Activate addon category').'" />'.
625               form::hidden(array('action'),'rateit_cat_active').
626               form::hidden(array('p'),'rateIt').
627               form::hidden(array('t'),'category').
628               $core->formNonce().
629               '</p></form>';
630          }
631          if ($core->blog->settings->rateit_category_active) {
632               if ($core->auth->check('admin',$core->blog->id)) {
633                    echo
634                    '<form action="plugin.php" method="post" id="form-categories-unactive"><p>'.
635                    '<input type="submit" name="save_category" value="'.__('Disactivate addon category').'" />'.
636                    form::hidden(array('action'),'rateit_cat_unactive').
637                    form::hidden(array('p'),'rateIt').
638                    form::hidden(array('t'),'category').
639                    $core->formNonce().
640                    '</p></form>';
641               }
642
643               $table = '';
644               while ($categories->fetch()) {
645                    $rs = $rateIt->get('category',$categories->cat_id);
646                    if (!$rs->total) continue;
647                    $table .= 
648                    '<tr class="line">'.
649                    '<td class="nowrap">'.form::checkbox(array('entries[]'),$categories->cat_id,'','','',false).'</td>'.
650                    '<td class="maximal"><a href="plugin.php?p=rateIt&amp;t=post&amp;cat_id='.$categories->cat_id.'">
651                         '.html::escapeHTML($categories->cat_title).'</a></td>'.
652                    '<td class="nowrap">'.$rs->note.'</td>'.
653                    '<td class="nowrap"><a title="'.__('Show rating details').'" href="plugin.php?p=rateIt&amp;t=details&amp;type=category&amp;id='.$categories->cat_id.'">'.$rs->total.'</a></td>'.
654                    '<td class="nowrap">'.$rs->max.'</td>'.
655                    '<td class="nowrap">'.$rs->min.'</td>'.
656                    '<td class="nowrap">'.$categories->cat_id.'</td>'.
657                    '<td class="nowrap">'.$categories->level.'</td>'.
658                    '<td class="nowrap">'.$categories->nb_post.'</td>'.
659                    '</tr>';
660               }
661
662               if ($table=='')
663                    echo '<p class="message">'.__('There is no category rating at this time').'</p>';
664               else {
665                    echo 
666                    '<p>'.__('This is a list of all the categories having rating').'</p>'.
667                    '<form action="plugin.php" method="post" id="form-categories">'.
668                    '<table class="clear"><tr>'.
669                    '<th colspan="2">'.__('Title').'</th>'.
670                    '<th>'.__('Note').'</th>'.
671                    '<th>'.__('Votes').'</th>'.
672                    '<th>'.__('Higher').'</th>'.
673                    '<th>'.__('Lower').'</th>'.
674                    '<th>'.__('Id').'</th>'.
675                    '<th>'.__('Level').'</th>'.
676                    '<th>'.__('Entries').'</th>'.
677                    '</tr>'.
678                    $table.
679                    '</table>';
680
681                    if ($core->auth->check('delete,contentadmin',$core->blog->id)) {
682                         echo 
683                         '<div class="two-cols">'.
684                         '<p class="col checkboxes-helpers"></p>'.
685                         '<p class="col right">'.__('Selected categories action:').' '.
686                         form::combo(array('action'),array(__('delete rating') => 'rateit_cat_empty')).
687                         '<input type="submit" name="save" value="'.__('ok').'" />'.
688                         form::hidden(array('p'),'rateIt').
689                         form::hidden(array('t'),'category').
690                         $core->formNonce().
691                         '</p>'.
692                         '</div>';
693                    }
694                    echo '</form>';
695               }
696          }
697          echo '</div>';
698     }
699
700     public static function commentTab($core,$requests)
701     {
702          if ($core->auth->check('admin',$core->blog->id)
703          && !empty($_POST['save']['comment']) && isset($_POST['s'])) {
704               try {
705                    $core->blog->settings->setNamespace('rateit');
706                    $core->blog->settings->put('rateit_comment_active',$_POST['s']['rateit_comment_active'],'boolean','Enable comments rating',true,false);
707                    $core->blog->settings->put('rateit_commentstpl',$_POST['s']['rateit_commentstpl'],'boolean','Use comments behavior',true,false);
708                    $core->blog->triggerBlog();
709                    http::redirect($requests->p_url.'&t=comment&done=1');
710               }
711               catch (Exception $e) {
712                    $core->error->add($e->getMessage());
713               }
714          }
715
716          try {
717               $rateIt = new rateIt($core);
718               $comments = $core->blog->getComments(array('post_type'=>'post'));
719          } catch (Exception $e) {
720               $core->error->add($e->getMessage());
721          }
722
723          if (isset($_POST['action']) && $_POST['action'] == 'rateit_comment_empty' && isset($_POST['entries'])) {
724
725               foreach($_POST['entries'] as $comment_id) {
726                    $rateIt->del('comment',$comment_id);
727               }
728          }
729
730          echo '<div class="multi-part" id="comment" title="'.__('Comments').'">';
731
732          if ($core->auth->check('admin',$core->blog->id)) {
733               echo 
734               '<h2 id="comment-options-title">'.__('Settings for comments').'</h2>'.
735               '<div id="comment-options-content">'.
736               '<form method="post" action="'.$requests->p_url.'">'.
737               '<table>'.
738               '<tr><td>'.__('Enable comments rating').'</td><td>'.form::combo(array('s[rateit_comment_active]'),array(__('no')=>0,__('yes')=>1),$core->blog->settings->rateit_comment_active).'</td></tr>'.
739               '<tr><td>'.__('Include on comments').'*</td><td>'.form::combo(array('s[rateit_commentstpl]'),array(__('no')=>0,__('yes')=>1),$core->blog->settings->rateit_commentstpl).'</td></tr>'.
740               '</table>'.
741               '<p>'.
742               form::hidden(array('p'),'rateIt').
743               form::hidden(array('t'),'comment').
744               $core->formNonce().
745               '<input type="submit" name="save[comment]" value="'.__('Save').'" /></p>'.
746               '</form>'.
747               '<p class="form-note">* '.__('To use this option you must have behavior "publicCommentAfterContent" in your theme').'</p>'.
748               '</div>';
749          }
750
751          $table = '';
752          while ($comments->fetch()) {
753               $rs = $rateIt->get('comment',$comments->comment_id);
754               if (!$rs->total) continue;
755               $table .= 
756               '<tr class="line">'.
757               '<td class="nowrap">'.form::checkbox(array('entries[]'),$comments->comment_id,'','','',false).'</td>'.
758               '<td class="maximal"><a href="post.php?id='.$comments->post_id.'">
759                    '.html::escapeHTML($comments->post_title).'</a></td>'.
760               '<td class="nowrap">'.$rs->note.'</td>'.
761               '<td class="nowrap"><a title="'.__('Show rating details').'" href="plugin.php?p=rateIt&amp;t=details&amp;type=comment&amp;id='.$comments->comment_id.'">'.$rs->total.'</a></td>'.
762               '<td class="nowrap">'.$rs->max.'</td>'.
763               '<td class="nowrap">'.$rs->min.'</td>'.
764               '<td class="nowrap">'.$comments->comment_id.'</td>'.
765               '<td class="nowrap">'.$comments->comment_author.'</td>'.
766               '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$comments->comment_dt,$core->auth->getInfo('user_tz')).'</td>'.
767               '</tr>';
768          }
769
770          echo 
771          '<h2 id="comment-entries-title">'.__('List of comments').'</h2>'.
772          '<div id="comment-entries-content">';
773
774          if ($table=='')
775               echo '<p class="message">'.__('There is no comment rating at this time').'</p>';
776          else {
777               echo 
778               '<p>'.__('This is a list of all the comments having rating').'</p>'.
779               '<form action="plugin.php" method="post" id="form-comments">'.
780               '<table class="clear"><tr>'.
781               '<th colspan="2">'.__('Title').'</th>'.
782               '<th>'.__('Note').'</th>'.
783               '<th>'.__('Votes').'</th>'.
784               '<th>'.__('Higher').'</th>'.
785               '<th>'.__('Lower').'</th>'.
786               '<th>'.__('Id').'</th>'.
787               '<th>'.__('Author').'</th>'.
788               '<th>'.__('Date').'</th>'.
789               '</tr>'.
790               $table.
791               '</table>';
792
793               if ($core->auth->check('delete,contentadmin',$core->blog->id)) {
794                    echo 
795                    '<div class="two-cols">'.
796                    '<p class="col checkboxes-helpers"></p>'.
797                    '<p class="col right">'.__('Selected comments action:').' '.
798                    form::combo(array('action'),array(__('delete rating') => 'rateit_comment_empty')).
799                    '<input type="submit" name="save[comment]" value="'.__('ok').'" />'.
800                    form::hidden(array('p'),'rateIt').
801                    form::hidden(array('t'),'comment').
802                    $core->formNonce().
803                    '</p>'.
804                    '</div>';
805               }
806               echo '</form>';
807          }
808          echo '</div></div>';
809     }
810
811     public static function tagTab($core,$requests)
812     {
813          if (!$core->plugins->moduleExists('metadata')) return;
814
815          try {
816               $rateIt = new rateIt($core);
817               $objMeta = new dcMeta($core);
818               $metas = $objMeta->getMeta('tag',null);
819          } catch (Exception $e) {
820               $core->error->add($e->getMessage());
821          }
822
823          if (isset($_POST['action']) && $_POST['action'] == 'rateit_tag_empty' && isset($_POST['entries'])) {
824
825               foreach($_POST['entries'] as $tag_id) {
826                    $rateIt->del('tag',$tag_id);
827               }
828          }
829
830          if ($core->auth->check('admin',$core->blog->id)
831          && isset($_POST['action']) && $_POST['action'] == 'rateit_tag_active') {
832
833               $core->blog->settings->setNameSpace('rateit');
834               $core->blog->settings->put('rateit_tag_active',true,'boolean','rateit tag addon enabled',true,false);
835               $core->blog->triggerBlog();
836               http::redirect('plugin.php?p=rateIt&t=tag');
837          }
838
839          if ($core->auth->check('admin',$core->blog->id)
840          && isset($_POST['action']) && $_POST['action'] == 'rateit_tag_unactive') {
841
842               $core->blog->settings->setNameSpace('rateit');
843               $core->blog->settings->put('rateit_tag_active',false,'boolean','rateit tag addon enabled',true,false);
844               $core->blog->triggerBlog();
845               http::redirect('plugin.php?p=rateIt&t=tag');
846          }
847
848          echo 
849          '<div class="multi-part" id="tag" title="'.__('Tags').'">';
850
851          if ($core->auth->check('admin',$core->blog->id)
852          && !$core->blog->settings->rateit_tag_active) {
853               echo
854               '<form action="plugin.php" method="post" id="form-tags-active"><p>'.
855               '<input type="submit" name="save_tag" value="'.__('Activate addon tag').'" />'.
856               form::hidden(array('action'),'rateit_tag_active').
857               form::hidden(array('p'),'rateIt').
858               form::hidden(array('t'),'tag').
859               $core->formNonce().
860               '</p></form>';
861          }
862          if ($core->blog->settings->rateit_tag_active) {
863               if ($core->auth->check('admin',$core->blog->id)) {
864                    echo
865                    '<form action="plugin.php" method="post" id="form-tags-unactive"><p>'.
866                    '<input type="submit" name="save_tag" value="'.__('Disactivate addon tag').'" />'.
867                    form::hidden(array('action'),'rateit_tag_unactive').
868                    form::hidden(array('p'),'rateIt').
869                    form::hidden(array('t'),'tag').
870                    $core->formNonce().
871                    '</p></form>';
872               }
873
874               $table = '';
875               while ($metas->fetch()) {
876                    $rs = $rateIt->get('tag',$metas->meta_id);
877                    if (!$rs->total) continue;
878                    $table .= 
879                    '<tr class="line">'.
880                    '<td class="nowrap">'.form::checkbox(array('entries[]'),$metas->meta_id,'','','',false).'</td>'.
881                    '<td class="maximal"><a href="plugin.php?p=metadata&amp;m=tag_posts&amp;tag='.$metas->meta_id.'">
882                         '.html::escapeHTML($metas->meta_id).'</a></td>'.
883                    '<td class="nowrap"><a title="'.__('Show rating details').'" href="plugin.php?p=rateIt&amp;t=details&amp;type=tag&amp;id='.$metas->meta_id.'">'.$rs->total.'</a></td>'.
884                    '<td class="nowrap">'.$rs->note.'</td>'.
885                    '<td class="nowrap">'.$rs->max.'</td>'.
886                    '<td class="nowrap">'.$rs->min.'</td>'.
887                    '</tr>';
888               }
889
890               echo 
891               '<p>'.__('This is a list of all the tags having rating').'</p>'.
892               '<form action="plugin.php" method="post" id="form-tags">';
893
894               if ($table=='')
895                    echo '<p class="message">'.__('There is no tag rating at this time').'</p>';
896               else {
897                    echo 
898                    '<table class="clear"><tr>'.
899                    '<th colspan="2">'.__('Title').'</th>'.
900                    '<th>'.__('Votes').'</th>'.
901                    '<th>'.__('Note').'</th>'.
902                    '<th>'.__('Higher').'</th>'.
903                    '<th>'.__('Lower').'</th>'.
904                    '</tr>'.
905                    $table.
906                    '</table>';
907               }
908
909               if ($core->auth->check('delete,contentadmin',$core->blog->id)) {
910                    echo 
911                    '<div class="two-cols">'.
912                    '<p class="col checkboxes-helpers"></p>'.
913                    '<p class="col right">'.__('Selected tags action:').' '.
914                    form::combo(array('action'),array(__('delete rating') => 'rateit_tag_empty')).
915                    '<input type="submit" name="save" value="'.__('ok').'" />'.
916                    form::hidden(array('p'),'rateIt').
917                    form::hidden(array('t'),'tag').
918                    $core->formNonce().
919                    '</p>'.
920                    '</div>';
921               }
922               echo '</form>';
923          }
924          echo '</div>';
925     }
926
927     public static function galleryTab($core,$requests)
928     {
929          if (!$core->plugins->moduleExists('gallery')) return;
930
931          try {
932               $rateIt = new rateIt($core);
933               $galObject = new dcGallery($core);
934               $galleries = $galObject->getGalleries();
935               $galleries_items = $galObject->getGalItems();
936          } catch (Exception $e) {
937               $core->error->add($e->getMessage());
938          }
939
940          if (isset($_POST['action']) && $_POST['action'] == 'rateit_gal_empty' && isset($_POST['entries'])) {
941               foreach($_POST['entries'] as $gal_id) {
942                    $rateIt->del('gal',$gal_id);
943               }
944          }
945
946          if (isset($_POST['action']) && $_POST['action'] == 'rateit_galitem_empty' && isset($_POST['entries'])) {
947               foreach($_POST['entries'] as $galitem_id) {
948                    $rateIt->del('galitem',$galitem_id);
949               }
950          }
951
952          # Save admin options
953          if ($core->auth->check('admin',$core->blog->id)
954          && !empty($_POST['save_gal'])) {
955               try {
956                    $core->blog->settings->setNamespace('rateit');
957                    $core->blog->settings->put('rateit_gal_active',$_POST['rateit_gal_active'],'boolean','rateit addon gallery enabled',true,false);
958                    $core->blog->settings->put('rateit_galitem_active',$_POST['rateit_galitem_active'],'boolean','rateit addon gallery item enabled',true,false);
959                    $core->blog->settings->put('rateit_galtpl',$_POST['rateit_galtpl'],'boolean','rateit template galleries page',true,false);
960                    $core->blog->settings->put('rateit_galitemtpl',$_POST['rateit_galitemtpl'],'boolean','rateit template gallery items page',true,false);
961                    $core->blog->triggerBlog();
962                    http::redirect('plugin.php?p=rateIt&t=gal&done=1');
963               }
964               catch (Exception $e) {
965                    $core->error->add($e->getMessage());
966               }
967          }
968
969          echo '<div class="multi-part" id="gal" title="'.__('Galleries').'">';
970
971          if ($core->auth->check('admin',$core->blog->id)) {
972               echo
973               '<h2 id="gallery-options-title">'.__('Settings for galleries').'</h2>'.
974               '<div id="gallery-options-content">'.
975               '<form method="post" action="plugin.php">'.
976               '<table>'.
977               '<tr><td>'.__('Enable addon gallery').'</td><td>'.form::combo(array('rateit_gal_active'),array(__('no')=>0,__('yes')=>1),$core->blog->settings->rateit_gal_active).'</td></tr>'.
978               '<tr><td>'.__('Enable addon gallery item').'</td><td>'.form::combo(array('rateit_galitem_active'),array(__('no')=>0,__('yes')=>1),$core->blog->settings->rateit_galitem_active).'</td></tr>'.
979               '<tr><td>'.__('Include on galleries page').'*</td><td>'.form::combo(array('sateit_galtpl'),array(__('no')=>0,__('yes')=>1),$core->blog->settings->rateit_galtpl).'</td></tr>'.
980               '<tr><td>'.__('Include on gallery items pages').'*</td><td>'.form::combo(array('rateit_galitemtpl'),array(__('no')=>0,__('yes')=>1),$core->blog->settings->rateit_galitemtpl).'</td></tr>'.
981               '</table>'.
982               '<p>'.
983               form::hidden(array('p'),'rateIt').
984               form::hidden(array('t'),'gal').
985               $core->formNonce().
986               '<input type="submit" name="save_gal" value="'.__('Save').'" /></p>'.
987               '</form>'.
988               '<p class="form-note">* '.__('To use this option you must have behavior "publicEntryAfterContent" in your theme').'</p>'.
989               '</div>';
990          }
991
992          if ($core->blog->settings->rateit_gal_active) {
993
994               $table = '';
995               while ($galleries->fetch()) {
996                    $rs = $rateIt->get('gal',$galleries->post_id);
997                    if (!$rs->total) continue;
998                    $table .= 
999                    '<tr class="line">'.
1000                    '<td class="nowrap">'.form::checkbox(array('entries[]'),$galleries->post_id,'','','',false).'</td>'.
1001                    '<td class="maximal"><a href="plugin.php?p=gallery&amp;m=gal&amp;id='.$galleries->post_id.'">
1002                         '.html::escapeHTML($galleries->post_title).'</a></td>'.
1003                    '<td class="nowrap"><a title="'.__('Show rating details').'" href="plugin.php?p=rateIt&amp;t=details&amp;type=gal&amp;id='.$galleries->post_id.'">'.$rs->total.'</a></td>'.
1004                    '<td class="nowrap">'.$rs->note.'</td>'.
1005                    '<td class="nowrap">'.$rs->max.'</td>'.
1006                    '<td class="nowrap">'.$rs->min.'</td>'.
1007                    '</tr>';
1008               }
1009
1010               echo 
1011               '<h2 id="gallery-gals-title">'.__('List of galleries').'</h2>'.
1012               '<div id="gallery-gals-content">'.
1013               '<p>'.__('This is a list of all the galleries having rating').'</p>'.
1014               '<form action="plugin.php" method="post" id="form-gal">';
1015
1016               if ($table=='')
1017                    echo '<p class="message">'.__('There is no gallery rating at this time').'</p>';
1018               else {
1019                    echo 
1020                    '<table class="clear"><tr>'.
1021                    '<th colspan="2">'.__('Title').'</th>'.
1022                    '<th>'.__('Votes').'</th>'.
1023                    '<th>'.__('Note').'</th>'.
1024                    '<th>'.__('Higher').'</th>'.
1025                    '<th>'.__('Lower').'</th>'.
1026                    '</tr>'.
1027                    $table.
1028                    '</table>';
1029               }
1030
1031               if ($core->auth->check('delete,contentadmin',$core->blog->id)) {
1032                    echo 
1033                    '<div class="two-cols">'.
1034                    '<p class="col checkboxes-helpers"></p>'.
1035                    '<p class="col right">'.__('Selected galeries action:').' '.
1036                    form::combo(array('action'),array(__('delete rating') => 'rateit_gal_empty')).
1037                    '<input type="submit" name="save" value="'.__('ok').'" />'.
1038                    form::hidden(array('p'),'rateIt').
1039                    form::hidden(array('t'),'gal').
1040                    $core->formNonce().
1041                    '</p>'.
1042                    '</div>';
1043               }
1044               echo '</form></div>';
1045          }
1046
1047          if ($core->blog->settings->rateit_galitem_active) {
1048
1049               $table = '';
1050               while ($galleries_items->fetch()) {
1051                    $rs = $rateIt->get('galitem',$galleries_items->post_id);
1052                    if (!$rs->total) continue;
1053                    $table .= 
1054                    '<tr class="line">'.
1055                    '<td class="nowrap">'.form::checkbox(array('entries[]'),$galleries_items->post_id,'','','',false).'</td>'.
1056                    '<td class="maximal"><a href="plugin.php?p=gallery&amp;m=item&amp;id='.$galleries_items->post_id.'">
1057                         '.html::escapeHTML($galleries_items->post_title).'</a></td>'.
1058                    '<td class="nowrap"><a title="'.__('Show rating details').'" href="plugin.php?p=rateIt&amp;t=details&amp;type=galitem&amp;id='.$galleries_items->post_id.'">'.$rs->total.'</a></td>'.
1059                    '<td class="nowrap">'.$rs->note.'</td>'.
1060                    '<td class="nowrap">'.$rs->max.'</td>'.
1061                    '<td class="nowrap">'.$rs->min.'</td>'.
1062                    '</tr>';
1063               }
1064
1065               echo 
1066               '<h2 id="gallery-galitems-title">'.__('List of images').'</h2>'.
1067               '<div id="gallery-galitems-content">'.
1068               '<p>'.__('This is a list of all the galleries items having rating').'</p>'.
1069               '<form action="plugin.php" method="post" id="form-galitem">';
1070
1071               if ($table=='')
1072                    echo '<p class="message">'.__('There is no gallery item rating at this time').'</p>';
1073               else {
1074                    echo 
1075                    '<table class="clear"><tr>'.
1076                    '<th colspan="2">'.__('Title').'</th>'.
1077                    '<th>'.__('Votes').'</th>'.
1078                    '<th>'.__('Note').'</th>'.
1079                    '<th>'.__('Higher').'</th>'.
1080                    '<th>'.__('Lower').'</th>'.
1081                    '</tr>'.
1082                    $table.
1083                    '</table>';
1084               }
1085
1086               if ($core->auth->check('delete,contentadmin',$core->blog->id)) {
1087                    echo 
1088                    '<div class="two-cols">'.
1089                    '<p class="col checkboxes-helpers"></p>'.
1090                    '<p class="col right">'.__('Selected galeries items action:').' '.
1091                    form::combo(array('action'),array(__('delete rating') => 'rateit_galitem_empty')).
1092                    '<input type="submit" name="save" value="'.__('ok').'" />'.
1093                    form::hidden(array('p'),'rateIt').
1094                    form::hidden(array('t'),'gal').
1095                    $core->formNonce().
1096                    '</p>'.
1097                    '</div>';
1098               }
1099               echo '</form></div>';
1100          }
1101          echo '</div>';
1102     }
1103}
1104
1105class rateItExtList
1106{
1107     protected $core;
1108     protected $rs;
1109     protected $rs_count;
1110     protected $base_url;
1111
1112     public function __construct($core,$rs,$rs_count,$base_url=null)
1113     {
1114          $this->core =& $core;
1115          $this->rs =& $rs;
1116          $this->rs_count = $rs_count;
1117          $this->base_url = $base_url;
1118          $this->html_prev = __('&#171;prev.');
1119          $this->html_next = __('next&#187;');
1120
1121          $this->html_none = '<p><strong>'.__('No entry').'</strong></p>';
1122          $this->html = '%1$s';
1123          $this->html_pager =  '<p>'.__('Page(s)').' : %1$s</p>';
1124          $this->html_table = '<table class="clear">%1$s%2$s</table>';
1125          $this->html_headline = '<tr %2$s>%1$s</tr>';
1126          $this->html_headcell = '<th %2$s>%1$s</th>';
1127          $this->html_line = '<tr %2$s>%1$s</tr>';
1128          $this->html_cell = '<td %2$s>%1$s</td>';
1129          $this->headlines = '';
1130          $this->headcells = '';
1131          $this->lines = '';
1132          $this->cells = '';
1133
1134          $this->rateit = new rateIt($core);
1135
1136          $this->init();
1137     }
1138
1139     public function headline($cells,$head='')
1140     {
1141          $line = '';
1142          foreach($cells AS $content => $extra) {
1143               $line .= sprintf($this->html_headcell,$content,$extra);
1144          }
1145          $this->headlines .= sprintf($this->html_headline,$line,$head);
1146     }
1147
1148     public function line($cells,$head='')
1149     {
1150          $line = '';
1151          foreach($cells AS $k => $cell) {
1152               $line .= sprintf($this->html_cell,$cell[0],$cell[1]);
1153          }
1154          $this->lines .= sprintf($this->html_line,$line,$head);
1155     }
1156
1157     public function display($page,$nb_per_page,$enclose_block='')
1158     {
1159          if ($this->rs->isEmpty()) {
1160               echo $this->html_none;
1161          } else {
1162               $pager = new pager($page,$this->rs_count,$nb_per_page,10);
1163               $pager->base_url = $this->base_url;
1164               $pager->html_prev = $this->html_prev;
1165               $pager->html_next = $this->html_next;
1166               $pager->var_page = 'page';
1167
1168               while ($this->rs->fetch()) {
1169                    $this->setLine();
1170               }
1171
1172               echo
1173               sprintf($this->html,
1174                    sprintf($enclose_block,
1175                         sprintf($this->html_pager,$pager->getLinks()).
1176                              sprintf($this->html_table,$this->headlines,$this->lines).
1177                         sprintf($this->html_pager,$pager->getLinks())));
1178          }
1179     }
1180}
1181
1182# Display admin posts list class
1183class rateItPostsList extends rateItExtList
1184{
1185     protected $core;
1186     protected $rs;
1187     protected $rs_count;
1188     protected $base_url;
1189
1190     public function init()
1191     {
1192          self::headline(array(
1193               __('Title') => 'colspan="2"',
1194               __('Votes') => '',
1195               __('Note') => '',
1196               __('Higher') => '',
1197               __('Lower') => '',
1198               __('Published on') => '',
1199               __('Category') => '',
1200               __('Author') => '',
1201               __('Status') => ''));
1202     }
1203     
1204     public function setLine()
1205     {
1206          if ($this->rs->cat_title)
1207               $cat_title = html::escapeHTML($this->rs->cat_title);
1208          else
1209               $cat_title = __('None');
1210
1211          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
1212          switch ($this->rs->post_status) {
1213               case 1:  $img_status = sprintf($img,__('published'),'check-on.png'); break;
1214               case 0:  $img_status = sprintf($img,__('unpublished'),'check-off.png'); break;
1215               case -1: $img_status = sprintf($img,__('scheduled'),'scheduled.png'); break;
1216               case -2: $img_status = sprintf($img,__('pending'),'check-wrn.png'); break;
1217          }
1218
1219          $protected = '';
1220          if ($this->rs->post_password)
1221               $protected = sprintf($img,__('protected'),'locker.png');
1222
1223          $selected = '';
1224          if ($this->rs->post_selected)
1225               $selected = sprintf($img,__('selected'),'selected.png');
1226
1227          $attach = '';
1228          $nb_media = $this->rs->countMedia();
1229          if ($nb_media > 0) {
1230               $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments');
1231               $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png');
1232          }
1233         
1234          $q = $this->core->blog->settings->rateit_quotient;
1235          $d = $this->core->blog->settings->rateit_digit;
1236         
1237          $r = $this->rateit->get('post',$this->rs->post_id);
1238
1239          self::line(
1240               array(
1241                    # Title
1242                    array(form::checkbox(array('entries[]'),$this->rs->post_id,'','','',!$this->rs->isEditable()),'class="nowrap"'),
1243                    array('<a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'">'.html::escapeHTML($this->rs->post_title).'</a>','class="maximal"'),
1244                    # Votes
1245                    array('<a title="'.__('Show rating details').'" href="plugin.php?p=rateIt&amp;t=details&amp;type=post&amp;id='.$this->rs->post_id.'">'.$r->total.'</a>','class="nowrap"'),
1246                    # Note
1247                    array($r->note,'class="nowrap"'),
1248                    # Higher
1249                    array($r->max,'class="nowrap"'),
1250                    # Lower
1251                    array($r->min,'class="nowrap"'),
1252                    # Post date
1253                    array(dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt,$this->core->auth->getInfo('user_tz')),'class="nowrap"'),
1254                    # Category
1255                    array($cat_title,'class="nowrap"'),
1256                    # Author
1257                    array($this->rs->user_id,'class="nowrap"'),
1258                    # Status
1259                    array($img_status.' '.$selected.' '.$protected.' '.$attach,'class="nowrap status"')
1260               ),
1261               'class="line'.($this->rs->post_status != 1 ? ' offline' : '').'" '
1262          );
1263     }
1264}
1265?>
Note: See TracBrowser for help on using the repository browser.

Sites map