ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilCaptchaUtil.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 {
13  const CONTEXT_FORUM = 'frm';
14  const CONTEXT_LOGIN = 'auth';
15  const CONTEXT_REGISTRATION = 'reg';
16  const CONTEXT_WIKI = 'wiki';
17 
21  protected static $context_map;
22 
27  public static function checkFreetype()
28  {
29  if (function_exists('imageftbbox')) {
30  ilLoggerFactory::getLogger('auth')->debug('Function imageftbox is available.');
31  return true;
32  }
33  ilLoggerFactory::getLogger('auth')->debug('Function imageftbox is not available.');
34  return false;
35  }
36 
43  public static function __callStatic($name, array $arguments = array())
44  {
45  if (
46  strpos($name, 'isActiveFor') === 0 ||
47  strpos($name, 'setActiveFor') === 0
48  ) {
49  $settings = new ilSetting('cptch');
50  $supported_contexts = self::getSupportedContexts();
51  $method_parts = explode('_', strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $name)));
52  $requested_context = strtolower($method_parts[count($method_parts) - 1]);
53  if (!isset($requested_context, self::$context_map)) {
54  throw new BadMethodCallException('Method ' . $name . ' called for a non existing context.');
55  }
56 
57  if ('set' == $method_parts[0]) {
58  $settings->set('activate_captcha_anonym_' . $supported_contexts[$requested_context], (int) $arguments[0]);
59  return;
60  } else {
61  return self::checkFreetype() && (bool) $settings->get('activate_captcha_anonym_' . $supported_contexts[$requested_context], false);
62  }
63  } else {
64  throw new BadMethodCallException('Call to an undefined static method ' . $name . ' in class ' . __CLASS__ . '.');
65  }
66  }
67 
71  public static function getPreconditionsMessage()
72  {
76  global $DIC;
77 
78  $lng = $DIC->language();
79 
80  $lng->loadLanguageModule('cptch');
81  return "<a target='_blank' href='http://php.net/manual/en/image.installation.php'>" . $lng->txt('cptch_freetype_support_needed') . "</a>";
82  }
83 
87  private static function getSupportedContexts()
88  {
89  if (null !== self::$context_map) {
90  return self::$context_map;
91  }
92 
93  self::$context_map = array();
94 
95  $r = new ReflectionClass(new self());
96  $constants = $r->getConstants();
97  foreach ($constants as $name => $value) {
98  if (strpos($name, 'CONTEXT_') === 0) {
99  self::$context_map[strtolower(substr($name, strlen('CONTEXT_')))] = $value;
100  }
101  }
102 
103  return self::$context_map;
104  }
105 }
Captcha util.
global $DIC
Definition: saml.php:7
static checkFreetype()
Check whether captcha support is active.
static __callStatic($name, array $arguments=array())
$r
Definition: example_031.php:79
$lng
static getSupportedContexts()
static getLogger($a_component_id)
Get component logger.