Dotclear


Ignore:
Timestamp:
02/17/18 18:03:29 (7 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Use array form of optionnal parameters for form::checkbox() where is relevant, code formatting (PSR-2)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/pages/class.listpage.php

    r3265 r3707  
    1515class adminPagesList extends adminGenericList 
    1616{ 
    17      public function display($page,$nb_per_page,$enclose_block='') 
    18      { 
    19           if ($this->rs->isEmpty()) 
    20           { 
    21                echo '<p><strong>'.__('No page').'</strong></p>'; 
    22           } 
    23           else 
    24           { 
    25                $pager = new dcPager($page,$this->rs_count,$nb_per_page,10); 
    26                $entries = array(); 
    27                if (isset($_REQUEST['entries'])) { 
    28                     foreach ($_REQUEST['entries'] as $v) { 
    29                          $entries[(integer)$v]=true; 
    30                     } 
    31                } 
    32                $html_block = 
    33                '<div class="table-outer">'. 
    34                '<table class="maximal dragable"><thead><tr>'; 
     17    public function display($page, $nb_per_page, $enclose_block = '') 
     18    { 
     19        if ($this->rs->isEmpty()) { 
     20            echo '<p><strong>' . __('No page') . '</strong></p>'; 
     21        } else { 
     22            $pager   = new dcPager($page, $this->rs_count, $nb_per_page, 10); 
     23            $entries = array(); 
     24            if (isset($_REQUEST['entries'])) { 
     25                foreach ($_REQUEST['entries'] as $v) { 
     26                    $entries[(integer) $v] = true; 
     27                } 
     28            } 
     29            $html_block = 
     30                '<div class="table-outer">' . 
     31                '<table class="maximal dragable"><thead><tr>'; 
    3532 
    36                $cols = array( 
    37                     'title' =>               '<th colspan="3" scope="col" class="first">'.__('Title').'</th>', 
    38                     'date' =>           '<th scope="col">'.__('Date').'</th>', 
    39                     'author' =>              '<th scope="col">'.__('Author').'</th>', 
    40                     'comments' =>       '<th scope="col"><img src="images/comments.png" alt="" title="'.__('Comments'). 
    41                                              '" /><span class="hidden">'.__('Comments').'</span></th>', 
    42                     'trackbacks' =>          '<th scope="col"><img src="images/trackbacks.png" alt="" title="'.__('Trackbacks'). 
    43                                              '" /><span class="hidden">'.__('Trackbacks').'</span></th>', 
    44                     'status' =>              '<th scope="col">'.__('Status').'</th>' 
    45                ); 
     33            $cols = array( 
     34                'title'      => '<th colspan="3" scope="col" class="first">' . __('Title') . '</th>', 
     35                'date'       => '<th scope="col">' . __('Date') . '</th>', 
     36                'author'     => '<th scope="col">' . __('Author') . '</th>', 
     37                'comments'   => '<th scope="col"><img src="images/comments.png" alt="" title="' . __('Comments') . 
     38                '" /><span class="hidden">' . __('Comments') . '</span></th>', 
     39                'trackbacks' => '<th scope="col"><img src="images/trackbacks.png" alt="" title="' . __('Trackbacks') . 
     40                '" /><span class="hidden">' . __('Trackbacks') . '</span></th>', 
     41                'status'     => '<th scope="col">' . __('Status') . '</th>' 
     42            ); 
    4643 
    47                $cols = new ArrayObject($cols); 
    48                $this->core->callBehavior('adminPagesListHeader',$this->core,$this->rs,$cols); 
     44            $cols = new ArrayObject($cols); 
     45            $this->core->callBehavior('adminPagesListHeader', $this->core, $this->rs, $cols); 
    4946 
    50                // Cope with optional columns 
    51                $this->userColumns('pages',$cols); 
     47            // Cope with optional columns 
     48            $this->userColumns('pages', $cols); 
    5249 
    53                $html_block .= '<tr>'.implode(iterator_to_array($cols)). 
    54                     '</tr></thead><tbody id="pageslist">%s</tbody></table></div>'; 
     50            $html_block .= '<tr>' . implode(iterator_to_array($cols)) . 
     51                '</tr></thead><tbody id="pageslist">%s</tbody></table></div>'; 
    5552 
    56                if ($enclose_block) { 
    57                     $html_block = sprintf($enclose_block,$html_block); 
    58                } 
     53            if ($enclose_block) { 
     54                $html_block = sprintf($enclose_block, $html_block); 
     55            } 
    5956 
    60                echo $pager->getLinks(); 
     57            echo $pager->getLinks(); 
    6158 
    62                $blocks = explode('%s',$html_block); 
     59            $blocks = explode('%s', $html_block); 
    6360 
    64                echo $blocks[0]; 
     61            echo $blocks[0]; 
    6562 
    66                $count = 0; 
    67                while ($this->rs->fetch()) 
    68                { 
    69                     echo $this->postLine($count,isset($entries[$this->rs->post_id])); 
    70                     $count ++; 
    71                } 
     63            $count = 0; 
     64            while ($this->rs->fetch()) { 
     65                echo $this->postLine($count, isset($entries[$this->rs->post_id])); 
     66                $count++; 
     67            } 
    7268 
    73                echo $blocks[1]; 
     69            echo $blocks[1]; 
    7470 
    75                echo $pager->getLinks(); 
    76           } 
    77      } 
     71            echo $pager->getLinks(); 
     72        } 
     73    } 
    7874 
    79      private function postLine($count,$checked) 
    80      { 
    81           $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; 
    82           $sts_class = ''; 
    83           switch ($this->rs->post_status) { 
    84                case 1: 
    85                     $img_status = sprintf($img,__('Published'),'check-on.png'); 
    86                     $sts_class = 'sts-online'; 
    87                     break; 
    88                case 0: 
    89                     $img_status = sprintf($img,__('Unpublished'),'check-off.png'); 
    90                     $sts_class = 'sts-offline'; 
    91                     break; 
    92                case -1: 
    93                     $img_status = sprintf($img,__('Scheduled'),'scheduled.png'); 
    94                     $sts_class = 'sts-scheduled'; 
    95                     break; 
    96                case -2: 
    97                     $img_status = sprintf($img,__('Pending'),'check-wrn.png'); 
    98                     $sts_class = 'sts-pending'; 
    99                     break; 
    100           } 
     75    private function postLine($count, $checked) 
     76    { 
     77        $img      = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; 
     78        $sts_class = ''; 
     79        switch ($this->rs->post_status) { 
     80            case 1: 
     81                $img_status = sprintf($img, __('Published'), 'check-on.png'); 
     82                $sts_class = 'sts-online'; 
     83                break; 
     84            case 0: 
     85                $img_status = sprintf($img, __('Unpublished'), 'check-off.png'); 
     86                $sts_class = 'sts-offline'; 
     87                break; 
     88            case -1: 
     89                $img_status = sprintf($img, __('Scheduled'), 'scheduled.png'); 
     90                $sts_class = 'sts-scheduled'; 
     91                break; 
     92            case -2: 
     93                $img_status = sprintf($img, __('Pending'), 'check-wrn.png'); 
     94                $sts_class = 'sts-pending'; 
     95                break; 
     96        } 
    10197 
    102           $protected = ''; 
    103           if ($this->rs->post_password) { 
    104                $protected = sprintf($img,__('Protected'),'locker.png'); 
    105           } 
     98        $protected = ''; 
     99        if ($this->rs->post_password) { 
     100            $protected = sprintf($img, __('Protected'), 'locker.png'); 
     101        } 
    106102 
    107           $selected = ''; 
    108           if ($this->rs->post_selected) { 
    109                $selected = sprintf($img,__('Hidden'),'hidden.png'); 
    110           } 
     103        $selected = ''; 
     104        if ($this->rs->post_selected) { 
     105            $selected = sprintf($img, __('Hidden'), 'hidden.png'); 
     106        } 
    111107 
    112           $attach = ''; 
    113           $nb_media = $this->rs->countMedia(); 
    114           if ($nb_media > 0) { 
    115                $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments'); 
    116                $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png'); 
    117           } 
     108        $attach  = ''; 
     109        $nb_media = $this->rs->countMedia(); 
     110        if ($nb_media > 0) { 
     111            $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments'); 
     112            $attach     = sprintf($img, sprintf($attach_str, $nb_media), 'attach.png'); 
     113        } 
    118114 
    119           $res = '<tr class="line '.($this->rs->post_status != 1 ? 'offline ' : '').$sts_class.'"'. 
    120           ' id="p'.$this->rs->post_id.'">'; 
     115        $res = '<tr class="line ' . ($this->rs->post_status != 1 ? 'offline ' : '') . $sts_class . '"' . 
     116        ' id="p' . $this->rs->post_id . '">'; 
    121117 
    122           $cols = array( 
    123                'position' =>       '<td class="nowrap handle minimal">'. 
    124                                         form::field(array('order['.$this->rs->post_id.']'),2,3,$count+1,'position','',false,'title="'.sprintf(__('position of %s'),html::escapeHTML($this->rs->post_title)).'"').'</td>', 
    125                'check' =>               '<td class="nowrap">'. 
    126                                         form::checkbox(array('entries[]'),$this->rs->post_id,$checked,'','',!$this->rs->isEditable(),'title="'.__('Select this page').'"').'</td>', 
    127                'title' =>               '<td class="maximal" scope="row"><a href="'. 
    128                                         $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'">'. 
    129                                         html::escapeHTML($this->rs->post_title).'</a></td>', 
    130                'date' =>           '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>', 
    131                'author' =>              '<td class="nowrap">'.$this->rs->user_id.'</td>', 
    132                'comments' =>       '<td class="nowrap count">'.$this->rs->nb_comment.'</td>', 
    133                'trackbacks' =>          '<td class="nowrap count">'.$this->rs->nb_trackback.'</td>', 
    134                'status' =>              '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>' 
    135           ); 
     118        $cols = array( 
     119            'position'   => '<td class="nowrap handle minimal">' . 
     120            form::field(array('order[' . $this->rs->post_id . ']'), 2, 3, $count + 1, 'position', '', false, 'title="' . sprintf(__('position of %s'), html::escapeHTML($this->rs->post_title)) . '"') . '</td>', 
     121            'check'      => '<td class="nowrap">' . 
     122            form::checkbox(array('entries[]'), $this->rs->post_id, 
     123                array( 
     124                    'checked'    => $checked, 
     125                    'disabled'   => !$this->rs->isEditable(), 
     126                    'extra_html' => 'title="' . __('Select this page') . '"' 
     127                ) 
     128            ) . '</td>', 
     129            'title'      => '<td class="maximal" scope="row"><a href="' . 
     130            $this->core->getPostAdminURL($this->rs->post_type, $this->rs->post_id) . '">' . 
     131            html::escapeHTML($this->rs->post_title) . '</a></td>', 
     132            'date'       => '<td class="nowrap">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->post_dt) . '</td>', 
     133            'author'     => '<td class="nowrap">' . $this->rs->user_id . '</td>', 
     134            'comments'   => '<td class="nowrap count">' . $this->rs->nb_comment . '</td>', 
     135            'trackbacks' => '<td class="nowrap count">' . $this->rs->nb_trackback . '</td>', 
     136            'status'     => '<td class="nowrap status">' . $img_status . ' ' . $selected . ' ' . $protected . ' ' . $attach . '</td>' 
     137        ); 
    136138 
    137           $cols = new ArrayObject($cols); 
    138           $this->core->callBehavior('adminPagesListValue',$this->core,$this->rs,$cols); 
     139        $cols = new ArrayObject($cols); 
     140        $this->core->callBehavior('adminPagesListValue', $this->core, $this->rs, $cols); 
    139141 
    140           // Cope with optional columns 
    141           $this->userColumns('pages',$cols); 
     142        // Cope with optional columns 
     143        $this->userColumns('pages', $cols); 
    142144 
    143           $res .= implode(iterator_to_array($cols)); 
    144           $res .= '</tr>'; 
     145        $res .= implode(iterator_to_array($cols)); 
     146        $res .= '</tr>'; 
    145147 
    146           return $res; 
    147      } 
     148        return $res; 
     149    } 
    148150} 
Note: See TracChangeset for help on using the changeset viewer.

Sites map