Changeset 2330
- Timestamp:
- 06/08/10 10:26:25 (13 years ago)
- Location:
- plugins/postExpired
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/postExpired/_admin.php
r2187 r2330 12 12 13 13 if (!defined('DC_CONTEXT_ADMIN')){return;} 14 if (!$core->plugins->moduleExists('metadata')){return;}15 14 16 15 # Admin behaviors … … 36 35 try { 37 36 $categories = $GLOBALS['core']->blog->getCategories(array('post_type'=>'post')); 38 while ($categories->fetch()) { 37 while ($categories->fetch()) 38 { 39 39 $categories_combo[] = new formSelectOption( 40 40 str_repeat(' ',$categories->level-1).'• '.html::escapeHTML($categories->cat_title), … … 42 42 ); 43 43 } 44 } catch (Exception $e) { } 44 } 45 catch (Exception $e) { } 45 46 return $categories_combo; 46 47 } 47 48 48 49 public static function statusCombo() 49 50 { … … 54 55 ); 55 56 } 56 57 57 58 public static function selectedCombo() 58 59 { … … 63 64 ); 64 65 } 65 66 66 67 public static function header($posts_actions=true) 67 68 { … … 69 70 dcPage::jsLoad('index.php?pf=postExpired/js/postexpired.js'); 70 71 } 71 72 72 73 public static function form($post) 73 74 { … … 77 78 if ($post) 78 79 { 79 $meta = new dcMeta($core); 80 $rs_date = $meta->getMeta('postexpired',1,null,$post->post_id); 80 $rs_date = $core->meta->getMetadata(array('meta_type'=>'postexpired','limit'=>1,'post_id'=>$post->post_id)); 81 81 if (!$rs_date->isEmpty()) 82 82 { 83 83 $expired_date = date('Y-m-d H:i',strtotime($rs_date->meta_id)); 84 84 85 $rs_status = $ meta->getMeta('postexpiredstatus',1,null,$post->post_id);85 $rs_status = $core->meta->getMetadata(array('meta_type'=>'postexpiredstatus','limit'=>1,'post_id'=>$post->post_id)); 86 86 $expired_status = $rs_status->isEmpty() ? '' : (string) $rs_status->meta_id; 87 87 88 $rs_cat = $ meta->getMeta('postexpiredcat',1,null,$post->post_id);88 $rs_cat = $core->meta->getMetadata(array('meta_type'=>'postexpiredcat','limit'=>1,'post_id'=>$post->post_id)); 89 89 $expired_cat = $rs_cat->isEmpty() ? '' : (string) $rs_cat->meta_id; 90 90 91 $rs_selected = $ meta->getMeta('postexpiredselected',1,null,$post->post_id);91 $rs_selected = $core->meta->getMetadata(array('meta_type'=>'postexpiredselected','limit'=>1,'post_id'=>$post->post_id)); 92 92 $expired_selected = $rs_selected->isEmpty() ? '' : (string) $rs_selected->meta_id; 93 93 } 94 94 } 95 95 96 96 echo 97 97 '<h3 id="postexpired-form-title">'.__('Expired date').'</h3>'. … … 115 115 echo '</div>'; 116 116 } 117 117 118 118 public static function set(&$cur,&$post_id) 119 119 { 120 120 global $core; 121 121 if (!isset($_POST['post_expired_date'])) return; 122 122 123 123 $post_id = (integer) $post_id; 124 $meta = new dcMeta($core); 125 124 126 125 # --BEHAVIOR-- adminBeforePostExpiredSave 127 126 $core->callBehavior('adminBeforePostExpiredSave',$cur,$post_id); 128 127 129 128 self::del($post_id); 130 129 131 130 if (!empty($_POST['post_expired_date']) 132 131 && (!empty($_POST['post_expired_status']) … … 135 134 { 136 135 $post_expired_date = date('Y-m-d H:i:00',strtotime($_POST['post_expired_date'])); 137 $meta->setPostMeta($post_id,'postexpired',$post_expired_date); 138 139 if (!empty($_POST['post_expired_status'])) { 140 $meta->setPostMeta($post_id,'postexpiredstatus',(string) $_POST['post_expired_status']); 141 } 142 if (!empty($_POST['post_expired_selected'])) { 143 $meta->setPostMeta($post_id,'postexpiredcat',(string) $_POST['post_expired_cat']); 144 } 145 if (!empty($_POST['post_expired_selected'])) { 146 $meta->setPostMeta($post_id,'postexpiredselected',(string) $_POST['post_expired_selected']); 147 } 148 } 149 136 $core->meta->setPostMeta($post_id,'postexpired',$post_expired_date); 137 138 if (!empty($_POST['post_expired_status'])) 139 { 140 $core->meta->setPostMeta($post_id,'postexpiredstatus',(string) $_POST['post_expired_status']); 141 } 142 if (!empty($_POST['post_expired_selected'])) 143 { 144 $core->meta->setPostMeta($post_id,'postexpiredcat',(string) $_POST['post_expired_cat']); 145 } 146 if (!empty($_POST['post_expired_selected'])) 147 { 148 $core->meta->setPostMeta($post_id,'postexpiredselected',(string) $_POST['post_expired_selected']); 149 } 150 } 151 150 152 # --BEHAVIOR-- adminAfterPostExpiredSave 151 153 $core->callBehavior('adminAfterPostExpiredSave',$cur,$post_id); 152 154 } 153 155 154 156 public static function del($post_id) 155 157 { 156 158 global $core; 157 159 158 160 $post_id = (integer) $post_id; 159 $meta = new dcMeta($core); 160 161 161 162 # --BEHAVIOR-- adminBeforePostExpiredDelete 162 163 $core->callBehavior('adminBeforePostExpiredDelete',$post_id); 163 164 $ meta->delPostMeta($post_id,'postexpired');165 $ meta->delPostMeta($post_id,'postexpiredstatus');166 $ meta->delPostMeta($post_id,'postexpiredcat');167 $ meta->delPostMeta($post_id,'postexpiredselected');168 } 169 164 165 $core->meta->delPostMeta($post_id,'postexpired'); 166 $core->meta->delPostMeta($post_id,'postexpiredstatus'); 167 $core->meta->delPostMeta($post_id,'postexpiredcat'); 168 $core->meta->delPostMeta($post_id,'postexpiredselected'); 169 } 170 170 171 public static function combo(&$args) 171 172 { 172 if ($GLOBALS['core']->auth->check('usage,contentadmin',$GLOBALS['core']->blog->id)) { 173 if ($GLOBALS['core']->auth->check('usage,contentadmin',$GLOBALS['core']->blog->id)) 174 { 173 175 $args[0][__('Expired entries')][__('add expired date')] = 'postexpired_add'; 174 176 } 175 if ($GLOBALS['core']->auth->check('delete,contentadmin',$GLOBALS['core']->blog->id)) { 177 if ($GLOBALS['core']->auth->check('delete,contentadmin',$GLOBALS['core']->blog->id)) 178 { 176 179 $args[0][__('Expired entries')][__('remove expired date')] = 'postexpired_remove'; 177 180 } 178 181 } 179 182 180 183 public static function action(&$core,$posts,$action,$redir) 181 184 { … … 184 187 # --BEHAVIOR-- adminPostExpiredActions 185 188 $core->callBehavior('adminPostExpiredActions',$core,$posts,$action,$redir); 186 189 187 190 if (!$core->auth->check('usage,contentadmin',$core->blog->id) 188 191 || empty($_POST['new_post_expired_date']) … … 193 196 http::redirect($redir); 194 197 } 195 196 try {197 $meta = new dcMeta($core);198 199 try 200 { 198 201 $new_post_expired_date = date('Y-m-d H:i:00',strtotime($_POST['new_post_expired_date'])); 199 202 200 203 while ($posts->fetch()) 201 204 { 202 $rs = $ meta->getMeta('postexpired',1,null,$posts->post_id);205 $rs = $core->meta->getMetadata(array('meta_type'=>'postexpired','limit'=>1,'post_id'=>$posts->post_id)); 203 206 if ($rs->isEmpty()) 204 207 { 205 $meta->setPostMeta($posts->post_id,'postexpired',$new_post_expired_date); 206 207 if (!empty($_POST['new_post_expired_status'])) { 208 $meta->setPostMeta($posts->post_id,'postexpiredstatus',$_POST['new_post_expired_status']); 208 $core->meta->setPostMeta($posts->post_id,'postexpired',$new_post_expired_date); 209 210 if (!empty($_POST['new_post_expired_status'])) 211 { 212 $core->meta->setPostMeta($posts->post_id,'postexpiredstatus',$_POST['new_post_expired_status']); 209 213 } 210 if (!empty($_POST['new_post_expired_cat'])) { 211 $meta->setPostMeta($posts->post_id,'postexpiredcat',$_POST['new_post_expired_cat']); 214 if (!empty($_POST['new_post_expired_cat'])) 215 { 216 $core->meta->setPostMeta($posts->post_id,'postexpiredcat',$_POST['new_post_expired_cat']); 212 217 } 213 if (!empty($_POST['new_post_expired_selected'])) { 214 $meta->setPostMeta($posts->post_id,'postexpiredselected',$_POST['new_post_expired_selected']); 218 if (!empty($_POST['new_post_expired_selected'])) 219 { 220 $core->meta->setPostMeta($posts->post_id,'postexpiredselected',$_POST['new_post_expired_selected']); 215 221 } 216 222 } … … 218 224 http::redirect($redir); 219 225 } 220 catch (Exception $e) { 226 catch (Exception $e) 227 { 221 228 $core->error->add($e->getMessage()); 222 229 } … … 230 237 } 231 238 232 try { 233 $meta = new dcMeta($core); 234 239 try 240 { 235 241 $posts_ids = array(); 236 242 while($posts->fetch()) … … 238 244 $posts_ids[] = $posts->id; 239 245 } 240 246 241 247 $rs_params['no_content'] = true; 242 248 $rs_params['post_id'] = $posts_ids; 243 249 $rs_params['meta_id'] = 'postexpired'; 244 $rs = $ meta->getPostsByMeta($rs_params);245 250 $rs = $core->meta->getPostsByMeta($rs_params); 251 246 252 while ($rs->fetch()) 247 253 { 248 254 self::del($rs->post_id); 249 255 } 250 256 251 257 http::redirect($redir); 252 258 } 253 catch (Exception $e) { 259 catch (Exception $e) 260 { 254 261 $core->error->add($e->getMessage()); 255 262 } … … 277 284 form::combo('new_post_expired_selected',self::selectedCombo(),'','',2). 278 285 '</label></p><p>'; 279 286 280 287 # --BEHAVIOR-- adminPostExpiredActionsContent 281 288 $core->callBehavior('adminPostExpiredActionsContent',$core,$action,$hidden_fields); 282 289 283 290 echo 284 291 $hidden_fields. … … 290 297 elseif ($action == 'postexpired_remove') 291 298 { 292 $meta = new dcMeta($core);293 299 $dts = array(); 294 300 295 301 foreach ($_POST['entries'] as $id) 296 302 { 297 $rs = $ meta->getMeta('postexpired',1,null,$id);303 $rs = $core->meta->getMetadata(array('meta_type'=>'postexpired','limit'=>1,'post_id'=>$id)); 298 304 if ($rs->isEmpty()) continue; 299 305 300 if (isset($dts[$rs->meta_id])) { 306 if (isset($dts[$rs->meta_id])) 307 { 301 308 $dts[$rs->meta_id]++; 302 } else { 309 } 310 else 311 { 303 312 $dts[$rs->meta_id] = 1; 304 313 } 305 314 } 306 315 307 316 echo '<h2>'.__('Remove selected expired date from entries').'</h2>'; 308 309 if (empty($dts)) { 317 318 if (empty($dts)) 319 { 310 320 echo '<p>'.__('No expired date for selected entries').'</p>'; 311 321 return; 312 322 } 313 323 314 324 $posts_count = count($_POST['entries']); 315 325 316 326 echo 317 327 '<form action="posts_actions.php" method="post">'. 318 328 '<fieldset><legend>'.__('Following expired date have been found in selected entries:').'</legend>'; 319 329 320 330 foreach ($dts as $k => $n) 321 331 { 322 332 $label = '<label class="classic">%s %s</label>'; 323 if ($posts_count == $n) { 333 if ($posts_count == $n) 334 { 324 335 $label = sprintf($label,'%s','<strong>%s</strong>'); 325 336 } 326 337 echo '<p>'.sprintf($label, 327 328 329 330 } 331 338 form::checkbox(array('rmv_post_expired[]'),html::escapeHTML($k)), 339 date('Y-m-d H:i',strtotime($k)) 340 ).'</p>'; 341 } 342 332 343 echo 333 344 '<p><input type="submit" value="'.__('ok').'" /></p>'. -
plugins/postExpired/_define.php
r2275 r2330 17 17 /* Description*/ "Change entries options at a given date", 18 18 /* Author */ "JC Denis", 19 /* Version */ '0. 2.1',19 /* Version */ '0.3', 20 20 /* Permissions */ 'contentadmin' 21 21 ); 22 /* date */ #20100 52822 /* date */ #20100608 23 23 ?> -
plugins/postExpired/_public.php
r2275 r2330 12 12 13 13 if (!defined('DC_RC_PATH')){return;} 14 if (!$core->plugins->moduleExists('metadata')){return;}15 14 16 15 __('Expired on'); 17 16 __('This entry has no expirion date'); 18 17 19 if (in_array($core->url->type,array('default','feed'))) 18 if (in_array($core->url->type,array('default','feed'))){ 20 19 $core->addBehavior('publicBeforeDocument',array('publicBehaviorPostExpired','unpublishExpiredEntries')); 21 20 } … … 30 29 public static function unpublishExpiredEntries($core) 31 30 { 32 $meta = new dcMeta($core);33 34 31 # Get expired dates and post_id 35 32 $posts = $core->con->select( … … 43 40 ); 44 41 # No expired date 45 if ($posts->isEmpty()) { 42 if ($posts->isEmpty()) 43 { 46 44 return; 47 45 } … … 59 57 { 60 58 # Delete meta for expired date 61 $core->auth->sudo(array($ meta,'delPostMeta'),$posts->post_id,'postexpired');59 $core->auth->sudo(array($core->meta,'delPostMeta'),$posts->post_id,'postexpired'); 62 60 # Retrieve action on 'post_status' 63 61 $rs_status = $core->con->select( … … 104 102 105 103 # Delete meta record for status 106 $core->auth->sudo(array($ meta,'delPostMeta'),$posts->post_id,'postexpiredstatus');104 $core->auth->sudo(array($core->meta,'delPostMeta'),$posts->post_id,'postexpiredstatus'); 107 105 } 108 106 # Action on 'cat_id' … … 114 112 115 113 # Delete meta record for category 116 $core->auth->sudo(array($ meta,'delPostMeta'),$posts->post_id,'postexpiredcat');114 $core->auth->sudo(array($core->meta,'delPostMeta'),$posts->post_id,'postexpiredcat'); 117 115 } 118 116 # Action on 'post_selected' … … 124 122 125 123 # Delete meta record for selected 126 $core->auth->sudo(array($ meta,'delPostMeta'),$posts->post_id,'postexpiredselected');124 $core->auth->sudo(array($core->meta,'delPostMeta'),$posts->post_id,'postexpiredselected'); 127 125 } 128 126 # Update post … … 151 149 public static function postExpiredDate(&$rs,$absolute_urls=false) 152 150 { 153 if (!$rs->postexpired[$rs->post_id]) { 154 $meta = new dcMeta($rs->core); 155 $rs_date = $meta->getMeta('postexpired',1,null,$rs->post_id); 151 if (!$rs->postexpired[$rs->post_id]) 152 { 153 $params = array( 154 'meta_type' => 'postexpired', 155 'post_id' => $rs->post_id, 156 'limit' => 1 157 ); 158 $rs_date = $rs->core->meta->getMetadata($params); 156 159 return $rs_date->isEmpty() ? null : (string) $rs_date->meta_id; 157 160 } -
plugins/postExpired/release.txt
r2275 r2330 1 todo 2 * Add option to add/remove tag 3 4 0.3 20100608 5 * Switched to DC 2.2 (settings,meta) 6 1 7 0.2.1 20100528 2 8 * Fixed DC 2.1.7 settings bugs
Note: See TracChangeset
for help on using the changeset viewer.