Changeset 26113


Ignore:
Timestamp:
12/23/13 11:58:09 (6 years ago)
Author:
mistic100
Message:

update for 2.6

Location:
extensions/comments_blacklist
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/comments_blacklist/admin.php

    r18651 r26113  
    33  
    44global $template, $page; 
     5 
     6load_language('plugin.lang', COMM_BLACKLIST_PATH); 
    57 
    68// save config 
     
    1315  file_put_contents(COMM_BLACKLIST_FILE, $_POST['content']); 
    1416  conf_update_param('comments_blacklist', serialize($conf['comments_blacklist'])); 
    15   array_push($page['infos'], l10n('Information data registered in database')); 
     17  $page['infos'][] = l10n('Information data registered in database'); 
    1618} 
    1719   
     
    2729$template->set_filename('comm_blacklist_content', realpath(COMM_BLACKLIST_PATH . 'admin.tpl')); 
    2830$template->assign_var_from_handle('ADMIN_CONTENT', 'comm_blacklist_content'); 
    29  
    30 ?> 
  • extensions/comments_blacklist/main.inc.php

    r19838 r26113  
    44Version: auto 
    55Description: Define a list of words which are not authorized in a comment. 
    6 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=637 
     6Plugin URI: auto 
    77Author: Mistic 
    88Author URI: http://www.strangeplanet.fr 
     
    1111defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); 
    1212 
    13 defined('COMM_BLACKLIST_ID') or define('COMM_BLACKLIST_ID', basename(dirname(__FILE__))); 
     13define('COMM_BLACKLIST_ID',      basename(dirname(__FILE__))); 
    1414define('COMM_BLACKLIST_PATH' ,   PHPWG_PLUGINS_PATH . COMM_BLACKLIST_ID . '/'); 
    1515define('COMM_BLACKLIST_ADMIN',   get_root_url() . 'admin.php?page=plugin-' . COMM_BLACKLIST_ID); 
     
    2323{ 
    2424  add_event_handler('get_admin_plugin_menu_links', 'comm_blacklist_admin_plugin_menu_links'); 
    25    
    26   function comm_blacklist_admin_plugin_menu_links($menu)  
    27   { 
    28     array_push($menu, array( 
    29       'NAME' => 'Comments Blacklist', 
    30       'URL' => COMM_BLACKLIST_ADMIN, 
    31     )); 
    32     return $menu; 
    33   } 
    3425} 
    3526else 
    3627{ 
    3728  add_event_handler('user_comment_check', 'comm_blacklist_user_comment_check', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); 
    38   add_event_handler('user_comment_check_albums', 'comm_blacklist_user_comment_check', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); 
    39   add_event_handler('user_comment_check_guestbook', 'comm_blacklist_user_comment_check', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); 
    40   include_once(COMM_BLACKLIST_PATH . 'include/functions.inc.php'); 
    4129} 
    4230 
     
    4735function comm_blacklist_init() 
    4836{ 
    49   global $conf, $pwg_loaded_plugins; 
     37  global $conf; 
    5038   
    51   // apply upgrade if needed 
    52   if ( 
    53     COMM_BLACKLIST_VERSION == 'auto' or  
    54     $pwg_loaded_plugins[COMM_BLACKLIST_ID]['version'] == 'auto' or 
    55     version_compare($pwg_loaded_plugins[COMM_BLACKLIST_ID]['version'], COMM_BLACKLIST_VERSION, '<') 
    56   ) 
    57   { 
    58     include_once(COMM_BLACKLIST_PATH . 'include/install.inc.php'); 
    59     comm_blacklist_install(); 
    60      
    61     if ( $pwg_loaded_plugins[COMM_BLACKLIST_ID]['version'] != 'auto' and COMM_BLACKLIST_VERSION != 'auto' ) 
    62     { 
    63       $query = ' 
    64 UPDATE '. PLUGINS_TABLE .' 
    65 SET version = "'. COMM_BLACKLIST_VERSION .'" 
    66 WHERE id = "'. COMM_BLACKLIST_ID .'"'; 
    67       pwg_query($query); 
    68        
    69       $pwg_loaded_plugins[COMM_BLACKLIST_ID]['version'] = COMM_BLACKLIST_VERSION; 
    70        
    71       if (defined('IN_ADMIN')) 
    72       { 
    73         $_SESSION['page_infos'][] = 'Comments Blacklist updated to version '. COMM_BLACKLIST_VERSION; 
    74       } 
    75     } 
    76   } 
     39  include_once(COMM_BLACKLIST_PATH . 'maintain.inc.php'); 
     40  $maintain = new comments_blacklist_maintain(COMM_BLACKLIST_ID); 
     41  $maintain->autoUpdate(COMM_BLACKLIST_VERSION, 'install'); 
    7742   
    78   // load plugin language file 
    79   load_language('plugin.lang', COMM_BLACKLIST_PATH); 
    80    
    81   // prepare plugin configuration 
    8243  $conf['comments_blacklist'] = unserialize($conf['comments_blacklist']); 
    8344} 
    8445 
     46/** 
     47 * admin link 
     48 */ 
     49function comm_blacklist_admin_plugin_menu_links($menu)  
     50{ 
     51  $menu[] = array( 
     52    'NAME' => 'Comments Blacklist', 
     53    'URL' => COMM_BLACKLIST_ADMIN, 
     54    ); 
     55  return $menu; 
     56} 
    8557 
    86 ?> 
     58/** 
     59 * comment check 
     60 */ 
     61function comm_blacklist_user_comment_check($comment_action, $comm) 
     62{ 
     63  global $conf; 
     64   
     65  if ($comment_action==$conf['comments_blacklist']['action'] 
     66      or $comment_action=='reject' or !isset($comm['content']) 
     67    ) 
     68  { 
     69    return $comment_action; 
     70  } 
     71   
     72  $blacklist = @file(COMM_BLACKLIST_FILE, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); 
     73   
     74  if (empty($blacklist)) 
     75  { 
     76    return $comment_action; 
     77  } 
     78   
     79  $blacklist = array_map(create_function('$w', 'return preg_quote($w);'), $blacklist); 
     80  $blacklist = implode('|', $blacklist); 
     81   
     82  if (preg_match('#\b('.$blacklist.')\b#i', $comm['content']) or 
     83      (isset($comm['author']) and preg_match('#\b('.$blacklist.')\b#i', $comm['author'])) 
     84    ) 
     85  { 
     86    return $conf['comments_blacklist']['action']; 
     87  } 
     88   
     89  return $comment_action; 
     90} 
  • extensions/comments_blacklist/maintain.inc.php

    r19838 r26113  
    22defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); 
    33 
    4 defined('COMM_BLACKLIST_ID') or define('COMM_BLACKLIST_ID', basename(dirname(__FILE__))); 
    5 include_once(PHPWG_PLUGINS_PATH . COMM_BLACKLIST_ID . '/include/install.inc.php'); 
     4class comments_blacklist_maintain extends PluginMaintain 
     5{ 
     6  private $installed = false; 
     7   
     8  private $default_conf = array( 
     9    'action' => 'reject', 
     10    ); 
     11     
     12  private $file; 
     13   
     14  function __contruct($plugin_id) 
     15  { 
     16    parent::_construct($plugin_id); 
     17    $this->file = PHPWG_ROOT_PATH . PWG_LOCAL_DIR . 'comments_blacklist.txt'; 
     18  } 
    619 
     20  function install($plugin_version, &$errors=array()) 
     21  { 
     22    global $conf, $prefixeTable; 
    723 
    8 function plugin_install()  
    9 { 
    10   comm_blacklist_install(); 
    11   define('comm_blacklist_installed', true); 
    12 } 
     24    if (empty($conf['comments_blacklist'])) 
     25    { 
     26      $conf['comments_blacklist'] = serialize($this->default_conf); 
     27      conf_update_param('comments_blacklist', $conf['comments_blacklist']); 
     28    } 
     29     
     30    if (!file_exists($this->file))  
     31    { 
     32      touch($this->file); 
     33    } 
    1334 
    14 function plugin_activate() 
    15 { 
    16   if (!defined('comm_blacklist_installed')) 
     35    $this->installed = true; 
     36  } 
     37 
     38  function activate($plugin_version, &$errors=array()) 
    1739  { 
    18     comm_blacklist_install(); 
     40    if (!$this->installed) 
     41    { 
     42      $this->install($plugin_version, $errors); 
     43    } 
     44  } 
     45 
     46  function deactivate() 
     47  { 
     48  } 
     49 
     50  function uninstall() 
     51  { 
     52    conf_delete_param('comments_blacklist'); 
     53 
     54    @unlink($this->file); 
    1955  } 
    2056} 
    21  
    22 function plugin_uninstall()  
    23 { 
    24   @unlink(PHPWG_ROOT_PATH . PWG_LOCAL_DIR . 'comments_blacklist.txt'); 
    25 } 
    26  
    27 ?> 
Note: See TracChangeset for help on using the changeset viewer.