ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
31 ilLoggerFactory::getLogger('auth')->debug('Function imageftbox is available.');
32 return true;
33 }
34 ilLoggerFactory::getLogger('auth')->debug('Function imageftbox is not available.');
35 return false;
36 }
37
44 public static function __callStatic($name, array $arguments = array())
45 {
46 if(
47 strpos($name, 'isActiveFor') === 0 ||
48 strpos($name, 'setActiveFor') === 0
49 )
50 {
51 $settings = new ilSetting('cptch');
52 $supported_contexts = self::getSupportedContexts();
53 $method_parts = explode('_', strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $name)));
54 $requested_context = strtolower($method_parts[count($method_parts) - 1]);
55 if(!isset($requested_context, self::$context_map))
56 {
57 throw new BadMethodCallException('Method ' . $name . ' called for a non existing context.');
58 }
59
60 if('set' == $method_parts[0])
61 {
62 $settings->set('activate_captcha_anonym_' . $supported_contexts[$requested_context], (int)$arguments[0]);
63 return;
64 }
65 else
66 {
67 return self::checkFreetype() && (bool)$settings->get('activate_captcha_anonym_' . $supported_contexts[$requested_context], false);
68 }
69 }
70 else
71 {
72 throw new BadMethodCallException('Call to an undefined static method ' . $name . ' in class ' . __CLASS__ . '.');
73 }
74 }
75
79 public static function getPreconditionsMessage()
80 {
84 global $lng;
85
86 $lng->loadLanguageModule('cptch');
87 return "<a target='_blank' href='http://php.net/manual/en/image.installation.php'>" . $lng->txt('cptch_freetype_support_needed') . "</a>";
88 }
89
93 private static function getSupportedContexts()
94 {
95 if(null !== self::$context_map)
96 {
97 return self::$context_map;
98 }
99
100 self::$context_map = array();
101
102 $r = new ReflectionClass(new self());
103 $constants = $r->getConstants();
104 foreach($constants as $name => $value)
105 {
106 if(strpos($name, 'CONTEXT_') === 0)
107 {
108 self::$context_map[strtolower(substr($name, strlen('CONTEXT_')))] = $value;
109 }
110 }
111
112 return self::$context_map;
113 }
114}
An exception for terminatinating execution or to throw for unit testing.
static getSupportedContexts()
static checkFreetype()
Check whether captcha support is active.
static __callStatic($name, array $arguments=array())
static getLogger($a_component_id)
Get component logger.
ILIAS Setting Class.
$r
Definition: example_031.php:79
global $lng
Definition: privfeed.php:17