Dotclear

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

Revision 1865, 48.3 KB checked in by JcDenis, 13 years ago (diff)

rateIt 0.9.7:

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

Sites map