Changeset 1806:6a0391e85f73
- Timestamp:
- 09/13/13 11:38:14 (11 years ago)
- Branch:
- actionsreloaded
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/js/_posts_actions.js
r1638 r1806 1 1 $(function() { 2 $('#new_auth_id').autocomplete(usersList, 3 { 4 delay: 1000, 5 matchSubset: true, 6 matchContains: true 7 }); 2 new_auth_id = $('#new_auth_id'); 3 if (new_auth_id.length) { 4 new_auth_id.autocomplete(usersList, 5 { 6 delay: 1000, 7 matchSubset: true, 8 matchContains: true 9 }); 10 } 8 11 $('#new_cat').toggleWithLegend($('#new_cat').parent().children().not('#new_cat'), { 9 12 // no cookie on new category as we don't use this every day -
admin/posts.php
r1796 r1806 104 104 # Actions combo box 105 105 106 $posts_actions et = new dcPostsActionSet($core,'posts.php');107 108 $posts_actions et->process();106 $posts_actions_page = new dcPostsActionsPage($core,'posts.php'); 107 108 $posts_actions_page->process(); 109 109 110 110 /* Get posts … … 287 287 288 288 '<p class="col right"><label for="action" class="classic">'.__('Selected entries action:').'</label> '. 289 form::combo('action',$posts_actions et->getCombo()).289 form::combo('action',$posts_actions_page->getCombo()). 290 290 '<input type="submit" value="'.__('ok').'" /></p>'. 291 291 form::hidden(array('user_id'),$user_id). -
admin/posts_actions.php
r1796 r1806 18 18 dcPage::check('usage,contentadmin'); 19 19 20 $posts_actions et = new dcPostsActionSet($core,'posts.php');20 $posts_actions_page = new dcPostsActionsPage($core,'posts.php'); 21 21 22 $posts_actions et->process();22 $posts_actions_page->process(); 23 23 24 24 ?> -
inc/admin/actions/class.dcaction.php
r1796 r1806 12 12 if (!defined('DC_RC_PATH')) { return; } 13 13 14 abstract class dcAction { 15 protected $actionset; 16 17 public function setActionSet($as) { 18 $this->actionset = $as; 19 } 20 abstract public function onAction($post,$actionset,$post); 21 } 22 23 class dcSimpleAction extends dcAction { 24 protected $callback; 25 26 public function __construct($callback) { 27 $this->callback = $callback; 28 } 29 30 public function onAction($core,$actionset,$post) { 31 return call_user_func($this->callback,$core,$actionset,$post); 32 } 33 } 34 35 class dcActionSet 14 /** 15 * dcActionsPage -- handler for action page on selected entries 16 * 17 */ 18 abstract class dcActionsPage 36 19 { 20 /** @var string form submit uri */ 37 21 protected $uri; 22 /** @var dcCore dotclear core instance */ 38 23 protected $core; 24 /** @var array action combo box */ 39 25 protected $combo; 26 /** @var array list of defined actions (callbacks) */ 40 27 protected $actions; 41 protected $ids; 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 */ 42 31 protected $rs; 32 /** @var array redirection $_GET arguments, if any (does not contain ids by default, ids may be merged to it) */ 43 33 protected $redir_args; 34 /** @var array list of $_POST fields used to build the redirection */ 44 35 protected $redirect_fields; 36 /** @var string current action, if any */ 45 37 protected $action; 46 38 39 /** @var string title for checkboxes list, if displayed */ 40 protected $cb_title; 41 42 /** 43 * Class constructor 44 * 45 * @param mixed $core dotclear core 46 * @param mixed $uri form uri 47 * 48 * @access public 49 * 50 * @return mixed Value. 51 */ 47 52 public function __construct($core,$uri) { 48 53 $this->core = $core; … … 53 58 $this->redirect_fields = array(); 54 59 $this->action = ''; 55 } 56 60 $this->cb_title = __('Title'); 61 } 62 63 /** 64 * addAction - adds an action 65 * 66 * @param string $actions the actions names as if it was a standalone combo array. 67 * It will be merged with other actions. 68 * Can be bound to multiple values, if the same callback is to be called 69 * @param callback $callback the callback for the action. 70 * 71 * @access public 72 * 73 * @return dcActionsPage the actions page itself, enabling to chain addAction(). 74 */ 57 75 public function addAction ($actions,$callback) { 58 if (is_array($callback)) {59 $callback = new dcSimpleAction($callback);60 }61 76 foreach ($actions as $k => $a) { 77 // Check each case of combo definition 78 // Store form values in $values 62 79 if (is_array($a)) { 63 80 $values = array_values($a); … … 73 90 $this->combo[$k] = $a; 74 91 } 92 // Associate each potential value to the callback 75 93 foreach ($values as $v) { 76 94 $this->actions[$v]=$callback; 77 95 } 78 96 } 79 $callback->setActionSet($this); 80 } 81 97 return $this; 98 } 99 100 /** 101 * getCombo - returns the actions combo, useable through form::combo 102 * 103 * @access public 104 * 105 * @return array the actions combo 106 */ 82 107 public function getCombo() { 83 108 return $this->combo; 84 109 } 85 110 111 112 /** 113 * getIDS() - returns the list of selected entries 114 * 115 * @access public 116 * 117 * @return array the list 118 */ 86 119 public function getIDs() { 87 return $this->ids; 88 } 89 public function getIDsHidden() { 120 return array_keys($this->entries); 121 } 122 123 /** 124 * getIDS() - returns the list of selected entries as HTML hidden fields string 125 * 126 * @access public 127 * 128 * @return string the HTML code for hidden fields 129 */ 130 public function getIDsHidden() { 90 131 $ret = ''; 91 foreach ($this-> ids as $id) {132 foreach ($this->entries as $id->$v) { 92 133 $ret .= form::hidden('entries[]',$id); 93 134 } 94 135 return $ret; 95 136 } 137 138 /** 139 * getHiddenFields() - returns all redirection parameters as HTML hidden fields 140 * 141 * @param boolean $with_ids if true, also include ids in HTML code 142 * 143 * @access public 144 * 145 * @return string the HTML code for hidden fields 146 */ 96 147 public function getHiddenFields($with_ids = false) { 97 148 $ret = ''; … … 104 155 return $ret; 105 156 } 157 158 159 /** 160 * getRS() - get record from DB Query containing requested IDs 161 * 162 * @param boolean $with_ids if true, also include ids in HTML code 163 * 164 * @access public 165 * 166 * @return string the HTML code for hidden fields 167 */ 106 168 public function getRS() { 107 169 return $this->rs; 108 170 } 109 171 110 public function setupRedir($from) { 172 /** 173 * setupRedir - setup redirection arguments 174 * by default, $_POST fields as defined in redirect_fields attributes 175 * are set into redirect_args. 176 * 177 * @param array $from input to parse fields from (usually $_POST) 178 * 179 * @access protected 180 */ 181 protected function setupRedir($from) { 111 182 foreach ($this->redirect_fields as $p) { 112 183 if (isset($from[$p])) { … … 115 186 } 116 187 } 188 189 /** 190 * getRedirection - returns redirection URL 191 * 192 * @param array $params extra parameters to append to redirection 193 * must be an array : each key is the name, 194 * each value is the wanted value 195 * @param boolean $with_selected_entries if true, add selected entries in url 196 * 197 * @access public 198 * 199 * @return string the redirection url 200 */ 117 201 public function getRedirection($params=array(),$with_selected_entries=false) { 118 202 $redir_args = array_merge($params,$this->redir_args); 119 203 if ($with_selected_entries) { 120 $redir_args['entries'] = $this->ids;204 $redir_args['entries'] = array_keys($this->entries); 121 205 } 122 206 return $this->uri.'?'.http_build_query($redir_args); 123 207 } 124 208 209 /** 210 * redirect - redirects to redirection page 211 * 212 * @see getRedirection for arguments details 213 * 214 * @access public 215 */ 125 216 public function redirect($params=array(),$with_selected_entries=false) { 126 217 http::redirect($this->getRedirection($params,$with_selected_entries)); 127 218 } 128 219 129 public function beginPage($head='') { 130 } 131 132 public function endPage() { 133 } 220 /** 221 * getAction - returns current action, if any 222 * 223 * @see getRedirection for arguments details 224 * 225 * @access public 226 * 227 * @return string the action 228 */ 134 229 public function getAction() { 135 230 return $this->action; 136 231 } 232 233 /** 234 * process - proceeds action handling, if any 235 * this method may issue an exit() if 236 * an action is being processed. If it 237 * returns, no action has been performed 238 * 239 * @access public 240 */ 137 241 public function process() { 138 242 $from = new ArrayObject($_POST); 139 if (isset($from['redir']) && strpos($from['redir'],'://') === false) { 140 $this->redir = html::escapeURL($_POST['redir']); 141 } else { 142 $this->setupRedir($from); 143 } 243 $this->setupRedir($from); 144 244 $this->fetchEntries($from); 145 245 if (isset($from['action'])) { … … 150 250 if ($from['action']==$k) { 151 251 $performed = true; 152 $v->onAction($this->core,$this,$from);252 call_user_func($v,$this->core,$this,$from); 153 253 } 154 254 } … … 161 261 } 162 262 } 163 263 264 /** 265 * getcheckboxes -returns html code for selected entries 266 * as a table containing entries checkboxes 267 * 268 * @access public 269 * 270 * @return string the html code for checkboxes 271 */ 272 public function getCheckboxes() { 273 $ret = 274 '<table class="posts-list"><tr>'. 275 '<th colspan="2">'.$this->cb_title.'</th>'. 276 '</tr>'; 277 foreach ($this->entries as $id=>$title) { 278 $ret .= 279 '<tr><td>'. 280 form::checkbox(array('entries[]'),$id,true,'','').'</td>'. 281 '<td>'. $title.'</td></tr>'; 282 } 283 $ret .= '</table>'; 284 return $ret; 285 } 286 287 /** 288 * beginPage, endPage - displays the beginning/ending of a page, if action does not redirects dirtectly 289 * 290 * These methods are called from the actions themselves. 291 * 292 * @param string $breadcrumb breadcrumb to display 293 * @param string $head page header to include 294 * 295 * @access public 296 */ 297 abstract public function beginPage($breadcrumb='',$head=''); 298 abstract public function endPage(); 299 300 /** 301 * fetchEntries - fills-in information by requesting into db 302 * this method may setup the following attributes 303 * * entries : list of entries (checked against permissions) 304 * entries ids are array keys, values contain entry description (if relevant) 305 * * rs : record given by db request 306 * @access protected 307 */ 308 abstract protected function fetchEntries($from); 309 164 310 } 165 311 -
inc/admin/actions/class.dcactionposts.php
r1796 r1806 12 12 if (!defined('DC_RC_PATH')) { return; } 13 13 14 $GLOBALS['core']->addBehavior('adminPostsActionSet',array('dcDefaultPostActions','adminPostsActionSet')); 15 $GLOBALS['core']->addBehavior('adminPostsActionSet',array('dcLegacyPosts','adminPostsActionSet')); 16 17 class dcPostsActionSet extends dcActionSet 14 class dcPostsActionsPage extends dcActionsPage 18 15 { 19 16 public function __construct($core,$uri) { … … 21 18 $this->redirect_fields = array('user_id','cat_id','status', 22 19 'selected','month','lang','sortby','order','page','nb'); 23 $core->callBehavior('adminPostsActionSet',$core,$this); 20 // We could have added a behavior here, but we want default action 21 // to be setup first 22 dcDefaultPostActions::adminPostsActionsPage($core,$this); 23 $core->callBehavior('adminPostsActionsPage',$core,$this); 24 24 25 25 } … … 28 28 dcPage::open( 29 29 __('Entries'), 30 dcPage::jsLoad('js/jquery/jquery.autocomplete.js').30 31 31 dcPage::jsLoad('js/_posts_actions.js'). 32 dcPage::jsMetaEditor().33 32 $head, 34 33 $breadcrumb … … 42 41 43 42 public function error(Exception $e) { 44 $this->core->er orr->add($e->getMessage());43 $this->core->error->add($e->getMessage()); 45 44 $this->beginPage(dcPage::breadcrumb( 46 45 array( 47 html::escapeHTML($ core->blog->name) => '',46 html::escapeHTML($this->core->blog->name) => '', 48 47 __('Entries') => 'posts.php', 49 48 '<span class="page-title">'.__('Entries actions').'</span>' => '' … … 53 52 } 54 53 55 public function getCheckboxes() { 56 $ret = 57 '<table class="posts-list"><tr>'. 58 '<th colspan="2">'.__('Title').'</th>'. 59 '</tr>'; 60 foreach ($this->entries as $id=>$title) { 61 $ret .= 62 '<tr><td>'. 63 form::checkbox(array('entries[]'),$id,true,'','').'</td>'. 64 '<td>'. $title.'</td></tr>'; 65 } 66 $ret .= '</table>'; 67 return $ret; 68 } 69 70 71 public function fetchEntries($from) { 54 protected function fetchEntries($from) { 72 55 if (!empty($from['entries'])) 73 56 { … … 90 73 $posts = $this->core->blog->getPosts($params); 91 74 while ($posts->fetch()) { 92 $this->ids[] = $posts->post_id;93 75 $this->entries[$posts->post_id] = $posts->post_title; 94 76 } … … 102 84 class dcDefaultPostActions 103 85 { 104 public static function adminPostsAction Set($core, dcPostsActionSet $as) {86 public static function adminPostsActionsPage($core, dcPostsActionsPage $ap) { 105 87 if ($core->auth->check('publish,contentadmin',$core->blog->id)) { 106 $a s->addAction(88 $ap->addAction( 107 89 array(__('Status') => array( 108 90 __('Publish') => 'publish', … … 114 96 ); 115 97 } 116 $a s->addAction(98 $ap->addAction( 117 99 array(__('Mark')=> array( 118 100 __('Mark as selected') => 'selected', … … 121 103 array('dcDefaultPostActions','doUpdateSelectedPost') 122 104 ); 123 $a s->addAction(105 $ap->addAction( 124 106 array(__('Change') => array( 125 107 __('Change category') => 'category', … … 127 109 array('dcDefaultPostActions','doChangePostCategory') 128 110 ); 129 $a s->addAction(111 $ap->addAction( 130 112 array(__('Change') => array( 131 113 __('Change language') => 'lang', … … 135 117 if ($core->auth->check('admin',$core->blog->id)) 136 118 { 137 $a s->addAction(119 $ap->addAction( 138 120 array(__('Change') => array( 139 121 __('Change author') => 'author')), 140 array('dcDefaultPostActions','doChangePost Lang')122 array('dcDefaultPostActions','doChangePostAuthor') 141 123 ); 142 124 } 143 125 if ($core->auth->check('delete,contentadmin',$core->blog->id)) { 144 $a s->addAction(126 $ap->addAction( 145 127 array(__('Delete') => array( 146 128 __('Delete') => 'delete')), … … 150 132 } 151 133 152 public static function doChangePostStatus($core, dcPostsAction Set $as, $post) {153 switch ($a s->getAction()) {134 public static function doChangePostStatus($core, dcPostsActionsPage $ap, $post) { 135 switch ($ap->getAction()) { 154 136 case 'unpublish' : $status = 0; break; 155 137 case 'schedule' : $status = -1; break; … … 157 139 default : $status = 1; break; 158 140 } 159 160 try 161 { 162 $posts_ids = $as->getIDs(); 163 if (empty($posts_ids)) { 164 throw new Exception(__('No entry selected')); 165 } 166 $core->blog->updPostsStatus($posts_ids,$status); 167 168 $as->redirect(array('upd' => 1),true); 169 } 170 catch (Exception $e) 171 { 172 $core->error->add($e->getMessage()); 173 } 174 } 175 176 public static function doUpdateSelectedPost($core, dcPostsActionSet $as, $post) { 177 try 178 { 179 $posts_ids = $as->getIDs(); 180 if (empty($posts_ids)) { 181 throw new Exception(__('No entry selected')); 182 } 183 184 $core->blog->updPostsSelected($posts_ids,$action == 'selected'); 185 186 $as->redirect(array('upd' => 1),true); 187 } 188 catch (Exception $e) 189 { 190 $core->error->add($e->getMessage()); 191 } 192 } 193 194 public static function doDeletePost($core, dcPostsActionSet $as, $post) { 195 196 $posts_ids = $as->getIDs(); 141 $posts_ids = $ap->getIDs(); 142 if (empty($posts_ids)) { 143 throw new Exception(__('No entry selected')); 144 } 145 $core->blog->updPostsStatus($posts_ids,$status); 146 147 $ap->redirect(array('upd' => 1),true); 148 } 149 150 public static function doUpdateSelectedPost($core, dcPostsActionsPage $ap, $post) { 151 $posts_ids = $ap->getIDs(); 152 if (empty($posts_ids)) { 153 throw new Exception(__('No entry selected')); 154 } 155 $action = $ap->getAction(); 156 $core->blog->updPostsSelected($posts_ids,$action == 'selected'); 157 158 $ap->redirect(array('upd' => 1),true); 159 } 160 161 public static function doDeletePost($core, dcPostsActionsPage $ap, $post) { 162 163 $posts_ids = $ap->getIDs(); 197 164 if (empty($posts_ids)) { 198 165 throw new Exception(__('No entry selected')); … … 210 177 $core->blog->delPosts($posts_ids); 211 178 212 $a s->redirect(array('del',1),false);213 } 214 215 public static function doChangePostCategory($core, dcPostsAction Set $as, $post) {179 $ap->redirect(array('del',1),false); 180 } 181 182 public static function doChangePostCategory($core, dcPostsActionsPage $ap, $post) { 216 183 if (isset($post['new_cat_id'])) { 217 $posts_ids = $a s->getIDs();184 $posts_ids = $ap->getIDs(); 218 185 if (empty($posts_ids)) { 219 186 throw new Exception(__('No entry selected')); … … 239 206 $core->blog->updPostsCategory($posts_ids, $new_cat_id); 240 207 241 $a s->redirect(array('upd'=>1),true);208 $ap->redirect(array('upd'=>1),true); 242 209 } else { 243 $a s->beginPage(210 $ap->beginPage( 244 211 dcPage::breadcrumb( 245 212 array( … … 256 223 echo 257 224 '<form action="posts.php" method="post">'. 258 $a s->getCheckboxes().225 $ap->getCheckboxes(). 259 226 '<p><label for="new_cat_id" class="classic">'.__('Category:').'</label> '. 260 227 form::combo('new_cat_id',$categories_combo,''); … … 277 244 '<input type="submit" value="'.__('Save').'" /></p>'. 278 245 '</form>'; 279 $a s->endPage();280 281 } 282 283 } 284 public static function doChangePostAuthor($core, dcPostsAction Set $as, $post) {246 $ap->endPage(); 247 248 } 249 250 } 251 public static function doChangePostAuthor($core, dcPostsActionsPage $ap, $post) { 285 252 if (isset($post['new_auth_id']) && $core->auth->check('admin',$core->blog->id)) { 286 253 $new_user_id = $post['new_auth_id']; 287 $posts_ids = $a s->getIDs();254 $posts_ids = $ap->getIDs(); 288 255 if (empty($posts_ids)) { 289 256 throw new Exception(__('No entry selected')); 290 257 } 291 292 try 293 { 294 if ($core->getUser($new_user_id)->isEmpty()) { 295 throw new Exception(__('This user does not exist')); 296 } 297 298 $cur = $core->con->openCursor($core->prefix.'post'); 299 $cur->user_id = $new_user_id; 300 $cur->update('WHERE post_id '.$core->con->in($posts_ids)); 301 302 $as->redirect(array('upd' => 1),true); 303 } 304 catch (Exception $e) 305 { 306 $core->error->add($e->getMessage()); 307 } 258 if ($core->getUser($new_user_id)->isEmpty()) { 259 throw new Exception(__('This user does not exist')); 260 } 261 262 $cur = $core->con->openCursor($core->prefix.'post'); 263 $cur->user_id = $new_user_id; 264 $cur->update('WHERE post_id '.$core->con->in($posts_ids)); 265 266 $ap->redirect(array('upd' => 1),true); 308 267 } else { 309 268 $usersList = ''; … … 319 278 } 320 279 } 321 $a s->beginPage(280 $ap->beginPage( 322 281 dcPage::breadcrumb( 323 282 array( 324 283 html::escapeHTML($core->blog->name) => '', 325 284 __('Entries') => 'posts.php', 326 '<span class="page-title">'.__('Change author for entries').'</span>' => '' 327 )),328 '<script type="text/javascript">'."\n".329 "//<![CDATA[\n".330 'usersList = ['.$usersList.']'."\n".331 "\n//]]>\n".332 "</script>\n"285 '<span class="page-title">'.__('Change author for entries').'</span>' => '')), 286 dcPage::jsLoad('js/jquery/jquery.autocomplete.js'). 287 '<script type="text/javascript">'."\n". 288 "//<![CDATA[\n". 289 'usersList = ['.$usersList.']'."\n". 290 "\n//]]>\n". 291 "</script>\n" 333 292 ); 334 293 335 294 echo 336 295 '<form action="posts_actions.php" method="post">'. 337 $a s->getCheckboxes().296 $ap->getCheckboxes(). 338 297 '<p><label for="new_auth_id" class="classic">'.__('New author (author ID):').'</label> '. 339 298 form::field('new_auth_id',20,255); … … 344 303 '<input type="submit" value="'.__('Save').'" /></p>'. 345 304 '</form>'; 346 $a s->endPage();347 } 348 } 349 public static function doChangePostLang($core, dcPostsAction Set $as, $post) {305 $ap->endPage(); 306 } 307 } 308 public static function doChangePostLang($core, dcPostsActionsPage $ap, $post) { 350 309 if (isset($post['new_lang'])) { 351 310 $new_lang = $post['new_lang']; 352 try 353 { 354 $cur = $core->con->openCursor($core->prefix.'post'); 355 $cur->post_lang = $new_lang; 356 $cur->update('WHERE post_id '.$core->con->in($posts_ids)); 357 358 $as->redirect(array('upd' => 1),true); 359 } 360 catch (Exception $e) 361 { 362 $core->error->add($e->getMessages()); 363 } 311 $cur = $core->con->openCursor($core->prefix.'post'); 312 $cur->post_lang = $new_lang; 313 $cur->update('WHERE post_id '.$core->con->in($posts_ids)); 314 315 $ap->redirect(array('upd' => 1),true); 364 316 } else { 365 $a s->beginPage(317 $ap->beginPage( 366 318 dcPage::breadcrumb( 367 319 array( … … 388 340 echo 389 341 '<form action="posts_actions.php" method="post">'. 390 $a s->getCheckboxes().342 $ap->getCheckboxes(). 391 343 392 344 '<p><label for="new_lang" class="classic">'.__('Entry lang:').'</label> '. … … 401 353 } 402 354 } 403 404 405 class dcLegacyPosts406 {407 public static function adminPostsActionSet($core, dcPostsActionSet $as) {408 $stub_actions = new ArrayObject();409 $core->callBehavior('adminPostsActionsCombo',array($stub_actions));410 if (!empty($stub_actions)) {411 $as->addAction($stub_actions,array('dcLegacyPosts','onActionLegacy'));412 }413 }414 415 public static function onActionLegacy($core, dcPostsActionSet $as, $post) {416 $core->callBehavior('adminPostsActions',$core,$as->getRS(),$as->getAction(),$as->getRedirection());417 $as->beginPage($core->callBehavior('adminPostsActionsHeaders'),'');418 $core->callBehavior('adminPostsActionsContent',$core,$as->getAction(),$as->getHiddenFields(true));419 $as->endPage();420 421 }422 } -
inc/prepend.php
r1796 r1806 64 64 $__autoload['context'] = dirname(__FILE__).'/public/lib.tpl.context.php'; 65 65 $__autoload['dcUrlHandlers'] = dirname(__FILE__).'/public/lib.urlhandlers.php'; 66 $__autoload['dcPostsAction Set'] = dirname(__FILE__).'/admin/actions/class.dcactionposts.php';67 $__autoload['dcAction Set'] = dirname(__FILE__).'/admin/actions/class.dcaction.php';66 $__autoload['dcPostsActionsPage'] = dirname(__FILE__).'/admin/actions/class.dcactionposts.php'; 67 $__autoload['dcActionsPage'] = dirname(__FILE__).'/admin/actions/class.dcaction.php'; 68 68 69 69 # Clearbricks extensions
Note: See TracChangeset
for help on using the changeset viewer.