Вход Регистрация
Файл: upload/module/captcha/include/service/captcha.class.php
Строк: 152
<?php
/**
 * [PHPFOX_HEADER]
 */

defined('PHPFOX') or exit('NO DICE!');

/**
 * 
 * 
 * @copyright        [PHPFOX_COPYRIGHT]
 * @author          Raymond Benc
 * @package          Module_Captcha
 * @version         $Id: captcha.class.php 1496 2010-03-05 17:15:05Z Raymond_Benc $
 */
class Captcha_Service_Captcha extends Phpfox_Service 
{
    private 
$_oSession;
    
    
/**
     * Class constructor
     */    
    
public function __construct()
    {        
        
$this->_oSession Phpfox::getService('log.session');
    }
    
    public function 
checkHash($sCode null)
    {
        if (
Phpfox::getParam('captcha.recaptcha'))
        {
            require_once(
PHPFOX_DIR_LIB 'recaptcha' PHPFOX_DS 'recaptchalib.php');        
        
            if (isset(
$_POST["recaptcha_response_field"])) 
            {            
                
$oResp recaptcha_check_answer(Phpfox::getParam('captcha.recaptcha_private_key'), $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
        
                if (
$oResp->is_valid
                {            
                    return 
true;
                } 
                else 
                {               
                    return 
false;
                }            
            }    
    
            return 
false;
        }        
        
        if (
$this->_getHash(strtolower($sCode), $this->_oSession->getSessionId()) == $this->_oSession->get('captcha_hash'))
        {
            return 
true;
        }
        return 
false;
    }
    
    public function 
setHash($sCode)
    {
        
$iId $this->_oSession->getSessionId();

        
$this->database()->update(Phpfox::getT('log_session'), array('captcha_hash' => $this->_getHash($sCode$iId)), "session_hash = '" $iId "'");
    }
    
    public function 
displayCaptcha($sText)
    {
        ((
Phpfox::getParam('captcha.captcha_use_font') && function_exists('imagettftext')) ? $this->_writeFromFont($sText) : $this->_writeFromString($sText));
        
        
ob_clean();
        
        
header("X-Content-Encoded-By: phpFox " PhpFox::getVersion());
        
header("Pragma: no-cache");
        
header('Cache-Control: no-store, no-cache, must-revalidate'); 
        
header('Content-Type: image/jpeg');
        
        
imagejpeg($this->_hImg);    
        
imagedestroy($this->_hImg);        
    }    
    
    public function 
generateCode($sCharacters
       {   
        
$sPossible Phpfox::getParam('captcha.captcha_code');
          
$sCode '';
          
$i 0;
          while (
$i $sCharacters
          { 
            
$sCode .= substr($sPossiblemt_rand(0strlen($sPossible)-1), 1);
                 
$i++;
          }      
        return 
strtolower($sCode);
       }        
    
    
/**
     * If a call is made to an unknown method attempt to connect
     * it to a specific plug-in with the same name thus allowing 
     * plug-in developers the ability to extend classes.
     *
     * @param string $sMethod is the name of the method
     * @param array $aArguments is the array of arguments of being passed
     */
    
public function __call($sMethod$aArguments)
    {
        
/**
         * Check if such a plug-in exists and if it does call it.
         */
        
if ($sPlugin Phpfox_Plugin::get('captcha.service_captcha__call'))
        {
            return eval(
$sPlugin);
        }
            
        
/**
         * No method or plug-in found we must throw a error.
         */
        
Phpfox_Error::trigger('Call to undefined method ' __CLASS__ '::' $sMethod '()'E_USER_ERROR);
    }        
    
    private function 
_getHash($sCode$sSalt)
    {
        return 
md5(md5($sCode) . $sSalt);
    }
    
    private function 
_writeFromFont($sText)
    {
        
$iString strlen($sText);
        
$iWidth = (($iString 5) * 10 2);
        
$iHeight 45;
        
$iTextSize 20;
        
$sFont Phpfox::getParam('core.dir_static') . 'image/font/' Phpfox::getParam('captcha.captcha_font');
        
        if (!
file_exists($sFont))
        {
            return 
$this->_writeFromString($sText);
        }
        
        
$this->_imageCreate($iWidth$iHeight);
        
        
$nBgColor  imageColorAllocate($this->_hImg255255255);
        
$nTxtColor imageColorAllocate($this->_hImg000);        
        
        if (!(
$aBox = @imagettfbbox($iTextSize0$sFont$sText)))
        {
            return 
$this->_writeFromString($sText);
        }
        
        
//Find out the width and height of the text box
        
$iTextW $aBox[2] - $aBox[0];
        
$iTextH $aBox[5] - $aBox[3];        

        if (
function_exists('imagefilledellipse'))
        {
            
$nNoiseColor imagecolorallocate($this->_hImg207181181);
            for (
$i 0$i < ($iWidth*$iHeight) / 3$i++)
              {
                
imagefilledellipse($this->_hImgmt_rand(0$iWidth), mt_rand(0$iHeight), 11$nNoiseColor);
            }
        }

        
$iImageLineColor imagecolorallocate($this->_hImg207181181);
        for (
$i 0$i < ($iWidth*$iHeight) / 150$i++)
        {
              
imageline($this->_hImgmt_rand(0$iWidth), mt_rand(0$iHeight), mt_rand(0$iWidth), mt_rand(0$iHeight), $iImageLineColor);
        }        
              
        
// Calculate the positions
        
$positionLeft = (($iWidth $iTextW) / 2) - (20 $iString);
        
$positionTop = (($iHeight $iTextH) / 2);
        
        for (
$i 0$i $iString$i++) 
        { 
            if (!@
imagettftext($this->_hImg$iTextSize0$positionLeft30$nTxtColor$sFont$sText[$i]))
            {
                return 
$this->_writeFromString($sText);
            }
            
            
$positionLeft += 20;
        }
    }
    
    private function 
_writeFromString($sText)
    {
        
$iString strlen($sText);
        
$iWidth = (($iString 5) * 6.4 2);
        
$iHeight 40;
        
        
$this->_imageCreate($iWidth$iHeight);
        
        
$nBgColor  imageColorAllocate($this->_hImg255255255);
        
$nTxtColor imageColorAllocate($this->_hImg000);        
        
        
$positionLeft 20;
        
        for (
$i 0$i $iString$i++) 
        { 
            
imagestring($this->_hImg5$positionLeft12,  $sText[$i], $nTxtColor);
            
            
$positionLeft += 15;
        }        
    }

    private function 
_imageCreate($iWidth$iHeight)
    {
        
$this->_hImg imageCreate($iWidth$iHeight);
    }     
}

?>
Онлайн: 3
Реклама