1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108:
<?php
/**
* text version of Captcha element
* Xoops Frameworks addon
*
* based on Frameworks::captcha by Taiwen Jiang (phppp or D.J.) <php_pp@hotmail.com>
*
* @copyright The XOOPS project http://www.xoops.org/
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
* @author Taiwen Jiang (phppp or D.J.) <php_pp@hotmail.com>
* @since XOOPS
*
* @category ICMS
* @package Form
* @subpackage Elements
* @author Taiwen Jiang (phppp or D.J.) <php_pp@hotmail.com>
* @version SVN: $Id: Text.php 12340 2013-09-22 04:11:09Z skenow $
*/
/**
* Creates text version of Captcha element
*
* @author modified by Sina Asghari (aka stranger) <pesian_stranger@users.sourceforge.net>
* @category ICMS
* @package Form
* @subpackage Elements
*/
class icms_form_elements_captcha_Text {
public $config = array();
public $code;
/**
* Constructor
*/
public function __construct() {
}
/**
* Creates icms_form_elements_captcha_Text object
* @return object reference to icms_form_elements_captcha_Text (@link icms_form_elements_captcha_Text) Object
*/
public function &instance() {
static $instance;
if (!isset($instance)) {
$instance = new self();
}
return $instance;
}
/**
* Loading configs from CAPTCHA class
* @param string $config the config array
*/
public function loadConfig($config = array()) {
// Loading default preferences
$this->config =& $config;
}
/**
* Sets CAPTCHA code
*/
public function setCode() {
$_SESSION['icms_form_elements_captcha_Object_sessioncode'] = strval($this->code);
}
/**
* Render the form
* @return string $form the Captcha Form
*/
public function render() {
global $icmsConfigCaptcha;
$form = $this->loadText()
. " <input type='text' name='" . $this->config["name"]
."' id='" . $this->config["name"]
. "' size='" . $icmsConfigCaptcha['captcha_num_chars']
. "' maxlength='" . $icmsConfigCaptcha['captcha_num_chars']
. "' value='' />";
$rule = constant("ICMS_CAPTCHA_RULE_TEXT");
if (!empty($rule)) {
$form .= " <small>{$rule}</small>";
}
$this->setCode();
return $form;
}
/**
* Load the ICMS Captcha Text
* @return string The Captcha Expression
*/
public function loadText() {
$val_a = rand(0, 9);
$val_b = rand(0, 9);
if ($val_a > $val_b) {
$expression = "{$val_a} - {$val_b} = ?";
$this->code = $val_a - $val_b;
} else {
$expression = "{$val_a} + {$val_b} = ?";
$this->code = $val_a + $val_b;
}
return "<span style='font-style: normal; font-weight: bold; font-size: 100%; font-color: #333; border: 1px solid #333; padding: 1px 5px;'>{$expression}</span>";
}
}