XOOPS  2.6.0
image.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
29 {
30 
36  public function isActive()
37  {
38  if (!extension_loaded('gd')) {
39  trigger_error('GD library is not loaded', E_USER_WARNING);
40  return false;
41  } else {
42  $required_functions = array(
43  'imagecreatetruecolor' ,
44  'imagecolorallocate' ,
45  'imagefilledrectangle' ,
46  'imagejpeg' ,
47  'imagedestroy' ,
48  'imageftbbox');
49  foreach ($required_functions as $func) {
50  if (!function_exists($func)) {
51  trigger_error('Function ' . $func . ' is not defined', E_USER_WARNING);
52  return false;
53  }
54  }
55  }
56  return true;
57  }
58 
64  public function render()
65  {
67  $js = "<script type='text/javascript'>
68  function xoops_captcha_refresh(imgId)
69  {
70  xoopsGetElementById(imgId).src = '" . $xoops_url . "/class/captcha/image/scripts/image.php?refresh='+Math.random();
71  }
72  </script>";
73  $image = $this->loadImage();
74  $image .= "<br /><a href=\"javascript: xoops_captcha_refresh('" . ($this->config['name']) . "')\">" . XoopsLocale::CLICK_TO_REFRESH_IMAGE_IF_NOT_CLEAR . "</a>";
75  $input = '<input type="text" name="' . $this->config['name'] . '" id="' . $this->config['name'] . '" size="' . $this->config['num_chars'] . '" maxlength="' . $this->config['num_chars'] . '" value="" required>';
77  $rule .= '<br />' . (empty($this->config['casesensitive']) ? XoopsLocale::CODE_IS_CASE_INSENSITIVE : XoopsLocale::CODE_IS_CASE_SENSITIVE);
78  if (!empty($this->config['maxattempts'])) {
79  $rule .= '<br />' . sprintf(XoopsLocale::F_MAXIMUM_ATTEMPTS, $this->config['maxattempts']);
80  }
81  return $js . $image . '<br /><br />' . $input . '<br />' . $rule;
82  }
83 
89  public function loadImage()
90  {
92  return '<img id="' . ($this->config["name"]) . '" src="' . $xoops_url . '/class/captcha/image/scripts/image.php" onclick=\'this.src="' . $xoops_url . '/class/captcha/image/scripts/image.php?refresh="+Math.random()' . '\' style="cursor: pointer; vertical-align: middle;" alt="" />';
93  }
94 }
if(empty($image_id)) $image
Definition: image.php:37
$xoops_url
Definition: backend.php:32
const CODE_IS_CASE_SENSITIVE
Definition: en_US.php:168
const INPUT_LETTERS_IN_THE_IMAGE
Definition: en_US.php:481
const F_MAXIMUM_ATTEMPTS
Definition: en_US.php:420
static get($name)
const CLICK_TO_REFRESH_IMAGE_IF_NOT_CLEAR
Definition: en_US.php:163
const CODE_IS_CASE_INSENSITIVE
Definition: en_US.php:167