Advertisement
KeyDog

akismet v 2.2.1

Jan 1st, 2012
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 11.91 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <extension engine="1.0">
  3.     <id>akismet</id>
  4.     <title>Akismet</title>
  5.     <version>2.2.1</version>
  6.     <description>Integrates Akismet spam protection into the forum. Based on code by Garciat</description>
  7.     <author>Rich Pedley</author>
  8.     <minversion>1.3</minversion>
  9.     <maxtestedon>1.4.1</maxtestedon>
  10.    
  11.     <install>
  12.         <![CDATA[
  13.         //test with username: viagra-test-123
  14.         //Insert config values
  15.         $new_config = array(
  16.             'o_akismet_member_posts'    => '10',
  17.             'o_akismet_spam_count'      => '0',
  18.             'o_akismet_ham_count'       => '0',
  19.             'o_akismet_ban_time'        => '1',
  20.             'o_akismet_key' => ''
  21.         );
  22.         foreach($new_config as $key => $value){
  23.             if (!isset($forum_config[$key])){
  24.                 $query = array(
  25.                     'INSERT'    => 'conf_name, conf_value',
  26.                     'INTO'      => 'config',
  27.                     'VALUES'    => '\''.$key.'\', \''.$value.'\''
  28.                 );
  29.                 $forum_db->query_build($query) or error(__FILE__, __LINE__);
  30.             }
  31.         }
  32.         $forum_db->add_field('posts', 'is_spam', 'TINYINT(1) UNSIGNED', true, '0');
  33.         ]]>
  34.     </install>
  35.    
  36.     <uninstall>
  37.         <![CDATA[
  38.         $query = array(
  39.             'DELETE'    => 'config',
  40.             'WHERE'     => 'conf_name in (\'o_akismet\', \'o_akismet_key\',\'o_akismet_spam_count\',\'o_akismet_ham_count\',\'o_akismet_ban_time\')',
  41.         );
  42.         $forum_db->query_build($query) or error(__FILE__, __LINE__);
  43.  
  44.         $forum_db->drop_field('posts', 'is_spam');
  45.         ]]>
  46.     </uninstall>
  47.    
  48.     <hooks>
  49.         <hook id="po_end_validation" priority="9">
  50.             <![CDATA[
  51.             if (file_exists($ext_info['path'].'/lang/'.$forum_user['language'].'/'.$ext_info['id'].'.php'))
  52.                 include $ext_info['path'].'/lang/'.$forum_user['language'].'/'.$ext_info['id'].'.php';
  53.             else
  54.                 include $ext_info['path'].'/lang/English/akismet.php';
  55.  
  56.             $post_is_spam = false;
  57.  
  58.             if(!empty($forum_config['o_akismet_key'])) {
  59.                 require_once  $ext_info['path'].'/akismet.php5.class.php';
  60.                
  61.                 if(($forum_user['is_guest'] || $forum_user['num_posts'] < $forum_config['o_akismet_member_posts']) && !$forum_user['is_admmod']){
  62.  
  63.                     //Create Akismet object
  64.                     $akismet = new Akismet($base_url, $forum_config['o_akismet_key']);
  65.                     //Set vars into object
  66.                     $akismet->setCommentAuthor($username);
  67.                     $akismet->setCommentAuthorEmail($email);
  68.                     $akismet->setCommentContent($message);
  69.                     $akismet->setCommentType('punbb');
  70.                     if($akismet->isCommentSpam()){
  71.                         //oh, it's spam! lets ban this dude! >:)
  72.                         $email_sql = ($forum_config['p_force_guest_email'] == '1' || $email != '') ? '\''.$email.'\'' : 'NULL';
  73.                         switch($forum_config['o_akismet_ban_time']){
  74.                             case '4':
  75.                                 $ban_expire = mktime(0, 0, 0, date("m"), date("d")+7, date("Y"));
  76.                                 break;
  77.                             case '3':
  78.                                 $ban_expire = mktime(0, 0, 0, date("m")+1, date("d"), date("Y"));
  79.                                 break;
  80.                             case '2':
  81.                                 $ban_expire = mktime(0, 0, 0, date("m")+3, date("d"), date("Y"));
  82.                                 break;
  83.                             case '1':
  84.                             default:
  85.                                 $ban_expire = 'NULL';
  86.                                 break;
  87.                         }
  88.                         $ban_user = '\''.$forum_db->escape($username).'\'';
  89.                         $ban_ip = '\''.$forum_db->escape(get_remote_address()).'\'';
  90.                         $ban_email = '\''.$forum_db->escape($email_sql).'\'';
  91.                         $ban_message = '\''.$forum_db->escape("Banned by Akismet").'\'';
  92.                         $ban_creator = '\'0\'';
  93.                         $forum_db->query('INSERT INTO '.$forum_db->prefix.'bans (username, ip, email, message, expire, ban_creator) VALUES('.$ban_user.', '.$ban_ip.', '.$ban_email.', '.$ban_message.', '.$ban_expire.', '.$ban_creator.')') or error('Unable to add ban', __FILE__, __LINE__, $forum_db->error());
  94.                         // Regenerate the bans cache
  95.                         require_once FORUM_ROOT.'include/cache.php';
  96.                         generate_bans_cache();
  97.                         $post_is_spam = true;
  98.                     }
  99.                 }
  100.             }
  101.             ]]>
  102.         </hook>
  103.         <hook id="po_pre_add_post, po_pre_add_topic">
  104.             <![CDATA[
  105.             if($post_is_spam)
  106.                 $post_info['is_spam'] = '1';
  107.             ]]>
  108.         </hook>
  109.         <hook id="po_pre_redirect">
  110.             <![CDATA[
  111.             if($post_is_spam)
  112.                 $lang_post['Post redirect'] = $lang_akismet['Post redirect'];
  113.             ]]>
  114.         </hook>
  115.         <hook id="fn_add_post_qr_add_post, fn_add_topic_qr_add_topic_post">
  116.             <![CDATA[
  117.             global $post_is_spam;
  118.             if($post_is_spam){
  119.                 $query['INSERT'] .= ', is_spam';
  120.                 $query['VALUES'] .= ', \'1\'';
  121.             }
  122.             ]]>
  123.         </hook>
  124.         <hook id="hd_alert">
  125.             <![CDATA[
  126.             $query = array(
  127.             'SELECT'    => 'COUNT(s.id)',
  128.             'FROM'      => 'posts AS s',
  129.             'WHERE'     => 's.is_spam = "1"',
  130.             );
  131.             $result_spam = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  132.             if ($forum_db->result($result_spam))
  133.                 $admod_links['spam'] = '<span id="spam"><a href="'.forum_link($forum_url['akismet']).'">Spam</a></span>';
  134.             ]]>
  135.         </hook>
  136.         <hook id="aop_setup_validation">
  137.             <![CDATA[
  138.             if (!isset($form['akismet']) || $form['akismet'] != '1')
  139.                 $form['akismet'] = '0';
  140.             ]]>
  141.         </hook>
  142.         <hook id="ca_fn_generate_admin_menu_new_sublink"><![CDATA[
  143.             if (FORUM_PAGE_SECTION == 'management')
  144.                 $forum_page['admin_submenu']['akismet'] = '<li class="'.((FORUM_PAGE == 'admin-akismet') ? 'active' : 'normal').((empty($forum_page['admin_submenu'])) ? ' first-item' : '').'"><a href="'.forum_link($forum_url['akismet']).'">Akismet</a></li>';
  145.             ]]>
  146.         </hook>
  147.         <hook id="co_modify_url_scheme">
  148.             <![CDATA[
  149.             $forum_url['akismet'] = 'extensions/akismet/akismet.php';
  150.             $forum_url['spam'] = 'extensions/akismet/akismet.php?id=$1&amp;topic=$2';
  151.             ]]>
  152.         </hook>
  153.        
  154.         <hook id="aop_setup_personal_fieldset_end">
  155.             <![CDATA[
  156.             if (file_exists($ext_info['path'].'/lang/'.$forum_user['language'].'/'.$ext_info['id'].'.php'))
  157.                 include $ext_info['path'].'/lang/'.$forum_user['language'].'/'.$ext_info['id'].'.php';
  158.             else
  159.                 include $ext_info['path'].'/lang/English/akismet.php';
  160.  
  161.             $forum_page['group_count'] = $forum_page['item_count'] = 0;
  162.             ?>
  163.             <div class="content-head">
  164.                 <h2 class="hn"><span><?php echo $lang_akismet['Setup'] ?></span></h2>
  165.             </div>
  166.             <fieldset class="frm-group group<?php echo ++$forum_page['group_count'] ?>">
  167.                 <legend class="group-legend"><strong><?php echo $lang_akismet['Setup'] ?></strong></legend>
  168.                 <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
  169.                     <div class="sf-box text">
  170.                         <label for="fld<?php echo ++$forum_page['fld_count'] ?>">
  171.                             <span><?php echo $lang_akismet['Key'] ?></span>
  172.                             <small><?php echo $lang_akismet['Key help'] ?></small>
  173.                         </label><br />
  174.                         <span class="fld-input"><input type="text" id="fld<?php echo $forum_page['fld_count'] ?>" name="form[akismet_key]" size="16" maxlength="255" value="<?php echo forum_htmlencode($forum_config['o_akismet_key']) ?>" /></span>
  175.                     </div>
  176.                 </div>
  177.                 <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
  178.                     <div class="sf-box select">
  179.                         <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_akismet['Ban Time'] ?></span><small><?php echo $lang_akismet['Ban Time Help'] ?></small></label><br />
  180.                         <span class="fld-input"><select id="fld<?php echo $forum_page['fld_count'] ?>" name="form[akismet_ban_time]">
  181.                             <option value="4"<?php if ($forum_config['o_akismet_ban_time'] == '4') echo ' selected="selected"' ?>><?php echo '1 week'; ?></option>
  182.                             <option value="3"<?php if ($forum_config['o_akismet_ban_time'] == '3') echo ' selected="selected"' ?>><?php echo '1 month'; ?></option>
  183.                             <option value="2"<?php if ($forum_config['o_akismet_ban_time'] == '2') echo ' selected="selected"' ?>><?php echo '3 months'; ?></option>
  184.                             <option value="1"<?php if ($forum_config['o_akismet_ban_time'] == '1') echo ' selected="selected"' ?>><?php echo 'Forever'; ?></option>
  185.                         </select></span>
  186.                     </div>
  187.                 </div>
  188.                 <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
  189.                     <div class="sf-box text">
  190.                         <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_akismet['Member Min posts'] ?></span><small><?php echo $lang_akismet['Member Min posts help'] ?></small></label><br />
  191.                         <span class="fld-input"><input type="text" id="fld<?php echo $forum_page['fld_count'] ?>" name="form[akismet_member_posts]" size="3" maxlength="3" value="<?php echo $forum_config['o_akismet_member_posts'] ?>" /></span>
  192.                     </div>
  193.                 </div>
  194.                
  195.             </fieldset>
  196.             <?php
  197.             ]]>
  198.         </hook>
  199.         <hook id="vt_qr_get_posts, mr_post_actions_qr_get_posts">
  200.             <![CDATA[
  201.                 //checking for spam
  202.                 $query['SELECT'] .= ', p.is_spam';
  203.             ]]>
  204.         </hook>
  205.         <hook id="vt_row_pre_post_actions_merge">
  206.         <![CDATA[
  207.             //hides post and quote button
  208.             if (file_exists($ext_info['path'].'/lang/'.$forum_user['language'].'/'.$ext_info['id'].'.php'))
  209.                 include $ext_info['path'].'/lang/'.$forum_user['language'].'/'.$ext_info['id'].'.php';
  210.             else
  211.                 include $ext_info['path'].'/lang/English/akismet.php';
  212.             if ($forum_user['is_admmod'] && $cur_post['is_spam']=='1'){
  213.                 $cur_post['message'] = $lang_akismet['Admmod message']."\n\n".$cur_post['message'];
  214.                 unset($forum_page['post_actions']['quote']);
  215.                 $forum_page['post_actions']['spam'] = '<span class="spam-post'.(!empty($forum_page['post_actions']) ? ' first-item' : '').'"><a href="'.forum_link($forum_url['spam'], array($cur_post['id'],$id)).'">'.$lang_akismet['Not spam'].'<span> '.$lang_topic['Post'].' '.forum_number_format($forum_page['start_from'] + $forum_page['item_count']).'</span></a></span>';
  216.             }elseif($cur_post['is_spam']=='1'){
  217.                 $cur_post['message'] = $lang_akismet['General message'];
  218.                 unset($forum_page['post_actions']['quote']);
  219.             }  
  220.             if ($forum_user['is_admmod'] && $cur_post['is_spam']=='0'){
  221.                 $forum_page['post_actions']['spam'] = '<span class="spam-post'.(!empty($forum_page['post_actions']) ? ' first-item' : '').'"><a href="'.forum_link($forum_url['spam'], array($cur_post['id'],$id)).'">'.$lang_akismet['Mark Spam'].'<span> '.$lang_topic['Post'].' '.forum_number_format($forum_page['start_from'] + $forum_page['item_count']).'</span></a></span>';
  222.             }
  223.             ]]>
  224.         </hook>
  225.         <hook id="mr_post_actions_loop_start">
  226.         <![CDATA[
  227.             //hides post and quote button
  228.             if (file_exists($ext_info['path'].'/lang/'.$forum_user['language'].'/'.$ext_info['id'].'.php'))
  229.                 include $ext_info['path'].'/lang/'.$forum_user['language'].'/'.$ext_info['id'].'.php';
  230.             else
  231.                 include $ext_info['path'].'/lang/English/akismet.php';
  232.             if ($forum_user['is_admmod'] && $cur_post['is_spam']=='1'){
  233.                 $cur_post['message'] = $lang_akismet['Admmod message']."\n\n".$cur_post['message'];
  234.             }
  235.             ]]>
  236.         </hook>
  237.         <hook id="fn_delete_post_qr_delete_post">
  238.             <![CDATA[
  239.             $akismetquery = array(
  240.                 'SELECT'    => 'is_spam',
  241.                 'FROM'      => 'posts',
  242.                 'WHERE'     => 'id='.$post_id,
  243.                 'LIMIT'     => '1'
  244.             );
  245.             $akresult = $forum_db->query_build($akismetquery) or error(__FILE__, __LINE__);
  246.             list($is_spam) = $forum_db->fetch_row($akresult);
  247.             if($is_spam=='1')
  248.                 $forum_db->query('UPDATE '.$forum_db->prefix.'config SET conf_value=conf_value+1 where conf_name=\'o_akismet_spam_count\' limit 1');
  249.             ]]>
  250.         </hook>
  251.         <hook id="fn_delete_topic_qr_delete_topic_posts">
  252.             <![CDATA[
  253.             $akismetquery = array(
  254.                 'SELECT'    => 'COUNT(s.id)',
  255.                 'FROM'      => 'posts AS s',
  256.                 'WHERE'     => 's.is_spam = \'1\' && topic_id='.$topic_id,
  257.             );
  258.             $akresult = $forum_db->query_build($akismetquery) or error(__FILE__, __LINE__);
  259.             list($akismet_spams) = $forum_db->fetch_row($akresult);
  260.             $forum_db->query('UPDATE '.$forum_db->prefix.'config SET conf_value=conf_value+'.$akismet_spams.' where conf_name=\'o_akismet_spam_count\' limit 1');
  261.             ]]>
  262.         </hook>
  263.         <hook id="mr_confirm_delete_posts_qr_delete_posts">
  264.             <![CDATA[
  265.             $akismetquery = array(
  266.                 'SELECT'    => 'COUNT(s.id)',
  267.                 'FROM'      => 'posts AS s',
  268.                 'WHERE'     => 's.is_spam = \'1\' && s.id IN('.implode(',', $posts).')'
  269.             );
  270.             $akresult = $forum_db->query_build($akismetquery) or error(__FILE__, __LINE__);
  271.             list($akismet_spams) = $forum_db->fetch_row($akresult);
  272.             $forum_db->query('UPDATE '.$forum_db->prefix.'config SET conf_value=conf_value+'.$akismet_spams.' where conf_name=\'o_akismet_spam_count\' limit 1');
  273.             ]]>
  274.         </hook>
  275.     </hooks>
  276. </extension>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement