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 | |
---|
13 | if (!defined('DC_CONTEXT_ADMIN')) return; |
---|
14 | |
---|
15 | class rateItExtList |
---|
16 | { |
---|
17 | protected $core; |
---|
18 | protected $rs; |
---|
19 | protected $rs_count; |
---|
20 | protected $base_url; |
---|
21 | |
---|
22 | public function __construct(&$core,&$rs,$rs_count,$base_url=null) |
---|
23 | { |
---|
24 | $this->core =& $core; |
---|
25 | $this->rs =& $rs; |
---|
26 | $this->rs_count = $rs_count; |
---|
27 | $this->base_url = $base_url; |
---|
28 | $this->html_prev = __('«prev.'); |
---|
29 | $this->html_next = __('next»'); |
---|
30 | |
---|
31 | $this->html_none = '<p><strong>'.__('No entry').'</strong></p>'; |
---|
32 | $this->html = '%1$s'; |
---|
33 | $this->html_pager = '<p>'.__('Page(s)').' : %1$s</p>'; |
---|
34 | $this->html_table = '<table class="clear">%1$s%2$s</table>'; |
---|
35 | $this->html_headline = '<tr %2$s>%1$s</tr>'; |
---|
36 | $this->html_headcell = '<th %2$s>%1$s</th>'; |
---|
37 | $this->html_line = '<tr %2$s>%1$s</tr>'; |
---|
38 | $this->html_cell = '<td %2$s>%1$s</td>'; |
---|
39 | $this->headlines = ''; |
---|
40 | $this->headcells = ''; |
---|
41 | $this->lines = ''; |
---|
42 | $this->cells = ''; |
---|
43 | |
---|
44 | $this->init(); |
---|
45 | } |
---|
46 | |
---|
47 | public function headline($cells,$head='') |
---|
48 | { |
---|
49 | $line = ''; |
---|
50 | foreach($cells AS $content => $extra) { |
---|
51 | $line .= sprintf($this->html_headcell,$content,$extra); |
---|
52 | } |
---|
53 | $this->headlines .= sprintf($this->html_headline,$line,$head); |
---|
54 | } |
---|
55 | |
---|
56 | public function line($cells,$head='') |
---|
57 | { |
---|
58 | $line = ''; |
---|
59 | foreach($cells AS $k => $cell) { |
---|
60 | $line .= sprintf($this->html_cell,$cell[0],$cell[1]); |
---|
61 | } |
---|
62 | $this->lines .= sprintf($this->html_line,$line,$head); |
---|
63 | } |
---|
64 | |
---|
65 | public function display($page,$nb_per_page,$enclose_block='') |
---|
66 | { |
---|
67 | if ($this->rs->isEmpty()) { |
---|
68 | echo $this->html_none; |
---|
69 | } else { |
---|
70 | $pager = new pager($page,$this->rs_count,$nb_per_page,10); |
---|
71 | $pager->base_url = $this->base_url; |
---|
72 | $pager->html_prev = $this->html_prev; |
---|
73 | $pager->html_next = $this->html_next; |
---|
74 | $pager->var_page = 'page'; |
---|
75 | |
---|
76 | while ($this->rs->fetch()) { |
---|
77 | $this->setLine(); |
---|
78 | } |
---|
79 | |
---|
80 | echo |
---|
81 | sprintf($this->html, |
---|
82 | sprintf($enclose_block, |
---|
83 | sprintf($this->html_pager,$pager->getLinks()). |
---|
84 | sprintf($this->html_table,$this->headlines,$this->lines). |
---|
85 | sprintf($this->html_pager,$pager->getLinks()))); |
---|
86 | } |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | # Display admin posts list class |
---|
91 | class rateItPostsList extends rateItExtList |
---|
92 | { |
---|
93 | public function init() |
---|
94 | { |
---|
95 | self::headline(array( |
---|
96 | __('Title') => 'colspan="2"', |
---|
97 | __('Note') => '', |
---|
98 | __('Votes') => '', |
---|
99 | __('Higher') => '', |
---|
100 | __('Lower') => '', |
---|
101 | __('Published on') => '', |
---|
102 | __('Category') => '', |
---|
103 | __('Author') => '', |
---|
104 | __('Status') => '')); |
---|
105 | } |
---|
106 | |
---|
107 | public function setLine() |
---|
108 | { |
---|
109 | if ($this->rs->cat_title) |
---|
110 | $cat_title = html::escapeHTML($this->rs->cat_title); |
---|
111 | else |
---|
112 | $cat_title = __('None'); |
---|
113 | |
---|
114 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
---|
115 | switch ($this->rs->post_status) { |
---|
116 | case 1: $img_status = sprintf($img,__('published'),'check-on.png'); break; |
---|
117 | case 0: $img_status = sprintf($img,__('unpublished'),'check-off.png'); break; |
---|
118 | case -1: $img_status = sprintf($img,__('scheduled'),'scheduled.png'); break; |
---|
119 | case -2: $img_status = sprintf($img,__('pending'),'check-wrn.png'); break; |
---|
120 | } |
---|
121 | |
---|
122 | $protected = ''; |
---|
123 | if ($this->rs->post_password) |
---|
124 | $protected = sprintf($img,__('protected'),'locker.png'); |
---|
125 | |
---|
126 | $selected = ''; |
---|
127 | if ($this->rs->post_selected) |
---|
128 | $selected = sprintf($img,__('selected'),'selected.png'); |
---|
129 | |
---|
130 | $attach = ''; |
---|
131 | $nb_media = $this->rs->countMedia(); |
---|
132 | if ($nb_media > 0) { |
---|
133 | $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments'); |
---|
134 | $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png'); |
---|
135 | } |
---|
136 | |
---|
137 | $q = $this->core->blog->settings->rateit_quotient; |
---|
138 | $d = $this->core->blog->settings->rateit_digit; |
---|
139 | |
---|
140 | self::line( |
---|
141 | array( |
---|
142 | # Title |
---|
143 | array(form::checkbox(array('entries[]'),$this->rs->post_id,'','','',!$this->rs->isEditable()),'class="nowrap"'), |
---|
144 | array('<a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'">'.html::escapeHTML($this->rs->post_title).'</a>','class="maximal"'), |
---|
145 | # Note |
---|
146 | array(round($this->rs->rateit_avg * $q,$d),'class="nowrap"'), |
---|
147 | # Votes |
---|
148 | array('<a title="'.__('Show rating details').'" href="plugin.php?p=rateIt&t=details&type=post&id='.$this->rs->post_id.'">'.$this->rs->rateit_total.'</a>','class="nowrap"'), |
---|
149 | # Higher |
---|
150 | array(round($this->rs->rateit_max * $q,$d),'class="nowrap"'), |
---|
151 | # Lower |
---|
152 | array(round($this->rs->rateit_min * $q,$d),'class="nowrap"'), |
---|
153 | # Post date |
---|
154 | array(dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt),'class="nowrap"'), |
---|
155 | # Category |
---|
156 | array($cat_title,'class="nowrap"'), |
---|
157 | # Author |
---|
158 | array($this->rs->user_id,'class="nowrap"'), |
---|
159 | # Status |
---|
160 | array($img_status.' '.$selected.' '.$protected.' '.$attach,'class="nowrap status"') |
---|
161 | ), |
---|
162 | 'class="line'.($this->rs->post_status != 1 ? ' offline' : '').'" ' |
---|
163 | ); |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | ?> |
---|