Dotclear


Ignore:
Timestamp:
01/02/17 17:03:59 (9 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Switch from functions to closures (PHP 5.3+), fix available favorites order

File:
1 edited

Legend:

Unmodified
Added
Removed
  • admin/post.php

    r3466 r3491  
    471471     exit; 
    472472} 
     473 
     474# Controls comments or trakbacks capabilities 
     475$isContributionAllowed = function ($id,$dt,$com=true) 
     476{ 
     477     global $core; 
     478 
     479     if (!$id) { 
     480          return true; 
     481     } 
     482     if ($com) { 
     483          if (($core->blog->settings->system->comments_ttl == 0) || 
     484               (time() - $core->blog->settings->system->comments_ttl*86400 < $dt)) { 
     485               return true; 
     486          } 
     487     } else { 
     488          if (($core->blog->settings->system->trackbacks_ttl == 0) || 
     489               (time() - $core->blog->settings->system->trackbacks_ttl*86400 < $dt)) { 
     490               return true; 
     491          } 
     492     } 
     493     return false; 
     494}; 
     495 
     496# Show comments or trackbacks 
     497$showComments = function($rs,$has_action,$tb=false) 
     498{ 
     499     global $core; 
     500     echo 
     501     '<div class="table-outer">'. 
     502     '<table class="comments-list"><tr>'. 
     503     '<th colspan="2" class="first">'.__('Author').'</th>'. 
     504     '<th>'.__('Date').'</th>'. 
     505     '<th class="nowrap">'.__('IP address').'</th>'. 
     506     '<th>'.__('Status').'</th>'. 
     507     '<th>'.__('Edit').'</th>'. 
     508     '</tr>'; 
     509     $comments = array(); 
     510     if (isset($_REQUEST['comments'])) { 
     511          foreach ($_REQUEST['comments'] as $v) { 
     512               $comments[(integer)$v]=true; 
     513          } 
     514     } 
     515 
     516     while($rs->fetch()) 
     517     { 
     518          $comment_url = $core->adminurl->get("admin.comment",array('id' => $rs->comment_id)); 
     519 
     520          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; 
     521          switch ($rs->comment_status) { 
     522               case 1: 
     523                    $img_status = sprintf($img,__('Published'),'check-on.png'); 
     524                    break; 
     525               case 0: 
     526                    $img_status = sprintf($img,__('Unpublished'),'check-off.png'); 
     527                    break; 
     528               case -1: 
     529                    $img_status = sprintf($img,__('Pending'),'check-wrn.png'); 
     530                    break; 
     531               case -2: 
     532                    $img_status = sprintf($img,__('Junk'),'junk.png'); 
     533                    break; 
     534          } 
     535 
     536          echo 
     537          '<tr class="line'.($rs->comment_status != 1 ? ' offline' : '').'"'. 
     538          ' id="c'.$rs->comment_id.'">'. 
     539 
     540          '<td class="nowrap">'. 
     541          ($has_action ? form::checkbox(array('comments[]'),$rs->comment_id,isset($comments[$rs->comment_id]),'','',0,'title="'.($tb ? __('select this trackback') : __('select this comment')).'"') : '').'</td>'. 
     542          '<td class="maximal">'.html::escapeHTML($rs->comment_author).'</td>'. 
     543          '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$rs->comment_dt).'</td>'. 
     544          '<td class="nowrap"><a href="'.$core->adminurl->get("admin.comments",array('ip' => $rs->comment_ip)).'">'.$rs->comment_ip.'</a></td>'. 
     545          '<td class="nowrap status">'.$img_status.'</td>'. 
     546          '<td class="nowrap status"><a href="'.$comment_url.'">'. 
     547          '<img src="images/edit-mini.png" alt="" title="'.__('Edit this comment').'" /> '.__('Edit').'</a></td>'. 
     548 
     549          '</tr>'; 
     550     } 
     551 
     552     echo '</table></div>'; 
     553}; 
     554 
    473555/* Post form if we can edit post 
    474556-------------------------------------------------------- */ 
     
    533615                         __('Accept comments').'</label></p>'. 
    534616                         ($core->blog->settings->system->allow_comments ? 
    535                               (isContributionAllowed($post_id,strtotime($post_dt),true) ? 
     617                              ($isContributionAllowed($post_id,strtotime($post_dt),true) ? 
    536618                                   '' : 
    537619                                   '<p class="form-note warn">'. 
     
    543625                         __('Accept trackbacks').'</label></p>'. 
    544626                         ($core->blog->settings->system->allow_trackbacks ? 
    545                               (isContributionAllowed($post_id,strtotime($post_dt),false) ? 
     627                              ($isContributionAllowed($post_id,strtotime($post_dt),false) ? 
    546628                                   '' : 
    547629                                   '<p class="form-note warn">'. 
     
    678760     echo '<h3>'.__('Comments').'</h3>'; 
    679761     if (!$comments->isEmpty()) { 
    680           showComments($comments,$has_action); 
     762          $showComments($comments,$has_action); 
    681763     } else { 
    682764          echo '<p>'.__('No comments').'</p>'; 
     
    762844 
    763845     if (!$trackbacks->isEmpty()) { 
    764           showComments($trackbacks, $has_action, true); 
     846          $showComments($trackbacks, $has_action, true); 
    765847     } else { 
    766848          echo '<p>'.__('No trackback').'</p>'; 
     
    830912} 
    831913 
    832 # Controls comments or trakbacks capabilities 
    833 function isContributionAllowed($id,$dt,$com=true) 
    834 { 
    835      global $core; 
    836  
    837      if (!$id) { 
    838           return true; 
    839      } 
    840      if ($com) { 
    841           if (($core->blog->settings->system->comments_ttl == 0) || 
    842                (time() - $core->blog->settings->system->comments_ttl*86400 < $dt)) { 
    843                return true; 
    844           } 
    845      } else { 
    846           if (($core->blog->settings->system->trackbacks_ttl == 0) || 
    847                (time() - $core->blog->settings->system->trackbacks_ttl*86400 < $dt)) { 
    848                return true; 
    849           } 
    850      } 
    851      return false; 
    852 } 
    853  
    854 # Show comments or trackbacks 
    855 function showComments($rs,$has_action,$tb=false) 
    856 { 
    857      global $core; 
    858      echo 
    859      '<div class="table-outer">'. 
    860      '<table class="comments-list"><tr>'. 
    861      '<th colspan="2" class="first">'.__('Author').'</th>'. 
    862      '<th>'.__('Date').'</th>'. 
    863      '<th class="nowrap">'.__('IP address').'</th>'. 
    864      '<th>'.__('Status').'</th>'. 
    865      '<th>'.__('Edit').'</th>'. 
    866      '</tr>'; 
    867      $comments = array(); 
    868      if (isset($_REQUEST['comments'])) { 
    869           foreach ($_REQUEST['comments'] as $v) { 
    870                $comments[(integer)$v]=true; 
    871           } 
    872      } 
    873  
    874      while($rs->fetch()) 
    875      { 
    876           $comment_url = $core->adminurl->get("admin.comment",array('id' => $rs->comment_id)); 
    877  
    878           $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; 
    879           switch ($rs->comment_status) { 
    880                case 1: 
    881                     $img_status = sprintf($img,__('Published'),'check-on.png'); 
    882                     break; 
    883                case 0: 
    884                     $img_status = sprintf($img,__('Unpublished'),'check-off.png'); 
    885                     break; 
    886                case -1: 
    887                     $img_status = sprintf($img,__('Pending'),'check-wrn.png'); 
    888                     break; 
    889                case -2: 
    890                     $img_status = sprintf($img,__('Junk'),'junk.png'); 
    891                     break; 
    892           } 
    893  
    894           echo 
    895           '<tr class="line'.($rs->comment_status != 1 ? ' offline' : '').'"'. 
    896           ' id="c'.$rs->comment_id.'">'. 
    897  
    898           '<td class="nowrap">'. 
    899           ($has_action ? form::checkbox(array('comments[]'),$rs->comment_id,isset($comments[$rs->comment_id]),'','',0,'title="'.($tb ? __('select this trackback') : __('select this comment')).'"') : '').'</td>'. 
    900           '<td class="maximal">'.html::escapeHTML($rs->comment_author).'</td>'. 
    901           '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$rs->comment_dt).'</td>'. 
    902           '<td class="nowrap"><a href="'.$core->adminurl->get("admin.comments",array('ip' => $rs->comment_ip)).'">'.$rs->comment_ip.'</a></td>'. 
    903           '<td class="nowrap status">'.$img_status.'</td>'. 
    904           '<td class="nowrap status"><a href="'.$comment_url.'">'. 
    905           '<img src="images/edit-mini.png" alt="" title="'.__('Edit this comment').'" /> '.__('Edit').'</a></td>'. 
    906  
    907           '</tr>'; 
    908      } 
    909  
    910      echo '</table></div>'; 
    911 } 
    912  
    913914dcPage::helpBlock('core_post','core_trackbacks','core_wiki'); 
    914915dcPage::close(); 
Note: See TracChangeset for help on using the changeset viewer.

Sites map