When a plugin returns 0 items for the Admins Block, don't display that as 'N/A' (bug #0001025)
5 * This is the functions.inc for the Geeklog Spam-X plugin
7 * Copyright (C) 2004-2009 by the following authors:
8 * Authors Tom Willett tomw AT pigstye DOT net
9 * Dirk Haun dirk AT haun-online DOT de
11 * Licensed under GNU General Public License
16 if (strpos(strtolower($_SERVER['PHP_SELF']), 'functions.inc') !== false) {
17 die ('This file can not be used on its own.');
21 * Language file include
23 $plugin_path = $_CONF['path'] . 'plugins/spamx/';
24 $langfile = $plugin_path . 'language/' . $_CONF['language'] . '.php';
26 if (file_exists($langfile)) {
27 include_once $langfile;
29 include_once $plugin_path . 'language/english.php';
33 * Check and see if we need to load the plugin configuration
35 if (!isset($_SPX_CONF['timeout'])) {
36 require_once $_CONF['path_system'] . 'classes/config.class.php';
38 $spx_config = config::get_instance();
39 $_SPX_CONF = $spx_config->get_config('spamx');
43 // +---------------------------------------------------------------------------+
44 // | Geeklog Plugin API Implementations |
45 // +---------------------------------------------------------------------------+
48 * Shows the statistics for the plugin on stats.php. If $showsitestats is 1
49 * then we are to only print the overall stats in the 'site statistics' box
50 * otherwise we show the detailed stats for the plugin
52 * @param int $showsitestats Flag to let us know which stats to get
53 * @return string returns formatted HTML to insert in stats page
54 * @see plugin_statssummary_spamx
57 function plugin_showstats_spamx($showsitestats)
59 global $_CONF, $_TABLES, $LANG_SX00;
63 if (SEC_hasRights('spamx.admin')) {
64 // detailed stats are only visible to Spam-X admins
65 require_once( $_CONF['path_system'] . 'lib-admin.php' );
67 array('text' => $LANG_SX00['stats_page_title'], 'field' => 'label', 'header_class' => 'stats-header-title'),
68 array('text' => $LANG_SX00['stats_entries'], 'field' => 'stats', 'header_class' => 'stats-header-count', 'field_class' => 'stats-list-count'),
71 $text_arr = array('has_menu' => false,
72 'title' => $LANG_SX00['stats_headline'],
75 array('label' => $LANG_SX00['stats_pblacklist'],
76 'stats' => COM_numberFormat (DB_count ($_TABLES['spamx'], 'name', 'Personal'))),
77 array('label' => $LANG_SX00['stats_ip'],
78 'stats' => COM_numberFormat (DB_count ($_TABLES['spamx'], 'name', 'IP'))),
79 array('label' => $LANG_SX00['stats_ipofurl'],
80 'stats' => COM_numberFormat (DB_count ($_TABLES['spamx'], 'name', 'IPofUrl'))),
81 array('label' => $LANG_SX00['stats_header'],
82 'stats' => COM_numberFormat (DB_count ($_TABLES['spamx'], 'name', 'HTTPHeader'))),
83 array('label' => $LANG_SX00['slvwhitelist'],
84 'stats' => COM_numberFormat (DB_count ($_TABLES['spamx'], 'name', 'SLVwhitelist')))
86 $retval .= ADMIN_simpleList("", $header_arr, $text_arr, $data_arr);
93 * New stats plugin API function for proper integration with the site stats
95 * @return array(item text, item count);
96 * @see plugin_showstats_spamx
99 function plugin_statssummary_spamx ()
101 global $_TABLES, $LANG_SX00;
103 $counter = DB_getItem ($_TABLES['vars'], 'value', "name = 'spamx.counter'");
105 return array ($LANG_SX00['stats_deleted'], COM_numberFormat ($counter));
109 * This will put an option for the plugin in the command and control block on moderation.php
111 * Add the plugin name, icon and link to the command and control block in moderation.php
113 * @return array Array containing (plugin name, admin url, url of plugin icon)
115 function plugin_cclabel_spamx()
117 global $_CONF, $LANG_SX00;
120 if (SEC_hasRights('spamx.admin')) {
121 $retval = array($LANG_SX00['plugin_name'],
122 $_CONF['site_admin_url'] . '/plugins/spamx/index.php',
123 plugin_geticon_spamx ());
130 * Returns the administrative option for this plugin
132 * Adds the plugin to the Admin menu
134 * @return array Array containing (plugin name, plugin admin url, # of items in plugin or '')
136 function plugin_getadminoption_spamx()
138 global $_CONF, $LANG_SX00;
140 if (SEC_hasRights('spamx.admin')) {
141 return array($LANG_SX00['plugin_name'],
142 $_CONF['site_admin_url'] . '/plugins/spamx/index.php', '');
147 * Returns the current plugin code version
149 * @return string plugin version
151 function plugin_chkVersion_spamx()
155 require_once $_CONF['path'] . 'plugins/spamx/autoinstall.php';
157 $inst_parms = plugin_autoinstall_spamx('spamx');
159 return $inst_parms['info']['pi_version'];
163 * Update the Spam-X plugin
165 * @return int Number of message to display
168 function plugin_upgrade_spamx()
170 global $_CONF, $_TABLES;
172 $installed_version = DB_getItem($_TABLES['plugins'], 'pi_version',
173 "pi_name = 'spamx'");
174 $code_version = plugin_chkVersion_spamx();
175 if ($installed_version == $code_version) {
180 require_once $_CONF['path'] . 'plugins/spamx/autoinstall.php';
182 if (! plugin_compatible_with_this_version_spamx('spamx')) {
186 $inst_parms = plugin_autoinstall_spamx('spamx');
187 $pi_gl_version = $inst_parms['info']['pi_gl_version'];
189 DB_query("UPDATE {$_TABLES['plugins']} SET pi_version = '$code_version', pi_gl_version = '$pi_gl_version' WHERE pi_name = 'spamx'");
195 * Called during site migration - handle changed URLs or paths
197 * @param array $old_conf contents of the $_CONF array on the old site
198 * @param boolean true on success, otherwise false
201 function plugin_migrate_spamx($old_conf)
203 global $_CONF, $_TABLES;
205 // only update the SLV whitelist, so we don't use INST_updateSiteUrl
206 $old_url = addslashes($old_conf['site_url']);
207 $result = DB_query("SELECT name, value FROM {$_TABLES['spamx']} WHERE name = 'SLVwhitelist' AND value LIKE '{$old_url}%'");
208 $num = DB_numRows($result);
210 for ($i = 0; $i < $num; $i++) {
211 list($name, $value) = DB_fetchArray($result);
212 $new_value = addslashes(str_replace($old_conf['site_url'],
213 $_CONF['site_url'], $value));
214 $old_value = addslashes($value);
216 DB_query("UPDATE {$_TABLES['spamx']} SET value = '$new_value' WHERE name = 'SLVwhitelist' AND value = '$old_value'");
223 * Actual Plugin Functions here.
227 * Check a post for spam
229 * @param string $comment comment text
230 * @param int $action (former spam action - not used any more)
231 * @return int > 0: spam detected, == 0: no spam
234 function plugin_checkforSpam_spamx ($comment, $action = -1)
236 global $_CONF, $_SPX_CONF;
238 // skip spam check for members of the 'spamx Admin' group, if enabled
239 if (isset ($_SPX_CONF['admin_override']) && $_SPX_CONF['admin_override']) {
240 if (SEC_inGroup ('spamx Admin')) {
245 $spamx_path = $_CONF['path'] . 'plugins/spamx/';
247 // Set up Spamx_Examine array
248 $Spamx_Examine = array ();
249 if ($dir = @opendir ($spamx_path)) {
250 while (($file = readdir ($dir)) !== false) {
251 if (is_file ($spamx_path . $file)) {
252 if (substr ($file, -18) == '.Examine.class.php') {
253 $sfile = str_replace ('.Examine.class.php', '', $file);
254 $Spamx_Examine[] = $sfile;
262 foreach ($Spamx_Examine as $Examine) {
263 $filename = $Examine . '.Examine.class.php';
264 require_once ($spamx_path . $filename);
266 $res = $EX->execute ($comment);
276 * Perform action after spam has been detected
278 * @param string $comment comment text
279 * @param int $action which action modules to call (sum of module numbers)
280 * @return int number of message to display to the spammer
283 function plugin_spamaction_spamx ($comment, $action)
285 global $_CONF, $_SPX_CONF;
289 $spamx_path = $_CONF['path'] . 'plugins/spamx/';
291 if (($action == -1) || ($action == '')) {
292 $action = $_SPX_CONF['action'];
295 // Set up Spamx_Action array
296 $Spamx_Action = array ();
297 if ($dir = @opendir ($spamx_path)) {
298 while (($file = readdir ($dir)) !== false) {
299 if (is_file ($spamx_path . $file)) {
300 if (substr ($file, -17) == '.Action.class.php') {
301 $sfile = str_replace ('.Action.class.php', '', $file);
302 require_once ($spamx_path . $file);
304 $Spamx_Action[$sfile] = $CM->number ();
311 foreach ($Spamx_Action as $Act => $Num) {
312 if (($action & $Num) == $Num) {
314 $AC->execute ($comment);
316 $res = max ($res, $AC->result ());
324 * Logs message to spamx.log
326 * This will print a message to the spamx log
328 * @param string $logentry Message to write to log
330 function SPAMX_log ($logentry)
332 global $_CONF, $LANG01, $_SPX_CONF;
334 if ((!isset ($_SPX_CONF['logging']) || ($_SPX_CONF['logging'] === true)) &&
335 !empty ($logentry)) {
336 $logentry = str_replace( array( '<?', '?>' ), array( '(@', '@)' ),
339 $timestamp = strftime ('%c');
340 $logfile = $_CONF['path_log'] . 'spamx.log';
342 if (!$file = fopen ($logfile, 'a')) {
343 COM_errorLog ($LANG01[33] . $logfile . ' (' . $timestamp . ')', 1);
346 fputs ($file, "$timestamp - $logentry \n");
351 * Returns the URL of the plugin's icon
353 * @return string URL of the icon
356 function plugin_geticon_spamx ()
360 return $_CONF['site_admin_url'] . '/plugins/spamx/images/spamx.png';
364 * Automatic uninstall function for plugins
366 * This code is automatically uninstalling the plugin.
367 * It passes an array to the core code function that removes
368 * tables, groups, features and php blocks from the tables.
369 * Additionally, this code can perform special actions that cannot be
370 * foreseen by the core code (interactions with other plugins for example)
372 * @return array Plugin information
375 function plugin_autouninstall_spamx ()
378 /* give the name of the tables, without $_TABLES[] */
379 'tables' => array('spamx'),
380 /* give the full name of the group, as in the db */
381 'groups' => array('spamx Admin'),
382 /* give the full name of the feature, as in the db */
383 'features' => array('spamx.admin', 'spamx.view'),
384 /* give the full name of the block, including 'phpblock_', etc */
385 'php_blocks' => array(),
386 /* give all vars with their name */
387 'vars' => array('spamx_gid', 'spamx.counter')
394 * Provide URL of a documentation file
396 * @param string $file documentation file being requested, e.g. 'config'
397 * @return mixed URL or false when not available
400 function plugin_getdocumentationurl_spamx($file)
409 if (isset($docurl)) {
412 $doclang = COM_getLanguageName();
413 $docs = 'docs/' . $doclang . '/spamx.html';
414 if (file_exists($_CONF['path_html'] . $docs)) {
415 $retval = $_CONF['site_url'] . '/' . $docs;
417 $retval = $_CONF['site_url'] . '/docs/english/spamx.html';