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/antispam/index.php

    r3421 r3707  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_CONTEXT_ADMIN')) { return; } 
     12if (!defined('DC_CONTEXT_ADMIN')) {return;} 
    1313dcPage::check('admin'); 
    1414 
     
    1616$filters = dcAntispam::$filters->getFilters(); 
    1717 
    18 $page_name = __('Antispam'); 
    19 $filter_gui = false; 
     18$page_name   = __('Antispam'); 
     19$filter_gui  = false; 
    2020$default_tab = null; 
    2121 
    2222try 
    2323{ 
    24      # Show filter configuration GUI 
    25      if (!empty($_GET['f'])) 
    26      { 
    27           if (!isset($filters[$_GET['f']])) { 
    28                throw new Exception(__('Filter does not exist.')); 
    29           } 
    30  
    31           if (!$filters[$_GET['f']]->hasGUI()) { 
    32                throw new Exception(__('Filter has no user interface.')); 
    33           } 
    34  
    35           $filter = $filters[$_GET['f']]; 
    36           $filter_gui = $filter->gui($filter->guiURL()); 
    37      } 
    38  
    39      # Remove all spam 
    40      if (!empty($_POST['delete_all'])) 
    41      { 
    42           $ts = dt::str('%Y-%m-%d %H:%M:%S',$_POST['ts'],$core->blog->settings->system->blog_timezone); 
    43  
    44           dcAntispam::delAllSpam($core,$ts); 
    45  
    46           dcPage::addSuccessNotice(__('Spam comments have been successfully deleted.')); 
    47           http::redirect($p_url); 
    48      } 
    49  
    50      # Update filters 
    51      if (isset($_POST['filters_upd'])) 
    52      { 
    53           $filters_opt = array(); 
    54           $i = 0; 
    55           foreach ($filters as $fid => $f) { 
    56                $filters_opt[$fid] = array(false,$i); 
    57                $i++; 
    58           } 
    59  
    60           # Enable active filters 
    61           if (isset($_POST['filters_active']) && is_array($_POST['filters_active'])) { 
    62                foreach ($_POST['filters_active'] as $v) { 
    63                     $filters_opt[$v][0] = true; 
    64                } 
    65           } 
    66  
    67           # Order filters 
    68           if (!empty($_POST['f_order']) && empty($_POST['filters_order'])) 
    69           { 
    70                $order = $_POST['f_order']; 
    71                asort($order); 
    72                $order = array_keys($order); 
    73           } 
    74           elseif (!empty($_POST['filters_order'])) 
    75           { 
    76                $order = explode(',',trim($_POST['filters_order'],',')); 
    77           } 
    78  
    79           if (isset($order)) { 
    80                foreach ($order as $i => $f) { 
    81                     $filters_opt[$f][1] = $i; 
    82                } 
    83           } 
    84  
    85           # Set auto delete flag 
    86           if (isset($_POST['filters_auto_del']) && is_array($_POST['filters_auto_del'])) { 
    87                foreach ($_POST['filters_auto_del'] as $v) { 
    88                     $filters_opt[$v][2] = true; 
    89                } 
    90           } 
    91  
    92           dcAntispam::$filters->saveFilterOpts($filters_opt); 
    93  
    94           dcPage::addSuccessNotice(__('Filters configuration has been successfully saved.')); 
    95           http::redirect($p_url); 
    96      } 
    97 } 
    98 catch (Exception $e) 
    99 { 
    100      $core->error->add($e->getMessage()); 
     24    # Show filter configuration GUI 
     25    if (!empty($_GET['f'])) { 
     26        if (!isset($filters[$_GET['f']])) { 
     27            throw new Exception(__('Filter does not exist.')); 
     28        } 
     29 
     30        if (!$filters[$_GET['f']]->hasGUI()) { 
     31            throw new Exception(__('Filter has no user interface.')); 
     32        } 
     33 
     34        $filter     = $filters[$_GET['f']]; 
     35        $filter_gui = $filter->gui($filter->guiURL()); 
     36    } 
     37 
     38    # Remove all spam 
     39    if (!empty($_POST['delete_all'])) { 
     40        $ts = dt::str('%Y-%m-%d %H:%M:%S', $_POST['ts'], $core->blog->settings->system->blog_timezone); 
     41 
     42        dcAntispam::delAllSpam($core, $ts); 
     43 
     44        dcPage::addSuccessNotice(__('Spam comments have been successfully deleted.')); 
     45        http::redirect($p_url); 
     46    } 
     47 
     48    # Update filters 
     49    if (isset($_POST['filters_upd'])) { 
     50        $filters_opt = array(); 
     51        $i           = 0; 
     52        foreach ($filters as $fid => $f) { 
     53            $filters_opt[$fid] = array(false, $i); 
     54            $i++; 
     55        } 
     56 
     57        # Enable active filters 
     58        if (isset($_POST['filters_active']) && is_array($_POST['filters_active'])) { 
     59            foreach ($_POST['filters_active'] as $v) { 
     60                $filters_opt[$v][0] = true; 
     61            } 
     62        } 
     63 
     64        # Order filters 
     65        if (!empty($_POST['f_order']) && empty($_POST['filters_order'])) { 
     66            $order = $_POST['f_order']; 
     67            asort($order); 
     68            $order = array_keys($order); 
     69        } elseif (!empty($_POST['filters_order'])) { 
     70            $order = explode(',', trim($_POST['filters_order'], ',')); 
     71        } 
     72 
     73        if (isset($order)) { 
     74            foreach ($order as $i => $f) { 
     75                $filters_opt[$f][1] = $i; 
     76            } 
     77        } 
     78 
     79        # Set auto delete flag 
     80        if (isset($_POST['filters_auto_del']) && is_array($_POST['filters_auto_del'])) { 
     81            foreach ($_POST['filters_auto_del'] as $v) { 
     82                $filters_opt[$v][2] = true; 
     83            } 
     84        } 
     85 
     86        dcAntispam::$filters->saveFilterOpts($filters_opt); 
     87 
     88        dcPage::addSuccessNotice(__('Filters configuration has been successfully saved.')); 
     89        http::redirect($p_url); 
     90    } 
     91} catch (Exception $e) { 
     92    $core->error->add($e->getMessage()); 
    10193} 
    10294?> 
    10395<html> 
    10496<head> 
    105   <title><?php echo ($filter_gui !== false ? sprintf(__('%s configuration'),$filter->name).' - ' : '').$page_name; ?></title> 
     97  <title><?php echo ($filter_gui !== false ? sprintf(__('%s configuration'), $filter->name) . ' - ' : '') . $page_name; ?></title> 
    10698  <script type="text/javascript"> 
    10799  <?php 
    108   echo dcPage::jsVar('dotclear.msg.confirm_spam_delete',__('Are you sure you want to delete all spams?')); 
    109   ?> 
     100echo dcPage::jsVar('dotclear.msg.confirm_spam_delete', __('Are you sure you want to delete all spams?')); 
     101?> 
    110102  </script> 
    111103  <?php 
    112   echo dcPage::jsPageTabs($default_tab); 
    113   $core->auth->user_prefs->addWorkspace('accessibility'); 
    114   if (!$core->auth->user_prefs->accessibility->nodragdrop) { 
    115      echo 
    116           dcPage::jsLoad('js/jquery/jquery-ui.custom.js'). 
    117           dcPage::jsLoad('js/jquery/jquery.ui.touch-punch.js'). 
    118           dcPage::jsLoad(dcPage::getPF('antispam/antispam.js')); 
    119   } 
    120   echo dcPage::cssLoad(dcPage::getPF('antispam/style.css')); 
    121   ?> 
     104echo dcPage::jsPageTabs($default_tab); 
     105$core->auth->user_prefs->addWorkspace('accessibility'); 
     106if (!$core->auth->user_prefs->accessibility->nodragdrop) { 
     107    echo 
     108    dcPage::jsLoad('js/jquery/jquery-ui.custom.js') . 
     109    dcPage::jsLoad('js/jquery/jquery.ui.touch-punch.js') . 
     110    dcPage::jsLoad(dcPage::getPF('antispam/antispam.js')); 
     111} 
     112echo dcPage::cssLoad(dcPage::getPF('antispam/style.css')); 
     113?> 
    122114</head> 
    123115<body> 
    124116<?php 
    125117 
    126 if ($filter_gui !== false) 
    127 { 
    128      echo dcPage::breadcrumb( 
    129           array( 
    130                __('Plugins') => '', 
    131                $page_name => $p_url, 
    132                sprintf(__('%s filter configuration'),$filter->name) => '' 
    133           )). 
    134           dcPage::notices(); 
    135  
    136      echo '<p><a href="'.$p_url.'" class="back">'.__('Back to filters list').'</a></p>'; 
    137  
    138      echo $filter_gui; 
    139  
    140      if ($filter->help) { 
    141           dcPage::helpBlock($filter->help); 
    142      } 
    143 } 
    144 else 
    145 { 
    146      echo dcPage::breadcrumb( 
    147           array( 
    148                __('Plugins') => '', 
    149                $page_name => '' 
    150           )). 
    151           dcPage::notices(); 
    152  
    153      # Information 
    154      $spam_count = dcAntispam::countSpam($core); 
    155      $published_count = dcAntispam::countPublishedComments($core); 
    156      $moderationTTL = $core->blog->settings->antispam->antispam_moderation_ttl; 
    157  
    158      echo 
    159      '<form action="'.$p_url.'" method="post" class="fieldset">'. 
    160      '<h3>'.__('Information').'</h3>'; 
    161  
    162      echo 
    163      '<ul class="spaminfo">'. 
    164      '<li class="spamcount"><a href="'.$core->adminurl->get('admin.comments',array('status' => '-2')).'">'.__('Junk comments:').'</a> '. 
    165      '<strong>'.$spam_count.'</strong></li>'. 
    166      '<li class="hamcount"><a href="'.$core->adminurl->get('admin.comments',array('status' => '1')).'">'.__('Published comments:').'</a> '. 
    167      $published_count.'</li>'. 
    168      '</ul>'; 
    169  
    170      if ($spam_count > 0) 
    171      { 
    172           echo 
    173           '<p>'.$core->formNonce(). 
    174           form::hidden('ts',time()). 
    175           '<input name="delete_all" class="delete" type="submit" value="'.__('Delete all spams').'" /></p>'; 
    176      } 
    177      if ($moderationTTL != null && $moderationTTL >=0) { 
    178           echo '<p>'.sprintf(__('All spam comments older than %s day(s) will be automatically deleted.'), $moderationTTL).' '. 
    179           sprintf(__('You can modify this duration in the %s'),'<a href="'.$core->adminurl->get('admin.blog.pref'). 
    180                '#antispam_moderation_ttl"> '.__('Blog settings').'</a>'). 
    181                '.</p>'; 
    182      } 
    183      echo '</form>'; 
    184  
    185  
    186      # Filters 
    187      echo 
    188      '<form action="'.$p_url.'" method="post" id="filters-list-form">'; 
    189  
    190      if (!empty($_GET['upd'])) { 
    191           dcPage::success(__('Filters configuration has been successfully saved.')); 
    192      } 
    193  
    194      echo 
    195      '<div class="table-outer">'. 
    196      '<table class="dragable">'. 
    197      '<caption class="as_h3">'.__('Available spam filters').'</caption>'. 
    198      '<thead><tr>'. 
    199      '<th>'.__('Order').'</th>'. 
    200      '<th>'.__('Active').'</th>'. 
    201      '<th>'.__('Auto Del.').'</th>'. 
    202      '<th class="nowrap">'.__('Filter name').'</th>'. 
    203      '<th colspan="2">'.__('Description').'</th>'. 
    204      '</tr></thead>'. 
    205      '<tbody id="filters-list" >'; 
    206  
    207      $i = 0; 
    208      foreach ($filters as $fid => $f) 
    209      { 
    210           $gui_link = '&nbsp;'; 
    211           if ($f->hasGUI()) { 
    212                $gui_link = 
    213                '<a href="'.html::escapeHTML($f->guiURL()).'">'. 
    214                '<img src="images/edit-mini.png" alt="'.__('Filter configuration').'" '. 
    215                'title="'.__('Filter configuration').'" /></a>'; 
    216           } 
    217  
    218           echo 
    219           '<tr class="line'.($f->active ? '' : ' offline').'" id="f_'.$fid.'">'. 
    220           '<td class="handle">'.form::field(array('f_order['.$fid.']'),2,5,(string) $i, 'position', '', false, 'title="'.__('position').'"').'</td>'. 
    221           '<td class="nowrap">'.form::checkbox(array('filters_active[]'),$fid,$f->active, '', '', false, 'title="'.__('Active').'"').'</td>'. 
    222           '<td class="nowrap">'.form::checkbox(array('filters_auto_del[]'),$fid,$f->auto_delete, '', '', false, 'title="'.__('Auto Del.').'"').'</td>'. 
    223           '<td class="nowrap" scope="row">'.$f->name.'</td>'. 
    224           '<td class="maximal">'.$f->description.'</td>'. 
    225           '<td class="status">'.$gui_link.'</td>'. 
    226           '</tr>'; 
    227           $i++; 
    228      } 
    229      echo 
    230      '</tbody></table></div>'. 
    231      '<p>'.form::hidden('filters_order',''). 
    232      $core->formNonce(). 
    233      '<input type="submit" name="filters_upd" value="'.__('Save').'" /></p>'. 
    234      '</form>'; 
    235  
    236  
    237      # Syndication 
    238      if (DC_ADMIN_URL) 
    239      { 
    240           $ham_feed = $core->blog->url.$core->url->getURLFor( 
    241                'hamfeed', 
    242                $code = dcAntispam::getUserCode($core) 
    243           ); 
    244           $spam_feed = $core->blog->url.$core->url->getURLFor( 
    245                'spamfeed', 
    246                $code = dcAntispam::getUserCode($core) 
    247           ); 
    248  
    249           echo 
    250           '<h3>'.__('Syndication').'</h3>'. 
    251           '<ul class="spaminfo">'. 
    252           '<li class="feed"><a href="'.$spam_feed.'">'.__('Junk comments RSS feed').'</a></li>'. 
    253           '<li class="feed"><a href="'.$ham_feed.'">'.__('Published comments RSS feed').'</a></li>'. 
    254           '</ul>'; 
    255      } 
    256  
    257      dcPage::helpBlock('antispam','antispam-filters'); 
     118if ($filter_gui !== false) { 
     119    echo dcPage::breadcrumb( 
     120        array( 
     121            __('Plugins')                                         => '', 
     122            $page_name                                            => $p_url, 
     123            sprintf(__('%s filter configuration'), $filter->name) => '' 
     124        )) . 
     125    dcPage::notices(); 
     126 
     127    echo '<p><a href="' . $p_url . '" class="back">' . __('Back to filters list') . '</a></p>'; 
     128 
     129    echo $filter_gui; 
     130 
     131    if ($filter->help) { 
     132        dcPage::helpBlock($filter->help); 
     133    } 
     134} else { 
     135    echo dcPage::breadcrumb( 
     136        array( 
     137            __('Plugins') => '', 
     138            $page_name    => '' 
     139        )) . 
     140    dcPage::notices(); 
     141 
     142    # Information 
     143    $spam_count      = dcAntispam::countSpam($core); 
     144    $published_count = dcAntispam::countPublishedComments($core); 
     145    $moderationTTL   = $core->blog->settings->antispam->antispam_moderation_ttl; 
     146 
     147    echo 
     148    '<form action="' . $p_url . '" method="post" class="fieldset">' . 
     149    '<h3>' . __('Information') . '</h3>'; 
     150 
     151    echo 
     152    '<ul class="spaminfo">' . 
     153    '<li class="spamcount"><a href="' . $core->adminurl->get('admin.comments', array('status' => '-2')) . '">' . __('Junk comments:') . '</a> ' . 
     154    '<strong>' . $spam_count . '</strong></li>' . 
     155    '<li class="hamcount"><a href="' . $core->adminurl->get('admin.comments', array('status' => '1')) . '">' . __('Published comments:') . '</a> ' . 
     156        $published_count . '</li>' . 
     157        '</ul>'; 
     158 
     159    if ($spam_count > 0) { 
     160        echo 
     161        '<p>' . $core->formNonce() . 
     162        form::hidden('ts', time()) . 
     163        '<input name="delete_all" class="delete" type="submit" value="' . __('Delete all spams') . '" /></p>'; 
     164    } 
     165    if ($moderationTTL != null && $moderationTTL >= 0) { 
     166        echo '<p>' . sprintf(__('All spam comments older than %s day(s) will be automatically deleted.'), $moderationTTL) . ' ' . 
     167        sprintf(__('You can modify this duration in the %s'), '<a href="' . $core->adminurl->get('admin.blog.pref') . 
     168            '#antispam_moderation_ttl"> ' . __('Blog settings') . '</a>') . 
     169            '.</p>'; 
     170    } 
     171    echo '</form>'; 
     172 
     173    # Filters 
     174    echo 
     175        '<form action="' . $p_url . '" method="post" id="filters-list-form">'; 
     176 
     177    if (!empty($_GET['upd'])) { 
     178        dcPage::success(__('Filters configuration has been successfully saved.')); 
     179    } 
     180 
     181    echo 
     182    '<div class="table-outer">' . 
     183    '<table class="dragable">' . 
     184    '<caption class="as_h3">' . __('Available spam filters') . '</caption>' . 
     185    '<thead><tr>' . 
     186    '<th>' . __('Order') . '</th>' . 
     187    '<th>' . __('Active') . '</th>' . 
     188    '<th>' . __('Auto Del.') . '</th>' . 
     189    '<th class="nowrap">' . __('Filter name') . '</th>' . 
     190    '<th colspan="2">' . __('Description') . '</th>' . 
     191        '</tr></thead>' . 
     192        '<tbody id="filters-list" >'; 
     193 
     194    $i = 0; 
     195    foreach ($filters as $fid => $f) { 
     196        $gui_link = '&nbsp;'; 
     197        if ($f->hasGUI()) { 
     198            $gui_link = 
     199            '<a href="' . html::escapeHTML($f->guiURL()) . '">' . 
     200            '<img src="images/edit-mini.png" alt="' . __('Filter configuration') . '" ' . 
     201            'title="' . __('Filter configuration') . '" /></a>'; 
     202        } 
     203 
     204        echo 
     205        '<tr class="line' . ($f->active ? '' : ' offline') . '" id="f_' . $fid . '">' . 
     206        '<td class="handle">' . form::field(array('f_order[' . $fid . ']'), 2, 5, (string) $i, 'position', '', false, 'title="' . __('position') . '"') . '</td>' . 
     207        '<td class="nowrap">' . form::checkbox(array('filters_active[]'), $fid, 
     208            array( 
     209                'checked'    => $f->active, 
     210                'extra_html' => 'title="' . __('Active') . '"' 
     211            ) 
     212        ) . '</td>' . 
     213        '<td class="nowrap">' . form::checkbox(array('filters_auto_del[]'), $fid, 
     214            array( 
     215                'checked'    => $f->auto_delete, 
     216                'extra_html' => 'title="' . __('Auto Del.') . '"' 
     217            ) 
     218        ) . '</td>' . 
     219        '<td class="nowrap" scope="row">' . $f->name . '</td>' . 
     220        '<td class="maximal">' . $f->description . '</td>' . 
     221            '<td class="status">' . $gui_link . '</td>' . 
     222            '</tr>'; 
     223        $i++; 
     224    } 
     225    echo 
     226    '</tbody></table></div>' . 
     227    '<p>' . form::hidden('filters_order', '') . 
     228    $core->formNonce() . 
     229    '<input type="submit" name="filters_upd" value="' . __('Save') . '" /></p>' . 
     230        '</form>'; 
     231 
     232    # Syndication 
     233    if (DC_ADMIN_URL) { 
     234        $ham_feed = $core->blog->url . $core->url->getURLFor( 
     235            'hamfeed', 
     236            $code = dcAntispam::getUserCode($core) 
     237        ); 
     238        $spam_feed = $core->blog->url . $core->url->getURLFor( 
     239            'spamfeed', 
     240            $code = dcAntispam::getUserCode($core) 
     241        ); 
     242 
     243        echo 
     244        '<h3>' . __('Syndication') . '</h3>' . 
     245        '<ul class="spaminfo">' . 
     246        '<li class="feed"><a href="' . $spam_feed . '">' . __('Junk comments RSS feed') . '</a></li>' . 
     247        '<li class="feed"><a href="' . $ham_feed . '">' . __('Published comments RSS feed') . '</a></li>' . 
     248            '</ul>'; 
     249    } 
     250 
     251    dcPage::helpBlock('antispam', 'antispam-filters'); 
    258252} 
    259253 
Note: See TracChangeset for help on using the changeset viewer.

Sites map