File Manager

Current Path : /webspace/www.babilon.be/html/modules/AkismetCheck/
Upload File :
Current File : //webspace/www.babilon.be/html/modules/AkismetCheck/AkismetCheck.module.php

<?php
# Akismet. A plugin for CMS - CMS Made Simple
# Copyright (c) 2008 by Morten Poulsen (morten@poulsen.org)
#
# CMS- CMS Made Simple is Copyright (c) Ted Kulp (wishy@users.sf.net)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


class AkismetCheck extends CMSModule 
{
  var $_comment;

  function AkismetCheck()
  {
    parent::CMSModule();
    
    $this->_comment = array();
  }

  function GetName() {
    return 'AkismetCheck';
  }

  function GetFriendlyName() {
    return $this->Lang('friendlyname');
  }

  function GetVersion() {
    return '0.2.0';
  }

  function GetHelp() {
    return $this->Lang('help');
  }

  function GetAuthor() {
    return 'Silmarillion';
  }

  function GetAuthorEmail()	{
    return 'morten@poulsen.org';
  }

  function GetChangeLog()	{
    return $this->ProcessTemplate("changelog.tpl");
  }

  function IsPluginModule() {
    return false;
  }

  function HasAdmin() {
    return true;
  }

  function GetAdminSection() {
    return 'extensions';
  }

  function GetAdminDescription() {
    return $this->Lang('moddescription');
  }

  function MinimumCMSVersion() {
    return "1.5.2";
  }

  function VisibleToAdminUser() {
    return $this->CheckPermission('Modify Site Preferences');
  }

  function UninstallPreMessage() {
    return $this->Lang('really_uninstall');
  }

  function InstallPostMessage()	{
		return $this->lang('postinstallmessage');
	}
  function UninstallPostMessage()	{
		return $this->lang('postuninstallmessage');
	}


  function HasCapability($capability,$params=array())
  {
    if( $capability == 'spamcheck' ) return true;
    return false;
  }

  function IsSpamCatcher() {
    return true;
  }

  function set_author($author)
  {
    $this->_comment['author'] = $author;
  }

  function set_title($title)
  {
    $this->_comment['title'] = $title;
  }

  function set_email($email)
  {
    $this->_comment['email'] = $email;
  }

  function set_website($website)
  {
    $this->_comment['website'] = $website;
  }

  function set_body($body)
  {
    $this->_comment['body'] = $body;
  }

  function set_permalink($permalink)
  {
    $this->_comment['permalink'] = $permalink;
  }

  function set_extra($key,$value)
  {
    $this->_comment['ex_'.$key] = $value;
  }

  function _check_array()
  {
    $comment =& $this->_comment;
    if( !isset($comment['body']) || !isset($comment['title']) ||
	!isset($comment['email']) || !isset($comment['website']) ||
	!isset($comment['permalink']) )
      {
	return false;
      }
    return true;
  }

  function &_get_array()
  {
    return $this->_comment;
  }

  function reset()
  {
    $this->_comment = array();
  }

  function _akismetBase($action,&$errors,$preciseurl = '')
  {
    include_once(dirname(__FILE__)."/akismet.class.php");

    $url=$this->GetPreference("reporturl");
    if ($preciseurl!="") $url=$preciseurl;

    $result = 'notspam';
    if( !$this->_check_array())
      {
	$errors = array($this->Lang('error_invaliddata'));
	return 'error';
      }
    
    $akismet = new Akismet($url, $this->GetPreference("akismetkey"), $this->_get_array());
    if($akismet->errorsExist()) 
      {
	$errors = $akismet->getErrors();
	$result = 'error';
      }
    else
      {
	switch($action)
	  {
	  case 'checkspam':
	    if($akismet->isSpam()) {
	      $result='spam';
	    }
	    break;
	    
	  case 'setham':
	    $akismet->submitHam();
	    $result = 'success';
	    break;
	  }
      }
    return $result;
  }

  function check_spam(&$errors,$preciseurl='')
  {
    return $this->_akismetBase('checkspam',$errors,$preciseurl);
  }

  function set_ham(&$errors,$preciseurl='')
  {
    return $this->_akismetBase('setham',$errors,$preciseurl);
  }


  function IsSpam($content=array(),$preciseurl="") {
    include_once(dirname(__FILE__)."/akismet.class.php");    
    $result=true;
    $url=$this->GetPreference("reporturl");
    if ($preciseurl!="") $url=$preciseurl;
    $akismet = new Akismet($url, $this->GetPreference("akismetkey"), $content);
    if($akismet->errorsExist()) {
      $errors="";
      foreach($akismet->getErrors() as $error) {
        $errors.=$error.="<br/>";
      }
      if ($this->GetPreference("akismetkey","notspam")) {
        $result=false;
      } else {
        $result=true;
      }      
    } else {
      if($akismet->isSpam()) {
        $result=true;
      } 
    }
    switch ($this->GetPreference("returnwhat","akismet")) {
      case "akismet" : return $result;
      case "spam" : return true;
      default : return false;
    }

  }

}
?>

File Manager Version 1.0, Coded By Lucas
Email: hehe@yahoo.com