XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
image.php
Go to the documentation of this file.
1 <?php
22 defined('XOOPS_ROOT_PATH') or die('Restricted access');
23 
25 {
26 
32  function isActive()
33  {
34  if (!extension_loaded('gd')) {
35  trigger_error('GD library is not loaded', E_USER_WARNING);
36  return false;
37  } else {
38  $required_functions = array(
39  'imagecreatetruecolor' ,
40  'imagecolorallocate' ,
41  'imagefilledrectangle' ,
42  'imagejpeg' ,
43  'imagedestroy' ,
44  'imageftbbox');
45  foreach ($required_functions as $func) {
46  if (!function_exists($func)) {
47  trigger_error('Function ' . $func . ' is not defined', E_USER_WARNING);
48  return false;
49  }
50  }
51  }
52  return true;
53  }
54 
60  function render()
61  {
62  $js = "<script type='text/javascript'>
63  function xoops_captcha_refresh(imgId)
64  {
65  xoopsGetElementById(imgId).src = '" . XOOPS_URL . "/class/captcha/image/scripts/image.php?refresh='+Math.random();
66  }
67  </script>";
68  $image = $this->loadImage();
69  $image .= "<br /><a href=\"javascript: xoops_captcha_refresh('" . ($this->config['name']) . "')\">" . _CAPTCHA_REFRESH . "</a>";
70  $input = '<input type="text" name="' . $this->config['name'] . '" id="' . $this->config['name'] . '" size="' . $this->config['num_chars'] . '" maxlength="' . $this->config['num_chars'] . '" value="" />';
71  $rule = _CAPTCHA_RULE_IMAGE;
72  $rule .= '<br />' . (empty($this->config['casesensitive']) ? _CAPTCHA_RULE_CASEINSENSITIVE : _CAPTCHA_RULE_CASESENSITIVE);
73  if (!empty($this->config['maxattempts'])) {
74  $rule .= '<br />' . sprintf(_CAPTCHA_MAXATTEMPTS, $this->config['maxattempts']);
75  }
76  return $js . $image . '<br /><br />' . $input . '<br />' . $rule;
77  }
78 
84  function loadImage()
85  {
86  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="" />';
87  }
88 }
89 
90 ?>