Changeset 11294

Show
Ignore:
Timestamp:
07/20/07 14:29:39 (1 year ago)
Author:
juhana
Message:

Added banned word editor and search_banned_words() method

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/net.nemein.bannedwords/config/config.inc

    r11274 r11294  
     1/** 
     2 * These configure how to show the censored words. 
     3 * Default is "***Censored***" 
     4 */ 
     5'censored_start'   => '***', 
     6'censored_end'     => '***', 
     7'censored_word_id' => 'censored', 
     8'censored_custom_word' => '', 
     9 
     10/** 
     11 * Global word libary is in sg0 and can be used by  
     12 * any website. Local library is only useable by 
     13 * the current sitegroup 
     14 */ 
     15'use_global_word_library' => true, 
     16'use_local_word_library'  => true, 
     17 
  • trunk/midcom/net.nemein.bannedwords/config/manifest.inc

    r11274 r11294  
    1818    ), 
    1919  ), 
     20  'customdata' => array( 
     21    'request_handler_plugin' => array( 
     22      'class' => 'net_nemein_bannedwords_edit_handler', 
     23      'src' => 'file:/net/nemein/bannedwords/editor.php', 
     24      'name' => 'Banned words editor', 
     25      'config' => null, 
     26    ), 
     27  ), 
  • trunk/midcom/net.nemein.bannedwords/config/mgdschema.sql

    r11274 r11294  
    11CREATE TABLE net_nemein_bannedwords_word ( 
    22  bannedWord varchar(255) NOT NULL default '', 
     3  description varchar(255) NOT NULL default '', 
     4  language varchar(255) NOT NULL default '', 
    35  # 
    46  id int(11) NOT NULL auto_increment, 
     
    810  # 
    911  KEY net_nemein_bannedwords_word_idx (`bannedWord`(30)), 
     12  KEY net_nemein_description_word_idx (`description`(30)), 
     13  KEY net_nemein_language_word_idx (`language`(30)), 
    1014); 
  • trunk/midcom/net.nemein.bannedwords/config/mgdschema.xml

    r11274 r11294  
    44         <property name="id" type="integer" primaryfield="id" /> 
    55         <property name="bannedWord" type="text"/> 
     6         <property name="description" type="text"/> 
     7         <property name="language" type="text"/> 
    68    </type> 
    79</Schema> 
  • trunk/midcom/net.nemein.bannedwords/locale/default.en.txt

    r11274 r11294  
    1515Delete 
    1616---STRINGEND 
     17 
     18---STRING banned editor 
     19Banned words editor 
     20---STRINGEND 
  • trunk/midcom/net.nemein.bannedwords/main.php

    r11274 r11294  
    1111    var $_sitegroup = null; 
    1212 
     13    var $_language = "en"; 
     14 
    1315    function net_nemein_bannedwords_handler() 
    1416    { 
     
    1921    } 
    2022 
     23    function set_language($language) 
     24    { 
     25        $this->_language = $language; 
     26    } 
     27 
    2128    function _populate_word_list() 
    2229    { 
    2330        $qb = net_nemein_bannedwords_word_dba::new_query_builder(); 
    24         $qb->add_constraint('sitegroup', '=', $this->_sitegroup); 
     31        $qb->add_constraint('language', '=', $this->_language); 
     32 
     33        if ($this->_config->get('use_global_word_library') && $this->_config->get('use_local_word_library')) 
     34        { 
     35            $qb->add_constraint('sitegroup', 'IN', array(0, $this->_sitegroup)); 
     36        } 
     37        elseif ($this->_config->get(use_global_word_library)) 
     38        { 
     39            $qb->add_constraint('sitegroup', '=', 0); 
     40        } 
     41        elseif ($this->_config->get('use_local_word_library')) 
     42        { 
     43            $qb->add_constraint('sitegroup', '=', $this->_sitegroup); 
     44        } 
     45 
    2546        $banned_objects = $qb->execute(); 
    2647 
     
    4263        if (!empty($this->_banned_words)) 
    4364        { 
     65            $censored_start = ""; 
     66            $censored_end = ""; 
     67            $censored_word_id = ""; 
     68            $censored_custom_word = ""; 
     69 
     70            if ($this->_config->get('censored_start')) 
     71            { 
     72                $censored_start = $this->_config->get('censored_start'); 
     73            } 
     74            if ($this->_config->get('censored_end')) 
     75            { 
     76                $censored_end = $this->_config->get('censored_end'); 
     77            } 
     78            if ($this->_config->get('censored_word_id')) 
     79            { 
     80                $censored_word_id = $this->_config->get('censored_word_id'); 
     81            } 
     82            if ($this->_config->get('censored_custom_word')) 
     83            { 
     84                $censored_custom_word = $this->_config->get('censored_custom_word'); 
     85            } 
     86 
    4487            $regexp = $this->_build_regexp(); 
    45             $censored = "<span class=\"net_nemein_bannedwords_censored\">***{$this->_l10n->get('censored')}***</span>"; 
     88            $censored = "<span class=\"net_nemein_bannedwords_censored\">{$censored_start}"; 
     89            if (!empty($censored_custom_word)) 
     90            { 
     91                $censored .= $censored_custom_word; 
     92            } 
     93            else 
     94            { 
     95                $censored .= $this->_l10n->get($censored_word_id); 
     96            } 
     97            $censored .= "{$censored_end}</span>"; 
     98             
    4699            $processed_content = eregi_replace($regexp, $censored, $content); 
    47100         
     
    66119            return $processed_content; 
    67120        } 
     121    } 
     122 
     123    function search_banned_words($content) 
     124    { 
     125        $content = strip_tags($content); 
     126 
     127        // Not working for some reason 
     128        $order = array('\r\n', '\r', '\n'); 
     129        str_replace($order, " ", $content); 
     130 
     131        if (!empty($this->_banned_words)) 
     132        { 
     133            $matches = array(); 
     134            $regexp = $this->_build_regexp(); 
     135            $words = explode(" ", $content); 
     136 
     137            foreach($words as $key => $word) 
     138            { 
     139                if (eregi($regexp, $word)) 
     140                { 
     141                     $matches[$key] = $word; 
     142                } 
     143            } 
     144 
     145            return $matches; 
     146        } 
     147 
     148        return false; 
    68149    } 
    69150