Advertisement
KeyDog

url_spam v 0.5.8

Jan 1st, 2012
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 7.63 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!DOCTYPE extension SYSTEM "ext-1.0.dtd">
  3.  
  4. <!--
  5. /*
  6.     Copyright (C) 2010 Tom 'Grez' Bartoň & KeyDog
  7.     Released under GPL license version 3 or any later version <http://www.gnu.org/licenses/gpl.html>
  8.    
  9.     This extension is free software: you can redistribute it and/or modify
  10.     it under the terms of the GNU General Public License as published by
  11.     the Free Software Foundation, either version 3 of the License, or
  12.     (at your option) any later version.
  13.  
  14.     This extension is distributed in the hope that it will be useful,
  15.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.     GNU General Public License for more details.
  18.  
  19.     You should have received a copy of the GNU General Public License
  20.     along with this extension.  If not, see <http://www.gnu.org/licenses/>.
  21.    
  22.     ON DUPLICATE UPDATE? dblayer
  23. */
  24. -->
  25.  
  26. <extension engine="1.0">
  27.     <id>url_spam</id>
  28.     <title>Disallowing spammers urls</title>
  29.     <version>0.5.8</version>
  30.     <description>Disallows users to use urls that are used by spammers and delete users which try to use these urls if they have less then 5 posts.</description>
  31.     <author>Grez &amp; KeyDog</author>
  32.     <minversion>1.3.4</minversion>
  33.     <maxtestedon>1.4.1</maxtestedon>
  34.     <install>
  35.         <![CDATA[
  36. if (!$forum_db->table_exists('url_spam'))
  37. {
  38.     $schema = array(
  39.         'FIELDS'    =>  array(
  40.             'user_id'       =>  array(
  41.                 'datatype'      =>  'int(7)',
  42.                 'allow_null'    =>  false
  43.             ),
  44.             'ip'        =>  array(
  45.                 'datatype'      =>  'VARCHAR(15)',
  46.                 'allow_null'    =>  false,
  47.                 'default'       =>  '\'0.0.0.0\'',
  48.             ),
  49.             'url'       =>  array(
  50.                 'datatype'      =>  'VARCHAR(150)',
  51.                 'allow_null'    =>  true,
  52.                 'default'       =>  '\'\''
  53.             ),
  54.             'time'      =>  array(
  55.                 'datatype'      =>  'DATETIME',
  56.                 'allow_null'    =>  false
  57.             ),
  58.             'type'      =>  array(
  59.                 'datatype'      =>  'VARCHAR(4)',
  60.                 'allow_null'    =>  false
  61.             ),
  62.         ),
  63.         'PRIMARY KEY'   =>  array('url', 'type')
  64.     );
  65.     $forum_db->create_table('url_spam', $schema);
  66. }
  67.         ]]>
  68.     </install>
  69.    
  70.     <uninstall>
  71.         <![CDATA[
  72. $forum_db->drop_table('url_spam');
  73.         ]]>
  74.     </uninstall>
  75.     <hooks>
  76.     <hook id="po_end_validation" priority="6"><![CDATA[
  77. if(!isset($_POST['preview'])) {
  78.  
  79.     function urlcheck($url, &$errors, $text = "") {
  80.         global $ext_info, $forum_user, $forum_db, $forum_url;
  81.    
  82.         $query = 'http://www.keydogbb.info/url_spam.php?url='.urlencode($url);
  83.         $remote_file = get_remote_file($query, 3);
  84.         if($remote_file['content'] == "Y") {
  85.             if (file_exists($ext_info['path'].'/lang/'.$forum_user['language'].'/'.$ext_info['id'].'.php'))
  86.                 include $ext_info['path'].'/lang/'.$forum_user['language'].'/'.$ext_info['id'].'.php';
  87.             else
  88.                 include $ext_info['path'].'/lang/English/'.$ext_info['id'].'.php';
  89.  
  90.             $query = array(
  91.                 'SELECT'    =>  'url',
  92.                 'FROM'      =>  'url_spam',
  93.                 'WHERE'     =>  'url = \''.$url.'\' AND type = \'post\''
  94.             );
  95.             $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  96.             if($forum_db->num_rows($result) == 0) {
  97.                 $query = array(
  98.                    'INSERT'   => 'user_id, ip, url, time, type',
  99.                    'INTO'     => 'url_spam',
  100.                    'VALUES'   => '\''.$forum_user['id'].'\', \''.get_remote_address().'\', \''.$url.'\', NOW(), \'post\''
  101.                 );
  102.                 $forum_db->query_build($query) or error(__FILE__, __LINE__);
  103.             }
  104.            
  105.             if($forum_user['num_posts'] < 5 && $forum_user['group_id'] != 2) {
  106.                 delete_user($forum_user['id'], true);
  107.                 message($lang_url_spam['User deleted']);
  108.             } else {
  109.                 $errors[] = sprintf($lang_url_spam['URL disallowed'], $url, $url);
  110.             }
  111.         } else {
  112.             $url = str_replace('"', '', $url);
  113.         }
  114.  
  115.         if(!empty($text)) {
  116.             return '[url='.$url.']'.$text.'[/url]';
  117.         } else {
  118.             return '[url]'.$url.'[/url]';
  119.         }
  120.     }
  121.  
  122.     $pattern = array();
  123.     $pattern[] = '#\[url\]([^\[]*?)\[/url\]#e';
  124.     $pattern[] = '#\[url=([^\[]+?)\](.*?)\[/url\]#e';
  125.  
  126.     $replace = array();
  127.     $replace[] = 'urlcheck(\'$1\', $errors)';
  128.     $replace[] = 'urlcheck(\'$1\', $errors, \'$2\')';
  129.  
  130.     $message = preg_replace($pattern, $replace, $message);
  131.  
  132. }
  133.     ]]></hook>
  134.     <hook id="pf_change_details_signature_validation"><![CDATA[
  135.     $pattern = array();
  136.     $pattern[] = '#\[url\]([^\[]*?)\[/url\]#e';
  137.     $pattern[] = '#\[url=([^\[]+?)\](.*?)\[/url\]#e';
  138.  
  139.     $replace = array();
  140.     $replace[] = 'urlcheck(\'$1\', $errors)';
  141.     $replace[] = 'urlcheck(\'$1\', $errors, \'$2\')';
  142.  
  143.     if ($forum_config['o_make_links'] == '1')
  144.     {
  145.         if (!defined('FORUM_PARSER_LOADED')) {
  146.             require FORUM_ROOT.'include/parser.php';
  147.         }
  148.         $_POST['signature'] = do_clickable($_POST['signature']);
  149.     }
  150.    
  151.     $_POST['signature'] = preg_replace($pattern, $replace, $_POST['signature']);
  152.  
  153.     function urlcheck($url, &$errors, $text = "") {
  154.         global $ext_info, $forum_user, $forum_db, $forum_url;
  155.  
  156.         $query = 'http://www.keydogbb.info/url_spam.php?url='.urlencode($url);
  157.         $remote_file = get_remote_file($query, 3);
  158.         if($remote_file['content'] == "Y") {
  159.             if (file_exists($ext_info['path'].'/lang/'.$forum_user['language'].'/'.$ext_info['id'].'.php'))
  160.                 include $ext_info['path'].'/lang/'.$forum_user['language'].'/'.$ext_info['id'].'.php';
  161.             else
  162.                 include $ext_info['path'].'/lang/English/'.$ext_info['id'].'.php';
  163.        
  164.             $query = array(
  165.                 'SELECT'    =>  'url',
  166.                 'FROM'      =>  'url_spam',
  167.                 'WHERE'     =>  'url = \''.$url.'\' AND type = \'sig\''
  168.             );
  169.             $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  170.             if($forum_db->num_rows($result) == 0) {
  171.                 $query = array(
  172.                    'INSERT'   => 'user_id, ip, url, time, type',
  173.                    'INTO'     => 'url_spam',
  174.                    'VALUES'   => '\''.$forum_user['id'].'\', \''.get_remote_address().'\', \''.$url.'\', NOW(), \'sig\''
  175.                 );
  176.                 $forum_db->query_build($query) or error(__FILE__, __LINE__);
  177.             }
  178.            
  179.             if($forum_user['num_posts'] < 5 && $forum_user['group_id'] != 2) {
  180.                 delete_user($forum_user['id'], true);
  181.                 message($lang_url_spam['User deleted']);
  182.             } else {
  183.                 $errors[] = sprintf($lang_url_spam['URL disallowed'], $url, $url);
  184.             }
  185.         } else {
  186.             $url = str_replace('"', '', $url);
  187.         }
  188.  
  189.         if(!empty($text)) {
  190.             return '[url='.$url.']'.$text.'[/url]';
  191.         } else {
  192.             return '[url]'.$url.'[/url]';
  193.         }
  194.     }
  195.     ]]></hook>
  196.     <hook id="ain_items_end"><![CDATA[
  197.     ?>
  198.     <div class="ct-set group-item<?php echo ++$forum_page['item_count'] ?>">
  199.         <div class="ct-box">
  200.             <h3 class="ct-legend hn"><span>URL spam checker</span></h3>
  201.                 <ul class="data-list">
  202.      
  203.     <?php
  204.         $query = array(
  205.             'SELECT'    => 'us.user_id, u.username, us.ip, us.url, DATE_FORMAT(us.time, \'%Y-%m-%d\') AS date, us.type',
  206.             'FROM'        => 'url_spam AS us',
  207.             'JOINS'        => array(
  208.                 array(
  209.                     'LEFT JOIN'    => 'users AS u',
  210.                     'ON'        => 'u.id = us.user_id',
  211.                 ),
  212.             ),
  213.             'ORDER BY'    => 'time DESC',
  214.             'LIMIT'     => '50',
  215.         );
  216.         $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  217.         ?>
  218.                             <li><table>
  219.                             <tr><th style="width: 100px;">User</th><th style="width: 70px;">IP</th><th style="width: 300px;">URL</th><th style="width: 70px;">Date</th><th style="width: 50px;">Type</th></tr>
  220.                             <?php
  221.                             while($spam = $forum_db->fetch_assoc($result)) {
  222.                                 echo "<tr>";
  223.                                     echo "<td>".((!empty($spam['username'])) ? "<a href=\"".forum_link($forum_url['user'], $spam['user_id'])."\">".forum_htmlencode($spam['username'])."</a>" : "DELETED")."</td>";
  224.                                     echo "<td>".$spam['ip']."</td>";
  225.                                     echo "<td><small>".$spam['url']."</small></td>";
  226.                                     echo "<td>".$spam['date']."</td>";
  227.                                     echo "<td>".$spam['type']."</td>";
  228.                                 echo "</tr>";
  229.                             }
  230.                             ?>
  231.                             </table>
  232.                             <center><i>Last 25 entries. Ordered by date.</i></center></li>
  233.                         </ul>
  234.                     </div>
  235.                 </div>
  236.     <?php
  237.     ]]></hooks>
  238. </extension>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement