[ Index ]
 

Code source de GeekLog 1.4.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/plugins/spamx/ -> functions.inc (source)

   1  <?php
   2  
   3  /**
   4   * File: functions.inc
   5   * This is the functions.inc for the Geeklog Spam-X plugin
   6   * 
   7   * Copyright (C) 2004-2006 by the following authors:
   8   * Authors      Tom Willett     tomw AT pigstye DOT net
   9   *              Dirk Haun       dirk AT haun-online DOT de
  10   * 
  11   * Licensed under GNU General Public License
  12   *
  13   * $Id: functions.inc,v 1.27 2006/12/30 13:57:08 dhaun Exp $
  14   */
  15  
  16  if (strpos ($_SERVER['PHP_SELF'], 'functions.inc') !== false) {
  17      die ('This file can not be used on its own.');
  18  }
  19  
  20  /**
  21   * Language file include
  22   */
  23  $langfile = $_CONF['path'] . 'plugins/spamx/language/'
  24            . $_CONF['language'] . '.php';
  25  
  26  if (file_exists ($langfile)) {
  27      include_once ($langfile);
  28  } else {
  29      include_once ($_CONF['path'] . 'plugins/spamx/language/english.php');
  30  } 
  31  
  32  /*
  33  * Include spamx config files
  34  */
  35  require_once ($_CONF['path'] . 'plugins/spamx/config.php');
  36  
  37  // +---------------------------------------------------------------------------+
  38  // | Geeklog Plugin API Implementations                                        |
  39  // +---------------------------------------------------------------------------+
  40  
  41  /**
  42   * Shows the statistics for the plugin on stats.php.  If
  43   * $showsitestats is 1 then we are to only print the overall stats in the 'site
  44   * statistics' box otherwise we show the detailed stats for the plugin
  45   * 
  46   * @param   int     $showsitestats  Flag to let us know which stats to get
  47   * @return  string  returns formatted HTML to insert in stats page
  48   */
  49  function plugin_showstats_spamx($showsitestats)
  50  {
  51      global $_CONF, $_TABLES, $LANG_SX00;
  52  
  53      $retval = '';
  54  
  55      if (SEC_hasRights('spamx.admin')) {
  56          // detailed stats are only visible to Spam-X admins
  57          require_once( $_CONF['path_system'] . 'lib-admin.php' );
  58          $header_arr = array(
  59              array('text' => $LANG_SX00['stats_page_title'], 'field' => 'label', 'header_class' => 'stats-header-title'),
  60              array('text' => $LANG_SX00['stats_entries'], 'field' => 'stats', 'header_class' => 'stats-header-count', 'field_class' => 'stats-list-count'),
  61          );
  62          $data_arr = array();
  63          $text_arr = array('has_menu'     => false,
  64                            'title'        => $LANG_SX00['stats_headline'],
  65          );
  66          $data_arr = array(
  67              array('label' => $LANG_SX00['stats_pblacklist'],
  68                  'stats' => COM_numberFormat (DB_count ($_TABLES['spamx'], 'name', 'Personal'))),
  69              array('label' => $LANG_SX00['stats_ip'],
  70                  'stats' => COM_numberFormat (DB_count ($_TABLES['spamx'], 'name', 'IP'))),
  71              array('label' => $LANG_SX00['stats_ipofurl'],
  72                  'stats' => COM_numberFormat (DB_count ($_TABLES['spamx'], 'name', 'IPofUrl'))),
  73              array('label' => $LANG_SX00['stats_header'],
  74                  'stats' => COM_numberFormat (DB_count ($_TABLES['spamx'], 'name', 'HTTPHeader'))),
  75              array('label' => $LANG_SX00['slvwhitelist'],
  76                  'stats' => COM_numberFormat (DB_count ($_TABLES['spamx'], 'name', 'SLVwhitelist')))
  77          );
  78          $retval .= ADMIN_simpleList("", $header_arr, $text_arr, $data_arr);
  79      }
  80  
  81      return $retval;
  82  }
  83  
  84  /**
  85  * New stats plugin API function for proper integration with the site stats
  86  * 
  87  * @return   array(item text, item count);
  88  * 
  89  */
  90  function plugin_statssummary_spamx ()
  91  {
  92      global $_TABLES, $LANG_SX00;
  93  
  94      $counter = DB_getItem ($_TABLES['vars'], 'value', "name = 'spamx.counter'");
  95  
  96      return array ($LANG_SX00['stats_deleted'], COM_numberFormat ($counter));
  97  }
  98  
  99  /**
 100   * This will put an option for the plugin in the command and control block on moderation.php
 101   * 
 102   * Add the plugin name, icon and link to the command and control block in moderation.php
 103   * 
 104   * @return array Array containing (plugin name, admin url, url of plugin icon)
 105   */
 106  function plugin_cclabel_spamx()
 107  {
 108      global $_CONF, $LANG_SX00;
 109  
 110      $retval = array();
 111      if (SEC_hasRights('spamx.admin')) {
 112          $retval = array($LANG_SX00['plugin_name'],
 113              $_CONF['site_admin_url'] . '/plugins/spamx/index.php',
 114              plugin_geticon_spamx ());
 115      } 
 116  
 117      return $retval;
 118  } 
 119  
 120  /**
 121   * Returns the administrative option for this plugin
 122   * 
 123   * Adds the plugin to the Admin menu
 124   * 
 125   * @return array Array containing (plugin name, plugin admin url, # of items in plugin or '')
 126   */
 127  function plugin_getadminoption_spamx()
 128  {
 129      global $_CONF, $LANG_SX00;
 130  
 131      if (SEC_hasRights('spamx.admin')) {
 132          return array($LANG_SX00['plugin_name'],
 133              $_CONF['site_admin_url'] . '/plugins/spamx/index.php', 0);
 134      } 
 135  }
 136  
 137  /**
 138   * Returns the current plugin code version
 139   * 
 140   * @return string    plugin version
 141   */
 142  function plugin_chkVersion_spamx ()
 143  {
 144      global $_SPX_CONF;
 145  
 146      return $_SPX_CONF['version'];
 147  }
 148  
 149  /**
 150  * Update the Spam-X plugin
 151  *
 152  * @return   int     Number of message to display
 153  *
 154  */
 155  function plugin_upgrade_spamx ()
 156  {
 157      global $_TABLES, $_SPX_CONF;
 158  
 159      if (!function_exists ('PLG_spamAction')) {
 160          return 3002; // plugin not compatible with this Geeklog version
 161      }
 162  
 163      $v = DB_getItem ($_TABLES['plugins'], 'pi_version', "pi_name = 'spamx'");
 164  
 165      if ($v != $_SPX_CONF['version']) {
 166          switch ($v) {
 167              case '1.0.1':
 168                  // Add the counter
 169                  DB_query ("INSERT INTO {$_TABLES['vars']} VALUES ('spamx.counter', '0')");
 170                  break;
 171          }
 172  
 173          // update version numbers
 174          DB_query ("UPDATE {$_TABLES['plugins']} SET pi_version = '{$_SPX_CONF['version']}', pi_gl_version = '1.4.1' WHERE pi_name = 'spamx'");
 175  
 176          // check if version number was updated successfully
 177          $v = DB_getItem ($_TABLES['plugins'], 'pi_version', "pi_name = 'spamx'");
 178      }
 179  
 180      if ($v == $_SPX_CONF['version']) {
 181          return 3001;
 182      }
 183  
 184      return 3002;
 185  }
 186  
 187  /**
 188   * Actual Plugin Functions here.
 189   */
 190  
 191  /**
 192   * Check a post for spam
 193   *
 194   * @param   string  $comment    comment text
 195   * @param   int     $action     (former spam action - not used any more)
 196   * @return  int                 > 0: spam detected, == 0: no spam
 197   *
 198   */
 199  function plugin_checkforSpam_spamx ($comment, $action = -1)
 200  {
 201      global $_CONF, $_SPX_CONF; 
 202  
 203      // skip spam check for members of the 'spamx Admin' group, if enabled
 204      if (isset ($_SPX_CONF['admin_override']) && $_SPX_CONF['admin_override']) {
 205          if (SEC_inGroup ('spamx Admin')) {
 206              return 0;
 207          }
 208      }
 209  
 210      $spamx_path = $_CONF['path'] . 'plugins/spamx/';
 211  
 212      // Set up Spamx_Examine array
 213      $Spamx_Examine = array ();
 214      if ($dir = @opendir ($spamx_path)) {
 215          while (($file = readdir ($dir)) !== false) {
 216              if (is_file ($spamx_path . $file)) {
 217                  if (substr ($file, -18) == '.Examine.class.php') {
 218                      $sfile = str_replace ('.Examine.class.php', '', $file);
 219                      $Spamx_Examine[] = $sfile;
 220                  }
 221              }
 222          }
 223          closedir ($dir);
 224      }
 225  
 226      $res = 0;
 227      foreach ($Spamx_Examine as $Examine) {
 228          $filename = $Examine . '.Examine.class.php';
 229          require_once ($spamx_path . $filename);
 230          $EX = new $Examine;
 231          $res = $EX->execute ($comment);
 232          if ($res == 1) {
 233              break;
 234          }
 235      }
 236  
 237      return $res;
 238  }
 239  
 240  /**
 241   * Perform action after spam has been detected
 242   *
 243   * @param   string  $comment    comment text
 244   * @param   int     $action     which action modules to call (sum of module numbers)
 245   * @return  int                 number of message to display to the spammer
 246   *
 247   */
 248  function plugin_spamaction_spamx ($comment, $action)
 249  {
 250      global $_CONF, $_SPX_CONF;
 251  
 252      $res = 0;
 253  
 254      $spamx_path = $_CONF['path'] . 'plugins/spamx/';
 255  
 256      if (($action == -1) || ($action == '')) {
 257          $action = $_SPX_CONF['action'];
 258      }
 259  
 260      // Set up Spamx_Action array
 261      $Spamx_Action = array ();
 262      if ($dir = @opendir ($spamx_path)) {
 263          while (($file = readdir ($dir)) !== false) {
 264              if (is_file ($spamx_path . $file)) {
 265                  if (substr ($file, -17) == '.Action.class.php') {
 266                      $sfile = str_replace ('.Action.class.php', '', $file);
 267                      require_once ($spamx_path . $file);
 268                      $CM = new $sfile;
 269                      $Spamx_Action[$sfile] = $CM->number ();
 270                  }   
 271              }   
 272          }   
 273          closedir ($dir);
 274      }
 275  
 276      foreach ($Spamx_Action as $Act => $Num) {
 277          if (($action & $Num) == $Num) {
 278              $AC = new $Act;
 279              $AC->execute ($comment);
 280              
 281              $res = max ($res, $AC->result ());
 282          }
 283      }
 284  
 285      return $res;
 286  }
 287  
 288  /**
 289   * Logs message to spamx.log
 290   * 
 291   * This will print a message to the spamx log
 292   * 
 293   * @param   string  $logentry   Message to write to log
 294   */
 295  function SPAMX_log ($logentry)
 296  {
 297      global $_CONF, $LANG01, $_SPX_CONF;
 298  
 299      if ((!isset ($_SPX_CONF['logging']) || ($_SPX_CONF['logging'] === true)) &&
 300              !empty ($logentry)) {
 301          $logentry = str_replace( array( '<?', '?>' ), array( '(@', '@)' ),
 302                                   $logentry );
 303  
 304          $timestamp = strftime ('%c');
 305          $logfile = $_CONF['path_log'] . 'spamx.log';
 306  
 307          if (!$file = fopen ($logfile, 'a')) {
 308              COM_errorLog ($LANG01[33] . $logfile . ' (' . $timestamp . ')', 1);
 309          } 
 310  
 311          fputs ($file, "$timestamp - $logentry \n");
 312      } 
 313  } 
 314  
 315  /**
 316  * Returns the URL of the plugin's icon
 317  *
 318  * @return   string      URL of the icon
 319  *
 320  */
 321  function plugin_geticon_spamx ()
 322  {
 323      global $_CONF;
 324  
 325      return $_CONF['site_admin_url'] . '/plugins/spamx/images/spamx.png';
 326  }
 327  
 328  /**
 329   * Removes the datastructures for this plugin from the Geeklog database.
 330   * This routine will get called from the Plugin install program if user select De-Install or if Delete is used in the Plugin Editor.
 331   * The Plugin Installer will also call this routine upon and install error to remove anything it has created.
 332   * The Plugin installer will pass the optional parameter which will then double check that plugin has first been disabled. 
 333   * 
 334   * Returns True if all Plugin related data is removed without error
 335   * 
 336   * @param string $installCheck Default is blank but if set, check if plugin is disabled first
 337   * @return boolean True if successful false otherwise
 338   */
 339  function plugin_uninstall_spamx($installCheck = '')
 340  {
 341      global $_TABLES, $LANG_SX00;
 342  
 343      $pi_name = 'spamx';
 344      $FEATURES = array ('spamx.admin', 'spamx.view');
 345      $admin_group = 'spamx Admin'; 
 346      // Check and see if plugin is still enabled - if so display warning and exit
 347      if ($installCheck != '' && DB_getItem($_TABLES['plugins'], 'pi_enabled', 'pi_name = "' . $pi_name . '"')) {
 348          COM_errorLog("Plugin is installed and enabled. Disable first if you want to de-install it", 1);
 349          $display .= COM_startBlock($LANG_SX00['warning']);
 350          $display .= $LANG_SX00['enabled'];
 351          $display .= COM_endBlock();
 352          echo $display;
 353          return false;
 354          exit;
 355      } 
 356      // Ok to proceed and delete plugin
 357      // Unregister the plugin with Geeklog
 358      COM_errorLog('Attempting to unregister the spamx plugin from Geeklog', 1);
 359      DB_query("DELETE FROM {$_TABLES['plugins']} WHERE pi_name = 'spamx'", 1); 
 360      // Remove Security for this plugin
 361      $grp_id = DB_getItem ($_TABLES['groups'], 'grp_id', "grp_name = '{$admin_group}'");
 362  
 363      COM_errorLog("Removing $pi_name Admin Group", 1);
 364      DB_query("DELETE FROM {$_TABLES['groups']} WHERE grp_id = $grp_id", 1);
 365      DB_query("DELETE FROM {$_TABLES['vars']} WHERE name = '{$pi_name}_gid'");
 366      DB_query("DELETE FROM {$_TABLES['vars']} WHERE name = 'spamx.counter'");
 367      COM_errorLog("Removing root users from admin of $pi_name");
 368      DB_query("DELETE FROM {$_TABLES['group_assignments']} WHERE ug_main_grp_id = $grp_id", 1); 
 369      // Remove all the associated features -- access rights
 370      foreach ($FEATURES as $feature) {
 371          COM_errorLog("Removing $feature feature and rights to it", 1);
 372          $feat_id = DB_getItem($_TABLES['features'], 'ft_id', "ft_name = '$feature'");
 373          DB_query("DELETE FROM {$_TABLES['access']} WHERE acc_ft_id = $feat_id", 1);
 374          DB_query("DELETE FROM {$_TABLES['features']} WHERE ft_id = $feat_id", 1);
 375      } 
 376  
 377      COM_errorLog ('Dropping ' . $_TABLES['spamx'] . ' table.', 1);
 378      DB_query ("DROP TABLE {$_TABLES['spamx']}", 1);
 379  
 380      COM_errorLog('...success', 1);
 381      return true;
 382  } 
 383  
 384  ?>


Généré le : Wed Nov 21 12:27:40 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics