Changeset 3707:3a350757c847 for inc/admin
- Timestamp:
- 02/17/18 18:03:29 (7 years ago)
- Branch:
- default
- Location:
- inc/admin
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/admin/actions/class.dcaction.php
r2888 r3707 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_RC_PATH')) { return;}12 if (!defined('DC_RC_PATH')) {return;} 13 13 14 14 /** 15 * dcActionsPage -- handler for action page on selected entries16 *17 */15 * dcActionsPage -- handler for action page on selected entries 16 * 17 */ 18 18 abstract class dcActionsPage 19 19 { 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 20 /** @var string form submit uri */ 21 protected $uri; 22 /** @var dcCore dotclear core instance */ 23 protected $core; 24 /** @var array action combo box */ 25 protected $combo; 26 /** @var array list of defined actions (callbacks) */ 27 protected $actions; 28 /** @var array selected entries (each key is the entry id, value contains the entry description) */ 29 protected $entries; 30 /** @var record record that challenges ids against permissions */ 31 protected $rs; 32 /** @var array redirection $_GET arguments, if any (does not contain ids by default, ids may be merged to it) */ 33 protected $redir_args; 34 /** @var array list of $_POST fields used to build the redirection */ 35 protected $redirect_fields; 36 /** @var string redirection anchor if any */ 37 protected $redir_anchor; 38 39 /** @var string current action, if any */ 40 protected $action; 41 /** @var array list of url parameters (usually $_POST) */ 42 protected $from; 43 /** @var string form field name for "entries" (usually "entries") */ 44 protected $field_entries; 45 46 /** @var string title for checkboxes list, if displayed */ 47 protected $cb_title; 48 49 /** @var string title for caller page title */ 50 protected $caller_title; 51 52 /** @var boolean true if we are acting inside a plugin (different handling of begin/endpage) */ 53 protected $in_plugin; 54 55 /** @var boolean true if we enable to keep selection when redirecting */ 56 protected $enable_redir_selection; 57 57 58 58 /** … … 66 66 * @return mixed Value. 67 67 */ 68 public function __construct($core,$uri,$redirect_args=array()) { 69 $this->core = $core; 70 $this->actions = new ArrayObject(); 71 $this->combo = array(); 72 $this->uri = $uri; 73 $this->redir_args = $redirect_args; 74 $this->redirect_fields = array(); 75 $this->action = ''; 76 $this->cb_title = __('Title'); 77 $this->entries = array(); 78 $this->from = new ArrayObject($_POST); 79 $this->field_entries = 'entries'; 80 $this->caller_title = __('Entries'); 81 if (isset($this->redir_args['_ANCHOR'])) { 82 $this->redir_anchor = '#'.$this->redir_args['_ANCHOR']; 83 unset($this->redir_args['_ANCHOR']); 84 } else { 85 $this->redir_anchor=''; 86 } 87 $u=explode('?',$_SERVER['REQUEST_URI']); 88 $this->in_plugin = (strpos($u[0],'plugin.php') !== false); 89 $this->enable_redir_selection = true; 90 } 68 public function __construct($core, $uri, $redirect_args = array()) 69 { 70 $this->core = $core; 71 $this->actions = new ArrayObject(); 72 $this->combo = array(); 73 $this->uri = $uri; 74 $this->redir_args = $redirect_args; 75 $this->redirect_fields = array(); 76 $this->action = ''; 77 $this->cb_title = __('Title'); 78 $this->entries = array(); 79 $this->from = new ArrayObject($_POST); 80 $this->field_entries = 'entries'; 81 $this->caller_title = __('Entries'); 82 if (isset($this->redir_args['_ANCHOR'])) { 83 $this->redir_anchor = '#' . $this->redir_args['_ANCHOR']; 84 unset($this->redir_args['_ANCHOR']); 85 } else { 86 $this->redir_anchor = ''; 87 } 88 $u = explode('?', $_SERVER['REQUEST_URI']); 89 $this->in_plugin = (strpos($u[0], 'plugin.php') !== false); 90 $this->enable_redir_selection = true; 91 } 91 92 92 93 /** 93 94 * setEnableRedirSelection - define whether to keep selection when redirecting 94 *Can be usefull to be disabled to preserve some compatibility.95 * Can be usefull to be disabled to preserve some compatibility. 95 96 * 96 97 * @param boolean $enable true to enable, false otherwise 97 * 98 * @access public 99 */ 100 public function setEnableRedirSelection($enable) { 101 $this->enable_redir_selection = $enable; 102 } 98 * 99 * @access public 100 */ 101 public function setEnableRedirSelection($enable) 102 { 103 $this->enable_redir_selection = $enable; 104 } 103 105 104 106 /** … … 106 108 * 107 109 * @param string $actions the actions names as if it was a standalone combo array. 108 *It will be merged with other actions.109 *Can be bound to multiple values, if the same callback is to be called110 * It will be merged with other actions. 111 * Can be bound to multiple values, if the same callback is to be called 110 112 * @param callback $callback the callback for the action. 111 113 * 112 114 * @access public 113 115 * 114 116 * @return dcActionsPage the actions page itself, enabling to chain addAction(). 115 117 */ 116 public function addAction ($actions,$callback) { 117 foreach ($actions as $k => $a) { 118 // Check each case of combo definition 119 // Store form values in $values 120 if (is_array($a)) { 121 $values = array_values($a); 122 if (!isset($this->combo[$k])) { 123 $this->combo[$k]=array(); 124 } 125 $this->combo[$k] = array_merge ($this->combo[$k],$a); 126 } elseif ($a instanceof formSelectOption) { 127 $values = array($a->value); 128 $this->combo[$k] = $a->value; 129 } else { 130 $values = array($a); 131 $this->combo[$k] = $a; 132 } 133 // Associate each potential value to the callback 134 foreach ($values as $v) { 135 $this->actions[$v]=$callback; 136 } 137 } 138 return $this; 139 } 118 public function addAction($actions, $callback) 119 { 120 foreach ($actions as $k => $a) { 121 // Check each case of combo definition 122 // Store form values in $values 123 if (is_array($a)) { 124 $values = array_values($a); 125 if (!isset($this->combo[$k])) { 126 $this->combo[$k] = array(); 127 } 128 $this->combo[$k] = array_merge($this->combo[$k], $a); 129 } elseif ($a instanceof formSelectOption) { 130 $values = array($a->value); 131 $this->combo[$k] = $a->value; 132 } else { 133 $values = array($a); 134 $this->combo[$k] = $a; 135 } 136 // Associate each potential value to the callback 137 foreach ($values as $v) { 138 $this->actions[$v] = $callback; 139 } 140 } 141 return $this; 142 } 140 143 141 144 /** … … 143 146 * 144 147 * @access public 145 148 * 146 149 * @return array the actions combo 147 150 */ 148 public function getCombo() { 149 return $this->combo; 150 } 151 151 public function getCombo() 152 { 153 return $this->combo; 154 } 152 155 153 156 /** … … 155 158 * 156 159 * @access public 157 160 * 158 161 * @return array the list 159 162 */ 160 public function getIDs() { 161 return array_keys($this->entries); 162 } 163 public function getIDs() 164 { 165 return array_keys($this->entries); 166 } 163 167 164 168 /** … … 166 170 * 167 171 * @access public 168 172 * 169 173 * @return string the HTML code for hidden fields 170 174 */ 171 public function getIDsHidden() { 172 $ret = ''; 173 foreach ($this->entries as $id=>$v) { 174 $ret .= form::hidden($this->field_entries.'[]',$id); 175 } 176 return $ret; 177 } 175 public function getIDsHidden() 176 { 177 $ret = ''; 178 foreach ($this->entries as $id => $v) { 179 $ret .= form::hidden($this->field_entries . '[]', $id); 180 } 181 return $ret; 182 } 178 183 179 184 /** … … 181 186 * 182 187 * @param boolean $with_ids if true, also include ids in HTML code 183 184 * @access public 185 188 * 189 * @access public 190 * 186 191 * @return string the HTML code for hidden fields 187 192 */ 188 public function getHiddenFields($with_ids = false) { 189 $ret = ''; 190 foreach ($this->redir_args as $k => $v) { 191 $ret .= form::hidden(array($k),$v); 192 } 193 if ($with_ids) { 194 $ret .= $this->getIDsHidden(); 195 } 196 return $ret; 197 } 198 199 200 193 public function getHiddenFields($with_ids = false) 194 { 195 $ret = ''; 196 foreach ($this->redir_args as $k => $v) { 197 $ret .= form::hidden(array($k), $v); 198 } 199 if ($with_ids) { 200 $ret .= $this->getIDsHidden(); 201 } 202 return $ret; 203 } 204 205 /** 201 206 * getRS() - get record from DB Query containing requested IDs 202 207 * 203 208 * @param boolean $with_ids if true, also include ids in HTML code 204 205 * @access public 206 209 * 210 * @access public 211 * 207 212 * @return string the HTML code for hidden fields 208 213 */ 209 public function getRS() { 210 return $this->rs; 211 } 212 213 /** 214 public function getRS() 215 { 216 return $this->rs; 217 } 218 219 /** 214 220 * setupRedir - setup redirection arguments 215 216 221 * by default, $_POST fields as defined in redirect_fields attributes 222 * are set into redirect_args. 217 223 * 218 224 * @param array $from input to parse fields from (usually $_POST) 219 225 * 220 226 * @access protected 221 227 */ 222 protected function setupRedir($from) { 223 foreach ($this->redirect_fields as $p){224 if (isset($from[$p])) {225 $this->redir_args[$p] = $from[$p]; 226 } 227 228 229 230 231 228 protected function setupRedir($from) 229 { 230 foreach ($this->redirect_fields as $p) { 231 if (isset($from[$p])) { 232 $this->redir_args[$p] = $from[$p]; 233 } 234 } 235 } 236 237 /** 232 238 * getRedirection - returns redirection URL 233 239 * 234 240 * @param array $params extra parameters to append to redirection 235 *must be an array : each key is the name,236 *each value is the wanted value241 * must be an array : each key is the name, 242 * each value is the wanted value 237 243 * @param boolean $with_selected_entries if true, add selected entries in url 238 239 * @access public 240 244 * 245 * @access public 246 * 241 247 * @return string the redirection url 242 248 */ 243 public function getRedirection($with_selected_entries=false,$params=array()) { 244 $redir_args = array_merge($params,$this->redir_args); 245 if (isset($redir_args['redir'])) { 246 unset($redir_args['redir']); 247 } 248 249 if ($with_selected_entries && $this->enable_redir_selection) { 250 $redir_args[$this->field_entries] = array_keys($this->entries); 251 } 252 return $this->uri.'?'.http_build_query($redir_args).$this->redir_anchor; 253 } 254 255 /** 249 public function getRedirection($with_selected_entries = false, $params = array()) 250 { 251 $redir_args = array_merge($params, $this->redir_args); 252 if (isset($redir_args['redir'])) { 253 unset($redir_args['redir']); 254 } 255 256 if ($with_selected_entries && $this->enable_redir_selection) { 257 $redir_args[$this->field_entries] = array_keys($this->entries); 258 } 259 return $this->uri . '?' . http_build_query($redir_args) . $this->redir_anchor; 260 } 261 262 /** 256 263 * redirect - redirects to redirection page 257 264 * 258 * @see getRedirection for arguments details 259 * 260 * @access public 261 */ 262 public function redirect($with_selected_entries=false,$params=array()) { 263 http::redirect($this->getRedirection($with_selected_entries,$params)); 264 exit; 265 } 266 267 /** 265 * @see getRedirection for arguments details 266 * 267 * @access public 268 */ 269 public function redirect($with_selected_entries = false, $params = array()) 270 { 271 http::redirect($this->getRedirection($with_selected_entries, $params)); 272 exit; 273 } 274 275 /** 268 276 * getURI - returns current form URI, if any 269 277 * 270 278 * @access public 271 279 * 272 280 * @return string the form URI 273 281 */ 274 public function getURI() { 275 return $this->uri; 276 } 277 278 /** 282 public function getURI() 283 { 284 return $this->uri; 285 } 286 287 /** 279 288 * getCallerTitle - returns current form URI, if any 280 289 * 281 290 * @access public 282 291 * 283 292 * @return string the form URI 284 293 */ 285 public function getCallerTitle() { 286 return $this->caller_title; 287 } 288 289 /** 294 public function getCallerTitle() 295 { 296 return $this->caller_title; 297 } 298 299 /** 290 300 * getAction - returns current action, if any 291 301 * 292 302 * @access public 293 303 * 294 304 * @return string the action 295 305 */ 296 public function getAction() { 297 return $this->action; 298 } 299 300 /** 306 public function getAction() 307 { 308 return $this->action; 309 } 310 311 /** 301 312 * process - proceeds action handling, if any 302 * this method may issue an exit() if 303 * an action is being processed. If it 304 * returns, no action has been performed 305 * 306 * @access public 307 */ 308 public function process() { 309 310 $this->setupRedir($this->from); 311 $this->fetchEntries($this->from); 312 if (isset($this->from['action'])) { 313 $this->action = $this->from['action']; 314 try { 315 $performed=false; 316 foreach ($this->actions as $k=>$v) { 317 if ($this->from['action']==$k) { 318 $performed = true; 319 call_user_func($v,$this->core,$this,$this->from); 320 } 321 } 322 if ($performed) { 323 return true; 324 } 325 } catch (Exception $e) { 326 $this->error($e); 327 return true; 328 } 329 } 330 } 331 332 /** 313 * this method may issue an exit() if 314 * an action is being processed. If it 315 * returns, no action has been performed 316 * 317 * @access public 318 */ 319 public function process() 320 { 321 322 $this->setupRedir($this->from); 323 $this->fetchEntries($this->from); 324 if (isset($this->from['action'])) { 325 $this->action = $this->from['action']; 326 try { 327 $performed = false; 328 foreach ($this->actions as $k => $v) { 329 if ($this->from['action'] == $k) { 330 $performed = true; 331 call_user_func($v, $this->core, $this, $this->from); 332 } 333 } 334 if ($performed) { 335 return true; 336 } 337 } catch (Exception $e) { 338 $this->error($e); 339 return true; 340 } 341 } 342 } 343 344 /** 333 345 * getcheckboxes -returns html code for selected entries 334 *as a table containing entries checkboxes335 * 336 * @access public 337 346 * as a table containing entries checkboxes 347 * 348 * @access public 349 * 338 350 * @return string the html code for checkboxes 339 351 */ 340 public function getCheckboxes() { 341 $ret = 342 '<table class="posts-list"><tr>'. 343 '<th colspan="2">'.$this->cb_title.'</th>'. 344 '</tr>'; 345 foreach ($this->entries as $id=>$title) { 346 $ret .= 347 '<tr><td class="minimal">'. 348 form::checkbox(array($this->field_entries.'[]'),$id,true,'','').'</td>'. 349 '<td>'. $title.'</td></tr>'; 350 } 351 $ret .= '</table>'; 352 return $ret; 353 } 354 355 /** 352 public function getCheckboxes() 353 { 354 $ret = 355 '<table class="posts-list"><tr>' . 356 '<th colspan="2">' . $this->cb_title . '</th>' . 357 '</tr>'; 358 foreach ($this->entries as $id => $title) { 359 $ret .= 360 '<tr><td class="minimal">' . 361 form::checkbox(array($this->field_entries . '[]'), $id, array( 362 'checked' => true 363 )) . 364 '</td>' . 365 '<td>' . $title . '</td></tr>'; 366 } 367 $ret .= '</table>'; 368 return $ret; 369 } 370 371 /** 356 372 * beginPage, endPage - displays the beginning/ending of a page, if action does not redirects dirtectly 357 373 * 358 359 374 * These methods are called from the actions themselves. 375 * 360 376 * @param string $breadcrumb breadcrumb to display 361 * @param string $head 362 363 * @access public 364 */ 365 abstract public function beginPage($breadcrumb='',$head='');366 367 368 377 * @param string $head page header to include 378 * 379 * @access public 380 */ 381 abstract public function beginPage($breadcrumb = '', $head = ''); 382 abstract public function endPage(); 383 384 /** 369 385 * fetchEntries - fills-in information by requesting into db 370 *this method may setup the following attributes371 372 386 * this method may setup the following attributes 387 * * entries : list of entries (checked against permissions) 388 * entries ids are array keys, values contain entry description (if relevant) 373 389 * * rs : record given by db request 374 390 * @access protected 375 391 */ 376 392 abstract protected function fetchEntries($from); 377 393 378 394 } -
inc/admin/actions/class.dcactionblogs.php
r3627 r3707 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_RC_PATH')) { return;}12 if (!defined('DC_RC_PATH')) {return;} 13 13 14 14 class dcBlogsActionsPage extends dcActionsPage 15 15 { 16 public function __construct($core,$uri,$redirect_args=array()) { 17 parent::__construct($core,$uri,$redirect_args); 18 $this->redirect_fields = array('status','sortby','order','page','nb'); 19 $this->field_entries = 'blogs'; 20 $this->title_cb = __('Blogs'); 21 $this->loadDefaults(); 22 $core->callBehavior('adminBlogsActionsPage',$core,$this); 23 } 24 25 protected function loadDefaults() { 26 // We could have added a behavior here, but we want default action 27 // to be setup first 28 dcDefaultBlogActions::adminBlogsActionsPage($this->core,$this); 29 } 30 31 public function beginPage($breadcrumb='',$head='') { 32 if ($this->in_plugin) { 33 echo '<html><head><title>'.__('Blogs').'</title>'. 34 dcPage::jsLoad('js/_blogs_actions.js'). 35 $head. 36 '</script></head><body>'. 37 $breadcrumb; 38 } else { 39 dcPage::open( 40 __('Blogs'), 41 dcPage::jsLoad('js/_blogs_actions.js'). 42 $head, 43 $breadcrumb 44 ); 45 } 46 echo '<p><a class="back" href="'.$this->getRedirection(true).'">'.__('Back to blogs list').'</a></p>'; 47 } 48 49 public function endPage() { 50 dcPage::close(); 51 } 52 53 public function error(Exception $e) { 54 $this->core->error->add($e->getMessage()); 55 $this->beginPage(dcPage::breadcrumb( 56 array( 57 html::escapeHTML($this->core->blog->name) => '', 58 __('Blogs') => $this->core->adminurl->get('admin.blogs'), 59 __('Blogs actions') => '' 60 )) 61 ); 62 $this->endPage(); 63 } 64 65 public function getCheckboxes() { 66 $ret = ''; 67 foreach ($this->entries as $id=>$res) { 68 $ret .= 69 '<tr>'. 70 '<td class="minimal">'.form::checkbox(array($this->field_entries.'[]'),$id,true,'','').'</td>'. 71 '<td>'.$res['blog'].'</td>'. 72 '<td>'.$res['name'].'</td>'. 73 '</tr>'; 74 } 75 76 return 77 '<table class="blogs-list"><tr>'. 78 '<th colspan="2">'.__('Blog id').'</th><th>'.__('Blog name').'</th>'. 79 '</tr>'.$ret.'</table>'; 80 } 81 82 protected function fetchEntries($from) { 83 $params=array(); 84 if (!empty($from['blogs'])) { 85 $params['blog_id'] = $from['blogs']; 86 } 87 88 $bl = $this->core->getBlogs($params); 89 while ($bl->fetch()) { 90 $this->entries[$bl->blog_id] = array( 91 'blog' => $bl->blog_id, 92 'name' => $bl->blog_name 93 ); 94 } 95 $this->rs = $bl; 96 } 16 public function __construct($core, $uri, $redirect_args = array()) 17 { 18 parent::__construct($core, $uri, $redirect_args); 19 $this->redirect_fields = array('status', 'sortby', 'order', 'page', 'nb'); 20 $this->field_entries = 'blogs'; 21 $this->title_cb = __('Blogs'); 22 $this->loadDefaults(); 23 $core->callBehavior('adminBlogsActionsPage', $core, $this); 24 } 25 26 protected function loadDefaults() 27 { 28 // We could have added a behavior here, but we want default action 29 // to be setup first 30 dcDefaultBlogActions::adminBlogsActionsPage($this->core, $this); 31 } 32 33 public function beginPage($breadcrumb = '', $head = '') 34 { 35 if ($this->in_plugin) { 36 echo '<html><head><title>' . __('Blogs') . '</title>' . 37 dcPage::jsLoad('js/_blogs_actions.js') . 38 $head . 39 '</script></head><body>' . 40 $breadcrumb; 41 } else { 42 dcPage::open( 43 __('Blogs'), 44 dcPage::jsLoad('js/_blogs_actions.js') . 45 $head, 46 $breadcrumb 47 ); 48 } 49 echo '<p><a class="back" href="' . $this->getRedirection(true) . '">' . __('Back to blogs list') . '</a></p>'; 50 } 51 52 public function endPage() 53 { 54 dcPage::close(); 55 } 56 57 public function error(Exception $e) 58 { 59 $this->core->error->add($e->getMessage()); 60 $this->beginPage(dcPage::breadcrumb( 61 array( 62 html::escapeHTML($this->core->blog->name) => '', 63 __('Blogs') => $this->core->adminurl->get('admin.blogs'), 64 __('Blogs actions') => '' 65 )) 66 ); 67 $this->endPage(); 68 } 69 70 public function getCheckboxes() 71 { 72 $ret = ''; 73 foreach ($this->entries as $id => $res) { 74 $ret .= 75 '<tr>' . 76 '<td class="minimal">' . form::checkbox(array($this->field_entries . '[]'), $id, 77 array( 78 'checked' => true 79 )) . 80 '</td>' . 81 '<td>' . $res['blog'] . '</td>' . 82 '<td>' . $res['name'] . '</td>' . 83 '</tr>'; 84 } 85 86 return 87 '<table class="blogs-list"><tr>' . 88 '<th colspan="2">' . __('Blog id') . '</th><th>' . __('Blog name') . '</th>' . 89 '</tr>' . $ret . '</table>'; 90 } 91 92 protected function fetchEntries($from) 93 { 94 $params = array(); 95 if (!empty($from['blogs'])) { 96 $params['blog_id'] = $from['blogs']; 97 } 98 99 $bl = $this->core->getBlogs($params); 100 while ($bl->fetch()) { 101 $this->entries[$bl->blog_id] = array( 102 'blog' => $bl->blog_id, 103 'name' => $bl->blog_name 104 ); 105 } 106 $this->rs = $bl; 107 } 97 108 } 98 109 99 110 class dcDefaultBlogActions 100 111 { 101 public static function adminBlogsActionsPage($core, dcBlogsActionsPage $ap) { 102 if (!$core->auth->isSuperAdmin()) { 103 return; 104 } 105 106 $ap->addAction( 107 array(__('Status') => array( 108 __('Set online') => 'online', 109 __('Set offline') => 'offline', 110 __('Set as removed') => 'remove' 111 )), 112 array('dcDefaultBlogActions','doChangeBlogStatus') 113 ); 114 $ap->addAction( 115 array(__('Delete') => array( 116 __('Delete') => 'delete')), 117 array('dcDefaultBlogActions','doDeleteBlog') 118 ); 119 } 120 121 public static function doChangeBlogStatus($core, dcBlogsActionsPage $ap, $post) { 122 if (!$core->auth->isSuperAdmin()) { 123 return; 124 } 125 126 $action = $ap->getAction(); 127 $ids = $ap->getIDs(); 128 if (empty($ids)) { 129 throw new Exception(__('No blog selected')); 130 } 131 switch ($action) { 132 case 'online' : $status = 1; break; 133 case 'offline' : $status = 0; break; 134 case 'remove' : $status = -1; break; 135 default : $status = 1; break; 136 } 137 138 $cur = $core->con->openCursor($core->prefix.'blog'); 139 $cur->blog_status = $status; 140 //$cur->blog_upddt = date('Y-m-d H:i:s'); 141 $cur->update('WHERE blog_id '.$core->con->in($ids)); 142 143 dcPage::addSuccessNotice(__('Selected blogs have been successfully updated.')); 144 $ap->redirect(true); 145 } 146 147 public static function doDeleteBlog($core, dcBlogsActionsPage $ap, $post) { 148 if (!$core->auth->isSuperAdmin()) { 149 return; 150 } 151 152 $ap_ids = $ap->getIDs(); 153 if (empty($ap_ids)) { 154 throw new Exception(__('No blog selected')); 155 } 156 157 if (!$core->auth->checkPassword($_POST['pwd'])) { 158 throw new Exception(__('Password verification failed')); 159 } 160 161 $ids = array(); 162 foreach($ap_ids as $id) { 163 if ($id == $core->blog->id) { 164 dcPage::addWarningNotice(__('The current blog cannot be deleted.')); 165 } else { 166 $ids[] = $id; 167 } 168 } 169 170 if (!empty($ids)) { 171 # --BEHAVIOR-- adminBeforeBlogsDelete 172 $core->callBehavior('adminBeforeBlogsDelete',$ids); 173 174 foreach($ids as $id) { 175 $core->delBlog($id); 176 } 177 178 dcPage::addSuccessNotice(sprintf( 179 __( 180 '%d blog has been successfully deleted', 181 '%d blogs have been successfully deleted', 182 count($ids) 183 ), 184 count($ids)) 185 ); 186 } 187 $ap->redirect(false); 188 } 112 public static function adminBlogsActionsPage($core, dcBlogsActionsPage $ap) 113 { 114 if (!$core->auth->isSuperAdmin()) { 115 return; 116 } 117 118 $ap->addAction( 119 array(__('Status') => array( 120 __('Set online') => 'online', 121 __('Set offline') => 'offline', 122 __('Set as removed') => 'remove' 123 )), 124 array('dcDefaultBlogActions', 'doChangeBlogStatus') 125 ); 126 $ap->addAction( 127 array(__('Delete') => array( 128 __('Delete') => 'delete')), 129 array('dcDefaultBlogActions', 'doDeleteBlog') 130 ); 131 } 132 133 public static function doChangeBlogStatus($core, dcBlogsActionsPage $ap, $post) 134 { 135 if (!$core->auth->isSuperAdmin()) { 136 return; 137 } 138 139 $action = $ap->getAction(); 140 $ids = $ap->getIDs(); 141 if (empty($ids)) { 142 throw new Exception(__('No blog selected')); 143 } 144 switch ($action) { 145 case 'online':$status = 1; 146 break; 147 case 'offline':$status = 0; 148 break; 149 case 'remove':$status = -1; 150 break; 151 default:$status = 1; 152 break; 153 } 154 155 $cur = $core->con->openCursor($core->prefix . 'blog'); 156 $cur->blog_status = $status; 157 //$cur->blog_upddt = date('Y-m-d H:i:s'); 158 $cur->update('WHERE blog_id ' . $core->con->in($ids)); 159 160 dcPage::addSuccessNotice(__('Selected blogs have been successfully updated.')); 161 $ap->redirect(true); 162 } 163 164 public static function doDeleteBlog($core, dcBlogsActionsPage $ap, $post) 165 { 166 if (!$core->auth->isSuperAdmin()) { 167 return; 168 } 169 170 $ap_ids = $ap->getIDs(); 171 if (empty($ap_ids)) { 172 throw new Exception(__('No blog selected')); 173 } 174 175 if (!$core->auth->checkPassword($_POST['pwd'])) { 176 throw new Exception(__('Password verification failed')); 177 } 178 179 $ids = array(); 180 foreach ($ap_ids as $id) { 181 if ($id == $core->blog->id) { 182 dcPage::addWarningNotice(__('The current blog cannot be deleted.')); 183 } else { 184 $ids[] = $id; 185 } 186 } 187 188 if (!empty($ids)) { 189 # --BEHAVIOR-- adminBeforeBlogsDelete 190 $core->callBehavior('adminBeforeBlogsDelete', $ids); 191 192 foreach ($ids as $id) { 193 $core->delBlog($id); 194 } 195 196 dcPage::addSuccessNotice(sprintf( 197 __( 198 '%d blog has been successfully deleted', 199 '%d blogs have been successfully deleted', 200 count($ids) 201 ), 202 count($ids)) 203 ); 204 } 205 $ap->redirect(false); 206 } 189 207 } -
inc/admin/actions/class.dcactioncomments.php
r3159 r3707 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_RC_PATH')) { return;}12 if (!defined('DC_RC_PATH')) {return;} 13 13 14 14 class dcCommentsActionsPage extends dcActionsPage 15 15 { 16 public function __construct($core,$uri,$redirect_args=array()) { 17 parent::__construct($core,$uri,$redirect_args); 18 $this->redirect_fields = array('type','author','status', 19 'sortby','ip','order','page','nb','section'); 20 $this->field_entries = 'comments'; 21 $this->title_cb = __('Comments'); 22 $this->loadDefaults(); 23 $core->callBehavior('adminCommentsActionsPage',$core,$this); 24 } 25 26 protected function loadDefaults() { 27 // We could have added a behavior here, but we want default action 28 // to be setup first 29 dcDefaultCommentActions::adminCommentsActionsPage($this->core,$this); 30 } 31 32 public function beginPage($breadcrumb='',$head='') { 33 if ($this->in_plugin) { 34 echo '<html><head><title>'.__('Comments').'</title>'. 35 dcPage::jsLoad('js/_comments_actions.js'). 36 $head. 37 '</script></head><body>'. 38 $breadcrumb; 39 } else { 40 dcPage::open( 41 __('Comments'), 42 dcPage::jsLoad('js/_comments_actions.js'). 43 $head, 44 $breadcrumb 45 ); 46 47 } 48 echo '<p><a class="back" href="'.$this->getRedirection(true).'">'.__('Back to comments list').'</a></p>'; 49 } 50 51 public function endPage() { 52 dcPage::close(); 53 } 54 55 public function error(Exception $e) { 56 $this->core->error->add($e->getMessage()); 57 $this->beginPage(dcPage::breadcrumb( 58 array( 59 html::escapeHTML($this->core->blog->name) => '', 60 __('Comments') => $this->core->adminurl->get('admin.comments'), 61 __('Comments actions') => '' 62 )) 63 ); 64 $this->endPage(); 65 } 66 67 /** 16 public function __construct($core, $uri, $redirect_args = array()) 17 { 18 parent::__construct($core, $uri, $redirect_args); 19 $this->redirect_fields = array('type', 'author', 'status', 20 'sortby', 'ip', 'order', 'page', 'nb', 'section'); 21 $this->field_entries = 'comments'; 22 $this->title_cb = __('Comments'); 23 $this->loadDefaults(); 24 $core->callBehavior('adminCommentsActionsPage', $core, $this); 25 } 26 27 protected function loadDefaults() 28 { 29 // We could have added a behavior here, but we want default action 30 // to be setup first 31 dcDefaultCommentActions::adminCommentsActionsPage($this->core, $this); 32 } 33 34 public function beginPage($breadcrumb = '', $head = '') 35 { 36 if ($this->in_plugin) { 37 echo '<html><head><title>' . __('Comments') . '</title>' . 38 dcPage::jsLoad('js/_comments_actions.js') . 39 $head . 40 '</script></head><body>' . 41 $breadcrumb; 42 } else { 43 dcPage::open( 44 __('Comments'), 45 dcPage::jsLoad('js/_comments_actions.js') . 46 $head, 47 $breadcrumb 48 ); 49 50 } 51 echo '<p><a class="back" href="' . $this->getRedirection(true) . '">' . __('Back to comments list') . '</a></p>'; 52 } 53 54 public function endPage() 55 { 56 dcPage::close(); 57 } 58 59 public function error(Exception $e) 60 { 61 $this->core->error->add($e->getMessage()); 62 $this->beginPage(dcPage::breadcrumb( 63 array( 64 html::escapeHTML($this->core->blog->name) => '', 65 __('Comments') => $this->core->adminurl->get('admin.comments'), 66 __('Comments actions') => '' 67 )) 68 ); 69 $this->endPage(); 70 } 71 72 /** 68 73 * getcheckboxes -returns html code for selected entries 69 *as a table containing entries checkboxes74 * as a table containing entries checkboxes 70 75 * 71 76 * @access public 72 77 * 73 78 * @return string the html code for checkboxes 74 79 */ 75 public function getCheckboxes() { 76 $ret = 77 '<table class="posts-list"><tr>'. 78 '<th colspan="2">'.__('Author').'</th><th>'.__('Title').'</th>'. 79 '</tr>'; 80 foreach ($this->entries as $id=>$title) { 81 $ret .= 82 '<tr><td class="minimal">'. 83 form::checkbox(array($this->field_entries.'[]'),$id,true,'','').'</td>'. 84 '<td>'. $title['author'].'</td><td>'.$title['title'].'</td></tr>'; 85 } 86 $ret .= '</table>'; 87 return $ret; 88 } 89 90 protected function fetchEntries($from) { 91 $params=array(); 92 if (!empty($from['comments'])) { 93 $comments = $from['comments']; 94 95 foreach ($comments as $k => $v) { 96 $comments[$k] = (integer) $v; 97 } 98 99 $params['sql'] = 'AND C.comment_id IN('.implode(',',$comments).') '; 100 } else { 101 $params['sql'] = 'AND 1=0 '; 102 } 103 104 if (!isset($from['full_content']) || empty($from['full_content'])) { 105 $params['no_content'] = true; 106 } 107 $co = $this->core->blog->getComments($params); 108 while ($co->fetch()) { 109 $this->entries[$co->comment_id] = array( 110 'title' => $co->post_title, 111 'author' => $co->comment_author 112 ); 113 } 114 $this->rs = $co; 115 } 80 public function getCheckboxes() 81 { 82 $ret = 83 '<table class="posts-list"><tr>' . 84 '<th colspan="2">' . __('Author') . '</th><th>' . __('Title') . '</th>' . 85 '</tr>'; 86 foreach ($this->entries as $id => $title) { 87 $ret .= 88 '<tr><td class="minimal">' . 89 form::checkbox(array($this->field_entries . '[]'), $id, 90 array( 91 'checked' => true 92 )) . 93 '</td>' . 94 '<td>' . $title['author'] . '</td><td>' . $title['title'] . '</td></tr>'; 95 } 96 $ret .= '</table>'; 97 return $ret; 98 } 99 100 protected function fetchEntries($from) 101 { 102 $params = array(); 103 if (!empty($from['comments'])) { 104 $comments = $from['comments']; 105 106 foreach ($comments as $k => $v) { 107 $comments[$k] = (integer) $v; 108 } 109 110 $params['sql'] = 'AND C.comment_id IN(' . implode(',', $comments) . ') '; 111 } else { 112 $params['sql'] = 'AND 1=0 '; 113 } 114 115 if (!isset($from['full_content']) || empty($from['full_content'])) { 116 $params['no_content'] = true; 117 } 118 $co = $this->core->blog->getComments($params); 119 while ($co->fetch()) { 120 $this->entries[$co->comment_id] = array( 121 'title' => $co->post_title, 122 'author' => $co->comment_author 123 ); 124 } 125 $this->rs = $co; 126 } 116 127 } 117 128 118 129 class dcDefaultCommentActions 119 130 { 120 public static function adminCommentsActionsPage($core, dcCommentsActionsPage $ap) { 121 if ($core->auth->check('publish,contentadmin',$core->blog->id)) 122 { 123 $ap->addAction( 124 array(__('Status') => array( 125 __('Publish') => 'publish', 126 __('Unpublish') => 'unpublish', 127 __('Mark as pending') => 'pending', 128 __('Mark as junk') => 'junk' 129 )), 130 array('dcDefaultCommentActions','doChangeCommentStatus') 131 ); 132 } 133 134 if ($core->auth->check('delete,contentadmin',$core->blog->id)) 135 { 136 $ap->addAction( 137 array(__('Delete') => array( 138 __('Delete') => 'delete')), 139 array('dcDefaultCommentActions','doDeleteComment') 140 ); 141 } 142 143 $ip_filter_active = true; 144 if ($core->blog->settings->antispam->antispam_filters !== null) { 145 $filters_opt = $core->blog->settings->antispam->antispam_filters; 146 if (is_array($filters_opt)) { 147 $ip_filter_active = isset($filters_opt['dcFilterIP']) && is_array($filters_opt['dcFilterIP']) && $filters_opt['dcFilterIP'][0]==1; 148 } 149 } 150 151 if ($ip_filter_active) { 152 $blacklist_actions = array(__('Blacklist IP') => 'blacklist'); 153 if ($core->auth->isSuperAdmin()) { 154 $blacklist_actions[__('Blacklist IP (global)')] = 'blacklist_global'; 155 } 156 157 $ap->addAction( 158 array(__('IP address') => $blacklist_actions), 159 array('dcDefaultCommentActions','doBlacklistIP') 160 ); 161 } 162 } 163 164 public static function doChangeCommentStatus($core, dcCommentsActionsPage $ap, $post) { 165 $action = $ap->getAction(); 166 $co_ids = $ap->getIDs(); 167 if (empty($co_ids)) { 168 throw new Exception(__('No comment selected')); 169 } 170 switch ($action) { 171 case 'unpublish' : $status = 0; break; 172 case 'pending' : $status = -1; break; 173 case 'junk' : $status = -2; break; 174 default : $status = 1; break; 175 } 176 177 $core->blog->updCommentsStatus($co_ids,$status); 178 179 dcPage::addSuccessNotice(__('Selected comments have been successfully updated.')); 180 $ap->redirect(true); 181 } 182 183 public static function doDeleteComment($core, dcCommentsActionsPage $ap, $post) { 184 $co_ids = $ap->getIDs(); 185 if (empty($co_ids)) { 186 throw new Exception(__('No comment selected')); 187 } 188 // Backward compatibility 189 foreach($co_ids as $comment_id) 190 { 191 # --BEHAVIOR-- adminBeforeCommentDelete 192 $core->callBehavior('adminBeforeCommentDelete',$comment_id); 193 } 194 195 # --BEHAVIOR-- adminBeforeCommentsDelete 196 $core->callBehavior('adminBeforeCommentsDelete',$co_ids); 197 198 $core->blog->delComments($co_ids); 199 dcPage::addSuccessNotice(__('Selected comments have been successfully deleted.')); 200 $ap->redirect(false); 201 } 202 203 public static function doBlacklistIP($core, dcCommentsActionsPage $ap, $post) { 204 $action = $ap->getAction(); 205 $co_ids = $ap->getIDs(); 206 if (empty($co_ids)) { 207 throw new Exception(__('No comment selected')); 208 } 209 210 $global = !empty($action) && $action == 'blacklist_global' && $core->auth->isSuperAdmin(); 211 212 $ip_filter = new dcFilterIP($core); 213 $rs = $ap->getRS(); 214 while ($rs->fetch()) { 215 $ip_filter->addIP('black',$rs->comment_ip,$global); 216 } 217 218 dcPage::addSuccessNotice(__('IP addresses for selected comments have been blacklisted.')); 219 $ap->redirect(true); 220 } 131 public static function adminCommentsActionsPage($core, dcCommentsActionsPage $ap) 132 { 133 if ($core->auth->check('publish,contentadmin', $core->blog->id)) { 134 $ap->addAction( 135 array(__('Status') => array( 136 __('Publish') => 'publish', 137 __('Unpublish') => 'unpublish', 138 __('Mark as pending') => 'pending', 139 __('Mark as junk') => 'junk' 140 )), 141 array('dcDefaultCommentActions', 'doChangeCommentStatus') 142 ); 143 } 144 145 if ($core->auth->check('delete,contentadmin', $core->blog->id)) { 146 $ap->addAction( 147 array(__('Delete') => array( 148 __('Delete') => 'delete')), 149 array('dcDefaultCommentActions', 'doDeleteComment') 150 ); 151 } 152 153 $ip_filter_active = true; 154 if ($core->blog->settings->antispam->antispam_filters !== null) { 155 $filters_opt = $core->blog->settings->antispam->antispam_filters; 156 if (is_array($filters_opt)) { 157 $ip_filter_active = isset($filters_opt['dcFilterIP']) && is_array($filters_opt['dcFilterIP']) && $filters_opt['dcFilterIP'][0] == 1; 158 } 159 } 160 161 if ($ip_filter_active) { 162 $blacklist_actions = array(__('Blacklist IP') => 'blacklist'); 163 if ($core->auth->isSuperAdmin()) { 164 $blacklist_actions[__('Blacklist IP (global)')] = 'blacklist_global'; 165 } 166 167 $ap->addAction( 168 array(__('IP address') => $blacklist_actions), 169 array('dcDefaultCommentActions', 'doBlacklistIP') 170 ); 171 } 172 } 173 174 public static function doChangeCommentStatus($core, dcCommentsActionsPage $ap, $post) 175 { 176 $action = $ap->getAction(); 177 $co_ids = $ap->getIDs(); 178 if (empty($co_ids)) { 179 throw new Exception(__('No comment selected')); 180 } 181 switch ($action) { 182 case 'unpublish':$status = 0; 183 break; 184 case 'pending':$status = -1; 185 break; 186 case 'junk':$status = -2; 187 break; 188 default:$status = 1; 189 break; 190 } 191 192 $core->blog->updCommentsStatus($co_ids, $status); 193 194 dcPage::addSuccessNotice(__('Selected comments have been successfully updated.')); 195 $ap->redirect(true); 196 } 197 198 public static function doDeleteComment($core, dcCommentsActionsPage $ap, $post) 199 { 200 $co_ids = $ap->getIDs(); 201 if (empty($co_ids)) { 202 throw new Exception(__('No comment selected')); 203 } 204 // Backward compatibility 205 foreach ($co_ids as $comment_id) { 206 # --BEHAVIOR-- adminBeforeCommentDelete 207 $core->callBehavior('adminBeforeCommentDelete', $comment_id); 208 } 209 210 # --BEHAVIOR-- adminBeforeCommentsDelete 211 $core->callBehavior('adminBeforeCommentsDelete', $co_ids); 212 213 $core->blog->delComments($co_ids); 214 dcPage::addSuccessNotice(__('Selected comments have been successfully deleted.')); 215 $ap->redirect(false); 216 } 217 218 public static function doBlacklistIP($core, dcCommentsActionsPage $ap, $post) 219 { 220 $action = $ap->getAction(); 221 $co_ids = $ap->getIDs(); 222 if (empty($co_ids)) { 223 throw new Exception(__('No comment selected')); 224 } 225 226 $global = !empty($action) && $action == 'blacklist_global' && $core->auth->isSuperAdmin(); 227 228 $ip_filter = new dcFilterIP($core); 229 $rs = $ap->getRS(); 230 while ($rs->fetch()) { 231 $ip_filter->addIP('black', $rs->comment_ip, $global); 232 } 233 234 dcPage::addSuccessNotice(__('IP addresses for selected comments have been blacklisted.')); 235 $ap->redirect(true); 236 } 221 237 } -
inc/admin/lib.pager.php
r3522 r3707 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_RC_PATH')) { return;}12 if (!defined('DC_RC_PATH')) {return;} 13 13 14 14 class dcPager extends pager 15 15 { 16 protected $form_action; 17 protected $form_hidden; 18 19 protected function getLink($li_class,$href,$img_src,$img_src_nolink,$img_alt,$enable_link) { 20 if ($enable_link) { 21 $formatter = '<li class="%s btn"><a href="%s"><img src="%s" alt="%s"/></a><span class="hidden">%s</span></li>'; 22 return sprintf ($formatter, 23 $li_class,$href,$img_src,$img_alt,$img_alt); 24 } else { 25 $formatter = '<li class="%s no-link btn"><img src="%s" alt="%s"/></li>'; 26 return sprintf ($formatter, 27 $li_class,$img_src_nolink,$img_alt,$img_alt); 28 } 29 } 30 public function setURL() { 31 parent::setURL(); 32 $url = parse_url($_SERVER['REQUEST_URI']); 33 if (isset($url['query'])) { 34 parse_str($url['query'],$args); 35 } else { 36 $args=array(); 37 } 38 # Removing session information 39 if (session_id()) 40 { 41 if (isset($args[session_name()])) 42 unset($args[session_name()]); 43 } 44 if (isset($args[$this->var_page])) { 45 unset($args[$this->var_page]); 46 } 47 if (isset($args['ok'])) { 48 unset($args['ok']); 49 } 50 $this->form_hidden = ''; 51 foreach ($args as $k=>$v) { 52 if (is_array($v)) { 53 foreach ($v as $k2=>$v2) { 54 $this->form_hidden .= form::hidden(array($k.'[]'),html::escapeHTML($v2)); 55 } 56 } else { 57 $this->form_hidden .= form::hidden(array($k),html::escapeHTML($v)); 58 } 59 } 60 $this->form_action = $url['path']; 61 } 62 63 /** 64 * Pager Links 65 * 66 * Returns pager links 67 * 68 * @return string 69 */ 70 public function getLinks() 71 { 72 $this->setURL(); 73 $htmlFirst = $this->getLink( 74 "first", 75 sprintf($this->page_url,1), 76 "images/pagination/first.png", 77 "images/pagination/no-first.png", 78 __('First page'), 79 ($this->env > 1) 80 ); 81 $htmlPrev = $this->getLink( 82 "prev", 83 sprintf($this->page_url,$this->env-1), 84 "images/pagination/previous.png", 85 "images/pagination/no-previous.png", 86 __('Previous page'), 87 ($this->env > 1) 88 ); 89 $htmlNext = $this->getLink( 90 "next", 91 sprintf($this->page_url,$this->env+1), 92 "images/pagination/next.png", 93 "images/pagination/no-next.png", 94 __('Next page'), 95 ($this->env < $this->nb_pages) 96 ); 97 $htmlLast = $this->getLink( 98 "last", 99 sprintf($this->page_url,$this->nb_pages), 100 "images/pagination/last.png", 101 "images/pagination/no-last.png", 102 __('Last page'), 103 ($this->env < $this->nb_pages) 104 ); 105 $htmlCurrent = 106 '<li class="active"><strong>'. 107 sprintf(__('Page %s / %s'),$this->env,$this->nb_pages). 108 '</strong></li>'; 109 110 $htmlDirect = 111 ($this->nb_pages > 1 ? 112 sprintf('<li class="direct-access">'.__('Direct access page %s'), 113 form::field(array($this->var_page),3,10)). 114 '<input type="submit" value="'.__('ok').'" class="reset" '. 115 'name="ok" />'.$this->form_hidden.'</li>' : ''); 116 117 $res = 118 '<form action="'.$this->form_action.'" method="get">'. 119 '<div class="pager"><ul>'. 120 $htmlFirst. 121 $htmlPrev. 122 $htmlCurrent. 123 $htmlNext. 124 $htmlLast. 125 $htmlDirect. 126 '</ul>'. 127 '</div>'. 128 '</form>' 129 ; 130 131 return $this->nb_elements > 0 ? $res : ''; 132 } 16 protected $form_action; 17 protected $form_hidden; 18 19 protected function getLink($li_class, $href, $img_src, $img_src_nolink, $img_alt, $enable_link) 20 { 21 if ($enable_link) { 22 $formatter = '<li class="%s btn"><a href="%s"><img src="%s" alt="%s"/></a><span class="hidden">%s</span></li>'; 23 return sprintf($formatter, 24 $li_class, $href, $img_src, $img_alt, $img_alt); 25 } else { 26 $formatter = '<li class="%s no-link btn"><img src="%s" alt="%s"/></li>'; 27 return sprintf($formatter, 28 $li_class, $img_src_nolink, $img_alt, $img_alt); 29 } 30 } 31 public function setURL() 32 { 33 parent::setURL(); 34 $url = parse_url($_SERVER['REQUEST_URI']); 35 if (isset($url['query'])) { 36 parse_str($url['query'], $args); 37 } else { 38 $args = array(); 39 } 40 # Removing session information 41 if (session_id()) { 42 if (isset($args[session_name()])) { 43 unset($args[session_name()]); 44 } 45 46 } 47 if (isset($args[$this->var_page])) { 48 unset($args[$this->var_page]); 49 } 50 if (isset($args['ok'])) { 51 unset($args['ok']); 52 } 53 $this->form_hidden = ''; 54 foreach ($args as $k => $v) { 55 if (is_array($v)) { 56 foreach ($v as $k2 => $v2) { 57 $this->form_hidden .= form::hidden(array($k . '[]'), html::escapeHTML($v2)); 58 } 59 } else { 60 $this->form_hidden .= form::hidden(array($k), html::escapeHTML($v)); 61 } 62 } 63 $this->form_action = $url['path']; 64 } 65 66 /** 67 * Pager Links 68 * 69 * Returns pager links 70 * 71 * @return string 72 */ 73 public function getLinks() 74 { 75 $this->setURL(); 76 $htmlFirst = $this->getLink( 77 "first", 78 sprintf($this->page_url, 1), 79 "images/pagination/first.png", 80 "images/pagination/no-first.png", 81 __('First page'), 82 ($this->env > 1) 83 ); 84 $htmlPrev = $this->getLink( 85 "prev", 86 sprintf($this->page_url, $this->env - 1), 87 "images/pagination/previous.png", 88 "images/pagination/no-previous.png", 89 __('Previous page'), 90 ($this->env > 1) 91 ); 92 $htmlNext = $this->getLink( 93 "next", 94 sprintf($this->page_url, $this->env + 1), 95 "images/pagination/next.png", 96 "images/pagination/no-next.png", 97 __('Next page'), 98 ($this->env < $this->nb_pages) 99 ); 100 $htmlLast = $this->getLink( 101 "last", 102 sprintf($this->page_url, $this->nb_pages), 103 "images/pagination/last.png", 104 "images/pagination/no-last.png", 105 __('Last page'), 106 ($this->env < $this->nb_pages) 107 ); 108 $htmlCurrent = 109 '<li class="active"><strong>' . 110 sprintf(__('Page %s / %s'), $this->env, $this->nb_pages) . 111 '</strong></li>'; 112 113 $htmlDirect = 114 ($this->nb_pages > 1 ? 115 sprintf('<li class="direct-access">' . __('Direct access page %s'), 116 form::field(array($this->var_page), 3, 10)) . 117 '<input type="submit" value="' . __('ok') . '" class="reset" ' . 118 'name="ok" />' . $this->form_hidden . '</li>' : ''); 119 120 $res = 121 '<form action="' . $this->form_action . '" method="get">' . 122 '<div class="pager"><ul>' . 123 $htmlFirst . 124 $htmlPrev . 125 $htmlCurrent . 126 $htmlNext . 127 $htmlLast . 128 $htmlDirect . 129 '</ul>' . 130 '</div>' . 131 '</form>' 132 ; 133 134 return $this->nb_elements > 0 ? $res : ''; 135 } 133 136 } 134 137 135 138 class adminGenericList 136 139 { 137 138 139 140 141 public function __construct($core,$rs,$rs_count)142 143 $this->core =&$core;144 $this->rs =&$rs;145 $this->rs_count= $rs_count;146 147 148 149 150 public function userColumns($type,$cols)151 152 153 154 155 156 157 158 159 160 161 162 140 protected $core; 141 protected $rs; 142 protected $rs_count; 143 144 public function __construct($core, $rs, $rs_count) 145 { 146 $this->core = &$core; 147 $this->rs = &$rs; 148 $this->rs_count = $rs_count; 149 $this->html_prev = __('« prev.'); 150 $this->html_next = __('next »'); 151 } 152 153 public function userColumns($type, $cols) 154 { 155 $cols_user = @$this->core->auth->user_prefs->interface->cols; 156 if (is_array($cols_user)) { 157 if (isset($cols_user[$type])) { 158 foreach ($cols_user[$type] as $cn => $cd) { 159 if (!$cd && isset($cols[$cn])) { 160 unset($cols[$cn]); 161 } 162 } 163 } 164 } 165 } 163 166 } 164 167 165 168 class adminPostList extends adminGenericList 166 169 { 167 public function display($page,$nb_per_page,$enclose_block='',$filter=false)168 169 if ($this->rs->isEmpty()) 170 171 if( $filter ) { 172 echo '<p><strong>'.__('No entry matches the filter').'</strong></p>'; 173 } else { 174 echo '<p><strong>'.__('No entry').'</strong></p>'; 175 } 176 } 177 else 178 179 $pager = new dcPager($page,$this->rs_count,$nb_per_page,10); 180 $entries = array();181 if (isset($_REQUEST['entries'])) { 182 foreach ($_REQUEST['entries'] as $v) { 183 $entries[(integer)$v]=true; 184 } 185 } 186 $html_block = 187 '<div class="table-outer">'. 188 '<table>';189 190 if( $filter ) { 191 $html_block .= '<caption>'.sprintf(__('List of %s entries matching the filter.'), $this->rs_count).'</caption>';192 } else { 193 $nb_published = $this->core->blog->getPosts(array('post_status' => 1),true)->f(0);194 $nb_pending = $this->core->blog->getPosts(array('post_status' => -2),true)->f(0); 195 $nb_programmed = $this->core->blog->getPosts(array('post_status' => -1),true)->f(0); 196 $nb_unpublished = $this->core->blog->getPosts(array('post_status' => 0),true)->f(0); 197 $html_block .= '<caption>'. 198 sprintf(__('List of entries (%s)'),$this->rs_count). 199 ($nb_published ? 200 sprintf( 201 __(', <a href="%s">published</a> (1)',', <a href="%s">published</a> (%s)',$nb_published), 202 $this->core->adminurl->get('admin.posts',array('status' => 1)), 203 $nb_published) : ''). 204 ($nb_pending ? 205 sprintf( 206 __(', <a href="%s">pending</a> (1)',', <a href="%s">pending</a> (%s)',$nb_pending), 207 $this->core->adminurl->get('admin.posts',array('status' => -2)),208 $nb_pending) : ''). 209 ($nb_programmed ? 210 sprintf(__(', <a href="%s">programmed</a> (1)',', <a href="%s">programmed</a> (%s)',$nb_programmed), 211 $this->core->adminurl->get('admin.posts',array('status' => -1)),212 $nb_programmed) : ''). 213 ($nb_unpublished ? 214 sprintf(__(', <a href="%s">unpublished</a> (1)',', <a href="%s">unpublished</a> (%s)',$nb_unpublished), 215 $this->core->adminurl->get('admin.posts',array('status' => 0)), 216 $nb_unpublished) : ''). 217 '</caption>'; 218 } 219 220 $cols = array( 221 'title' => '<th colspan="2" class="first">'.__('Title').'</th>',222 'date' => '<th scope="col">'.__('Date').'</th>', 223 'category' => '<th scope="col">'.__('Category').'</th>',224 'author' => '<th scope="col">'.__('Author').'</th>', 225 'comments' => '<th scope="col"><img src="images/comments.png" alt="" title="'.__('Comments'). 226 '" /><span class="hidden">'.__('Comments').'</span></th>', 227 'trackbacks' => '<th scope="col"><img src="images/trackbacks.png" alt="" title="'.__('Trackbacks'). 228 '" /><span class="hidden">'.__('Trackbacks').'</span></th>', 229 'status' => '<th scope="col">'.__('Status').'</th>' 230 ); 231 $cols = new ArrayObject($cols); 232 $this->core->callBehavior('adminPostListHeader',$this->core,$this->rs,$cols);233 234 // Cope with optional columns 235 $this->userColumns('posts',$cols); 236 237 $html_block .= '<tr>'.implode(iterator_to_array($cols)).'</tr>%s</table></div>'; 238 if ($enclose_block) { 239 $html_block = sprintf($enclose_block,$html_block);240 } 241 242 echo $pager->getLinks(); 243 244 $blocks = explode('%s',$html_block); 245 246 echo $blocks[0];247 248 while ($this->rs->fetch()) 249 { 250 echo $this->postLine(isset($entries[$this->rs->post_id])); 251 } 252 253 echo $blocks[1]; 254 255 echo $pager->getLinks(); 256 } 257 } 258 259 private function postLine($checked) 260 { 261 if ($this->core->auth->check('categories',$this->core->blog->id)) { 262 $cat_link = '<a href="'.$this->core->adminurl->get('admin.category',array('id' => '%s'),'&',true).'">%s</a>'; 263 } else{264 $cat_link = '%2$s'; 265 } 266 267 if ($this->rs->cat_title) { 268 $cat_title = sprintf($cat_link,$this->rs->cat_id, 269 html::escapeHTML($this->rs->cat_title)); 270 } else { 271 $cat_title = __('(No cat)');272 } 273 274 $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';275 $sts_class = '';276 switch ($this->rs->post_status) { 277 case 1:278 $img_status = sprintf($img,__('Published'),'check-on.png');279 $sts_class = 'sts-online';280 281 case 0:282 $img_status = sprintf($img,__('Unpublished'),'check-off.png');283 $sts_class = 'sts-offline';284 285 case -1:286 $img_status = sprintf($img,__('Scheduled'),'scheduled.png');287 $sts_class = 'sts-scheduled';288 289 case -2: 290 $img_status = sprintf($img,__('Pending'),'check-wrn.png'); 291 $sts_class = 'sts-pending';292 break; 293 } 294 295 $protected = ''; 296 if ($this->rs->post_password) { 297 $protected = sprintf($img,__('Protected'),'locker.png'); 298 } 299 300 $selected = ''; 301 if ($this->rs->post_selected) { 302 $selected = sprintf($img,__('Selected'),'selected.png');303 } 304 305 $attach = '';306 $nb_media = $this->rs->countMedia(); 307 if ($nb_media > 0) { 308 $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments'); 309 $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png');310 } 311 312 $res = '<tr class="line '.($this->rs->post_status != 1 ? 'offline ' : '').$sts_class.'"'.313 ' id="p'.$this->rs->post_id.'">'; 314 315 $cols = array( 316 'check' => '<td class="nowrap">'. 317 form::checkbox(array('entries[]'),$this->rs->post_id,$checked,'','',!$this->rs->isEditable()).318 319 'title' => '<td class="maximal" scope="row"><a href="'.320 $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'">'.321 html::escapeHTML($this->rs->post_title).'</a></td>',322 'date' => '<td class="nowrap count">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>',323 'category' => '<td class="nowrap">'.$cat_title.'</td>',324 'author' => '<td class="nowrap">'.html::escapeHTML($this->rs->user_id).'</td>',325 'comments' => '<td class="nowrap count">'.$this->rs->nb_comment.'</td>',326 'trackbacks' => '<td class="nowrap count">'.$this->rs->nb_trackback.'</td>',327 'status' => '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>'328 329 330 $this->core->callBehavior('adminPostListValue',$this->core,$this->rs,$cols);331 332 333 $this->userColumns('posts',$cols);334 335 336 337 338 339 170 public function display($page, $nb_per_page, $enclose_block = '', $filter = false) 171 { 172 if ($this->rs->isEmpty()) { 173 if ($filter) { 174 echo '<p><strong>' . __('No entry matches the filter') . '</strong></p>'; 175 } else { 176 echo '<p><strong>' . __('No entry') . '</strong></p>'; 177 } 178 } else { 179 $pager = new dcPager($page, $this->rs_count, $nb_per_page, 10); 180 $entries = array(); 181 if (isset($_REQUEST['entries'])) { 182 foreach ($_REQUEST['entries'] as $v) { 183 $entries[(integer) $v] = true; 184 } 185 } 186 $html_block = 187 '<div class="table-outer">' . 188 '<table>'; 189 190 if ($filter) { 191 $html_block .= '<caption>' . sprintf(__('List of %s entries matching the filter.'), $this->rs_count) . '</caption>'; 192 } else { 193 $nb_published = $this->core->blog->getPosts(array('post_status' => 1), true)->f(0); 194 $nb_pending = $this->core->blog->getPosts(array('post_status' => -2), true)->f(0); 195 $nb_programmed = $this->core->blog->getPosts(array('post_status' => -1), true)->f(0); 196 $nb_unpublished = $this->core->blog->getPosts(array('post_status' => 0), true)->f(0); 197 $html_block .= '<caption>' . 198 sprintf(__('List of entries (%s)'), $this->rs_count) . 199 ($nb_published ? 200 sprintf( 201 __(', <a href="%s">published</a> (1)', ', <a href="%s">published</a> (%s)', $nb_published), 202 $this->core->adminurl->get('admin.posts', array('status' => 1)), 203 $nb_published) : '') . 204 ($nb_pending ? 205 sprintf( 206 __(', <a href="%s">pending</a> (1)', ', <a href="%s">pending</a> (%s)', $nb_pending), 207 $this->core->adminurl->get('admin.posts', array('status' => -2)), 208 $nb_pending) : '') . 209 ($nb_programmed ? 210 sprintf(__(', <a href="%s">programmed</a> (1)', ', <a href="%s">programmed</a> (%s)', $nb_programmed), 211 $this->core->adminurl->get('admin.posts', array('status' => -1)), 212 $nb_programmed) : '') . 213 ($nb_unpublished ? 214 sprintf(__(', <a href="%s">unpublished</a> (1)', ', <a href="%s">unpublished</a> (%s)', $nb_unpublished), 215 $this->core->adminurl->get('admin.posts', array('status' => 0)), 216 $nb_unpublished) : '') . 217 '</caption>'; 218 } 219 220 $cols = array( 221 'title' => '<th colspan="2" class="first">' . __('Title') . '</th>', 222 'date' => '<th scope="col">' . __('Date') . '</th>', 223 'category' => '<th scope="col">' . __('Category') . '</th>', 224 'author' => '<th scope="col">' . __('Author') . '</th>', 225 'comments' => '<th scope="col"><img src="images/comments.png" alt="" title="' . __('Comments') . 226 '" /><span class="hidden">' . __('Comments') . '</span></th>', 227 'trackbacks' => '<th scope="col"><img src="images/trackbacks.png" alt="" title="' . __('Trackbacks') . 228 '" /><span class="hidden">' . __('Trackbacks') . '</span></th>', 229 'status' => '<th scope="col">' . __('Status') . '</th>' 230 ); 231 $cols = new ArrayObject($cols); 232 $this->core->callBehavior('adminPostListHeader', $this->core, $this->rs, $cols); 233 234 // Cope with optional columns 235 $this->userColumns('posts', $cols); 236 237 $html_block .= '<tr>' . implode(iterator_to_array($cols)) . '</tr>%s</table></div>'; 238 if ($enclose_block) { 239 $html_block = sprintf($enclose_block, $html_block); 240 } 241 242 echo $pager->getLinks(); 243 244 $blocks = explode('%s', $html_block); 245 246 echo $blocks[0]; 247 248 while ($this->rs->fetch()) { 249 echo $this->postLine(isset($entries[$this->rs->post_id])); 250 } 251 252 echo $blocks[1]; 253 254 echo $pager->getLinks(); 255 } 256 } 257 258 private function postLine($checked) 259 { 260 if ($this->core->auth->check('categories', $this->core->blog->id)) { 261 $cat_link = '<a href="' . $this->core->adminurl->get('admin.category', array('id' => '%s'), '&', true) . '">%s</a>'; 262 } else { 263 $cat_link = '%2$s'; 264 } 265 266 if ($this->rs->cat_title) { 267 $cat_title = sprintf($cat_link, $this->rs->cat_id, 268 html::escapeHTML($this->rs->cat_title)); 269 } else { 270 $cat_title = __('(No cat)'); 271 } 272 273 $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; 274 $sts_class = ''; 275 switch ($this->rs->post_status) { 276 case 1: 277 $img_status = sprintf($img, __('Published'), 'check-on.png'); 278 $sts_class = 'sts-online'; 279 break; 280 case 0: 281 $img_status = sprintf($img, __('Unpublished'), 'check-off.png'); 282 $sts_class = 'sts-offline'; 283 break; 284 case -1: 285 $img_status = sprintf($img, __('Scheduled'), 'scheduled.png'); 286 $sts_class = 'sts-scheduled'; 287 break; 288 case -2: 289 $img_status = sprintf($img, __('Pending'), 'check-wrn.png'); 290 $sts_class = 'sts-pending'; 291 break; 292 } 293 294 $protected = ''; 295 if ($this->rs->post_password) { 296 $protected = sprintf($img, __('Protected'), 'locker.png'); 297 } 298 299 $selected = ''; 300 if ($this->rs->post_selected) { 301 $selected = sprintf($img, __('Selected'), 'selected.png'); 302 } 303 304 $attach = ''; 305 $nb_media = $this->rs->countMedia(); 306 if ($nb_media > 0) { 307 $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments'); 308 $attach = sprintf($img, sprintf($attach_str, $nb_media), 'attach.png'); 309 } 310 311 $res = '<tr class="line ' . ($this->rs->post_status != 1 ? 'offline ' : '') . $sts_class . '"' . 312 ' id="p' . $this->rs->post_id . '">'; 313 314 $cols = array( 315 'check' => '<td class="nowrap">' . 316 form::checkbox(array('entries[]'), $this->rs->post_id, 317 array( 318 'checked' => $checked, 319 'disabled' => !$this->rs->isEditable() 320 )) . 321 '</td>', 322 'title' => '<td class="maximal" scope="row"><a href="' . 323 $this->core->getPostAdminURL($this->rs->post_type, $this->rs->post_id) . '">' . 324 html::escapeHTML($this->rs->post_title) . '</a></td>', 325 'date' => '<td class="nowrap count">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->post_dt) . '</td>', 326 'category' => '<td class="nowrap">' . $cat_title . '</td>', 327 'author' => '<td class="nowrap">' . html::escapeHTML($this->rs->user_id) . '</td>', 328 'comments' => '<td class="nowrap count">' . $this->rs->nb_comment . '</td>', 329 'trackbacks' => '<td class="nowrap count">' . $this->rs->nb_trackback . '</td>', 330 'status' => '<td class="nowrap status">' . $img_status . ' ' . $selected . ' ' . $protected . ' ' . $attach . '</td>' 331 ); 332 $cols = new ArrayObject($cols); 333 $this->core->callBehavior('adminPostListValue', $this->core, $this->rs, $cols); 334 335 // Cope with optional columns 336 $this->userColumns('posts', $cols); 337 338 $res .= implode(iterator_to_array($cols)); 339 $res .= '</tr>'; 340 341 return $res; 342 } 340 343 } 341 344 342 345 class adminPostMiniList extends adminGenericList 343 346 { 344 public function display($page,$nb_per_page,$enclose_block='') 345 { 346 if ($this->rs->isEmpty()) 347 { 348 echo '<p><strong>'.__('No entry').'</strong></p>'; 349 } 350 else 351 { 352 $pager = new dcPager($page,$this->rs_count,$nb_per_page,10); 353 354 $html_block = 355 '<div class="table-outer clear">'. 356 '<table><caption class="hidden">'.__('Entries list').'</caption><tr>'; 357 358 $cols = array( 359 'title' => '<th scope="col">'.__('Title').'</th>', 360 'date' => '<th scope="col">'.__('Date').'</th>', 361 'author' => '<th scope="col">'.__('Author').'</th>', 362 'status' => '<th scope="col">'.__('Status').'</th>' 363 ); 364 365 $cols = new ArrayObject($cols); 366 $this->core->callBehavior('adminPostMiniListHeader',$this->core,$this->rs,$cols); 367 368 // Cope with optional columns 369 $this->userColumns('posts',$cols); 370 371 $html_block .= '<tr>'.implode(iterator_to_array($cols)).'</tr>%s</table></div>'; 372 if ($enclose_block) { 373 $html_block = sprintf($enclose_block,$html_block); 374 } 375 376 echo $pager->getLinks(); 377 378 $blocks = explode('%s',$html_block); 379 380 echo $blocks[0]; 381 382 while ($this->rs->fetch()) 383 { 384 echo $this->postLine(); 385 } 386 387 echo $blocks[1]; 388 389 echo $pager->getLinks(); 390 } 391 } 392 393 private function postLine() 394 { 395 $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; 396 $sts_class = ''; 397 switch ($this->rs->post_status) { 398 case 1: 399 $img_status = sprintf($img,__('Published'),'check-on.png'); 400 $sts_class = 'sts-online'; 401 break; 402 case 0: 403 $img_status = sprintf($img,__('Unpublished'),'check-off.png'); 404 $sts_class = 'sts-offline'; 405 break; 406 case -1: 407 $img_status = sprintf($img,__('Scheduled'),'scheduled.png'); 408 $sts_class = 'sts-scheduled'; 409 break; 410 case -2: 411 $img_status = sprintf($img,__('Pending'),'check-wrn.png'); 412 $sts_class = 'sts-pending'; 413 break; 414 } 415 416 $protected = ''; 417 if ($this->rs->post_password) { 418 $protected = sprintf($img,__('Protected'),'locker.png'); 419 } 420 421 $selected = ''; 422 if ($this->rs->post_selected) { 423 $selected = sprintf($img,__('Selected'),'selected.png'); 424 } 425 426 $attach = ''; 427 $nb_media = $this->rs->countMedia(); 428 if ($nb_media > 0) { 429 $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments'); 430 $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png'); 431 } 432 433 $res = '<tr class="line '.($this->rs->post_status != 1 ? 'offline ' : '').$sts_class.'"'. 434 ' id="p'.$this->rs->post_id.'">'; 435 436 $cols = array( 437 'title' => '<td scope="row" class="maximal"><a href="'. 438 $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'" '. 439 'title="'.html::escapeHTML($this->rs->getURL()).'">'. 440 html::escapeHTML($this->rs->post_title).'</a></td>', 441 'date' => '<td class="nowrap count">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>', 442 'author' => '<td class="nowrap">'.html::escapeHTML($this->rs->user_id).'</td>', 443 'status' => '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>' 444 ); 445 446 $cols = new ArrayObject($cols); 447 $this->core->callBehavior('adminPostMiniListValue',$this->core,$this->rs,$cols); 448 449 // Cope with optional columns 450 $this->userColumns('posts',$cols); 451 452 $res .= implode(iterator_to_array($cols)); 453 $res .= '</tr>'; 454 455 return $res; 456 } 347 public function display($page, $nb_per_page, $enclose_block = '') 348 { 349 if ($this->rs->isEmpty()) { 350 echo '<p><strong>' . __('No entry') . '</strong></p>'; 351 } else { 352 $pager = new dcPager($page, $this->rs_count, $nb_per_page, 10); 353 354 $html_block = 355 '<div class="table-outer clear">' . 356 '<table><caption class="hidden">' . __('Entries list') . '</caption><tr>'; 357 358 $cols = array( 359 'title' => '<th scope="col">' . __('Title') . '</th>', 360 'date' => '<th scope="col">' . __('Date') . '</th>', 361 'author' => '<th scope="col">' . __('Author') . '</th>', 362 'status' => '<th scope="col">' . __('Status') . '</th>' 363 ); 364 365 $cols = new ArrayObject($cols); 366 $this->core->callBehavior('adminPostMiniListHeader', $this->core, $this->rs, $cols); 367 368 // Cope with optional columns 369 $this->userColumns('posts', $cols); 370 371 $html_block .= '<tr>' . implode(iterator_to_array($cols)) . '</tr>%s</table></div>'; 372 if ($enclose_block) { 373 $html_block = sprintf($enclose_block, $html_block); 374 } 375 376 echo $pager->getLinks(); 377 378 $blocks = explode('%s', $html_block); 379 380 echo $blocks[0]; 381 382 while ($this->rs->fetch()) { 383 echo $this->postLine(); 384 } 385 386 echo $blocks[1]; 387 388 echo $pager->getLinks(); 389 } 390 } 391 392 private function postLine() 393 { 394 $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; 395 $sts_class = ''; 396 switch ($this->rs->post_status) { 397 case 1: 398 $img_status = sprintf($img, __('Published'), 'check-on.png'); 399 $sts_class = 'sts-online'; 400 break; 401 case 0: 402 $img_status = sprintf($img, __('Unpublished'), 'check-off.png'); 403 $sts_class = 'sts-offline'; 404 break; 405 case -1: 406 $img_status = sprintf($img, __('Scheduled'), 'scheduled.png'); 407 $sts_class = 'sts-scheduled'; 408 break; 409 case -2: 410 $img_status = sprintf($img, __('Pending'), 'check-wrn.png'); 411 $sts_class = 'sts-pending'; 412 break; 413 } 414 415 $protected = ''; 416 if ($this->rs->post_password) { 417 $protected = sprintf($img, __('Protected'), 'locker.png'); 418 } 419 420 $selected = ''; 421 if ($this->rs->post_selected) { 422 $selected = sprintf($img, __('Selected'), 'selected.png'); 423 } 424 425 $attach = ''; 426 $nb_media = $this->rs->countMedia(); 427 if ($nb_media > 0) { 428 $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments'); 429 $attach = sprintf($img, sprintf($attach_str, $nb_media), 'attach.png'); 430 } 431 432 $res = '<tr class="line ' . ($this->rs->post_status != 1 ? 'offline ' : '') . $sts_class . '"' . 433 ' id="p' . $this->rs->post_id . '">'; 434 435 $cols = array( 436 'title' => '<td scope="row" class="maximal"><a href="' . 437 $this->core->getPostAdminURL($this->rs->post_type, $this->rs->post_id) . '" ' . 438 'title="' . html::escapeHTML($this->rs->getURL()) . '">' . 439 html::escapeHTML($this->rs->post_title) . '</a></td>', 440 'date' => '<td class="nowrap count">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->post_dt) . '</td>', 441 'author' => '<td class="nowrap">' . html::escapeHTML($this->rs->user_id) . '</td>', 442 'status' => '<td class="nowrap status">' . $img_status . ' ' . $selected . ' ' . $protected . ' ' . $attach . '</td>' 443 ); 444 445 $cols = new ArrayObject($cols); 446 $this->core->callBehavior('adminPostMiniListValue', $this->core, $this->rs, $cols); 447 448 // Cope with optional columns 449 $this->userColumns('posts', $cols); 450 451 $res .= implode(iterator_to_array($cols)); 452 $res .= '</tr>'; 453 454 return $res; 455 } 457 456 } 458 457 459 458 class adminCommentList extends adminGenericList 460 459 { 461 public function display($page,$nb_per_page,$enclose_block='',$filter=false,$spam=false) 462 { 463 if ($this->rs->isEmpty()) 464 { 465 if( $filter ) { 466 echo '<p><strong>'.__('No comments or trackbacks matches the filter').'</strong></p>'; 467 } else { 468 echo '<p><strong>'.__('No comments').'</strong></p>'; 469 } 470 } 471 else 472 { 473 // Get antispam filters' name 474 $filters = array(); 475 if ($spam) { 476 if (class_exists('dcAntispam')) { 477 dcAntispam::initFilters(); 478 $fs = dcAntispam::$filters->getFilters(); 479 foreach ($fs as $fid => $f) 480 { 481 $filters[$fid] = $f->name; 482 } 483 } 484 } 485 486 $pager = new dcPager($page,$this->rs_count,$nb_per_page,10); 487 488 $comments = array(); 489 if (isset($_REQUEST['comments'])) { 490 foreach ($_REQUEST['comments'] as $v) { 491 $comments[(integer)$v]=true; 492 } 493 } 494 $html_block = 495 '<div class="table-outer">'. 496 '<table>'; 497 498 if( $filter ) { 499 $html_block .= '<caption>'. 500 sprintf(__( 501 'Comment or trackback matching the filter.', 502 'List of %s comments or trackbacks matching the filter.', 503 $this->rs_count), $this->rs_count). 504 '</caption>'; 505 } else { 506 $nb_published = $this->core->blog->getComments(array('comment_status' => 1),true)->f(0); 507 $nb_spam = $this->core->blog->getComments(array('comment_status' => -2),true)->f(0); 508 $nb_pending = $this->core->blog->getComments(array('comment_status' => -1),true)->f(0); 509 $nb_unpublished = $this->core->blog->getComments(array('comment_status' => 0),true)->f(0); 510 $html_block .= '<caption>'. 511 sprintf(__('List of comments and trackbacks (%s)'),$this->rs_count). 512 ($nb_published ? 513 sprintf( 514 __(', <a href="%s">published</a> (1)',', <a href="%s">published</a> (%s)',$nb_published), 515 $this->core->adminurl->get('admin.comments',array('status' => 1)), 516 $nb_published) : ''). 517 ($nb_spam ? 518 sprintf( 519 __(', <a href="%s">spam</a> (1)',', <a href="%s">spam</a> (%s)',$nb_spam), 520 $this->core->adminurl->get('admin.comments',array('status' => -2)), 521 $nb_spam) : ''). 522 ($nb_pending ? 523 sprintf(__(', <a href="%s">pending</a> (1)',', <a href="%s">pending</a> (%s)',$nb_pending), 524 $this->core->adminurl->get('admin.comments',array('status' => -1)), 525 $nb_pending) : ''). 526 ($nb_unpublished ? 527 sprintf(__(', <a href="%s">unpublished</a> (1)',', <a href="%s">unpublished</a> (%s)',$nb_unpublished), 528 $this->core->adminurl->get('admin.comments',array('status' => 0)), 529 $nb_unpublished) : ''). 530 '</caption>'; 531 } 532 533 $cols = array( 534 'type' => '<th colspan="2" scope="col" abbr="comm" class="first">'.__('Type').'</th>', 535 'author' => '<th scope="col">'.__('Author').'</th>', 536 'date' => '<th scope="col">'.__('Date').'</th>', 537 'status' => '<th scope="col" class="txt-center">'.__('Status').'</th>' 538 ); 539 if ($spam) { 540 $cols['ip'] = '<th scope="col">'.__('IP').'</th>'; 541 $cols['spam_filter'] = '<th scope="col">'.__('Spam filter').'</th>'; 542 } 543 $cols['entry'] = '<th scope="col" abbr="entry">'.__('Entry').'</th>'; 544 545 $cols = new ArrayObject($cols); 546 $this->core->callBehavior('adminCommentListHeader',$this->core,$this->rs,$cols); 547 548 $html_block .= '<tr>'.implode(iterator_to_array($cols)).'</tr>%s</table></div>'; 549 550 if ($enclose_block) { 551 $html_block = sprintf($enclose_block,$html_block); 552 } 553 554 echo $pager->getLinks(); 555 556 $blocks = explode('%s',$html_block); 557 558 echo $blocks[0]; 559 560 while ($this->rs->fetch()) 561 { 562 echo $this->commentLine(isset($comments[$this->rs->comment_id]),$spam,$filters); 563 } 564 565 echo $blocks[1]; 566 567 echo $pager->getLinks(); 568 } 569 } 570 571 private function commentLine($checked=false,$spam=false,$filters=array()) 572 { 573 global $core, $author, $status, $sortby, $order, $nb_per_page; 574 575 $author_url = 576 $this->core->adminurl->get('admin.comments',array( 577 'n' => $nb_per_page, 578 'status' => $status, 579 'sortby' => $sortby, 580 'order' => $order, 581 'author' => $this->rs->comment_author 582 )); 583 584 $post_url = $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id); 585 586 $comment_url = $this->core->adminurl->get('admin.comment',array('id' => $this->rs->comment_id)); 587 588 $comment_dt = 589 dt::dt2str($this->core->blog->settings->system->date_format.' - '. 590 $this->core->blog->settings->system->time_format,$this->rs->comment_dt); 591 592 $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; 593 $sts_class = ''; 594 switch ($this->rs->comment_status) { 595 case 1: 596 $img_status = sprintf($img,__('Published'),'check-on.png'); 597 $sts_class = 'sts-online'; 598 break; 599 case 0: 600 $img_status = sprintf($img,__('Unpublished'),'check-off.png'); 601 $sts_class = 'sts-offline'; 602 break; 603 case -1: 604 $img_status = sprintf($img,__('Pending'),'check-wrn.png'); 605 $sts_class = 'sts-pending'; 606 break; 607 case -2: 608 $img_status = sprintf($img,__('Junk'),'junk.png'); 609 $sts_class = 'sts-junk'; 610 break; 611 } 612 613 $post_title = html::escapeHTML($this->rs->post_title); 614 if (mb_strlen($post_title) > 70) { 615 $post_title = mb_strcut($post_title,0,67).'...'; 616 } 617 $comment_title = sprintf(__('Edit the %1$s from %2$s'), 618 $this->rs->comment_trackback ? __('trackback') : __('comment'), 619 html::escapeHTML($this->rs->comment_author)); 620 621 $res = '<tr class="line '.($this->rs->comment_status != 1 ? 'offline ' : '').$sts_class.'"'. 622 ' id="c'.$this->rs->comment_id.'">'; 623 624 $cols = array( 625 'check' => '<td class="nowrap">'. 626 form::checkbox(array('comments[]'),$this->rs->comment_id,$checked,'','',0).'</td>', 627 'type' => '<td class="nowrap" abbr="'.__('Type and author').'" scope="row">'. 628 '<a href="'.$comment_url.'" title="'.$comment_title.'">'. 629 '<img src="images/edit-mini.png" alt="'.__('Edit').'"/> '. 630 ($this->rs->comment_trackback ? __('trackback') : __('comment')).' '.'</a></td>', 631 'author' => '<td class="nowrap maximal"><a href="'.$author_url.'">'. 632 html::escapeHTML($this->rs->comment_author).'</a></td>', 633 'date' => '<td class="nowrap count">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->comment_dt).'</td>', 634 'status' => '<td class="nowrap status txt-center">'.$img_status.'</td>' 635 ); 636 637 if ($spam) { 638 $filter_name = ''; 639 if ($this->rs->comment_spam_filter) { 640 if (isset($filters[$this->rs->comment_spam_filter])) { 641 $filter_name = $filters[$this->rs->comment_spam_filter]; 642 } else { 643 $filter_name = $this->rs->comment_spam_filter; 644 } 645 } 646 $cols['ip'] = '<td class="nowrap"><a href="'. 647 $core->adminurl->get("admin.comments",array('ip' => $this->rs->comment_ip)).'">'. 648 $this->rs->comment_ip.'</a></td>'; 649 $cols['spam_filter'] = '<td class="nowrap">'.$filter_name.'</td>'; 650 } 651 $cols['entry'] = '<td class="nowrap discrete"><a href="'.$post_url.'">'.$post_title.'</a>'. 652 ($this->rs->post_type != 'post' ? ' ('.html::escapeHTML($this->rs->post_type).')' : '').'</td>'; 653 654 $cols = new ArrayObject($cols); 655 $this->core->callBehavior('adminCommentListValue',$this->core,$this->rs,$cols); 656 657 $res .= implode(iterator_to_array($cols)); 658 $res .= '</tr>'; 659 660 return $res; 661 } 460 public function display($page, $nb_per_page, $enclose_block = '', $filter = false, $spam = false) 461 { 462 if ($this->rs->isEmpty()) { 463 if ($filter) { 464 echo '<p><strong>' . __('No comments or trackbacks matches the filter') . '</strong></p>'; 465 } else { 466 echo '<p><strong>' . __('No comments') . '</strong></p>'; 467 } 468 } else { 469 // Get antispam filters' name 470 $filters = array(); 471 if ($spam) { 472 if (class_exists('dcAntispam')) { 473 dcAntispam::initFilters(); 474 $fs = dcAntispam::$filters->getFilters(); 475 foreach ($fs as $fid => $f) { 476 $filters[$fid] = $f->name; 477 } 478 } 479 } 480 481 $pager = new dcPager($page, $this->rs_count, $nb_per_page, 10); 482 483 $comments = array(); 484 if (isset($_REQUEST['comments'])) { 485 foreach ($_REQUEST['comments'] as $v) { 486 $comments[(integer) $v] = true; 487 } 488 } 489 $html_block = 490 '<div class="table-outer">' . 491 '<table>'; 492 493 if ($filter) { 494 $html_block .= '<caption>' . 495 sprintf(__( 496 'Comment or trackback matching the filter.', 497 'List of %s comments or trackbacks matching the filter.', 498 $this->rs_count), $this->rs_count) . 499 '</caption>'; 500 } else { 501 $nb_published = $this->core->blog->getComments(array('comment_status' => 1), true)->f(0); 502 $nb_spam = $this->core->blog->getComments(array('comment_status' => -2), true)->f(0); 503 $nb_pending = $this->core->blog->getComments(array('comment_status' => -1), true)->f(0); 504 $nb_unpublished = $this->core->blog->getComments(array('comment_status' => 0), true)->f(0); 505 $html_block .= '<caption>' . 506 sprintf(__('List of comments and trackbacks (%s)'), $this->rs_count) . 507 ($nb_published ? 508 sprintf( 509 __(', <a href="%s">published</a> (1)', ', <a href="%s">published</a> (%s)', $nb_published), 510 $this->core->adminurl->get('admin.comments', array('status' => 1)), 511 $nb_published) : '') . 512 ($nb_spam ? 513 sprintf( 514 __(', <a href="%s">spam</a> (1)', ', <a href="%s">spam</a> (%s)', $nb_spam), 515 $this->core->adminurl->get('admin.comments', array('status' => -2)), 516 $nb_spam) : '') . 517 ($nb_pending ? 518 sprintf(__(', <a href="%s">pending</a> (1)', ', <a href="%s">pending</a> (%s)', $nb_pending), 519 $this->core->adminurl->get('admin.comments', array('status' => -1)), 520 $nb_pending) : '') . 521 ($nb_unpublished ? 522 sprintf(__(', <a href="%s">unpublished</a> (1)', ', <a href="%s">unpublished</a> (%s)', $nb_unpublished), 523 $this->core->adminurl->get('admin.comments', array('status' => 0)), 524 $nb_unpublished) : '') . 525 '</caption>'; 526 } 527 528 $cols = array( 529 'type' => '<th colspan="2" scope="col" abbr="comm" class="first">' . __('Type') . '</th>', 530 'author' => '<th scope="col">' . __('Author') . '</th>', 531 'date' => '<th scope="col">' . __('Date') . '</th>', 532 'status' => '<th scope="col" class="txt-center">' . __('Status') . '</th>' 533 ); 534 if ($spam) { 535 $cols['ip'] = '<th scope="col">' . __('IP') . '</th>'; 536 $cols['spam_filter'] = '<th scope="col">' . __('Spam filter') . '</th>'; 537 } 538 $cols['entry'] = '<th scope="col" abbr="entry">' . __('Entry') . '</th>'; 539 540 $cols = new ArrayObject($cols); 541 $this->core->callBehavior('adminCommentListHeader', $this->core, $this->rs, $cols); 542 543 $html_block .= '<tr>' . implode(iterator_to_array($cols)) . '</tr>%s</table></div>'; 544 545 if ($enclose_block) { 546 $html_block = sprintf($enclose_block, $html_block); 547 } 548 549 echo $pager->getLinks(); 550 551 $blocks = explode('%s', $html_block); 552 553 echo $blocks[0]; 554 555 while ($this->rs->fetch()) { 556 echo $this->commentLine(isset($comments[$this->rs->comment_id]), $spam, $filters); 557 } 558 559 echo $blocks[1]; 560 561 echo $pager->getLinks(); 562 } 563 } 564 565 private function commentLine($checked = false, $spam = false, $filters = array()) 566 { 567 global $core, $author, $status, $sortby, $order, $nb_per_page; 568 569 $author_url = 570 $this->core->adminurl->get('admin.comments', array( 571 'n' => $nb_per_page, 572 'status' => $status, 573 'sortby' => $sortby, 574 'order' => $order, 575 'author' => $this->rs->comment_author 576 )); 577 578 $post_url = $this->core->getPostAdminURL($this->rs->post_type, $this->rs->post_id); 579 580 $comment_url = $this->core->adminurl->get('admin.comment', array('id' => $this->rs->comment_id)); 581 582 $comment_dt = 583 dt::dt2str($this->core->blog->settings->system->date_format . ' - ' . 584 $this->core->blog->settings->system->time_format, $this->rs->comment_dt); 585 586 $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; 587 $sts_class = ''; 588 switch ($this->rs->comment_status) { 589 case 1: 590 $img_status = sprintf($img, __('Published'), 'check-on.png'); 591 $sts_class = 'sts-online'; 592 break; 593 case 0: 594 $img_status = sprintf($img, __('Unpublished'), 'check-off.png'); 595 $sts_class = 'sts-offline'; 596 break; 597 case -1: 598 $img_status = sprintf($img, __('Pending'), 'check-wrn.png'); 599 $sts_class = 'sts-pending'; 600 break; 601 case -2: 602 $img_status = sprintf($img, __('Junk'), 'junk.png'); 603 $sts_class = 'sts-junk'; 604 break; 605 } 606 607 $post_title = html::escapeHTML($this->rs->post_title); 608 if (mb_strlen($post_title) > 70) { 609 $post_title = mb_strcut($post_title, 0, 67) . '...'; 610 } 611 $comment_title = sprintf(__('Edit the %1$s from %2$s'), 612 $this->rs->comment_trackback ? __('trackback') : __('comment'), 613 html::escapeHTML($this->rs->comment_author)); 614 615 $res = '<tr class="line ' . ($this->rs->comment_status != 1 ? 'offline ' : '') . $sts_class . '"' . 616 ' id="c' . $this->rs->comment_id . '">'; 617 618 $cols = array( 619 'check' => '<td class="nowrap">' . 620 form::checkbox(array('comments[]'), $this->rs->comment_id, $checked) . 621 '</td>', 622 'type' => '<td class="nowrap" abbr="' . __('Type and author') . '" scope="row">' . 623 '<a href="' . $comment_url . '" title="' . $comment_title . '">' . 624 '<img src="images/edit-mini.png" alt="' . __('Edit') . '"/> ' . 625 ($this->rs->comment_trackback ? __('trackback') : __('comment')) . ' ' . '</a></td>', 626 'author' => '<td class="nowrap maximal"><a href="' . $author_url . '">' . 627 html::escapeHTML($this->rs->comment_author) . '</a></td>', 628 'date' => '<td class="nowrap count">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->comment_dt) . '</td>', 629 'status' => '<td class="nowrap status txt-center">' . $img_status . '</td>' 630 ); 631 632 if ($spam) { 633 $filter_name = ''; 634 if ($this->rs->comment_spam_filter) { 635 if (isset($filters[$this->rs->comment_spam_filter])) { 636 $filter_name = $filters[$this->rs->comment_spam_filter]; 637 } else { 638 $filter_name = $this->rs->comment_spam_filter; 639 } 640 } 641 $cols['ip'] = '<td class="nowrap"><a href="' . 642 $core->adminurl->get("admin.comments", array('ip' => $this->rs->comment_ip)) . '">' . 643 $this->rs->comment_ip . '</a></td>'; 644 $cols['spam_filter'] = '<td class="nowrap">' . $filter_name . '</td>'; 645 } 646 $cols['entry'] = '<td class="nowrap discrete"><a href="' . $post_url . '">' . $post_title . '</a>' . 647 ($this->rs->post_type != 'post' ? ' (' . html::escapeHTML($this->rs->post_type) . ')' : '') . '</td>'; 648 649 $cols = new ArrayObject($cols); 650 $this->core->callBehavior('adminCommentListValue', $this->core, $this->rs, $cols); 651 652 $res .= implode(iterator_to_array($cols)); 653 $res .= '</tr>'; 654 655 return $res; 656 } 662 657 } 663 658 664 659 class adminBlogList extends adminGenericList 665 660 { 666 public function display($page,$nb_per_page,$enclose_block='',$filter=false) 667 { 668 if ($this->rs->isEmpty()) 669 { 670 if($filter) { 671 echo '<p><strong>'.__('No blog matches the filter').'</strong></p>'; 672 } else { 673 echo '<p><strong>'.__('No blog').'</strong></p>'; 674 } 675 } 676 else 677 { 678 $blogs = array(); 679 if (isset($_REQUEST['blogs'])) { 680 foreach ($_REQUEST['blogs'] as $v) { 681 $blogs[$v]=true; 682 } 683 } 684 685 $pager = new dcPager($page,$this->rs_count,$nb_per_page,10); 686 687 $cols = array( 688 'blog' => '<th'. 689 ($this->core->auth->isSuperAdmin() ? ' colspan="2"' : ''). 690 ' scope="col" abbr="comm" class="first nowrap">'.__('Blog id').'</th>', 691 'name' => '<th scope="col" abbr="name">'.__('Blog name').'</th>', 692 'url' => '<th scope="col" class="nowrap">'.__('URL').'</th>', 693 'posts' => '<th scope="col" class="nowrap">'.__('Entries (all types)').'</th>', 694 'upddt' => '<th scope="col" class="nowrap">'.__('Last update').'</th>', 695 'status' => '<th scope="col" class="txt-center">'.__('Status').'</th>' 696 ); 697 698 $cols = new ArrayObject($cols); 699 $this->core->callBehavior('adminBlogListHeader',$this->core,$this->rs,$cols); 700 701 $html_block = 702 '<div class="table-outer"><table>'. 703 ($filter ? 704 '<caption>'. 705 sprintf(__('%d blog matches the filter.','%d blogs match the filter.',$this->rs_count),$this->rs_count). 706 '</caption>' 707 : 708 '<caption class="hidden">'.__('Blogs list').'</caption>' 709 ). 710 '<tr>'.implode(iterator_to_array($cols)).'</tr>%s</table></div>'; 711 712 if ($enclose_block) { 713 $html_block = sprintf($enclose_block,$html_block); 714 } 715 716 $blocks = explode('%s',$html_block); 717 718 echo $pager->getLinks(); 719 720 echo $blocks[0]; 721 722 while ($this->rs->fetch()) { 723 echo $this->blogLine(isset($blogs[$this->rs->blog_id])); 724 } 725 726 echo $blocks[1]; 727 728 echo $pager->getLinks(); 729 } 730 } 731 732 private function blogLine($checked=false) 733 { 734 $blog_id = html::escapeHTML($this->rs->blog_id); 735 736 $cols = array( 737 'check' => 738 ($this->core->auth->isSuperAdmin() ? 739 '<td class="nowrap">'. 740 form::checkbox(array('blogs[]'),$this->rs->blog_id,$checked,'','',0). 741 '</td>' : ''), 742 'blog' => 743 '<td class="nowrap">'. 744 ($this->core->auth->isSuperAdmin() ? 745 '<a href="'.$this->core->adminurl->get("admin.blog",array('id' => $blog_id)).'" '. 746 'title="'.sprintf(__('Edit blog settings for %s'),$blog_id).'">'. 747 '<img src="images/edit-mini.png" alt="'.__('Edit blog settings').'" /> '.$blog_id.'</a> ' : 748 $blog_id.' '). 749 '</td>', 750 'name' => 751 '<td class="maximal">'. 752 '<a href="'.$this->core->adminurl->get("admin.home",array('switchblog' => $this->rs->blog_id)).'" '. 753 'title="'.sprintf(__('Switch to blog %s'),$this->rs->blog_id).'">'. 754 html::escapeHTML($this->rs->blog_name).'</a>'. 755 '</td>', 756 'url' => 757 '<td class="nowrap">'. 758 '<a class="outgoing" href="'. 759 html::escapeHTML($this->rs->blog_url).'">'.html::escapeHTML($this->rs->blog_url). 760 ' <img src="images/outgoing-blue.png" alt="" /></a></td>', 761 'posts' => 762 '<td class="nowrap count">'. 763 $this->core->countBlogPosts($this->rs->blog_id). 764 '</td>', 765 'upddt' => 766 '<td class="nowrap count">'. 767 dt::str(__('%Y-%m-%d %H:%M'),strtotime($this->rs->blog_upddt) + dt::getTimeOffset($this->core->auth->getInfo('user_tz'))). 768 '</td>', 769 'status' => 770 '<td class="nowrap status txt-center">'. 771 sprintf( 772 '<img src="images/%1$s.png" alt="%2$s" title="%2$s" />', 773 ($this->rs->blog_status == 1 ? 'check-on' : ($this->rs->blog_status == 0 ? 'check-off' : 'check-wrn')), 774 $this->core->getBlogStatus($this->rs->blog_status) 775 ). 776 '</td>' 777 ); 778 779 $cols = new ArrayObject($cols); 780 $this->core->callBehavior('adminBlogListValue',$this->core,$this->rs,$cols); 781 782 return 783 '<tr class="line" id="b'.$blog_id.'">'. 784 implode(iterator_to_array($cols)). 785 '</tr>'; 786 } 661 public function display($page, $nb_per_page, $enclose_block = '', $filter = false) 662 { 663 if ($this->rs->isEmpty()) { 664 if ($filter) { 665 echo '<p><strong>' . __('No blog matches the filter') . '</strong></p>'; 666 } else { 667 echo '<p><strong>' . __('No blog') . '</strong></p>'; 668 } 669 } else { 670 $blogs = array(); 671 if (isset($_REQUEST['blogs'])) { 672 foreach ($_REQUEST['blogs'] as $v) { 673 $blogs[$v] = true; 674 } 675 } 676 677 $pager = new dcPager($page, $this->rs_count, $nb_per_page, 10); 678 679 $cols = array( 680 'blog' => '<th' . 681 ($this->core->auth->isSuperAdmin() ? ' colspan="2"' : '') . 682 ' scope="col" abbr="comm" class="first nowrap">' . __('Blog id') . '</th>', 683 'name' => '<th scope="col" abbr="name">' . __('Blog name') . '</th>', 684 'url' => '<th scope="col" class="nowrap">' . __('URL') . '</th>', 685 'posts' => '<th scope="col" class="nowrap">' . __('Entries (all types)') . '</th>', 686 'upddt' => '<th scope="col" class="nowrap">' . __('Last update') . '</th>', 687 'status' => '<th scope="col" class="txt-center">' . __('Status') . '</th>' 688 ); 689 690 $cols = new ArrayObject($cols); 691 $this->core->callBehavior('adminBlogListHeader', $this->core, $this->rs, $cols); 692 693 $html_block = 694 '<div class="table-outer"><table>' . 695 ($filter ? 696 '<caption>' . 697 sprintf(__('%d blog matches the filter.', '%d blogs match the filter.', $this->rs_count), $this->rs_count) . 698 '</caption>' 699 : 700 '<caption class="hidden">' . __('Blogs list') . '</caption>' 701 ) . 702 '<tr>' . implode(iterator_to_array($cols)) . '</tr>%s</table></div>'; 703 704 if ($enclose_block) { 705 $html_block = sprintf($enclose_block, $html_block); 706 } 707 708 $blocks = explode('%s', $html_block); 709 710 echo $pager->getLinks(); 711 712 echo $blocks[0]; 713 714 while ($this->rs->fetch()) { 715 echo $this->blogLine(isset($blogs[$this->rs->blog_id])); 716 } 717 718 echo $blocks[1]; 719 720 echo $pager->getLinks(); 721 } 722 } 723 724 private function blogLine($checked = false) 725 { 726 $blog_id = html::escapeHTML($this->rs->blog_id); 727 728 $cols = array( 729 'check' => 730 ($this->core->auth->isSuperAdmin() ? 731 '<td class="nowrap">' . 732 form::checkbox(array('blogs[]'), $this->rs->blog_id, $checked) . 733 '</td>' : ''), 734 'blog' => 735 '<td class="nowrap">' . 736 ($this->core->auth->isSuperAdmin() ? 737 '<a href="' . $this->core->adminurl->get("admin.blog", array('id' => $blog_id)) . '" ' . 738 'title="' . sprintf(__('Edit blog settings for %s'), $blog_id) . '">' . 739 '<img src="images/edit-mini.png" alt="' . __('Edit blog settings') . '" /> ' . $blog_id . '</a> ' : 740 $blog_id . ' ') . 741 '</td>', 742 'name' => 743 '<td class="maximal">' . 744 '<a href="' . $this->core->adminurl->get("admin.home", array('switchblog' => $this->rs->blog_id)) . '" ' . 745 'title="' . sprintf(__('Switch to blog %s'), $this->rs->blog_id) . '">' . 746 html::escapeHTML($this->rs->blog_name) . '</a>' . 747 '</td>', 748 'url' => 749 '<td class="nowrap">' . 750 '<a class="outgoing" href="' . 751 html::escapeHTML($this->rs->blog_url) . '">' . html::escapeHTML($this->rs->blog_url) . 752 ' <img src="images/outgoing-blue.png" alt="" /></a></td>', 753 'posts' => 754 '<td class="nowrap count">' . 755 $this->core->countBlogPosts($this->rs->blog_id) . 756 '</td>', 757 'upddt' => 758 '<td class="nowrap count">' . 759 dt::str(__('%Y-%m-%d %H:%M'), strtotime($this->rs->blog_upddt) + dt::getTimeOffset($this->core->auth->getInfo('user_tz'))) . 760 '</td>', 761 'status' => 762 '<td class="nowrap status txt-center">' . 763 sprintf( 764 '<img src="images/%1$s.png" alt="%2$s" title="%2$s" />', 765 ($this->rs->blog_status == 1 ? 'check-on' : ($this->rs->blog_status == 0 ? 'check-off' : 'check-wrn')), 766 $this->core->getBlogStatus($this->rs->blog_status) 767 ) . 768 '</td>' 769 ); 770 771 $cols = new ArrayObject($cols); 772 $this->core->callBehavior('adminBlogListValue', $this->core, $this->rs, $cols); 773 774 return 775 '<tr class="line" id="b' . $blog_id . '">' . 776 implode(iterator_to_array($cols)) . 777 '</tr>'; 778 } 787 779 } 788 780 789 781 class adminUserList extends adminGenericList 790 782 { 791 public function display($page,$nb_per_page,$enclose_block='',$filter=false) 792 { 793 if ($this->rs->isEmpty()) 794 { 795 if( $filter ) { 796 echo '<p><strong>'.__('No user matches the filter').'</strong></p>'; 797 } else { 798 echo '<p><strong>'.__('No user').'</strong></p>'; 799 } 800 } 801 else 802 { 803 $pager = new dcPager($page,$this->rs_count,$nb_per_page,10); 804 805 $html_block = 806 '<div class="table-outer clear">'. 807 '<table>'; 808 809 if( $filter ) { 810 $html_block .= '<caption>'.sprintf(__('List of %s users match the filter.'), $this->rs_count).'</caption>'; 811 } else { 812 $html_block .= '<caption class="hidden">'.__('Users list').'</caption>'; 813 } 814 815 $cols = array( 816 'username' => '<th colspan="2" scope="col" class="first">'.__('Username').'</th>', 817 'first_name' => '<th scope="col">'.__('First Name').'</th>', 818 'last_name' => '<th scope="col">'.__('Last Name').'</th>', 819 'display_name' => '<th scope="col">'.__('Display name').'</th>', 820 'entries' => '<th scope="col" class="nowrap">'.__('Entries (all types)').'</th>' 821 ); 822 823 $cols = new ArrayObject($cols); 824 $this->core->callBehavior('adminUserListHeader',$this->core,$this->rs,$cols); 825 826 $html_block .= '<tr>'.implode(iterator_to_array($cols)).'</tr>%s</table></div>'; 827 if ($enclose_block) { 828 $html_block = sprintf($enclose_block,$html_block); 829 } 830 831 echo $pager->getLinks(); 832 833 $blocks = explode('%s',$html_block); 834 835 echo $blocks[0]; 836 837 while ($this->rs->fetch()) 838 { 839 echo $this->userLine(); 840 } 841 842 echo $blocks[1]; 843 844 echo $pager->getLinks(); 845 } 846 } 847 848 private function userLine() 849 { 850 $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; 851 $img_status = ''; 852 853 $p = $this->core->getUserPermissions($this->rs->user_id); 854 855 if (isset($p[$this->core->blog->id]['p']['admin'])) { 856 $img_status = sprintf($img,__('admin'),'admin.png'); 857 } 858 if ($this->rs->user_super) { 859 $img_status = sprintf($img,__('superadmin'),'superadmin.png'); 860 } 861 862 $res = '<tr class="line">'; 863 864 $cols = array( 865 'check' => '<td class="nowrap">'.form::hidden(array('nb_post[]'),(integer) $this->rs->nb_post). 866 form::checkbox(array('users[]'),$this->rs->user_id).'</td>', 867 'username' => '<td class="maximal" scope="row"><a href="'. 868 $this->core->adminurl->get('admin.user',array('id' => $this->rs->user_id)).'">'. 869 $this->rs->user_id.'</a> '.$img_status.'</td>', 870 'first_name' => '<td class="nowrap">'.html::escapeHTML($this->rs->user_firstname).'</td>', 871 'last_name' => '<td class="nowrap">'.html::escapeHTML($this->rs->user_name).'</td>', 872 'display_name' => '<td class="nowrap">'.html::escapeHTML($this->rs->user_displayname).'</td>', 873 'entries' => '<td class="nowrap count"><a href="'. 874 $this->core->adminurl->get('admin.posts',array('user_id' => $this->rs->user_id)).'">'. 875 $this->rs->nb_post.'</a></td>' 876 ); 877 878 $cols = new ArrayObject($cols); 879 $this->core->callBehavior('adminUserListValue',$this->core,$this->rs,$cols); 880 881 $res .= implode(iterator_to_array($cols)); 882 $res .= '</tr>'; 883 884 return $res; 885 } 783 public function display($page, $nb_per_page, $enclose_block = '', $filter = false) 784 { 785 if ($this->rs->isEmpty()) { 786 if ($filter) { 787 echo '<p><strong>' . __('No user matches the filter') . '</strong></p>'; 788 } else { 789 echo '<p><strong>' . __('No user') . '</strong></p>'; 790 } 791 } else { 792 $pager = new dcPager($page, $this->rs_count, $nb_per_page, 10); 793 794 $html_block = 795 '<div class="table-outer clear">' . 796 '<table>'; 797 798 if ($filter) { 799 $html_block .= '<caption>' . sprintf(__('List of %s users match the filter.'), $this->rs_count) . '</caption>'; 800 } else { 801 $html_block .= '<caption class="hidden">' . __('Users list') . '</caption>'; 802 } 803 804 $cols = array( 805 'username' => '<th colspan="2" scope="col" class="first">' . __('Username') . '</th>', 806 'first_name' => '<th scope="col">' . __('First Name') . '</th>', 807 'last_name' => '<th scope="col">' . __('Last Name') . '</th>', 808 'display_name' => '<th scope="col">' . __('Display name') . '</th>', 809 'entries' => '<th scope="col" class="nowrap">' . __('Entries (all types)') . '</th>' 810 ); 811 812 $cols = new ArrayObject($cols); 813 $this->core->callBehavior('adminUserListHeader', $this->core, $this->rs, $cols); 814 815 $html_block .= '<tr>' . implode(iterator_to_array($cols)) . '</tr>%s</table></div>'; 816 if ($enclose_block) { 817 $html_block = sprintf($enclose_block, $html_block); 818 } 819 820 echo $pager->getLinks(); 821 822 $blocks = explode('%s', $html_block); 823 824 echo $blocks[0]; 825 826 while ($this->rs->fetch()) { 827 echo $this->userLine(); 828 } 829 830 echo $blocks[1]; 831 832 echo $pager->getLinks(); 833 } 834 } 835 836 private function userLine() 837 { 838 $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; 839 $img_status = ''; 840 841 $p = $this->core->getUserPermissions($this->rs->user_id); 842 843 if (isset($p[$this->core->blog->id]['p']['admin'])) { 844 $img_status = sprintf($img, __('admin'), 'admin.png'); 845 } 846 if ($this->rs->user_super) { 847 $img_status = sprintf($img, __('superadmin'), 'superadmin.png'); 848 } 849 850 $res = '<tr class="line">'; 851 852 $cols = array( 853 'check' => '<td class="nowrap">' . form::hidden(array('nb_post[]'), (integer) $this->rs->nb_post) . 854 form::checkbox(array('users[]'), $this->rs->user_id) . '</td>', 855 'username' => '<td class="maximal" scope="row"><a href="' . 856 $this->core->adminurl->get('admin.user', array('id' => $this->rs->user_id)) . '">' . 857 $this->rs->user_id . '</a> ' . $img_status . '</td>', 858 'first_name' => '<td class="nowrap">' . html::escapeHTML($this->rs->user_firstname) . '</td>', 859 'last_name' => '<td class="nowrap">' . html::escapeHTML($this->rs->user_name) . '</td>', 860 'display_name' => '<td class="nowrap">' . html::escapeHTML($this->rs->user_displayname) . '</td>', 861 'entries' => '<td class="nowrap count"><a href="' . 862 $this->core->adminurl->get('admin.posts', array('user_id' => $this->rs->user_id)) . '">' . 863 $this->rs->nb_post . '</a></td>' 864 ); 865 866 $cols = new ArrayObject($cols); 867 $this->core->callBehavior('adminUserListValue', $this->core, $this->rs, $cols); 868 869 $res .= implode(iterator_to_array($cols)); 870 $res .= '</tr>'; 871 872 return $res; 873 } 886 874 }
Note: See TracChangeset
for help on using the changeset viewer.