phpDocumentor pond
[ class tree: pond ] [ index: pond ] [ all elements ]

Source for file _antispam_ban.form.php

Documentation is available at _antispam_ban.form.php

  1. <?php
  2. /**
  3.  * This file implements the UI controller for the antispam management.
  4.  *
  5.  * This file is part of the Quam Plures project - {@link http://quamplures.net/}.
  6.  * See also {@link https://launchpad.net/quam-plures}.
  7.  *
  8.  * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
  9.  * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}.
  10.  *
  11.  * @license http://quamplures.net/license.html GNU General Public License (GPL)
  12.  *
  13.  *  {@internal Open Source relicensing agreement:
  14.  *  }}}
  15.  *
  16.  *  {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  17.  *
  18.  * @todo Allow applying / re-checking of the known data, not just after an update!
  19.  *
  20.  * @package pond
  21.  */
  22. if!defined('QP_MAIN_INIT') ) die'Please, do not access this page directly.' );
  23.  
  24. global $Settings;
  25. global $keyword;
  26. global $aspm_source;
  27.  
  28. global $row_stats;    // for hit functions
  29.  
  30. $Form new FormNULL'antispam_ban''post''compact' );
  31. $Form->global_iconT_('Cancel!')'close'regenerate_url'action' ) );
  32. $Form->begin_form'fform',  T_('Confirm ban & delete') );
  33.     $Form->hidden_ctrl();
  34.     $Form->hiddens_by_keyget_memorized() );
  35.     $Form->hidden'confirm''confirm' );
  36.     $Form->hidden'aspm_source'$aspm_source );
  37.  
  38.     // Check for junk:
  39.  
  40.     // Check for potentially affected logged hits:
  41.     $sql 'SELECT hit_ID, UNIX_TIMESTAMP(hit_datetime) as hit_datetime, hit_uri, hit_referer, dom_name,
  42.                                     hit_blog_ID, hit_remote_addr, blog_shortname
  43.                      FROM T_hitlog INNER JOIN T_basedomains ON hit_referer_dom_ID = dom_ID
  44.                                  LEFT JOIN T_blogs ON hit_blog_ID = blog_ID
  45.                     WHERE hit_referer LIKE '.$DB->quote('%'.$keyword.'%').'
  46.                     ORDER BY dom_name ASC
  47.                     LIMIT 500';
  48.     $res_affected_hits $DB->get_results$sqlARRAY_A );
  49.     if$DB->num_rows == )
  50.     // No matching hits.
  51.         printf'<p><strong>'.T_('No log-hits match the keyword [%s].').'</strong></p>'htmlspecialchars($keyword) );
  52.     }
  53.     else
  54.     {
  55.     ?>
  56.         <p>
  57.             <input type="checkbox" name="delhits" id="delhits_cb" value="1" checked="checked" />
  58.             <label for="delhits_cb">
  59.             <strong><?php printf T_('Delete the following %s referer hits:')$DB->num_rows == 500 '500+' $DB->num_rows ?></strong>
  60.             </label>
  61.         </p>
  62.         <table class="grouped" cellspacing="0">
  63.             <thead>
  64.             <tr>
  65.                 <th class="firstcol"><?php echo T_('Date'?></th>
  66.                 <th><?php echo T_('Referer'?></th>
  67.                 <th><?php echo T_('Ref. IP'?></th>
  68.                 <th><?php echo T_('Target Blog'?></th>
  69.                 <th><?php echo T_('Target URL'?></th>
  70.             </tr>
  71.             </thead>
  72.             <tbody>
  73.             <?php
  74.             load_funcs('sessions/model/_hitlog.funcs.php');
  75.             $count 0;
  76.             foreach$res_affected_hits as $row_stats )
  77.             {
  78.                 ?>
  79.                 <tr class="<?php echo ($count%== 1'odd' 'even' ?>">
  80.                     <td class="firstcol"><?php stats_time(?></td>
  81.                     <td><a href="<?php stats_referer(?>"><?php stats_basedomain(?></a></td>
  82.                     <td><?php stats_hit_remote_addr(?></td>
  83.                     <td><?php echo format_to_output$row_stats['blog_shortname']'htmlbody' )?></td>
  84.                     <td><?php disp_url$row_stats['hit_uri']50 )?></td>
  85.                 </tr>
  86.                 <?php
  87.                 $count++;
  88.             ?>
  89.             </tbody>
  90.         </table>
  91.     <?php
  92.     }
  93.  
  94.     // Check for potentially affected comments:
  95.     $sql 'SELECT comment_ID, comment_date, comment_author, comment_author_url,
  96.                                     comment_author_IP, comment_content
  97.                         FROM T_comments
  98.                      WHERE comment_author LIKE '.$DB->quote('%'.$keyword.'%').'
  99.                                  OR comment_author_email LIKE '.$DB->quote('%'.$keyword.'%').'
  100.                                   OR comment_author_url LIKE '.$DB->quote('%'.$keyword.'%').'
  101.                             OR comment_content LIKE '.$DB->quote('%'.$keyword.'%').'
  102.                      ORDER BY comment_date ASC
  103.                      LIMIT 500';
  104.     $res_affected_comments $DB->get_results$sqlARRAY_A'Find matching comments' );
  105.     if$DB->num_rows == )
  106.     // No matching hits.
  107.         printf'<p><strong>'.T_('No comments match the keyword [%s].').'</strong></p>'htmlspecialchars($keyword) );
  108.     }
  109.     else
  110.     {
  111.     ?>
  112.         <p>
  113.             <input type="checkbox" name="delcomments" id="delcomments_cb" value="1" checked="checked" />
  114.             <label for="delcomments_cb">
  115.             <strong><?php printf T_('Delete the following %s comments:')$DB->num_rows == 500 '500+' $DB->num_rows ?></strong>
  116.             </label>
  117.         </p>
  118.         <table class="grouped" cellspacing="0">
  119.             <thead>
  120.             <tr>
  121.                 <th class="firstcol"><?php echo T_('Date'?></th>
  122.                 <th><?php echo T_('Author'?></th>
  123.                 <th><?php echo T_('Auth. URL'?></th>
  124.                 <th><?php echo T_('Auth. IP'?></th>
  125.                 <th><?php echo T_('Content starts with...'?></th>
  126.                 <th><?php echo T_('Action'?></th>
  127.             </tr>
  128.             </thead>
  129.             <tbody>
  130.             <?php
  131.             $count 0;
  132.             foreach$res_affected_comments as $row_stats )
  133.             // TODO: new Comment( $row_stats )
  134.                 ?>
  135.                 <tr class="<?php echo ($count%== 1'odd' 'even' ?>">
  136.                 <td class="firstcol"><?php echo mysql2date(locale_datefmt().' '.locale_timefmt()$row_stats['comment_date')?></td>
  137.                 <td><?php echo $row_stats['comment_author'?></td>
  138.                 <td><?php disp_url$row_stats['comment_author_url']50 )?></td>
  139.                 <td><?php echo $row_stats['comment_author_IP'?></td>
  140.                 <td><?php
  141.                 $comment_content strip_tags$row_stats['comment_content');
  142.                 if evo_strlen($comment_content70 )
  143.                 {
  144.                     // Trail off (truncate and add '...') after 70 chars
  145.                     echo evo_substr($comment_content070"...";
  146.                 }
  147.                 else
  148.                 {
  149.                     echo $comment_content;
  150.                 }
  151.                 ?></td>
  152.                 <td><?php echo action_iconT_('Edit...')'edit''?ctrl=comments&amp;action=edit&amp;comment_ID='.$row_stats['comment_ID'?></td>
  153.                 </tr>
  154.                 <?php
  155.             $count++;
  156.             ?>
  157.             </tbody>
  158.         </table>
  159.     <?php
  160.     }
  161.  
  162.     // Check if the string is already in the blacklist:
  163.     ifantispam_check($keyword) )
  164.     // Already there:
  165.         printf'<p><strong>'.T_('The keyword [%s] is already handled by the blacklist.').'</strong></p>'htmlspecialchars($keyword) );
  166.     }
  167.     else
  168.     // Not in blacklist
  169.         ?>
  170.         <p>
  171.         <input type="checkbox" name="blacklist_locally" id="blacklist_locally_cb" value="1" checked="checked" />
  172.         <label for="blacklist_locally_cb">
  173.             <strong><?php printf T_('Blacklist the keyword [%s] locally.')htmlspecialchars($keyword) ) ?></strong>
  174.         </label>
  175.         </p>
  176.  
  177.         <?php
  178.     }
  179.  
  180.     $Form->buttonsarray(
  181.         array'''actionArray[ban]'T_('Perform selected operations')'DeleteButton' ),
  182.     ) );
  183.  
  184. $Form->end_form();
  185.  
  186. // this is when you click a "ban" symbol next to a comment domain
  187. // figure out what might be shorter and offer it as a "wider net"
  188. $start_char $string $new_keyword '';
  189. $offer_shorter true;
  190.  
  191. ifsubstr$keyword0== '//' )
  192. // remove and remember leading // characters
  193.     $start_char '//';
  194.     $string substr$keyword);
  195. }
  196. elseifsubstr$keyword0== '.' )
  197. // or remove and remember leading . character
  198.     $start_char '.';
  199.     $string substr$keyword);
  200. }
  201. else
  202. // or we're done (this is not from clicking the "ban" symbol)
  203.     $offer_shorter false;
  204. }
  205.  
  206. if$aspm_source == 'local' )
  207. // no shortening if the keyword was manually entered
  208.     $offer_shorter false;
  209. }
  210.  
  211. if$offer_shorter )
  212. // count /s and .s and split into elements
  213.     $string_slash_array explode'/'$string );
  214.     $slash_elements count$string_slash_array );
  215.     $string_dot_array explode'.'$string_slash_array[0);
  216.     $dot_elements count$string_dot_array );
  217.  
  218.     if$slash_elements )
  219.     // we have at least one / so let's shrink from the right...
  220.         $new_keyword '';
  221.         $ii 0;
  222.         while$ii $slash_elements-)
  223.         // rebuild the keyword from the left to the right
  224.             $new_keyword .= $string_slash_array[$ii];
  225.             if$slash_elements )
  226.             // add a trailing / unless we are down to domain.com
  227.                 $new_keyword .= '/';
  228.             }
  229.             $ii++;
  230.         }
  231.     }
  232.  
  233.     elseif$dot_elements )
  234.     // no /s to work on and we have at least one . so let's shrink from the left...
  235.         $new_keyword '';
  236.         $ii $dot_elements-1;
  237.         while$ii )
  238.         // rebuild the keyword from the right to the left
  239.             $new_keyword $string_dot_array[$ii].$new_keyword;
  240.             $new_keyword '.'.$new_keyword;
  241.             $ii--;
  242.         }
  243.         // whatever $start_char was, it got removed with the first subdo
  244.         $start_char '';
  245.     }
  246.  
  247.     else
  248.     // no /s or .s so the form is not displayed
  249.         $offer_shorter false;
  250.     }
  251.  
  252.     $new_keyword $start_char.$new_keyword;
  253.  
  254. }
  255.  
  256. if$offer_shorter )
  257. // offer to check and ban a shortened version of the original keyword
  258.     $Form new FormNULL'antispam_add''post''compact' );
  259.     $Form->begin_form'fform'T_('Cast a wider net?') );
  260.     $Form->hidden_ctrl();
  261.     $Form->hidden'action''ban' );
  262.     $Form->hidden'aspm_source''central' )// central means modified
  263.     $Form->hidden'keyword'$new_keyword );
  264.     $Form->infoT_('Check this instead')$new_keyword'<br />'.T_('Check this shorter version of the URL you clicked to ban') );
  265.     $Form->end_formarrayarray'submit''submit'T_('Check & ban...')'SaveButton' ) ) );
  266. }
  267.  
  268. ?>