Dotclear

Changeset 3245


Ignore:
Timestamp:
11/03/13 23:54:19 (10 years ago)
Author:
JcDenis
Message:

Switch to DC 2.6, limit perms to contentadmin, change meta managment

Location:
plugins/postExpired
Files:
5 added
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • plugins/postExpired/_admin.php

    r3135 r3245  
    1313# -- END LICENSE BLOCK ------------------------------------ 
    1414 
    15 if (!defined('DC_CONTEXT_ADMIN')){return;} 
    16  
    17 if (!$core->auth->check('usage,contentadmin',$core->blog->id)) { return; } 
     15if (!defined('DC_CONTEXT_ADMIN')) { 
     16 
     17     return null; 
     18} 
     19 
     20# Check plugin version 
     21if ($core->getVersion('postExpired') != $core->plugins->moduleInfo('postExpired', 'version')) { 
     22 
     23     return null; 
     24} 
     25 
     26# Check user right 
     27if (!$core->auth->check('contentadmin', $core->blog->id)) { 
     28 
     29     return null; 
     30} 
    1831 
    1932# Admin behaviors 
    20 $core->addBehavior('adminPostHeaders',array('postExpiredAdmin','header')); 
    21 $core->addBehavior('adminPageHeaders',array('postExpiredAdmin','header')); 
    22 $core->addBehavior('adminPostFormSidebar',array('postExpiredAdmin','form')); 
    23 $core->addBehavior('adminPageFormSidebar',array('postExpiredAdmin','form')); 
    24 $core->addBehavior('adminAfterPostCreate',array('postExpiredAdmin','set')); 
    25 $core->addBehavior('adminAfterPageCreate',array('postExpiredAdmin','set')); 
    26 $core->addBehavior('adminAfterPostUpdate',array('postExpiredAdmin','set')); 
    27 $core->addBehavior('adminAfterPageUpdate',array('postExpiredAdmin','set')); 
    28 $core->addBehavior('adminBeforePostDelete',array('postExpiredAdmin','del')); 
    29 $core->addBehavior('adminBeforePageDelete',array('postExpiredAdmin','del')); 
    30 $core->addBehavior('adminPostsActionsCombo',array('postExpiredAdmin','combo')); 
    31 $core->addBehavior('adminPagesActionsCombo',array('postExpiredAdmin','combo')); 
    32 $core->addBehavior('adminPostsActions',array('postExpiredAdmin','action')); 
    33 $core->addBehavior('adminPostsActionsContent',array('postExpiredAdmin','content')); 
    34  
    35 # Admin behaviors class 
    36 class postExpiredAdmin 
     33$core->addBehavior( 
     34     'adminPostsActionsPage', 
     35     array('adminBehaviorPostExpired', 'adminPostsActionsPage') 
     36); 
     37$core->addBehavior( 
     38     'adminPagesActionsPage', 
     39     array('adminBehaviorPostExpired', 'adminPostsActionsPage') 
     40); 
     41$core->addBehavior( 
     42     'adminPostHeaders', 
     43     array('adminBehaviorPostExpired', 'adminPostHeaders') 
     44); 
     45$core->addBehavior( 
     46     'adminPageHeaders', 
     47     array('adminBehaviorPostExpired', 'adminPostHeaders') 
     48); 
     49$core->addBehavior( 
     50     'adminPostFormItems', 
     51     array('adminBehaviorPostExpired', 'adminPostFormItems') 
     52); 
     53$core->addBehavior( 
     54     'adminPageFormItems', 
     55     array('adminBehaviorPostExpired', 'adminPostFormItems') 
     56); 
     57$core->addBehavior( 
     58     'adminBeforePostDelete', 
     59     array('adminBehaviorPostExpired', 'adminBeforePostDelete') 
     60); 
     61$core->addBehavior( 
     62     'adminBeforePageDelete', 
     63     array('adminBehaviorPostExpired', 'adminBeforePostDelete') 
     64); 
     65$core->addBehavior( 
     66     'adminAfterPostUpdate', 
     67     array('adminBehaviorPostExpired', 'adminAfterPostSave') 
     68); 
     69$core->addBehavior( 
     70     'adminAfterPageUpdate', 
     71     array('adminBehaviorPostExpired', 'adminAfterPostSave') 
     72); 
     73$core->addBehavior( 
     74     'adminAfterPostCreate', 
     75     array('adminBehaviorPostExpired', 'adminAfterPostSave') 
     76); 
     77$core->addBehavior( 
     78     'adminAfterPageCreate', 
     79     array('adminBehaviorPostExpired', 'adminAfterPostSave') 
     80); 
     81 
     82/** 
     83 * @ingroup DC_PLUGIN_POSTEXPIRED 
     84 * @brief Scheduled post change - admin methods. 
     85 * @since 2.6 
     86 */ 
     87class adminBehaviorPostExpired 
    3788{ 
    38      public static function categoriesCombo() 
     89     /** 
     90      * Add actions to posts page combo 
     91      *  
     92      * @param  dcCore             $core dcCore instance 
     93      * @param  dcPostsActionsPage $ap   dcPostsActionsPage instance 
     94      */ 
     95     public static function adminPostsActionsPage(dcCore $core, dcPostsActionsPage $pa) 
     96     { 
     97          $pa->addAction( 
     98               array( 
     99                    __('Expired entries') => array( 
     100                         __('Add expired date') => 'post_expired_add' 
     101                    ) 
     102               ), 
     103               array('adminBehaviorPostExpired', 'callbackAdd') 
     104          ); 
     105 
     106          $pa->addAction( 
     107               array( 
     108                    __('Expired entries') => array( 
     109                         __('Remove expired date') => 'post_expired_remove' 
     110                    ) 
     111               ), 
     112               array('adminBehaviorPostExpired', 'callbackRemove') 
     113          ); 
     114     } 
     115 
     116     /** 
     117      * Add javascript for date field and toggle 
     118      *  
     119      * @return string HTML head 
     120      */ 
     121     public static function adminPostHeaders() 
     122     { 
     123          return dcPage::jsLoad('index.php?pf=postExpired/js/postexpired.js'); 
     124     } 
     125 
     126     /** 
     127      * Add form to post sidebar 
     128      *  
     129      * @param  ArrayObject $main_items    Main items 
     130      * @param  ArrayObject $sidebar_items Sidebar items 
     131      * @param  record      $post          Post record or null 
     132      */ 
     133     public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, $post) 
     134     { 
     135          if ($post === null) { 
     136 
     137               return null; 
     138          } 
     139 
     140          $sidebar_items['post_expired'] = array( 
     141               'title' => __('Expired date'), 
     142               'items' => self::fieldsPostExpired( 
     143                    $GLOBALS['core'], 
     144                    $post->post_type, 
     145                    $post->post_id 
     146               ) 
     147          ); 
     148     } 
     149 
     150     /** 
     151      * Delete expired date on post edition 
     152      *  
     153      * @param  integer $post_id Post id 
     154      */ 
     155     public static function adminBeforePostDelete($post_id) 
     156     { 
     157          self::delPostExpired($GLOBALS['core'], $post_id); 
     158     } 
     159 
     160     /** 
     161      * Add expired date on post edition 
     162      *  
     163      * @param  cursor $cur      Current post cursor 
     164      * @param  integer $post_id Post id 
     165      */ 
     166     public static function adminAfterPostSave(cursor $cur, $post_id) 
     167     { 
     168          global $core; 
     169 
     170          self::delPostExpired($core, $post_id); 
     171 
     172          if (!empty($_POST['post_expired_date']) 
     173           && (!empty($_POST['post_expired_status']) 
     174            || !empty($_POST['post_expired_cat']) 
     175            || !empty($_POST['post_expired_selected']) 
     176            || !empty($_POST['post_expired_comment']) 
     177            || !empty($_POST['post_expired_trackback'])) 
     178          ) { 
     179               self::setPostExpired($core, $post_id, $_POST); 
     180          } 
     181     } 
     182 
     183     /** 
     184      * Posts actions callback to add expired date 
     185      *  
     186      * @param  dcCore             $core dcCore instance 
     187      * @param  dcPostsActionsPage $pa   dcPostsActionsPage instance 
     188      * @param  ArrayObject        $post _POST actions 
     189      */ 
     190     public static function callbackAdd(dcCore $core, dcPostsActionsPage $pa, ArrayObject $post) 
     191     { 
     192          # No entry 
     193          $posts_ids = $pa->getIDs(); 
     194          if (empty($posts_ids)) { 
     195               throw new Exception(__('No entry selected')); 
     196          } 
     197 
     198          # Add epired date 
     199          if (!empty($post['post_expired_date']) 
     200           && (!empty($post['post_expired_status']) 
     201            || !empty($post['post_expired_category']) 
     202            || !empty($post['post_expired_selected']) 
     203            || !empty($post['post_expired_comment']) 
     204            || !empty($post['post_expired_trackback'])) 
     205          ) { 
     206               foreach($posts_ids as $post_id) { 
     207                    self::delPostExpired($core, $post_id); 
     208                    self::setPostExpired($core, $post_id, $post); 
     209               } 
     210 
     211               dcPage::addSuccessNotice(__('Expired date added.')); 
     212               $pa->redirect(true); 
     213          } 
     214 
     215          # Display form 
     216          else { 
     217               # Get records to know post type 
     218               $posts = $pa->getRS(); 
     219 
     220               $pa->beginPage( 
     221                    dcPage::breadcrumb(array( 
     222                         html::escapeHTML($core->blog->name) => '', 
     223                         $pa->getCallerTitle() => $pa->getRedirection(true), 
     224                         __('Add expired date to this selection') => ''  
     225                    )), 
     226                    dcPage::jsDatePicker(). 
     227                    self::adminPostHeaders() 
     228               ); 
     229 
     230               echo 
     231               '<form action="'.$pa->getURI().'" method="post">'. 
     232               $pa->getCheckboxes(). 
     233 
     234               implode('', self::fieldsPostExpired($core, $posts->post_type)). 
     235 
     236               $core->formNonce(). 
     237               $pa->getHiddenFields(). 
     238               form::hidden(array('action'), 'post_expired_add'). 
     239               '<input type="submit" value="'.__('Save').'" /></p>'. 
     240               '</form>'; 
     241 
     242               $pa->endPage(); 
     243          } 
     244     } 
     245 
     246     /** 
     247      * Posts actions callback to add expired date 
     248      *  
     249      * @param  dcCore             $core dcCore instance 
     250      * @param  dcPostsActionsPage $pa   dcPostsActionsPage instance 
     251      * @param  ArrayObject        $post _POST actions 
     252      */ 
     253     public static function callbackRemove(dcCore $core, dcPostsActionsPage $pa, ArrayObject $post) 
     254     { 
     255          # No entry 
     256          $posts_ids = $pa->getIDs(); 
     257          if (empty($posts_ids)) { 
     258               throw new Exception(__('No entry selected')); 
     259          } 
     260 
     261          # Delete expired date 
     262          foreach($posts_ids as $post_id) { 
     263               self::delPostExpired($core, $post_id); 
     264          } 
     265 
     266          dcPage::addSuccessNotice(__('Expired date deleted.')); 
     267          $pa->redirect(true); 
     268     } 
     269 
     270     /** 
     271      * Delete expired date 
     272      *  
     273      * @param  dcCore  $core    dcCore instance 
     274      * @param  integer $post_id Post id 
     275      */ 
     276     protected static function delPostExpired(dcCore $core, $post_id) 
     277     { 
     278          $core->meta->delPostMeta($post_id, 'post_expired'); 
     279     } 
     280 
     281     /** 
     282      * Save expired date 
     283      *  
     284      * @param dcCore  $core    dcCore instance 
     285      * @param integer $post_id Post id 
     286      * @param array   $post    _POST fields 
     287      */ 
     288     protected static function setPostExpired(dcCore $core, $post_id, $post) 
     289     { 
     290          $post_expired = array( 
     291               'status'       => '', 
     292               'category'     => '', 
     293               'selected'     => '', 
     294               'comment'      => '', 
     295               'trackback'    => '', 
     296               'date'         => date( 
     297                    'Y-m-d H:i:00', 
     298                    strtotime($post['post_expired_date']) 
     299               ) 
     300          ); 
     301 
     302          if (!empty($post['post_expired_status'])) { 
     303               $post_expired['status'] = 
     304                    (string) $post['post_expired_status']; 
     305          } 
     306          if (!empty($post['post_expired_category'])) { 
     307               $post_expired['category'] = 
     308                    (string) $post['post_expired_category']; 
     309          } 
     310          if (!empty($post['post_expired_selected'])) { 
     311               $post_expired['selected'] = 
     312                    (string) $post['post_expired_selected']; 
     313          } 
     314          if (!empty($post['post_expired_comment'])) { 
     315               $post_expired['comment'] = 
     316                    (string) $post['post_expired_comment']; 
     317          } 
     318          if (!empty($post['post_expired_trackback'])) { 
     319               $post_expired['trackback'] = 
     320                    (string) $post['post_expired_trackback']; 
     321          } 
     322 
     323          $core->meta->setPostMeta( 
     324               $post_id, 
     325               'post_expired', 
     326               encodePostExpired($post_expired) 
     327          ); 
     328     } 
     329 
     330     /** 
     331      * Expired date form fields 
     332      *  
     333      * @param  dcCore $core      dcCore instance 
     334      * @param  string $post_type Posts type 
     335      * @return array             Array of HTML form fields 
     336      */ 
     337     protected static function fieldsPostExpired(dcCore $core, $post_type, $post_id=null) 
     338     { 
     339          $fields = $post_expired = array(); 
     340 
     341          if ($post_id) { 
     342 
     343               $rs = $core->meta->getMeta( 
     344                    'post_expired', 
     345                    1, 
     346                    null, 
     347                    $post_id 
     348               ); 
     349 
     350               if (!$rs->isEmpty()) { 
     351                    $post_expired = decodePostExpired($rs->meta_id); 
     352               } 
     353          } 
     354 
     355          $fields['post_expired_date'] = 
     356               '<p><label for="post_expired_date">'. 
     357               __('Date:').'</label>'. 
     358               form::field( 
     359                    'post_expired_date', 
     360                    16, 
     361                    16, 
     362                    empty($post_expired['date']) ?  
     363                         '' : $post_expired['date'] 
     364               ).'</p>'; 
     365 
     366          $fields['post_expired_status'] = 
     367               '<h5>'.__('On this date, change:').'</h5>'. 
     368               '<p><label for="post_expired_status">'. 
     369               __('Status:').'</label>'. 
     370               form::combo( 
     371                    'post_expired_status', 
     372                    self::statusCombo(), 
     373                    empty($post_expired['status']) ?  
     374                         '' : $post_expired['status'] 
     375               ).'</p>'; 
     376 
     377          if ($post_type == 'post') { 
     378 
     379               $fields['post_expired_category'] = 
     380                    '<p><label for="post_expired_category">'. 
     381                    __('Category:').'</label>'. 
     382                    form::combo( 
     383                         'post_expired_category', 
     384                         self::categoriesCombo( 
     385                              $core->blog->getCategories( 
     386                                   array('post_type' => 'post') 
     387                              ) 
     388                         ), 
     389                         empty($post_expired['category']) ?  
     390                              '' : $post_expired['category'] 
     391                    ).'</p>'; 
     392 
     393               $fields['post_expired_selected'] = 
     394                    '<p><label for="post_expired_selected">'. 
     395                    __('Selection:').'</label>'. 
     396                    form::combo( 
     397                         'post_expired_selected', 
     398                         self::selectedCombo(), 
     399                         empty($post_expired['selected']) ?  
     400                              '' : $post_expired['selected'] 
     401                    ).'</p>'; 
     402          } 
     403 
     404          $fields['post_expired_comment'] = 
     405               '<p><label for="post_expired_comment">'. 
     406               __('Comments status:').'</label>'. 
     407               form::combo( 
     408                    'post_expired_comment', 
     409                    self::commentCombo(), 
     410                    empty($post_expired['comment']) ?  
     411                         '' : $post_expired['comment'] 
     412               ).'</p>'; 
     413 
     414          $fields['post_expired_trackback'] = 
     415               '<p><label for="post_expired_trackback">'. 
     416               __('Trackbacks status:').'</label>'. 
     417               form::combo( 
     418                    'post_expired_trackback', 
     419                    self::trackbackCombo(), 
     420                    empty($post_expired['trackback']) ?  
     421                         '' : $post_expired['trackback'] 
     422               ).'</p>'; 
     423 
     424          return $fields; 
     425     } 
     426 
     427     /** 
     428      * Custom categories combo 
     429      *  
     430      * @param  record $categories Categories recordset 
     431      * @return array              Categorires combo 
     432      */ 
     433     protected static function categoriesCombo(record $categories) 
    39434     { 
    40435          # Getting categories 
    41436          $categories_combo = array( 
    42                __('Not changed') => '', 
    43                __('Uncategorized') => '.' 
     437               __('Not changed')   => '', 
     438               __('Uncategorized') => '!' 
    44439          ); 
    45440          try { 
    46                $categories = $GLOBALS['core']->blog->getCategories(array('post_type'=>'post')); 
    47                while ($categories->fetch()) 
    48                { 
     441               $categories = $GLOBALS['core']->blog->getCategories( 
     442                    array('post_type' => 'post') 
     443               ); 
     444               while ($categories->fetch()) { 
    49445                    $categories_combo[] = new formSelectOption( 
    50                          str_repeat('&nbsp;&nbsp;',$categories->level-1).'&bull; '.html::escapeHTML($categories->cat_title), 
    51                          '.'.$categories->cat_id 
     446                         str_repeat('&nbsp;&nbsp;', $categories->level-1).'&bull; '.html::escapeHTML($categories->cat_title), 
     447                         '!'.$categories->cat_id 
    52448                    ); 
    53449               } 
    54450          } 
    55           catch (Exception $e) { } 
     451          catch (Exception $e) { 
     452 
     453               return array(); 
     454          } 
     455 
    56456          return $categories_combo; 
    57457     } 
    58       
    59      public static function statusCombo() 
     458 
     459     /** 
     460      * Custom status combo 
     461      *  
     462      * @return array Status combo 
     463      */ 
     464     protected static function statusCombo() 
    60465     { 
    61466          return array( 
    62                __('Not changed') => '', 
    63                __('Pending') => '.-2', 
    64                __('Unpublished') => '.0' 
    65           ); 
    66      } 
    67       
    68      public static function selectedCombo() 
     467               __('Not changed')   => '', 
     468               __('Published')     => '!1', 
     469               __('Pending')       => '!-2', 
     470               __('Unpublished')   => '!0' 
     471          ); 
     472     } 
     473 
     474     /** 
     475      * Custom selection combo 
     476      *  
     477      * @return array Selection combo 
     478      */ 
     479     protected static function selectedCombo() 
    69480     { 
    70481          return array( 
    71                __('Not changed') => '', 
    72                __('Selected') => '.1', 
    73                __('Not selected') => '.0' 
    74           ); 
    75      } 
    76       
    77      public static function commentCombo() 
     482               __('Not changed')   => '', 
     483               __('Selected')      => '!1', 
     484               __('Not selected')  => '!0' 
     485          ); 
     486     } 
     487 
     488     /** 
     489      * Custom comment status combo 
     490      *  
     491      * @return array Comment status combo 
     492      */ 
     493     protected static function commentCombo() 
    78494     { 
    79495          return array( 
    80                __('Not changed') => '', 
    81                __('Opened') => '.1', 
    82                __('Closed') => '.0' 
    83           ); 
    84      } 
    85       
    86      public static function trackbackCombo() 
     496               __('Not changed')   => '', 
     497               __('Opened')        => '!1', 
     498               __('Closed')        => '!0' 
     499          ); 
     500     } 
     501 
     502     /** 
     503      * Custom trackback status combo 
     504      *  
     505      * @return array Trackback status combo 
     506      */ 
     507     protected static function trackbackCombo() 
    87508     { 
    88509          return array( 
    89                __('Not changed') => '', 
    90                __('Opened') => '.1', 
    91                __('Closed') => '.0' 
    92           ); 
    93      } 
    94       
    95      public static function header($posts_actions=true) 
    96      { 
    97           return ($posts_actions ? dcPage::jsDatePicker() : ''). 
    98           dcPage::jsLoad('index.php?pf=postExpired/js/postexpired.js'); 
    99      } 
    100       
    101      public static function form($post) 
    102      { 
    103           global $core; 
    104           $expired_date = $expired_status = $expired_cat = $expired_selected =  
    105           $expired_comment = $expired_trackback = ''; 
    106           $can_edit = true; 
    107  
    108           if ($post) 
    109           { 
    110                $can_edit = $post->isEditable(); 
    111                $rs_date = $core->meta->getMetadata(array('meta_type'=>'postexpired','limit'=>1,'post_id'=>$post->post_id)); 
    112                if (!$rs_date->isEmpty()) 
    113                { 
    114                     $expired_date = date('Y-m-d H:i',strtotime($rs_date->meta_id)); 
    115                      
    116                     $rs_status = $core->meta->getMetadata(array('meta_type'=>'postexpiredstatus','limit'=>1,'post_id'=>$post->post_id)); 
    117                     $expired_status = $rs_status->isEmpty() ? '' : (string) $rs_status->meta_id; 
    118                      
    119                     if (!isset($_REQUEST['p']) || $_REQUEST['p'] != 'pages') { 
    120                          $rs_cat = $core->meta->getMetadata(array('meta_type'=>'postexpiredcat','limit'=>1,'post_id'=>$post->post_id)); 
    121                          $expired_cat = $rs_cat->isEmpty() ? '' : (string) $rs_cat->meta_id; 
    122                           
    123                          $rs_selected = $core->meta->getMetadata(array('meta_type'=>'postexpiredselected','limit'=>1,'post_id'=>$post->post_id)); 
    124                          $expired_selected = $rs_selected->isEmpty() ? '' : (string) $rs_selected->meta_id; 
    125                     } 
    126                     $rs_comment = $core->meta->getMetadata(array('meta_type'=>'postexpiredcomment','limit'=>1,'post_id'=>$post->post_id)); 
    127                     $expired_comment = $rs_comment->isEmpty() ? '' : (string) $rs_comment->meta_id; 
    128                      
    129                     $rs_trackback = $core->meta->getMetadata(array('meta_type'=>'postexpiredtrackback','limit'=>1,'post_id'=>$post->post_id)); 
    130                     $expired_trackback = $rs_trackback->isEmpty() ? '' : (string) $rs_trackback->meta_id; 
    131                } 
    132           } 
    133            
    134           echo  
    135           '<h3 id="postexpired-form-title">'.__('Expired date').'</h3>'. 
    136           '<div id="postexpired-form-content">'; 
    137            
    138           if (!$can_edit && $post) 
    139           { 
    140                $status = (string) array_search($expired_status,self::statusCombo()); 
    141                if (!isset($_REQUEST['p']) || $_REQUEST['p'] != 'pages') { 
    142                     $category = (string) array_search($expired_cat,self::categoriesCombo()); 
    143                     $selected = (string) array_search($expired_selected,self::selectedCombo()); 
    144                } 
    145                $comment = (string) array_search($expired_comment,self::commentCombo()); 
    146                $trackback = (string) array_search($expired_trackback,self::commentCombo()); 
    147                 
    148                echo 
    149                '<p>'.__('Date:').' '.$expired_date.'</p>'. 
    150                '<p>'.__('Status:').' '.$status.'</p>'; 
    151                 
    152                if (!isset($_REQUEST['p']) || $_REQUEST['p'] != 'pages') { 
    153                     echo  
    154                     '<p>'.__('Category:').' '.$category.'</p>'. 
    155                     '<p>'.__('Selected:').' '.$selected.'</p>'; 
    156                } 
    157                echo  
    158                '<p>'.__('Comments:').' '.$comment.'</p>'. 
    159                '<p>'.__('Trackbacks:').' '.$trackback.'</p>'; 
    160           } 
    161           else 
    162           { 
    163                echo  
    164                '<p><label>'.__('Date:'). 
    165                form::field('post_expired_date',16,16,$expired_date,'',3). 
    166                '</label></p>'. 
    167                '<p>'.__('On this date, change:').'</p>'. 
    168                '<p><label>'.__('Status:'). 
    169                form::combo('post_expired_status',self::statusCombo(),$expired_status,'maximal',3). 
    170                '</label></p>'; 
    171                 
    172                if (!isset($_REQUEST['p']) || $_REQUEST['p'] != 'pages') { 
    173                     echo  
    174                     '<p><label>'.__('Category:'). 
    175                     form::combo('post_expired_cat',self::categoriesCombo(),$expired_cat,'maximal',3). 
    176                     '</label></p>'. 
    177                     '<p><label>'.__('Selection:'). 
    178                     form::combo('post_expired_selected',self::selectedCombo(),$expired_selected,'maximal',3). 
    179                     '</label></p>'; 
    180                } 
    181                echo  
    182                '<p><label>'.__('Comments status:'). 
    183                form::combo('post_expired_comment',self::commentCombo(),$expired_comment,'maximal',3). 
    184                '</label></p>'. 
    185                '<p><label>'.__('Trackbacks status:'). 
    186                form::combo('post_expired_trackback',self::trackbackCombo(),$expired_trackback,'maximal',3). 
    187                '</label></p>'; 
    188           } 
    189            
    190           # --BEHAVIOR-- adminPostExpiredFormSidebar 
    191           $core->callbehavior('adminPostExpiredFormSidebar',$post); 
    192            
    193           echo '</div>'; 
    194      } 
    195       
    196      public static function set($cur,$post_id) 
    197      { 
    198           global $core; 
    199           if (!isset($_POST['post_expired_date'])) return; 
    200            
    201           $post_id = (integer) $post_id; 
    202            
    203           # --BEHAVIOR-- adminBeforePostExpiredSave 
    204           $core->callBehavior('adminBeforePostExpiredSave',$cur,$post_id); 
    205            
    206           self::del($post_id); 
    207            
    208           if (!empty($_POST['post_expired_date'])  
    209            && (!empty($_POST['post_expired_status'])  
    210             || !empty($_POST['post_expired_cat'])  
    211             || !empty($_POST['post_expired_selected'])  
    212             || !empty($_POST['post_expired_comment'])  
    213             || !empty($_POST['post_expired_trackback']))) 
    214           { 
    215                $post_expired_date = date('Y-m-d H:i:00',strtotime($_POST['post_expired_date'])); 
    216                $core->meta->setPostMeta($post_id,'postexpired',$post_expired_date); 
    217                 
    218                if (!empty($_POST['post_expired_status'])) 
    219                { 
    220                     $core->meta->setPostMeta($post_id,'postexpiredstatus',(string) $_POST['post_expired_status']); 
    221                } 
    222                if (!empty($_POST['post_expired_selected'])) 
    223                { 
    224                     $core->meta->setPostMeta($post_id,'postexpiredcat',(string) $_POST['post_expired_cat']); 
    225                } 
    226                if (!empty($_POST['post_expired_selected'])) 
    227                { 
    228                     $core->meta->setPostMeta($post_id,'postexpiredselected',(string) $_POST['post_expired_selected']); 
    229                } 
    230                if (!empty($_POST['post_expired_comment'])) 
    231                { 
    232                     $core->meta->setPostMeta($post_id,'postexpiredcomment',(string) $_POST['post_expired_comment']); 
    233                } 
    234                if (!empty($_POST['post_expired_trackback'])) 
    235                { 
    236                     $core->meta->setPostMeta($post_id,'postexpiredtrackback',(string) $_POST['post_expired_trackback']); 
    237                } 
    238           } 
    239            
    240           # --BEHAVIOR-- adminAfterPostExpiredSave 
    241           $core->callBehavior('adminAfterPostExpiredSave',$cur,$post_id); 
    242      } 
    243       
    244      public static function del($post_id) 
    245      { 
    246           global $core; 
    247            
    248           $post_id = (integer) $post_id; 
    249            
    250           # --BEHAVIOR-- adminBeforePostExpiredDelete 
    251           $core->callBehavior('adminBeforePostExpiredDelete',$post_id); 
    252            
    253           $core->meta->delPostMeta($post_id,'postexpired'); 
    254           $core->meta->delPostMeta($post_id,'postexpiredstatus'); 
    255           $core->meta->delPostMeta($post_id,'postexpiredcat'); 
    256           $core->meta->delPostMeta($post_id,'postexpiredselected'); 
    257           $core->meta->delPostMeta($post_id,'postexpiredcomment'); 
    258           $core->meta->delPostMeta($post_id,'postexpiredtrackback'); 
    259      } 
    260       
    261      public static function combo($args) 
    262      { 
    263           global $core; 
    264           if ($core->auth->check('usage,contentadmin',$core->blog->id)) 
    265           { 
    266                $args[0][__('Expired entries')][__('Add expired date')] = 'postexpired_add'; 
    267           } 
    268           if ($core->auth->check('delete,contentadmin',$core->blog->id)) 
    269           { 
    270                $args[0][__('Expired entries')][__('Remove expired date')] = 'postexpired_remove'; 
    271           } 
    272      } 
    273       
    274      public static function action($core,$posts,$action,$redir) 
    275      { 
    276           if ($action == 'action_postexpired_add') 
    277           { 
    278                # --BEHAVIOR-- adminPostExpiredActions 
    279                $core->callBehavior('adminPostExpiredActions',$core,$posts,$action,$redir); 
    280                 
    281                if (!$core->auth->check('usage,contentadmin',$core->blog->id)  
    282                 || empty($_POST['new_post_expired_date'])  
    283                 || (empty($_POST['new_post_expired_status'])  
    284                  && empty($_POST['new_post_expired_cat'])  
    285                  && empty($_POST['new_post_expired_selected'])  
    286                  && empty($_POST['new_post_expired_comment'])  
    287                  && empty($_POST['new_post_expired_trackback']))) 
    288                { 
    289                     http::redirect($redir); 
    290                } 
    291                 
    292                try 
    293                { 
    294                     $new_post_expired_date = date('Y-m-d H:i:00',strtotime($_POST['new_post_expired_date'])); 
    295                      
    296                     while ($posts->fetch()) 
    297                     { 
    298                          $rs = $core->meta->getMetadata(array('meta_type'=>'postexpired','limit'=>1,'post_id'=>$posts->post_id)); 
    299                          if ($rs->isEmpty()) 
    300                          { 
    301                               $core->meta->setPostMeta($posts->post_id,'postexpired',$new_post_expired_date); 
    302  
    303                               if (!empty($_POST['new_post_expired_status'])) 
    304                               { 
    305                                    $core->meta->setPostMeta($posts->post_id,'postexpiredstatus',$_POST['new_post_expired_status']); 
    306                               } 
    307                               if (!empty($_POST['new_post_expired_cat'])) 
    308                               { 
    309                                    $core->meta->setPostMeta($posts->post_id,'postexpiredcat',$_POST['new_post_expired_cat']); 
    310                               } 
    311                               if (!empty($_POST['new_post_expired_selected'])) 
    312                               { 
    313                                    $core->meta->setPostMeta($posts->post_id,'postexpiredselected',$_POST['new_post_expired_selected']); 
    314                               } 
    315                               if (!empty($_POST['new_post_expired_comment'])) 
    316                               { 
    317                                    $core->meta->setPostMeta($posts->post_id,'postexpiredcomment',$_POST['new_post_expired_comment']); 
    318                               } 
    319                               if (!empty($_POST['new_post_expired_trackback'])) 
    320                               { 
    321                                    $core->meta->setPostMeta($posts->post_id,'postexpiredtrackback',$_POST['new_post_expired_trackback']); 
    322                               } 
    323                          } 
    324                     } 
    325                     http::redirect($redir); 
    326                } 
    327                catch (Exception $e) 
    328                { 
    329                     $core->error->add($e->getMessage()); 
    330                } 
    331           } 
    332           elseif ($action == 'action_postexpired_remove') 
    333           { 
    334                if (empty($_POST['rmv_post_expired'])  
    335                 || !$core->auth->check('delete,contentadmin',$core->blog->id)) 
    336                { 
    337                     http::redirect($redir); 
    338                } 
    339                 
    340                try 
    341                { 
    342                     $posts_ids = array(); 
    343                     while($posts->fetch()) 
    344                     { 
    345                          $posts_ids[] = $posts->post_id; 
    346                     } 
    347                      
    348                     $rs_params['no_content'] = true; 
    349                     $rs_params['post_id'] = $posts_ids; 
    350                     $rs_params['post_type'] = ''; 
    351                     $rs_params['meta_type'] = 'postexpired'; 
    352                      
    353                     foreach($_POST['rmv_post_expired'] as $meta_id) 
    354                     { 
    355                          $rs_params['meta_id'] = $meta_id; 
    356                          $rs = $core->meta->getPostsByMeta($rs_params); 
    357                           
    358                          while ($rs->fetch()) 
    359                          { 
    360                               if ($rs->isEditable()) 
    361                               { 
    362                                    self::del($rs->post_id); 
    363                               } 
    364                          } 
    365                     } 
    366                      
    367                     http::redirect($redir); 
    368                } 
    369                catch (Exception $e) 
    370                { 
    371                     $core->error->add($e->getMessage()); 
    372                } 
    373           } 
    374      } 
    375       
    376      public static function content($core,$action,$hidden_fields) 
    377      { 
    378           if ($action == 'postexpired_add') 
    379           { 
    380                echo self::header(). 
    381                '<h2><span class="page-title">'.__('Add expired date to entries').'</span></h2>'. 
    382                '<p>'.__('It will be added only if there is no expired date on entry.').'<p>'. 
    383                '<form action="posts_actions.php" method="post">'. 
    384                '<p><label>'.__('Date:'). 
    385                form::field('new_post_expired_date',16,16,'','',2). 
    386                '</label></p>'. 
    387                '<p>'.__('On this date, change:').'</p>'. 
    388                '<p><label>'.__('Status:'). 
    389                form::combo('new_post_expired_status',self::statusCombo(),'','',2). 
    390                '</label></p>'; 
    391                 
    392                if (!isset($_POST['psot_type']) || $_POST['post_type'] != 'page') { 
    393                     echo  
    394                     '<p><label>'.__('Category:'). 
    395                     form::combo('new_post_expired_cat',self::categoriesCombo(),'','',2). 
    396                     '</label></p>'. 
    397                     '<p><label>'.__('Selection:'). 
    398                     form::combo('new_post_expired_selected',self::selectedCombo(),'','',2). 
    399                     '</label></p>'; 
    400                } 
    401                echo  
    402                '<p><label>'.__('Comments status:'). 
    403                form::combo('new_post_expired_comment',self::commentCombo(),'','',2). 
    404                '</label></p>'. 
    405                '<p><label>'.__('Trackbacks status:'). 
    406                form::combo('new_post_expired_trackback',self::trackbackCombo(),'','',2). 
    407                '</label></p>'; 
    408                 
    409                # --BEHAVIOR-- adminPostExpiredActionsContent 
    410                $core->callBehavior('adminPostExpiredActionsContent',$core,$action,$hidden_fields); 
    411                 
    412                echo  
    413                '<p>'. 
    414                $hidden_fields. 
    415                $core->formNonce(). 
    416                form::hidden(array('action'),'action_postexpired_add'). 
    417                '<input type="submit" value="'.__('Save').'" /></p>'. 
    418                '</form>'; 
    419           } 
    420           elseif ($action == 'postexpired_remove') 
    421           { 
    422                $dts = array(); 
    423  
    424                foreach ($_POST['entries'] as $id) 
    425                { 
    426                     $rs = $core->meta->getMetadata(array('meta_type'=>'postexpired','limit'=>1,'post_id'=>$id)); 
    427                     if ($rs->isEmpty()) continue; 
    428                      
    429                     if (isset($dts[$rs->meta_id])) 
    430                     { 
    431                          $dts[$rs->meta_id]++; 
    432                     } 
    433                     else 
    434                     { 
    435                          $dts[$rs->meta_id] = 1; 
    436                     } 
    437                } 
    438                 
    439                echo '<h2><span class="page-title">'.__('Remove selected expired date from entries').'</span></h2>'; 
    440                 
    441                if (empty($dts)) 
    442                { 
    443                     echo '<p>'.__('No expired date for selected entries').'</p>'; 
    444                     return; 
    445                } 
    446                 
    447                $posts_count = count($_POST['entries']); 
    448                 
    449                echo 
    450                '<form action="posts_actions.php" method="post">'. 
    451                '<fieldset><legend>'.__('Following expired date have been found in selected entries:').'</legend>'; 
    452                 
    453                foreach ($dts as $k => $n) 
    454                { 
    455                     $label = '<label class="classic">%s %s</label>'; 
    456                     if ($posts_count == $n) 
    457                     { 
    458                          $label = sprintf($label,'%s','<strong>%s</strong>'); 
    459                     } 
    460                     echo '<p>'.sprintf($label, 
    461                          form::checkbox(array('rmv_post_expired[]'),html::escapeHTML($k)), 
    462                          date('Y-m-d H:i',strtotime($k)) 
    463                     ).'</p>'; 
    464                } 
    465                 
    466                echo 
    467                '<p><input type="submit" value="'.__('ok').'" /></p>'. 
    468                $hidden_fields. 
    469                $core->formNonce(). 
    470                form::hidden(array('action'),'action_postexpired_remove'). 
    471                '</fieldset></form>'; 
    472           } 
     510               __('Not changed')   => '', 
     511               __('Opened')        => '!1', 
     512               __('Closed')        => '!0' 
     513          ); 
    473514     } 
    474515} 
    475 ?> 
  • plugins/postExpired/_define.php

    r3135 r3245  
    1616  
    1717$this->registerModule( 
    18      /* Name */               "Expired entries", 
    19      /* Description*/         "Change entries options at a given date", 
    20      /* Author */             "JC Denis", 
    21      /* Version */            '2013.06.30', 
    22      /* Permissions */        'usage,contentadmin' 
     18     /* Name */ 
     19     "Expired entries", 
     20     /* Description*/ 
     21     "Change entries options at a given date", 
     22     /* Author */ 
     23     "Jean-Christian Denis", 
     24     /* Version */ 
     25     '2013.11.03', 
     26     /* Properies */ 
     27     array( 
     28          'permissions' => 'usage,contentadmin', 
     29          'type' => 'plugin', 
     30          'dc_min' => '2.6', 
     31          'support' => 'http://jcd.lv/q=postExpired', 
     32          'details' => 'http://plugins.dotaddict.org/dc2/details/postExpired' 
     33     ) 
    2334); 
    24 ?> 
  • plugins/postExpired/_public.php

    r3135 r3245  
    1313# -- END LICENSE BLOCK ------------------------------------ 
    1414 
    15 if (!defined('DC_RC_PATH')){return;} 
     15if (!defined('DC_RC_PATH')) { 
     16 
     17     return null; 
     18} 
     19 
     20if ($core->getVersion('postExpired') != $core->plugins->moduleInfo('postExpired', 'version')) { 
     21 
     22     return null; 
     23} 
    1624 
    1725__('Expired on'); 
    1826__('This entry has no expiration date'); 
    1927 
    20 if (in_array($core->url->type,array('default','feed'))){ //launch update only on home page and feed 
    21      $core->addBehavior('publicBeforeDocument',array('publicBehaviorPostExpired','updateExpiredEntries')); 
    22 } 
    23 $core->addBehavior('coreBlogGetPosts',array('publicBehaviorPostExpired','coreBlogGetPosts')); 
    24  
    25 $core->tpl->addBlock('EntryExpiredIf',array('tplPostExpired','EntryExpiredIf')); 
    26 $core->tpl->addValue('EntryExpiredDate',array('tplPostExpired','EntryExpiredDate')); 
    27 $core->tpl->addValue('EntryExpiredTime',array('tplPostExpired','EntryExpiredTime')); 
    28  
     28# launch update only on public home page and feed 
     29if (in_array($core->url->type, array('default', 'feed'))) {  
     30     $core->addBehavior( 
     31          'publicBeforeDocument', 
     32          array('publicBehaviorPostExpired', 'publicBeforeDocument') 
     33     ); 
     34} 
     35$core->addBehavior( 
     36     'coreBlogGetPosts', 
     37     array('publicBehaviorPostExpired', 'coreBlogGetPosts') 
     38); 
     39$core->tpl->addBlock( 
     40     'EntryExpiredIf', 
     41     array('tplPostExpired', 'EntryExpiredIf') 
     42); 
     43$core->tpl->addValue( 
     44     'EntryExpiredDate', 
     45     array('tplPostExpired', 'EntryExpiredDate') 
     46); 
     47$core->tpl->addValue( 
     48     'EntryExpiredTime', 
     49     array('tplPostExpired', 'EntryExpiredTime') 
     50); 
     51 
     52/** 
     53 * @ingroup DC_PLUGIN_POSTEXPIRED 
     54 * @brief Scheduled post change - public methods. 
     55 * @since 2.6 
     56 */ 
    2957class publicBehaviorPostExpired 
    3058{ 
    31      public static function updateExpiredEntries($core) 
     59     /** 
     60      * Check if there are expired dates 
     61      *  
     62      * @param  dcCore $core dcCore instance 
     63      */ 
     64     public static function publicBeforeDocument(dcCore $core) 
    3265     { 
    3366          # Get expired dates and post_id 
     
    3871               'ON META.post_id = P.post_id '. 
    3972               "WHERE blog_id = '".$core->con->escape($core->blog->id)."' ". 
    40                //"AND P.post_type = 'post' ". //quick compatibility with some plugins 
    41                "AND META.meta_type = 'postexpired' " 
     73               // Removed for quick compatibility with some plugins 
     74               //"AND P.post_type = 'post' ".  
     75               "AND META.meta_type = 'post_expired' " 
    4276          ); 
     77 
    4378          # No expired date 
    44           if ($posts->isEmpty()) 
    45           { 
    46                return; 
    47           } 
     79          if ($posts->isEmpty()) { 
     80 
     81               return null; 
     82          } 
     83 
    4884          # Get curent timestamp 
    4985          $now = dt::toUTC(time()); 
     86 
    5087          # Prepared post cursor 
    5188          $post_cur = $core->con->openCursor($core->prefix.'post'); 
     89 
    5290          # Loop through marked posts 
    53           while($posts->fetch()) 
    54           { 
     91          $updated = false; 
     92          while($posts->fetch()) { 
     93 
     94               # Decode meta record 
     95               $post_expired = decodePostExpired($posts->meta_id); 
     96 
    5597               # Check if post is outdated 
    56                $now_tz = $now + dt::getTimeOffset($posts->post_tz,$now); 
    57                $meta_tz = strtotime($posts->meta_id); 
     98               $now_tz = $now + dt::getTimeOffset($posts->post_tz, $now); 
     99               $meta_tz = strtotime($post_expired['date']); 
    58100               if ($now_tz > $meta_tz) 
    59101               { 
    60102                    # Delete meta for expired date 
    61                     $core->auth->sudo(array($core->meta,'delPostMeta'),$posts->post_id,'postexpired'); 
    62                     # Know types of actions 
    63                     $types = array( 
    64                          'postexpiredstatus', 
    65                          'postexpiredcat', 
    66                          'postexpiredselected', 
    67                          'postexpiredcomment', 
    68                          'postexpiredtrackback' 
     103                    $core->auth->sudo( 
     104                         array($core->meta, 'delPostMeta'), 
     105                         $posts->post_id, 
     106                         'post_expired' 
    69107                    ); 
    70                     # Retrieve actions 
    71                     $rs = $core->con->select( 
    72                          'SELECT meta_id, meta_type FROM '.$core->prefix.'meta '. 
     108 
     109                    # Prepare post cursor 
     110                    $post_cur->clean(); 
     111                    $post_cur->post_upddt = date('Y-m-d H:i:s', $now_tz); 
     112 
     113                    # Loop through actions 
     114                    foreach($post_expired as $k => $v) 
     115                    { 
     116                         if (empty($v)) { 
     117                              continue; 
     118                         } 
     119 
     120                         # values are prefixed by "!" 
     121                         $v =  (integer) substr($v, 1); 
     122 
     123                         # Put value in post cursor 
     124                         switch($k) 
     125                         { 
     126                              case 'status': 
     127                              $post_cur->post_status = $v; 
     128                              break; 
     129 
     130                              case 'category': 
     131                              $post_cur->cat_id = $v ? $v : null; 
     132                              break; 
     133 
     134                              case 'selected': 
     135                              $post_cur->post_selected = $v; 
     136                              break; 
     137 
     138                              case 'comment': 
     139                              $post_cur->post_open_comment = $v; 
     140                              break; 
     141 
     142                              case 'trackback': 
     143                              $post_cur->post_open_tb = $v; 
     144                              break; 
     145                         } 
     146                    } 
     147 
     148                    # Update post 
     149                    $post_cur->update( 
    73150                         'WHERE post_id = '.$posts->post_id.' '. 
    74                          'AND meta_type '.$core->con->in($types) 
     151                         "AND blog_id = '".$core->con->escape($core->blog->id)."' " 
    75152                    ); 
    76                      
    77                     # --BEHAVIOR-- publicBeforePostExpiredUpdate 
    78                     $core->callbehavior('publicBeforePostExpiredUpdate',$posts->post_id,$posts->meta_id,$posts->post_tz); 
    79                      
    80                     # If there are actions to do 
    81                     if (!$rs->isEmpty()) 
    82                     { 
    83                          # Prepare post cursor 
    84                          $post_cur->clean(); 
    85                          $post_cur->post_upddt = date('Y-m-d H:i:s',$now_tz); 
    86                          # Loop through actions 
    87                          while($rs->fetch()) 
    88                          { 
    89                               // All new values are in same format 
    90                               $value =  (integer) substr($rs->meta_id,1); 
    91                               # Put value in post cursor 
    92                               switch($rs->meta_type) 
    93                               { 
    94                                    case 'postexpiredstatus': 
    95                                    $post_cur->post_status = $value; 
    96                                    break; 
    97                                     
    98                                    case 'postexpiredcat': 
    99                                    $post_cur->cat_id = $value ? $value : null; 
    100                                    break; 
    101                                     
    102                                    case 'postexpiredselected': 
    103                                    $post_cur->post_selected = $value ? 1 : 0; 
    104                                    break; 
    105                                     
    106                                    case 'postexpiredcomment': 
    107                                    $post_cur->post_open_comment = $value ? 1 : 0; 
    108                                    break; 
    109                                     
    110                                    case 'postexpiredtrackback': 
    111                                    $post_cur->post_open_tb = $value ? 1 : 0; 
    112                                    break; 
    113                               } 
    114                               # Delete meta record of this type 
    115                               $core->auth->sudo(array($core->meta,'delPostMeta'),$posts->post_id,$rs->meta_type); 
    116                          } 
    117                          # Update post 
    118                          $post_cur->update( 
    119                               'WHERE post_id = '.$posts->post_id.' '. 
    120                               "AND blog_id = '".$core->con->escape($core->blog->id)."' " 
    121                          ); 
    122                          # Say blog is updated 
    123                          $core->blog->triggerBlog(); 
    124                     } 
    125                      
    126                     # --BEHAVIOR-- publicAfterPostExpiredUpdate 
    127                     $core->callbehavior('publicAfterPostExpiredUpdate',$posts->post_id,$posts->meta_id,$posts->post_tz); 
     153 
     154                    $updated = true; 
    128155               } 
    129156          } 
    130      } 
    131       
    132      public static function coreBlogGetPosts($rs) 
     157 
     158          # Say blog is updated 
     159          if ($updated) { 
     160               $core->blog->triggerBlog(); 
     161          } 
     162     } 
     163 
     164     /** 
     165      * Extends posts record with expired date 
     166      *  
     167      * @param  record $rs Post recordset 
     168      */ 
     169     public static function coreBlogGetPosts(record $rs) 
    133170     { 
    134171          $rs->extend('rsExtPostExpiredPublic'); 
     
    136173} 
    137174 
     175/** 
     176 * @ingroup DC_PLUGIN_POSTEXPIRED 
     177 * @brief Scheduled post change - extends recordset. 
     178 * @since 2.6 
     179 */ 
    138180class rsExtPostExpiredPublic extends rsExtPost 
    139181{ 
    140      public static function postExpiredDate($rs,$absolute_urls=false) 
    141      { 
    142           if (!$rs->postexpired[$rs->post_id]) //memory 
    143           { 
    144                $params = array( 
    145                     'meta_type' => 'postexpired', 
    146                     'post_id' => $rs->post_id, 
    147                     'limit' => 1 
    148                ); 
    149                $rs_date = $rs->core->meta->getMetadata($params); 
    150                return $rs_date->isEmpty() ? null : (string) $rs_date->meta_id; 
    151           } 
     182     /** 
     183      * Retrieve expired date of a post 
     184      *  
     185      * @param  record  $rs            Post recordset 
     186      * @return string                 Expired date or null 
     187      */ 
     188     public static function postExpiredDate(record $rs) 
     189     { 
     190          if (!$rs->postexpired[$rs->post_id]) { //memory 
     191               $rs_date = $rs->core->meta->getMetadata(array( 
     192                    'meta_type'    => 'post_expired', 
     193                    'post_id'      => $rs->post_id, 
     194                    'limit'        => 1 
     195               )); 
     196 
     197               if ($rs_date->isEmpty()) { 
     198 
     199                    return null; 
     200               } 
     201 
     202               $v = unserialize(base64_decode($rs_date->meta_id)); 
     203               $rs->postexpired[$rs->post_id] = $v['date']; 
     204          } 
     205 
    152206          return $rs->postexpired[$rs->post_id]; 
    153207     } 
    154208} 
    155209 
     210/** 
     211 * @ingroup DC_PLUGIN_POSTEXPIRED 
     212 * @brief Scheduled post change - template methods. 
     213 * @since 2.6 
     214 */ 
    156215class tplPostExpired 
    157216{ 
    158      public static function EntryExpiredIf($attr,$content) 
     217     /** 
     218      * Template condition to check if there is an expired date 
     219      *  
     220      * @param array  $attr    Block attributes 
     221      * @param string $content Block content 
     222      */ 
     223     public static function EntryExpiredIf($attr, $content) 
    159224     { 
    160225          $if = array(); 
    161           $operator = isset($attr['operator']) ? self::getOperator($attr['operator']) : '&&'; 
    162  
    163           if (isset($attr['has_date'])) 
    164           { 
     226          $operator = isset($attr['operator']) ?  
     227               self::getOperator($attr['operator']) : '&&'; 
     228 
     229          if (isset($attr['has_date'])) { 
    165230               $sign = (boolean) $attr['has_date'] ? '!' : '='; 
    166231               $if[] = '(null '.$sign.'== $_ctx->posts->postExpiredDate())'; 
     
    171236 
    172237          return  
    173           "<?php if(".implode(' '.$operator.' ',$if).") : ?>\n". 
     238          "<?php if(".implode(' '.$operator.' ', $if).") : ?>\n". 
    174239          $content. 
    175240          "<?php endif; ?>\n"; 
    176241     } 
    177242 
     243     /** 
     244      * Template for expired date 
     245      *  
     246      * @param array $attr Value attributes 
     247      */ 
    178248     public static function EntryExpiredDate($attr) 
    179249     { 
    180           $format = !empty($attr['format']) ? addslashes($attr['format']) : ''; 
     250          $format = !empty($attr['format']) ?  
     251               addslashes($attr['format']) : ''; 
    181252          $f = $GLOBALS['core']->tpl->getFilters($attr); 
    182253 
     
    188259               $res = sprintf($f,"dt::dt2str('".$format."',\$_ctx->posts->postExpiredDate())"); 
    189260          else  
    190                $res = sprintf($f,"dt::dt2str((version_compare(DC_VERSION,'2.2-alpha','>=') ? \$core->blog->settings->system->date_format : \$core->blog->settings->date_format),\$_ctx->posts->postExpiredDate())"); 
     261               $res = sprintf($f,"dt::dt2str(\$core->blog->settings->system->date_format,\$_ctx->posts->postExpiredDate())"); 
    191262 
    192263          return '<?php if (null !== $_ctx->posts->postExpiredDate()) { echo '.$res.'; } ?>'; 
    193264     } 
    194265 
     266     /** 
     267      * Template for expired time 
     268      *  
     269      * @param array $attr Value attributes 
     270      */ 
    195271     public static function EntryExpiredTime($attr) 
    196272     { 
    197           return '<?php if (null !== $_ctx->posts->postExpiredDate()) { echo '.sprintf($GLOBALS['core']->tpl->getFilters($attr),"dt::dt2str(".(!empty($attr['format']) ? "'".addslashes($attr['format'])."'" : "(version_compare(DC_VERSION,'2.2-alpha','>=') ? \$core->blog->settings->system->time_format : \$core->blog->settings->time_format)").",\$_ctx->posts->postExpiredDate())").'; } ?>'; 
    198      } 
    199  
     273          return '<?php if (null !== $_ctx->posts->postExpiredDate()) { echo '.sprintf($GLOBALS['core']->tpl->getFilters($attr),"dt::dt2str(".(!empty($attr['format']) ? "'".addslashes($attr['format'])."'" : "\$core->blog->settings->system->time_format").",\$_ctx->posts->postExpiredDate())").'; } ?>'; 
     274     } 
     275 
     276     /** 
     277      * Parse tempalte attributes oprerator 
     278      *  
     279      * @param string $op Operator 
     280      */ 
    200281     protected static function getOperator($op) 
    201282     { 
     
    212293     } 
    213294} 
    214 ?> 
  • plugins/postExpired/js/postexpired.js

    r3135 r3245  
    1919          post_pe_dtPick.draw(); 
    2020     } 
    21      var act_pe_field=document.getElementById('new_post_expired_date'); 
    22      if(act_pe_field!=undefined){ 
    23           var act_pe_dtPick=new datePicker(act_pe_field); 
    24           act_pe_dtPick.img_top='1.5em'; 
    25           act_pe_dtPick.draw(); 
    26      } 
    27      $('#postexpired-form-title').toggleWithLegend($('#postexpired-form-content'),{cookie:'dcx_postexpired_admin_form_sidebar'}); 
     21     $('#post_expired h4').toggleWithLegend( 
     22          $('#post_expired').children().not('h4'), 
     23          {cookie:'dcx_postexpired_admin_form_sidebar',legend_click:true} 
     24     ); 
    2825}); 
  • plugins/postExpired/locales/fr/main.lang.php

    r3135 r3245  
    11<?php 
    22// Language: Français  
    3 // Module: postExpired - 2013.06.30 
    4 // Date: 2013-07-01 00:33:05  
     3// Module: postExpired - 2013.11.03 
     4// Date: 2013-11-03 22:12:31  
    55// Translated with dcTranslater - 2013.05.11  
    66 
    7 #_admin.php:42 
    8 #_admin.php:62 
    9 #_admin.php:71 
    10 #_admin.php:80 
    11 #_admin.php:89 
     7#_admin.php:100 
     8#_admin.php:110 
     9$GLOBALS['__l10n']['Expired entries'] = 'Billets périmés'; 
     10 
     11#_admin.php:101 
     12$GLOBALS['__l10n']['Add expired date'] = 'Ajouter une date de péremption'; 
     13 
     14#_admin.php:111 
     15$GLOBALS['__l10n']['Remove expired date'] = 'Retirer une date de péremption'; 
     16 
     17#_admin.php:139 
     18$GLOBALS['__l10n']['Expired date'] = 'Date de péremption'; 
     19 
     20#_admin.php:209 
     21$GLOBALS['__l10n']['Expired date added.'] = 'Date de péremption ajoutée.'; 
     22 
     23#_admin.php:222 
     24$GLOBALS['__l10n']['Add expired date to this selection'] = 'Ajouter une date de péremtion à cette sélection'; 
     25 
     26#_admin.php:269 
     27$GLOBALS['__l10n']['Expired date deleted.'] = 'Dtae de péremtion supprimé'; 
     28 
     29#_admin.php:370 
     30$GLOBALS['__l10n']['On this date, change:'] = 'Á cette date, changer :'; 
     31 
     32#_admin.php:398 
     33$GLOBALS['__l10n']['Selection:'] = 'Séléction :'; 
     34 
     35#_admin.php:409 
     36$GLOBALS['__l10n']['Comments status:'] = 'Status des commentaires :'; 
     37 
     38#_admin.php:419 
     39$GLOBALS['__l10n']['Trackbacks status:'] = 'Status des rétroliens :'; 
     40 
     41#_admin.php:440 
     42#_admin.php:470 
     43#_admin.php:485 
     44#_admin.php:499 
     45#_admin.php:513 
    1246$GLOBALS['__l10n']['Not changed'] = 'Inchangé'; 
    1347 
    14 #_admin.php:63 
    15 $GLOBALS['__l10n']['Pending'] = 'En attente'; 
    16  
    17 #_admin.php:64 
    18 $GLOBALS['__l10n']['Unpublished'] = 'Non publié'; 
    19  
    20 #_admin.php:73 
    21 $GLOBALS['__l10n']['Not selected'] = 'Non sélectionné'; 
    22  
    23 #_admin.php:81 
    24 #_admin.php:90 
     48#_admin.php:500 
     49#_admin.php:514 
    2550$GLOBALS['__l10n']['Opened'] = 'Ouvert'; 
    2651 
    27 #_admin.php:82 
    28 #_admin.php:91 
     52#_admin.php:501 
     53#_admin.php:515 
    2954$GLOBALS['__l10n']['Closed'] = 'Fermé'; 
    3055 
    31 #_admin.php:135 
    32 $GLOBALS['__l10n']['Expired date'] = 'Date de péremption'; 
    33  
    34 #_admin.php:158 
    35 $GLOBALS['__l10n']['Comments:'] = 'Commentaires :'; 
    36  
    37 #_admin.php:159 
    38 $GLOBALS['__l10n']['Trackbacks:'] = 'Rétroliens :'; 
    39  
    40 #_admin.php:167 
    41 #_admin.php:387 
    42 $GLOBALS['__l10n']['On this date, change:'] = 'Á cette date, changer :'; 
    43  
    44 #_admin.php:177 
    45 #_admin.php:397 
    46 $GLOBALS['__l10n']['Selection:'] = 'Séléction :'; 
    47  
    48 #_admin.php:182 
    49 #_admin.php:402 
    50 $GLOBALS['__l10n']['Comments status:'] = 'Status des commentaires :'; 
    51  
    52 #_admin.php:185 
    53 #_admin.php:405 
    54 $GLOBALS['__l10n']['Trackbacks status:'] = 'Status des rétroliens :'; 
    55  
    56 #_admin.php:266 
    57 #_admin.php:270 
    58 $GLOBALS['__l10n']['Expired entries'] = 'Billets périmés'; 
    59  
    60 #_admin.php:266 
    61 $GLOBALS['__l10n']['Add expired date'] = 'Ajouter une date de péremption'; 
    62  
    63 #_admin.php:270 
    64 $GLOBALS['__l10n']['Remove expired date'] = 'Retirer une date de péremption'; 
    65  
    66 #_admin.php:381 
    67 $GLOBALS['__l10n']['Add expired date to entries'] = 'Ajouter une date de péremption aux billets'; 
    68  
    69 #_admin.php:382 
    70 $GLOBALS['__l10n']['It will be added only if there is no expired date on entry.'] = 'Ajouté uniquement si il n\'y a pas de date de péremption sur le billet.'; 
    71  
    72 #_admin.php:439 
    73 $GLOBALS['__l10n']['Remove selected expired date from entries'] = 'Retirer les dates de péremption sélectionnées des billets'; 
    74  
    75 #_admin.php:443 
    76 $GLOBALS['__l10n']['No expired date for selected entries'] = 'Pas de date de peremption sur les billets sélectionnés'; 
    77  
    78 #_admin.php:451 
    79 $GLOBALS['__l10n']['Following expired date have been found in selected entries:'] = 'Les dates de péremption suivantes ont été trouvé sur les billets sélectionnés :'; 
    80  
    81 #_public.php:17 
     56#_public.php:25 
    8257$GLOBALS['__l10n']['Expired on'] = 'Expire le'; 
    8358 
    84 #_public.php:18 
     59#_public.php:26 
    8560$GLOBALS['__l10n']['This entry has no expiration date'] = 'Ce billet n\'a pas de date de péremption'; 
    8661 
  • plugins/postExpired/locales/fr/main.po

    r3135 r3245  
    11# Language: Français 
    2 # Module: postExpired - 2013.06.30 
    3 # Date: 2013-07-01 00:33:05 
     2# Module: postExpired - 2013.11.03 
     3# Date: 2013-11-03 22:12:31 
    44# Translated with translater 2013.05.11 
    55 
     
    77msgstr "" 
    88"Content-Type: text/plain; charset=UTF-8\n" 
    9 "Project-Id-Version: postExpired 2013.06.30\n" 
     9"Project-Id-Version: postExpired 2013.11.03\n" 
    1010"POT-Creation-Date: \n" 
    11 "PO-Revision-Date: 2013-07-01T00:33:05+00:00\n" 
     11"PO-Revision-Date: 2013-11-03T22:12:31+00:00\n" 
    1212"Last-Translator: Jean-Christian Denis\n" 
    1313"Language-Team: \n" 
     
    1515"Content-Transfer-Encoding: 8bit\n" 
    1616 
    17 #: _admin.php:42 
    18 #: _admin.php:62 
    19 #: _admin.php:71 
    20 #: _admin.php:80 
    21 #: _admin.php:89 
     17#: _admin.php:100 
     18#: _admin.php:110 
     19msgid "Expired entries" 
     20msgstr "Billets périmés" 
     21 
     22#: _admin.php:101 
     23msgid "Add expired date" 
     24msgstr "Ajouter une date de péremption" 
     25 
     26#: _admin.php:111 
     27msgid "Remove expired date" 
     28msgstr "Retirer une date de péremption" 
     29 
     30#: _admin.php:139 
     31msgid "Expired date" 
     32msgstr "Date de péremption" 
     33 
     34#: _admin.php:209 
     35msgid "Expired date added." 
     36msgstr "Date de péremption ajoutée." 
     37 
     38#: _admin.php:222 
     39msgid "Add expired date to this selection" 
     40msgstr "Ajouter une date de péremtion à cette sélection" 
     41 
     42#: _admin.php:269 
     43msgid "Expired date deleted." 
     44msgstr "Dtae de péremtion supprimé" 
     45 
     46#: _admin.php:370 
     47msgid "On this date, change:" 
     48msgstr "Á cette date, changer :" 
     49 
     50#: _admin.php:398 
     51msgid "Selection:" 
     52msgstr "Séléction :" 
     53 
     54#: _admin.php:409 
     55msgid "Comments status:" 
     56msgstr "Status des commentaires :" 
     57 
     58#: _admin.php:419 
     59msgid "Trackbacks status:" 
     60msgstr "Status des rétroliens :" 
     61 
     62#: _admin.php:440 
     63#: _admin.php:470 
     64#: _admin.php:485 
     65#: _admin.php:499 
     66#: _admin.php:513 
    2267msgid "Not changed" 
    2368msgstr "Inchangé" 
    2469 
    25 #: _admin.php:63 
    26 msgid "Pending" 
    27 msgstr "En attente" 
    28  
    29 #: _admin.php:64 
    30 msgid "Unpublished" 
    31 msgstr "Non publié" 
    32  
    33 #: _admin.php:73 
    34 msgid "Not selected" 
    35 msgstr "Non sélectionné" 
    36  
    37 #: _admin.php:81 
    38 #: _admin.php:90 
     70#: _admin.php:500 
     71#: _admin.php:514 
    3972msgid "Opened" 
    4073msgstr "Ouvert" 
    4174 
    42 #: _admin.php:82 
    43 #: _admin.php:91 
     75#: _admin.php:501 
     76#: _admin.php:515 
    4477msgid "Closed" 
    4578msgstr "Fermé" 
    4679 
    47 #: _admin.php:135 
    48 msgid "Expired date" 
    49 msgstr "Date de péremption" 
    50  
    51 #: _admin.php:158 
    52 msgid "Comments:" 
    53 msgstr "Commentaires :" 
    54  
    55 #: _admin.php:159 
    56 msgid "Trackbacks:" 
    57 msgstr "Rétroliens :" 
    58  
    59 #: _admin.php:167 
    60 #: _admin.php:387 
    61 msgid "On this date, change:" 
    62 msgstr "Á cette date, changer :" 
    63  
    64 #: _admin.php:177 
    65 #: _admin.php:397 
    66 msgid "Selection:" 
    67 msgstr "Séléction :" 
    68  
    69 #: _admin.php:182 
    70 #: _admin.php:402 
    71 msgid "Comments status:" 
    72 msgstr "Status des commentaires :" 
    73  
    74 #: _admin.php:185 
    75 #: _admin.php:405 
    76 msgid "Trackbacks status:" 
    77 msgstr "Status des rétroliens :" 
    78  
    79 #: _admin.php:266 
    80 #: _admin.php:270 
    81 msgid "Expired entries" 
    82 msgstr "Billets périmés" 
    83  
    84 #: _admin.php:266 
    85 msgid "Add expired date" 
    86 msgstr "Ajouter une date de péremption" 
    87  
    88 #: _admin.php:270 
    89 msgid "Remove expired date" 
    90 msgstr "Retirer une date de péremption" 
    91  
    92 #: _admin.php:381 
    93 msgid "Add expired date to entries" 
    94 msgstr "Ajouter une date de péremption aux billets" 
    95  
    96 #: _admin.php:382 
    97 msgid "It will be added only if there is no expired date on entry." 
    98 msgstr "Ajouté uniquement si il n'y a pas de date de péremption sur le billet." 
    99  
    100 #: _admin.php:439 
    101 msgid "Remove selected expired date from entries" 
    102 msgstr "Retirer les dates de péremption sélectionnées des billets" 
    103  
    104 #: _admin.php:443 
    105 msgid "No expired date for selected entries" 
    106 msgstr "Pas de date de peremption sur les billets sélectionnés" 
    107  
    108 #: _admin.php:451 
    109 msgid "Following expired date have been found in selected entries:" 
    110 msgstr "Les dates de péremption suivantes ont été trouvé sur les billets sélectionnés :" 
    111  
    112 #: _public.php:17 
     80#: _public.php:25 
    11381msgid "Expired on" 
    11482msgstr "Expire le" 
    11583 
    116 #: _public.php:18 
     84#: _public.php:26 
    11785msgid "This entry has no expiration date" 
    11886msgstr "Ce billet n'a pas de date de péremption" 
Note: See TracChangeset for help on using the changeset viewer.

Sites map