aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/3rdparty/htmlpurifier/HTMLPurifier/Context.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2014-02-21 15:43:14 +0100
committerNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2014-02-21 15:43:14 +0100
commitd4949327efa15b492cab1bef3fe074290a328a17 (patch)
treee89e0322bb1f1b06d663fd10fdded21bac867e5d /inc/3rdparty/htmlpurifier/HTMLPurifier/Context.php
parentc9bd17a1007bb78e5de0775efca01df0fb515031 (diff)
downloadwallabag-d4949327efa15b492cab1bef3fe074290a328a17.tar.gz
wallabag-d4949327efa15b492cab1bef3fe074290a328a17.tar.zst
wallabag-d4949327efa15b492cab1bef3fe074290a328a17.zip
[add] HTML Purifier added to clean code
Diffstat (limited to 'inc/3rdparty/htmlpurifier/HTMLPurifier/Context.php')
-rw-r--r--inc/3rdparty/htmlpurifier/HTMLPurifier/Context.php95
1 files changed, 95 insertions, 0 deletions
diff --git a/inc/3rdparty/htmlpurifier/HTMLPurifier/Context.php b/inc/3rdparty/htmlpurifier/HTMLPurifier/Context.php
new file mode 100644
index 00000000..5ad536d5
--- /dev/null
+++ b/inc/3rdparty/htmlpurifier/HTMLPurifier/Context.php
@@ -0,0 +1,95 @@
1<?php
2
3/**
4 * Registry object that contains information about the current context.
5 * @warning Is a bit buggy when variables are set to null: it thinks
6 * they don't exist! So use false instead, please.
7 * @note Since the variables Context deals with may not be objects,
8 * references are very important here! Do not remove!
9 */
10class HTMLPurifier_Context
11{
12
13 /**
14 * Private array that stores the references.
15 * @type array
16 */
17 private $_storage = array();
18
19 /**
20 * Registers a variable into the context.
21 * @param string $name String name
22 * @param mixed $ref Reference to variable to be registered
23 */
24 public function register($name, &$ref)
25 {
26 if (array_key_exists($name, $this->_storage)) {
27 trigger_error(
28 "Name $name produces collision, cannot re-register",
29 E_USER_ERROR
30 );
31 return;
32 }
33 $this->_storage[$name] =& $ref;
34 }
35
36 /**
37 * Retrieves a variable reference from the context.
38 * @param string $name String name
39 * @param bool $ignore_error Boolean whether or not to ignore error
40 * @return mixed
41 */
42 public function &get($name, $ignore_error = false)
43 {
44 if (!array_key_exists($name, $this->_storage)) {
45 if (!$ignore_error) {
46 trigger_error(
47 "Attempted to retrieve non-existent variable $name",
48 E_USER_ERROR
49 );
50 }
51 $var = null; // so we can return by reference
52 return $var;
53 }
54 return $this->_storage[$name];
55 }
56
57 /**
58 * Destroys a variable in the context.
59 * @param string $name String name
60 */
61 public function destroy($name)
62 {
63 if (!array_key_exists($name, $this->_storage)) {
64 trigger_error(
65 "Attempted to destroy non-existent variable $name",
66 E_USER_ERROR
67 );
68 return;
69 }
70 unset($this->_storage[$name]);
71 }
72
73 /**
74 * Checks whether or not the variable exists.
75 * @param string $name String name
76 * @return bool
77 */
78 public function exists($name)
79 {
80 return array_key_exists($name, $this->_storage);
81 }
82
83 /**
84 * Loads a series of variables from an associative array
85 * @param array $context_array Assoc array of variables to load
86 */
87 public function loadArray($context_array)
88 {
89 foreach ($context_array as $key => $discard) {
90 $this->register($key, $context_array[$key]);
91 }
92 }
93}
94
95// vim: et sw=4 sts=4