From 7ab520b71e727ac665a7a12959090c7e3906863d Mon Sep 17 00:00:00 2001 From: Kenji ITO Date: Thu, 19 Jan 2017 18:17:37 +0900 Subject: [PATCH] Fixed a bug where error occurred when trying to post a comment (SPAM-X issue) (bug #735) --- plugins/spamx/BannedUsers.Examine.class.php | 4 +- plugins/spamx/BaseCommand.class.php | 22 + plugins/spamx/BlackList.Examine.class.php | 7 +- plugins/spamx/Header.Examine.class.php | 4 +- plugins/spamx/IP.Examine.class.php | 6 +- plugins/spamx/IPofUrl.Examine.class.php | 4 +- plugins/spamx/SLVbase.class.php | 29 +- plugins/spamx/SNLbase.class.php | 29 +- plugins/spamx/functions.inc | 503 ++++++++++---------- 9 files changed, 303 insertions(+), 305 deletions(-) diff --git a/plugins/spamx/BannedUsers.Examine.class.php b/plugins/spamx/BannedUsers.Examine.class.php index a5a8aa75e..19f382334 100644 --- a/plugins/spamx/BannedUsers.Examine.class.php +++ b/plugins/spamx/BannedUsers.Examine.class.php @@ -58,9 +58,9 @@ public function execute($comment) for ($i = 0; $i < $numRows; $i++) { list($val) = DB_fetchArray($result); - $val = str_replace('#', '\\#', $val); + $pattern = $this->prepareRegularExpression($val); - if (preg_match("#$val#i", $comment)) { + if (preg_match($pattern, $comment)) { $ans = 1; // quit on first positive match SPAMX_log($LANG_SX00['foundspam'] . $val . ' (' . $LANG28[42] . ')' . diff --git a/plugins/spamx/BaseCommand.class.php b/plugins/spamx/BaseCommand.class.php index 57234142a..b9dadfd7b 100644 --- a/plugins/spamx/BaseCommand.class.php +++ b/plugins/spamx/BaseCommand.class.php @@ -9,6 +9,8 @@ */ abstract class BaseCommand { + const REGX_DELIMITER = '#'; + protected $result = PLG_SPAM_ACTION_NONE; // Result of execute command protected $actionCode = PLG_SPAM_ACTION_NONE; // Action code @@ -108,4 +110,24 @@ protected function updateStat($name, $value) . "WHERE name='{$name}' AND value='{$value}' "; DB_query($sql, 1); } + + /** + * Prepare regular expression + * + * @param string $str + * @param string $delimiter + * @param bool $caseSensitive + * @return string + */ + protected function prepareRegularExpression($str, $delimiter = self::REGX_DELIMITER, $caseSensitive = false) + { + $str = preg_quote($str, $delimiter); + $str = $delimiter . $str . $delimiter; + + if (!$caseSensitive) { + $str .= 'i'; + } + + return $str; + } } diff --git a/plugins/spamx/BlackList.Examine.class.php b/plugins/spamx/BlackList.Examine.class.php index 86900459e..403db0e2d 100644 --- a/plugins/spamx/BlackList.Examine.class.php +++ b/plugins/spamx/BlackList.Examine.class.php @@ -59,12 +59,11 @@ public function execute($comment) for ($i = 1; $i <= $nrows; $i++) { list($val) = DB_fetchArray($result); - $originalVal = $val; - $val = str_replace('#', '\\#', $val); + $pattern = $this->prepareRegularExpression($val); - if (preg_match("#$val#i", $comment)) { + if (preg_match($pattern, $comment)) { $ans = PLG_SPAM_FOUND; // quit on first positive match - $this->updateStat('Personal', $originalVal); + $this->updateStat('Personal', $val); SPAMX_log($LANG_SX00['foundspam'] . $val . $LANG_SX00['foundspam2'] . $uid . $LANG_SX00['foundspam3'] . $_SERVER['REMOTE_ADDR']); diff --git a/plugins/spamx/Header.Examine.class.php b/plugins/spamx/Header.Examine.class.php index 794690e6c..d6beb30de 100644 --- a/plugins/spamx/Header.Examine.class.php +++ b/plugins/spamx/Header.Examine.class.php @@ -66,11 +66,11 @@ public function execute($comment) $v = explode(':', $entry); $name = trim($v[0]); $value = trim($v[1]); - $value = str_replace('#', '\\#', $value); + $pattern = $this->prepareRegularExpression($value); foreach ($headers as $key => $content) { if (strcasecmp($name, $key) === 0) { - if (preg_match("#{$value}#i", $content)) { + if (preg_match($pattern, $content)) { $ans = PLG_SPAM_FOUND; // quit on first positive match $this->updateStat('HTTPHeader', $entry); SPAMX_log($LANG_SX00['foundspam'] . $entry . diff --git a/plugins/spamx/IP.Examine.class.php b/plugins/spamx/IP.Examine.class.php index af23cdfd1..4a88b488d 100644 --- a/plugins/spamx/IP.Examine.class.php +++ b/plugins/spamx/IP.Examine.class.php @@ -171,7 +171,11 @@ private function _process($ip) } elseif (strpos($val, '-') !== false) { $matches = $this->_matchRange($ip, $val); } else { - $matches = preg_match("#^{$val}$#i", $ip); + if (strpos($val, '^') !== 0) { + $val = '^' . $val; + } + $pattern = $this->prepareRegularExpression($val); + $matches = preg_match($pattern, $ip); } if ($matches) { diff --git a/plugins/spamx/IPofUrl.Examine.class.php b/plugins/spamx/IPofUrl.Examine.class.php index 5253c4a99..bb5b9ffa2 100644 --- a/plugins/spamx/IPofUrl.Examine.class.php +++ b/plugins/spamx/IPofUrl.Examine.class.php @@ -44,9 +44,7 @@ public function execute($comment) /* * regex to find urls $2 = fqd */ - $regx = '(ftp|http|file)://([^/\\s]+)'; - $num = preg_match_all("#{$regx}#", html_entity_decode($comment), $urls); - + $num = preg_match_all('#(https|http|ftps|ftp|file)://([^/\\s]+)#', html_entity_decode($comment), $urls); $result = DB_query("SELECT value FROM {$_TABLES['spamx']} WHERE name='IPofUrl'", 1); $numRows = DB_numRows($result); diff --git a/plugins/spamx/SLVbase.class.php b/plugins/spamx/SLVbase.class.php index b034effcf..ff9bbb701 100644 --- a/plugins/spamx/SLVbase.class.php +++ b/plugins/spamx/SLVbase.class.php @@ -118,11 +118,11 @@ public function checkWhitelist(&$links) for ($i = 0; $i < $nrows; $i++) { $A = DB_fetchArray($result); $val = $A['value']; - $val = str_replace('#', '\\#', $val); + $pattern = '#' . preg_quote($val, '#') . '#i'; foreach ($links as $key => $link) { if (!empty($link)) { - if (preg_match("#$val#i", $link)) { + if (preg_match($pattern, $link)) { $links[$key] = ''; DB_query("UPDATE {$_TABLES['spamx']} SET counter = counter + 1, regdate = '$timestamp' WHERE name='SLVwhitelist' AND value='" . DB_escapeString($A['value']) . "'", 1); } @@ -144,16 +144,10 @@ public function getLinks($comment) $links = array(); - preg_match_all("/]*href=[\"']([^\"']*)[\"'][^>]*>(.*?)<\/a>/i", - $comment, $matches); + preg_match_all("|]*href=[\"']([^\"']*)[\"'][^>]*>(.*?)|i", $comment, $matches); for ($i = 0; $i < count($matches[0]); $i++) { $url = $matches[1][$i]; - if (!empty($_CONF['site_url']) && - strpos($url, $_CONF['site_url']) === 0 - ) { - // skip links to our own site - continue; - } else { + if (empty($_CONF['site_url']) || stripos($url, $_CONF['site_url']) !== 0) { $links[] = $url; } } @@ -169,22 +163,19 @@ public function getLinks($comment) * through getLinks() twice. * * @param string $comment The post to check - * @return string All the URLs in the post, sep. by linefeeds + * @return string All the URLs in the post, sep. by line feeds */ public function prepareLinks($comment) { - $links = array(); - $linklist = ''; + $linkList = ''; // some spam posts have extra backslashes $comment = stripslashes($comment); // some spammers have yet to realize that we're not supporting BBcode // but since we want the URLs, convert it here ... - $comment = preg_replace('/\[url=([^\]]*)\]/i', '', - $comment); - $comment = str_replace(array('[/url]', '[/URL]'), - array('', ''), $comment); + $comment = preg_replace('/\[url=([^\]]*)\]/i', '', $comment); + $comment = str_ireplace('[/url]', '', $comment); // get all links from tags $links = $this->getLinks($comment); @@ -195,9 +186,9 @@ public function prepareLinks($comment) if (count($links) > 0) { $this->checkWhitelist($links); - $linklist = implode("\n", $links); + $linkList = implode("\n", $links); } - return trim($linklist); + return trim($linkList); } } diff --git a/plugins/spamx/SNLbase.class.php b/plugins/spamx/SNLbase.class.php index 7f4f23e9d..036b8713f 100644 --- a/plugins/spamx/SNLbase.class.php +++ b/plugins/spamx/SNLbase.class.php @@ -54,8 +54,9 @@ public function CheckForSpam($post) } $links = $this->prepareLinks($post); + $numLinks = count($links); - if (empty($links)) { + if ($numLinks === 0) { return $retval; } @@ -63,9 +64,9 @@ public function CheckForSpam($post) $_SPX_CONF['snl_num_links'] = 5; } - if ($links > $_SPX_CONF['snl_num_links']) { + if ($numLinks > $_SPX_CONF['snl_num_links']) { $retval = true; - SPAMX_log('SNL: spam detected, found ' . $links . ' links.'); + SPAMX_log('SNL: spam detected, found ' . $numLinks . ' links.'); } return $retval; @@ -76,24 +77,20 @@ public function CheckForSpam($post) * Extracts all the links from a post; expects HTML links, i.e. tags * * @param string $comment The post to check - * @return string All the URLs in the post, sep. by line feeds + * @return array an array of links in the post */ public function getLinks($comment) { global $_CONF; - $links = ''; + $links = array(); - preg_match_all("/]*href=[\"']([^\"']*)[\"'][^>]*>(.*?)<\/a>/i", $comment, $matches); + preg_match_all("|]*href=[\"']([^\"']*)[\"'][^>]*>(.*?)|i", $comment, $matches); for ($i = 0; $i < count($matches[0]); $i++) { $url = $matches[1][$i]; - if (stripos($url, $_CONF['site_url']) === 0) { - // skip links to our own site - continue; - } else { - // $links .= $url . "\n"; - $links++; + if (stripos($url, $_CONF['site_url']) !== 0) { + $links[] = $url; } } @@ -108,7 +105,7 @@ public function getLinks($comment) * through getLinks() twice. * * @param string $comment The post to check - * @return string All the URLs in the post, sep. by linefeeds + * @return array an array of all the URLs in the post */ public function prepareLinks($comment) { @@ -117,10 +114,8 @@ public function prepareLinks($comment) // some spammers have yet to realize that we're not supporting BBcode // but since we want the URLs, convert it here ... - $comment = preg_replace('/\[url=([^\]]*)\]/i', '', - $comment); - $comment = str_replace(array('[/url]', '[/URL]'), - array('', ''), $comment); + $comment = preg_replace('/\[url=([^\]]*)\]/i', '', $comment); + $comment = str_ireplace('[/url]','', $comment); // get all links from tags $links = $this->getLinks($comment); diff --git a/plugins/spamx/functions.inc b/plugins/spamx/functions.inc index f0e8a7fad..2ebb55e21 100644 --- a/plugins/spamx/functions.inc +++ b/plugins/spamx/functions.inc @@ -3,11 +3,9 @@ /** * File: functions.inc * This is the functions.inc for the Geeklog Spam-X plugin - * * Copyright (C) 2004-2011 by the following authors: * Authors Tom Willett tomw AT pigstye DOT net * Dirk Haun dirk AT haun-online DOT de - * * Licensed under GNU General Public License * * @package Spam-X @@ -31,9 +29,7 @@ Language::override(array( 'LANG_SX00', 'PLG_spamx_MESSAGE128', 'PLG_spamx_MESSAGE8', )); -/** -* Check and see if we need to load the plugin configuration -*/ +// Check and see if we need to load the plugin configuration if (!isset($_SPX_CONF['timeout'])) { require_once $_CONF['path_system'] . 'classes/config.class.php'; @@ -46,16 +42,15 @@ if (!isset($_SPX_CONF['timeout'])) { // +---------------------------------------------------------------------------+ /** -* Shows the statistics for the plugin on stats.php. If $showsitestats is 1 -* then we are to only print the overall stats in the 'site statistics' box -* otherwise we show the detailed stats for the plugin -* -* @param int $showsitestats Flag to let us know which stats to get -* @return string returns formatted HTML to insert in stats page -* @see plugin_statssummary_spamx -* -*/ -function plugin_showstats_spamx($showsitestats) + * Shows the statistics for the plugin on stats.php. If $showsitestats is 1 + * then we are to only print the overall stats in the 'site statistics' box + * otherwise we show the detailed stats for the plugin + * + * @param int $showSiteStats Flag to let us know which stats to get + * @return string returns formatted HTML to insert in stats page + * @see plugin_statssummary_spamx + */ +function plugin_showstats_spamx($showSiteStats) { global $_CONF, $_TABLES, $LANG_SX00; @@ -63,27 +58,38 @@ function plugin_showstats_spamx($showsitestats) if (SEC_hasRights('spamx.admin')) { // detailed stats are only visible to Spam-X admins - require_once( $_CONF['path_system'] . 'lib-admin.php' ); + require_once($_CONF['path_system'] . 'lib-admin.php'); $header_arr = array( array('text' => $LANG_SX00['stats_page_title'], 'field' => 'label', 'header_class' => 'stats-header-title'), array('text' => $LANG_SX00['stats_entries'], 'field' => 'stats', 'header_class' => 'stats-header-count', 'field_class' => 'stats-list-count'), ); $data_arr = array(); - $text_arr = array('has_menu' => false, - 'title' => $LANG_SX00['stats_headline'], - 'form_url' => $_CONF['site_url'] . '/stats.php' + $text_arr = array( + 'has_menu' => false, + 'title' => $LANG_SX00['stats_headline'], + 'form_url' => $_CONF['site_url'] . '/stats.php', ); $data_arr = array( - array('label' => $LANG_SX00['stats_pblacklist'], - 'stats' => COM_numberFormat (DB_count ($_TABLES['spamx'], 'name', 'Personal'))), - array('label' => $LANG_SX00['stats_ip'], - 'stats' => COM_numberFormat (DB_count ($_TABLES['spamx'], 'name', 'IP'))), - array('label' => $LANG_SX00['stats_ipofurl'], - 'stats' => COM_numberFormat (DB_count ($_TABLES['spamx'], 'name', 'IPofUrl'))), - array('label' => $LANG_SX00['stats_header'], - 'stats' => COM_numberFormat (DB_count ($_TABLES['spamx'], 'name', 'HTTPHeader'))), - array('label' => $LANG_SX00['slvwhitelist'], - 'stats' => COM_numberFormat (DB_count ($_TABLES['spamx'], 'name', 'SLVwhitelist'))) + array( + 'label' => $LANG_SX00['stats_pblacklist'], + 'stats' => COM_numberFormat(DB_count($_TABLES['spamx'], 'name', 'Personal')), + ), + array( + 'label' => $LANG_SX00['stats_ip'], + 'stats' => COM_numberFormat(DB_count($_TABLES['spamx'], 'name', 'IP')), + ), + array( + 'label' => $LANG_SX00['stats_ipofurl'], + 'stats' => COM_numberFormat(DB_count($_TABLES['spamx'], 'name', 'IPofUrl')), + ), + array( + 'label' => $LANG_SX00['stats_header'], + 'stats' => COM_numberFormat(DB_count($_TABLES['spamx'], 'name', 'HTTPHeader')), + ), + array( + 'label' => $LANG_SX00['slvwhitelist'], + 'stats' => COM_numberFormat(DB_count($_TABLES['spamx'], 'name', 'SLVwhitelist')), + ), ); $retval .= ADMIN_simpleList("", $header_arr, $text_arr, $data_arr); } @@ -92,24 +98,22 @@ function plugin_showstats_spamx($showsitestats) } /** -* New stats plugin API function for proper integration with the site stats -* -* @return array(item text, item count); -* @see plugin_showstats_spamx -* -*/ -function plugin_statssummary_spamx () + * New stats plugin API function for proper integration with the site stats + * + * @return array(item text, item count); + * @see plugin_showstats_spamx + */ +function plugin_statssummary_spamx() { global $_TABLES, $LANG_SX00; - $counter = DB_getItem ($_TABLES['vars'], 'value', "name = 'spamx.counter'"); + $counter = DB_getItem($_TABLES['vars'], 'value', "name = 'spamx.counter'"); - return array ($LANG_SX00['stats_deleted'], COM_numberFormat ($counter)); + return array($LANG_SX00['stats_deleted'], COM_numberFormat($counter)); } /** * This will put an option for the plugin in the command and control block on moderation.php - * * Add the plugin name, icon and link to the command and control block in moderation.php * * @return array Array containing (plugin name, admin url, url of plugin icon) @@ -122,7 +126,7 @@ function plugin_cclabel_spamx() if (SEC_hasRights('spamx.admin')) { $retval = array($LANG_SX00['plugin_name'], $_CONF['site_admin_url'] . '/plugins/spamx/index.php', - plugin_geticon_spamx (), 'tools'); + plugin_geticon_spamx(), 'tools'); } return $retval; @@ -130,7 +134,6 @@ function plugin_cclabel_spamx() /** * Returns the administrative option for this plugin - * * Adds the plugin to the Admin menu * * @return array Array containing (plugin name, plugin admin url, # of items in plugin or '') @@ -140,12 +143,11 @@ function plugin_getadminoption_spamx() global $_CONF, $LANG_SX00, $_TABLES; if (SEC_hasRights('spamx.admin')) { - $result = DB_query ("SELECT count(*) AS cnt FROM {$_TABLES['spamx']}"); - $A = DB_fetchArray ($result); + $result = DB_query("SELECT count(*) AS cnt FROM {$_TABLES['spamx']}"); + $A = DB_fetchArray($result); $count = $A['cnt']; - return array($LANG_SX00['plugin_name'], - $_CONF['site_admin_url'] . '/plugins/spamx/index.php', $count, 'tools'); + return array($LANG_SX00['plugin_name'], $_CONF['site_admin_url'] . '/plugins/spamx/index.php', $count, 'tools'); } } @@ -166,17 +168,15 @@ function plugin_chkVersion_spamx() } /** -* Update the Spam-X plugin -* -* @return int Number of message to display -* -*/ + * Update the Spam-X plugin + * + * @return int Number of message to display + */ function plugin_upgrade_spamx() { global $_CONF, $_TABLES, $_DB_dbms; - $installed_version = DB_getItem($_TABLES['plugins'], 'pi_version', - "pi_name = 'spamx'"); + $installed_version = DB_getItem($_TABLES['plugins'], 'pi_version', "pi_name = 'spamx'"); $code_version = plugin_chkVersion_spamx(); if ($installed_version == $code_version) { // nothing to do @@ -185,147 +185,147 @@ function plugin_upgrade_spamx() require_once $_CONF['path'] . 'plugins/spamx/autoinstall.php'; - if (! plugin_compatible_with_this_version_spamx('spamx')) { + if (!plugin_compatible_with_this_version_spamx('spamx')) { return 3002; } $inst_parms = plugin_autoinstall_spamx('spamx'); $pi_gl_version = $inst_parms['info']['pi_gl_version']; - require_once $_CONF['path'] . 'plugins/spamx/sql/' - . $_DB_dbms . '_updates.php'; - + require_once $_CONF['path'] . 'plugins/spamx/sql/' . $_DB_dbms . '_updates.php'; require_once $_CONF['path'] . 'plugins/spamx/install_updates.php'; $current_version = $installed_version; $done = false; $current_config = false; - while (! $done) { - switch ($current_version) { - case '1.1.0': - require_once $_CONF['path_system'] . 'classes/config.class.php'; - - $plugin_path = $_CONF['path'] . 'plugins/spamx/'; - require_once $plugin_path . 'install_defaults.php'; - if (file_exists($plugin_path . 'config.php')) { - global $_DB_table_prefix, $_SPX_CONF; - - require_once $plugin_path . 'config.php'; - } + while (!$done) { + switch ($current_version) { + case '1.1.0': + require_once $_CONF['path_system'] . 'classes/config.class.php'; - if (!plugin_initconfig_spamx()) { - echo 'There was an error upgrading the Spam-X plugin'; - return false; - } - $current_config = true; + $plugin_path = $_CONF['path'] . 'plugins/spamx/'; + require_once $plugin_path . 'install_defaults.php'; - $current_version = '1.1.1'; - break; + if (file_exists($plugin_path . 'config.php')) { + global $_DB_table_prefix, $_SPX_CONF; - case '1.1.1': - // no db changes - $current_version = '1.1.2'; - break; + require_once $plugin_path . 'config.php'; + } - case '1.1.2': - // no db changes - $current_version = '1.2.0'; - break; + if (!plugin_initconfig_spamx()) { + echo 'There was an error upgrading the Spam-X plugin'; - case '1.2.0': - if (isset($_UPDATES[$current_version])) { - $_SQL = $_UPDATES[$current_version]; - foreach ($_SQL as $sql) { - DB_query($sql); + return false; + } + $current_config = true; + + $current_version = '1.1.1'; + break; + + case '1.1.1': + // no db changes + $current_version = '1.1.2'; + break; + + case '1.1.2': + // no db changes + $current_version = '1.2.0'; + break; + + case '1.2.0': + if (isset($_UPDATES[$current_version])) { + $_SQL = $_UPDATES[$current_version]; + foreach ($_SQL as $sql) { + DB_query($sql); + } } - } - if (! $current_config) { - // Remove admin override since not needed anymore - $c = config::get_instance(); - $c->del('admin_override', 'spamx'); - - // late fix: ensure 'notification_email' option can be disabled - $result = DB_query("SELECT value, default_value FROM {$_TABLES['conf_values']} WHERE name = 'notification_email' AND group_name = 'spamx'"); - list($value, $default_value) = DB_fetchArray($result); - if ($value != 'unset') { - if (substr($default_value, 0, 6) != 'unset:') { - $unset = DB_escapeString('unset:' . $default_value); - DB_query("UPDATE {$_TABLES['conf_values']} SET default_value = '$unset' WHERE name = 'notification_email' AND group_name = 'spamx'"); + if (!$current_config) { + // Remove admin override since not needed anymore + $c = config::get_instance(); + $c->del('admin_override', 'spamx'); + + // late fix: ensure 'notification_email' option can be disabled + $result = DB_query("SELECT value, default_value FROM {$_TABLES['conf_values']} WHERE name = 'notification_email' AND group_name = 'spamx'"); + list($value, $default_value) = DB_fetchArray($result); + if ($value != 'unset') { + if (substr($default_value, 0, 6) != 'unset:') { + $unset = DB_escapeString('unset:' . $default_value); + DB_query("UPDATE {$_TABLES['conf_values']} SET default_value = '$unset' WHERE name = 'notification_email' AND group_name = 'spamx'"); + } } } - } - $current_version = '1.2.1'; - break; + $current_version = '1.2.1'; + break; - case '1.2.1': - if (isset($_UPDATES[$current_version])) { - $_SQL = $_UPDATES[$current_version]; - foreach ($_SQL as $sql) { - DB_query($sql); + case '1.2.1': + if (isset($_UPDATES[$current_version])) { + $_SQL = $_UPDATES[$current_version]; + foreach ($_SQL as $sql) { + DB_query($sql); + } } - } - if (! $current_config) { - spamx_update_ConfValues_1_2_1(); - } + if (!$current_config) { + spamx_update_ConfValues_1_2_1(); + } - spamx_update_ConfigSecurity_1_2_1(); + spamx_update_ConfigSecurity_1_2_1(); - $current_version = '1.2.2'; - break; + $current_version = '1.2.2'; + break; - case '1.2.2': - if (isset($_UPDATES[$current_version])) { - $_SQL = $_UPDATES[$current_version]; - foreach ($_SQL as $sql) { - DB_query($sql); + case '1.2.2': + if (isset($_UPDATES[$current_version])) { + $_SQL = $_UPDATES[$current_version]; + foreach ($_SQL as $sql) { + DB_query($sql); + } } - } - if (! $current_config) { - // Update to Config Tables must be performed here and not in regular SQL update array since if config is current then they shouldn't be run - // Set new Tab column to whatever fieldset is - $sql = "UPDATE {$_TABLES['conf_values']} SET tab = fieldset WHERE group_name = 'spamx'"; - DB_query($sql); + if (!$current_config) { + // Update to Config Tables must be performed here and not in regular SQL update array since if config is current then they shouldn't be run + // Set new Tab column to whatever fieldset is + $sql = "UPDATE {$_TABLES['conf_values']} SET tab = fieldset WHERE group_name = 'spamx'"; + DB_query($sql); - // Rename the action config option since it is causes JavaScript issues in the config and IE 8 - $sql = "UPDATE {$_TABLES['conf_values']} SET name = 'spamx_action' WHERE name = 'action' AND group_name = 'spamx'"; - DB_query($sql); + // Rename the action config option since it is causes JavaScript issues in the config and IE 8 + $sql = "UPDATE {$_TABLES['conf_values']} SET name = 'spamx_action' WHERE name = 'action' AND group_name = 'spamx'"; + DB_query($sql); - // in an earlier update we accidentally renamed the 'action' option to 'spamx_name' - fix that - $sql = "UPDATE {$_TABLES['conf_values']} SET name = 'spamx_action' WHERE name = 'spamx_name' AND group_name = 'spamx'"; - DB_query($sql); + // in an earlier update we accidentally renamed the 'action' option to 'spamx_name' - fix that + $sql = "UPDATE {$_TABLES['conf_values']} SET name = 'spamx_action' WHERE name = 'spamx_name' AND group_name = 'spamx'"; + DB_query($sql); - spamx_update_ConfValues_1_2_2(); - } + spamx_update_ConfValues_1_2_2(); + } - spamx_update_ConfigSecurity_1_2_2(); + spamx_update_ConfigSecurity_1_2_2(); - $current_version = '1.3.0'; - break; + $current_version = '1.3.0'; + break; - case '1.3.0': // Shipped with Geeklog-2.0.0 - if (isset($_UPDATES[$current_version])) { - $_SQL = $_UPDATES[$current_version]; - foreach ($_SQL as $sql) { - DB_query($sql); + case '1.3.0': // Shipped with Geeklog-2.0.0 + if (isset($_UPDATES[$current_version])) { + $_SQL = $_UPDATES[$current_version]; + foreach ($_SQL as $sql) { + DB_query($sql); + } } - } - spamx_update_ConfValues_1_3_0(); + spamx_update_ConfValues_1_3_0(); - $current_version = '1.3.1'; - break; + $current_version = '1.3.1'; + break; - case '1.3.1': // Shipped with Geeklog-2.1.1 - $current_version = '1.3.2'; - break; + case '1.3.1': // Shipped with Geeklog-2.1.1 + $current_version = '1.3.2'; + break; - default: - $done = true; + default: + $done = true; } } @@ -335,12 +335,11 @@ function plugin_upgrade_spamx() } /** -* Called during site migration - handle changed URLs or paths -* -* @param array $old_conf contents of the $_CONF array on the old site -* @param boolean true on success, otherwise false -* -*/ + * Called during site migration - handle changed URLs or paths + * + * @param array $old_conf contents of the $_CONF array on the old site + * @return boolean true on success, otherwise false + */ function plugin_migrate_spamx($old_conf) { global $_CONF, $_TABLES; @@ -353,7 +352,7 @@ function plugin_migrate_spamx($old_conf) for ($i = 0; $i < $num; $i++) { list($name, $value) = DB_fetchArray($result); $new_value = DB_escapeString(str_replace($old_conf['site_url'], - $_CONF['site_url'], $value)); + $_CONF['site_url'], $value)); $old_value = DB_escapeString($value); DB_query("UPDATE {$_TABLES['spamx']} SET value = '$new_value' WHERE name = 'SLVwhitelist' AND value = '$old_value'"); @@ -371,12 +370,11 @@ function plugin_migrate_spamx($old_conf) /** * Check a post for spam * - * @param string $comment comment text - * @param int $action (former spam action - not used any more) + * @param string $comment comment text + * @param int $action (former spam action - not used any more) * @return int > 0: spam detected, == 0: no spam - * */ -function plugin_checkforSpam_spamx ($comment, $action = -1) +function plugin_checkforSpam_spamx($comment, $action = -1) { global $_CONF, $_SPX_CONF, $_TABLES; @@ -415,17 +413,17 @@ function plugin_checkforSpam_spamx ($comment, $action = -1) $spamx_path = $_CONF['path'] . 'plugins/spamx/'; // Set up Spamx_Examine array - $Spamx_Examine = array (); - if ($dir = @opendir ($spamx_path)) { - while (($file = readdir ($dir)) !== false) { - if (is_file ($spamx_path . $file)) { - if (substr ($file, -18) == '.Examine.class.php') { - $sfile = str_replace ('.Examine.class.php', '', $file); + $Spamx_Examine = array(); + if ($dir = @opendir($spamx_path)) { + while (($file = readdir($dir)) !== false) { + if (is_file($spamx_path . $file)) { + if (substr($file, -18) == '.Examine.class.php') { + $sfile = str_replace('.Examine.class.php', '', $file); $Spamx_Examine[] = $sfile; } } } - closedir ($dir); + closedir($dir); } $res = PLG_SPAM_NOT_FOUND; @@ -434,7 +432,8 @@ function plugin_checkforSpam_spamx ($comment, $action = -1) foreach ($Spamx_Examine as $Examine) { $filename = $Examine . '.Examine.class.php'; - require_once ($spamx_path . $filename); + require_once($spamx_path . $filename); + $EX = new $Examine; $res = $EX->execute($comment); @@ -449,12 +448,11 @@ function plugin_checkforSpam_spamx ($comment, $action = -1) /** * Perform action after spam has been detected * - * @param string $comment comment text - * @param int $action which action modules to call (sum of module numbers) + * @param string $comment comment text + * @param int $action which action modules to call (sum of module numbers) * @return int number of message to display to the spammer - * */ -function plugin_spamaction_spamx ($comment, $action) +function plugin_spamaction_spamx($comment, $action) { global $_CONF, $_SPX_CONF; @@ -467,19 +465,19 @@ function plugin_spamaction_spamx ($comment, $action) } // Set up Spamx_Action array - $Spamx_Action = array (); - if ($dir = @opendir ($spamx_path)) { - while (($file = readdir ($dir)) !== false) { - if (is_file ($spamx_path . $file)) { - if (substr ($file, -17) == '.Action.class.php') { - $sfile = str_replace ('.Action.class.php', '', $file); - require_once ($spamx_path . $file); + $Spamx_Action = array(); + if ($dir = @opendir($spamx_path)) { + while (($file = readdir($dir)) !== false) { + if (is_file($spamx_path . $file)) { + if (substr($file, -17) == '.Action.class.php') { + $sfile = str_replace('.Action.class.php', '', $file); + require_once($spamx_path . $file); $CM = new $sfile; $Spamx_Action[$sfile] = $CM->getActionCode(); } } } - closedir ($dir); + closedir($dir); } foreach ($Spamx_Action as $Act => $actionCode) { @@ -495,38 +493,34 @@ function plugin_spamaction_spamx ($comment, $action) /** * Logs message to spamx.log - * * This will print a message to the spamx log * - * @param string $logentry Message to write to log + * @param string $logentry Message to write to log */ -function SPAMX_log ($logentry) +function SPAMX_log($logentry) { global $_CONF, $LANG01, $_SPX_CONF; - if ((!isset ($_SPX_CONF['logging']) || ($_SPX_CONF['logging'] === true)) && - !empty ($logentry)) { - $logentry = str_replace( array( '' ), array( '(@', '@)' ), - $logentry ); + if ((!isset($_SPX_CONF['logging']) || ($_SPX_CONF['logging'] === true)) && !empty($logentry)) { + $logentry = str_replace(array(''), array('(@', '@)'), $logentry); - $timestamp = strftime ('%c'); + $timestamp = strftime('%c'); $logfile = $_CONF['path_log'] . 'spamx.log'; - if (!$file = fopen ($logfile, 'a')) { - COM_errorLog ($LANG01[33] . $logfile . ' (' . $timestamp . ')', 1); + if (!$file = fopen($logfile, 'a')) { + COM_errorLog($LANG01[33] . $logfile . ' (' . $timestamp . ')', 1); } - fputs ($file, "$timestamp - $logentry \n"); + fputs($file, "$timestamp - $logentry \n"); } } /** -* Returns the URL of the plugin's icon -* -* @return string URL of the icon -* -*/ -function plugin_geticon_spamx () + * Returns the URL of the plugin's icon + * + * @return string URL of the icon + */ +function plugin_geticon_spamx() { global $_CONF; @@ -534,45 +528,42 @@ function plugin_geticon_spamx () } /** -* Automatic uninstall function for plugins -* -* This code is automatically uninstalling the plugin. -* It passes an array to the core code function that removes -* tables, groups, features and php blocks from the tables. -* Additionally, this code can perform special actions that cannot be -* foreseen by the core code (interactions with other plugins for example) -* -* @return array Plugin information -* -*/ -function plugin_autouninstall_spamx () + * Automatic uninstall function for plugins + * This code is automatically uninstalling the plugin. + * It passes an array to the core code function that removes + * tables, groups, features and php blocks from the tables. + * Additionally, this code can perform special actions that cannot be + * foreseen by the core code (interactions with other plugins for example) + * + * @return array Plugin information + */ +function plugin_autouninstall_spamx() { - $out = array ( + $out = array( /* give the name of the tables, without $_TABLES[] */ - 'tables' => array('spamx'), + 'tables' => array('spamx'), /* give the full name of the group, as in the db */ - 'groups' => array('spamx Admin'), + 'groups' => array('spamx Admin'), /* give the full name of the feature, as in the db */ - 'features' => array('spamx.admin', - 'spamx.view', - 'spamx.skip', - 'config.spamx.tab_main'), + 'features' => array('spamx.admin', + 'spamx.view', + 'spamx.skip', + 'config.spamx.tab_main'), /* give the full name of the block, including 'phpblock_', etc */ 'php_blocks' => array(), /* give all vars with their name */ - 'vars' => array('spamx_gid', 'spamx.counter') + 'vars' => array('spamx_gid', 'spamx.counter'), ); return $out; } /** -* Provide URL of a documentation file -* -* @param string $file documentation file being requested, e.g. 'config' -* @return mixed URL or false when not available -* -*/ + * Provide URL of a documentation file + * + * @param string $file documentation file being requested, e.g. 'config' + * @return mixed URL or false when not available + */ function plugin_getdocumentationurl_spamx($file) { global $_CONF; @@ -580,38 +571,37 @@ function plugin_getdocumentationurl_spamx($file) static $docurl; switch ($file) { - case 'index': - case 'config': - if (isset($docurl)) { - $retval = $docurl; - } else { - $doclang = COM_getLanguageName(); - $docs = 'docs/' . $doclang . '/spamx.html'; - if (file_exists($_CONF['path_html'] . $docs)) { - $retval = $_CONF['site_url'] . '/' . $docs; + case 'index': + case 'config': + if (isset($docurl)) { + $retval = $docurl; } else { - $retval = $_CONF['site_url'] . '/docs/english/spamx.html'; + $doclang = COM_getLanguageName(); + $docs = 'docs/' . $doclang . '/spamx.html'; + if (file_exists($_CONF['path_html'] . $docs)) { + $retval = $_CONF['site_url'] . '/' . $docs; + } else { + $retval = $_CONF['site_url'] . '/docs/english/spamx.html'; + } + $docurl = $retval; } - $docurl = $retval; - } - break; + break; - default: - $retval = false; - break; + default: + $retval = false; + break; } return $retval; } /** -* Provides text for a Configuration tooltip -* -* @param string $id Id of config value -* @return mixed Text to use regular tooltip, NULL to use config -* tooltip hack, or empty string when not available -* -*/ + * Provides text for a Configuration tooltip + * + * @param string $id Id of config value + * @return mixed Text to use regular tooltip, NULL to use config + * tooltip hack, or empty string when not available + */ function plugin_getconfigtooltip_spamx($id) { // Use config tooltip hack where tooltip is read from the config documentation @@ -619,19 +609,18 @@ function plugin_getconfigtooltip_spamx($id) } /** -* Checks user registrations against stopforumspam.com to validate email and IP addresses -* -* @param string $type Type of item -* @param string $username Type of item -* @return string -* -*/ + * Checks user registrations against stopforumspam.com to validate email and IP addresses + * + * @param string $type Type of item + * @param string $username Type of item + * @return string + */ function plugin_itemPreSave_spamx($type, $username) { global $_CONF, $LANG_SX00; if ($type == 'registration') { - require_once $_CONF['path'].'/plugins/spamx/SFS.Misc.class.php'; + require_once $_CONF['path'] . '/plugins/spamx/SFS.Misc.class.php'; $EX = new SFS; $res = $EX->execute(Geeklog\Input::post('email'), Geeklog\Input::server('REMOTE_ADDR')); if ($res > 0) {