Changeset 3707:3a350757c847 for inc/admin/actions/class.dcactionblogs.php
- Timestamp:
- 02/17/18 18:03:29 (7 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.