Changeset 19933

Show
Ignore:
Timestamp:
12/22/08 17:05:58 (1 year ago)
Author:
bergie
Message:

Use Mollom comment spam checker if enabled, fixes #684

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/ragnaroek/midcom/net.nehmer.comments/comment.php

    r18515 r19933  
    165165        return $qb->count_unchecked(); 
    166166    } 
     167 
     168    /** 
     169     * Check the post against possible spam filters. 
     170     * 
     171     * This will update post status on the background and log the information. 
     172     */ 
     173    function check_spam(&$config) 
     174    { 
     175        if (!$config->get('enable_mollom_check')) 
     176        { 
     177            // Mollom spam checker is not enabled, skip check 
     178            return; 
     179        } 
     180         
     181        if (!$_MIDCOM->componentloader->is_installed('be.crsolutions.mollom')) 
     182        { 
     183            debug_push_class(__CLASS__, __FUNCTION__); 
     184            debug_add('be.crsolutions.mollom spam checker is enabled but not installed, aborting check', MIDCOM_LOG_INFO); 
     185            debug_pop(); 
     186            return; 
     187        } 
     188         
     189        $_MIDCOM->load_library('be.crsolutions.mollom'); 
     190         
     191        $mollom = new be_crsolutions_mollom(); 
     192        if (!$mollom->initialize()) 
     193        { 
     194            debug_push_class(__CLASS__, __FUNCTION__); 
     195            debug_add('be.crsolutions.mollom initialization failed, aborting check', MIDCOM_LOG_INFO); 
     196            debug_pop(); 
     197            return; 
     198        } 
     199         
     200        $ret = $mollom->check_content(null, $this->title, $this->content, $this->author); 
     201        if (!isset($ret['spam'])) 
     202        { 
     203            // No need to log here, the mollom class does that. Just abort. 
     204            return; 
     205        } 
     206         
     207        if ($ret['spam'] == 'ham') 
     208        { 
     209            // Quality content 
     210            debug_push_class(__CLASS__, __FUNCTION__); 
     211            debug_add("Mollom noted comment \"{$this->title}\" ({$this->guid}) as ham with quality {$ret['quality']}", MIDCOM_LOG_DEBUG); 
     212            debug_pop(); 
     213             
     214            $this->status = NET_NEHMER_COMMENTS_MODERATED; 
     215            $this->update(); 
     216            $this->_log_moderation('reported_not_junk', 'mollom', "Quality = {$ret['quality']}"); 
     217            return; 
     218        } 
     219         
     220        if ($ret['spam'] == 'spam') 
     221        { 
     222            // Spam 
     223            debug_push_class(__CLASS__, __FUNCTION__); 
     224            debug_add("Mollom noted comment \"{$this->title}\" ({$this->guid}) as spam with quality {$ret['quality']}", MIDCOM_LOG_DEBUG); 
     225            debug_pop(); 
     226             
     227            $this->status = NET_NEHMER_COMMENTS_JUNK; 
     228            $this->update(); 
     229            $this->_log_moderation('confirmed_junk', 'mollom', "Quality = {$ret['quality']}"); 
     230            return; 
     231        } 
     232         
     233        // Otherwise we let it stay in initial status, as Mollom was unsure 
     234 
     235        debug_push_class(__CLASS__, __FUNCTION__); 
     236        debug_add("Mollom noted comment \"{$this->title}\" ({$this->guid}) as unsure with quality {$ret['quality']}", MIDCOM_LOG_DEBUG); 
     237        debug_pop(); 
    167238     
     239        return; 
     240    } 
     241 
    168242    function report_abuse() 
    169243    { 
     
    282356            if (count($log_action) == 2) 
    283357            { 
    284                 if ($log_details[0] == 'anonymous'
     358                switch ($log_details[0]
    285359                { 
    286                     $reporter = 'anonymous'; 
    287                 } 
    288                 else 
    289                 { 
    290                     $user =& $_MIDCOM->auth->get_user($log_details[0]); 
    291                     $reporter = $user->name; 
     360                    case 'anonymous': 
     361                        $reporter = 'anonymous'; 
     362                        break; 
     363                    case 'mollom': 
     364                        $reporter = 'mollom'; 
     365                        break; 
     366                    default: 
     367                        $user =& $_MIDCOM->auth->get_user($log_details[0]); 
     368                        $reporter = $user->name; 
     369                        break; 
    292370                } 
    293371 
     
    304382    } 
    305383 
    306     function _log_moderation($action = 'marked_spam') 
    307     { 
    308         if ($_MIDCOM->auth->user) 
    309         { 
    310             $reporter = $_MIDCOM->auth->user->guid; 
    311         } 
    312         else 
    313         { 
    314             $reporter = 'anonymous'; 
     384    function _log_moderation($action = 'marked_spam', $reporter = null, $extra = null) 
     385    { 
     386        if ($reporter === null) 
     387        { 
     388            if ($_MIDCOM->auth->user) 
     389            { 
     390                $reporter = $_MIDCOM->auth->user->guid; 
     391            } 
     392            else 
     393            { 
     394                $reporter = 'anonymous'; 
     395            } 
    315396        } 
    316397        $browser = str_replace(':', '_', $_SERVER['HTTP_USER_AGENT']); 
     
    329410            2 => $browser 
    330411        ); 
     412 
     413        if ($extra !== null) 
     414        { 
     415            $log_details[] = $extra; 
     416        } 
    331417         
    332418        $this->set_parameter('net.nehmer.comments:moderation_log', implode(':', $log_action), implode(':', $log_details)); 
  • branches/ragnaroek/midcom/net.nehmer.comments/config/config.inc

    r19119 r19933  
    1414// Allow anonymous posting. 
    1515'allow_anonymous' => true, 
     16 
     17'enable_mollom_check' => false, 
    1618 
    1719// Notify authors on new comments 
  • branches/ragnaroek/midcom/net.nehmer.comments/handler/view.php

    r19753 r19933  
    601601    { 
    602602        if (   ! $_MIDCOM->auth->user 
    603             && ! $_MIDCOM->auth->request_sudo()) 
     603            && ! $_MIDCOM->auth->request_sudo('net.nehmer.comments')) 
    604604        { 
    605605            $_MIDCOM->generate_error(MIDCOM_ERRCRIT, 
     
    611611        { 
    612612            case 'save': 
     613                // Check against comment spam 
     614                $this->_new_comment->check_spam($this->_config); 
     615 
    613616                $this->_cache_ratings(); 
    614617                $this->_notify_authors(); 
  • branches/ragnaroek/midcom/net.nemein.discussion/config/config.inc

    r15134 r19933  
    5959'moderators' => '', 
    6060 
     61'enable_mollom_check' => false, 
    6162'remove_unpopular_threads' => false, 
    6263 
  • branches/ragnaroek/midcom/net.nemein.discussion/handler/post.php

    r19753 r19933  
    332332        { 
    333333            case 'save': 
     334                // Check spam 
     335                $this->_post->check_spam($this->_config); 
     336                 
    334337                // Update thread accordingly 
    335338                $this->_thread->title = $this->_post->subject; 
     
    589592        { 
    590593            case 'save': 
     594                // Check spam 
     595                $this->_post->check_spam($this->_config); 
     596 
    591597                // Index the article 
    592598                $indexer =& $_MIDCOM->get_service('indexer'); 
  • branches/ragnaroek/midcom/net.nemein.discussion/helper_email_import.php

    r19753 r19933  
    235235            } 
    236236        } 
     237         
    237238        $post->set_parameter('midcom.helper.datamanager2', 'schema_name', $this->schema_name); 
    238239        debug_add("Created new post #{$post->id}",  MIDCOM_LOG_INFO); 
     
    296297            $post->update(); 
    297298        } 
     299         
     300        // Handle spam checks 
     301        $post->check_spam($this->_config); 
    298302 
    299303        // Index the post ?? 
  • branches/ragnaroek/midcom/net.nemein.discussion/midcom/interfaces.php

    r18578 r19933  
    2929 
    3030        $this->_component = 'net.nemein.discussion'; 
    31         $this->_autoload_files = Array 
     31        $this->_autoload_files = array 
    3232        ( 
    3333            'viewer.php', 
     
    3636            'post.php', 
    3737        ); 
    38         $this->_autoload_libraries = Array( 
     38        $this->_autoload_libraries = array 
     39        ( 
    3940            'midcom.helper.datamanager2', 
    4041            'de.bitfolge.feedcreator', 
  • branches/ragnaroek/midcom/net.nemein.discussion/post.php

    r18578 r19933  
    141141        return $this->subject; 
    142142    } 
     143     
     144    /** 
     145     * Check the post against possible spam filters. 
     146     * 
     147     * This will update post status on the background and log the information. 
     148     */ 
     149    function check_spam(&$config) 
     150    { 
     151        if (!$config->get('enable_mollom_check')) 
     152        { 
     153            // Mollom spam checker is not enabled, skip check 
     154            return; 
     155        } 
     156         
     157        if (!$_MIDCOM->componentloader->is_installed('be.crsolutions.mollom')) 
     158        { 
     159            debug_push_class(__CLASS__, __FUNCTION__); 
     160            debug_add('be.crsolutions.mollom spam checker is enabled but not installed, aborting check', MIDCOM_LOG_INFO); 
     161            debug_pop(); 
     162            return; 
     163        } 
     164         
     165        $_MIDCOM->load_library('be.crsolutions.mollom'); 
     166         
     167        $mollom = new be_crsolutions_mollom(); 
     168        if (!$mollom->initialize()) 
     169        { 
     170            debug_push_class(__CLASS__, __FUNCTION__); 
     171            debug_add('be.crsolutions.mollom initialization failed, aborting check', MIDCOM_LOG_INFO); 
     172            debug_pop(); 
     173            return; 
     174        } 
     175         
     176        $ret = $mollom->check_content(null, $this->subject, $this->content, $this->sendername, $this->senderurl, $this->senderemail); 
     177        if (!isset($ret['spam'])) 
     178        { 
     179            // No need to log here, the mollom class does that. Just abort. 
     180            return; 
     181        } 
     182         
     183        if ($ret['spam'] == 'ham') 
     184        { 
     185            // Quality content 
     186            debug_push_class(__CLASS__, __FUNCTION__); 
     187            debug_add("Mollom noted post \"{$this->subject}\" ({$this->guid}) as ham with quality {$ret['quality']}", MIDCOM_LOG_DEBUG); 
     188            debug_pop(); 
     189             
     190            $this->status = NET_NEMEIN_DISCUSSION_MODERATED; 
     191            $this->update(); 
     192            $this->_log_moderation('reported_not_junk', 'mollom', "Quality = {$ret['quality']}"); 
     193            return; 
     194        } 
     195         
     196        if ($ret['spam'] == 'spam') 
     197        { 
     198            // Spam 
     199            debug_push_class(__CLASS__, __FUNCTION__); 
     200            debug_add("Mollom noted post \"{$this->subject}\" ({$this->guid}) as spam with quality {$ret['quality']}", MIDCOM_LOG_DEBUG); 
     201            debug_pop(); 
     202             
     203            $this->status = NET_NEMEIN_DISCUSSION_JUNK; 
     204            $this->update(); 
     205            $this->_log_moderation('confirmed_junk', 'mollom', "Quality = {$ret['quality']}"); 
     206            return; 
     207        } 
     208         
     209        // Otherwise we let it stay in initial status, as Mollom was unsure 
     210 
     211        debug_push_class(__CLASS__, __FUNCTION__); 
     212        debug_add("Mollom noted post \"{$this->subject}\" ({$this->guid}) as unsure with quality {$ret['quality']}", MIDCOM_LOG_DEBUG); 
     213        debug_pop(); 
     214     
     215        return; 
     216    } 
    143217 
    144218    /** 
     
    258332            if (count($log_action) == 2) 
    259333            { 
    260                 if ($log_details[0] == 'anonymous'
     334                switch ($log_details[0]
    261335                { 
    262                     $reporter = 'anonymous'; 
    263                 } 
    264                 else 
    265                 { 
    266                     $user =& $_MIDCOM->auth->get_user($log_details[0]); 
    267                     $reporter = $user->name; 
     336                    case 'anonymous': 
     337                        $reporter = 'anonymous'; 
     338                        break; 
     339                    case 'mollom': 
     340                        $reporter = 'mollom'; 
     341                        break; 
     342                    default: 
     343                        $user =& $_MIDCOM->auth->get_user($log_details[0]); 
     344                        $reporter = $user->name; 
     345                        break; 
    268346                } 
    269347 
     
    280358    } 
    281359 
    282     function _log_moderation($action = 'marked_spam') 
    283     { 
    284         if ($_MIDCOM->auth->user) 
    285         { 
    286             $reporter = $_MIDCOM->auth->user->guid; 
    287         } 
    288         else 
    289         { 
    290             $reporter = 'anonymous'; 
     360    function _log_moderation($action = 'marked_spam', $reporter = null, $extra = null) 
     361    { 
     362        if ($reporter === null) 
     363        { 
     364            if ($_MIDCOM->auth->user) 
     365            { 
     366                $reporter = $_MIDCOM->auth->user->guid; 
     367            } 
     368            else 
     369            { 
     370                $reporter = 'anonymous'; 
     371            } 
    291372        } 
    292373        $browser = str_replace(':', '_', $_SERVER['HTTP_USER_AGENT']); 
     
    306387        ); 
    307388         
     389        if ($extra !== null) 
     390        { 
     391            $log_details[] = $extra; 
     392        } 
     393         
    308394        $this->set_parameter('net.nemein.discussion:moderation_log', implode(':', $log_action), implode(':', $log_details)); 
    309395    }