@@ -113,7 +113,7 @@ |
||
113 | 113 | * @param int $unused1 Unused |
114 | 114 | * @param int $unused2 Unused |
115 | 115 | * |
116 | - * @return mixed |
|
116 | + * @return ElggEntity |
|
117 | 117 | */ |
118 | 118 | public function load($key, $unused1 = 0, $unused2 = null) { |
119 | 119 | $key = $this->makeMemcacheKey($key); |
@@ -5,172 +5,172 @@ |
||
5 | 5 | */ |
6 | 6 | class ElggMemcache extends \ElggSharedMemoryCache { |
7 | 7 | |
8 | - /** |
|
9 | - * TTL of saved items (default timeout after a day to prevent anything getting too stale) |
|
10 | - */ |
|
11 | - private $ttl = 86400; |
|
12 | - |
|
13 | - /** |
|
14 | - * @var \Stash\Pool |
|
15 | - */ |
|
16 | - private $stash_pool; |
|
17 | - |
|
18 | - /** |
|
19 | - * Constructor |
|
20 | - * |
|
21 | - * @param string $namespace The namespace for this cache to write to |
|
22 | - * @param \Stash\Pool $pool The cache pool to use. Default is memcache. |
|
23 | - * @param int $ttl The TTL in seconds. Default is from $CONFIG->memcache_expires. |
|
24 | - * |
|
25 | - * @throws ConfigurationException |
|
26 | - * |
|
27 | - * @see _elgg_get_memcache() Core developers should use this instead of direct construction. |
|
28 | - */ |
|
29 | - public function __construct($namespace = 'default', \Stash\Pool $pool = null, $ttl = null) { |
|
30 | - parent::__construct(); |
|
31 | - |
|
32 | - $this->setNamespace($namespace); |
|
33 | - |
|
34 | - if (!$pool) { |
|
35 | - $pool = _elgg_services()->memcacheStashPool; |
|
36 | - if (!$pool) { |
|
37 | - throw new \ConfigurationException('No memcache servers defined, please populate the $this->CONFIG->memcache_servers variable'); |
|
38 | - } |
|
39 | - } |
|
40 | - $this->stash_pool = $pool; |
|
41 | - |
|
42 | - if ($ttl === null) { |
|
43 | - $ttl = _elgg_config()->memcache_expires; |
|
44 | - } |
|
45 | - if (isset($ttl)) { |
|
46 | - $this->ttl = $ttl; |
|
47 | - } |
|
8 | + /** |
|
9 | + * TTL of saved items (default timeout after a day to prevent anything getting too stale) |
|
10 | + */ |
|
11 | + private $ttl = 86400; |
|
12 | + |
|
13 | + /** |
|
14 | + * @var \Stash\Pool |
|
15 | + */ |
|
16 | + private $stash_pool; |
|
17 | + |
|
18 | + /** |
|
19 | + * Constructor |
|
20 | + * |
|
21 | + * @param string $namespace The namespace for this cache to write to |
|
22 | + * @param \Stash\Pool $pool The cache pool to use. Default is memcache. |
|
23 | + * @param int $ttl The TTL in seconds. Default is from $CONFIG->memcache_expires. |
|
24 | + * |
|
25 | + * @throws ConfigurationException |
|
26 | + * |
|
27 | + * @see _elgg_get_memcache() Core developers should use this instead of direct construction. |
|
28 | + */ |
|
29 | + public function __construct($namespace = 'default', \Stash\Pool $pool = null, $ttl = null) { |
|
30 | + parent::__construct(); |
|
31 | + |
|
32 | + $this->setNamespace($namespace); |
|
33 | + |
|
34 | + if (!$pool) { |
|
35 | + $pool = _elgg_services()->memcacheStashPool; |
|
36 | + if (!$pool) { |
|
37 | + throw new \ConfigurationException('No memcache servers defined, please populate the $this->CONFIG->memcache_servers variable'); |
|
38 | + } |
|
39 | + } |
|
40 | + $this->stash_pool = $pool; |
|
41 | + |
|
42 | + if ($ttl === null) { |
|
43 | + $ttl = _elgg_config()->memcache_expires; |
|
44 | + } |
|
45 | + if (isset($ttl)) { |
|
46 | + $this->ttl = $ttl; |
|
47 | + } |
|
48 | 48 | |
49 | - // make sure memcache is reset |
|
50 | - _elgg_services()->events->registerHandler('cache:flush', 'system', [$this, 'clear']); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Set the default TTL. |
|
55 | - * |
|
56 | - * @param int $ttl The TTL in seconds from now. Default is no expiration. |
|
57 | - * |
|
58 | - * @return void |
|
59 | - */ |
|
60 | - public function setDefaultExpiry($ttl = 0) { |
|
61 | - $this->ttl = $ttl; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Combine a key with the namespace. |
|
66 | - * Memcache can only accept <250 char key. If the given key is too long it is shortened. |
|
67 | - * |
|
68 | - * @param string $key The key |
|
69 | - * |
|
70 | - * @return string The new key. |
|
71 | - */ |
|
72 | - private function makeMemcacheKey($key) { |
|
73 | - // using stacks grouping http://www.stashphp.com/Grouping.html#stacks |
|
74 | - // this will allowing clearing the namespace later |
|
75 | - return "/{$this->getNamespace()}/$key"; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Saves a name and value to the cache |
|
80 | - * |
|
81 | - * @param string $key Name |
|
82 | - * @param string $data Value |
|
83 | - * @param integer $ttl TTL of cache item (seconds), 0 for no expiration, null for default. |
|
84 | - * |
|
85 | - * @return bool |
|
86 | - */ |
|
87 | - public function save($key, $data, $ttl = null) { |
|
88 | - $key = $this->makeMemcacheKey($key); |
|
89 | - |
|
90 | - if ($ttl === null) { |
|
91 | - $ttl = $this->ttl; |
|
92 | - } |
|
93 | - |
|
94 | - $item = $this->stash_pool->getItem($key); |
|
95 | - |
|
96 | - $item->set($data); |
|
97 | - $item->expiresAfter($ttl); |
|
98 | - $result = $item->save(); |
|
99 | - |
|
100 | - if ($result) { |
|
101 | - _elgg_services()->logger->info("MEMCACHE: SAVE SUCCESS $key"); |
|
102 | - } else { |
|
103 | - _elgg_services()->logger->error("MEMCACHE: SAVE FAIL $key"); |
|
104 | - } |
|
105 | - |
|
106 | - return $result; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Retrieves data. |
|
111 | - * |
|
112 | - * @param string $key Name of data to retrieve |
|
113 | - * @param int $unused1 Unused |
|
114 | - * @param int $unused2 Unused |
|
115 | - * |
|
116 | - * @return mixed |
|
117 | - */ |
|
118 | - public function load($key, $unused1 = 0, $unused2 = null) { |
|
119 | - $key = $this->makeMemcacheKey($key); |
|
120 | - |
|
121 | - $item = $this->stash_pool->getItem($key); |
|
122 | - |
|
123 | - $item->setInvalidationMethod(\Stash\Invalidation::NONE); |
|
124 | - $value = $item->get(); |
|
125 | - |
|
126 | - if ($item->isMiss()) { |
|
127 | - _elgg_services()->logger->info("MEMCACHE: LOAD MISS $key"); |
|
128 | - return false; |
|
129 | - } |
|
130 | - |
|
131 | - _elgg_services()->logger->info("MEMCACHE: LOAD HIT $key"); |
|
132 | - |
|
133 | - return $value; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Delete data |
|
138 | - * |
|
139 | - * @param string $key Name of data |
|
140 | - * |
|
141 | - * @return bool |
|
142 | - */ |
|
143 | - public function delete($key) { |
|
144 | - $key = $this->makeMemcacheKey($key); |
|
145 | - return $this->stash_pool->getItem($key)->clear(); |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Clears all values in the namespace of this cache |
|
150 | - * |
|
151 | - * @return bool |
|
152 | - */ |
|
153 | - public function clear() { |
|
154 | - // using stacks grouping http://www.stashphp.com/Grouping.html#stacks |
|
155 | - // this will clear all key keys beneath it |
|
156 | - return $this->stash_pool->getItem("/{$this->getNamespace()}")->clear(); |
|
157 | - } |
|
49 | + // make sure memcache is reset |
|
50 | + _elgg_services()->events->registerHandler('cache:flush', 'system', [$this, 'clear']); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Set the default TTL. |
|
55 | + * |
|
56 | + * @param int $ttl The TTL in seconds from now. Default is no expiration. |
|
57 | + * |
|
58 | + * @return void |
|
59 | + */ |
|
60 | + public function setDefaultExpiry($ttl = 0) { |
|
61 | + $this->ttl = $ttl; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Combine a key with the namespace. |
|
66 | + * Memcache can only accept <250 char key. If the given key is too long it is shortened. |
|
67 | + * |
|
68 | + * @param string $key The key |
|
69 | + * |
|
70 | + * @return string The new key. |
|
71 | + */ |
|
72 | + private function makeMemcacheKey($key) { |
|
73 | + // using stacks grouping http://www.stashphp.com/Grouping.html#stacks |
|
74 | + // this will allowing clearing the namespace later |
|
75 | + return "/{$this->getNamespace()}/$key"; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Saves a name and value to the cache |
|
80 | + * |
|
81 | + * @param string $key Name |
|
82 | + * @param string $data Value |
|
83 | + * @param integer $ttl TTL of cache item (seconds), 0 for no expiration, null for default. |
|
84 | + * |
|
85 | + * @return bool |
|
86 | + */ |
|
87 | + public function save($key, $data, $ttl = null) { |
|
88 | + $key = $this->makeMemcacheKey($key); |
|
89 | + |
|
90 | + if ($ttl === null) { |
|
91 | + $ttl = $this->ttl; |
|
92 | + } |
|
93 | + |
|
94 | + $item = $this->stash_pool->getItem($key); |
|
95 | + |
|
96 | + $item->set($data); |
|
97 | + $item->expiresAfter($ttl); |
|
98 | + $result = $item->save(); |
|
99 | + |
|
100 | + if ($result) { |
|
101 | + _elgg_services()->logger->info("MEMCACHE: SAVE SUCCESS $key"); |
|
102 | + } else { |
|
103 | + _elgg_services()->logger->error("MEMCACHE: SAVE FAIL $key"); |
|
104 | + } |
|
105 | + |
|
106 | + return $result; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Retrieves data. |
|
111 | + * |
|
112 | + * @param string $key Name of data to retrieve |
|
113 | + * @param int $unused1 Unused |
|
114 | + * @param int $unused2 Unused |
|
115 | + * |
|
116 | + * @return mixed |
|
117 | + */ |
|
118 | + public function load($key, $unused1 = 0, $unused2 = null) { |
|
119 | + $key = $this->makeMemcacheKey($key); |
|
120 | + |
|
121 | + $item = $this->stash_pool->getItem($key); |
|
122 | + |
|
123 | + $item->setInvalidationMethod(\Stash\Invalidation::NONE); |
|
124 | + $value = $item->get(); |
|
125 | + |
|
126 | + if ($item->isMiss()) { |
|
127 | + _elgg_services()->logger->info("MEMCACHE: LOAD MISS $key"); |
|
128 | + return false; |
|
129 | + } |
|
130 | + |
|
131 | + _elgg_services()->logger->info("MEMCACHE: LOAD HIT $key"); |
|
132 | + |
|
133 | + return $value; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Delete data |
|
138 | + * |
|
139 | + * @param string $key Name of data |
|
140 | + * |
|
141 | + * @return bool |
|
142 | + */ |
|
143 | + public function delete($key) { |
|
144 | + $key = $this->makeMemcacheKey($key); |
|
145 | + return $this->stash_pool->getItem($key)->clear(); |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Clears all values in the namespace of this cache |
|
150 | + * |
|
151 | + * @return bool |
|
152 | + */ |
|
153 | + public function clear() { |
|
154 | + // using stacks grouping http://www.stashphp.com/Grouping.html#stacks |
|
155 | + // this will clear all key keys beneath it |
|
156 | + return $this->stash_pool->getItem("/{$this->getNamespace()}")->clear(); |
|
157 | + } |
|
158 | 158 | |
159 | - /** |
|
160 | - * Set the namespace of this cache. |
|
161 | - * |
|
162 | - * This will also add the Memcache namespace prefix as defined in settings.php |
|
163 | - * |
|
164 | - * @param string $namespace Namespace for cache |
|
165 | - * |
|
166 | - * @return void |
|
167 | - */ |
|
168 | - public function setNamespace($namespace = "default") { |
|
169 | - $config_prefix = _elgg_services()->config->getVolatile('memcache_namespace_prefix'); |
|
170 | - if ($config_prefix) { |
|
171 | - $namespace = $config_prefix . $namespace; |
|
172 | - } |
|
159 | + /** |
|
160 | + * Set the namespace of this cache. |
|
161 | + * |
|
162 | + * This will also add the Memcache namespace prefix as defined in settings.php |
|
163 | + * |
|
164 | + * @param string $namespace Namespace for cache |
|
165 | + * |
|
166 | + * @return void |
|
167 | + */ |
|
168 | + public function setNamespace($namespace = "default") { |
|
169 | + $config_prefix = _elgg_services()->config->getVolatile('memcache_namespace_prefix'); |
|
170 | + if ($config_prefix) { |
|
171 | + $namespace = $config_prefix . $namespace; |
|
172 | + } |
|
173 | 173 | |
174 | - parent::setNamespace($namespace); |
|
175 | - } |
|
174 | + parent::setNamespace($namespace); |
|
175 | + } |
|
176 | 176 | } |
@@ -72,389 +72,389 @@ |
||
72 | 72 | */ |
73 | 73 | class ElggBatch implements BatchResult { |
74 | 74 | |
75 | - /** |
|
76 | - * The objects to iterate over. |
|
77 | - * |
|
78 | - * @var array |
|
79 | - */ |
|
80 | - private $results = []; |
|
81 | - |
|
82 | - /** |
|
83 | - * The function used to get results. |
|
84 | - * |
|
85 | - * @var callable |
|
86 | - */ |
|
87 | - private $getter = null; |
|
88 | - |
|
89 | - /** |
|
90 | - * The given $options to alter and pass to the getter. |
|
91 | - * |
|
92 | - * @var array |
|
93 | - */ |
|
94 | - private $options = []; |
|
95 | - |
|
96 | - /** |
|
97 | - * The number of results to grab at a time. |
|
98 | - * |
|
99 | - * @var int |
|
100 | - */ |
|
101 | - private $chunkSize = 25; |
|
102 | - |
|
103 | - /** |
|
104 | - * A callback function to pass results through. |
|
105 | - * |
|
106 | - * @var callable |
|
107 | - */ |
|
108 | - private $callback = null; |
|
109 | - |
|
110 | - /** |
|
111 | - * Start after this many results. |
|
112 | - * |
|
113 | - * @var int |
|
114 | - */ |
|
115 | - private $offset = 0; |
|
116 | - |
|
117 | - /** |
|
118 | - * Stop after this many results. |
|
119 | - * |
|
120 | - * @var int |
|
121 | - */ |
|
122 | - private $limit = 0; |
|
123 | - |
|
124 | - /** |
|
125 | - * Number of processed results. |
|
126 | - * |
|
127 | - * @var int |
|
128 | - */ |
|
129 | - private $retrievedResults = 0; |
|
130 | - |
|
131 | - /** |
|
132 | - * The index of the current result within the current chunk |
|
133 | - * |
|
134 | - * @var int |
|
135 | - */ |
|
136 | - private $resultIndex = 0; |
|
137 | - |
|
138 | - /** |
|
139 | - * The index of the current chunk |
|
140 | - * |
|
141 | - * @var int |
|
142 | - */ |
|
143 | - private $chunkIndex = 0; |
|
144 | - |
|
145 | - /** |
|
146 | - * The number of results iterated through |
|
147 | - * |
|
148 | - * @var int |
|
149 | - */ |
|
150 | - private $processedResults = 0; |
|
151 | - |
|
152 | - /** |
|
153 | - * Is the getter a valid callback |
|
154 | - * |
|
155 | - * @var bool |
|
156 | - */ |
|
157 | - private $validGetter = null; |
|
158 | - |
|
159 | - /** |
|
160 | - * The result of running all entities through the callback function. |
|
161 | - * |
|
162 | - * @var mixed |
|
163 | - */ |
|
164 | - public $callbackResult = null; |
|
165 | - |
|
166 | - /** |
|
167 | - * If false, offset will not be incremented. This is used for callbacks/loops that delete. |
|
168 | - * |
|
169 | - * @var bool |
|
170 | - */ |
|
171 | - private $incrementOffset = true; |
|
172 | - |
|
173 | - /** |
|
174 | - * Entities that could not be instantiated during a fetch |
|
175 | - * |
|
176 | - * @var \stdClass[] |
|
177 | - */ |
|
178 | - private $incompleteEntities = []; |
|
179 | - |
|
180 | - /** |
|
181 | - * Total number of incomplete entities fetched |
|
182 | - * |
|
183 | - * @var int |
|
184 | - */ |
|
185 | - private $totalIncompletes = 0; |
|
186 | - |
|
187 | - /** |
|
188 | - * Batches operations on any elgg_get_*() or compatible function that supports |
|
189 | - * an options array. |
|
190 | - * |
|
191 | - * Instead of returning all objects in memory, it goes through $chunk_size |
|
192 | - * objects, then requests more from the server. This avoids OOM errors. |
|
193 | - * |
|
194 | - * @param string $getter The function used to get objects. Usually |
|
195 | - * an elgg_get_*() function, but can be any valid PHP callback. |
|
196 | - * @param array $options The options array to pass to the getter function. If limit is |
|
197 | - * not set, 10 is used as the default. In most cases that is not |
|
198 | - * what you want. |
|
199 | - * @param mixed $callback An optional callback function that all results will be passed |
|
200 | - * to upon load. The callback needs to accept $result, $getter, |
|
201 | - * $options. |
|
202 | - * @param int $chunk_size The number of entities to pull in before requesting more. |
|
203 | - * You have to balance this between running out of memory in PHP |
|
204 | - * and hitting the db server too often. |
|
205 | - * @param bool $inc_offset Increment the offset on each fetch. This must be false for |
|
206 | - * callbacks that delete rows. You can set this after the |
|
207 | - * object is created with {@link \ElggBatch::setIncrementOffset()}. |
|
208 | - */ |
|
209 | - public function __construct($getter, $options, $callback = null, $chunk_size = 25, |
|
210 | - $inc_offset = true) { |
|
75 | + /** |
|
76 | + * The objects to iterate over. |
|
77 | + * |
|
78 | + * @var array |
|
79 | + */ |
|
80 | + private $results = []; |
|
81 | + |
|
82 | + /** |
|
83 | + * The function used to get results. |
|
84 | + * |
|
85 | + * @var callable |
|
86 | + */ |
|
87 | + private $getter = null; |
|
88 | + |
|
89 | + /** |
|
90 | + * The given $options to alter and pass to the getter. |
|
91 | + * |
|
92 | + * @var array |
|
93 | + */ |
|
94 | + private $options = []; |
|
95 | + |
|
96 | + /** |
|
97 | + * The number of results to grab at a time. |
|
98 | + * |
|
99 | + * @var int |
|
100 | + */ |
|
101 | + private $chunkSize = 25; |
|
102 | + |
|
103 | + /** |
|
104 | + * A callback function to pass results through. |
|
105 | + * |
|
106 | + * @var callable |
|
107 | + */ |
|
108 | + private $callback = null; |
|
109 | + |
|
110 | + /** |
|
111 | + * Start after this many results. |
|
112 | + * |
|
113 | + * @var int |
|
114 | + */ |
|
115 | + private $offset = 0; |
|
116 | + |
|
117 | + /** |
|
118 | + * Stop after this many results. |
|
119 | + * |
|
120 | + * @var int |
|
121 | + */ |
|
122 | + private $limit = 0; |
|
123 | + |
|
124 | + /** |
|
125 | + * Number of processed results. |
|
126 | + * |
|
127 | + * @var int |
|
128 | + */ |
|
129 | + private $retrievedResults = 0; |
|
130 | + |
|
131 | + /** |
|
132 | + * The index of the current result within the current chunk |
|
133 | + * |
|
134 | + * @var int |
|
135 | + */ |
|
136 | + private $resultIndex = 0; |
|
137 | + |
|
138 | + /** |
|
139 | + * The index of the current chunk |
|
140 | + * |
|
141 | + * @var int |
|
142 | + */ |
|
143 | + private $chunkIndex = 0; |
|
144 | + |
|
145 | + /** |
|
146 | + * The number of results iterated through |
|
147 | + * |
|
148 | + * @var int |
|
149 | + */ |
|
150 | + private $processedResults = 0; |
|
151 | + |
|
152 | + /** |
|
153 | + * Is the getter a valid callback |
|
154 | + * |
|
155 | + * @var bool |
|
156 | + */ |
|
157 | + private $validGetter = null; |
|
158 | + |
|
159 | + /** |
|
160 | + * The result of running all entities through the callback function. |
|
161 | + * |
|
162 | + * @var mixed |
|
163 | + */ |
|
164 | + public $callbackResult = null; |
|
165 | + |
|
166 | + /** |
|
167 | + * If false, offset will not be incremented. This is used for callbacks/loops that delete. |
|
168 | + * |
|
169 | + * @var bool |
|
170 | + */ |
|
171 | + private $incrementOffset = true; |
|
172 | + |
|
173 | + /** |
|
174 | + * Entities that could not be instantiated during a fetch |
|
175 | + * |
|
176 | + * @var \stdClass[] |
|
177 | + */ |
|
178 | + private $incompleteEntities = []; |
|
179 | + |
|
180 | + /** |
|
181 | + * Total number of incomplete entities fetched |
|
182 | + * |
|
183 | + * @var int |
|
184 | + */ |
|
185 | + private $totalIncompletes = 0; |
|
186 | + |
|
187 | + /** |
|
188 | + * Batches operations on any elgg_get_*() or compatible function that supports |
|
189 | + * an options array. |
|
190 | + * |
|
191 | + * Instead of returning all objects in memory, it goes through $chunk_size |
|
192 | + * objects, then requests more from the server. This avoids OOM errors. |
|
193 | + * |
|
194 | + * @param string $getter The function used to get objects. Usually |
|
195 | + * an elgg_get_*() function, but can be any valid PHP callback. |
|
196 | + * @param array $options The options array to pass to the getter function. If limit is |
|
197 | + * not set, 10 is used as the default. In most cases that is not |
|
198 | + * what you want. |
|
199 | + * @param mixed $callback An optional callback function that all results will be passed |
|
200 | + * to upon load. The callback needs to accept $result, $getter, |
|
201 | + * $options. |
|
202 | + * @param int $chunk_size The number of entities to pull in before requesting more. |
|
203 | + * You have to balance this between running out of memory in PHP |
|
204 | + * and hitting the db server too often. |
|
205 | + * @param bool $inc_offset Increment the offset on each fetch. This must be false for |
|
206 | + * callbacks that delete rows. You can set this after the |
|
207 | + * object is created with {@link \ElggBatch::setIncrementOffset()}. |
|
208 | + */ |
|
209 | + public function __construct($getter, $options, $callback = null, $chunk_size = 25, |
|
210 | + $inc_offset = true) { |
|
211 | 211 | |
212 | - $this->getter = $getter; |
|
213 | - $this->options = $options; |
|
214 | - $this->callback = $callback; |
|
215 | - $this->chunkSize = $chunk_size; |
|
216 | - $this->setIncrementOffset($inc_offset); |
|
217 | - |
|
218 | - if ($this->chunkSize <= 0) { |
|
219 | - $this->chunkSize = 25; |
|
220 | - } |
|
221 | - |
|
222 | - // store these so we can compare later |
|
223 | - $this->offset = elgg_extract('offset', $options, 0); |
|
224 | - $this->limit = elgg_extract('limit', $options, _elgg_config()->default_limit); |
|
225 | - |
|
226 | - // if passed a callback, create a new \ElggBatch with the same options |
|
227 | - // and pass each to the callback. |
|
228 | - if ($callback && is_callable($callback)) { |
|
229 | - $batch = new \ElggBatch($getter, $options, null, $chunk_size, $inc_offset); |
|
230 | - |
|
231 | - $all_results = null; |
|
232 | - |
|
233 | - foreach ($batch as $result) { |
|
234 | - $result = call_user_func($callback, $result, $getter, $options); |
|
235 | - |
|
236 | - if (!isset($all_results)) { |
|
237 | - if ($result === true || $result === false || $result === null) { |
|
238 | - $all_results = $result; |
|
239 | - } else { |
|
240 | - $all_results = []; |
|
241 | - } |
|
242 | - } |
|
243 | - |
|
244 | - if (($result === true || $result === false || $result === null) && !is_array($all_results)) { |
|
245 | - $all_results = $result && $all_results; |
|
246 | - } else { |
|
247 | - $all_results[] = $result; |
|
248 | - } |
|
249 | - } |
|
250 | - |
|
251 | - $this->callbackResult = $all_results; |
|
252 | - } |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Tell the process that an entity was incomplete during a fetch |
|
257 | - * |
|
258 | - * @param \stdClass $row |
|
259 | - * |
|
260 | - * @access private |
|
261 | - */ |
|
262 | - public function reportIncompleteEntity(\stdClass $row) { |
|
263 | - $this->incompleteEntities[] = $row; |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Fetches the next chunk of results |
|
268 | - * |
|
269 | - * @return bool |
|
270 | - */ |
|
271 | - private function getNextResultsChunk() { |
|
272 | - |
|
273 | - // always reset results. |
|
274 | - $this->results = []; |
|
275 | - |
|
276 | - if (!isset($this->validGetter)) { |
|
277 | - $this->validGetter = is_callable($this->getter); |
|
278 | - } |
|
279 | - |
|
280 | - if (!$this->validGetter) { |
|
281 | - return false; |
|
282 | - } |
|
283 | - |
|
284 | - $limit = $this->chunkSize; |
|
285 | - |
|
286 | - // if someone passed limit = 0 they want everything. |
|
287 | - if ($this->limit != 0) { |
|
288 | - if ($this->retrievedResults >= $this->limit) { |
|
289 | - return false; |
|
290 | - } |
|
291 | - |
|
292 | - // if original limit < chunk size, set limit to original limit |
|
293 | - // else if the number of results we'll fetch if greater than the original limit |
|
294 | - if ($this->limit < $this->chunkSize) { |
|
295 | - $limit = $this->limit; |
|
296 | - } elseif ($this->retrievedResults + $this->chunkSize > $this->limit) { |
|
297 | - // set the limit to the number of results remaining in the original limit |
|
298 | - $limit = $this->limit - $this->retrievedResults; |
|
299 | - } |
|
300 | - } |
|
301 | - |
|
302 | - if ($this->incrementOffset) { |
|
303 | - $offset = $this->offset + $this->retrievedResults; |
|
304 | - } else { |
|
305 | - $offset = $this->offset + $this->totalIncompletes; |
|
306 | - } |
|
307 | - |
|
308 | - $current_options = [ |
|
309 | - 'limit' => $limit, |
|
310 | - 'offset' => $offset, |
|
311 | - '__ElggBatch' => $this, |
|
312 | - ]; |
|
313 | - |
|
314 | - $options = array_merge($this->options, $current_options); |
|
315 | - |
|
316 | - $this->incompleteEntities = []; |
|
317 | - $this->results = call_user_func($this->getter, $options); |
|
318 | - |
|
319 | - // batch result sets tend to be large; we don't want to cache these. |
|
320 | - _elgg_services()->db->disableQueryCache(); |
|
321 | - |
|
322 | - $num_results = count($this->results); |
|
323 | - $num_incomplete = count($this->incompleteEntities); |
|
324 | - |
|
325 | - $this->totalIncompletes += $num_incomplete; |
|
326 | - |
|
327 | - if ($this->incompleteEntities) { |
|
328 | - // pad the front of the results with nulls representing the incompletes |
|
329 | - array_splice($this->results, 0, 0, array_pad([], $num_incomplete, null)); |
|
330 | - // ...and skip past them |
|
331 | - reset($this->results); |
|
332 | - for ($i = 0; $i < $num_incomplete; $i++) { |
|
333 | - next($this->results); |
|
334 | - } |
|
335 | - } |
|
336 | - |
|
337 | - if ($this->results) { |
|
338 | - $this->chunkIndex++; |
|
339 | - |
|
340 | - // let the system know we've jumped past the nulls |
|
341 | - $this->resultIndex = $num_incomplete; |
|
342 | - |
|
343 | - $this->retrievedResults += ($num_results + $num_incomplete); |
|
344 | - if ($num_results == 0) { |
|
345 | - // This fetch was *all* incompletes! We need to fetch until we can either |
|
346 | - // offer at least one row to iterate over, or give up. |
|
347 | - return $this->getNextResultsChunk(); |
|
348 | - } |
|
349 | - _elgg_services()->db->enableQueryCache(); |
|
350 | - return true; |
|
351 | - } else { |
|
352 | - _elgg_services()->db->enableQueryCache(); |
|
353 | - return false; |
|
354 | - } |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Increment the offset from the original options array? Setting to |
|
359 | - * false is required for callbacks that delete rows. |
|
360 | - * |
|
361 | - * @param bool $increment Set to false when deleting data |
|
362 | - * @return void |
|
363 | - */ |
|
364 | - public function setIncrementOffset($increment = true) { |
|
365 | - $this->incrementOffset = (bool) $increment; |
|
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * Implements Iterator |
|
370 | - */ |
|
371 | - |
|
372 | - /** |
|
373 | - * {@inheritdoc} |
|
374 | - */ |
|
375 | - public function rewind() { |
|
376 | - $this->resultIndex = 0; |
|
377 | - $this->retrievedResults = 0; |
|
378 | - $this->processedResults = 0; |
|
379 | - |
|
380 | - // only grab results if we haven't yet or we're crossing chunks |
|
381 | - if ($this->chunkIndex == 0 || $this->limit > $this->chunkSize) { |
|
382 | - $this->chunkIndex = 0; |
|
383 | - $this->getNextResultsChunk(); |
|
384 | - } |
|
385 | - } |
|
386 | - |
|
387 | - /** |
|
388 | - * {@inheritdoc} |
|
389 | - */ |
|
390 | - public function current() { |
|
391 | - return current($this->results); |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * {@inheritdoc} |
|
396 | - */ |
|
397 | - public function key() { |
|
398 | - return $this->processedResults; |
|
399 | - } |
|
400 | - |
|
401 | - /** |
|
402 | - * {@inheritdoc} |
|
403 | - */ |
|
404 | - public function next() { |
|
405 | - // if we'll be at the end. |
|
406 | - if (($this->processedResults + 1) >= $this->limit && $this->limit > 0) { |
|
407 | - $this->results = []; |
|
408 | - return false; |
|
409 | - } |
|
410 | - |
|
411 | - // if we'll need new results. |
|
412 | - if (($this->resultIndex + 1) >= $this->chunkSize) { |
|
413 | - if (!$this->getNextResultsChunk()) { |
|
414 | - $this->results = []; |
|
415 | - return false; |
|
416 | - } |
|
417 | - |
|
418 | - $result = current($this->results); |
|
419 | - } else { |
|
420 | - // the function above resets the indexes, so only inc if not |
|
421 | - // getting new set |
|
422 | - $this->resultIndex++; |
|
423 | - $result = next($this->results); |
|
424 | - } |
|
425 | - |
|
426 | - $this->processedResults++; |
|
427 | - return $result; |
|
428 | - } |
|
429 | - |
|
430 | - /** |
|
431 | - * {@inheritdoc} |
|
432 | - */ |
|
433 | - public function valid() { |
|
434 | - if (!is_array($this->results)) { |
|
435 | - return false; |
|
436 | - } |
|
437 | - $key = key($this->results); |
|
438 | - return ($key !== null && $key !== false); |
|
439 | - } |
|
440 | - |
|
441 | - /** |
|
442 | - * Count the total results available at this moment. |
|
443 | - * |
|
444 | - * As this performs a separate query, the count returned may not match the number of results you can |
|
445 | - * fetch via iteration on a very active DB. |
|
446 | - * |
|
447 | - * @see Countable::count() |
|
448 | - * @return int |
|
449 | - */ |
|
450 | - public function count() { |
|
451 | - if (!is_callable($this->getter)) { |
|
452 | - $inspector = new \Elgg\Debug\Inspector(); |
|
453 | - throw new RuntimeException("Getter is not callable: " . $inspector->describeCallable($this->getter)); |
|
454 | - } |
|
455 | - |
|
456 | - $options = array_merge($this->options, ['count' => true]); |
|
457 | - |
|
458 | - return call_user_func($this->getter, $options); |
|
459 | - } |
|
212 | + $this->getter = $getter; |
|
213 | + $this->options = $options; |
|
214 | + $this->callback = $callback; |
|
215 | + $this->chunkSize = $chunk_size; |
|
216 | + $this->setIncrementOffset($inc_offset); |
|
217 | + |
|
218 | + if ($this->chunkSize <= 0) { |
|
219 | + $this->chunkSize = 25; |
|
220 | + } |
|
221 | + |
|
222 | + // store these so we can compare later |
|
223 | + $this->offset = elgg_extract('offset', $options, 0); |
|
224 | + $this->limit = elgg_extract('limit', $options, _elgg_config()->default_limit); |
|
225 | + |
|
226 | + // if passed a callback, create a new \ElggBatch with the same options |
|
227 | + // and pass each to the callback. |
|
228 | + if ($callback && is_callable($callback)) { |
|
229 | + $batch = new \ElggBatch($getter, $options, null, $chunk_size, $inc_offset); |
|
230 | + |
|
231 | + $all_results = null; |
|
232 | + |
|
233 | + foreach ($batch as $result) { |
|
234 | + $result = call_user_func($callback, $result, $getter, $options); |
|
235 | + |
|
236 | + if (!isset($all_results)) { |
|
237 | + if ($result === true || $result === false || $result === null) { |
|
238 | + $all_results = $result; |
|
239 | + } else { |
|
240 | + $all_results = []; |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + if (($result === true || $result === false || $result === null) && !is_array($all_results)) { |
|
245 | + $all_results = $result && $all_results; |
|
246 | + } else { |
|
247 | + $all_results[] = $result; |
|
248 | + } |
|
249 | + } |
|
250 | + |
|
251 | + $this->callbackResult = $all_results; |
|
252 | + } |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Tell the process that an entity was incomplete during a fetch |
|
257 | + * |
|
258 | + * @param \stdClass $row |
|
259 | + * |
|
260 | + * @access private |
|
261 | + */ |
|
262 | + public function reportIncompleteEntity(\stdClass $row) { |
|
263 | + $this->incompleteEntities[] = $row; |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Fetches the next chunk of results |
|
268 | + * |
|
269 | + * @return bool |
|
270 | + */ |
|
271 | + private function getNextResultsChunk() { |
|
272 | + |
|
273 | + // always reset results. |
|
274 | + $this->results = []; |
|
275 | + |
|
276 | + if (!isset($this->validGetter)) { |
|
277 | + $this->validGetter = is_callable($this->getter); |
|
278 | + } |
|
279 | + |
|
280 | + if (!$this->validGetter) { |
|
281 | + return false; |
|
282 | + } |
|
283 | + |
|
284 | + $limit = $this->chunkSize; |
|
285 | + |
|
286 | + // if someone passed limit = 0 they want everything. |
|
287 | + if ($this->limit != 0) { |
|
288 | + if ($this->retrievedResults >= $this->limit) { |
|
289 | + return false; |
|
290 | + } |
|
291 | + |
|
292 | + // if original limit < chunk size, set limit to original limit |
|
293 | + // else if the number of results we'll fetch if greater than the original limit |
|
294 | + if ($this->limit < $this->chunkSize) { |
|
295 | + $limit = $this->limit; |
|
296 | + } elseif ($this->retrievedResults + $this->chunkSize > $this->limit) { |
|
297 | + // set the limit to the number of results remaining in the original limit |
|
298 | + $limit = $this->limit - $this->retrievedResults; |
|
299 | + } |
|
300 | + } |
|
301 | + |
|
302 | + if ($this->incrementOffset) { |
|
303 | + $offset = $this->offset + $this->retrievedResults; |
|
304 | + } else { |
|
305 | + $offset = $this->offset + $this->totalIncompletes; |
|
306 | + } |
|
307 | + |
|
308 | + $current_options = [ |
|
309 | + 'limit' => $limit, |
|
310 | + 'offset' => $offset, |
|
311 | + '__ElggBatch' => $this, |
|
312 | + ]; |
|
313 | + |
|
314 | + $options = array_merge($this->options, $current_options); |
|
315 | + |
|
316 | + $this->incompleteEntities = []; |
|
317 | + $this->results = call_user_func($this->getter, $options); |
|
318 | + |
|
319 | + // batch result sets tend to be large; we don't want to cache these. |
|
320 | + _elgg_services()->db->disableQueryCache(); |
|
321 | + |
|
322 | + $num_results = count($this->results); |
|
323 | + $num_incomplete = count($this->incompleteEntities); |
|
324 | + |
|
325 | + $this->totalIncompletes += $num_incomplete; |
|
326 | + |
|
327 | + if ($this->incompleteEntities) { |
|
328 | + // pad the front of the results with nulls representing the incompletes |
|
329 | + array_splice($this->results, 0, 0, array_pad([], $num_incomplete, null)); |
|
330 | + // ...and skip past them |
|
331 | + reset($this->results); |
|
332 | + for ($i = 0; $i < $num_incomplete; $i++) { |
|
333 | + next($this->results); |
|
334 | + } |
|
335 | + } |
|
336 | + |
|
337 | + if ($this->results) { |
|
338 | + $this->chunkIndex++; |
|
339 | + |
|
340 | + // let the system know we've jumped past the nulls |
|
341 | + $this->resultIndex = $num_incomplete; |
|
342 | + |
|
343 | + $this->retrievedResults += ($num_results + $num_incomplete); |
|
344 | + if ($num_results == 0) { |
|
345 | + // This fetch was *all* incompletes! We need to fetch until we can either |
|
346 | + // offer at least one row to iterate over, or give up. |
|
347 | + return $this->getNextResultsChunk(); |
|
348 | + } |
|
349 | + _elgg_services()->db->enableQueryCache(); |
|
350 | + return true; |
|
351 | + } else { |
|
352 | + _elgg_services()->db->enableQueryCache(); |
|
353 | + return false; |
|
354 | + } |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Increment the offset from the original options array? Setting to |
|
359 | + * false is required for callbacks that delete rows. |
|
360 | + * |
|
361 | + * @param bool $increment Set to false when deleting data |
|
362 | + * @return void |
|
363 | + */ |
|
364 | + public function setIncrementOffset($increment = true) { |
|
365 | + $this->incrementOffset = (bool) $increment; |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * Implements Iterator |
|
370 | + */ |
|
371 | + |
|
372 | + /** |
|
373 | + * {@inheritdoc} |
|
374 | + */ |
|
375 | + public function rewind() { |
|
376 | + $this->resultIndex = 0; |
|
377 | + $this->retrievedResults = 0; |
|
378 | + $this->processedResults = 0; |
|
379 | + |
|
380 | + // only grab results if we haven't yet or we're crossing chunks |
|
381 | + if ($this->chunkIndex == 0 || $this->limit > $this->chunkSize) { |
|
382 | + $this->chunkIndex = 0; |
|
383 | + $this->getNextResultsChunk(); |
|
384 | + } |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * {@inheritdoc} |
|
389 | + */ |
|
390 | + public function current() { |
|
391 | + return current($this->results); |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * {@inheritdoc} |
|
396 | + */ |
|
397 | + public function key() { |
|
398 | + return $this->processedResults; |
|
399 | + } |
|
400 | + |
|
401 | + /** |
|
402 | + * {@inheritdoc} |
|
403 | + */ |
|
404 | + public function next() { |
|
405 | + // if we'll be at the end. |
|
406 | + if (($this->processedResults + 1) >= $this->limit && $this->limit > 0) { |
|
407 | + $this->results = []; |
|
408 | + return false; |
|
409 | + } |
|
410 | + |
|
411 | + // if we'll need new results. |
|
412 | + if (($this->resultIndex + 1) >= $this->chunkSize) { |
|
413 | + if (!$this->getNextResultsChunk()) { |
|
414 | + $this->results = []; |
|
415 | + return false; |
|
416 | + } |
|
417 | + |
|
418 | + $result = current($this->results); |
|
419 | + } else { |
|
420 | + // the function above resets the indexes, so only inc if not |
|
421 | + // getting new set |
|
422 | + $this->resultIndex++; |
|
423 | + $result = next($this->results); |
|
424 | + } |
|
425 | + |
|
426 | + $this->processedResults++; |
|
427 | + return $result; |
|
428 | + } |
|
429 | + |
|
430 | + /** |
|
431 | + * {@inheritdoc} |
|
432 | + */ |
|
433 | + public function valid() { |
|
434 | + if (!is_array($this->results)) { |
|
435 | + return false; |
|
436 | + } |
|
437 | + $key = key($this->results); |
|
438 | + return ($key !== null && $key !== false); |
|
439 | + } |
|
440 | + |
|
441 | + /** |
|
442 | + * Count the total results available at this moment. |
|
443 | + * |
|
444 | + * As this performs a separate query, the count returned may not match the number of results you can |
|
445 | + * fetch via iteration on a very active DB. |
|
446 | + * |
|
447 | + * @see Countable::count() |
|
448 | + * @return int |
|
449 | + */ |
|
450 | + public function count() { |
|
451 | + if (!is_callable($this->getter)) { |
|
452 | + $inspector = new \Elgg\Debug\Inspector(); |
|
453 | + throw new RuntimeException("Getter is not callable: " . $inspector->describeCallable($this->getter)); |
|
454 | + } |
|
455 | + |
|
456 | + $options = array_merge($this->options, ['count' => true]); |
|
457 | + |
|
458 | + return call_user_func($this->getter, $options); |
|
459 | + } |
|
460 | 460 | } |
@@ -11,228 +11,228 @@ |
||
11 | 11 | */ |
12 | 12 | class MetadataCache { |
13 | 13 | |
14 | - /** |
|
15 | - * The cached values (or null for known to be empty). |
|
16 | - * |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - protected $values = []; |
|
20 | - |
|
21 | - /** |
|
22 | - * @var \ElggSession |
|
23 | - */ |
|
24 | - protected $session; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var ElggSharedMemoryCache |
|
28 | - */ |
|
29 | - protected $cache; |
|
30 | - |
|
31 | - /** |
|
32 | - * Constructor |
|
33 | - * |
|
34 | - * @param ElggSharedMemoryCache $cache Cache |
|
35 | - */ |
|
36 | - public function __construct(ElggSharedMemoryCache $cache = null) { |
|
37 | - if (!$cache) { |
|
38 | - $cache = new NullCache(); |
|
39 | - } |
|
40 | - $this->cache = $cache; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Set the visible metadata for an entity in the cache |
|
45 | - * |
|
46 | - * Note this does NOT invalidate any other part of the cache. |
|
47 | - * |
|
48 | - * @param int $entity_guid The GUID of the entity |
|
49 | - * @param array $values The metadata values to cache |
|
50 | - * @return void |
|
51 | - * |
|
52 | - * @access private For testing only |
|
53 | - */ |
|
54 | - public function inject($entity_guid, array $values) { |
|
55 | - $this->values[$entity_guid] = $values; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Get the metadata for a particular name. Note, this can return an array of values. |
|
60 | - * |
|
61 | - * Warning: You should always call isLoaded() beforehand to verify that this |
|
62 | - * function's return value can be trusted. |
|
63 | - * |
|
64 | - * @see isLoaded |
|
65 | - * |
|
66 | - * @param int $entity_guid The GUID of the entity |
|
67 | - * @param string $name The metadata name |
|
68 | - * |
|
69 | - * @return array|string|int|null null = value does not exist |
|
70 | - */ |
|
71 | - public function getSingle($entity_guid, $name) { |
|
72 | - if (isset($this->values[$entity_guid]) |
|
73 | - && array_key_exists($name, $this->values[$entity_guid])) { |
|
74 | - return $this->values[$entity_guid][$name]; |
|
75 | - } else { |
|
76 | - return null; |
|
77 | - } |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Forget about all metadata for an entity. |
|
82 | - * |
|
83 | - * @param int $entity_guid The GUID of the entity |
|
84 | - * @return void |
|
85 | - */ |
|
86 | - public function clear($entity_guid) { |
|
87 | - unset($this->values[$entity_guid]); |
|
88 | - $this->cache->delete($entity_guid); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * If true, getSingle() will return an accurate values from the DB |
|
93 | - * |
|
94 | - * @param int $entity_guid The GUID of the entity |
|
95 | - * @return bool |
|
96 | - */ |
|
97 | - public function isLoaded($entity_guid) { |
|
98 | - return array_key_exists($entity_guid, $this->values); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Clear entire cache |
|
103 | - * |
|
104 | - * @return void |
|
105 | - */ |
|
106 | - public function clearAll() { |
|
107 | - foreach (array_keys($this->values) as $guid) { |
|
108 | - $this->cache->delete($guid); |
|
109 | - } |
|
110 | - $this->values = []; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Invalidate based on options passed to the global *_metadata functions |
|
115 | - * |
|
116 | - * @param array $options Options passed to elgg_(delete|disable|enable)_metadata |
|
117 | - * "guid" if given, invalidation will be limited to this entity |
|
118 | - * @return void |
|
119 | - */ |
|
120 | - public function invalidateByOptions(array $options) { |
|
121 | - if (empty($options['guid'])) { |
|
122 | - $this->clearAll(); |
|
123 | - } else { |
|
124 | - $this->clear($options['guid']); |
|
125 | - } |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Populate the cache from a set of entities |
|
130 | - * |
|
131 | - * @param int|array $guids Array of or single GUIDs |
|
132 | - * @return void |
|
133 | - */ |
|
134 | - public function populateFromEntities($guids) { |
|
135 | - if (empty($guids)) { |
|
136 | - return; |
|
137 | - } |
|
14 | + /** |
|
15 | + * The cached values (or null for known to be empty). |
|
16 | + * |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + protected $values = []; |
|
20 | + |
|
21 | + /** |
|
22 | + * @var \ElggSession |
|
23 | + */ |
|
24 | + protected $session; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var ElggSharedMemoryCache |
|
28 | + */ |
|
29 | + protected $cache; |
|
30 | + |
|
31 | + /** |
|
32 | + * Constructor |
|
33 | + * |
|
34 | + * @param ElggSharedMemoryCache $cache Cache |
|
35 | + */ |
|
36 | + public function __construct(ElggSharedMemoryCache $cache = null) { |
|
37 | + if (!$cache) { |
|
38 | + $cache = new NullCache(); |
|
39 | + } |
|
40 | + $this->cache = $cache; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Set the visible metadata for an entity in the cache |
|
45 | + * |
|
46 | + * Note this does NOT invalidate any other part of the cache. |
|
47 | + * |
|
48 | + * @param int $entity_guid The GUID of the entity |
|
49 | + * @param array $values The metadata values to cache |
|
50 | + * @return void |
|
51 | + * |
|
52 | + * @access private For testing only |
|
53 | + */ |
|
54 | + public function inject($entity_guid, array $values) { |
|
55 | + $this->values[$entity_guid] = $values; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Get the metadata for a particular name. Note, this can return an array of values. |
|
60 | + * |
|
61 | + * Warning: You should always call isLoaded() beforehand to verify that this |
|
62 | + * function's return value can be trusted. |
|
63 | + * |
|
64 | + * @see isLoaded |
|
65 | + * |
|
66 | + * @param int $entity_guid The GUID of the entity |
|
67 | + * @param string $name The metadata name |
|
68 | + * |
|
69 | + * @return array|string|int|null null = value does not exist |
|
70 | + */ |
|
71 | + public function getSingle($entity_guid, $name) { |
|
72 | + if (isset($this->values[$entity_guid]) |
|
73 | + && array_key_exists($name, $this->values[$entity_guid])) { |
|
74 | + return $this->values[$entity_guid][$name]; |
|
75 | + } else { |
|
76 | + return null; |
|
77 | + } |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Forget about all metadata for an entity. |
|
82 | + * |
|
83 | + * @param int $entity_guid The GUID of the entity |
|
84 | + * @return void |
|
85 | + */ |
|
86 | + public function clear($entity_guid) { |
|
87 | + unset($this->values[$entity_guid]); |
|
88 | + $this->cache->delete($entity_guid); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * If true, getSingle() will return an accurate values from the DB |
|
93 | + * |
|
94 | + * @param int $entity_guid The GUID of the entity |
|
95 | + * @return bool |
|
96 | + */ |
|
97 | + public function isLoaded($entity_guid) { |
|
98 | + return array_key_exists($entity_guid, $this->values); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Clear entire cache |
|
103 | + * |
|
104 | + * @return void |
|
105 | + */ |
|
106 | + public function clearAll() { |
|
107 | + foreach (array_keys($this->values) as $guid) { |
|
108 | + $this->cache->delete($guid); |
|
109 | + } |
|
110 | + $this->values = []; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Invalidate based on options passed to the global *_metadata functions |
|
115 | + * |
|
116 | + * @param array $options Options passed to elgg_(delete|disable|enable)_metadata |
|
117 | + * "guid" if given, invalidation will be limited to this entity |
|
118 | + * @return void |
|
119 | + */ |
|
120 | + public function invalidateByOptions(array $options) { |
|
121 | + if (empty($options['guid'])) { |
|
122 | + $this->clearAll(); |
|
123 | + } else { |
|
124 | + $this->clear($options['guid']); |
|
125 | + } |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Populate the cache from a set of entities |
|
130 | + * |
|
131 | + * @param int|array $guids Array of or single GUIDs |
|
132 | + * @return void |
|
133 | + */ |
|
134 | + public function populateFromEntities($guids) { |
|
135 | + if (empty($guids)) { |
|
136 | + return; |
|
137 | + } |
|
138 | 138 | |
139 | - $version = (int) _elgg_config()->version; |
|
140 | - if (!empty($version) && ($version < 2016110900)) { |
|
141 | - // can't use this during upgrade from 2.x to 3.0 |
|
142 | - return; |
|
143 | - } |
|
144 | - |
|
145 | - if (!is_array($guids)) { |
|
146 | - $guids = [$guids]; |
|
147 | - } |
|
148 | - $guids = array_unique($guids); |
|
149 | - |
|
150 | - foreach ($guids as $i => $guid) { |
|
151 | - $value = $this->cache->load($guid); |
|
152 | - if ($value !== false) { |
|
153 | - $this->values[$guid] = unserialize($value); |
|
154 | - unset($guids[$i]); |
|
155 | - } |
|
156 | - } |
|
157 | - if (empty($guids)) { |
|
158 | - return; |
|
159 | - } |
|
160 | - |
|
161 | - // could be useful at some point in future |
|
162 | - //$guids = $this->filterMetadataHeavyEntities($guids); |
|
163 | - |
|
164 | - $options = [ |
|
165 | - 'guids' => $guids, |
|
166 | - 'limit' => 0, |
|
167 | - 'callback' => false, |
|
168 | - 'distinct' => false, |
|
169 | - 'order_by' => 'n_table.entity_guid, n_table.time_created ASC, n_table.id ASC', |
|
170 | - ]; |
|
171 | - $data = _elgg_services()->metadataTable->getAll($options); |
|
172 | - |
|
173 | - // make sure we show all entities as loaded |
|
174 | - foreach ($guids as $guid) { |
|
175 | - $this->values[$guid] = null; |
|
176 | - } |
|
177 | - |
|
178 | - // build up metadata for each entity, save when GUID changes (or data ends) |
|
179 | - $last_guid = null; |
|
180 | - $metadata = []; |
|
181 | - $last_row_idx = count($data) - 1; |
|
182 | - foreach ($data as $i => $row) { |
|
183 | - $name = $row->name; |
|
184 | - $value = ($row->value_type === 'text') ? $row->value : (int) $row->value; |
|
185 | - $guid = $row->entity_guid; |
|
186 | - if ($guid !== $last_guid) { |
|
187 | - if ($last_guid) { |
|
188 | - $this->values[$last_guid] = $metadata; |
|
189 | - } |
|
190 | - $metadata = []; |
|
191 | - } |
|
192 | - if (isset($metadata[$name])) { |
|
193 | - $metadata[$name] = (array) $metadata[$name]; |
|
194 | - $metadata[$name][] = $value; |
|
195 | - } else { |
|
196 | - $metadata[$name] = $value; |
|
197 | - } |
|
198 | - if (($i == $last_row_idx)) { |
|
199 | - $this->values[$guid] = $metadata; |
|
200 | - } |
|
201 | - $last_guid = $guid; |
|
202 | - } |
|
203 | - |
|
204 | - foreach ($guids as $guid) { |
|
205 | - $this->cache->save($guid, serialize($this->values[$guid])); |
|
206 | - } |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Filter out entities whose concatenated metadata values (INTs casted as string) |
|
211 | - * exceed a threshold in characters. This could be used to avoid overpopulating the |
|
212 | - * cache if RAM usage becomes an issue. |
|
213 | - * |
|
214 | - * @param array $guids GUIDs of entities to examine |
|
215 | - * @param int $limit Limit in characters of all metadata (with ints casted to strings) |
|
216 | - * @return array |
|
217 | - */ |
|
218 | - public function filterMetadataHeavyEntities(array $guids, $limit = 1024000) { |
|
219 | - $db_prefix = _elgg_config()->dbprefix; |
|
220 | - |
|
221 | - $options = [ |
|
222 | - 'guids' => $guids, |
|
223 | - 'limit' => 0, |
|
224 | - 'callback' => false, |
|
225 | - 'selects' => ['SUM(LENGTH(n_table.value)) AS bytes'], |
|
226 | - 'order_by' => 'n_table.entity_guid, n_table.time_created ASC', |
|
227 | - 'group_by' => 'n_table.entity_guid', |
|
228 | - ]; |
|
229 | - $data = _elgg_services()->metadataTable->getAll($options); |
|
230 | - // don't cache if metadata for entity is over 10MB (or rolled INT) |
|
231 | - foreach ($data as $row) { |
|
232 | - if ($row->bytes > $limit || $row->bytes < 0) { |
|
233 | - array_splice($guids, array_search($row->entity_guid, $guids), 1); |
|
234 | - } |
|
235 | - } |
|
236 | - return $guids; |
|
237 | - } |
|
139 | + $version = (int) _elgg_config()->version; |
|
140 | + if (!empty($version) && ($version < 2016110900)) { |
|
141 | + // can't use this during upgrade from 2.x to 3.0 |
|
142 | + return; |
|
143 | + } |
|
144 | + |
|
145 | + if (!is_array($guids)) { |
|
146 | + $guids = [$guids]; |
|
147 | + } |
|
148 | + $guids = array_unique($guids); |
|
149 | + |
|
150 | + foreach ($guids as $i => $guid) { |
|
151 | + $value = $this->cache->load($guid); |
|
152 | + if ($value !== false) { |
|
153 | + $this->values[$guid] = unserialize($value); |
|
154 | + unset($guids[$i]); |
|
155 | + } |
|
156 | + } |
|
157 | + if (empty($guids)) { |
|
158 | + return; |
|
159 | + } |
|
160 | + |
|
161 | + // could be useful at some point in future |
|
162 | + //$guids = $this->filterMetadataHeavyEntities($guids); |
|
163 | + |
|
164 | + $options = [ |
|
165 | + 'guids' => $guids, |
|
166 | + 'limit' => 0, |
|
167 | + 'callback' => false, |
|
168 | + 'distinct' => false, |
|
169 | + 'order_by' => 'n_table.entity_guid, n_table.time_created ASC, n_table.id ASC', |
|
170 | + ]; |
|
171 | + $data = _elgg_services()->metadataTable->getAll($options); |
|
172 | + |
|
173 | + // make sure we show all entities as loaded |
|
174 | + foreach ($guids as $guid) { |
|
175 | + $this->values[$guid] = null; |
|
176 | + } |
|
177 | + |
|
178 | + // build up metadata for each entity, save when GUID changes (or data ends) |
|
179 | + $last_guid = null; |
|
180 | + $metadata = []; |
|
181 | + $last_row_idx = count($data) - 1; |
|
182 | + foreach ($data as $i => $row) { |
|
183 | + $name = $row->name; |
|
184 | + $value = ($row->value_type === 'text') ? $row->value : (int) $row->value; |
|
185 | + $guid = $row->entity_guid; |
|
186 | + if ($guid !== $last_guid) { |
|
187 | + if ($last_guid) { |
|
188 | + $this->values[$last_guid] = $metadata; |
|
189 | + } |
|
190 | + $metadata = []; |
|
191 | + } |
|
192 | + if (isset($metadata[$name])) { |
|
193 | + $metadata[$name] = (array) $metadata[$name]; |
|
194 | + $metadata[$name][] = $value; |
|
195 | + } else { |
|
196 | + $metadata[$name] = $value; |
|
197 | + } |
|
198 | + if (($i == $last_row_idx)) { |
|
199 | + $this->values[$guid] = $metadata; |
|
200 | + } |
|
201 | + $last_guid = $guid; |
|
202 | + } |
|
203 | + |
|
204 | + foreach ($guids as $guid) { |
|
205 | + $this->cache->save($guid, serialize($this->values[$guid])); |
|
206 | + } |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Filter out entities whose concatenated metadata values (INTs casted as string) |
|
211 | + * exceed a threshold in characters. This could be used to avoid overpopulating the |
|
212 | + * cache if RAM usage becomes an issue. |
|
213 | + * |
|
214 | + * @param array $guids GUIDs of entities to examine |
|
215 | + * @param int $limit Limit in characters of all metadata (with ints casted to strings) |
|
216 | + * @return array |
|
217 | + */ |
|
218 | + public function filterMetadataHeavyEntities(array $guids, $limit = 1024000) { |
|
219 | + $db_prefix = _elgg_config()->dbprefix; |
|
220 | + |
|
221 | + $options = [ |
|
222 | + 'guids' => $guids, |
|
223 | + 'limit' => 0, |
|
224 | + 'callback' => false, |
|
225 | + 'selects' => ['SUM(LENGTH(n_table.value)) AS bytes'], |
|
226 | + 'order_by' => 'n_table.entity_guid, n_table.time_created ASC', |
|
227 | + 'group_by' => 'n_table.entity_guid', |
|
228 | + ]; |
|
229 | + $data = _elgg_services()->metadataTable->getAll($options); |
|
230 | + // don't cache if metadata for entity is over 10MB (or rolled INT) |
|
231 | + foreach ($data as $row) { |
|
232 | + if ($row->bytes > $limit || $row->bytes < 0) { |
|
233 | + array_splice($guids, array_search($row->entity_guid, $guids), 1); |
|
234 | + } |
|
235 | + } |
|
236 | + return $guids; |
|
237 | + } |
|
238 | 238 | } |
@@ -71,7 +71,7 @@ |
||
71 | 71 | /** @var Result $result */ |
72 | 72 | $result = null; |
73 | 73 | |
74 | - $condition = function () use (&$count, &$processed, &$result, $started) { |
|
74 | + $condition = function() use (&$count, &$processed, &$result, $started) { |
|
75 | 75 | if ((microtime(true) - $started) >= $this->config->batch_run_time_in_secs) { |
76 | 76 | return false; |
77 | 77 | } |
@@ -17,132 +17,132 @@ |
||
17 | 17 | */ |
18 | 18 | class BatchUpgrader { |
19 | 19 | |
20 | - /** |
|
21 | - * @var $config Config |
|
22 | - */ |
|
23 | - private $config; |
|
24 | - |
|
25 | - /** |
|
26 | - * Constructor |
|
27 | - * |
|
28 | - * @param Config $config Site configuration |
|
29 | - */ |
|
30 | - public function __construct(Config $config) { |
|
31 | - $this->config = $config; |
|
32 | - |
|
33 | - // Custom limit can be defined in settings.php if necessary |
|
34 | - if (empty($this->config->batch_run_time_in_secs)) { |
|
35 | - $this->config->batch_run_time_in_secs = 4; |
|
36 | - } |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Call the upgrade's run() for a short period of time, or until it completes |
|
41 | - * |
|
42 | - * @param ElggUpgrade $upgrade Upgrade to run |
|
43 | - * @return array |
|
44 | - * @throws \RuntimeException |
|
45 | - */ |
|
46 | - public function run(ElggUpgrade $upgrade) { |
|
47 | - // Upgrade also disabled data, so the compatibility is |
|
48 | - // preserved in case the data ever gets enabled again |
|
49 | - $ha = access_get_show_hidden_status(); |
|
50 | - access_show_hidden_entities(true); |
|
51 | - |
|
52 | - $started = microtime(true); |
|
53 | - |
|
54 | - // Get the class taking care of the actual upgrading |
|
55 | - $batch = $upgrade->getBatch(); |
|
20 | + /** |
|
21 | + * @var $config Config |
|
22 | + */ |
|
23 | + private $config; |
|
24 | + |
|
25 | + /** |
|
26 | + * Constructor |
|
27 | + * |
|
28 | + * @param Config $config Site configuration |
|
29 | + */ |
|
30 | + public function __construct(Config $config) { |
|
31 | + $this->config = $config; |
|
32 | + |
|
33 | + // Custom limit can be defined in settings.php if necessary |
|
34 | + if (empty($this->config->batch_run_time_in_secs)) { |
|
35 | + $this->config->batch_run_time_in_secs = 4; |
|
36 | + } |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Call the upgrade's run() for a short period of time, or until it completes |
|
41 | + * |
|
42 | + * @param ElggUpgrade $upgrade Upgrade to run |
|
43 | + * @return array |
|
44 | + * @throws \RuntimeException |
|
45 | + */ |
|
46 | + public function run(ElggUpgrade $upgrade) { |
|
47 | + // Upgrade also disabled data, so the compatibility is |
|
48 | + // preserved in case the data ever gets enabled again |
|
49 | + $ha = access_get_show_hidden_status(); |
|
50 | + access_show_hidden_entities(true); |
|
51 | + |
|
52 | + $started = microtime(true); |
|
53 | + |
|
54 | + // Get the class taking care of the actual upgrading |
|
55 | + $batch = $upgrade->getBatch(); |
|
56 | 56 | |
57 | - if (!$batch) { |
|
58 | - throw new \RuntimeException(elgg_echo('admin:upgrades:error:invalid_batch', [$upgrade->title, $upgrade->guid])); |
|
59 | - } |
|
57 | + if (!$batch) { |
|
58 | + throw new \RuntimeException(elgg_echo('admin:upgrades:error:invalid_batch', [$upgrade->title, $upgrade->guid])); |
|
59 | + } |
|
60 | 60 | |
61 | - $count = $batch->countItems(); |
|
61 | + $count = $batch->countItems(); |
|
62 | 62 | |
63 | - $batch_failure_count = 0; |
|
64 | - $batch_success_count = 0; |
|
65 | - $errors = []; |
|
66 | - |
|
67 | - $processed = (int) $upgrade->processed; |
|
68 | - $offset = (int) $upgrade->offset; |
|
69 | - $has_errors = (bool) $upgrade->has_errors; |
|
70 | - |
|
71 | - /** @var Result $result */ |
|
72 | - $result = null; |
|
73 | - |
|
74 | - $condition = function () use (&$count, &$processed, &$result, $started) { |
|
75 | - if ((microtime(true) - $started) >= $this->config->batch_run_time_in_secs) { |
|
76 | - return false; |
|
77 | - } |
|
78 | - if ($result && $result->wasMarkedComplete()) { |
|
79 | - return false; |
|
80 | - } |
|
81 | - |
|
82 | - return ($count === Batch::UNKNOWN_COUNT || ($count > $processed)); |
|
83 | - }; |
|
63 | + $batch_failure_count = 0; |
|
64 | + $batch_success_count = 0; |
|
65 | + $errors = []; |
|
66 | + |
|
67 | + $processed = (int) $upgrade->processed; |
|
68 | + $offset = (int) $upgrade->offset; |
|
69 | + $has_errors = (bool) $upgrade->has_errors; |
|
70 | + |
|
71 | + /** @var Result $result */ |
|
72 | + $result = null; |
|
73 | + |
|
74 | + $condition = function () use (&$count, &$processed, &$result, $started) { |
|
75 | + if ((microtime(true) - $started) >= $this->config->batch_run_time_in_secs) { |
|
76 | + return false; |
|
77 | + } |
|
78 | + if ($result && $result->wasMarkedComplete()) { |
|
79 | + return false; |
|
80 | + } |
|
81 | + |
|
82 | + return ($count === Batch::UNKNOWN_COUNT || ($count > $processed)); |
|
83 | + }; |
|
84 | 84 | |
85 | - while ($condition()) { |
|
86 | - $result = $batch->run(new Result(), $offset); |
|
85 | + while ($condition()) { |
|
86 | + $result = $batch->run(new Result(), $offset); |
|
87 | 87 | |
88 | - $failure_count = $result->getFailureCount(); |
|
89 | - $success_count = $result->getSuccessCount(); |
|
88 | + $failure_count = $result->getFailureCount(); |
|
89 | + $success_count = $result->getSuccessCount(); |
|
90 | 90 | |
91 | - $batch_failure_count += $failure_count; |
|
92 | - $batch_success_count += $success_count; |
|
91 | + $batch_failure_count += $failure_count; |
|
92 | + $batch_success_count += $success_count; |
|
93 | 93 | |
94 | - $total = $failure_count + $success_count; |
|
94 | + $total = $failure_count + $success_count; |
|
95 | 95 | |
96 | - if ($batch->needsIncrementOffset()) { |
|
97 | - // Offset needs to incremented by the total amount of processed |
|
98 | - // items so the upgrade we won't get stuck upgrading the same |
|
99 | - // items over and over. |
|
100 | - $offset += $total; |
|
101 | - } else { |
|
102 | - // Offset doesn't need to be incremented, so we mark only |
|
103 | - // the items that caused a failure. |
|
104 | - $offset += $failure_count; |
|
105 | - } |
|
106 | - |
|
107 | - if ($failure_count > 0) { |
|
108 | - $has_errors = true; |
|
109 | - } |
|
110 | - |
|
111 | - $processed += $total; |
|
112 | - |
|
113 | - $errors = array_merge($errors, $result->getErrors()); |
|
114 | - } |
|
115 | - |
|
116 | - access_show_hidden_entities($ha); |
|
117 | - |
|
118 | - $upgrade->processed = $processed; |
|
119 | - $upgrade->offset = $offset; |
|
120 | - $upgrade->has_errors = $has_errors; |
|
96 | + if ($batch->needsIncrementOffset()) { |
|
97 | + // Offset needs to incremented by the total amount of processed |
|
98 | + // items so the upgrade we won't get stuck upgrading the same |
|
99 | + // items over and over. |
|
100 | + $offset += $total; |
|
101 | + } else { |
|
102 | + // Offset doesn't need to be incremented, so we mark only |
|
103 | + // the items that caused a failure. |
|
104 | + $offset += $failure_count; |
|
105 | + } |
|
106 | + |
|
107 | + if ($failure_count > 0) { |
|
108 | + $has_errors = true; |
|
109 | + } |
|
110 | + |
|
111 | + $processed += $total; |
|
112 | + |
|
113 | + $errors = array_merge($errors, $result->getErrors()); |
|
114 | + } |
|
115 | + |
|
116 | + access_show_hidden_entities($ha); |
|
117 | + |
|
118 | + $upgrade->processed = $processed; |
|
119 | + $upgrade->offset = $offset; |
|
120 | + $upgrade->has_errors = $has_errors; |
|
121 | 121 | |
122 | - $completed = ($result && $result->wasMarkedComplete()) || ($processed >= $count); |
|
123 | - if ($completed) { |
|
124 | - // Upgrade is finished |
|
125 | - if ($has_errors) { |
|
126 | - // The upgrade was finished with errors. Reset offset |
|
127 | - // and errors so the upgrade can start from a scratch |
|
128 | - // if attempted to run again. |
|
129 | - $upgrade->processed = 0; |
|
130 | - $upgrade->offset = 0; |
|
131 | - $upgrade->has_errors = false; |
|
132 | - } else { |
|
133 | - // Everything has been processed without errors |
|
134 | - // so the upgrade can be marked as completed. |
|
135 | - $upgrade->setCompleted(); |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - // Give feedback to the user interface about the current batch. |
|
140 | - return [ |
|
141 | - 'errors' => $errors, |
|
142 | - 'numErrors' => $batch_failure_count, |
|
143 | - 'numSuccess' => $batch_success_count, |
|
144 | - 'isComplete' => $result && $result->wasMarkedComplete(), |
|
145 | - ]; |
|
146 | - } |
|
122 | + $completed = ($result && $result->wasMarkedComplete()) || ($processed >= $count); |
|
123 | + if ($completed) { |
|
124 | + // Upgrade is finished |
|
125 | + if ($has_errors) { |
|
126 | + // The upgrade was finished with errors. Reset offset |
|
127 | + // and errors so the upgrade can start from a scratch |
|
128 | + // if attempted to run again. |
|
129 | + $upgrade->processed = 0; |
|
130 | + $upgrade->offset = 0; |
|
131 | + $upgrade->has_errors = false; |
|
132 | + } else { |
|
133 | + // Everything has been processed without errors |
|
134 | + // so the upgrade can be marked as completed. |
|
135 | + $upgrade->setCompleted(); |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + // Give feedback to the user interface about the current batch. |
|
140 | + return [ |
|
141 | + 'errors' => $errors, |
|
142 | + 'numErrors' => $batch_failure_count, |
|
143 | + 'numSuccess' => $batch_success_count, |
|
144 | + 'isComplete' => $result && $result->wasMarkedComplete(), |
|
145 | + ]; |
|
146 | + } |
|
147 | 147 | |
148 | 148 | } |
@@ -21,518 +21,518 @@ discard block |
||
21 | 21 | */ |
22 | 22 | class UsersTable { |
23 | 23 | |
24 | - use \Elgg\TimeUsing; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var Conf |
|
28 | - */ |
|
29 | - protected $config; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var Database |
|
33 | - */ |
|
34 | - protected $db; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var EntityTable |
|
38 | - */ |
|
39 | - protected $entities; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var EntityCache |
|
43 | - */ |
|
44 | - protected $entity_cache; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var EventsService |
|
48 | - */ |
|
49 | - protected $events; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - protected $table; |
|
55 | - |
|
56 | - /** |
|
57 | - * Constructor |
|
58 | - * |
|
59 | - * @param Conf $config Config |
|
60 | - * @param Database $db Database |
|
61 | - * @param EntityTable $entities Entity table |
|
62 | - * @param EntityCache $cache Entity cache |
|
63 | - * @param EventsService $events Event service |
|
64 | - */ |
|
65 | - public function __construct( |
|
66 | - Conf $config, Database $db, EntityTable $entities, EntityCache $cache, EventsService $events |
|
67 | - ) { |
|
68 | - $this->config = $config; |
|
69 | - $this->db = $db; |
|
70 | - $this->table = $this->db->prefix . "users_entity"; |
|
71 | - $this->entities = $entities; |
|
72 | - $this->entity_cache = $cache; |
|
73 | - $this->events = $events; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Return the user specific details of a user by a row. |
|
78 | - * |
|
79 | - * @param int $guid The \ElggUser guid |
|
80 | - * |
|
81 | - * @return mixed |
|
82 | - * @access private |
|
83 | - */ |
|
84 | - public function getRow($guid) { |
|
85 | - $sql = " |
|
24 | + use \Elgg\TimeUsing; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var Conf |
|
28 | + */ |
|
29 | + protected $config; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var Database |
|
33 | + */ |
|
34 | + protected $db; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var EntityTable |
|
38 | + */ |
|
39 | + protected $entities; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var EntityCache |
|
43 | + */ |
|
44 | + protected $entity_cache; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var EventsService |
|
48 | + */ |
|
49 | + protected $events; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + protected $table; |
|
55 | + |
|
56 | + /** |
|
57 | + * Constructor |
|
58 | + * |
|
59 | + * @param Conf $config Config |
|
60 | + * @param Database $db Database |
|
61 | + * @param EntityTable $entities Entity table |
|
62 | + * @param EntityCache $cache Entity cache |
|
63 | + * @param EventsService $events Event service |
|
64 | + */ |
|
65 | + public function __construct( |
|
66 | + Conf $config, Database $db, EntityTable $entities, EntityCache $cache, EventsService $events |
|
67 | + ) { |
|
68 | + $this->config = $config; |
|
69 | + $this->db = $db; |
|
70 | + $this->table = $this->db->prefix . "users_entity"; |
|
71 | + $this->entities = $entities; |
|
72 | + $this->entity_cache = $cache; |
|
73 | + $this->events = $events; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Return the user specific details of a user by a row. |
|
78 | + * |
|
79 | + * @param int $guid The \ElggUser guid |
|
80 | + * |
|
81 | + * @return mixed |
|
82 | + * @access private |
|
83 | + */ |
|
84 | + public function getRow($guid) { |
|
85 | + $sql = " |
|
86 | 86 | SELECT * FROM {$this->table} |
87 | 87 | WHERE guid = :guid |
88 | 88 | "; |
89 | - $params = [ |
|
90 | - ':guid' => $guid, |
|
91 | - ]; |
|
92 | - return $this->db->getDataRow($sql, null, $params); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Disables all of a user's entities |
|
97 | - * |
|
98 | - * @param int $owner_guid The owner GUID |
|
99 | - * @return bool Depending on success |
|
100 | - * @deprecated 2.3 |
|
101 | - */ |
|
102 | - public function disableEntities($owner_guid) { |
|
103 | - return $this->entities->disableEntities($owner_guid); |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Ban a user (calls events, stores the reason) |
|
108 | - * |
|
109 | - * @param int $user_guid The user guid |
|
110 | - * @param string $reason A reason |
|
111 | - * @return bool |
|
112 | - */ |
|
113 | - public function ban($user_guid, $reason = "") { |
|
114 | - |
|
115 | - $user = get_entity($user_guid); |
|
116 | - |
|
117 | - if (!$user instanceof ElggUser || !$user->canEdit()) { |
|
118 | - return false; |
|
119 | - } |
|
120 | - |
|
121 | - if (!$this->events->trigger('ban', 'user', $user)) { |
|
122 | - return false; |
|
123 | - } |
|
124 | - |
|
125 | - $user->ban_reason = $reason; |
|
126 | - |
|
127 | - _elgg_invalidate_cache_for_entity($user_guid); |
|
128 | - _elgg_invalidate_memcache_for_entity($user_guid); |
|
129 | - |
|
130 | - if ($this->markBanned($user_guid, true)) { |
|
131 | - return true; |
|
132 | - } |
|
133 | - |
|
134 | - return false; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Mark a user entity banned or unbanned. |
|
139 | - * |
|
140 | - * @note Use ban() or unban() |
|
141 | - * |
|
142 | - * @param int $guid User GUID |
|
143 | - * @param bool $banned Mark the user banned? |
|
144 | - * @return int Num rows affected |
|
145 | - */ |
|
146 | - public function markBanned($guid, $banned) { |
|
147 | - |
|
148 | - $query = " |
|
89 | + $params = [ |
|
90 | + ':guid' => $guid, |
|
91 | + ]; |
|
92 | + return $this->db->getDataRow($sql, null, $params); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Disables all of a user's entities |
|
97 | + * |
|
98 | + * @param int $owner_guid The owner GUID |
|
99 | + * @return bool Depending on success |
|
100 | + * @deprecated 2.3 |
|
101 | + */ |
|
102 | + public function disableEntities($owner_guid) { |
|
103 | + return $this->entities->disableEntities($owner_guid); |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Ban a user (calls events, stores the reason) |
|
108 | + * |
|
109 | + * @param int $user_guid The user guid |
|
110 | + * @param string $reason A reason |
|
111 | + * @return bool |
|
112 | + */ |
|
113 | + public function ban($user_guid, $reason = "") { |
|
114 | + |
|
115 | + $user = get_entity($user_guid); |
|
116 | + |
|
117 | + if (!$user instanceof ElggUser || !$user->canEdit()) { |
|
118 | + return false; |
|
119 | + } |
|
120 | + |
|
121 | + if (!$this->events->trigger('ban', 'user', $user)) { |
|
122 | + return false; |
|
123 | + } |
|
124 | + |
|
125 | + $user->ban_reason = $reason; |
|
126 | + |
|
127 | + _elgg_invalidate_cache_for_entity($user_guid); |
|
128 | + _elgg_invalidate_memcache_for_entity($user_guid); |
|
129 | + |
|
130 | + if ($this->markBanned($user_guid, true)) { |
|
131 | + return true; |
|
132 | + } |
|
133 | + |
|
134 | + return false; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Mark a user entity banned or unbanned. |
|
139 | + * |
|
140 | + * @note Use ban() or unban() |
|
141 | + * |
|
142 | + * @param int $guid User GUID |
|
143 | + * @param bool $banned Mark the user banned? |
|
144 | + * @return int Num rows affected |
|
145 | + */ |
|
146 | + public function markBanned($guid, $banned) { |
|
147 | + |
|
148 | + $query = " |
|
149 | 149 | UPDATE {$this->table} |
150 | 150 | SET banned = :banned |
151 | 151 | WHERE guid = :guid |
152 | 152 | "; |
153 | 153 | |
154 | - $params = [ |
|
155 | - ':banned' => $banned ? 'yes' : 'no', |
|
156 | - ':guid' => (int) $guid, |
|
157 | - ]; |
|
154 | + $params = [ |
|
155 | + ':banned' => $banned ? 'yes' : 'no', |
|
156 | + ':guid' => (int) $guid, |
|
157 | + ]; |
|
158 | 158 | |
159 | - return $this->db->updateData($query, true, $params); |
|
160 | - } |
|
159 | + return $this->db->updateData($query, true, $params); |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * Unban a user (calls events, removes the reason) |
|
164 | - * |
|
165 | - * @param int $user_guid Unban a user |
|
166 | - * @return bool |
|
167 | - */ |
|
168 | - public function unban($user_guid) { |
|
162 | + /** |
|
163 | + * Unban a user (calls events, removes the reason) |
|
164 | + * |
|
165 | + * @param int $user_guid Unban a user |
|
166 | + * @return bool |
|
167 | + */ |
|
168 | + public function unban($user_guid) { |
|
169 | 169 | |
170 | - $user = get_entity($user_guid); |
|
170 | + $user = get_entity($user_guid); |
|
171 | 171 | |
172 | - if (!$user instanceof ElggUser || !$user->canEdit()) { |
|
173 | - return false; |
|
174 | - } |
|
172 | + if (!$user instanceof ElggUser || !$user->canEdit()) { |
|
173 | + return false; |
|
174 | + } |
|
175 | 175 | |
176 | - if (!$this->events->trigger('unban', 'user', $user)) { |
|
177 | - return false; |
|
178 | - } |
|
176 | + if (!$this->events->trigger('unban', 'user', $user)) { |
|
177 | + return false; |
|
178 | + } |
|
179 | 179 | |
180 | - $user->deleteMetadata('ban_reason'); |
|
180 | + $user->deleteMetadata('ban_reason'); |
|
181 | 181 | |
182 | - _elgg_invalidate_cache_for_entity($user_guid); |
|
183 | - _elgg_invalidate_memcache_for_entity($user_guid); |
|
182 | + _elgg_invalidate_cache_for_entity($user_guid); |
|
183 | + _elgg_invalidate_memcache_for_entity($user_guid); |
|
184 | 184 | |
185 | - return $this->markBanned($user_guid, false); |
|
186 | - } |
|
185 | + return $this->markBanned($user_guid, false); |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * Makes user $guid an admin. |
|
190 | - * |
|
191 | - * @param int $user_guid User guid |
|
192 | - * @return bool |
|
193 | - */ |
|
194 | - public function makeAdmin($user_guid) { |
|
195 | - $user = get_entity($user_guid); |
|
188 | + /** |
|
189 | + * Makes user $guid an admin. |
|
190 | + * |
|
191 | + * @param int $user_guid User guid |
|
192 | + * @return bool |
|
193 | + */ |
|
194 | + public function makeAdmin($user_guid) { |
|
195 | + $user = get_entity($user_guid); |
|
196 | 196 | |
197 | - if (!$user instanceof ElggUser || !$user->canEdit()) { |
|
198 | - return false; |
|
199 | - } |
|
197 | + if (!$user instanceof ElggUser || !$user->canEdit()) { |
|
198 | + return false; |
|
199 | + } |
|
200 | 200 | |
201 | - if (!$this->events->trigger('make_admin', 'user', $user)) { |
|
202 | - return false; |
|
203 | - } |
|
201 | + if (!$this->events->trigger('make_admin', 'user', $user)) { |
|
202 | + return false; |
|
203 | + } |
|
204 | 204 | |
205 | - $query = " |
|
205 | + $query = " |
|
206 | 206 | UPDATE {$this->table} |
207 | 207 | SET admin = 'yes' |
208 | 208 | WHERE guid = :guid |
209 | 209 | "; |
210 | 210 | |
211 | - $params = [ |
|
212 | - ':guid' => (int) $user_guid, |
|
213 | - ]; |
|
211 | + $params = [ |
|
212 | + ':guid' => (int) $user_guid, |
|
213 | + ]; |
|
214 | 214 | |
215 | - _elgg_invalidate_cache_for_entity($user_guid); |
|
216 | - _elgg_invalidate_memcache_for_entity($user_guid); |
|
215 | + _elgg_invalidate_cache_for_entity($user_guid); |
|
216 | + _elgg_invalidate_memcache_for_entity($user_guid); |
|
217 | 217 | |
218 | - if ($this->db->updateData($query, true, $params)) { |
|
219 | - return true; |
|
220 | - } |
|
218 | + if ($this->db->updateData($query, true, $params)) { |
|
219 | + return true; |
|
220 | + } |
|
221 | 221 | |
222 | - return false; |
|
223 | - } |
|
222 | + return false; |
|
223 | + } |
|
224 | 224 | |
225 | - /** |
|
226 | - * Removes user $guid's admin flag. |
|
227 | - * |
|
228 | - * @param int $user_guid User GUID |
|
229 | - * @return bool |
|
230 | - */ |
|
231 | - public function removeAdmin($user_guid) { |
|
225 | + /** |
|
226 | + * Removes user $guid's admin flag. |
|
227 | + * |
|
228 | + * @param int $user_guid User GUID |
|
229 | + * @return bool |
|
230 | + */ |
|
231 | + public function removeAdmin($user_guid) { |
|
232 | 232 | |
233 | - $user = get_entity($user_guid); |
|
233 | + $user = get_entity($user_guid); |
|
234 | 234 | |
235 | - if (!$user instanceof ElggUser || !$user->canEdit()) { |
|
236 | - return false; |
|
237 | - } |
|
235 | + if (!$user instanceof ElggUser || !$user->canEdit()) { |
|
236 | + return false; |
|
237 | + } |
|
238 | 238 | |
239 | - if (!$this->events->trigger('remove_admin', 'user', $user)) { |
|
240 | - return false; |
|
241 | - } |
|
239 | + if (!$this->events->trigger('remove_admin', 'user', $user)) { |
|
240 | + return false; |
|
241 | + } |
|
242 | 242 | |
243 | - $query = " |
|
243 | + $query = " |
|
244 | 244 | UPDATE {$this->table} |
245 | 245 | SET admin = 'no' |
246 | 246 | WHERE guid = :guid |
247 | 247 | "; |
248 | 248 | |
249 | - $params = [ |
|
250 | - ':guid' => (int) $user_guid, |
|
251 | - ]; |
|
252 | - |
|
253 | - _elgg_invalidate_cache_for_entity($user_guid); |
|
254 | - _elgg_invalidate_memcache_for_entity($user_guid); |
|
255 | - |
|
256 | - if ($this->db->updateData($query, true, $params)) { |
|
257 | - return true; |
|
258 | - } |
|
259 | - |
|
260 | - return false; |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * Get user by username |
|
265 | - * |
|
266 | - * @param string $username The user's username |
|
267 | - * |
|
268 | - * @return ElggUser|false Depending on success |
|
269 | - */ |
|
270 | - public function getByUsername($username) { |
|
271 | - |
|
272 | - // Fixes #6052. Username is frequently sniffed from the path info, which, |
|
273 | - // unlike $_GET, is not URL decoded. If the username was not URL encoded, |
|
274 | - // this is harmless. |
|
275 | - $username = rawurldecode($username); |
|
276 | - |
|
277 | - if (!$username) { |
|
278 | - return false; |
|
279 | - } |
|
280 | - |
|
281 | - $entity = $this->entity_cache->getByUsername($username); |
|
282 | - if ($entity) { |
|
283 | - return $entity; |
|
284 | - } |
|
285 | - |
|
286 | - $users = $this->entities->getEntitiesFromAttributes([ |
|
287 | - 'types' => 'user', |
|
288 | - 'attribute_name_value_pairs' => [ |
|
289 | - 'name' => 'username', |
|
290 | - 'value' => $username, |
|
291 | - ], |
|
292 | - 'limit' => 1, |
|
293 | - ]); |
|
294 | - return $users ? $users[0] : false; |
|
295 | - } |
|
296 | - |
|
297 | - /** |
|
298 | - * Get an array of users from an email address |
|
299 | - * |
|
300 | - * @param string $email Email address |
|
301 | - * @return array |
|
302 | - */ |
|
303 | - public function getByEmail($email) { |
|
304 | - if (!$email) { |
|
305 | - return []; |
|
306 | - } |
|
307 | - |
|
308 | - $users = $this->entities->getEntitiesFromAttributes([ |
|
309 | - 'types' => 'user', |
|
310 | - 'attribute_name_value_pairs' => [ |
|
311 | - 'name' => 'email', |
|
312 | - 'value' => $email, |
|
313 | - ], |
|
314 | - 'limit' => 1, |
|
315 | - ]); |
|
316 | - |
|
317 | - return $users ? : []; |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * Return users (or the number of them) who have been active within a recent period. |
|
322 | - * |
|
323 | - * @param array $options Array of options with keys: |
|
324 | - * |
|
325 | - * seconds (int) => Length of period (default 600 = 10min) |
|
326 | - * limit (int) => Limit (default 10) |
|
327 | - * offset (int) => Offset (default 0) |
|
328 | - * count (bool) => Return a count instead of users? (default false) |
|
329 | - * |
|
330 | - * @return \ElggUser[]|int |
|
331 | - */ |
|
332 | - public function findActive(array $options = []) { |
|
249 | + $params = [ |
|
250 | + ':guid' => (int) $user_guid, |
|
251 | + ]; |
|
252 | + |
|
253 | + _elgg_invalidate_cache_for_entity($user_guid); |
|
254 | + _elgg_invalidate_memcache_for_entity($user_guid); |
|
255 | + |
|
256 | + if ($this->db->updateData($query, true, $params)) { |
|
257 | + return true; |
|
258 | + } |
|
259 | + |
|
260 | + return false; |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * Get user by username |
|
265 | + * |
|
266 | + * @param string $username The user's username |
|
267 | + * |
|
268 | + * @return ElggUser|false Depending on success |
|
269 | + */ |
|
270 | + public function getByUsername($username) { |
|
271 | + |
|
272 | + // Fixes #6052. Username is frequently sniffed from the path info, which, |
|
273 | + // unlike $_GET, is not URL decoded. If the username was not URL encoded, |
|
274 | + // this is harmless. |
|
275 | + $username = rawurldecode($username); |
|
276 | + |
|
277 | + if (!$username) { |
|
278 | + return false; |
|
279 | + } |
|
280 | + |
|
281 | + $entity = $this->entity_cache->getByUsername($username); |
|
282 | + if ($entity) { |
|
283 | + return $entity; |
|
284 | + } |
|
285 | + |
|
286 | + $users = $this->entities->getEntitiesFromAttributes([ |
|
287 | + 'types' => 'user', |
|
288 | + 'attribute_name_value_pairs' => [ |
|
289 | + 'name' => 'username', |
|
290 | + 'value' => $username, |
|
291 | + ], |
|
292 | + 'limit' => 1, |
|
293 | + ]); |
|
294 | + return $users ? $users[0] : false; |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * Get an array of users from an email address |
|
299 | + * |
|
300 | + * @param string $email Email address |
|
301 | + * @return array |
|
302 | + */ |
|
303 | + public function getByEmail($email) { |
|
304 | + if (!$email) { |
|
305 | + return []; |
|
306 | + } |
|
307 | + |
|
308 | + $users = $this->entities->getEntitiesFromAttributes([ |
|
309 | + 'types' => 'user', |
|
310 | + 'attribute_name_value_pairs' => [ |
|
311 | + 'name' => 'email', |
|
312 | + 'value' => $email, |
|
313 | + ], |
|
314 | + 'limit' => 1, |
|
315 | + ]); |
|
316 | + |
|
317 | + return $users ? : []; |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * Return users (or the number of them) who have been active within a recent period. |
|
322 | + * |
|
323 | + * @param array $options Array of options with keys: |
|
324 | + * |
|
325 | + * seconds (int) => Length of period (default 600 = 10min) |
|
326 | + * limit (int) => Limit (default 10) |
|
327 | + * offset (int) => Offset (default 0) |
|
328 | + * count (bool) => Return a count instead of users? (default false) |
|
329 | + * |
|
330 | + * @return \ElggUser[]|int |
|
331 | + */ |
|
332 | + public function findActive(array $options = []) { |
|
333 | 333 | |
334 | - $options = array_merge([ |
|
335 | - 'seconds' => 600, |
|
336 | - 'limit' => $this->config->default_limit, |
|
337 | - ], $options); |
|
338 | - |
|
339 | - // cast options we're sending to hook |
|
340 | - foreach (['seconds', 'limit', 'offset'] as $key) { |
|
341 | - $options[$key] = (int) $options[$key]; |
|
342 | - } |
|
343 | - $options['count'] = (bool) $options['count']; |
|
344 | - |
|
345 | - // allow plugins to override |
|
346 | - $params = [ |
|
347 | - 'seconds' => $options['seconds'], |
|
348 | - 'limit' => $options['limit'], |
|
349 | - 'offset' => $options['offset'], |
|
350 | - 'count' => $options['count'], |
|
351 | - 'options' => $options, |
|
352 | - ]; |
|
353 | - $data = _elgg_services()->hooks->trigger('find_active_users', 'system', $params, null); |
|
354 | - // check null because the handler could legitimately return falsey values. |
|
355 | - if ($data !== null) { |
|
356 | - return $data; |
|
357 | - } |
|
358 | - |
|
359 | - $dbprefix = $this->config->dbprefix; |
|
360 | - $time = $this->getCurrentTime()->getTimestamp() - $options['seconds']; |
|
361 | - return elgg_get_entities([ |
|
362 | - 'type' => 'user', |
|
363 | - 'limit' => $options['limit'], |
|
364 | - 'offset' => $options['offset'], |
|
365 | - 'count' => $options['count'], |
|
366 | - 'joins' => ["join {$dbprefix}users_entity u on e.guid = u.guid"], |
|
367 | - 'wheres' => ["u.last_action >= {$time}"], |
|
368 | - 'order_by' => "u.last_action desc", |
|
369 | - ]); |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Registers a user, returning false if the username already exists |
|
374 | - * |
|
375 | - * @param string $username The username of the new user |
|
376 | - * @param string $password The password |
|
377 | - * @param string $name The user's display name |
|
378 | - * @param string $email The user's email address |
|
379 | - * @param bool $allow_multiple_emails Allow the same email address to be |
|
380 | - * registered multiple times? |
|
381 | - * |
|
382 | - * @return int|false The new user's GUID; false on failure |
|
383 | - * @throws RegistrationException |
|
384 | - */ |
|
385 | - public function register($username, $password, $name, $email, $allow_multiple_emails = false) { |
|
386 | - |
|
387 | - // no need to trim password |
|
388 | - $username = trim($username); |
|
389 | - $name = trim(strip_tags($name)); |
|
390 | - $email = trim($email); |
|
391 | - |
|
392 | - // A little sanity checking |
|
393 | - if (empty($username) || empty($password) || empty($name) || empty($email)) { |
|
394 | - return false; |
|
395 | - } |
|
396 | - |
|
397 | - // Make sure a user with conflicting details hasn't registered and been disabled |
|
398 | - $access_status = access_get_show_hidden_status(); |
|
399 | - access_show_hidden_entities(true); |
|
400 | - |
|
401 | - if (!validate_email_address($email)) { |
|
402 | - throw new RegistrationException(_elgg_services()->translator->translate('registration:emailnotvalid')); |
|
403 | - } |
|
404 | - |
|
405 | - if (!validate_password($password)) { |
|
406 | - throw new RegistrationException(_elgg_services()->translator->translate('registration:passwordnotvalid')); |
|
407 | - } |
|
408 | - |
|
409 | - if (!validate_username($username)) { |
|
410 | - throw new RegistrationException(_elgg_services()->translator->translate('registration:usernamenotvalid')); |
|
411 | - } |
|
412 | - |
|
413 | - if ($user = get_user_by_username($username)) { |
|
414 | - throw new RegistrationException(_elgg_services()->translator->translate('registration:userexists')); |
|
415 | - } |
|
416 | - |
|
417 | - if ((!$allow_multiple_emails) && (get_user_by_email($email))) { |
|
418 | - throw new RegistrationException(_elgg_services()->translator->translate('registration:dupeemail')); |
|
419 | - } |
|
420 | - |
|
421 | - access_show_hidden_entities($access_status); |
|
422 | - |
|
423 | - // Create user |
|
424 | - $user = new ElggUser(); |
|
425 | - $user->username = $username; |
|
426 | - $user->email = $email; |
|
427 | - $user->name = $name; |
|
428 | - $user->access_id = ACCESS_PUBLIC; |
|
429 | - $user->setPassword($password); |
|
430 | - $user->owner_guid = 0; // Users aren't owned by anyone, even if they are admin created. |
|
431 | - $user->container_guid = 0; // Users aren't contained by anyone, even if they are admin created. |
|
432 | - $user->language = _elgg_services()->translator->getCurrentLanguage(); |
|
433 | - if ($user->save() === false) { |
|
434 | - return false; |
|
435 | - } |
|
436 | - |
|
437 | - // Turn on email notifications by default |
|
438 | - $user->setNotificationSetting('email', true); |
|
334 | + $options = array_merge([ |
|
335 | + 'seconds' => 600, |
|
336 | + 'limit' => $this->config->default_limit, |
|
337 | + ], $options); |
|
338 | + |
|
339 | + // cast options we're sending to hook |
|
340 | + foreach (['seconds', 'limit', 'offset'] as $key) { |
|
341 | + $options[$key] = (int) $options[$key]; |
|
342 | + } |
|
343 | + $options['count'] = (bool) $options['count']; |
|
344 | + |
|
345 | + // allow plugins to override |
|
346 | + $params = [ |
|
347 | + 'seconds' => $options['seconds'], |
|
348 | + 'limit' => $options['limit'], |
|
349 | + 'offset' => $options['offset'], |
|
350 | + 'count' => $options['count'], |
|
351 | + 'options' => $options, |
|
352 | + ]; |
|
353 | + $data = _elgg_services()->hooks->trigger('find_active_users', 'system', $params, null); |
|
354 | + // check null because the handler could legitimately return falsey values. |
|
355 | + if ($data !== null) { |
|
356 | + return $data; |
|
357 | + } |
|
358 | + |
|
359 | + $dbprefix = $this->config->dbprefix; |
|
360 | + $time = $this->getCurrentTime()->getTimestamp() - $options['seconds']; |
|
361 | + return elgg_get_entities([ |
|
362 | + 'type' => 'user', |
|
363 | + 'limit' => $options['limit'], |
|
364 | + 'offset' => $options['offset'], |
|
365 | + 'count' => $options['count'], |
|
366 | + 'joins' => ["join {$dbprefix}users_entity u on e.guid = u.guid"], |
|
367 | + 'wheres' => ["u.last_action >= {$time}"], |
|
368 | + 'order_by' => "u.last_action desc", |
|
369 | + ]); |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Registers a user, returning false if the username already exists |
|
374 | + * |
|
375 | + * @param string $username The username of the new user |
|
376 | + * @param string $password The password |
|
377 | + * @param string $name The user's display name |
|
378 | + * @param string $email The user's email address |
|
379 | + * @param bool $allow_multiple_emails Allow the same email address to be |
|
380 | + * registered multiple times? |
|
381 | + * |
|
382 | + * @return int|false The new user's GUID; false on failure |
|
383 | + * @throws RegistrationException |
|
384 | + */ |
|
385 | + public function register($username, $password, $name, $email, $allow_multiple_emails = false) { |
|
386 | + |
|
387 | + // no need to trim password |
|
388 | + $username = trim($username); |
|
389 | + $name = trim(strip_tags($name)); |
|
390 | + $email = trim($email); |
|
391 | + |
|
392 | + // A little sanity checking |
|
393 | + if (empty($username) || empty($password) || empty($name) || empty($email)) { |
|
394 | + return false; |
|
395 | + } |
|
396 | + |
|
397 | + // Make sure a user with conflicting details hasn't registered and been disabled |
|
398 | + $access_status = access_get_show_hidden_status(); |
|
399 | + access_show_hidden_entities(true); |
|
400 | + |
|
401 | + if (!validate_email_address($email)) { |
|
402 | + throw new RegistrationException(_elgg_services()->translator->translate('registration:emailnotvalid')); |
|
403 | + } |
|
404 | + |
|
405 | + if (!validate_password($password)) { |
|
406 | + throw new RegistrationException(_elgg_services()->translator->translate('registration:passwordnotvalid')); |
|
407 | + } |
|
408 | + |
|
409 | + if (!validate_username($username)) { |
|
410 | + throw new RegistrationException(_elgg_services()->translator->translate('registration:usernamenotvalid')); |
|
411 | + } |
|
412 | + |
|
413 | + if ($user = get_user_by_username($username)) { |
|
414 | + throw new RegistrationException(_elgg_services()->translator->translate('registration:userexists')); |
|
415 | + } |
|
416 | + |
|
417 | + if ((!$allow_multiple_emails) && (get_user_by_email($email))) { |
|
418 | + throw new RegistrationException(_elgg_services()->translator->translate('registration:dupeemail')); |
|
419 | + } |
|
420 | + |
|
421 | + access_show_hidden_entities($access_status); |
|
422 | + |
|
423 | + // Create user |
|
424 | + $user = new ElggUser(); |
|
425 | + $user->username = $username; |
|
426 | + $user->email = $email; |
|
427 | + $user->name = $name; |
|
428 | + $user->access_id = ACCESS_PUBLIC; |
|
429 | + $user->setPassword($password); |
|
430 | + $user->owner_guid = 0; // Users aren't owned by anyone, even if they are admin created. |
|
431 | + $user->container_guid = 0; // Users aren't contained by anyone, even if they are admin created. |
|
432 | + $user->language = _elgg_services()->translator->getCurrentLanguage(); |
|
433 | + if ($user->save() === false) { |
|
434 | + return false; |
|
435 | + } |
|
436 | + |
|
437 | + // Turn on email notifications by default |
|
438 | + $user->setNotificationSetting('email', true); |
|
439 | 439 | |
440 | - return $user->getGUID(); |
|
441 | - } |
|
442 | - |
|
443 | - /** |
|
444 | - * Generates a unique invite code for a user |
|
445 | - * |
|
446 | - * @param string $username The username of the user sending the invitation |
|
447 | - * |
|
448 | - * @return string Invite code |
|
449 | - * @see validateInviteCode |
|
450 | - */ |
|
451 | - public function generateInviteCode($username) { |
|
452 | - $time = $this->getCurrentTime()->getTimestamp(); |
|
453 | - return "$time." . _elgg_services()->hmac->getHmac([(int) $time, $username])->getToken(); |
|
454 | - } |
|
455 | - |
|
456 | - /** |
|
457 | - * Validate a user's invite code |
|
458 | - * |
|
459 | - * @param string $username The username |
|
460 | - * @param string $code The invite code |
|
461 | - * |
|
462 | - * @return bool |
|
463 | - * @see generateInviteCode |
|
464 | - */ |
|
465 | - public function validateInviteCode($username, $code) { |
|
466 | - // validate the format of the token created by ->generateInviteCode() |
|
467 | - if (!preg_match('~^(\d+)\.([a-zA-Z0-9\-_]+)$~', $code, $m)) { |
|
468 | - return false; |
|
469 | - } |
|
470 | - $time = $m[1]; |
|
471 | - $mac = $m[2]; |
|
472 | - |
|
473 | - return _elgg_services()->hmac->getHmac([(int) $time, $username])->matchesToken($mac); |
|
474 | - } |
|
475 | - |
|
476 | - /** |
|
477 | - * Set the validation status for a user. |
|
478 | - * |
|
479 | - * @param int $user_guid The user's GUID |
|
480 | - * @param bool $status Validated (true) or unvalidated (false) |
|
481 | - * @param string $method Optional method to say how a user was validated |
|
482 | - * @return bool |
|
483 | - */ |
|
484 | - public function setValidationStatus($user_guid, $status, $method = '') { |
|
485 | - $user = get_user($user_guid); |
|
486 | - if (!$user) { |
|
487 | - return false; |
|
488 | - } |
|
489 | - |
|
490 | - $result1 = create_metadata($user->guid, 'validated', (int) $status); |
|
491 | - $result2 = create_metadata($user->guid, 'validated_method', $method); |
|
492 | - if ($result1 && $result2) { |
|
493 | - if ((bool) $status) { |
|
494 | - elgg_trigger_after_event('validate', 'user', $user); |
|
495 | - } else { |
|
496 | - elgg_trigger_after_event('invalidate', 'user', $user); |
|
497 | - } |
|
498 | - return true; |
|
499 | - } else { |
|
500 | - return false; |
|
501 | - } |
|
502 | - } |
|
503 | - |
|
504 | - /** |
|
505 | - * Gets the validation status of a user. |
|
506 | - * |
|
507 | - * @param int $user_guid The user's GUID |
|
508 | - * @return bool|null Null means status was not set for this user. |
|
509 | - */ |
|
510 | - public function getValidationStatus($user_guid) { |
|
511 | - $user = get_entity($user_guid); |
|
512 | - if (!$user || !isset($user->validated)) { |
|
513 | - return null; |
|
514 | - } |
|
515 | - return (bool) $user->validated; |
|
516 | - } |
|
517 | - |
|
518 | - /** |
|
519 | - * Sets the last action time of the given user to right now. |
|
520 | - * |
|
521 | - * @see _elgg_session_boot The session boot calls this at the beginning of every request |
|
522 | - * |
|
523 | - * @param ElggUser $user User entity |
|
524 | - * @return void |
|
525 | - */ |
|
526 | - public function setLastAction(ElggUser $user) { |
|
527 | - |
|
528 | - $time = $this->getCurrentTime()->getTimestamp(); |
|
529 | - |
|
530 | - if ($user->last_action == $time) { |
|
531 | - // no change required |
|
532 | - return; |
|
533 | - } |
|
534 | - |
|
535 | - $query = " |
|
440 | + return $user->getGUID(); |
|
441 | + } |
|
442 | + |
|
443 | + /** |
|
444 | + * Generates a unique invite code for a user |
|
445 | + * |
|
446 | + * @param string $username The username of the user sending the invitation |
|
447 | + * |
|
448 | + * @return string Invite code |
|
449 | + * @see validateInviteCode |
|
450 | + */ |
|
451 | + public function generateInviteCode($username) { |
|
452 | + $time = $this->getCurrentTime()->getTimestamp(); |
|
453 | + return "$time." . _elgg_services()->hmac->getHmac([(int) $time, $username])->getToken(); |
|
454 | + } |
|
455 | + |
|
456 | + /** |
|
457 | + * Validate a user's invite code |
|
458 | + * |
|
459 | + * @param string $username The username |
|
460 | + * @param string $code The invite code |
|
461 | + * |
|
462 | + * @return bool |
|
463 | + * @see generateInviteCode |
|
464 | + */ |
|
465 | + public function validateInviteCode($username, $code) { |
|
466 | + // validate the format of the token created by ->generateInviteCode() |
|
467 | + if (!preg_match('~^(\d+)\.([a-zA-Z0-9\-_]+)$~', $code, $m)) { |
|
468 | + return false; |
|
469 | + } |
|
470 | + $time = $m[1]; |
|
471 | + $mac = $m[2]; |
|
472 | + |
|
473 | + return _elgg_services()->hmac->getHmac([(int) $time, $username])->matchesToken($mac); |
|
474 | + } |
|
475 | + |
|
476 | + /** |
|
477 | + * Set the validation status for a user. |
|
478 | + * |
|
479 | + * @param int $user_guid The user's GUID |
|
480 | + * @param bool $status Validated (true) or unvalidated (false) |
|
481 | + * @param string $method Optional method to say how a user was validated |
|
482 | + * @return bool |
|
483 | + */ |
|
484 | + public function setValidationStatus($user_guid, $status, $method = '') { |
|
485 | + $user = get_user($user_guid); |
|
486 | + if (!$user) { |
|
487 | + return false; |
|
488 | + } |
|
489 | + |
|
490 | + $result1 = create_metadata($user->guid, 'validated', (int) $status); |
|
491 | + $result2 = create_metadata($user->guid, 'validated_method', $method); |
|
492 | + if ($result1 && $result2) { |
|
493 | + if ((bool) $status) { |
|
494 | + elgg_trigger_after_event('validate', 'user', $user); |
|
495 | + } else { |
|
496 | + elgg_trigger_after_event('invalidate', 'user', $user); |
|
497 | + } |
|
498 | + return true; |
|
499 | + } else { |
|
500 | + return false; |
|
501 | + } |
|
502 | + } |
|
503 | + |
|
504 | + /** |
|
505 | + * Gets the validation status of a user. |
|
506 | + * |
|
507 | + * @param int $user_guid The user's GUID |
|
508 | + * @return bool|null Null means status was not set for this user. |
|
509 | + */ |
|
510 | + public function getValidationStatus($user_guid) { |
|
511 | + $user = get_entity($user_guid); |
|
512 | + if (!$user || !isset($user->validated)) { |
|
513 | + return null; |
|
514 | + } |
|
515 | + return (bool) $user->validated; |
|
516 | + } |
|
517 | + |
|
518 | + /** |
|
519 | + * Sets the last action time of the given user to right now. |
|
520 | + * |
|
521 | + * @see _elgg_session_boot The session boot calls this at the beginning of every request |
|
522 | + * |
|
523 | + * @param ElggUser $user User entity |
|
524 | + * @return void |
|
525 | + */ |
|
526 | + public function setLastAction(ElggUser $user) { |
|
527 | + |
|
528 | + $time = $this->getCurrentTime()->getTimestamp(); |
|
529 | + |
|
530 | + if ($user->last_action == $time) { |
|
531 | + // no change required |
|
532 | + return; |
|
533 | + } |
|
534 | + |
|
535 | + $query = " |
|
536 | 536 | UPDATE {$this->table} |
537 | 537 | SET |
538 | 538 | prev_last_action = last_action, |
@@ -540,44 +540,44 @@ discard block |
||
540 | 540 | WHERE guid = :guid |
541 | 541 | "; |
542 | 542 | |
543 | - $params = [ |
|
544 | - ':last_action' => $time, |
|
545 | - ':guid' => (int) $user->guid, |
|
546 | - ]; |
|
543 | + $params = [ |
|
544 | + ':last_action' => $time, |
|
545 | + ':guid' => (int) $user->guid, |
|
546 | + ]; |
|
547 | 547 | |
548 | - // these writes actually work, we just type hint read-only. |
|
549 | - $user->prev_last_action = $user->last_action; |
|
550 | - $user->last_action = $time; |
|
548 | + // these writes actually work, we just type hint read-only. |
|
549 | + $user->prev_last_action = $user->last_action; |
|
550 | + $user->last_action = $time; |
|
551 | 551 | |
552 | - execute_delayed_write_query($query, null, $params); |
|
552 | + execute_delayed_write_query($query, null, $params); |
|
553 | 553 | |
554 | - $this->entity_cache->set($user); |
|
554 | + $this->entity_cache->set($user); |
|
555 | 555 | |
556 | - // If we save the user to memcache during this request, then we'll end up with the |
|
557 | - // old (incorrect) attributes cached (notice the above query is delayed). So it's |
|
558 | - // simplest to just resave the user after all plugin code runs. |
|
559 | - register_shutdown_function(function () use ($user, $time) { |
|
560 | - $this->entities->updateLastAction($user, $time); // keep entity table in sync |
|
561 | - $user->storeInPersistedCache(_elgg_get_memcache('new_entity_cache'), $time); |
|
562 | - }); |
|
563 | - } |
|
556 | + // If we save the user to memcache during this request, then we'll end up with the |
|
557 | + // old (incorrect) attributes cached (notice the above query is delayed). So it's |
|
558 | + // simplest to just resave the user after all plugin code runs. |
|
559 | + register_shutdown_function(function () use ($user, $time) { |
|
560 | + $this->entities->updateLastAction($user, $time); // keep entity table in sync |
|
561 | + $user->storeInPersistedCache(_elgg_get_memcache('new_entity_cache'), $time); |
|
562 | + }); |
|
563 | + } |
|
564 | 564 | |
565 | - /** |
|
566 | - * Sets the last logon time of the given user to right now. |
|
567 | - * |
|
568 | - * @param ElggUser $user User entity |
|
569 | - * @return void |
|
570 | - */ |
|
571 | - public function setLastLogin(ElggUser $user) { |
|
565 | + /** |
|
566 | + * Sets the last logon time of the given user to right now. |
|
567 | + * |
|
568 | + * @param ElggUser $user User entity |
|
569 | + * @return void |
|
570 | + */ |
|
571 | + public function setLastLogin(ElggUser $user) { |
|
572 | 572 | |
573 | - $time = $this->getCurrentTime()->getTimestamp(); |
|
573 | + $time = $this->getCurrentTime()->getTimestamp(); |
|
574 | 574 | |
575 | - if ($user->last_login == $time) { |
|
576 | - // no change required |
|
577 | - return; |
|
578 | - } |
|
575 | + if ($user->last_login == $time) { |
|
576 | + // no change required |
|
577 | + return; |
|
578 | + } |
|
579 | 579 | |
580 | - $query = " |
|
580 | + $query = " |
|
581 | 581 | UPDATE {$this->table} |
582 | 582 | SET |
583 | 583 | prev_last_login = last_login, |
@@ -585,24 +585,24 @@ discard block |
||
585 | 585 | WHERE guid = :guid |
586 | 586 | "; |
587 | 587 | |
588 | - $params = [ |
|
589 | - ':last_login' => $time, |
|
590 | - ':guid' => (int) $user->guid, |
|
591 | - ]; |
|
588 | + $params = [ |
|
589 | + ':last_login' => $time, |
|
590 | + ':guid' => (int) $user->guid, |
|
591 | + ]; |
|
592 | 592 | |
593 | - // these writes actually work, we just type hint read-only. |
|
594 | - $user->prev_last_login = $user->last_login; |
|
595 | - $user->last_login = $time; |
|
593 | + // these writes actually work, we just type hint read-only. |
|
594 | + $user->prev_last_login = $user->last_login; |
|
595 | + $user->last_login = $time; |
|
596 | 596 | |
597 | - execute_delayed_write_query($query, null, $params); |
|
597 | + execute_delayed_write_query($query, null, $params); |
|
598 | 598 | |
599 | - $this->entity_cache->set($user); |
|
599 | + $this->entity_cache->set($user); |
|
600 | 600 | |
601 | - // If we save the user to memcache during this request, then we'll end up with the |
|
602 | - // old (incorrect) attributes cached. Hence we want to invalidate as late as possible. |
|
603 | - // the user object gets saved |
|
604 | - register_shutdown_function(function () use ($user) { |
|
605 | - $user->storeInPersistedCache(_elgg_get_memcache('new_entity_cache')); |
|
606 | - }); |
|
607 | - } |
|
601 | + // If we save the user to memcache during this request, then we'll end up with the |
|
602 | + // old (incorrect) attributes cached. Hence we want to invalidate as late as possible. |
|
603 | + // the user object gets saved |
|
604 | + register_shutdown_function(function () use ($user) { |
|
605 | + $user->storeInPersistedCache(_elgg_get_memcache('new_entity_cache')); |
|
606 | + }); |
|
607 | + } |
|
608 | 608 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | if ($handle) { |
94 | 94 | while ($plugin_dir = readdir($handle)) { |
95 | 95 | // must be directory and not begin with a . |
96 | - if (substr($plugin_dir, 0, 1) !== '.' && is_dir($dir . $plugin_dir)) { |
|
96 | + if (substr($plugin_dir, 0, 1) !== '.' && is_dir($dir.$plugin_dir)) { |
|
97 | 97 | $plugin_dirs[] = $plugin_dir; |
98 | 98 | } |
99 | 99 | } |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | } else { |
177 | 177 | // create new plugin |
178 | 178 | // priority is forced to last in save() if not set. |
179 | - $plugin = new \ElggPlugin($mod_dir . $plugin_id); |
|
179 | + $plugin = new \ElggPlugin($mod_dir.$plugin_id); |
|
180 | 180 | $plugin->save(); |
181 | 181 | } |
182 | 182 | } |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | * @return \ElggPlugin|null |
224 | 224 | */ |
225 | 225 | function get($plugin_id) { |
226 | - return $this->plugins_by_id->get($plugin_id, function () use ($plugin_id) { |
|
226 | + return $this->plugins_by_id->get($plugin_id, function() use ($plugin_id) { |
|
227 | 227 | $plugin_id = sanitize_string($plugin_id); |
228 | 228 | $db_prefix = _elgg_config()->dbprefix; |
229 | 229 | |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | $plugins = elgg_get_entities_from_relationship($options); |
452 | 452 | elgg_set_ignore_access($old_ia); |
453 | 453 | |
454 | - usort($plugins, function (\ElggPlugin $a, \ElggPlugin $b) { |
|
454 | + usort($plugins, function(\ElggPlugin $a, \ElggPlugin $b) { |
|
455 | 455 | $a_value = $a->getVolatileData('select:value'); |
456 | 456 | $b_value = $b->getVolatileData('select:value'); |
457 | 457 | |
@@ -563,11 +563,11 @@ discard block |
||
563 | 563 | if (!$id) { |
564 | 564 | throw new \InvalidArgumentException("You must pass the plugin id for user settings"); |
565 | 565 | } |
566 | - $name = ELGG_PLUGIN_USER_SETTING_PREFIX . "$id:$name"; |
|
566 | + $name = ELGG_PLUGIN_USER_SETTING_PREFIX."$id:$name"; |
|
567 | 567 | break; |
568 | 568 | |
569 | 569 | case 'internal': |
570 | - $name = ELGG_PLUGIN_INTERNAL_PREFIX . $name; |
|
570 | + $name = ELGG_PLUGIN_INTERNAL_PREFIX.$name; |
|
571 | 571 | break; |
572 | 572 | } |
573 | 573 | |
@@ -746,7 +746,7 @@ discard block |
||
746 | 746 | 'priority' 'before blog' -- after 'move it' |
747 | 747 | */ |
748 | 748 | $strings = []; |
749 | - $strings['type'] = $translator->translate('ElggPlugin:Dependencies:' . ucwords($dep_system)); |
|
749 | + $strings['type'] = $translator->translate('ElggPlugin:Dependencies:'.ucwords($dep_system)); |
|
750 | 750 | |
751 | 751 | switch ($type) { |
752 | 752 | case 'elgg_release': |
@@ -16,713 +16,713 @@ discard block |
||
16 | 16 | * @since 1.10.0 |
17 | 17 | */ |
18 | 18 | class Plugins { |
19 | - use Profilable; |
|
19 | + use Profilable; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @var \ElggPlugin[] |
|
23 | - */ |
|
24 | - private $boot_plugins = []; |
|
21 | + /** |
|
22 | + * @var \ElggPlugin[] |
|
23 | + */ |
|
24 | + private $boot_plugins = []; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @var array|null |
|
28 | - */ |
|
29 | - private $provides_cache; |
|
26 | + /** |
|
27 | + * @var array|null |
|
28 | + */ |
|
29 | + private $provides_cache; |
|
30 | 30 | |
31 | - /** |
|
32 | - * @var string[] Active plugins, with plugin ID => GUID. Missing keys imply inactive plugins. |
|
33 | - */ |
|
34 | - private $active_guids = []; |
|
31 | + /** |
|
32 | + * @var string[] Active plugins, with plugin ID => GUID. Missing keys imply inactive plugins. |
|
33 | + */ |
|
34 | + private $active_guids = []; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var bool Has $active_guids been populated? |
|
38 | - */ |
|
39 | - private $active_guids_known = false; |
|
36 | + /** |
|
37 | + * @var bool Has $active_guids been populated? |
|
38 | + */ |
|
39 | + private $active_guids_known = false; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @var Pool |
|
43 | - */ |
|
44 | - private $plugins_by_id; |
|
41 | + /** |
|
42 | + * @var Pool |
|
43 | + */ |
|
44 | + private $plugins_by_id; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @var PluginSettingsCache |
|
48 | - */ |
|
49 | - private $settings_cache; |
|
46 | + /** |
|
47 | + * @var PluginSettingsCache |
|
48 | + */ |
|
49 | + private $settings_cache; |
|
50 | 50 | |
51 | - /** |
|
52 | - * Constructor |
|
53 | - * |
|
54 | - * @param Pool $pool Cache for referencing plugins by ID |
|
55 | - * @param PluginSettingsCache $cache Plugin settings cache |
|
56 | - */ |
|
57 | - public function __construct(Pool $pool, PluginSettingsCache $cache) { |
|
58 | - $this->plugins_by_id = $pool; |
|
59 | - $this->settings_cache = $cache; |
|
60 | - } |
|
51 | + /** |
|
52 | + * Constructor |
|
53 | + * |
|
54 | + * @param Pool $pool Cache for referencing plugins by ID |
|
55 | + * @param PluginSettingsCache $cache Plugin settings cache |
|
56 | + */ |
|
57 | + public function __construct(Pool $pool, PluginSettingsCache $cache) { |
|
58 | + $this->plugins_by_id = $pool; |
|
59 | + $this->settings_cache = $cache; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Set the list of active plugins according to the boot data cache |
|
64 | - * |
|
65 | - * @param \ElggPlugin[] $plugins Set of active plugins |
|
66 | - * @return void |
|
67 | - */ |
|
68 | - public function setBootPlugins(array $plugins) { |
|
69 | - $this->boot_plugins = $plugins; |
|
70 | - foreach ($plugins as $plugin) { |
|
71 | - $this->plugins_by_id->put($plugin->getID(), $plugin); |
|
72 | - } |
|
73 | - } |
|
62 | + /** |
|
63 | + * Set the list of active plugins according to the boot data cache |
|
64 | + * |
|
65 | + * @param \ElggPlugin[] $plugins Set of active plugins |
|
66 | + * @return void |
|
67 | + */ |
|
68 | + public function setBootPlugins(array $plugins) { |
|
69 | + $this->boot_plugins = $plugins; |
|
70 | + foreach ($plugins as $plugin) { |
|
71 | + $this->plugins_by_id->put($plugin->getID(), $plugin); |
|
72 | + } |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Returns a list of plugin directory names from a base directory. |
|
77 | - * |
|
78 | - * @param string $dir A dir to scan for plugins. Defaults to config's plugins_path. |
|
79 | - * Must have a trailing slash. |
|
80 | - * |
|
81 | - * @return array Array of directory names (not full paths) |
|
82 | - * @access private |
|
83 | - */ |
|
84 | - function getDirsInDir($dir = null) { |
|
85 | - if (!$dir) { |
|
86 | - $dir = elgg_get_plugins_path(); |
|
87 | - } |
|
88 | - |
|
89 | - $plugin_dirs = []; |
|
90 | - $handle = opendir($dir); |
|
91 | - |
|
92 | - if ($handle) { |
|
93 | - while ($plugin_dir = readdir($handle)) { |
|
94 | - // must be directory and not begin with a . |
|
95 | - if (substr($plugin_dir, 0, 1) !== '.' && is_dir($dir . $plugin_dir)) { |
|
96 | - $plugin_dirs[] = $plugin_dir; |
|
97 | - } |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - sort($plugin_dirs); |
|
102 | - |
|
103 | - return $plugin_dirs; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Discovers plugins in the plugins_path setting and creates \ElggPlugin |
|
108 | - * entities for them if they don't exist. If there are plugins with entities |
|
109 | - * but not actual files, will disable the \ElggPlugin entities and mark as inactive. |
|
110 | - * The \ElggPlugin object holds config data, so don't delete. |
|
111 | - * |
|
112 | - * @return bool |
|
113 | - * @access private |
|
114 | - */ |
|
115 | - function generateEntities() { |
|
116 | - |
|
117 | - $mod_dir = elgg_get_plugins_path(); |
|
118 | - $db_prefix = _elgg_config()->dbprefix; |
|
119 | - |
|
120 | - // ignore access in case this is called with no admin logged in - needed for creating plugins perhaps? |
|
121 | - $old_ia = elgg_set_ignore_access(true); |
|
122 | - |
|
123 | - // show hidden entities so that we can enable them if appropriate |
|
124 | - $old_access = access_show_hidden_entities(true); |
|
125 | - |
|
126 | - $known_plugins = elgg_get_entities_from_relationship([ |
|
127 | - 'type' => 'object', |
|
128 | - 'subtype' => 'plugin', |
|
129 | - 'selects' => ['plugin_oe.*'], |
|
130 | - 'joins' => ["JOIN {$db_prefix}objects_entity plugin_oe on plugin_oe.guid = e.guid"], |
|
131 | - 'limit' => ELGG_ENTITIES_NO_VALUE, |
|
132 | - ]); |
|
133 | - /* @var \ElggPlugin[] $known_plugins */ |
|
134 | - |
|
135 | - if (!$known_plugins) { |
|
136 | - $known_plugins = []; |
|
137 | - } |
|
138 | - |
|
139 | - // map paths to indexes |
|
140 | - $id_map = []; |
|
141 | - foreach ($known_plugins as $i => $plugin) { |
|
142 | - // if the ID is wrong, delete the plugin because we can never load it. |
|
143 | - $id = $plugin->getID(); |
|
144 | - if (!$id) { |
|
145 | - $plugin->delete(); |
|
146 | - unset($known_plugins[$i]); |
|
147 | - continue; |
|
148 | - } |
|
149 | - $id_map[$plugin->getID()] = $i; |
|
150 | - } |
|
151 | - |
|
152 | - $physical_plugins = $this->getDirsInDir($mod_dir); |
|
153 | - if (!$physical_plugins) { |
|
154 | - return false; |
|
155 | - } |
|
156 | - |
|
157 | - // check real plugins against known ones |
|
158 | - foreach ($physical_plugins as $plugin_id) { |
|
159 | - // is this already in the db? |
|
160 | - if (array_key_exists($plugin_id, $id_map)) { |
|
161 | - $index = $id_map[$plugin_id]; |
|
162 | - $plugin = $known_plugins[$index]; |
|
163 | - // was this plugin deleted and its entity disabled? |
|
164 | - if (!$plugin->isEnabled()) { |
|
165 | - $plugin->enable(); |
|
166 | - $plugin->deactivate(); |
|
167 | - $plugin->setPriority('last'); |
|
168 | - } |
|
169 | - |
|
170 | - // remove from the list of plugins to disable |
|
171 | - unset($known_plugins[$index]); |
|
172 | - } else { |
|
173 | - // create new plugin |
|
174 | - // priority is forced to last in save() if not set. |
|
175 | - $plugin = new \ElggPlugin($mod_dir . $plugin_id); |
|
176 | - $plugin->save(); |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - // everything remaining in $known_plugins needs to be disabled |
|
181 | - // because they are entities, but their dirs were removed. |
|
182 | - // don't delete the entities because they hold settings. |
|
183 | - foreach ($known_plugins as $plugin) { |
|
184 | - if ($plugin->isActive()) { |
|
185 | - $plugin->deactivate(); |
|
186 | - } |
|
187 | - // remove the priority. |
|
188 | - $name = $this->namespacePrivateSetting('internal', 'priority'); |
|
189 | - remove_private_setting($plugin->guid, $name); |
|
190 | - if ($plugin->isEnabled()) { |
|
191 | - $plugin->disable(); |
|
192 | - } |
|
193 | - } |
|
194 | - |
|
195 | - access_show_hidden_entities($old_access); |
|
196 | - elgg_set_ignore_access($old_ia); |
|
197 | - |
|
198 | - return true; |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * Cache a reference to this plugin by its ID |
|
203 | - * |
|
204 | - * @param \ElggPlugin $plugin |
|
205 | - * |
|
206 | - * @access private |
|
207 | - */ |
|
208 | - function cache(\ElggPlugin $plugin) { |
|
209 | - $this->plugins_by_id->put($plugin->getID(), $plugin); |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Returns an \ElggPlugin object with the path $path. |
|
214 | - * |
|
215 | - * @param string $plugin_id The id (dir name) of the plugin. NOT the guid. |
|
216 | - * @return \ElggPlugin|null |
|
217 | - */ |
|
218 | - function get($plugin_id) { |
|
219 | - return $this->plugins_by_id->get($plugin_id, function () use ($plugin_id) { |
|
220 | - $plugin_id = sanitize_string($plugin_id); |
|
221 | - $db_prefix = _elgg_config()->dbprefix; |
|
75 | + /** |
|
76 | + * Returns a list of plugin directory names from a base directory. |
|
77 | + * |
|
78 | + * @param string $dir A dir to scan for plugins. Defaults to config's plugins_path. |
|
79 | + * Must have a trailing slash. |
|
80 | + * |
|
81 | + * @return array Array of directory names (not full paths) |
|
82 | + * @access private |
|
83 | + */ |
|
84 | + function getDirsInDir($dir = null) { |
|
85 | + if (!$dir) { |
|
86 | + $dir = elgg_get_plugins_path(); |
|
87 | + } |
|
88 | + |
|
89 | + $plugin_dirs = []; |
|
90 | + $handle = opendir($dir); |
|
91 | + |
|
92 | + if ($handle) { |
|
93 | + while ($plugin_dir = readdir($handle)) { |
|
94 | + // must be directory and not begin with a . |
|
95 | + if (substr($plugin_dir, 0, 1) !== '.' && is_dir($dir . $plugin_dir)) { |
|
96 | + $plugin_dirs[] = $plugin_dir; |
|
97 | + } |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + sort($plugin_dirs); |
|
102 | + |
|
103 | + return $plugin_dirs; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Discovers plugins in the plugins_path setting and creates \ElggPlugin |
|
108 | + * entities for them if they don't exist. If there are plugins with entities |
|
109 | + * but not actual files, will disable the \ElggPlugin entities and mark as inactive. |
|
110 | + * The \ElggPlugin object holds config data, so don't delete. |
|
111 | + * |
|
112 | + * @return bool |
|
113 | + * @access private |
|
114 | + */ |
|
115 | + function generateEntities() { |
|
116 | + |
|
117 | + $mod_dir = elgg_get_plugins_path(); |
|
118 | + $db_prefix = _elgg_config()->dbprefix; |
|
119 | + |
|
120 | + // ignore access in case this is called with no admin logged in - needed for creating plugins perhaps? |
|
121 | + $old_ia = elgg_set_ignore_access(true); |
|
122 | + |
|
123 | + // show hidden entities so that we can enable them if appropriate |
|
124 | + $old_access = access_show_hidden_entities(true); |
|
125 | + |
|
126 | + $known_plugins = elgg_get_entities_from_relationship([ |
|
127 | + 'type' => 'object', |
|
128 | + 'subtype' => 'plugin', |
|
129 | + 'selects' => ['plugin_oe.*'], |
|
130 | + 'joins' => ["JOIN {$db_prefix}objects_entity plugin_oe on plugin_oe.guid = e.guid"], |
|
131 | + 'limit' => ELGG_ENTITIES_NO_VALUE, |
|
132 | + ]); |
|
133 | + /* @var \ElggPlugin[] $known_plugins */ |
|
134 | + |
|
135 | + if (!$known_plugins) { |
|
136 | + $known_plugins = []; |
|
137 | + } |
|
138 | + |
|
139 | + // map paths to indexes |
|
140 | + $id_map = []; |
|
141 | + foreach ($known_plugins as $i => $plugin) { |
|
142 | + // if the ID is wrong, delete the plugin because we can never load it. |
|
143 | + $id = $plugin->getID(); |
|
144 | + if (!$id) { |
|
145 | + $plugin->delete(); |
|
146 | + unset($known_plugins[$i]); |
|
147 | + continue; |
|
148 | + } |
|
149 | + $id_map[$plugin->getID()] = $i; |
|
150 | + } |
|
151 | + |
|
152 | + $physical_plugins = $this->getDirsInDir($mod_dir); |
|
153 | + if (!$physical_plugins) { |
|
154 | + return false; |
|
155 | + } |
|
156 | + |
|
157 | + // check real plugins against known ones |
|
158 | + foreach ($physical_plugins as $plugin_id) { |
|
159 | + // is this already in the db? |
|
160 | + if (array_key_exists($plugin_id, $id_map)) { |
|
161 | + $index = $id_map[$plugin_id]; |
|
162 | + $plugin = $known_plugins[$index]; |
|
163 | + // was this plugin deleted and its entity disabled? |
|
164 | + if (!$plugin->isEnabled()) { |
|
165 | + $plugin->enable(); |
|
166 | + $plugin->deactivate(); |
|
167 | + $plugin->setPriority('last'); |
|
168 | + } |
|
169 | + |
|
170 | + // remove from the list of plugins to disable |
|
171 | + unset($known_plugins[$index]); |
|
172 | + } else { |
|
173 | + // create new plugin |
|
174 | + // priority is forced to last in save() if not set. |
|
175 | + $plugin = new \ElggPlugin($mod_dir . $plugin_id); |
|
176 | + $plugin->save(); |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + // everything remaining in $known_plugins needs to be disabled |
|
181 | + // because they are entities, but their dirs were removed. |
|
182 | + // don't delete the entities because they hold settings. |
|
183 | + foreach ($known_plugins as $plugin) { |
|
184 | + if ($plugin->isActive()) { |
|
185 | + $plugin->deactivate(); |
|
186 | + } |
|
187 | + // remove the priority. |
|
188 | + $name = $this->namespacePrivateSetting('internal', 'priority'); |
|
189 | + remove_private_setting($plugin->guid, $name); |
|
190 | + if ($plugin->isEnabled()) { |
|
191 | + $plugin->disable(); |
|
192 | + } |
|
193 | + } |
|
194 | + |
|
195 | + access_show_hidden_entities($old_access); |
|
196 | + elgg_set_ignore_access($old_ia); |
|
197 | + |
|
198 | + return true; |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * Cache a reference to this plugin by its ID |
|
203 | + * |
|
204 | + * @param \ElggPlugin $plugin |
|
205 | + * |
|
206 | + * @access private |
|
207 | + */ |
|
208 | + function cache(\ElggPlugin $plugin) { |
|
209 | + $this->plugins_by_id->put($plugin->getID(), $plugin); |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Returns an \ElggPlugin object with the path $path. |
|
214 | + * |
|
215 | + * @param string $plugin_id The id (dir name) of the plugin. NOT the guid. |
|
216 | + * @return \ElggPlugin|null |
|
217 | + */ |
|
218 | + function get($plugin_id) { |
|
219 | + return $this->plugins_by_id->get($plugin_id, function () use ($plugin_id) { |
|
220 | + $plugin_id = sanitize_string($plugin_id); |
|
221 | + $db_prefix = _elgg_config()->dbprefix; |
|
222 | 222 | |
223 | - $options = [ |
|
224 | - 'type' => 'object', |
|
225 | - 'subtype' => 'plugin', |
|
226 | - 'joins' => ["JOIN {$db_prefix}objects_entity oe on oe.guid = e.guid"], |
|
227 | - 'selects' => ["oe.title", "oe.description"], |
|
228 | - 'wheres' => ["oe.title = '$plugin_id'"], |
|
229 | - 'limit' => 1, |
|
230 | - 'distinct' => false, |
|
231 | - ]; |
|
223 | + $options = [ |
|
224 | + 'type' => 'object', |
|
225 | + 'subtype' => 'plugin', |
|
226 | + 'joins' => ["JOIN {$db_prefix}objects_entity oe on oe.guid = e.guid"], |
|
227 | + 'selects' => ["oe.title", "oe.description"], |
|
228 | + 'wheres' => ["oe.title = '$plugin_id'"], |
|
229 | + 'limit' => 1, |
|
230 | + 'distinct' => false, |
|
231 | + ]; |
|
232 | 232 | |
233 | - $plugins = elgg_get_entities($options); |
|
233 | + $plugins = elgg_get_entities($options); |
|
234 | 234 | |
235 | - if ($plugins) { |
|
236 | - return $plugins[0]; |
|
237 | - } |
|
235 | + if ($plugins) { |
|
236 | + return $plugins[0]; |
|
237 | + } |
|
238 | 238 | |
239 | - return null; |
|
240 | - }); |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * Returns if a plugin exists in the system. |
|
245 | - * |
|
246 | - * @warning This checks only plugins that are registered in the system! |
|
247 | - * If the plugin cache is outdated, be sure to regenerate it with |
|
248 | - * {@link _elgg_generate_plugin_objects()} first. |
|
249 | - * |
|
250 | - * @param string $id The plugin ID. |
|
251 | - * @return bool |
|
252 | - */ |
|
253 | - function exists($id) { |
|
254 | - return (bool) $this->get($id); |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Returns the highest priority of the plugins |
|
259 | - * |
|
260 | - * @return int |
|
261 | - * @access private |
|
262 | - */ |
|
263 | - function getMaxPriority() { |
|
264 | - $db_prefix = _elgg_config()->dbprefix; |
|
265 | - $priority = $this->namespacePrivateSetting('internal', 'priority'); |
|
266 | - $plugin_subtype = get_subtype_id('object', 'plugin'); |
|
267 | - |
|
268 | - $q = "SELECT MAX(CAST(ps.value AS unsigned)) as max |
|
239 | + return null; |
|
240 | + }); |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Returns if a plugin exists in the system. |
|
245 | + * |
|
246 | + * @warning This checks only plugins that are registered in the system! |
|
247 | + * If the plugin cache is outdated, be sure to regenerate it with |
|
248 | + * {@link _elgg_generate_plugin_objects()} first. |
|
249 | + * |
|
250 | + * @param string $id The plugin ID. |
|
251 | + * @return bool |
|
252 | + */ |
|
253 | + function exists($id) { |
|
254 | + return (bool) $this->get($id); |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Returns the highest priority of the plugins |
|
259 | + * |
|
260 | + * @return int |
|
261 | + * @access private |
|
262 | + */ |
|
263 | + function getMaxPriority() { |
|
264 | + $db_prefix = _elgg_config()->dbprefix; |
|
265 | + $priority = $this->namespacePrivateSetting('internal', 'priority'); |
|
266 | + $plugin_subtype = get_subtype_id('object', 'plugin'); |
|
267 | + |
|
268 | + $q = "SELECT MAX(CAST(ps.value AS unsigned)) as max |
|
269 | 269 | FROM {$db_prefix}entities e, {$db_prefix}private_settings ps |
270 | 270 | WHERE ps.name = '$priority' |
271 | 271 | AND ps.entity_guid = e.guid |
272 | 272 | AND e.type = 'object' and e.subtype = $plugin_subtype"; |
273 | 273 | |
274 | - $data = get_data($q); |
|
275 | - if ($data) { |
|
276 | - $max = $data[0]->max; |
|
277 | - } else { |
|
278 | - $max = 1; |
|
279 | - } |
|
280 | - |
|
281 | - // can't have a priority of 0. |
|
282 | - return ($max) ? $max : 1; |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * Returns if a plugin is active for a current site. |
|
287 | - * |
|
288 | - * @param string $plugin_id The plugin ID |
|
289 | - * @return bool |
|
290 | - */ |
|
291 | - function isActive($plugin_id) { |
|
292 | - if ($this->active_guids_known) { |
|
293 | - return isset($this->active_guids[$plugin_id]); |
|
294 | - } |
|
274 | + $data = get_data($q); |
|
275 | + if ($data) { |
|
276 | + $max = $data[0]->max; |
|
277 | + } else { |
|
278 | + $max = 1; |
|
279 | + } |
|
280 | + |
|
281 | + // can't have a priority of 0. |
|
282 | + return ($max) ? $max : 1; |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * Returns if a plugin is active for a current site. |
|
287 | + * |
|
288 | + * @param string $plugin_id The plugin ID |
|
289 | + * @return bool |
|
290 | + */ |
|
291 | + function isActive($plugin_id) { |
|
292 | + if ($this->active_guids_known) { |
|
293 | + return isset($this->active_guids[$plugin_id]); |
|
294 | + } |
|
295 | 295 | |
296 | - $site = elgg_get_site_entity(); |
|
297 | - |
|
298 | - if (!($site instanceof \ElggSite)) { |
|
299 | - return false; |
|
300 | - } |
|
301 | - |
|
302 | - $plugin = $this->get($plugin_id); |
|
303 | - |
|
304 | - if (!$plugin) { |
|
305 | - return false; |
|
306 | - } |
|
307 | - |
|
308 | - return $plugin->isActive($site->guid); |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * Loads all active plugins in the order specified in the tool admin panel. |
|
313 | - * |
|
314 | - * @note This is called on every page load. If a plugin is active and problematic, it |
|
315 | - * will be disabled and a visible error emitted. This does not check the deps system because |
|
316 | - * that was too slow. |
|
317 | - * |
|
318 | - * @return bool |
|
319 | - * @access private |
|
320 | - */ |
|
321 | - function load() { |
|
322 | - if ($this->timer) { |
|
323 | - $this->timer->begin([__METHOD__]); |
|
324 | - } |
|
296 | + $site = elgg_get_site_entity(); |
|
297 | + |
|
298 | + if (!($site instanceof \ElggSite)) { |
|
299 | + return false; |
|
300 | + } |
|
301 | + |
|
302 | + $plugin = $this->get($plugin_id); |
|
303 | + |
|
304 | + if (!$plugin) { |
|
305 | + return false; |
|
306 | + } |
|
307 | + |
|
308 | + return $plugin->isActive($site->guid); |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * Loads all active plugins in the order specified in the tool admin panel. |
|
313 | + * |
|
314 | + * @note This is called on every page load. If a plugin is active and problematic, it |
|
315 | + * will be disabled and a visible error emitted. This does not check the deps system because |
|
316 | + * that was too slow. |
|
317 | + * |
|
318 | + * @return bool |
|
319 | + * @access private |
|
320 | + */ |
|
321 | + function load() { |
|
322 | + if ($this->timer) { |
|
323 | + $this->timer->begin([__METHOD__]); |
|
324 | + } |
|
325 | 325 | |
326 | - $plugins_path = elgg_get_plugins_path(); |
|
327 | - $start_flags = ELGG_PLUGIN_INCLUDE_START | |
|
328 | - ELGG_PLUGIN_REGISTER_VIEWS | |
|
329 | - ELGG_PLUGIN_REGISTER_ACTIONS | |
|
330 | - ELGG_PLUGIN_REGISTER_LANGUAGES | |
|
331 | - ELGG_PLUGIN_REGISTER_WIDGETS | |
|
332 | - ELGG_PLUGIN_REGISTER_CLASSES; |
|
333 | - |
|
334 | - if (!$plugins_path) { |
|
335 | - return false; |
|
336 | - } |
|
337 | - |
|
338 | - // temporary disable all plugins if there is a file called 'disabled' in the plugin dir |
|
339 | - if (file_exists("$plugins_path/disabled")) { |
|
340 | - if (elgg_is_admin_logged_in() && elgg_in_context('admin')) { |
|
341 | - system_message(_elgg_services()->translator->translate('plugins:disabled')); |
|
342 | - } |
|
343 | - return false; |
|
344 | - } |
|
326 | + $plugins_path = elgg_get_plugins_path(); |
|
327 | + $start_flags = ELGG_PLUGIN_INCLUDE_START | |
|
328 | + ELGG_PLUGIN_REGISTER_VIEWS | |
|
329 | + ELGG_PLUGIN_REGISTER_ACTIONS | |
|
330 | + ELGG_PLUGIN_REGISTER_LANGUAGES | |
|
331 | + ELGG_PLUGIN_REGISTER_WIDGETS | |
|
332 | + ELGG_PLUGIN_REGISTER_CLASSES; |
|
333 | + |
|
334 | + if (!$plugins_path) { |
|
335 | + return false; |
|
336 | + } |
|
337 | + |
|
338 | + // temporary disable all plugins if there is a file called 'disabled' in the plugin dir |
|
339 | + if (file_exists("$plugins_path/disabled")) { |
|
340 | + if (elgg_is_admin_logged_in() && elgg_in_context('admin')) { |
|
341 | + system_message(_elgg_services()->translator->translate('plugins:disabled')); |
|
342 | + } |
|
343 | + return false; |
|
344 | + } |
|
345 | 345 | |
346 | - $config = _elgg_config(); |
|
346 | + $config = _elgg_config(); |
|
347 | 347 | |
348 | - if ($config->system_cache_loaded) { |
|
349 | - $start_flags = $start_flags & ~ELGG_PLUGIN_REGISTER_VIEWS; |
|
350 | - } |
|
348 | + if ($config->system_cache_loaded) { |
|
349 | + $start_flags = $start_flags & ~ELGG_PLUGIN_REGISTER_VIEWS; |
|
350 | + } |
|
351 | 351 | |
352 | - if (!empty($GLOBALS['_ELGG']->i18n_loaded_from_cache)) { |
|
353 | - $start_flags = $start_flags & ~ELGG_PLUGIN_REGISTER_LANGUAGES; |
|
354 | - } |
|
352 | + if (!empty($GLOBALS['_ELGG']->i18n_loaded_from_cache)) { |
|
353 | + $start_flags = $start_flags & ~ELGG_PLUGIN_REGISTER_LANGUAGES; |
|
354 | + } |
|
355 | 355 | |
356 | - $plugins = $this->boot_plugins; |
|
357 | - if (!$plugins) { |
|
358 | - $this->active_guids_known = true; |
|
359 | - return true; |
|
360 | - } |
|
356 | + $plugins = $this->boot_plugins; |
|
357 | + if (!$plugins) { |
|
358 | + $this->active_guids_known = true; |
|
359 | + return true; |
|
360 | + } |
|
361 | 361 | |
362 | - $return = true; |
|
363 | - foreach ($plugins as $plugin) { |
|
364 | - $id = $plugin->getID(); |
|
365 | - try { |
|
366 | - $plugin->start($start_flags); |
|
367 | - $this->active_guids[$id] = $plugin->guid; |
|
368 | - } catch (Exception $e) { |
|
369 | - $disable_plugins = _elgg_config()->auto_disable_plugins; |
|
370 | - if ($disable_plugins === null) { |
|
371 | - $disable_plugins = true; |
|
372 | - } |
|
373 | - if ($disable_plugins) { |
|
374 | - $plugin->deactivate(); |
|
362 | + $return = true; |
|
363 | + foreach ($plugins as $plugin) { |
|
364 | + $id = $plugin->getID(); |
|
365 | + try { |
|
366 | + $plugin->start($start_flags); |
|
367 | + $this->active_guids[$id] = $plugin->guid; |
|
368 | + } catch (Exception $e) { |
|
369 | + $disable_plugins = _elgg_config()->auto_disable_plugins; |
|
370 | + if ($disable_plugins === null) { |
|
371 | + $disable_plugins = true; |
|
372 | + } |
|
373 | + if ($disable_plugins) { |
|
374 | + $plugin->deactivate(); |
|
375 | 375 | |
376 | - $msg = _elgg_services()->translator->translate('PluginException:CannotStart', |
|
377 | - [$id, $plugin->guid, $e->getMessage()]); |
|
378 | - elgg_add_admin_notice("cannot_start $id", $msg); |
|
379 | - $return = false; |
|
380 | - } |
|
381 | - } |
|
382 | - } |
|
376 | + $msg = _elgg_services()->translator->translate('PluginException:CannotStart', |
|
377 | + [$id, $plugin->guid, $e->getMessage()]); |
|
378 | + elgg_add_admin_notice("cannot_start $id", $msg); |
|
379 | + $return = false; |
|
380 | + } |
|
381 | + } |
|
382 | + } |
|
383 | 383 | |
384 | - $this->active_guids_known = true; |
|
384 | + $this->active_guids_known = true; |
|
385 | 385 | |
386 | - if ($this->timer) { |
|
387 | - $this->timer->end([__METHOD__]); |
|
388 | - } |
|
389 | - return $return; |
|
390 | - } |
|
391 | - |
|
392 | - /** |
|
393 | - * Returns an ordered list of plugins |
|
394 | - * |
|
395 | - * @param string $status The status of the plugins. active, inactive, or all. |
|
396 | - * @return \ElggPlugin[] |
|
397 | - */ |
|
398 | - function find($status = 'active') { |
|
399 | - $db_prefix = elgg_get_config('dbprefix'); |
|
400 | - $priority = $this->namespacePrivateSetting('internal', 'priority'); |
|
401 | - $site_guid = 1; |
|
386 | + if ($this->timer) { |
|
387 | + $this->timer->end([__METHOD__]); |
|
388 | + } |
|
389 | + return $return; |
|
390 | + } |
|
391 | + |
|
392 | + /** |
|
393 | + * Returns an ordered list of plugins |
|
394 | + * |
|
395 | + * @param string $status The status of the plugins. active, inactive, or all. |
|
396 | + * @return \ElggPlugin[] |
|
397 | + */ |
|
398 | + function find($status = 'active') { |
|
399 | + $db_prefix = elgg_get_config('dbprefix'); |
|
400 | + $priority = $this->namespacePrivateSetting('internal', 'priority'); |
|
401 | + $site_guid = 1; |
|
402 | 402 | |
403 | - // grab plugins |
|
404 | - $options = [ |
|
405 | - 'type' => 'object', |
|
406 | - 'subtype' => 'plugin', |
|
407 | - 'limit' => ELGG_ENTITIES_NO_VALUE, |
|
408 | - 'selects' => ['plugin_oe.*', 'ps.value'], |
|
409 | - 'joins' => [ |
|
410 | - "JOIN {$db_prefix}private_settings ps on ps.entity_guid = e.guid", |
|
411 | - "JOIN {$db_prefix}objects_entity plugin_oe on plugin_oe.guid = e.guid" |
|
412 | - ], |
|
413 | - 'wheres' => ["ps.name = '$priority'"], |
|
414 | - // ORDER BY CAST(ps.value) is super slow. We usort() below. |
|
415 | - 'order_by' => false, |
|
416 | - 'distinct' => false, |
|
417 | - ]; |
|
418 | - |
|
419 | - switch ($status) { |
|
420 | - case 'active': |
|
421 | - $options['relationship'] = 'active_plugin'; |
|
422 | - $options['relationship_guid'] = $site_guid; |
|
423 | - $options['inverse_relationship'] = true; |
|
424 | - break; |
|
425 | - |
|
426 | - case 'inactive': |
|
427 | - $options['wheres'][] = "NOT EXISTS ( |
|
403 | + // grab plugins |
|
404 | + $options = [ |
|
405 | + 'type' => 'object', |
|
406 | + 'subtype' => 'plugin', |
|
407 | + 'limit' => ELGG_ENTITIES_NO_VALUE, |
|
408 | + 'selects' => ['plugin_oe.*', 'ps.value'], |
|
409 | + 'joins' => [ |
|
410 | + "JOIN {$db_prefix}private_settings ps on ps.entity_guid = e.guid", |
|
411 | + "JOIN {$db_prefix}objects_entity plugin_oe on plugin_oe.guid = e.guid" |
|
412 | + ], |
|
413 | + 'wheres' => ["ps.name = '$priority'"], |
|
414 | + // ORDER BY CAST(ps.value) is super slow. We usort() below. |
|
415 | + 'order_by' => false, |
|
416 | + 'distinct' => false, |
|
417 | + ]; |
|
418 | + |
|
419 | + switch ($status) { |
|
420 | + case 'active': |
|
421 | + $options['relationship'] = 'active_plugin'; |
|
422 | + $options['relationship_guid'] = $site_guid; |
|
423 | + $options['inverse_relationship'] = true; |
|
424 | + break; |
|
425 | + |
|
426 | + case 'inactive': |
|
427 | + $options['wheres'][] = "NOT EXISTS ( |
|
428 | 428 | SELECT 1 FROM {$db_prefix}entity_relationships active_er |
429 | 429 | WHERE active_er.guid_one = e.guid |
430 | 430 | AND active_er.relationship = 'active_plugin' |
431 | 431 | AND active_er.guid_two = $site_guid)"; |
432 | - break; |
|
432 | + break; |
|
433 | 433 | |
434 | - case 'all': |
|
435 | - default: |
|
436 | - break; |
|
437 | - } |
|
434 | + case 'all': |
|
435 | + default: |
|
436 | + break; |
|
437 | + } |
|
438 | 438 | |
439 | - $old_ia = elgg_set_ignore_access(true); |
|
440 | - $plugins = elgg_get_entities_from_relationship($options); |
|
441 | - elgg_set_ignore_access($old_ia); |
|
439 | + $old_ia = elgg_set_ignore_access(true); |
|
440 | + $plugins = elgg_get_entities_from_relationship($options); |
|
441 | + elgg_set_ignore_access($old_ia); |
|
442 | 442 | |
443 | - usort($plugins, function (\ElggPlugin $a, \ElggPlugin $b) { |
|
444 | - $a_value = $a->getVolatileData('select:value'); |
|
445 | - $b_value = $b->getVolatileData('select:value'); |
|
443 | + usort($plugins, function (\ElggPlugin $a, \ElggPlugin $b) { |
|
444 | + $a_value = $a->getVolatileData('select:value'); |
|
445 | + $b_value = $b->getVolatileData('select:value'); |
|
446 | 446 | |
447 | - if ($b_value !== $a_value) { |
|
448 | - return $a_value - $b_value; |
|
449 | - } else { |
|
450 | - return $a->guid - $b->guid; |
|
451 | - } |
|
452 | - }); |
|
453 | - |
|
454 | - return $plugins; |
|
455 | - } |
|
456 | - |
|
457 | - /** |
|
458 | - * Reorder plugins to an order specified by the array. |
|
459 | - * Plugins not included in this array will be appended to the end. |
|
460 | - * |
|
461 | - * @note This doesn't use the \ElggPlugin->setPriority() method because |
|
462 | - * all plugins are being changed and we don't want it to automatically |
|
463 | - * reorder plugins. |
|
464 | - * @todo Can this be done in a single sql command? |
|
465 | - * |
|
466 | - * @param array $order An array of plugin ids in the order to set them |
|
467 | - * @return bool |
|
468 | - * @access private |
|
469 | - */ |
|
470 | - function setPriorities(array $order) { |
|
471 | - $name = $this->namespacePrivateSetting('internal', 'priority'); |
|
472 | - |
|
473 | - $plugins = $this->find('any'); |
|
474 | - if (!$plugins) { |
|
475 | - return false; |
|
476 | - } |
|
477 | - |
|
478 | - // reindex to get standard counting. no need to increment by 10. |
|
479 | - // though we do start with 1 |
|
480 | - $order = array_values($order); |
|
481 | - |
|
482 | - $missing_plugins = []; |
|
483 | - /* @var \ElggPlugin[] $missing_plugins */ |
|
484 | - |
|
485 | - $priority = 0; |
|
486 | - foreach ($plugins as $plugin) { |
|
487 | - $plugin_id = $plugin->getID(); |
|
488 | - |
|
489 | - if (!in_array($plugin_id, $order)) { |
|
490 | - $missing_plugins[] = $plugin; |
|
491 | - continue; |
|
492 | - } |
|
493 | - |
|
494 | - $priority = array_search($plugin_id, $order) + 1; |
|
495 | - |
|
496 | - if (!$plugin->setPrivateSetting($name, $priority)) { |
|
497 | - return false; |
|
498 | - } |
|
499 | - } |
|
500 | - |
|
501 | - // set the missing plugins' priorities |
|
502 | - if (empty($missing_plugins)) { |
|
503 | - return true; |
|
504 | - } |
|
447 | + if ($b_value !== $a_value) { |
|
448 | + return $a_value - $b_value; |
|
449 | + } else { |
|
450 | + return $a->guid - $b->guid; |
|
451 | + } |
|
452 | + }); |
|
453 | + |
|
454 | + return $plugins; |
|
455 | + } |
|
456 | + |
|
457 | + /** |
|
458 | + * Reorder plugins to an order specified by the array. |
|
459 | + * Plugins not included in this array will be appended to the end. |
|
460 | + * |
|
461 | + * @note This doesn't use the \ElggPlugin->setPriority() method because |
|
462 | + * all plugins are being changed and we don't want it to automatically |
|
463 | + * reorder plugins. |
|
464 | + * @todo Can this be done in a single sql command? |
|
465 | + * |
|
466 | + * @param array $order An array of plugin ids in the order to set them |
|
467 | + * @return bool |
|
468 | + * @access private |
|
469 | + */ |
|
470 | + function setPriorities(array $order) { |
|
471 | + $name = $this->namespacePrivateSetting('internal', 'priority'); |
|
472 | + |
|
473 | + $plugins = $this->find('any'); |
|
474 | + if (!$plugins) { |
|
475 | + return false; |
|
476 | + } |
|
477 | + |
|
478 | + // reindex to get standard counting. no need to increment by 10. |
|
479 | + // though we do start with 1 |
|
480 | + $order = array_values($order); |
|
481 | + |
|
482 | + $missing_plugins = []; |
|
483 | + /* @var \ElggPlugin[] $missing_plugins */ |
|
484 | + |
|
485 | + $priority = 0; |
|
486 | + foreach ($plugins as $plugin) { |
|
487 | + $plugin_id = $plugin->getID(); |
|
488 | + |
|
489 | + if (!in_array($plugin_id, $order)) { |
|
490 | + $missing_plugins[] = $plugin; |
|
491 | + continue; |
|
492 | + } |
|
493 | + |
|
494 | + $priority = array_search($plugin_id, $order) + 1; |
|
495 | + |
|
496 | + if (!$plugin->setPrivateSetting($name, $priority)) { |
|
497 | + return false; |
|
498 | + } |
|
499 | + } |
|
500 | + |
|
501 | + // set the missing plugins' priorities |
|
502 | + if (empty($missing_plugins)) { |
|
503 | + return true; |
|
504 | + } |
|
505 | 505 | |
506 | - foreach ($missing_plugins as $plugin) { |
|
507 | - $priority++; |
|
508 | - if (!$plugin->setPrivateSetting($name, $priority)) { |
|
509 | - return false; |
|
510 | - } |
|
511 | - } |
|
512 | - |
|
513 | - return true; |
|
514 | - } |
|
515 | - |
|
516 | - /** |
|
517 | - * Reindexes all plugin priorities starting at 1. |
|
518 | - * |
|
519 | - * @return bool |
|
520 | - * @access private |
|
521 | - */ |
|
522 | - function reindexPriorities() { |
|
523 | - return $this->setPriorities([]); |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * Namespaces a string to be used as a private setting name for a plugin. |
|
528 | - * |
|
529 | - * For user_settings, two namespaces are added: a user setting namespace and the |
|
530 | - * plugin id. |
|
531 | - * |
|
532 | - * For internal (plugin priority), there is a single internal namespace added. |
|
533 | - * |
|
534 | - * @param string $type The type of setting: user_setting or internal. |
|
535 | - * @param string $name The name to namespace. |
|
536 | - * @param string $id The plugin's ID to namespace with. Required for user_setting. |
|
537 | - * @return string |
|
538 | - * @access private |
|
539 | - */ |
|
540 | - function namespacePrivateSetting($type, $name, $id = null) { |
|
541 | - switch ($type) { |
|
542 | - // commented out because it breaks $plugin->$name access to variables |
|
543 | - //case 'setting': |
|
544 | - // $name = ELGG_PLUGIN_SETTING_PREFIX . $name; |
|
545 | - // break; |
|
546 | - |
|
547 | - case 'user_setting': |
|
548 | - if (!$id) { |
|
549 | - throw new \InvalidArgumentException("You must pass the plugin id for user settings"); |
|
550 | - } |
|
551 | - $name = ELGG_PLUGIN_USER_SETTING_PREFIX . "$id:$name"; |
|
552 | - break; |
|
553 | - |
|
554 | - case 'internal': |
|
555 | - $name = ELGG_PLUGIN_INTERNAL_PREFIX . $name; |
|
556 | - break; |
|
557 | - } |
|
558 | - |
|
559 | - return $name; |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - /** |
|
564 | - * Returns an array of all provides from all active plugins. |
|
565 | - * |
|
566 | - * Array in the form array( |
|
567 | - * 'provide_type' => array( |
|
568 | - * 'provided_name' => array( |
|
569 | - * 'version' => '1.8', |
|
570 | - * 'provided_by' => 'provider_plugin_id' |
|
571 | - * ) |
|
572 | - * ) |
|
573 | - * ) |
|
574 | - * |
|
575 | - * @param string $type The type of provides to return |
|
576 | - * @param string $name A specific provided name to return. Requires $provide_type. |
|
577 | - * |
|
578 | - * @return array |
|
579 | - * @access private |
|
580 | - */ |
|
581 | - function getProvides($type = null, $name = null) { |
|
582 | - if ($this->provides_cache === null) { |
|
583 | - $active_plugins = $this->find('active'); |
|
506 | + foreach ($missing_plugins as $plugin) { |
|
507 | + $priority++; |
|
508 | + if (!$plugin->setPrivateSetting($name, $priority)) { |
|
509 | + return false; |
|
510 | + } |
|
511 | + } |
|
512 | + |
|
513 | + return true; |
|
514 | + } |
|
515 | + |
|
516 | + /** |
|
517 | + * Reindexes all plugin priorities starting at 1. |
|
518 | + * |
|
519 | + * @return bool |
|
520 | + * @access private |
|
521 | + */ |
|
522 | + function reindexPriorities() { |
|
523 | + return $this->setPriorities([]); |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * Namespaces a string to be used as a private setting name for a plugin. |
|
528 | + * |
|
529 | + * For user_settings, two namespaces are added: a user setting namespace and the |
|
530 | + * plugin id. |
|
531 | + * |
|
532 | + * For internal (plugin priority), there is a single internal namespace added. |
|
533 | + * |
|
534 | + * @param string $type The type of setting: user_setting or internal. |
|
535 | + * @param string $name The name to namespace. |
|
536 | + * @param string $id The plugin's ID to namespace with. Required for user_setting. |
|
537 | + * @return string |
|
538 | + * @access private |
|
539 | + */ |
|
540 | + function namespacePrivateSetting($type, $name, $id = null) { |
|
541 | + switch ($type) { |
|
542 | + // commented out because it breaks $plugin->$name access to variables |
|
543 | + //case 'setting': |
|
544 | + // $name = ELGG_PLUGIN_SETTING_PREFIX . $name; |
|
545 | + // break; |
|
546 | + |
|
547 | + case 'user_setting': |
|
548 | + if (!$id) { |
|
549 | + throw new \InvalidArgumentException("You must pass the plugin id for user settings"); |
|
550 | + } |
|
551 | + $name = ELGG_PLUGIN_USER_SETTING_PREFIX . "$id:$name"; |
|
552 | + break; |
|
553 | + |
|
554 | + case 'internal': |
|
555 | + $name = ELGG_PLUGIN_INTERNAL_PREFIX . $name; |
|
556 | + break; |
|
557 | + } |
|
558 | + |
|
559 | + return $name; |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + /** |
|
564 | + * Returns an array of all provides from all active plugins. |
|
565 | + * |
|
566 | + * Array in the form array( |
|
567 | + * 'provide_type' => array( |
|
568 | + * 'provided_name' => array( |
|
569 | + * 'version' => '1.8', |
|
570 | + * 'provided_by' => 'provider_plugin_id' |
|
571 | + * ) |
|
572 | + * ) |
|
573 | + * ) |
|
574 | + * |
|
575 | + * @param string $type The type of provides to return |
|
576 | + * @param string $name A specific provided name to return. Requires $provide_type. |
|
577 | + * |
|
578 | + * @return array |
|
579 | + * @access private |
|
580 | + */ |
|
581 | + function getProvides($type = null, $name = null) { |
|
582 | + if ($this->provides_cache === null) { |
|
583 | + $active_plugins = $this->find('active'); |
|
584 | 584 | |
585 | - $provides = []; |
|
586 | - |
|
587 | - foreach ($active_plugins as $plugin) { |
|
588 | - $plugin_provides = []; |
|
589 | - $manifest = $plugin->getManifest(); |
|
590 | - if ($manifest instanceof \ElggPluginManifest) { |
|
591 | - $plugin_provides = $plugin->getManifest()->getProvides(); |
|
592 | - } |
|
593 | - if ($plugin_provides) { |
|
594 | - foreach ($plugin_provides as $provided) { |
|
595 | - $provides[$provided['type']][$provided['name']] = [ |
|
596 | - 'version' => $provided['version'], |
|
597 | - 'provided_by' => $plugin->getID() |
|
598 | - ]; |
|
599 | - } |
|
600 | - } |
|
601 | - } |
|
585 | + $provides = []; |
|
586 | + |
|
587 | + foreach ($active_plugins as $plugin) { |
|
588 | + $plugin_provides = []; |
|
589 | + $manifest = $plugin->getManifest(); |
|
590 | + if ($manifest instanceof \ElggPluginManifest) { |
|
591 | + $plugin_provides = $plugin->getManifest()->getProvides(); |
|
592 | + } |
|
593 | + if ($plugin_provides) { |
|
594 | + foreach ($plugin_provides as $provided) { |
|
595 | + $provides[$provided['type']][$provided['name']] = [ |
|
596 | + 'version' => $provided['version'], |
|
597 | + 'provided_by' => $plugin->getID() |
|
598 | + ]; |
|
599 | + } |
|
600 | + } |
|
601 | + } |
|
602 | 602 | |
603 | - $this->provides_cache = $provides; |
|
604 | - } |
|
603 | + $this->provides_cache = $provides; |
|
604 | + } |
|
605 | 605 | |
606 | - if ($type && $name) { |
|
607 | - if (isset($this->provides_cache[$type][$name])) { |
|
608 | - return $this->provides_cache[$type][$name]; |
|
609 | - } else { |
|
610 | - return false; |
|
611 | - } |
|
612 | - } elseif ($type) { |
|
613 | - if (isset($this->provides_cache[$type])) { |
|
614 | - return $this->provides_cache[$type]; |
|
615 | - } else { |
|
616 | - return false; |
|
617 | - } |
|
618 | - } |
|
619 | - |
|
620 | - return $this->provides_cache; |
|
621 | - } |
|
622 | - |
|
623 | - /** |
|
624 | - * Deletes all cached data on plugins being provided. |
|
625 | - * |
|
626 | - * @return boolean |
|
627 | - * @access private |
|
628 | - */ |
|
629 | - function invalidateProvidesCache() { |
|
630 | - $this->provides_cache = null; |
|
631 | - return true; |
|
632 | - } |
|
606 | + if ($type && $name) { |
|
607 | + if (isset($this->provides_cache[$type][$name])) { |
|
608 | + return $this->provides_cache[$type][$name]; |
|
609 | + } else { |
|
610 | + return false; |
|
611 | + } |
|
612 | + } elseif ($type) { |
|
613 | + if (isset($this->provides_cache[$type])) { |
|
614 | + return $this->provides_cache[$type]; |
|
615 | + } else { |
|
616 | + return false; |
|
617 | + } |
|
618 | + } |
|
619 | + |
|
620 | + return $this->provides_cache; |
|
621 | + } |
|
622 | + |
|
623 | + /** |
|
624 | + * Deletes all cached data on plugins being provided. |
|
625 | + * |
|
626 | + * @return boolean |
|
627 | + * @access private |
|
628 | + */ |
|
629 | + function invalidateProvidesCache() { |
|
630 | + $this->provides_cache = null; |
|
631 | + return true; |
|
632 | + } |
|
633 | 633 | |
634 | - /** |
|
635 | - * Delete the cache holding whether plugins are active or not |
|
636 | - * |
|
637 | - * @return void |
|
638 | - * @access private |
|
639 | - */ |
|
640 | - public function invalidateIsActiveCache() { |
|
641 | - $this->active_guids = []; |
|
642 | - $this->active_guids_known = false; |
|
643 | - } |
|
644 | - |
|
645 | - /** |
|
646 | - * Checks if a plugin is currently providing $type and $name, and optionally |
|
647 | - * checking a version. |
|
648 | - * |
|
649 | - * @param string $type The type of the provide |
|
650 | - * @param string $name The name of the provide |
|
651 | - * @param string $version A version to check against |
|
652 | - * @param string $comparison The comparison operator to use in version_compare() |
|
653 | - * |
|
654 | - * @return array An array in the form array( |
|
655 | - * 'status' => bool Does the provide exist?, |
|
656 | - * 'value' => string The version provided |
|
657 | - * ) |
|
658 | - * @access private |
|
659 | - */ |
|
660 | - function checkProvides($type, $name, $version = null, $comparison = 'ge') { |
|
661 | - $provided = $this->getProvides($type, $name); |
|
662 | - if (!$provided) { |
|
663 | - return [ |
|
664 | - 'status' => false, |
|
665 | - 'value' => '' |
|
666 | - ]; |
|
667 | - } |
|
668 | - |
|
669 | - if ($version) { |
|
670 | - $status = version_compare($provided['version'], $version, $comparison); |
|
671 | - } else { |
|
672 | - $status = true; |
|
673 | - } |
|
674 | - |
|
675 | - return [ |
|
676 | - 'status' => $status, |
|
677 | - 'value' => $provided['version'] |
|
678 | - ]; |
|
679 | - } |
|
680 | - |
|
681 | - /** |
|
682 | - * Returns an array of parsed strings for a dependency in the |
|
683 | - * format: array( |
|
684 | - * 'type' => requires, conflicts, or provides. |
|
685 | - * 'name' => The name of the requirement / conflict |
|
686 | - * 'value' => A string representing the expected value: <1, >=3, !=enabled |
|
687 | - * 'local_value' => The current value, ("Not installed") |
|
688 | - * 'comment' => Free form text to help resovle the problem ("Enable / Search for plugin <link>") |
|
689 | - * ) |
|
690 | - * |
|
691 | - * @param array $dep An \ElggPluginPackage dependency array |
|
692 | - * @return array |
|
693 | - * @access private |
|
694 | - */ |
|
695 | - function getDependencyStrings($dep) { |
|
696 | - $translator = _elgg_services()->translator; |
|
697 | - $dep_system = elgg_extract('type', $dep); |
|
698 | - $info = elgg_extract('dep', $dep); |
|
699 | - $type = elgg_extract('type', $info); |
|
700 | - |
|
701 | - if (!$dep_system || !$info || !$type) { |
|
702 | - return false; |
|
703 | - } |
|
704 | - |
|
705 | - // rewrite some of these to be more readable |
|
706 | - $comparison = elgg_extract('comparison', $info); |
|
707 | - switch ($comparison) { |
|
708 | - case 'lt': |
|
709 | - $comparison = '<'; |
|
710 | - break; |
|
711 | - case 'gt': |
|
712 | - $comparison = '>'; |
|
713 | - break; |
|
714 | - case 'ge': |
|
715 | - $comparison = '>='; |
|
716 | - break; |
|
717 | - case 'le': |
|
718 | - $comparison = '<='; |
|
719 | - break; |
|
720 | - default: |
|
721 | - //keep $comparison value intact |
|
722 | - break; |
|
723 | - } |
|
724 | - |
|
725 | - /* |
|
634 | + /** |
|
635 | + * Delete the cache holding whether plugins are active or not |
|
636 | + * |
|
637 | + * @return void |
|
638 | + * @access private |
|
639 | + */ |
|
640 | + public function invalidateIsActiveCache() { |
|
641 | + $this->active_guids = []; |
|
642 | + $this->active_guids_known = false; |
|
643 | + } |
|
644 | + |
|
645 | + /** |
|
646 | + * Checks if a plugin is currently providing $type and $name, and optionally |
|
647 | + * checking a version. |
|
648 | + * |
|
649 | + * @param string $type The type of the provide |
|
650 | + * @param string $name The name of the provide |
|
651 | + * @param string $version A version to check against |
|
652 | + * @param string $comparison The comparison operator to use in version_compare() |
|
653 | + * |
|
654 | + * @return array An array in the form array( |
|
655 | + * 'status' => bool Does the provide exist?, |
|
656 | + * 'value' => string The version provided |
|
657 | + * ) |
|
658 | + * @access private |
|
659 | + */ |
|
660 | + function checkProvides($type, $name, $version = null, $comparison = 'ge') { |
|
661 | + $provided = $this->getProvides($type, $name); |
|
662 | + if (!$provided) { |
|
663 | + return [ |
|
664 | + 'status' => false, |
|
665 | + 'value' => '' |
|
666 | + ]; |
|
667 | + } |
|
668 | + |
|
669 | + if ($version) { |
|
670 | + $status = version_compare($provided['version'], $version, $comparison); |
|
671 | + } else { |
|
672 | + $status = true; |
|
673 | + } |
|
674 | + |
|
675 | + return [ |
|
676 | + 'status' => $status, |
|
677 | + 'value' => $provided['version'] |
|
678 | + ]; |
|
679 | + } |
|
680 | + |
|
681 | + /** |
|
682 | + * Returns an array of parsed strings for a dependency in the |
|
683 | + * format: array( |
|
684 | + * 'type' => requires, conflicts, or provides. |
|
685 | + * 'name' => The name of the requirement / conflict |
|
686 | + * 'value' => A string representing the expected value: <1, >=3, !=enabled |
|
687 | + * 'local_value' => The current value, ("Not installed") |
|
688 | + * 'comment' => Free form text to help resovle the problem ("Enable / Search for plugin <link>") |
|
689 | + * ) |
|
690 | + * |
|
691 | + * @param array $dep An \ElggPluginPackage dependency array |
|
692 | + * @return array |
|
693 | + * @access private |
|
694 | + */ |
|
695 | + function getDependencyStrings($dep) { |
|
696 | + $translator = _elgg_services()->translator; |
|
697 | + $dep_system = elgg_extract('type', $dep); |
|
698 | + $info = elgg_extract('dep', $dep); |
|
699 | + $type = elgg_extract('type', $info); |
|
700 | + |
|
701 | + if (!$dep_system || !$info || !$type) { |
|
702 | + return false; |
|
703 | + } |
|
704 | + |
|
705 | + // rewrite some of these to be more readable |
|
706 | + $comparison = elgg_extract('comparison', $info); |
|
707 | + switch ($comparison) { |
|
708 | + case 'lt': |
|
709 | + $comparison = '<'; |
|
710 | + break; |
|
711 | + case 'gt': |
|
712 | + $comparison = '>'; |
|
713 | + break; |
|
714 | + case 'ge': |
|
715 | + $comparison = '>='; |
|
716 | + break; |
|
717 | + case 'le': |
|
718 | + $comparison = '<='; |
|
719 | + break; |
|
720 | + default: |
|
721 | + //keep $comparison value intact |
|
722 | + break; |
|
723 | + } |
|
724 | + |
|
725 | + /* |
|
726 | 726 | 'requires' 'plugin oauth_lib' <1.3 1.3 'downgrade' |
727 | 727 | 'requires' 'php setting bob' >3 3 'change it' |
728 | 728 | 'conflicts' 'php setting' >3 4 'change it' |
@@ -730,304 +730,304 @@ discard block |
||
730 | 730 | 'provides' 'plugin oauth_lib' 1.3 -- -- |
731 | 731 | 'priority' 'before blog' -- after 'move it' |
732 | 732 | */ |
733 | - $strings = []; |
|
734 | - $strings['type'] = $translator->translate('ElggPlugin:Dependencies:' . ucwords($dep_system)); |
|
735 | - |
|
736 | - switch ($type) { |
|
737 | - case 'elgg_release': |
|
738 | - // 'Elgg Version' |
|
739 | - $strings['name'] = $translator->translate('ElggPlugin:Dependencies:Elgg'); |
|
740 | - $strings['expected_value'] = "$comparison {$info['version']}"; |
|
741 | - $strings['local_value'] = $dep['value']; |
|
742 | - $strings['comment'] = ''; |
|
743 | - break; |
|
744 | - |
|
745 | - case 'php_version': |
|
746 | - // 'PHP version' |
|
747 | - $strings['name'] = $translator->translate('ElggPlugin:Dependencies:PhpVersion'); |
|
748 | - $strings['expected_value'] = "$comparison {$info['version']}"; |
|
749 | - $strings['local_value'] = $dep['value']; |
|
750 | - $strings['comment'] = ''; |
|
751 | - break; |
|
733 | + $strings = []; |
|
734 | + $strings['type'] = $translator->translate('ElggPlugin:Dependencies:' . ucwords($dep_system)); |
|
735 | + |
|
736 | + switch ($type) { |
|
737 | + case 'elgg_release': |
|
738 | + // 'Elgg Version' |
|
739 | + $strings['name'] = $translator->translate('ElggPlugin:Dependencies:Elgg'); |
|
740 | + $strings['expected_value'] = "$comparison {$info['version']}"; |
|
741 | + $strings['local_value'] = $dep['value']; |
|
742 | + $strings['comment'] = ''; |
|
743 | + break; |
|
744 | + |
|
745 | + case 'php_version': |
|
746 | + // 'PHP version' |
|
747 | + $strings['name'] = $translator->translate('ElggPlugin:Dependencies:PhpVersion'); |
|
748 | + $strings['expected_value'] = "$comparison {$info['version']}"; |
|
749 | + $strings['local_value'] = $dep['value']; |
|
750 | + $strings['comment'] = ''; |
|
751 | + break; |
|
752 | 752 | |
753 | - case 'php_extension': |
|
754 | - // PHP Extension %s [version] |
|
755 | - $strings['name'] = $translator->translate('ElggPlugin:Dependencies:PhpExtension', [$info['name']]); |
|
756 | - if ($info['version']) { |
|
757 | - $strings['expected_value'] = "$comparison {$info['version']}"; |
|
758 | - $strings['local_value'] = $dep['value']; |
|
759 | - } else { |
|
760 | - $strings['expected_value'] = ''; |
|
761 | - $strings['local_value'] = ''; |
|
762 | - } |
|
763 | - $strings['comment'] = ''; |
|
764 | - break; |
|
765 | - |
|
766 | - case 'php_ini': |
|
767 | - $strings['name'] = $translator->translate('ElggPlugin:Dependencies:PhpIni', [$info['name']]); |
|
768 | - $strings['expected_value'] = "$comparison {$info['value']}"; |
|
769 | - $strings['local_value'] = $dep['value']; |
|
770 | - $strings['comment'] = ''; |
|
771 | - break; |
|
772 | - |
|
773 | - case 'plugin': |
|
774 | - $strings['name'] = $translator->translate('ElggPlugin:Dependencies:Plugin', [$info['name']]); |
|
775 | - $expected = $info['version'] ? "$comparison {$info['version']}" : $translator->translate('any'); |
|
776 | - $strings['expected_value'] = $expected; |
|
777 | - $strings['local_value'] = $dep['value'] ? $dep['value'] : '--'; |
|
778 | - $strings['comment'] = ''; |
|
779 | - break; |
|
780 | - |
|
781 | - case 'priority': |
|
782 | - $expected_priority = ucwords($info['priority']); |
|
783 | - $real_priority = ucwords($dep['value']); |
|
784 | - $strings['name'] = $translator->translate('ElggPlugin:Dependencies:Priority'); |
|
785 | - $strings['expected_value'] = $translator->translate("ElggPlugin:Dependencies:Priority:$expected_priority", [$info['plugin']]); |
|
786 | - $strings['local_value'] = $translator->translate("ElggPlugin:Dependencies:Priority:$real_priority", [$info['plugin']]); |
|
787 | - $strings['comment'] = ''; |
|
788 | - break; |
|
789 | - } |
|
790 | - |
|
791 | - if ($dep['type'] == 'suggests') { |
|
792 | - if ($dep['status']) { |
|
793 | - $strings['comment'] = $translator->translate('ok'); |
|
794 | - } else { |
|
795 | - $strings['comment'] = $translator->translate('ElggPlugin:Dependencies:Suggests:Unsatisfied'); |
|
796 | - } |
|
797 | - } else { |
|
798 | - if ($dep['status']) { |
|
799 | - $strings['comment'] = $translator->translate('ok'); |
|
800 | - } else { |
|
801 | - $strings['comment'] = $translator->translate('error'); |
|
802 | - } |
|
803 | - } |
|
804 | - |
|
805 | - return $strings; |
|
806 | - } |
|
807 | - |
|
808 | - /** |
|
809 | - * Returns an array of all plugin user settings for a user. |
|
810 | - * |
|
811 | - * @param int $user_guid The user GUID or 0 for the currently logged in user. |
|
812 | - * @param string $plugin_id The plugin ID (Required) |
|
813 | - * @param bool $return_obj Return settings as an object? This can be used to in reusable |
|
814 | - * views where the settings are passed as $vars['entity']. |
|
815 | - * @return array |
|
816 | - * @see \ElggPlugin::getAllUserSettings() |
|
817 | - */ |
|
818 | - function getAllUserSettings($user_guid = 0, $plugin_id = null, $return_obj = false) { |
|
819 | - $plugin = $this->get($plugin_id); |
|
820 | - if (!$plugin) { |
|
821 | - return false; |
|
822 | - } |
|
823 | - |
|
824 | - $settings = $plugin->getAllUserSettings((int) $user_guid); |
|
825 | - |
|
826 | - if ($settings && $return_obj) { |
|
827 | - $return = new \stdClass; |
|
828 | - |
|
829 | - foreach ($settings as $k => $v) { |
|
830 | - $return->$k = $v; |
|
831 | - } |
|
832 | - |
|
833 | - return $return; |
|
834 | - } else { |
|
835 | - return $settings; |
|
836 | - } |
|
837 | - } |
|
838 | - |
|
839 | - /** |
|
840 | - * Set a user specific setting for a plugin. |
|
841 | - * |
|
842 | - * @param string $name The name. Note: cannot be "title". |
|
843 | - * @param mixed $value The value. |
|
844 | - * @param int $user_guid The user GUID or 0 for the currently logged in user. |
|
845 | - * @param string $plugin_id The plugin ID (Required) |
|
846 | - * |
|
847 | - * @return bool |
|
848 | - * @see \ElggPlugin::setUserSetting() |
|
849 | - */ |
|
850 | - function setUserSetting($name, $value, $user_guid = 0, $plugin_id = null) { |
|
851 | - $plugin = $this->get($plugin_id); |
|
852 | - if (!$plugin) { |
|
853 | - return false; |
|
854 | - } |
|
753 | + case 'php_extension': |
|
754 | + // PHP Extension %s [version] |
|
755 | + $strings['name'] = $translator->translate('ElggPlugin:Dependencies:PhpExtension', [$info['name']]); |
|
756 | + if ($info['version']) { |
|
757 | + $strings['expected_value'] = "$comparison {$info['version']}"; |
|
758 | + $strings['local_value'] = $dep['value']; |
|
759 | + } else { |
|
760 | + $strings['expected_value'] = ''; |
|
761 | + $strings['local_value'] = ''; |
|
762 | + } |
|
763 | + $strings['comment'] = ''; |
|
764 | + break; |
|
765 | + |
|
766 | + case 'php_ini': |
|
767 | + $strings['name'] = $translator->translate('ElggPlugin:Dependencies:PhpIni', [$info['name']]); |
|
768 | + $strings['expected_value'] = "$comparison {$info['value']}"; |
|
769 | + $strings['local_value'] = $dep['value']; |
|
770 | + $strings['comment'] = ''; |
|
771 | + break; |
|
772 | + |
|
773 | + case 'plugin': |
|
774 | + $strings['name'] = $translator->translate('ElggPlugin:Dependencies:Plugin', [$info['name']]); |
|
775 | + $expected = $info['version'] ? "$comparison {$info['version']}" : $translator->translate('any'); |
|
776 | + $strings['expected_value'] = $expected; |
|
777 | + $strings['local_value'] = $dep['value'] ? $dep['value'] : '--'; |
|
778 | + $strings['comment'] = ''; |
|
779 | + break; |
|
780 | + |
|
781 | + case 'priority': |
|
782 | + $expected_priority = ucwords($info['priority']); |
|
783 | + $real_priority = ucwords($dep['value']); |
|
784 | + $strings['name'] = $translator->translate('ElggPlugin:Dependencies:Priority'); |
|
785 | + $strings['expected_value'] = $translator->translate("ElggPlugin:Dependencies:Priority:$expected_priority", [$info['plugin']]); |
|
786 | + $strings['local_value'] = $translator->translate("ElggPlugin:Dependencies:Priority:$real_priority", [$info['plugin']]); |
|
787 | + $strings['comment'] = ''; |
|
788 | + break; |
|
789 | + } |
|
790 | + |
|
791 | + if ($dep['type'] == 'suggests') { |
|
792 | + if ($dep['status']) { |
|
793 | + $strings['comment'] = $translator->translate('ok'); |
|
794 | + } else { |
|
795 | + $strings['comment'] = $translator->translate('ElggPlugin:Dependencies:Suggests:Unsatisfied'); |
|
796 | + } |
|
797 | + } else { |
|
798 | + if ($dep['status']) { |
|
799 | + $strings['comment'] = $translator->translate('ok'); |
|
800 | + } else { |
|
801 | + $strings['comment'] = $translator->translate('error'); |
|
802 | + } |
|
803 | + } |
|
804 | + |
|
805 | + return $strings; |
|
806 | + } |
|
807 | + |
|
808 | + /** |
|
809 | + * Returns an array of all plugin user settings for a user. |
|
810 | + * |
|
811 | + * @param int $user_guid The user GUID or 0 for the currently logged in user. |
|
812 | + * @param string $plugin_id The plugin ID (Required) |
|
813 | + * @param bool $return_obj Return settings as an object? This can be used to in reusable |
|
814 | + * views where the settings are passed as $vars['entity']. |
|
815 | + * @return array |
|
816 | + * @see \ElggPlugin::getAllUserSettings() |
|
817 | + */ |
|
818 | + function getAllUserSettings($user_guid = 0, $plugin_id = null, $return_obj = false) { |
|
819 | + $plugin = $this->get($plugin_id); |
|
820 | + if (!$plugin) { |
|
821 | + return false; |
|
822 | + } |
|
823 | + |
|
824 | + $settings = $plugin->getAllUserSettings((int) $user_guid); |
|
825 | + |
|
826 | + if ($settings && $return_obj) { |
|
827 | + $return = new \stdClass; |
|
828 | + |
|
829 | + foreach ($settings as $k => $v) { |
|
830 | + $return->$k = $v; |
|
831 | + } |
|
832 | + |
|
833 | + return $return; |
|
834 | + } else { |
|
835 | + return $settings; |
|
836 | + } |
|
837 | + } |
|
838 | + |
|
839 | + /** |
|
840 | + * Set a user specific setting for a plugin. |
|
841 | + * |
|
842 | + * @param string $name The name. Note: cannot be "title". |
|
843 | + * @param mixed $value The value. |
|
844 | + * @param int $user_guid The user GUID or 0 for the currently logged in user. |
|
845 | + * @param string $plugin_id The plugin ID (Required) |
|
846 | + * |
|
847 | + * @return bool |
|
848 | + * @see \ElggPlugin::setUserSetting() |
|
849 | + */ |
|
850 | + function setUserSetting($name, $value, $user_guid = 0, $plugin_id = null) { |
|
851 | + $plugin = $this->get($plugin_id); |
|
852 | + if (!$plugin) { |
|
853 | + return false; |
|
854 | + } |
|
855 | 855 | |
856 | - return $plugin->setUserSetting($name, $value, (int) $user_guid); |
|
857 | - } |
|
858 | - |
|
859 | - /** |
|
860 | - * Unsets a user-specific plugin setting |
|
861 | - * |
|
862 | - * @param string $name Name of the setting |
|
863 | - * @param int $user_guid The user GUID or 0 for the currently logged in user. |
|
864 | - * @param string $plugin_id The plugin ID (Required) |
|
865 | - * |
|
866 | - * @return bool |
|
867 | - * @see \ElggPlugin::unsetUserSetting() |
|
868 | - */ |
|
869 | - function unsetUserSetting($name, $user_guid = 0, $plugin_id = null) { |
|
870 | - $plugin = $this->get($plugin_id); |
|
871 | - if (!$plugin) { |
|
872 | - return false; |
|
873 | - } |
|
856 | + return $plugin->setUserSetting($name, $value, (int) $user_guid); |
|
857 | + } |
|
858 | + |
|
859 | + /** |
|
860 | + * Unsets a user-specific plugin setting |
|
861 | + * |
|
862 | + * @param string $name Name of the setting |
|
863 | + * @param int $user_guid The user GUID or 0 for the currently logged in user. |
|
864 | + * @param string $plugin_id The plugin ID (Required) |
|
865 | + * |
|
866 | + * @return bool |
|
867 | + * @see \ElggPlugin::unsetUserSetting() |
|
868 | + */ |
|
869 | + function unsetUserSetting($name, $user_guid = 0, $plugin_id = null) { |
|
870 | + $plugin = $this->get($plugin_id); |
|
871 | + if (!$plugin) { |
|
872 | + return false; |
|
873 | + } |
|
874 | 874 | |
875 | - return $plugin->unsetUserSetting($name, (int) $user_guid); |
|
876 | - } |
|
877 | - |
|
878 | - /** |
|
879 | - * Get a user specific setting for a plugin. |
|
880 | - * |
|
881 | - * @param string $name The name of the setting. |
|
882 | - * @param int $user_guid The user GUID or 0 for the currently logged in user. |
|
883 | - * @param string $plugin_id The plugin ID (Required) |
|
884 | - * @param mixed $default The default value to return if none is set |
|
885 | - * |
|
886 | - * @return mixed |
|
887 | - * @see \ElggPlugin::getUserSetting() |
|
888 | - */ |
|
889 | - function getUserSetting($name, $user_guid = 0, $plugin_id = null, $default = null) { |
|
890 | - $plugin = $this->get($plugin_id); |
|
891 | - if (!$plugin) { |
|
892 | - return false; |
|
893 | - } |
|
875 | + return $plugin->unsetUserSetting($name, (int) $user_guid); |
|
876 | + } |
|
877 | + |
|
878 | + /** |
|
879 | + * Get a user specific setting for a plugin. |
|
880 | + * |
|
881 | + * @param string $name The name of the setting. |
|
882 | + * @param int $user_guid The user GUID or 0 for the currently logged in user. |
|
883 | + * @param string $plugin_id The plugin ID (Required) |
|
884 | + * @param mixed $default The default value to return if none is set |
|
885 | + * |
|
886 | + * @return mixed |
|
887 | + * @see \ElggPlugin::getUserSetting() |
|
888 | + */ |
|
889 | + function getUserSetting($name, $user_guid = 0, $plugin_id = null, $default = null) { |
|
890 | + $plugin = $this->get($plugin_id); |
|
891 | + if (!$plugin) { |
|
892 | + return false; |
|
893 | + } |
|
894 | 894 | |
895 | - return $plugin->getUserSetting($name, (int) $user_guid, $default); |
|
896 | - } |
|
897 | - |
|
898 | - /** |
|
899 | - * Set a setting for a plugin. |
|
900 | - * |
|
901 | - * @param string $name The name of the setting - note, can't be "title". |
|
902 | - * @param mixed $value The value. |
|
903 | - * @param string $plugin_id The plugin ID (Required) |
|
904 | - * |
|
905 | - * @return bool |
|
906 | - * @see \ElggPlugin::setSetting() |
|
907 | - */ |
|
908 | - function setSetting($name, $value, $plugin_id) { |
|
909 | - $plugin = $this->get($plugin_id); |
|
910 | - if (!$plugin) { |
|
911 | - return false; |
|
912 | - } |
|
895 | + return $plugin->getUserSetting($name, (int) $user_guid, $default); |
|
896 | + } |
|
897 | + |
|
898 | + /** |
|
899 | + * Set a setting for a plugin. |
|
900 | + * |
|
901 | + * @param string $name The name of the setting - note, can't be "title". |
|
902 | + * @param mixed $value The value. |
|
903 | + * @param string $plugin_id The plugin ID (Required) |
|
904 | + * |
|
905 | + * @return bool |
|
906 | + * @see \ElggPlugin::setSetting() |
|
907 | + */ |
|
908 | + function setSetting($name, $value, $plugin_id) { |
|
909 | + $plugin = $this->get($plugin_id); |
|
910 | + if (!$plugin) { |
|
911 | + return false; |
|
912 | + } |
|
913 | 913 | |
914 | - return $plugin->setSetting($name, $value); |
|
915 | - } |
|
916 | - |
|
917 | - /** |
|
918 | - * Get setting for a plugin. |
|
919 | - * |
|
920 | - * @param string $name The name of the setting. |
|
921 | - * @param string $plugin_id The plugin ID (Required) |
|
922 | - * @param mixed $default The default value to return if none is set |
|
923 | - * |
|
924 | - * @return mixed |
|
925 | - * @see \ElggPlugin::getSetting() |
|
926 | - */ |
|
927 | - function getSetting($name, $plugin_id, $default = null) { |
|
928 | - $plugin = $this->get($plugin_id); |
|
929 | - if (!$plugin) { |
|
930 | - return false; |
|
931 | - } |
|
914 | + return $plugin->setSetting($name, $value); |
|
915 | + } |
|
916 | + |
|
917 | + /** |
|
918 | + * Get setting for a plugin. |
|
919 | + * |
|
920 | + * @param string $name The name of the setting. |
|
921 | + * @param string $plugin_id The plugin ID (Required) |
|
922 | + * @param mixed $default The default value to return if none is set |
|
923 | + * |
|
924 | + * @return mixed |
|
925 | + * @see \ElggPlugin::getSetting() |
|
926 | + */ |
|
927 | + function getSetting($name, $plugin_id, $default = null) { |
|
928 | + $plugin = $this->get($plugin_id); |
|
929 | + if (!$plugin) { |
|
930 | + return false; |
|
931 | + } |
|
932 | 932 | |
933 | - return $plugin->getSetting($name, $default); |
|
934 | - } |
|
935 | - |
|
936 | - /** |
|
937 | - * Unsets a plugin setting. |
|
938 | - * |
|
939 | - * @param string $name The name of the setting. |
|
940 | - * @param string $plugin_id The plugin ID (Required) |
|
941 | - * |
|
942 | - * @return bool |
|
943 | - * @see \ElggPlugin::unsetSetting() |
|
944 | - */ |
|
945 | - function unsetSetting($name, $plugin_id) { |
|
946 | - $plugin = $this->get($plugin_id); |
|
947 | - if (!$plugin) { |
|
948 | - return false; |
|
949 | - } |
|
933 | + return $plugin->getSetting($name, $default); |
|
934 | + } |
|
935 | + |
|
936 | + /** |
|
937 | + * Unsets a plugin setting. |
|
938 | + * |
|
939 | + * @param string $name The name of the setting. |
|
940 | + * @param string $plugin_id The plugin ID (Required) |
|
941 | + * |
|
942 | + * @return bool |
|
943 | + * @see \ElggPlugin::unsetSetting() |
|
944 | + */ |
|
945 | + function unsetSetting($name, $plugin_id) { |
|
946 | + $plugin = $this->get($plugin_id); |
|
947 | + if (!$plugin) { |
|
948 | + return false; |
|
949 | + } |
|
950 | 950 | |
951 | - return $plugin->unsetSetting($name); |
|
952 | - } |
|
953 | - |
|
954 | - /** |
|
955 | - * Unsets all plugin settings for a plugin. |
|
956 | - * |
|
957 | - * @param string $plugin_id The plugin ID (Required) |
|
958 | - * |
|
959 | - * @return bool |
|
960 | - * @see \ElggPlugin::unsetAllSettings() |
|
961 | - */ |
|
962 | - function unsetAllSettings($plugin_id) { |
|
963 | - $plugin = $this->get($plugin_id); |
|
964 | - if (!$plugin) { |
|
965 | - return false; |
|
966 | - } |
|
967 | - |
|
968 | - return $plugin->unsetAllSettings(); |
|
969 | - } |
|
970 | - |
|
971 | - /** |
|
972 | - * Returns entities based upon plugin user settings. |
|
973 | - * Takes all the options for {@link elgg_get_entities_from_private_settings()} |
|
974 | - * in addition to the ones below. |
|
975 | - * |
|
976 | - * @param array $options Array in the format: |
|
977 | - * |
|
978 | - * plugin_id => STR The plugin id. Required. |
|
979 | - * |
|
980 | - * plugin_user_setting_names => null|ARR private setting names |
|
981 | - * |
|
982 | - * plugin_user_setting_values => null|ARR metadata values |
|
983 | - * |
|
984 | - * plugin_user_setting_name_value_pairs => null|ARR ( |
|
985 | - * name => 'name', |
|
986 | - * value => 'value', |
|
987 | - * 'operand' => '=', |
|
988 | - * ) |
|
989 | - * Currently if multiple values are sent via |
|
990 | - * an array (value => array('value1', 'value2') |
|
991 | - * the pair's operand will be forced to "IN". |
|
992 | - * |
|
993 | - * plugin_user_setting_name_value_pairs_operator => null|STR The operator to use for combining |
|
994 | - * (name = value) OPERATOR (name = value); default AND |
|
995 | - * |
|
996 | - * @return mixed int If count, int. If not count, array. false on errors. |
|
997 | - */ |
|
998 | - function getEntitiesFromUserSettings(array $options = []) { |
|
999 | - $singulars = ['plugin_user_setting_name', 'plugin_user_setting_value', |
|
1000 | - 'plugin_user_setting_name_value_pair']; |
|
1001 | - |
|
1002 | - $options = _elgg_normalize_plural_options_array($options, $singulars); |
|
1003 | - |
|
1004 | - // rewrite plugin_user_setting_name_* to the right PS ones. |
|
1005 | - $map = [ |
|
1006 | - 'plugin_user_setting_names' => 'private_setting_names', |
|
1007 | - 'plugin_user_setting_values' => 'private_setting_values', |
|
1008 | - 'plugin_user_setting_name_value_pairs' => 'private_setting_name_value_pairs', |
|
1009 | - 'plugin_user_setting_name_value_pairs_operator' => 'private_setting_name_value_pairs_operator', |
|
1010 | - ]; |
|
1011 | - |
|
1012 | - foreach ($map as $plugin => $private) { |
|
1013 | - if (!isset($options[$plugin])) { |
|
1014 | - continue; |
|
1015 | - } |
|
1016 | - |
|
1017 | - if (isset($options[$private])) { |
|
1018 | - if (!is_array($options[$private])) { |
|
1019 | - $options[$private] = [$options[$private]]; |
|
1020 | - } |
|
1021 | - |
|
1022 | - $options[$private] = array_merge($options[$private], $options[$plugin]); |
|
1023 | - } else { |
|
1024 | - $options[$private] = $options[$plugin]; |
|
1025 | - } |
|
1026 | - } |
|
1027 | - |
|
1028 | - $prefix = $this->namespacePrivateSetting('user_setting', '', $options['plugin_id']); |
|
1029 | - $options['private_setting_name_prefix'] = $prefix; |
|
1030 | - |
|
1031 | - return elgg_get_entities_from_private_settings($options); |
|
1032 | - } |
|
951 | + return $plugin->unsetSetting($name); |
|
952 | + } |
|
953 | + |
|
954 | + /** |
|
955 | + * Unsets all plugin settings for a plugin. |
|
956 | + * |
|
957 | + * @param string $plugin_id The plugin ID (Required) |
|
958 | + * |
|
959 | + * @return bool |
|
960 | + * @see \ElggPlugin::unsetAllSettings() |
|
961 | + */ |
|
962 | + function unsetAllSettings($plugin_id) { |
|
963 | + $plugin = $this->get($plugin_id); |
|
964 | + if (!$plugin) { |
|
965 | + return false; |
|
966 | + } |
|
967 | + |
|
968 | + return $plugin->unsetAllSettings(); |
|
969 | + } |
|
970 | + |
|
971 | + /** |
|
972 | + * Returns entities based upon plugin user settings. |
|
973 | + * Takes all the options for {@link elgg_get_entities_from_private_settings()} |
|
974 | + * in addition to the ones below. |
|
975 | + * |
|
976 | + * @param array $options Array in the format: |
|
977 | + * |
|
978 | + * plugin_id => STR The plugin id. Required. |
|
979 | + * |
|
980 | + * plugin_user_setting_names => null|ARR private setting names |
|
981 | + * |
|
982 | + * plugin_user_setting_values => null|ARR metadata values |
|
983 | + * |
|
984 | + * plugin_user_setting_name_value_pairs => null|ARR ( |
|
985 | + * name => 'name', |
|
986 | + * value => 'value', |
|
987 | + * 'operand' => '=', |
|
988 | + * ) |
|
989 | + * Currently if multiple values are sent via |
|
990 | + * an array (value => array('value1', 'value2') |
|
991 | + * the pair's operand will be forced to "IN". |
|
992 | + * |
|
993 | + * plugin_user_setting_name_value_pairs_operator => null|STR The operator to use for combining |
|
994 | + * (name = value) OPERATOR (name = value); default AND |
|
995 | + * |
|
996 | + * @return mixed int If count, int. If not count, array. false on errors. |
|
997 | + */ |
|
998 | + function getEntitiesFromUserSettings(array $options = []) { |
|
999 | + $singulars = ['plugin_user_setting_name', 'plugin_user_setting_value', |
|
1000 | + 'plugin_user_setting_name_value_pair']; |
|
1001 | + |
|
1002 | + $options = _elgg_normalize_plural_options_array($options, $singulars); |
|
1003 | + |
|
1004 | + // rewrite plugin_user_setting_name_* to the right PS ones. |
|
1005 | + $map = [ |
|
1006 | + 'plugin_user_setting_names' => 'private_setting_names', |
|
1007 | + 'plugin_user_setting_values' => 'private_setting_values', |
|
1008 | + 'plugin_user_setting_name_value_pairs' => 'private_setting_name_value_pairs', |
|
1009 | + 'plugin_user_setting_name_value_pairs_operator' => 'private_setting_name_value_pairs_operator', |
|
1010 | + ]; |
|
1011 | + |
|
1012 | + foreach ($map as $plugin => $private) { |
|
1013 | + if (!isset($options[$plugin])) { |
|
1014 | + continue; |
|
1015 | + } |
|
1016 | + |
|
1017 | + if (isset($options[$private])) { |
|
1018 | + if (!is_array($options[$private])) { |
|
1019 | + $options[$private] = [$options[$private]]; |
|
1020 | + } |
|
1021 | + |
|
1022 | + $options[$private] = array_merge($options[$private], $options[$plugin]); |
|
1023 | + } else { |
|
1024 | + $options[$private] = $options[$plugin]; |
|
1025 | + } |
|
1026 | + } |
|
1027 | + |
|
1028 | + $prefix = $this->namespacePrivateSetting('user_setting', '', $options['plugin_id']); |
|
1029 | + $options['private_setting_name_prefix'] = $prefix; |
|
1030 | + |
|
1031 | + return elgg_get_entities_from_private_settings($options); |
|
1032 | + } |
|
1033 | 1033 | } |
@@ -16,13 +16,13 @@ discard block |
||
16 | 16 | * @todo used by elgg_get_upgrade_files |
17 | 17 | */ |
18 | 18 | function elgg_get_upgrade_file_version($filename) { |
19 | - preg_match('/^([0-9]{10})([\.a-z0-9-_]+)?\.(php)$/i', $filename, $matches); |
|
19 | + preg_match('/^([0-9]{10})([\.a-z0-9-_]+)?\.(php)$/i', $filename, $matches); |
|
20 | 20 | |
21 | - if (isset($matches[1])) { |
|
22 | - return (int) $matches[1]; |
|
23 | - } |
|
21 | + if (isset($matches[1])) { |
|
22 | + return (int) $matches[1]; |
|
23 | + } |
|
24 | 24 | |
25 | - return false; |
|
25 | + return false; |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -35,33 +35,33 @@ discard block |
||
35 | 35 | * @todo the wire and groups plugins and the installer are using this |
36 | 36 | */ |
37 | 37 | function elgg_get_upgrade_files($upgrade_path = null) { |
38 | - if (!$upgrade_path) { |
|
39 | - $upgrade_path = elgg_get_engine_path() . '/lib/upgrades/'; |
|
40 | - } |
|
41 | - $upgrade_path = sanitise_filepath($upgrade_path); |
|
42 | - $handle = opendir($upgrade_path); |
|
38 | + if (!$upgrade_path) { |
|
39 | + $upgrade_path = elgg_get_engine_path() . '/lib/upgrades/'; |
|
40 | + } |
|
41 | + $upgrade_path = sanitise_filepath($upgrade_path); |
|
42 | + $handle = opendir($upgrade_path); |
|
43 | 43 | |
44 | - if (!$handle) { |
|
45 | - return false; |
|
46 | - } |
|
44 | + if (!$handle) { |
|
45 | + return false; |
|
46 | + } |
|
47 | 47 | |
48 | - $upgrade_files = []; |
|
48 | + $upgrade_files = []; |
|
49 | 49 | |
50 | - while ($upgrade_file = readdir($handle)) { |
|
51 | - // make sure this is a well formed upgrade. |
|
52 | - if (is_dir($upgrade_path . '$upgrade_file')) { |
|
53 | - continue; |
|
54 | - } |
|
55 | - $upgrade_version = elgg_get_upgrade_file_version($upgrade_file); |
|
56 | - if (!$upgrade_version) { |
|
57 | - continue; |
|
58 | - } |
|
59 | - $upgrade_files[] = $upgrade_file; |
|
60 | - } |
|
50 | + while ($upgrade_file = readdir($handle)) { |
|
51 | + // make sure this is a well formed upgrade. |
|
52 | + if (is_dir($upgrade_path . '$upgrade_file')) { |
|
53 | + continue; |
|
54 | + } |
|
55 | + $upgrade_version = elgg_get_upgrade_file_version($upgrade_file); |
|
56 | + if (!$upgrade_version) { |
|
57 | + continue; |
|
58 | + } |
|
59 | + $upgrade_files[] = $upgrade_file; |
|
60 | + } |
|
61 | 61 | |
62 | - sort($upgrade_files); |
|
62 | + sort($upgrade_files); |
|
63 | 63 | |
64 | - return $upgrade_files; |
|
64 | + return $upgrade_files; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | * @todo the hack in the 2011010101 upgrade requires this |
73 | 73 | */ |
74 | 74 | function _elgg_upgrade_unlock() { |
75 | - $prefix = _elgg_config()->dbprefix; |
|
76 | - delete_data("drop table {$prefix}upgrade_lock"); |
|
77 | - elgg_log('Upgrade unlocked.', 'NOTICE'); |
|
75 | + $prefix = _elgg_config()->dbprefix; |
|
76 | + delete_data("drop table {$prefix}upgrade_lock"); |
|
77 | + elgg_log('Upgrade unlocked.', 'NOTICE'); |
|
78 | 78 | } |
@@ -10,57 +10,57 @@ discard block |
||
10 | 10 | */ |
11 | 11 | function discussion_init() { |
12 | 12 | |
13 | - elgg_register_page_handler('discussion', 'discussion_page_handler'); |
|
13 | + elgg_register_page_handler('discussion', 'discussion_page_handler'); |
|
14 | 14 | |
15 | - elgg_register_plugin_hook_handler('entity:url', 'object', 'discussion_set_topic_url'); |
|
15 | + elgg_register_plugin_hook_handler('entity:url', 'object', 'discussion_set_topic_url'); |
|
16 | 16 | |
17 | - // commenting not allowed on discussion topics (use a different annotation) |
|
18 | - elgg_register_plugin_hook_handler('permissions_check:comment', 'object', 'discussion_comment_override'); |
|
19 | - elgg_register_plugin_hook_handler('permissions_check', 'object', 'discussion_can_edit_reply'); |
|
17 | + // commenting not allowed on discussion topics (use a different annotation) |
|
18 | + elgg_register_plugin_hook_handler('permissions_check:comment', 'object', 'discussion_comment_override'); |
|
19 | + elgg_register_plugin_hook_handler('permissions_check', 'object', 'discussion_can_edit_reply'); |
|
20 | 20 | |
21 | - // discussion reply menu |
|
22 | - elgg_register_plugin_hook_handler('register', 'menu:entity', 'discussion_reply_menu_setup'); |
|
21 | + // discussion reply menu |
|
22 | + elgg_register_plugin_hook_handler('register', 'menu:entity', 'discussion_reply_menu_setup'); |
|
23 | 23 | |
24 | - // allow non-owners to add replies to discussion |
|
25 | - elgg_register_plugin_hook_handler('container_logic_check', 'object', 'discussion_reply_container_logic_override'); |
|
26 | - elgg_register_plugin_hook_handler('container_permissions_check', 'object', 'discussion_reply_container_permissions_override'); |
|
24 | + // allow non-owners to add replies to discussion |
|
25 | + elgg_register_plugin_hook_handler('container_logic_check', 'object', 'discussion_reply_container_logic_override'); |
|
26 | + elgg_register_plugin_hook_handler('container_permissions_check', 'object', 'discussion_reply_container_permissions_override'); |
|
27 | 27 | |
28 | - elgg_register_event_handler('update:after', 'object', 'discussion_update_reply_access_ids'); |
|
28 | + elgg_register_event_handler('update:after', 'object', 'discussion_update_reply_access_ids'); |
|
29 | 29 | |
30 | - // add link to owner block |
|
31 | - elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'discussion_owner_block_menu'); |
|
30 | + // add link to owner block |
|
31 | + elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'discussion_owner_block_menu'); |
|
32 | 32 | |
33 | - // Register for search. |
|
34 | - elgg_register_plugin_hook_handler('search', 'object:discussion', 'discussion_search_discussion'); |
|
33 | + // Register for search. |
|
34 | + elgg_register_plugin_hook_handler('search', 'object:discussion', 'discussion_search_discussion'); |
|
35 | 35 | |
36 | - // because replies are not comments, need of our menu item |
|
37 | - elgg_register_plugin_hook_handler('register', 'menu:river', 'discussion_add_to_river_menu'); |
|
36 | + // because replies are not comments, need of our menu item |
|
37 | + elgg_register_plugin_hook_handler('register', 'menu:river', 'discussion_add_to_river_menu'); |
|
38 | 38 | |
39 | - // add the forum tool option |
|
40 | - add_group_tool_option('forum', elgg_echo('groups:enableforum'), true); |
|
41 | - elgg_extend_view('groups/tool_latest', 'discussion/group_module'); |
|
39 | + // add the forum tool option |
|
40 | + add_group_tool_option('forum', elgg_echo('groups:enableforum'), true); |
|
41 | + elgg_extend_view('groups/tool_latest', 'discussion/group_module'); |
|
42 | 42 | |
43 | - // TODO remove in 3.0 |
|
44 | - elgg_register_js('elgg.discussion', elgg_get_simplecache_url('discussion/discussion.js')); |
|
43 | + // TODO remove in 3.0 |
|
44 | + elgg_register_js('elgg.discussion', elgg_get_simplecache_url('discussion/discussion.js')); |
|
45 | 45 | |
46 | - elgg_register_ajax_view('ajax/discussion/reply/edit'); |
|
46 | + elgg_register_ajax_view('ajax/discussion/reply/edit'); |
|
47 | 47 | |
48 | - // notifications |
|
49 | - elgg_register_plugin_hook_handler('get', 'subscriptions', 'discussion_get_subscriptions'); |
|
50 | - elgg_register_notification_event('object', 'discussion'); |
|
51 | - elgg_register_plugin_hook_handler('prepare', 'notification:create:object:discussion', 'discussion_prepare_notification'); |
|
52 | - elgg_register_notification_event('object', 'discussion_reply'); |
|
53 | - elgg_register_plugin_hook_handler('prepare', 'notification:create:object:discussion_reply', 'discussion_prepare_reply_notification'); |
|
48 | + // notifications |
|
49 | + elgg_register_plugin_hook_handler('get', 'subscriptions', 'discussion_get_subscriptions'); |
|
50 | + elgg_register_notification_event('object', 'discussion'); |
|
51 | + elgg_register_plugin_hook_handler('prepare', 'notification:create:object:discussion', 'discussion_prepare_notification'); |
|
52 | + elgg_register_notification_event('object', 'discussion_reply'); |
|
53 | + elgg_register_plugin_hook_handler('prepare', 'notification:create:object:discussion_reply', 'discussion_prepare_reply_notification'); |
|
54 | 54 | |
55 | - // allow ecml in discussion |
|
56 | - elgg_register_plugin_hook_handler('get_views', 'ecml', 'discussion_ecml_views_hook'); |
|
55 | + // allow ecml in discussion |
|
56 | + elgg_register_plugin_hook_handler('get_views', 'ecml', 'discussion_ecml_views_hook'); |
|
57 | 57 | |
58 | - // allow to be liked |
|
59 | - elgg_register_plugin_hook_handler('likes:is_likable', 'object:discussion', 'Elgg\Values::getTrue'); |
|
60 | - elgg_register_plugin_hook_handler('likes:is_likable', 'object:discussion_reply', 'Elgg\Values::getTrue'); |
|
58 | + // allow to be liked |
|
59 | + elgg_register_plugin_hook_handler('likes:is_likable', 'object:discussion', 'Elgg\Values::getTrue'); |
|
60 | + elgg_register_plugin_hook_handler('likes:is_likable', 'object:discussion_reply', 'Elgg\Values::getTrue'); |
|
61 | 61 | |
62 | - // Add latest discussions tab to /groups/all page |
|
63 | - elgg_register_plugin_hook_handler('register', 'menu:filter:groups/all', 'discussion_setup_groups_filter_tabs'); |
|
62 | + // Add latest discussions tab to /groups/all page |
|
63 | + elgg_register_plugin_hook_handler('register', 'menu:filter:groups/all', 'discussion_setup_groups_filter_tabs'); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -78,59 +78,59 @@ discard block |
||
78 | 78 | */ |
79 | 79 | function discussion_page_handler($page) { |
80 | 80 | |
81 | - if (!isset($page[0])) { |
|
82 | - $page[0] = 'all'; |
|
83 | - } |
|
84 | - |
|
85 | - elgg_push_breadcrumb(elgg_echo('discussion'), 'discussion/all'); |
|
86 | - |
|
87 | - switch ($page[0]) { |
|
88 | - case 'all': |
|
89 | - echo elgg_view_resource('discussion/all'); |
|
90 | - break; |
|
91 | - case 'owner': |
|
92 | - echo elgg_view_resource('discussion/owner', [ |
|
93 | - 'guid' => elgg_extract(1, $page), |
|
94 | - ]); |
|
95 | - break; |
|
96 | - case 'group': |
|
97 | - echo elgg_view_resource('discussion/group', [ |
|
98 | - 'guid' => elgg_extract(1, $page), |
|
99 | - ]); |
|
100 | - break; |
|
101 | - case 'add': |
|
102 | - echo elgg_view_resource('discussion/add', [ |
|
103 | - 'guid' => elgg_extract(1, $page), |
|
104 | - ]); |
|
105 | - break; |
|
106 | - case 'reply': |
|
107 | - switch (elgg_extract(1, $page)) { |
|
108 | - case 'edit': |
|
109 | - echo elgg_view_resource('discussion/reply/edit', [ |
|
110 | - 'guid' => elgg_extract(2, $page), |
|
111 | - ]); |
|
112 | - break; |
|
113 | - case 'view': |
|
114 | - discussion_redirect_to_reply(elgg_extract(2, $page), elgg_extract(3, $page)); |
|
115 | - break; |
|
116 | - default: |
|
117 | - return false; |
|
118 | - } |
|
119 | - break; |
|
120 | - case 'edit': |
|
121 | - echo elgg_view_resource('discussion/edit', [ |
|
122 | - 'guid' => elgg_extract(1, $page), |
|
123 | - ]); |
|
124 | - break; |
|
125 | - case 'view': |
|
126 | - echo elgg_view_resource('discussion/view', [ |
|
127 | - 'guid' => elgg_extract(1, $page), |
|
128 | - ]); |
|
129 | - break; |
|
130 | - default: |
|
131 | - return false; |
|
132 | - } |
|
133 | - return true; |
|
81 | + if (!isset($page[0])) { |
|
82 | + $page[0] = 'all'; |
|
83 | + } |
|
84 | + |
|
85 | + elgg_push_breadcrumb(elgg_echo('discussion'), 'discussion/all'); |
|
86 | + |
|
87 | + switch ($page[0]) { |
|
88 | + case 'all': |
|
89 | + echo elgg_view_resource('discussion/all'); |
|
90 | + break; |
|
91 | + case 'owner': |
|
92 | + echo elgg_view_resource('discussion/owner', [ |
|
93 | + 'guid' => elgg_extract(1, $page), |
|
94 | + ]); |
|
95 | + break; |
|
96 | + case 'group': |
|
97 | + echo elgg_view_resource('discussion/group', [ |
|
98 | + 'guid' => elgg_extract(1, $page), |
|
99 | + ]); |
|
100 | + break; |
|
101 | + case 'add': |
|
102 | + echo elgg_view_resource('discussion/add', [ |
|
103 | + 'guid' => elgg_extract(1, $page), |
|
104 | + ]); |
|
105 | + break; |
|
106 | + case 'reply': |
|
107 | + switch (elgg_extract(1, $page)) { |
|
108 | + case 'edit': |
|
109 | + echo elgg_view_resource('discussion/reply/edit', [ |
|
110 | + 'guid' => elgg_extract(2, $page), |
|
111 | + ]); |
|
112 | + break; |
|
113 | + case 'view': |
|
114 | + discussion_redirect_to_reply(elgg_extract(2, $page), elgg_extract(3, $page)); |
|
115 | + break; |
|
116 | + default: |
|
117 | + return false; |
|
118 | + } |
|
119 | + break; |
|
120 | + case 'edit': |
|
121 | + echo elgg_view_resource('discussion/edit', [ |
|
122 | + 'guid' => elgg_extract(1, $page), |
|
123 | + ]); |
|
124 | + break; |
|
125 | + case 'view': |
|
126 | + echo elgg_view_resource('discussion/view', [ |
|
127 | + 'guid' => elgg_extract(1, $page), |
|
128 | + ]); |
|
129 | + break; |
|
130 | + default: |
|
131 | + return false; |
|
132 | + } |
|
133 | + return true; |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -143,57 +143,57 @@ discard block |
||
143 | 143 | * @access private |
144 | 144 | */ |
145 | 145 | function discussion_redirect_to_reply($reply_guid, $fallback_guid) { |
146 | - $fail = function () { |
|
147 | - register_error(elgg_echo('discussion:reply:error:notfound')); |
|
148 | - forward(REFERER); |
|
149 | - }; |
|
150 | - |
|
151 | - $reply = get_entity($reply_guid); |
|
152 | - if (!$reply) { |
|
153 | - // try fallback |
|
154 | - $fallback = get_entity($fallback_guid); |
|
155 | - if (!elgg_instanceof($fallback, 'object', 'discussion')) { |
|
156 | - $fail(); |
|
157 | - } |
|
158 | - |
|
159 | - register_error(elgg_echo('discussion:reply:error:notfound_fallback')); |
|
160 | - forward($fallback->getURL()); |
|
161 | - } |
|
162 | - |
|
163 | - if (!elgg_instanceof($reply, 'object', 'discussion_reply')) { |
|
164 | - $fail(); |
|
165 | - } |
|
166 | - |
|
167 | - // start with topic URL |
|
168 | - $topic = $reply->getContainerEntity(); |
|
169 | - |
|
170 | - // this won't work with threaded comments, but core doesn't support that yet |
|
171 | - $count = elgg_get_entities([ |
|
172 | - 'type' => 'object', |
|
173 | - 'subtype' => $reply->getSubtype(), |
|
174 | - 'container_guid' => $topic->guid, |
|
175 | - 'count' => true, |
|
176 | - 'wheres' => ["e.guid < " . (int) $reply->guid], |
|
177 | - ]); |
|
178 | - $limit = (int) get_input('limit', 0); |
|
179 | - if (!$limit) { |
|
180 | - $limit = _elgg_config()->default_limit; |
|
181 | - } |
|
182 | - $offset = floor($count / $limit) * $limit; |
|
183 | - if (!$offset) { |
|
184 | - $offset = null; |
|
185 | - } |
|
186 | - |
|
187 | - $url = elgg_http_add_url_query_elements($topic->getURL(), [ |
|
188 | - 'offset' => $offset, |
|
189 | - ]); |
|
146 | + $fail = function () { |
|
147 | + register_error(elgg_echo('discussion:reply:error:notfound')); |
|
148 | + forward(REFERER); |
|
149 | + }; |
|
150 | + |
|
151 | + $reply = get_entity($reply_guid); |
|
152 | + if (!$reply) { |
|
153 | + // try fallback |
|
154 | + $fallback = get_entity($fallback_guid); |
|
155 | + if (!elgg_instanceof($fallback, 'object', 'discussion')) { |
|
156 | + $fail(); |
|
157 | + } |
|
158 | + |
|
159 | + register_error(elgg_echo('discussion:reply:error:notfound_fallback')); |
|
160 | + forward($fallback->getURL()); |
|
161 | + } |
|
162 | + |
|
163 | + if (!elgg_instanceof($reply, 'object', 'discussion_reply')) { |
|
164 | + $fail(); |
|
165 | + } |
|
166 | + |
|
167 | + // start with topic URL |
|
168 | + $topic = $reply->getContainerEntity(); |
|
169 | + |
|
170 | + // this won't work with threaded comments, but core doesn't support that yet |
|
171 | + $count = elgg_get_entities([ |
|
172 | + 'type' => 'object', |
|
173 | + 'subtype' => $reply->getSubtype(), |
|
174 | + 'container_guid' => $topic->guid, |
|
175 | + 'count' => true, |
|
176 | + 'wheres' => ["e.guid < " . (int) $reply->guid], |
|
177 | + ]); |
|
178 | + $limit = (int) get_input('limit', 0); |
|
179 | + if (!$limit) { |
|
180 | + $limit = _elgg_config()->default_limit; |
|
181 | + } |
|
182 | + $offset = floor($count / $limit) * $limit; |
|
183 | + if (!$offset) { |
|
184 | + $offset = null; |
|
185 | + } |
|
186 | + |
|
187 | + $url = elgg_http_add_url_query_elements($topic->getURL(), [ |
|
188 | + 'offset' => $offset, |
|
189 | + ]); |
|
190 | 190 | |
191 | - // make sure there's only one fragment (#) |
|
192 | - $parts = parse_url($url); |
|
193 | - $parts['fragment'] = "elgg-object-{$reply->guid}"; |
|
194 | - $url = elgg_http_build_url($parts, false); |
|
191 | + // make sure there's only one fragment (#) |
|
192 | + $parts = parse_url($url); |
|
193 | + $parts['fragment'] = "elgg-object-{$reply->guid}"; |
|
194 | + $url = elgg_http_build_url($parts, false); |
|
195 | 195 | |
196 | - forward($url); |
|
196 | + forward($url); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -209,21 +209,21 @@ discard block |
||
209 | 209 | * @return string |
210 | 210 | */ |
211 | 211 | function discussion_set_topic_url($hook, $type, $url, $params) { |
212 | - $entity = $params['entity']; |
|
212 | + $entity = $params['entity']; |
|
213 | 213 | |
214 | - if (!$entity instanceof ElggObject) { |
|
215 | - return; |
|
216 | - } |
|
214 | + if (!$entity instanceof ElggObject) { |
|
215 | + return; |
|
216 | + } |
|
217 | 217 | |
218 | - if ($entity->getSubtype() === 'discussion') { |
|
219 | - $title = elgg_get_friendly_title($entity->title); |
|
220 | - return "discussion/view/{$entity->guid}/{$title}"; |
|
221 | - } |
|
218 | + if ($entity->getSubtype() === 'discussion') { |
|
219 | + $title = elgg_get_friendly_title($entity->title); |
|
220 | + return "discussion/view/{$entity->guid}/{$title}"; |
|
221 | + } |
|
222 | 222 | |
223 | - if ($entity->getSubtype() === 'discussion_reply') { |
|
224 | - $topic = $entity->getContainerEntity(); |
|
225 | - return "discussion/reply/view/{$entity->guid}/{$topic->guid}"; |
|
226 | - } |
|
223 | + if ($entity->getSubtype() === 'discussion_reply') { |
|
224 | + $topic = $entity->getContainerEntity(); |
|
225 | + return "discussion/reply/view/{$entity->guid}/{$topic->guid}"; |
|
226 | + } |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -236,9 +236,9 @@ discard block |
||
236 | 236 | * @return bool |
237 | 237 | */ |
238 | 238 | function discussion_comment_override($hook, $type, $return, $params) { |
239 | - if (elgg_instanceof($params['entity'], 'object', 'discussion')) { |
|
240 | - return false; |
|
241 | - } |
|
239 | + if (elgg_instanceof($params['entity'], 'object', 'discussion')) { |
|
240 | + return false; |
|
241 | + } |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -251,15 +251,15 @@ discard block |
||
251 | 251 | * @return ElggMenuItem[] $return |
252 | 252 | */ |
253 | 253 | function discussion_owner_block_menu($hook, $type, $return, $params) { |
254 | - if (elgg_instanceof($params['entity'], 'group')) { |
|
255 | - if ($params['entity']->forum_enable != "no") { |
|
256 | - $url = "discussion/group/{$params['entity']->guid}"; |
|
257 | - $item = new ElggMenuItem('discussion', elgg_echo('discussion:group'), $url); |
|
258 | - $return[] = $item; |
|
259 | - } |
|
260 | - } |
|
261 | - |
|
262 | - return $return; |
|
254 | + if (elgg_instanceof($params['entity'], 'group')) { |
|
255 | + if ($params['entity']->forum_enable != "no") { |
|
256 | + $url = "discussion/group/{$params['entity']->guid}"; |
|
257 | + $item = new ElggMenuItem('discussion', elgg_echo('discussion:group'), $url); |
|
258 | + $return[] = $item; |
|
259 | + } |
|
260 | + } |
|
261 | + |
|
262 | + return $return; |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
@@ -275,39 +275,39 @@ discard block |
||
275 | 275 | * @return ElggMenuItem[] $return |
276 | 276 | */ |
277 | 277 | function discussion_add_to_river_menu($hook, $type, $return, $params) { |
278 | - if (!elgg_is_logged_in() || elgg_in_context('widgets')) { |
|
279 | - return $return; |
|
280 | - } |
|
281 | - |
|
282 | - $item = $params['item']; |
|
283 | - $object = $item->getObjectEntity(); |
|
284 | - |
|
285 | - if (elgg_instanceof($object, 'object', 'discussion')) { |
|
286 | - /* @var $object ElggObject */ |
|
287 | - if ($object->canWriteToContainer(0, 'object', 'discussion_reply')) { |
|
288 | - $options = [ |
|
289 | - 'name' => 'reply', |
|
290 | - 'href' => "#discussion-reply-{$object->guid}", |
|
291 | - 'text' => elgg_view_icon('speech-bubble'), |
|
292 | - 'title' => elgg_echo('reply:this'), |
|
293 | - 'rel' => 'toggle', |
|
294 | - 'priority' => 50, |
|
295 | - ]; |
|
296 | - $return[] = ElggMenuItem::factory($options); |
|
297 | - } |
|
298 | - } else if (elgg_instanceof($object, 'object', 'discussion_reply')) { |
|
299 | - /* @var $object ElggDiscussionReply */ |
|
300 | - if (!$object->canComment()) { |
|
301 | - // Discussion replies cannot be commented |
|
302 | - foreach ($return as $key => $item) { |
|
303 | - if ($item->getName() === 'comment') { |
|
304 | - unset($return[$key]); |
|
305 | - } |
|
306 | - } |
|
307 | - } |
|
308 | - } |
|
309 | - |
|
310 | - return $return; |
|
278 | + if (!elgg_is_logged_in() || elgg_in_context('widgets')) { |
|
279 | + return $return; |
|
280 | + } |
|
281 | + |
|
282 | + $item = $params['item']; |
|
283 | + $object = $item->getObjectEntity(); |
|
284 | + |
|
285 | + if (elgg_instanceof($object, 'object', 'discussion')) { |
|
286 | + /* @var $object ElggObject */ |
|
287 | + if ($object->canWriteToContainer(0, 'object', 'discussion_reply')) { |
|
288 | + $options = [ |
|
289 | + 'name' => 'reply', |
|
290 | + 'href' => "#discussion-reply-{$object->guid}", |
|
291 | + 'text' => elgg_view_icon('speech-bubble'), |
|
292 | + 'title' => elgg_echo('reply:this'), |
|
293 | + 'rel' => 'toggle', |
|
294 | + 'priority' => 50, |
|
295 | + ]; |
|
296 | + $return[] = ElggMenuItem::factory($options); |
|
297 | + } |
|
298 | + } else if (elgg_instanceof($object, 'object', 'discussion_reply')) { |
|
299 | + /* @var $object ElggDiscussionReply */ |
|
300 | + if (!$object->canComment()) { |
|
301 | + // Discussion replies cannot be commented |
|
302 | + foreach ($return as $key => $item) { |
|
303 | + if ($item->getName() === 'comment') { |
|
304 | + unset($return[$key]); |
|
305 | + } |
|
306 | + } |
|
307 | + } |
|
308 | + } |
|
309 | + |
|
310 | + return $return; |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | /** |
@@ -320,23 +320,23 @@ discard block |
||
320 | 320 | * @return Elgg\Notifications\Notification |
321 | 321 | */ |
322 | 322 | function discussion_prepare_notification($hook, $type, $notification, $params) { |
323 | - $entity = $params['event']->getObject(); |
|
324 | - $owner = $params['event']->getActor(); |
|
325 | - $language = $params['language']; |
|
326 | - |
|
327 | - $descr = $entity->description; |
|
328 | - $title = $entity->title; |
|
329 | - |
|
330 | - $notification->subject = elgg_echo('discussion:topic:notify:subject', [$title], $language); |
|
331 | - $notification->body = elgg_echo('discussion:topic:notify:body', [ |
|
332 | - $owner->name, |
|
333 | - $title, |
|
334 | - $descr, |
|
335 | - $entity->getURL() |
|
336 | - ], $language); |
|
337 | - $notification->summary = elgg_echo('discussion:topic:notify:summary', [$entity->title], $language); |
|
338 | - $notification->url = $entity->getURL(); |
|
339 | - return $notification; |
|
323 | + $entity = $params['event']->getObject(); |
|
324 | + $owner = $params['event']->getActor(); |
|
325 | + $language = $params['language']; |
|
326 | + |
|
327 | + $descr = $entity->description; |
|
328 | + $title = $entity->title; |
|
329 | + |
|
330 | + $notification->subject = elgg_echo('discussion:topic:notify:subject', [$title], $language); |
|
331 | + $notification->body = elgg_echo('discussion:topic:notify:body', [ |
|
332 | + $owner->name, |
|
333 | + $title, |
|
334 | + $descr, |
|
335 | + $entity->getURL() |
|
336 | + ], $language); |
|
337 | + $notification->summary = elgg_echo('discussion:topic:notify:summary', [$entity->title], $language); |
|
338 | + $notification->url = $entity->getURL(); |
|
339 | + return $notification; |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | /** |
@@ -349,22 +349,22 @@ discard block |
||
349 | 349 | * @return Elgg\Notifications\Notification |
350 | 350 | */ |
351 | 351 | function discussion_prepare_reply_notification($hook, $type, $notification, $params) { |
352 | - $reply = $params['event']->getObject(); |
|
353 | - $topic = $reply->getContainerEntity(); |
|
354 | - $poster = $reply->getOwnerEntity(); |
|
355 | - $language = elgg_extract('language', $params); |
|
356 | - |
|
357 | - $notification->subject = elgg_echo('discussion:reply:notify:subject', [$topic->title], $language); |
|
358 | - $notification->body = elgg_echo('discussion:reply:notify:body', [ |
|
359 | - $poster->name, |
|
360 | - $topic->title, |
|
361 | - $reply->description, |
|
362 | - $reply->getURL(), |
|
363 | - ], $language); |
|
364 | - $notification->summary = elgg_echo('discussion:reply:notify:summary', [$topic->title], $language); |
|
365 | - $notification->url = $reply->getURL(); |
|
352 | + $reply = $params['event']->getObject(); |
|
353 | + $topic = $reply->getContainerEntity(); |
|
354 | + $poster = $reply->getOwnerEntity(); |
|
355 | + $language = elgg_extract('language', $params); |
|
356 | + |
|
357 | + $notification->subject = elgg_echo('discussion:reply:notify:subject', [$topic->title], $language); |
|
358 | + $notification->body = elgg_echo('discussion:reply:notify:body', [ |
|
359 | + $poster->name, |
|
360 | + $topic->title, |
|
361 | + $reply->description, |
|
362 | + $reply->getURL(), |
|
363 | + ], $language); |
|
364 | + $notification->summary = elgg_echo('discussion:reply:notify:summary', [$topic->title], $language); |
|
365 | + $notification->url = $reply->getURL(); |
|
366 | 366 | |
367 | - return $notification; |
|
367 | + return $notification; |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
@@ -378,25 +378,25 @@ discard block |
||
378 | 378 | * @return array |
379 | 379 | */ |
380 | 380 | function discussion_get_subscriptions($hook, $type, $subscriptions, $params) { |
381 | - $reply = $params['event']->getObject(); |
|
381 | + $reply = $params['event']->getObject(); |
|
382 | 382 | |
383 | - if (!elgg_instanceof($reply, 'object', 'discussion_reply')) { |
|
384 | - return $subscriptions; |
|
385 | - } |
|
383 | + if (!elgg_instanceof($reply, 'object', 'discussion_reply')) { |
|
384 | + return $subscriptions; |
|
385 | + } |
|
386 | 386 | |
387 | - $container_guid = $reply->getContainerEntity()->container_guid; |
|
388 | - $container_subscriptions = elgg_get_subscriptions_for_container($container_guid); |
|
387 | + $container_guid = $reply->getContainerEntity()->container_guid; |
|
388 | + $container_subscriptions = elgg_get_subscriptions_for_container($container_guid); |
|
389 | 389 | |
390 | - return ($subscriptions + $container_subscriptions); |
|
390 | + return ($subscriptions + $container_subscriptions); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | /** |
394 | 394 | * Parse ECML on discussion views |
395 | 395 | */ |
396 | 396 | function discussion_ecml_views_hook($hook, $type, $return_value, $params) { |
397 | - $return_value['forum/viewposts'] = elgg_echo('discussion:ecml:discussion'); |
|
397 | + $return_value['forum/viewposts'] = elgg_echo('discussion:ecml:discussion'); |
|
398 | 398 | |
399 | - return $return_value; |
|
399 | + return $return_value; |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | |
@@ -410,29 +410,29 @@ discard block |
||
410 | 410 | * @return boolean True if user is discussion or group owner |
411 | 411 | */ |
412 | 412 | function discussion_can_edit_reply($hook, $type, $return, $params) { |
413 | - /** @var $reply ElggEntity */ |
|
414 | - $reply = $params['entity']; |
|
415 | - $user = $params['user']; |
|
413 | + /** @var $reply ElggEntity */ |
|
414 | + $reply = $params['entity']; |
|
415 | + $user = $params['user']; |
|
416 | 416 | |
417 | - if (!elgg_instanceof($reply, 'object', 'discussion_reply')) { |
|
418 | - return $return; |
|
419 | - } |
|
417 | + if (!elgg_instanceof($reply, 'object', 'discussion_reply')) { |
|
418 | + return $return; |
|
419 | + } |
|
420 | 420 | |
421 | - if ($reply->owner_guid == $user->guid) { |
|
422 | - return true; |
|
423 | - } |
|
421 | + if ($reply->owner_guid == $user->guid) { |
|
422 | + return true; |
|
423 | + } |
|
424 | 424 | |
425 | - $discussion = $reply->getContainerEntity(); |
|
426 | - if ($discussion->owner_guid == $user->guid) { |
|
427 | - return true; |
|
428 | - } |
|
425 | + $discussion = $reply->getContainerEntity(); |
|
426 | + if ($discussion->owner_guid == $user->guid) { |
|
427 | + return true; |
|
428 | + } |
|
429 | 429 | |
430 | - $container = $discussion->getContainerEntity(); |
|
431 | - if (elgg_instanceof($container, 'group') && $container->owner_guid == $user->guid) { |
|
432 | - return true; |
|
433 | - } |
|
430 | + $container = $discussion->getContainerEntity(); |
|
431 | + if (elgg_instanceof($container, 'group') && $container->owner_guid == $user->guid) { |
|
432 | + return true; |
|
433 | + } |
|
434 | 434 | |
435 | - return false; |
|
435 | + return false; |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | /** |
@@ -447,22 +447,22 @@ discard block |
||
447 | 447 | */ |
448 | 448 | function discussion_reply_container_logic_override($hook, $type, $return, $params) { |
449 | 449 | |
450 | - $container = elgg_extract('container', $params); |
|
451 | - $subtype = elgg_extract('subtype', $params); |
|
450 | + $container = elgg_extract('container', $params); |
|
451 | + $subtype = elgg_extract('subtype', $params); |
|
452 | 452 | |
453 | - if ($type !== 'object' || $subtype !== 'discussion_reply') { |
|
454 | - return; |
|
455 | - } |
|
453 | + if ($type !== 'object' || $subtype !== 'discussion_reply') { |
|
454 | + return; |
|
455 | + } |
|
456 | 456 | |
457 | - if (!elgg_instanceof($container, 'object', 'discussion')) { |
|
458 | - // only discussions can contain discussion replies |
|
459 | - return false; |
|
460 | - } |
|
457 | + if (!elgg_instanceof($container, 'object', 'discussion')) { |
|
458 | + // only discussions can contain discussion replies |
|
459 | + return false; |
|
460 | + } |
|
461 | 461 | |
462 | - if ($container->status == 'closed') { |
|
463 | - // do not allow new replies in closed discussions |
|
464 | - return false; |
|
465 | - } |
|
462 | + if ($container->status == 'closed') { |
|
463 | + // do not allow new replies in closed discussions |
|
464 | + return false; |
|
465 | + } |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | /** |
@@ -475,25 +475,25 @@ discard block |
||
475 | 475 | * @return boolean $return |
476 | 476 | */ |
477 | 477 | function discussion_reply_container_permissions_override($hook, $type, $return, $params) { |
478 | - if ($params['subtype'] !== 'discussion_reply') { |
|
479 | - return $return; |
|
480 | - } |
|
478 | + if ($params['subtype'] !== 'discussion_reply') { |
|
479 | + return $return; |
|
480 | + } |
|
481 | 481 | |
482 | - /** @var $discussion ElggEntity */ |
|
483 | - $discussion = $params['container']; |
|
484 | - $user = $params['user']; |
|
482 | + /** @var $discussion ElggEntity */ |
|
483 | + $discussion = $params['container']; |
|
484 | + $user = $params['user']; |
|
485 | 485 | |
486 | - $container = $discussion->getContainerEntity(); |
|
486 | + $container = $discussion->getContainerEntity(); |
|
487 | 487 | |
488 | - if (elgg_instanceof($container, 'group')) { |
|
489 | - // Only group members are allowed to reply |
|
490 | - // to a discussion within a group |
|
491 | - if (!$container->canWriteToContainer($user->guid)) { |
|
492 | - return false; |
|
493 | - } |
|
494 | - } |
|
488 | + if (elgg_instanceof($container, 'group')) { |
|
489 | + // Only group members are allowed to reply |
|
490 | + // to a discussion within a group |
|
491 | + if (!$container->canWriteToContainer($user->guid)) { |
|
492 | + return false; |
|
493 | + } |
|
494 | + } |
|
495 | 495 | |
496 | - return true; |
|
496 | + return true; |
|
497 | 497 | } |
498 | 498 | |
499 | 499 | /** |
@@ -504,30 +504,30 @@ discard block |
||
504 | 504 | * @param ElggObject $object ElggObject |
505 | 505 | */ |
506 | 506 | function discussion_update_reply_access_ids($event, $type, $object) { |
507 | - if (!elgg_instanceof($object, 'object', 'discussion')) { |
|
508 | - return; |
|
509 | - } |
|
510 | - |
|
511 | - $ia = elgg_set_ignore_access(true); |
|
512 | - $options = [ |
|
513 | - 'type' => 'object', |
|
514 | - 'subtype' => 'discussion_reply', |
|
515 | - 'container_guid' => $object->getGUID(), |
|
516 | - 'limit' => 0, |
|
517 | - ]; |
|
518 | - $batch = new ElggBatch('elgg_get_entities', $options); |
|
519 | - foreach ($batch as $reply) { |
|
520 | - if ($reply->access_id == $object->access_id) { |
|
521 | - // Assume access_id of the replies is up-to-date |
|
522 | - break; |
|
523 | - } |
|
524 | - |
|
525 | - // Update reply access_id |
|
526 | - $reply->access_id = $object->access_id; |
|
527 | - $reply->save(); |
|
528 | - } |
|
529 | - |
|
530 | - elgg_set_ignore_access($ia); |
|
507 | + if (!elgg_instanceof($object, 'object', 'discussion')) { |
|
508 | + return; |
|
509 | + } |
|
510 | + |
|
511 | + $ia = elgg_set_ignore_access(true); |
|
512 | + $options = [ |
|
513 | + 'type' => 'object', |
|
514 | + 'subtype' => 'discussion_reply', |
|
515 | + 'container_guid' => $object->getGUID(), |
|
516 | + 'limit' => 0, |
|
517 | + ]; |
|
518 | + $batch = new ElggBatch('elgg_get_entities', $options); |
|
519 | + foreach ($batch as $reply) { |
|
520 | + if ($reply->access_id == $object->access_id) { |
|
521 | + // Assume access_id of the replies is up-to-date |
|
522 | + break; |
|
523 | + } |
|
524 | + |
|
525 | + // Update reply access_id |
|
526 | + $reply->access_id = $object->access_id; |
|
527 | + $reply->save(); |
|
528 | + } |
|
529 | + |
|
530 | + elgg_set_ignore_access($ia); |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | /** |
@@ -540,56 +540,56 @@ discard block |
||
540 | 540 | * @return ElggMenuItem[] $return |
541 | 541 | */ |
542 | 542 | function discussion_reply_menu_setup($hook, $type, $return, $params) { |
543 | - /** @var $reply ElggEntity */ |
|
544 | - $reply = elgg_extract('entity', $params); |
|
545 | - |
|
546 | - if (empty($reply) || !elgg_instanceof($reply, 'object', 'discussion_reply')) { |
|
547 | - return $return; |
|
548 | - } |
|
549 | - |
|
550 | - if (!elgg_is_logged_in()) { |
|
551 | - return $return; |
|
552 | - } |
|
553 | - |
|
554 | - if (elgg_in_context('widgets')) { |
|
555 | - return $return; |
|
556 | - } |
|
557 | - |
|
558 | - $remove = []; |
|
559 | - |
|
560 | - $user = elgg_get_logged_in_user_entity(); |
|
561 | - |
|
562 | - // Allow discussion topic owner, group owner and admins to edit and delete |
|
563 | - if ($reply->canEdit() && !elgg_in_context('activity')) { |
|
564 | - $return[] = ElggMenuItem::factory([ |
|
565 | - 'name' => 'edit', |
|
566 | - 'text' => elgg_echo('edit'), |
|
567 | - 'href' => "discussion/reply/edit/{$reply->guid}", |
|
568 | - 'priority' => 150, |
|
569 | - ]); |
|
570 | - |
|
571 | - $return[] = ElggMenuItem::factory([ |
|
572 | - 'name' => 'delete', |
|
573 | - 'text' => elgg_view_icon('delete'), |
|
574 | - 'href' => "action/discussion/reply/delete?guid={$reply->guid}", |
|
575 | - 'priority' => 150, |
|
576 | - 'is_action' => true, |
|
577 | - 'confirm' => elgg_echo('deleteconfirm'), |
|
578 | - ]); |
|
579 | - } else { |
|
580 | - // Edit and delete links can be removed from all other users |
|
581 | - $remove[] = 'edit'; |
|
582 | - $remove[] = 'delete'; |
|
583 | - } |
|
584 | - |
|
585 | - // Remove unneeded menu items |
|
586 | - foreach ($return as $key => $item) { |
|
587 | - if (in_array($item->getName(), $remove)) { |
|
588 | - unset($return[$key]); |
|
589 | - } |
|
590 | - } |
|
591 | - |
|
592 | - return $return; |
|
543 | + /** @var $reply ElggEntity */ |
|
544 | + $reply = elgg_extract('entity', $params); |
|
545 | + |
|
546 | + if (empty($reply) || !elgg_instanceof($reply, 'object', 'discussion_reply')) { |
|
547 | + return $return; |
|
548 | + } |
|
549 | + |
|
550 | + if (!elgg_is_logged_in()) { |
|
551 | + return $return; |
|
552 | + } |
|
553 | + |
|
554 | + if (elgg_in_context('widgets')) { |
|
555 | + return $return; |
|
556 | + } |
|
557 | + |
|
558 | + $remove = []; |
|
559 | + |
|
560 | + $user = elgg_get_logged_in_user_entity(); |
|
561 | + |
|
562 | + // Allow discussion topic owner, group owner and admins to edit and delete |
|
563 | + if ($reply->canEdit() && !elgg_in_context('activity')) { |
|
564 | + $return[] = ElggMenuItem::factory([ |
|
565 | + 'name' => 'edit', |
|
566 | + 'text' => elgg_echo('edit'), |
|
567 | + 'href' => "discussion/reply/edit/{$reply->guid}", |
|
568 | + 'priority' => 150, |
|
569 | + ]); |
|
570 | + |
|
571 | + $return[] = ElggMenuItem::factory([ |
|
572 | + 'name' => 'delete', |
|
573 | + 'text' => elgg_view_icon('delete'), |
|
574 | + 'href' => "action/discussion/reply/delete?guid={$reply->guid}", |
|
575 | + 'priority' => 150, |
|
576 | + 'is_action' => true, |
|
577 | + 'confirm' => elgg_echo('deleteconfirm'), |
|
578 | + ]); |
|
579 | + } else { |
|
580 | + // Edit and delete links can be removed from all other users |
|
581 | + $remove[] = 'edit'; |
|
582 | + $remove[] = 'delete'; |
|
583 | + } |
|
584 | + |
|
585 | + // Remove unneeded menu items |
|
586 | + foreach ($return as $key => $item) { |
|
587 | + if (in_array($item->getName(), $remove)) { |
|
588 | + unset($return[$key]); |
|
589 | + } |
|
590 | + } |
|
591 | + |
|
592 | + return $return; |
|
593 | 593 | } |
594 | 594 | |
595 | 595 | /** |
@@ -602,20 +602,20 @@ discard block |
||
602 | 602 | */ |
603 | 603 | function discussion_search_discussion($hook, $type, $value, $params) { |
604 | 604 | |
605 | - if (empty($params) || !is_array($params)) { |
|
606 | - return $value; |
|
607 | - } |
|
605 | + if (empty($params) || !is_array($params)) { |
|
606 | + return $value; |
|
607 | + } |
|
608 | 608 | |
609 | - $subtype = elgg_extract("subtype", $params); |
|
610 | - if (empty($subtype) || ($subtype !== "discussion")) { |
|
611 | - return $value; |
|
612 | - } |
|
609 | + $subtype = elgg_extract("subtype", $params); |
|
610 | + if (empty($subtype) || ($subtype !== "discussion")) { |
|
611 | + return $value; |
|
612 | + } |
|
613 | 613 | |
614 | - unset($params["subtype"]); |
|
615 | - $params["subtypes"] = ["discussion", "discussion_reply"]; |
|
614 | + unset($params["subtype"]); |
|
615 | + $params["subtypes"] = ["discussion", "discussion_reply"]; |
|
616 | 616 | |
617 | - // trigger the 'normal' object search as it can handle the added options |
|
618 | - return elgg_trigger_plugin_hook('search', 'object', $params, []); |
|
617 | + // trigger the 'normal' object search as it can handle the added options |
|
618 | + return elgg_trigger_plugin_hook('search', 'object', $params, []); |
|
619 | 619 | } |
620 | 620 | |
621 | 621 | /** |
@@ -625,37 +625,37 @@ discard block |
||
625 | 625 | * @return array |
626 | 626 | */ |
627 | 627 | function discussion_prepare_form_vars($topic = null) { |
628 | - // input names => defaults |
|
629 | - $values = [ |
|
630 | - 'title' => '', |
|
631 | - 'description' => '', |
|
632 | - 'status' => '', |
|
633 | - 'access_id' => ACCESS_DEFAULT, |
|
634 | - 'tags' => '', |
|
635 | - 'container_guid' => elgg_get_page_owner_guid(), |
|
636 | - 'guid' => null, |
|
637 | - 'topic' => $topic, |
|
638 | - 'entity' => $topic, |
|
639 | - ]; |
|
640 | - |
|
641 | - if ($topic) { |
|
642 | - foreach (array_keys($values) as $field) { |
|
643 | - if (isset($topic->$field)) { |
|
644 | - $values[$field] = $topic->$field; |
|
645 | - } |
|
646 | - } |
|
647 | - } |
|
648 | - |
|
649 | - if (elgg_is_sticky_form('topic')) { |
|
650 | - $sticky_values = elgg_get_sticky_values('topic'); |
|
651 | - foreach ($sticky_values as $key => $value) { |
|
652 | - $values[$key] = $value; |
|
653 | - } |
|
654 | - } |
|
655 | - |
|
656 | - elgg_clear_sticky_form('topic'); |
|
657 | - |
|
658 | - return $values; |
|
628 | + // input names => defaults |
|
629 | + $values = [ |
|
630 | + 'title' => '', |
|
631 | + 'description' => '', |
|
632 | + 'status' => '', |
|
633 | + 'access_id' => ACCESS_DEFAULT, |
|
634 | + 'tags' => '', |
|
635 | + 'container_guid' => elgg_get_page_owner_guid(), |
|
636 | + 'guid' => null, |
|
637 | + 'topic' => $topic, |
|
638 | + 'entity' => $topic, |
|
639 | + ]; |
|
640 | + |
|
641 | + if ($topic) { |
|
642 | + foreach (array_keys($values) as $field) { |
|
643 | + if (isset($topic->$field)) { |
|
644 | + $values[$field] = $topic->$field; |
|
645 | + } |
|
646 | + } |
|
647 | + } |
|
648 | + |
|
649 | + if (elgg_is_sticky_form('topic')) { |
|
650 | + $sticky_values = elgg_get_sticky_values('topic'); |
|
651 | + foreach ($sticky_values as $key => $value) { |
|
652 | + $values[$key] = $value; |
|
653 | + } |
|
654 | + } |
|
655 | + |
|
656 | + elgg_clear_sticky_form('topic'); |
|
657 | + |
|
658 | + return $values; |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | /** |
@@ -669,15 +669,15 @@ discard block |
||
669 | 669 | */ |
670 | 670 | function discussion_setup_groups_filter_tabs($hook, $type, $return, $params) { |
671 | 671 | |
672 | - $filter_value = elgg_extract('filter_value', $params); |
|
672 | + $filter_value = elgg_extract('filter_value', $params); |
|
673 | 673 | |
674 | - $return[] = ElggMenuItem::factory([ |
|
675 | - 'name' => 'discussion', |
|
676 | - 'text' => elgg_echo('discussion:latest'), |
|
677 | - 'href' => 'groups/all?filter=discussion', |
|
678 | - 'priority' => 500, |
|
679 | - 'selected' => $filter_value == 'discussion', |
|
680 | - ]); |
|
674 | + $return[] = ElggMenuItem::factory([ |
|
675 | + 'name' => 'discussion', |
|
676 | + 'text' => elgg_echo('discussion:latest'), |
|
677 | + 'href' => 'groups/all?filter=discussion', |
|
678 | + 'priority' => 500, |
|
679 | + 'selected' => $filter_value == 'discussion', |
|
680 | + ]); |
|
681 | 681 | |
682 | - return $return; |
|
682 | + return $return; |
|
683 | 683 | } |
@@ -29,27 +29,27 @@ discard block |
||
29 | 29 | * @since 1.8.0 |
30 | 30 | */ |
31 | 31 | function elgg_get_admins(array $options = []) { |
32 | - $config = _elgg_config(); |
|
33 | - |
|
34 | - if (isset($options['joins'])) { |
|
35 | - if (!is_array($options['joins'])) { |
|
36 | - $options['joins'] = [$options['joins']]; |
|
37 | - } |
|
38 | - $options['joins'][] = "join {$config->dbprefix}users_entity u on e.guid=u.guid"; |
|
39 | - } else { |
|
40 | - $options['joins'] = ["join {$config->dbprefix}users_entity u on e.guid=u.guid"]; |
|
41 | - } |
|
42 | - |
|
43 | - if (isset($options['wheres'])) { |
|
44 | - if (!is_array($options['wheres'])) { |
|
45 | - $options['wheres'] = [$options['wheres']]; |
|
46 | - } |
|
47 | - $options['wheres'][] = "u.admin = 'yes'"; |
|
48 | - } else { |
|
49 | - $options['wheres'][] = "u.admin = 'yes'"; |
|
50 | - } |
|
51 | - |
|
52 | - return elgg_get_entities($options); |
|
32 | + $config = _elgg_config(); |
|
33 | + |
|
34 | + if (isset($options['joins'])) { |
|
35 | + if (!is_array($options['joins'])) { |
|
36 | + $options['joins'] = [$options['joins']]; |
|
37 | + } |
|
38 | + $options['joins'][] = "join {$config->dbprefix}users_entity u on e.guid=u.guid"; |
|
39 | + } else { |
|
40 | + $options['joins'] = ["join {$config->dbprefix}users_entity u on e.guid=u.guid"]; |
|
41 | + } |
|
42 | + |
|
43 | + if (isset($options['wheres'])) { |
|
44 | + if (!is_array($options['wheres'])) { |
|
45 | + $options['wheres'] = [$options['wheres']]; |
|
46 | + } |
|
47 | + $options['wheres'][] = "u.admin = 'yes'"; |
|
48 | + } else { |
|
49 | + $options['wheres'][] = "u.admin = 'yes'"; |
|
50 | + } |
|
51 | + |
|
52 | + return elgg_get_entities($options); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @since 1.8.0 |
70 | 70 | */ |
71 | 71 | function elgg_add_admin_notice($id, $message) { |
72 | - return _elgg_services()->adminNotices->add($id, $message); |
|
72 | + return _elgg_services()->adminNotices->add($id, $message); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * @since 1.8.0 |
82 | 82 | */ |
83 | 83 | function elgg_delete_admin_notice($id) { |
84 | - return _elgg_services()->adminNotices->delete($id); |
|
84 | + return _elgg_services()->adminNotices->delete($id); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @since 1.8.0 |
94 | 94 | */ |
95 | 95 | function elgg_get_admin_notices(array $options = []) { |
96 | - return _elgg_services()->adminNotices->find($options); |
|
96 | + return _elgg_services()->adminNotices->find($options); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * @since 1.8.0 |
106 | 106 | */ |
107 | 107 | function elgg_admin_notice_exists($id) { |
108 | - return _elgg_services()->adminNotices->exists($id); |
|
108 | + return _elgg_services()->adminNotices->exists($id); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -117,17 +117,17 @@ discard block |
||
117 | 117 | * @access private |
118 | 118 | */ |
119 | 119 | function _elgg_create_notice_of_pending_upgrade($event, $type, $object) { |
120 | - if ($object instanceof \ElggUpgrade) { |
|
121 | - // Link to the Upgrades section |
|
122 | - $link = elgg_view('output/url', [ |
|
123 | - 'href' => 'admin/upgrades', |
|
124 | - 'text' => elgg_echo('admin:view_upgrades'), |
|
125 | - ]); |
|
120 | + if ($object instanceof \ElggUpgrade) { |
|
121 | + // Link to the Upgrades section |
|
122 | + $link = elgg_view('output/url', [ |
|
123 | + 'href' => 'admin/upgrades', |
|
124 | + 'text' => elgg_echo('admin:view_upgrades'), |
|
125 | + ]); |
|
126 | 126 | |
127 | - $message = elgg_echo('admin:pending_upgrades'); |
|
127 | + $message = elgg_echo('admin:pending_upgrades'); |
|
128 | 128 | |
129 | - elgg_add_admin_notice('pending_upgrades', "$message $link"); |
|
130 | - } |
|
129 | + elgg_add_admin_notice('pending_upgrades', "$message $link"); |
|
130 | + } |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -137,85 +137,85 @@ discard block |
||
137 | 137 | */ |
138 | 138 | function _elgg_admin_init() { |
139 | 139 | |
140 | - elgg_register_css('elgg.admin', elgg_get_simplecache_url('admin.css')); |
|
140 | + elgg_register_css('elgg.admin', elgg_get_simplecache_url('admin.css')); |
|
141 | 141 | |
142 | - elgg_extend_view('admin.css', 'lightbox/elgg-colorbox-theme/colorbox.css'); |
|
142 | + elgg_extend_view('admin.css', 'lightbox/elgg-colorbox-theme/colorbox.css'); |
|
143 | 143 | |
144 | - elgg_register_plugin_hook_handler('register', 'menu:admin_header', '_elgg_admin_header_menu'); |
|
145 | - elgg_register_plugin_hook_handler('register', 'menu:admin_footer', '_elgg_admin_footer_menu'); |
|
146 | - elgg_register_plugin_hook_handler('register', 'menu:page', '_elgg_admin_page_menu'); |
|
147 | - elgg_register_plugin_hook_handler('register', 'menu:page', '_elgg_admin_page_menu_plugin_settings'); |
|
148 | - |
|
149 | - // maintenance mode |
|
150 | - if (elgg_get_config('elgg_maintenance_mode', null)) { |
|
151 | - elgg_register_plugin_hook_handler('route', 'all', '_elgg_admin_maintenance_handler', 600); |
|
152 | - elgg_register_plugin_hook_handler('action', 'all', '_elgg_admin_maintenance_action_check', 600); |
|
153 | - elgg_register_css('maintenance', elgg_get_simplecache_url('maintenance.css')); |
|
154 | - |
|
155 | - elgg_register_menu_item('topbar', [ |
|
156 | - 'name' => 'maintenance_mode', |
|
157 | - 'href' => 'admin/configure_utilities/maintenance', |
|
158 | - 'text' => elgg_echo('admin:maintenance_mode:indicator_menu_item'), |
|
159 | - 'priority' => 900, |
|
160 | - ]); |
|
161 | - } |
|
162 | - |
|
163 | - elgg_register_action('admin/user/ban', '', 'admin'); |
|
164 | - elgg_register_action('admin/user/unban', '', 'admin'); |
|
165 | - elgg_register_action('admin/user/delete', '', 'admin'); |
|
166 | - elgg_register_action('admin/user/resetpassword', '', 'admin'); |
|
167 | - elgg_register_action('admin/user/makeadmin', '', 'admin'); |
|
168 | - elgg_register_action('admin/user/removeadmin', '', 'admin'); |
|
169 | - |
|
170 | - elgg_register_action('admin/site/update_basic', '', 'admin'); |
|
171 | - elgg_register_action('admin/site/update_advanced', '', 'admin'); |
|
172 | - elgg_register_action('admin/site/flush_cache', '', 'admin'); |
|
173 | - elgg_register_action('admin/site/unlock_upgrade', '', 'admin'); |
|
174 | - elgg_register_action('admin/site/set_robots', '', 'admin'); |
|
175 | - elgg_register_action('admin/site/set_maintenance_mode', '', 'admin'); |
|
176 | - |
|
177 | - elgg_register_action('admin/upgrades/upgrade_database_guid_columns', '', 'admin'); |
|
178 | - elgg_register_action('admin/site/regenerate_secret', '', 'admin'); |
|
179 | - elgg_register_action('admin/upgrade', '', 'admin'); |
|
180 | - |
|
181 | - elgg_register_action('admin/menu/save', '', 'admin'); |
|
182 | - |
|
183 | - elgg_register_action('admin/delete_admin_notice', '', 'admin'); |
|
144 | + elgg_register_plugin_hook_handler('register', 'menu:admin_header', '_elgg_admin_header_menu'); |
|
145 | + elgg_register_plugin_hook_handler('register', 'menu:admin_footer', '_elgg_admin_footer_menu'); |
|
146 | + elgg_register_plugin_hook_handler('register', 'menu:page', '_elgg_admin_page_menu'); |
|
147 | + elgg_register_plugin_hook_handler('register', 'menu:page', '_elgg_admin_page_menu_plugin_settings'); |
|
148 | + |
|
149 | + // maintenance mode |
|
150 | + if (elgg_get_config('elgg_maintenance_mode', null)) { |
|
151 | + elgg_register_plugin_hook_handler('route', 'all', '_elgg_admin_maintenance_handler', 600); |
|
152 | + elgg_register_plugin_hook_handler('action', 'all', '_elgg_admin_maintenance_action_check', 600); |
|
153 | + elgg_register_css('maintenance', elgg_get_simplecache_url('maintenance.css')); |
|
154 | + |
|
155 | + elgg_register_menu_item('topbar', [ |
|
156 | + 'name' => 'maintenance_mode', |
|
157 | + 'href' => 'admin/configure_utilities/maintenance', |
|
158 | + 'text' => elgg_echo('admin:maintenance_mode:indicator_menu_item'), |
|
159 | + 'priority' => 900, |
|
160 | + ]); |
|
161 | + } |
|
162 | + |
|
163 | + elgg_register_action('admin/user/ban', '', 'admin'); |
|
164 | + elgg_register_action('admin/user/unban', '', 'admin'); |
|
165 | + elgg_register_action('admin/user/delete', '', 'admin'); |
|
166 | + elgg_register_action('admin/user/resetpassword', '', 'admin'); |
|
167 | + elgg_register_action('admin/user/makeadmin', '', 'admin'); |
|
168 | + elgg_register_action('admin/user/removeadmin', '', 'admin'); |
|
169 | + |
|
170 | + elgg_register_action('admin/site/update_basic', '', 'admin'); |
|
171 | + elgg_register_action('admin/site/update_advanced', '', 'admin'); |
|
172 | + elgg_register_action('admin/site/flush_cache', '', 'admin'); |
|
173 | + elgg_register_action('admin/site/unlock_upgrade', '', 'admin'); |
|
174 | + elgg_register_action('admin/site/set_robots', '', 'admin'); |
|
175 | + elgg_register_action('admin/site/set_maintenance_mode', '', 'admin'); |
|
176 | + |
|
177 | + elgg_register_action('admin/upgrades/upgrade_database_guid_columns', '', 'admin'); |
|
178 | + elgg_register_action('admin/site/regenerate_secret', '', 'admin'); |
|
179 | + elgg_register_action('admin/upgrade', '', 'admin'); |
|
180 | + |
|
181 | + elgg_register_action('admin/menu/save', '', 'admin'); |
|
182 | + |
|
183 | + elgg_register_action('admin/delete_admin_notice', '', 'admin'); |
|
184 | 184 | |
185 | - elgg_register_action('admin/security/settings', '', 'admin'); |
|
186 | - |
|
187 | - elgg_register_simplecache_view('admin.css'); |
|
188 | - |
|
189 | - // widgets |
|
190 | - $widgets = ['online_users', 'new_users', 'content_stats', 'banned_users', 'admin_welcome', 'control_panel', 'cron_status']; |
|
191 | - foreach ($widgets as $widget) { |
|
192 | - elgg_register_widget_type( |
|
193 | - $widget, |
|
194 | - elgg_echo("admin:widget:$widget"), |
|
195 | - elgg_echo("admin:widget:$widget:help"), |
|
196 | - ['admin'] |
|
197 | - ); |
|
198 | - } |
|
199 | - |
|
200 | - // automatic adding of widgets for admin |
|
201 | - elgg_register_event_handler('make_admin', 'user', '_elgg_add_admin_widgets'); |
|
185 | + elgg_register_action('admin/security/settings', '', 'admin'); |
|
186 | + |
|
187 | + elgg_register_simplecache_view('admin.css'); |
|
188 | + |
|
189 | + // widgets |
|
190 | + $widgets = ['online_users', 'new_users', 'content_stats', 'banned_users', 'admin_welcome', 'control_panel', 'cron_status']; |
|
191 | + foreach ($widgets as $widget) { |
|
192 | + elgg_register_widget_type( |
|
193 | + $widget, |
|
194 | + elgg_echo("admin:widget:$widget"), |
|
195 | + elgg_echo("admin:widget:$widget:help"), |
|
196 | + ['admin'] |
|
197 | + ); |
|
198 | + } |
|
199 | + |
|
200 | + // automatic adding of widgets for admin |
|
201 | + elgg_register_event_handler('make_admin', 'user', '_elgg_add_admin_widgets'); |
|
202 | 202 | |
203 | - elgg_register_notification_event('user', '', ['make_admin', 'remove_admin']); |
|
204 | - elgg_register_plugin_hook_handler('get', 'subscriptions', '_elgg_admin_get_admin_subscribers_admin_action'); |
|
205 | - elgg_register_plugin_hook_handler('get', 'subscriptions', '_elgg_admin_get_user_subscriber_admin_action'); |
|
206 | - elgg_register_plugin_hook_handler('prepare', 'notification:make_admin:user:', '_elgg_admin_prepare_admin_notification_make_admin'); |
|
207 | - elgg_register_plugin_hook_handler('prepare', 'notification:make_admin:user:', '_elgg_admin_prepare_user_notification_make_admin'); |
|
208 | - elgg_register_plugin_hook_handler('prepare', 'notification:remove_admin:user:', '_elgg_admin_prepare_admin_notification_remove_admin'); |
|
209 | - elgg_register_plugin_hook_handler('prepare', 'notification:remove_admin:user:', '_elgg_admin_prepare_user_notification_remove_admin'); |
|
203 | + elgg_register_notification_event('user', '', ['make_admin', 'remove_admin']); |
|
204 | + elgg_register_plugin_hook_handler('get', 'subscriptions', '_elgg_admin_get_admin_subscribers_admin_action'); |
|
205 | + elgg_register_plugin_hook_handler('get', 'subscriptions', '_elgg_admin_get_user_subscriber_admin_action'); |
|
206 | + elgg_register_plugin_hook_handler('prepare', 'notification:make_admin:user:', '_elgg_admin_prepare_admin_notification_make_admin'); |
|
207 | + elgg_register_plugin_hook_handler('prepare', 'notification:make_admin:user:', '_elgg_admin_prepare_user_notification_make_admin'); |
|
208 | + elgg_register_plugin_hook_handler('prepare', 'notification:remove_admin:user:', '_elgg_admin_prepare_admin_notification_remove_admin'); |
|
209 | + elgg_register_plugin_hook_handler('prepare', 'notification:remove_admin:user:', '_elgg_admin_prepare_user_notification_remove_admin'); |
|
210 | 210 | |
211 | - // Add notice about pending upgrades |
|
212 | - elgg_register_event_handler('create', 'object', '_elgg_create_notice_of_pending_upgrade'); |
|
213 | - |
|
214 | - elgg_register_page_handler('admin', '_elgg_admin_page_handler'); |
|
215 | - elgg_register_page_handler('admin_plugin_text_file', '_elgg_admin_markdown_page_handler'); |
|
216 | - elgg_register_page_handler('robots.txt', '_elgg_robots_page_handler'); |
|
217 | - elgg_register_page_handler('phpinfo', '_elgg_phpinfo_page_handler'); |
|
218 | - elgg_register_page_handler('admin_plugins_refresh', '_elgg_ajax_plugins_update'); |
|
211 | + // Add notice about pending upgrades |
|
212 | + elgg_register_event_handler('create', 'object', '_elgg_create_notice_of_pending_upgrade'); |
|
213 | + |
|
214 | + elgg_register_page_handler('admin', '_elgg_admin_page_handler'); |
|
215 | + elgg_register_page_handler('admin_plugin_text_file', '_elgg_admin_markdown_page_handler'); |
|
216 | + elgg_register_page_handler('robots.txt', '_elgg_robots_page_handler'); |
|
217 | + elgg_register_page_handler('phpinfo', '_elgg_phpinfo_page_handler'); |
|
218 | + elgg_register_page_handler('admin_plugins_refresh', '_elgg_ajax_plugins_update'); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -225,13 +225,13 @@ discard block |
||
225 | 225 | * @return Elgg\Http\OkResponse |
226 | 226 | */ |
227 | 227 | function _elgg_ajax_plugins_update() { |
228 | - elgg_admin_gatekeeper(); |
|
229 | - elgg_set_context('admin'); |
|
228 | + elgg_admin_gatekeeper(); |
|
229 | + elgg_set_context('admin'); |
|
230 | 230 | |
231 | - return elgg_ok_response([ |
|
232 | - 'list' => elgg_view('admin/plugins', ['list_only' => true]), |
|
233 | - 'sidebar' => elgg_view('admin/sidebar'), |
|
234 | - ]); |
|
231 | + return elgg_ok_response([ |
|
232 | + 'list' => elgg_view('admin/plugins', ['list_only' => true]), |
|
233 | + 'sidebar' => elgg_view('admin/sidebar'), |
|
234 | + ]); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
@@ -248,52 +248,52 @@ discard block |
||
248 | 248 | * @since 3.0 |
249 | 249 | */ |
250 | 250 | function _elgg_admin_header_menu($hook, $type, $return, $params) { |
251 | - if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) { |
|
252 | - return; |
|
253 | - } |
|
254 | - |
|
255 | - $admin = elgg_get_logged_in_user_entity(); |
|
256 | - |
|
257 | - $admin_icon = elgg_view_entity_icon($admin, 'tiny'); |
|
258 | - $admin_link = elgg_view('output/url', [ |
|
259 | - 'href' => $admin->getURL(), |
|
260 | - 'text' => $admin->name, |
|
261 | - ]); |
|
262 | - |
|
263 | - $return[] = \ElggMenuItem::factory([ |
|
264 | - 'name' => 'admin_profile', |
|
265 | - 'href' => false, |
|
266 | - 'text' => "$admin_link $admin_icon", |
|
267 | - 'priority' => 1000, |
|
268 | - ]); |
|
269 | - |
|
270 | - $return[] = \ElggMenuItem::factory([ |
|
271 | - 'name' => 'admin_logout', |
|
272 | - 'href' => 'action/logout', |
|
273 | - 'text' => elgg_echo('logout'), |
|
274 | - 'is_trusted' => true, |
|
275 | - 'priority' => 900, |
|
276 | - ]); |
|
277 | - |
|
278 | - $return[] = \ElggMenuItem::factory([ |
|
279 | - 'name' => 'view_site', |
|
280 | - 'href' => elgg_get_site_url(), |
|
281 | - 'text' => elgg_echo('admin:view_site'), |
|
282 | - 'is_trusted' => true, |
|
283 | - 'priority' => 800, |
|
284 | - ]); |
|
285 | - |
|
286 | - if (elgg_get_config('elgg_maintenance_mode')) { |
|
287 | - $return[] = \ElggMenuItem::factory([ |
|
288 | - 'name' => 'maintenance', |
|
289 | - 'href' => 'admin/configure_utilities/maintenance', |
|
290 | - 'text' => elgg_echo('admin:configure_utilities:maintenance'), |
|
291 | - 'link_class' => 'elgg-maintenance-mode-warning', |
|
292 | - 'priority' => 700, |
|
293 | - ]); |
|
294 | - } |
|
251 | + if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) { |
|
252 | + return; |
|
253 | + } |
|
254 | + |
|
255 | + $admin = elgg_get_logged_in_user_entity(); |
|
256 | + |
|
257 | + $admin_icon = elgg_view_entity_icon($admin, 'tiny'); |
|
258 | + $admin_link = elgg_view('output/url', [ |
|
259 | + 'href' => $admin->getURL(), |
|
260 | + 'text' => $admin->name, |
|
261 | + ]); |
|
262 | + |
|
263 | + $return[] = \ElggMenuItem::factory([ |
|
264 | + 'name' => 'admin_profile', |
|
265 | + 'href' => false, |
|
266 | + 'text' => "$admin_link $admin_icon", |
|
267 | + 'priority' => 1000, |
|
268 | + ]); |
|
269 | + |
|
270 | + $return[] = \ElggMenuItem::factory([ |
|
271 | + 'name' => 'admin_logout', |
|
272 | + 'href' => 'action/logout', |
|
273 | + 'text' => elgg_echo('logout'), |
|
274 | + 'is_trusted' => true, |
|
275 | + 'priority' => 900, |
|
276 | + ]); |
|
277 | + |
|
278 | + $return[] = \ElggMenuItem::factory([ |
|
279 | + 'name' => 'view_site', |
|
280 | + 'href' => elgg_get_site_url(), |
|
281 | + 'text' => elgg_echo('admin:view_site'), |
|
282 | + 'is_trusted' => true, |
|
283 | + 'priority' => 800, |
|
284 | + ]); |
|
285 | + |
|
286 | + if (elgg_get_config('elgg_maintenance_mode')) { |
|
287 | + $return[] = \ElggMenuItem::factory([ |
|
288 | + 'name' => 'maintenance', |
|
289 | + 'href' => 'admin/configure_utilities/maintenance', |
|
290 | + 'text' => elgg_echo('admin:configure_utilities:maintenance'), |
|
291 | + 'link_class' => 'elgg-maintenance-mode-warning', |
|
292 | + 'priority' => 700, |
|
293 | + ]); |
|
294 | + } |
|
295 | 295 | |
296 | - return $return; |
|
296 | + return $return; |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | /** |
@@ -310,35 +310,35 @@ discard block |
||
310 | 310 | * @since 3.0 |
311 | 311 | */ |
312 | 312 | function _elgg_admin_footer_menu($hook, $type, $return, $params) { |
313 | - if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) { |
|
314 | - return; |
|
315 | - } |
|
316 | - |
|
317 | - $return[] = \ElggMenuItem::factory([ |
|
318 | - 'name' => 'faq', |
|
319 | - 'text' => elgg_echo('admin:footer:faq'), |
|
320 | - 'href' => 'http://learn.elgg.org/en/stable/appendix/faqs.html', |
|
321 | - ]); |
|
322 | - |
|
323 | - $return[] = \ElggMenuItem::factory([ |
|
324 | - 'name' => 'manual', |
|
325 | - 'text' => elgg_echo('admin:footer:manual'), |
|
326 | - 'href' => 'http://learn.elgg.org/en/stable/admin/index.html', |
|
327 | - ]); |
|
328 | - |
|
329 | - $return[] = \ElggMenuItem::factory([ |
|
330 | - 'name' => 'community_forums', |
|
331 | - 'text' => elgg_echo('admin:footer:community_forums'), |
|
332 | - 'href' => 'http://elgg.org/groups/all/', |
|
333 | - ]); |
|
334 | - |
|
335 | - $return[] = \ElggMenuItem::factory([ |
|
336 | - 'name' => 'blog', |
|
337 | - 'text' => elgg_echo('admin:footer:blog'), |
|
338 | - 'href' => 'https://elgg.org/blog/all', |
|
339 | - ]); |
|
313 | + if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) { |
|
314 | + return; |
|
315 | + } |
|
316 | + |
|
317 | + $return[] = \ElggMenuItem::factory([ |
|
318 | + 'name' => 'faq', |
|
319 | + 'text' => elgg_echo('admin:footer:faq'), |
|
320 | + 'href' => 'http://learn.elgg.org/en/stable/appendix/faqs.html', |
|
321 | + ]); |
|
322 | + |
|
323 | + $return[] = \ElggMenuItem::factory([ |
|
324 | + 'name' => 'manual', |
|
325 | + 'text' => elgg_echo('admin:footer:manual'), |
|
326 | + 'href' => 'http://learn.elgg.org/en/stable/admin/index.html', |
|
327 | + ]); |
|
328 | + |
|
329 | + $return[] = \ElggMenuItem::factory([ |
|
330 | + 'name' => 'community_forums', |
|
331 | + 'text' => elgg_echo('admin:footer:community_forums'), |
|
332 | + 'href' => 'http://elgg.org/groups/all/', |
|
333 | + ]); |
|
334 | + |
|
335 | + $return[] = \ElggMenuItem::factory([ |
|
336 | + 'name' => 'blog', |
|
337 | + 'text' => elgg_echo('admin:footer:blog'), |
|
338 | + 'href' => 'https://elgg.org/blog/all', |
|
339 | + ]); |
|
340 | 340 | |
341 | - return $return; |
|
341 | + return $return; |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | /** |
@@ -354,148 +354,148 @@ discard block |
||
354 | 354 | * @since 3.0 |
355 | 355 | */ |
356 | 356 | function _elgg_admin_page_menu(\Elgg\Hook $hook) { |
357 | - if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) { |
|
358 | - return; |
|
359 | - } |
|
357 | + if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) { |
|
358 | + return; |
|
359 | + } |
|
360 | 360 | |
361 | - $return = $hook->getValue(); |
|
362 | - |
|
363 | - // administer |
|
364 | - $return[] = \ElggMenuItem::factory([ |
|
365 | - 'name' => 'dashboard', |
|
366 | - 'href' => 'admin', |
|
367 | - 'text' => elgg_echo('admin:dashboard'), |
|
368 | - 'priority' => 10, |
|
369 | - 'section' => 'administer', |
|
370 | - ]); |
|
361 | + $return = $hook->getValue(); |
|
362 | + |
|
363 | + // administer |
|
364 | + $return[] = \ElggMenuItem::factory([ |
|
365 | + 'name' => 'dashboard', |
|
366 | + 'href' => 'admin', |
|
367 | + 'text' => elgg_echo('admin:dashboard'), |
|
368 | + 'priority' => 10, |
|
369 | + 'section' => 'administer', |
|
370 | + ]); |
|
371 | 371 | |
372 | - $return[] = \ElggMenuItem::factory([ |
|
373 | - 'name' => 'plugins', |
|
374 | - 'href' => 'admin/plugins', |
|
375 | - 'text' => elgg_echo('admin:plugins'), |
|
376 | - 'priority' => 30, |
|
377 | - 'section' => 'administer', |
|
378 | - ]); |
|
379 | - |
|
380 | - $return[] = \ElggMenuItem::factory([ |
|
381 | - 'name' => 'users', |
|
382 | - 'text' => elgg_echo('admin:users'), |
|
383 | - 'priority' => 40, |
|
384 | - 'section' => 'administer', |
|
385 | - ]); |
|
386 | - $return[] = \ElggMenuItem::factory([ |
|
387 | - 'name' => 'users:online', |
|
388 | - 'text' => elgg_echo('admin:users:online'), |
|
389 | - 'href' => 'admin/users/online', |
|
390 | - 'priority' => 10, |
|
391 | - 'section' => 'administer', |
|
392 | - 'parent_name' => 'users', |
|
393 | - ]); |
|
394 | - $return[] = \ElggMenuItem::factory([ |
|
395 | - 'name' => 'users:admins', |
|
396 | - 'text' => elgg_echo('admin:users:admins'), |
|
397 | - 'href' => 'admin/users/admins', |
|
398 | - 'priority' => 20, |
|
399 | - 'section' => 'administer', |
|
400 | - 'parent_name' => 'users', |
|
401 | - ]); |
|
402 | - $return[] = \ElggMenuItem::factory([ |
|
403 | - 'name' => 'users:newest', |
|
404 | - 'text' => elgg_echo('admin:users:newest'), |
|
405 | - 'href' => 'admin/users/newest', |
|
406 | - 'priority' => 30, |
|
407 | - 'section' => 'administer', |
|
408 | - 'parent_name' => 'users', |
|
409 | - ]); |
|
410 | - $return[] = \ElggMenuItem::factory([ |
|
411 | - 'name' => 'users:add', |
|
412 | - 'text' => elgg_echo('admin:users:add'), |
|
413 | - 'href' => 'admin/users/add', |
|
414 | - 'priority' => 40, |
|
415 | - 'section' => 'administer', |
|
416 | - 'parent_name' => 'users', |
|
417 | - ]); |
|
418 | - $return[] = \ElggMenuItem::factory([ |
|
419 | - 'name' => 'upgrades', |
|
420 | - 'href' => 'admin/upgrades', |
|
421 | - 'text' => elgg_echo('admin:upgrades'), |
|
422 | - 'priority' => 600, |
|
423 | - 'section' => 'administer', |
|
424 | - ]); |
|
372 | + $return[] = \ElggMenuItem::factory([ |
|
373 | + 'name' => 'plugins', |
|
374 | + 'href' => 'admin/plugins', |
|
375 | + 'text' => elgg_echo('admin:plugins'), |
|
376 | + 'priority' => 30, |
|
377 | + 'section' => 'administer', |
|
378 | + ]); |
|
379 | + |
|
380 | + $return[] = \ElggMenuItem::factory([ |
|
381 | + 'name' => 'users', |
|
382 | + 'text' => elgg_echo('admin:users'), |
|
383 | + 'priority' => 40, |
|
384 | + 'section' => 'administer', |
|
385 | + ]); |
|
386 | + $return[] = \ElggMenuItem::factory([ |
|
387 | + 'name' => 'users:online', |
|
388 | + 'text' => elgg_echo('admin:users:online'), |
|
389 | + 'href' => 'admin/users/online', |
|
390 | + 'priority' => 10, |
|
391 | + 'section' => 'administer', |
|
392 | + 'parent_name' => 'users', |
|
393 | + ]); |
|
394 | + $return[] = \ElggMenuItem::factory([ |
|
395 | + 'name' => 'users:admins', |
|
396 | + 'text' => elgg_echo('admin:users:admins'), |
|
397 | + 'href' => 'admin/users/admins', |
|
398 | + 'priority' => 20, |
|
399 | + 'section' => 'administer', |
|
400 | + 'parent_name' => 'users', |
|
401 | + ]); |
|
402 | + $return[] = \ElggMenuItem::factory([ |
|
403 | + 'name' => 'users:newest', |
|
404 | + 'text' => elgg_echo('admin:users:newest'), |
|
405 | + 'href' => 'admin/users/newest', |
|
406 | + 'priority' => 30, |
|
407 | + 'section' => 'administer', |
|
408 | + 'parent_name' => 'users', |
|
409 | + ]); |
|
410 | + $return[] = \ElggMenuItem::factory([ |
|
411 | + 'name' => 'users:add', |
|
412 | + 'text' => elgg_echo('admin:users:add'), |
|
413 | + 'href' => 'admin/users/add', |
|
414 | + 'priority' => 40, |
|
415 | + 'section' => 'administer', |
|
416 | + 'parent_name' => 'users', |
|
417 | + ]); |
|
418 | + $return[] = \ElggMenuItem::factory([ |
|
419 | + 'name' => 'upgrades', |
|
420 | + 'href' => 'admin/upgrades', |
|
421 | + 'text' => elgg_echo('admin:upgrades'), |
|
422 | + 'priority' => 600, |
|
423 | + 'section' => 'administer', |
|
424 | + ]); |
|
425 | 425 | |
426 | - $return[] = \ElggMenuItem::factory([ |
|
427 | - 'name' => 'administer_utilities', |
|
428 | - 'text' => elgg_echo('admin:administer_utilities'), |
|
429 | - 'priority' => 50, |
|
430 | - 'section' => 'administer', |
|
431 | - ]); |
|
426 | + $return[] = \ElggMenuItem::factory([ |
|
427 | + 'name' => 'administer_utilities', |
|
428 | + 'text' => elgg_echo('admin:administer_utilities'), |
|
429 | + 'priority' => 50, |
|
430 | + 'section' => 'administer', |
|
431 | + ]); |
|
432 | 432 | |
433 | - // configure |
|
434 | - $return[] = \ElggMenuItem::factory([ |
|
435 | - 'name' => 'settings:basic', |
|
436 | - 'href' => 'admin/settings/basic', |
|
437 | - 'text' => elgg_echo('admin:settings:basic'), |
|
438 | - 'priority' => 10, |
|
439 | - 'section' => 'configure', |
|
440 | - ]); |
|
441 | - $return[] = \ElggMenuItem::factory([ |
|
442 | - 'name' => 'settings:advanced', |
|
443 | - 'href' => 'admin/settings/advanced', |
|
444 | - 'text' => elgg_echo('admin:settings:advanced'), |
|
445 | - 'priority' => 20, |
|
446 | - 'section' => 'configure', |
|
447 | - ]); |
|
448 | - $return[] = \ElggMenuItem::factory([ |
|
449 | - 'name' => 'security', |
|
450 | - 'href' => 'admin/security', |
|
451 | - 'text' => elgg_echo('admin:security'), |
|
452 | - 'priority' => 30, |
|
453 | - 'section' => 'configure', |
|
454 | - ]); |
|
455 | - |
|
456 | - $return[] = \ElggMenuItem::factory([ |
|
457 | - 'name' => 'configure_utilities', |
|
458 | - 'text' => elgg_echo('admin:configure_utilities'), |
|
459 | - 'priority' => 600, |
|
460 | - 'section' => 'configure', |
|
461 | - ]); |
|
462 | - $return[] = \ElggMenuItem::factory([ |
|
463 | - 'name' => 'configure_utilities:maintenance', |
|
464 | - 'text' => elgg_echo('admin:configure_utilities:maintenance'), |
|
465 | - 'href' => 'admin/configure_utilities/maintenance', |
|
466 | - 'section' => 'configure', |
|
467 | - 'parent_name' => 'configure_utilities', |
|
468 | - ]); |
|
469 | - $return[] = \ElggMenuItem::factory([ |
|
470 | - 'name' => 'configure_utilities:menu_items', |
|
471 | - 'text' => elgg_echo('admin:configure_utilities:menu_items'), |
|
472 | - 'href' => 'admin/configure_utilities/menu_items', |
|
473 | - 'section' => 'configure', |
|
474 | - 'parent_name' => 'configure_utilities', |
|
475 | - ]); |
|
476 | - $return[] = \ElggMenuItem::factory([ |
|
477 | - 'name' => 'configure_utilities:robots', |
|
478 | - 'text' => elgg_echo('admin:configure_utilities:robots'), |
|
479 | - 'href' => 'admin/configure_utilities/robots', |
|
480 | - 'section' => 'configure', |
|
481 | - 'parent_name' => 'configure_utilities', |
|
482 | - ]); |
|
433 | + // configure |
|
434 | + $return[] = \ElggMenuItem::factory([ |
|
435 | + 'name' => 'settings:basic', |
|
436 | + 'href' => 'admin/settings/basic', |
|
437 | + 'text' => elgg_echo('admin:settings:basic'), |
|
438 | + 'priority' => 10, |
|
439 | + 'section' => 'configure', |
|
440 | + ]); |
|
441 | + $return[] = \ElggMenuItem::factory([ |
|
442 | + 'name' => 'settings:advanced', |
|
443 | + 'href' => 'admin/settings/advanced', |
|
444 | + 'text' => elgg_echo('admin:settings:advanced'), |
|
445 | + 'priority' => 20, |
|
446 | + 'section' => 'configure', |
|
447 | + ]); |
|
448 | + $return[] = \ElggMenuItem::factory([ |
|
449 | + 'name' => 'security', |
|
450 | + 'href' => 'admin/security', |
|
451 | + 'text' => elgg_echo('admin:security'), |
|
452 | + 'priority' => 30, |
|
453 | + 'section' => 'configure', |
|
454 | + ]); |
|
455 | + |
|
456 | + $return[] = \ElggMenuItem::factory([ |
|
457 | + 'name' => 'configure_utilities', |
|
458 | + 'text' => elgg_echo('admin:configure_utilities'), |
|
459 | + 'priority' => 600, |
|
460 | + 'section' => 'configure', |
|
461 | + ]); |
|
462 | + $return[] = \ElggMenuItem::factory([ |
|
463 | + 'name' => 'configure_utilities:maintenance', |
|
464 | + 'text' => elgg_echo('admin:configure_utilities:maintenance'), |
|
465 | + 'href' => 'admin/configure_utilities/maintenance', |
|
466 | + 'section' => 'configure', |
|
467 | + 'parent_name' => 'configure_utilities', |
|
468 | + ]); |
|
469 | + $return[] = \ElggMenuItem::factory([ |
|
470 | + 'name' => 'configure_utilities:menu_items', |
|
471 | + 'text' => elgg_echo('admin:configure_utilities:menu_items'), |
|
472 | + 'href' => 'admin/configure_utilities/menu_items', |
|
473 | + 'section' => 'configure', |
|
474 | + 'parent_name' => 'configure_utilities', |
|
475 | + ]); |
|
476 | + $return[] = \ElggMenuItem::factory([ |
|
477 | + 'name' => 'configure_utilities:robots', |
|
478 | + 'text' => elgg_echo('admin:configure_utilities:robots'), |
|
479 | + 'href' => 'admin/configure_utilities/robots', |
|
480 | + 'section' => 'configure', |
|
481 | + 'parent_name' => 'configure_utilities', |
|
482 | + ]); |
|
483 | 483 | |
484 | - // information |
|
485 | - $return[] = \ElggMenuItem::factory([ |
|
486 | - 'name' => 'statistics', |
|
487 | - 'href' => 'admin/statistics', |
|
488 | - 'text' => elgg_echo('admin:statistics'), |
|
489 | - 'section' => 'information', |
|
490 | - ]); |
|
491 | - $return[] = \ElggMenuItem::factory([ |
|
492 | - 'name' => 'server', |
|
493 | - 'href' => 'admin/server', |
|
494 | - 'text' => elgg_echo('admin:server'), |
|
495 | - 'section' => 'information', |
|
496 | - ]); |
|
484 | + // information |
|
485 | + $return[] = \ElggMenuItem::factory([ |
|
486 | + 'name' => 'statistics', |
|
487 | + 'href' => 'admin/statistics', |
|
488 | + 'text' => elgg_echo('admin:statistics'), |
|
489 | + 'section' => 'information', |
|
490 | + ]); |
|
491 | + $return[] = \ElggMenuItem::factory([ |
|
492 | + 'name' => 'server', |
|
493 | + 'href' => 'admin/server', |
|
494 | + 'text' => elgg_echo('admin:server'), |
|
495 | + 'section' => 'information', |
|
496 | + ]); |
|
497 | 497 | |
498 | - return $return; |
|
498 | + return $return; |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | /** |
@@ -511,56 +511,56 @@ discard block |
||
511 | 511 | * @since 3.0 |
512 | 512 | */ |
513 | 513 | function _elgg_admin_page_menu_plugin_settings(\Elgg\Hook $hook) { |
514 | - if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) { |
|
515 | - return; |
|
516 | - } |
|
514 | + if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) { |
|
515 | + return; |
|
516 | + } |
|
517 | 517 | |
518 | - // plugin settings |
|
519 | - $active_plugins = elgg_get_plugins('active'); |
|
520 | - if (!$active_plugins) { |
|
521 | - // nothing added because no items |
|
522 | - return; |
|
523 | - } |
|
518 | + // plugin settings |
|
519 | + $active_plugins = elgg_get_plugins('active'); |
|
520 | + if (!$active_plugins) { |
|
521 | + // nothing added because no items |
|
522 | + return; |
|
523 | + } |
|
524 | 524 | |
525 | - $plugins_with_settings = []; |
|
525 | + $plugins_with_settings = []; |
|
526 | 526 | |
527 | - foreach ($active_plugins as $plugin) { |
|
528 | - $plugin_id = $plugin->getID(); |
|
527 | + foreach ($active_plugins as $plugin) { |
|
528 | + $plugin_id = $plugin->getID(); |
|
529 | 529 | |
530 | - if (!elgg_view_exists("plugins/{$plugin_id}/settings") ) { |
|
531 | - continue; |
|
532 | - } |
|
533 | - $plugin_name = $plugin->getDisplayName(); |
|
534 | - $plugins_with_settings[$plugin_name] = [ |
|
535 | - 'name' => $plugin_id, |
|
536 | - 'href' => "admin/plugin_settings/$plugin_id", |
|
537 | - 'text' => $plugin_name, |
|
538 | - 'parent_name' => 'plugin_settings', |
|
539 | - 'section' => 'configure', |
|
540 | - ]; |
|
541 | - } |
|
530 | + if (!elgg_view_exists("plugins/{$plugin_id}/settings") ) { |
|
531 | + continue; |
|
532 | + } |
|
533 | + $plugin_name = $plugin->getDisplayName(); |
|
534 | + $plugins_with_settings[$plugin_name] = [ |
|
535 | + 'name' => $plugin_id, |
|
536 | + 'href' => "admin/plugin_settings/$plugin_id", |
|
537 | + 'text' => $plugin_name, |
|
538 | + 'parent_name' => 'plugin_settings', |
|
539 | + 'section' => 'configure', |
|
540 | + ]; |
|
541 | + } |
|
542 | 542 | |
543 | - if (empty($plugins_with_settings)) { |
|
544 | - return; |
|
545 | - } |
|
543 | + if (empty($plugins_with_settings)) { |
|
544 | + return; |
|
545 | + } |
|
546 | 546 | |
547 | - $return = $hook->getValue(); |
|
547 | + $return = $hook->getValue(); |
|
548 | 548 | |
549 | - $return[] = \ElggMenuItem::factory([ |
|
550 | - 'name' => 'plugin_settings', |
|
551 | - 'text' => elgg_echo('admin:plugin_settings'), |
|
552 | - 'section' => 'configure', |
|
553 | - ]); |
|
549 | + $return[] = \ElggMenuItem::factory([ |
|
550 | + 'name' => 'plugin_settings', |
|
551 | + 'text' => elgg_echo('admin:plugin_settings'), |
|
552 | + 'section' => 'configure', |
|
553 | + ]); |
|
554 | 554 | |
555 | - ksort($plugins_with_settings); |
|
556 | - $priority = 0; |
|
557 | - foreach ($plugins_with_settings as $plugin_item) { |
|
558 | - $priority += 10; |
|
559 | - $plugin_item['priority'] = $priority; |
|
560 | - $return[] = \ElggMenuItem::factory($plugin_item); |
|
561 | - } |
|
555 | + ksort($plugins_with_settings); |
|
556 | + $priority = 0; |
|
557 | + foreach ($plugins_with_settings as $plugin_item) { |
|
558 | + $priority += 10; |
|
559 | + $plugin_item['priority'] = $priority; |
|
560 | + $return[] = \ElggMenuItem::factory($plugin_item); |
|
561 | + } |
|
562 | 562 | |
563 | - return $return; |
|
563 | + return $return; |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | /** |
@@ -572,53 +572,53 @@ discard block |
||
572 | 572 | * @access private |
573 | 573 | */ |
574 | 574 | function _elgg_admin_page_handler($page) { |
575 | - elgg_admin_gatekeeper(); |
|
576 | - elgg_set_context('admin'); |
|
577 | - |
|
578 | - elgg_unregister_css('elgg'); |
|
579 | - elgg_require_js('elgg/admin'); |
|
580 | - |
|
581 | - // default to dashboard |
|
582 | - if (!isset($page[0]) || empty($page[0])) { |
|
583 | - $page = ['dashboard']; |
|
584 | - } |
|
585 | - |
|
586 | - // was going to fix this in the page_handler() function but |
|
587 | - // it's commented to explicitly return a string if there's a trailing / |
|
588 | - if (empty($page[count($page) - 1])) { |
|
589 | - array_pop($page); |
|
590 | - } |
|
591 | - |
|
592 | - $vars = ['page' => $page]; |
|
593 | - |
|
594 | - // special page for plugin settings since we create the form for them |
|
595 | - if ($page[0] == 'plugin_settings') { |
|
596 | - if (isset($page[1]) && (elgg_view_exists("plugins/{$page[1]}/settings"))) { |
|
597 | - $view = 'admin/plugin_settings'; |
|
598 | - $plugin = elgg_get_plugin_from_id($page[1]); |
|
599 | - $vars['plugin'] = $plugin; |
|
600 | - |
|
601 | - $title = elgg_echo("admin:{$page[0]}"); |
|
602 | - } else { |
|
603 | - forward('', '404'); |
|
604 | - } |
|
605 | - } else { |
|
606 | - $view = 'admin/' . implode('/', $page); |
|
607 | - $title = elgg_echo("admin:{$page[0]}"); |
|
608 | - if (count($page) > 1) { |
|
609 | - $title .= ' : ' . elgg_echo('admin:' . implode(':', $page)); |
|
610 | - } |
|
611 | - } |
|
612 | - |
|
613 | - // gets content and prevents direct access to 'components' views |
|
614 | - if ($page[0] == 'components' || !($content = elgg_view($view, $vars))) { |
|
615 | - $title = elgg_echo('admin:unknown_section'); |
|
616 | - $content = elgg_echo('admin:unknown_section'); |
|
617 | - } |
|
618 | - |
|
619 | - $body = elgg_view_layout('admin', ['content' => $content, 'title' => $title]); |
|
620 | - echo elgg_view_page($title, $body, 'admin'); |
|
621 | - return true; |
|
575 | + elgg_admin_gatekeeper(); |
|
576 | + elgg_set_context('admin'); |
|
577 | + |
|
578 | + elgg_unregister_css('elgg'); |
|
579 | + elgg_require_js('elgg/admin'); |
|
580 | + |
|
581 | + // default to dashboard |
|
582 | + if (!isset($page[0]) || empty($page[0])) { |
|
583 | + $page = ['dashboard']; |
|
584 | + } |
|
585 | + |
|
586 | + // was going to fix this in the page_handler() function but |
|
587 | + // it's commented to explicitly return a string if there's a trailing / |
|
588 | + if (empty($page[count($page) - 1])) { |
|
589 | + array_pop($page); |
|
590 | + } |
|
591 | + |
|
592 | + $vars = ['page' => $page]; |
|
593 | + |
|
594 | + // special page for plugin settings since we create the form for them |
|
595 | + if ($page[0] == 'plugin_settings') { |
|
596 | + if (isset($page[1]) && (elgg_view_exists("plugins/{$page[1]}/settings"))) { |
|
597 | + $view = 'admin/plugin_settings'; |
|
598 | + $plugin = elgg_get_plugin_from_id($page[1]); |
|
599 | + $vars['plugin'] = $plugin; |
|
600 | + |
|
601 | + $title = elgg_echo("admin:{$page[0]}"); |
|
602 | + } else { |
|
603 | + forward('', '404'); |
|
604 | + } |
|
605 | + } else { |
|
606 | + $view = 'admin/' . implode('/', $page); |
|
607 | + $title = elgg_echo("admin:{$page[0]}"); |
|
608 | + if (count($page) > 1) { |
|
609 | + $title .= ' : ' . elgg_echo('admin:' . implode(':', $page)); |
|
610 | + } |
|
611 | + } |
|
612 | + |
|
613 | + // gets content and prevents direct access to 'components' views |
|
614 | + if ($page[0] == 'components' || !($content = elgg_view($view, $vars))) { |
|
615 | + $title = elgg_echo('admin:unknown_section'); |
|
616 | + $content = elgg_echo('admin:unknown_section'); |
|
617 | + } |
|
618 | + |
|
619 | + $body = elgg_view_layout('admin', ['content' => $content, 'title' => $title]); |
|
620 | + echo elgg_view_page($title, $body, 'admin'); |
|
621 | + return true; |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | /** |
@@ -638,13 +638,13 @@ discard block |
||
638 | 638 | * @access private |
639 | 639 | */ |
640 | 640 | function _elgg_admin_markdown_page_handler($pages) { |
641 | - elgg_set_context('admin'); |
|
641 | + elgg_set_context('admin'); |
|
642 | 642 | |
643 | - echo elgg_view_resource('admin/plugin_text_file', [ |
|
644 | - 'plugin_id' => elgg_extract(0, $pages), |
|
645 | - 'filename' => elgg_extract(1, $pages), |
|
646 | - ]); |
|
647 | - return true; |
|
643 | + echo elgg_view_resource('admin/plugin_text_file', [ |
|
644 | + 'plugin_id' => elgg_extract(0, $pages), |
|
645 | + 'filename' => elgg_extract(1, $pages), |
|
646 | + ]); |
|
647 | + return true; |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | /** |
@@ -653,8 +653,8 @@ discard block |
||
653 | 653 | * @access private |
654 | 654 | */ |
655 | 655 | function _elgg_robots_page_handler() { |
656 | - echo elgg_view_resource('robots.txt'); |
|
657 | - return true; |
|
656 | + echo elgg_view_resource('robots.txt'); |
|
657 | + return true; |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | /** |
@@ -663,8 +663,8 @@ discard block |
||
663 | 663 | * @access private |
664 | 664 | */ |
665 | 665 | function _elgg_phpinfo_page_handler() { |
666 | - echo elgg_view_resource('phpinfo'); |
|
667 | - return true; |
|
666 | + echo elgg_view_resource('phpinfo'); |
|
667 | + return true; |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | /** |
@@ -676,20 +676,20 @@ discard block |
||
676 | 676 | * @access private |
677 | 677 | */ |
678 | 678 | function _elgg_admin_maintenance_allow_url($current_url) { |
679 | - $site_path = preg_replace('~^https?~', '', elgg_get_site_url()); |
|
680 | - $current_path = preg_replace('~^https?~', '', $current_url); |
|
681 | - if (0 === strpos($current_path, $site_path)) { |
|
682 | - $current_path = ($current_path === $site_path) ? '' : substr($current_path, strlen($site_path)); |
|
683 | - } else { |
|
684 | - $current_path = false; |
|
685 | - } |
|
686 | - |
|
687 | - // allow plugins to control access for specific URLs/paths |
|
688 | - $params = [ |
|
689 | - 'current_path' => $current_path, |
|
690 | - 'current_url' => $current_url, |
|
691 | - ]; |
|
692 | - return (bool) elgg_trigger_plugin_hook('maintenance:allow', 'url', $params, false); |
|
679 | + $site_path = preg_replace('~^https?~', '', elgg_get_site_url()); |
|
680 | + $current_path = preg_replace('~^https?~', '', $current_url); |
|
681 | + if (0 === strpos($current_path, $site_path)) { |
|
682 | + $current_path = ($current_path === $site_path) ? '' : substr($current_path, strlen($site_path)); |
|
683 | + } else { |
|
684 | + $current_path = false; |
|
685 | + } |
|
686 | + |
|
687 | + // allow plugins to control access for specific URLs/paths |
|
688 | + $params = [ |
|
689 | + 'current_path' => $current_path, |
|
690 | + 'current_url' => $current_url, |
|
691 | + ]; |
|
692 | + return (bool) elgg_trigger_plugin_hook('maintenance:allow', 'url', $params, false); |
|
693 | 693 | } |
694 | 694 | |
695 | 695 | /** |
@@ -698,23 +698,23 @@ discard block |
||
698 | 698 | * @access private |
699 | 699 | */ |
700 | 700 | function _elgg_admin_maintenance_handler($hook, $type, $info) { |
701 | - if (elgg_is_admin_logged_in()) { |
|
702 | - return; |
|
703 | - } |
|
701 | + if (elgg_is_admin_logged_in()) { |
|
702 | + return; |
|
703 | + } |
|
704 | 704 | |
705 | - if ($info['identifier'] == 'action' && $info['segments'][0] == 'login') { |
|
706 | - return; |
|
707 | - } |
|
705 | + if ($info['identifier'] == 'action' && $info['segments'][0] == 'login') { |
|
706 | + return; |
|
707 | + } |
|
708 | 708 | |
709 | - if (_elgg_admin_maintenance_allow_url(current_page_url())) { |
|
710 | - return; |
|
711 | - } |
|
709 | + if (_elgg_admin_maintenance_allow_url(current_page_url())) { |
|
710 | + return; |
|
711 | + } |
|
712 | 712 | |
713 | - elgg_unregister_plugin_hook_handler('register', 'menu:login', '_elgg_login_menu_setup'); |
|
713 | + elgg_unregister_plugin_hook_handler('register', 'menu:login', '_elgg_login_menu_setup'); |
|
714 | 714 | |
715 | - echo elgg_view_resource('maintenance'); |
|
715 | + echo elgg_view_resource('maintenance'); |
|
716 | 716 | |
717 | - return false; |
|
717 | + return false; |
|
718 | 718 | } |
719 | 719 | |
720 | 720 | /** |
@@ -727,34 +727,34 @@ discard block |
||
727 | 727 | * @return bool |
728 | 728 | */ |
729 | 729 | function _elgg_admin_maintenance_action_check($hook, $type) { |
730 | - if (elgg_is_admin_logged_in()) { |
|
731 | - return true; |
|
732 | - } |
|
730 | + if (elgg_is_admin_logged_in()) { |
|
731 | + return true; |
|
732 | + } |
|
733 | 733 | |
734 | - if ($type == 'login') { |
|
735 | - $username = get_input('username'); |
|
734 | + if ($type == 'login') { |
|
735 | + $username = get_input('username'); |
|
736 | 736 | |
737 | - $user = get_user_by_username($username); |
|
737 | + $user = get_user_by_username($username); |
|
738 | 738 | |
739 | - if (!$user) { |
|
740 | - $users = get_user_by_email($username); |
|
741 | - if ($users) { |
|
742 | - $user = $users[0]; |
|
743 | - } |
|
744 | - } |
|
739 | + if (!$user) { |
|
740 | + $users = get_user_by_email($username); |
|
741 | + if ($users) { |
|
742 | + $user = $users[0]; |
|
743 | + } |
|
744 | + } |
|
745 | 745 | |
746 | - if ($user && $user->isAdmin()) { |
|
747 | - return true; |
|
748 | - } |
|
749 | - } |
|
746 | + if ($user && $user->isAdmin()) { |
|
747 | + return true; |
|
748 | + } |
|
749 | + } |
|
750 | 750 | |
751 | - if (_elgg_admin_maintenance_allow_url(current_page_url())) { |
|
752 | - return true; |
|
753 | - } |
|
751 | + if (_elgg_admin_maintenance_allow_url(current_page_url())) { |
|
752 | + return true; |
|
753 | + } |
|
754 | 754 | |
755 | - register_error(elgg_echo('actionunauthorized')); |
|
755 | + register_error(elgg_echo('actionunauthorized')); |
|
756 | 756 | |
757 | - return false; |
|
757 | + return false; |
|
758 | 758 | } |
759 | 759 | |
760 | 760 | /** |
@@ -768,30 +768,30 @@ discard block |
||
768 | 768 | * @access private |
769 | 769 | */ |
770 | 770 | function _elgg_add_admin_widgets($event, $type, $user) { |
771 | - elgg_set_ignore_access(true); |
|
772 | - |
|
773 | - // check if the user already has widgets |
|
774 | - if (elgg_get_widgets($user->getGUID(), 'admin')) { |
|
775 | - return true; |
|
776 | - } |
|
777 | - |
|
778 | - // In the form column => array of handlers in order, top to bottom |
|
779 | - $adminWidgets = [ |
|
780 | - 1 => ['control_panel', 'admin_welcome'], |
|
781 | - 2 => ['online_users', 'new_users', 'content_stats'], |
|
782 | - ]; |
|
783 | - |
|
784 | - foreach ($adminWidgets as $column => $handlers) { |
|
785 | - foreach ($handlers as $position => $handler) { |
|
786 | - $guid = elgg_create_widget($user->getGUID(), $handler, 'admin'); |
|
787 | - if ($guid) { |
|
788 | - $widget = get_entity($guid); |
|
789 | - /* @var \ElggWidget $widget */ |
|
790 | - $widget->move($column, $position); |
|
791 | - } |
|
792 | - } |
|
793 | - } |
|
794 | - elgg_set_ignore_access(false); |
|
771 | + elgg_set_ignore_access(true); |
|
772 | + |
|
773 | + // check if the user already has widgets |
|
774 | + if (elgg_get_widgets($user->getGUID(), 'admin')) { |
|
775 | + return true; |
|
776 | + } |
|
777 | + |
|
778 | + // In the form column => array of handlers in order, top to bottom |
|
779 | + $adminWidgets = [ |
|
780 | + 1 => ['control_panel', 'admin_welcome'], |
|
781 | + 2 => ['online_users', 'new_users', 'content_stats'], |
|
782 | + ]; |
|
783 | + |
|
784 | + foreach ($adminWidgets as $column => $handlers) { |
|
785 | + foreach ($handlers as $position => $handler) { |
|
786 | + $guid = elgg_create_widget($user->getGUID(), $handler, 'admin'); |
|
787 | + if ($guid) { |
|
788 | + $widget = get_entity($guid); |
|
789 | + /* @var \ElggWidget $widget */ |
|
790 | + $widget->move($column, $position); |
|
791 | + } |
|
792 | + } |
|
793 | + } |
|
794 | + elgg_set_ignore_access(false); |
|
795 | 795 | } |
796 | 796 | |
797 | 797 | /** |
@@ -806,39 +806,39 @@ discard block |
||
806 | 806 | */ |
807 | 807 | function _elgg_admin_get_admin_subscribers_admin_action($hook, $type, $return_value, $params) { |
808 | 808 | |
809 | - if (!_elgg_config()->security_notify_admins) { |
|
810 | - return; |
|
811 | - } |
|
809 | + if (!_elgg_config()->security_notify_admins) { |
|
810 | + return; |
|
811 | + } |
|
812 | 812 | |
813 | - $event = elgg_extract('event', $params); |
|
814 | - if (!($event instanceof \Elgg\Notifications\Event)) { |
|
815 | - return; |
|
816 | - } |
|
813 | + $event = elgg_extract('event', $params); |
|
814 | + if (!($event instanceof \Elgg\Notifications\Event)) { |
|
815 | + return; |
|
816 | + } |
|
817 | 817 | |
818 | - if (!in_array($event->getAction(), ['make_admin', 'remove_admin'])) { |
|
819 | - return; |
|
820 | - } |
|
818 | + if (!in_array($event->getAction(), ['make_admin', 'remove_admin'])) { |
|
819 | + return; |
|
820 | + } |
|
821 | 821 | |
822 | - $user = $event->getObject(); |
|
823 | - if (!($user instanceof \ElggUser)) { |
|
824 | - return; |
|
825 | - } |
|
822 | + $user = $event->getObject(); |
|
823 | + if (!($user instanceof \ElggUser)) { |
|
824 | + return; |
|
825 | + } |
|
826 | 826 | |
827 | - /* @var $admin_batch \Elgg\BatchResult */ |
|
828 | - $admin_batch = elgg_get_admins([ |
|
829 | - 'limit' => false, |
|
830 | - 'wheres' => [ |
|
831 | - "e.guid <> {$user->getGUID()}", |
|
832 | - ], |
|
833 | - 'batch' => true, |
|
834 | - ]); |
|
827 | + /* @var $admin_batch \Elgg\BatchResult */ |
|
828 | + $admin_batch = elgg_get_admins([ |
|
829 | + 'limit' => false, |
|
830 | + 'wheres' => [ |
|
831 | + "e.guid <> {$user->getGUID()}", |
|
832 | + ], |
|
833 | + 'batch' => true, |
|
834 | + ]); |
|
835 | 835 | |
836 | - /* @var $admin \ElggUser */ |
|
837 | - foreach ($admin_batch as $admin) { |
|
838 | - $return_value[$admin->getGUID()] = ['email']; |
|
839 | - } |
|
836 | + /* @var $admin \ElggUser */ |
|
837 | + foreach ($admin_batch as $admin) { |
|
838 | + $return_value[$admin->getGUID()] = ['email']; |
|
839 | + } |
|
840 | 840 | |
841 | - return $return_value; |
|
841 | + return $return_value; |
|
842 | 842 | } |
843 | 843 | |
844 | 844 | /** |
@@ -853,39 +853,39 @@ discard block |
||
853 | 853 | */ |
854 | 854 | function _elgg_admin_prepare_admin_notification_make_admin($hook, $type, $return_value, $params) { |
855 | 855 | |
856 | - if (!($return_value instanceof \Elgg\Notifications\Notification)) { |
|
857 | - return; |
|
858 | - } |
|
856 | + if (!($return_value instanceof \Elgg\Notifications\Notification)) { |
|
857 | + return; |
|
858 | + } |
|
859 | 859 | |
860 | - $recipient = elgg_extract('recipient', $params); |
|
861 | - $object = elgg_extract('object', $params); |
|
862 | - $actor = elgg_extract('sender', $params); |
|
863 | - $language = elgg_extract('language', $params); |
|
860 | + $recipient = elgg_extract('recipient', $params); |
|
861 | + $object = elgg_extract('object', $params); |
|
862 | + $actor = elgg_extract('sender', $params); |
|
863 | + $language = elgg_extract('language', $params); |
|
864 | 864 | |
865 | - if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser) || !($actor instanceof ElggUser)) { |
|
866 | - return; |
|
867 | - } |
|
865 | + if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser) || !($actor instanceof ElggUser)) { |
|
866 | + return; |
|
867 | + } |
|
868 | 868 | |
869 | - if ($recipient->getGUID() === $object->getGUID()) { |
|
870 | - // recipient is the user being acted on, this is handled elsewhere |
|
871 | - return; |
|
872 | - } |
|
869 | + if ($recipient->getGUID() === $object->getGUID()) { |
|
870 | + // recipient is the user being acted on, this is handled elsewhere |
|
871 | + return; |
|
872 | + } |
|
873 | 873 | |
874 | - $site = elgg_get_site_entity(); |
|
874 | + $site = elgg_get_site_entity(); |
|
875 | 875 | |
876 | - $return_value->subject = elgg_echo('admin:notification:make_admin:admin:subject', [$site->name], $language); |
|
877 | - $return_value->body = elgg_echo('admin:notification:make_admin:admin:body', [ |
|
878 | - $recipient->name, |
|
879 | - $actor->name, |
|
880 | - $object->name, |
|
881 | - $site->name, |
|
882 | - $object->getURL(), |
|
883 | - $site->getURL(), |
|
884 | - ], $language); |
|
885 | - |
|
886 | - $return_value->url = elgg_normalize_url('admin/users/admins'); |
|
876 | + $return_value->subject = elgg_echo('admin:notification:make_admin:admin:subject', [$site->name], $language); |
|
877 | + $return_value->body = elgg_echo('admin:notification:make_admin:admin:body', [ |
|
878 | + $recipient->name, |
|
879 | + $actor->name, |
|
880 | + $object->name, |
|
881 | + $site->name, |
|
882 | + $object->getURL(), |
|
883 | + $site->getURL(), |
|
884 | + ], $language); |
|
885 | + |
|
886 | + $return_value->url = elgg_normalize_url('admin/users/admins'); |
|
887 | 887 | |
888 | - return $return_value; |
|
888 | + return $return_value; |
|
889 | 889 | } |
890 | 890 | |
891 | 891 | /** |
@@ -900,39 +900,39 @@ discard block |
||
900 | 900 | */ |
901 | 901 | function _elgg_admin_prepare_admin_notification_remove_admin($hook, $type, $return_value, $params) { |
902 | 902 | |
903 | - if (!($return_value instanceof \Elgg\Notifications\Notification)) { |
|
904 | - return; |
|
905 | - } |
|
903 | + if (!($return_value instanceof \Elgg\Notifications\Notification)) { |
|
904 | + return; |
|
905 | + } |
|
906 | 906 | |
907 | - $recipient = elgg_extract('recipient', $params); |
|
908 | - $object = elgg_extract('object', $params); |
|
909 | - $actor = elgg_extract('sender', $params); |
|
910 | - $language = elgg_extract('language', $params); |
|
907 | + $recipient = elgg_extract('recipient', $params); |
|
908 | + $object = elgg_extract('object', $params); |
|
909 | + $actor = elgg_extract('sender', $params); |
|
910 | + $language = elgg_extract('language', $params); |
|
911 | 911 | |
912 | - if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser) || !($actor instanceof ElggUser)) { |
|
913 | - return; |
|
914 | - } |
|
912 | + if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser) || !($actor instanceof ElggUser)) { |
|
913 | + return; |
|
914 | + } |
|
915 | 915 | |
916 | - if ($recipient->getGUID() === $object->getGUID()) { |
|
917 | - // recipient is the user being acted on, this is handled elsewhere |
|
918 | - return; |
|
919 | - } |
|
916 | + if ($recipient->getGUID() === $object->getGUID()) { |
|
917 | + // recipient is the user being acted on, this is handled elsewhere |
|
918 | + return; |
|
919 | + } |
|
920 | 920 | |
921 | - $site = elgg_get_site_entity(); |
|
921 | + $site = elgg_get_site_entity(); |
|
922 | 922 | |
923 | - $return_value->subject = elgg_echo('admin:notification:remove_admin:admin:subject', [$site->name], $language); |
|
924 | - $return_value->body = elgg_echo('admin:notification:remove_admin:admin:body', [ |
|
925 | - $recipient->name, |
|
926 | - $actor->name, |
|
927 | - $object->name, |
|
928 | - $site->name, |
|
929 | - $object->getURL(), |
|
930 | - $site->getURL(), |
|
931 | - ], $language); |
|
932 | - |
|
933 | - $return_value->url = elgg_normalize_url('admin/users/admins'); |
|
923 | + $return_value->subject = elgg_echo('admin:notification:remove_admin:admin:subject', [$site->name], $language); |
|
924 | + $return_value->body = elgg_echo('admin:notification:remove_admin:admin:body', [ |
|
925 | + $recipient->name, |
|
926 | + $actor->name, |
|
927 | + $object->name, |
|
928 | + $site->name, |
|
929 | + $object->getURL(), |
|
930 | + $site->getURL(), |
|
931 | + ], $language); |
|
932 | + |
|
933 | + $return_value->url = elgg_normalize_url('admin/users/admins'); |
|
934 | 934 | |
935 | - return $return_value; |
|
935 | + return $return_value; |
|
936 | 936 | } |
937 | 937 | |
938 | 938 | /** |
@@ -947,27 +947,27 @@ discard block |
||
947 | 947 | */ |
948 | 948 | function _elgg_admin_get_user_subscriber_admin_action($hook, $type, $return_value, $params) { |
949 | 949 | |
950 | - if (!_elgg_config()->security_notify_user_admin) { |
|
951 | - return; |
|
952 | - } |
|
950 | + if (!_elgg_config()->security_notify_user_admin) { |
|
951 | + return; |
|
952 | + } |
|
953 | 953 | |
954 | - $event = elgg_extract('event', $params); |
|
955 | - if (!($event instanceof \Elgg\Notifications\Event)) { |
|
956 | - return; |
|
957 | - } |
|
954 | + $event = elgg_extract('event', $params); |
|
955 | + if (!($event instanceof \Elgg\Notifications\Event)) { |
|
956 | + return; |
|
957 | + } |
|
958 | 958 | |
959 | - if (!in_array($event->getAction(), ['make_admin', 'remove_admin'])) { |
|
960 | - return; |
|
961 | - } |
|
959 | + if (!in_array($event->getAction(), ['make_admin', 'remove_admin'])) { |
|
960 | + return; |
|
961 | + } |
|
962 | 962 | |
963 | - $user = $event->getObject(); |
|
964 | - if (!($user instanceof \ElggUser)) { |
|
965 | - return; |
|
966 | - } |
|
963 | + $user = $event->getObject(); |
|
964 | + if (!($user instanceof \ElggUser)) { |
|
965 | + return; |
|
966 | + } |
|
967 | 967 | |
968 | - $return_value[$user->getGUID()] = ['email']; |
|
968 | + $return_value[$user->getGUID()] = ['email']; |
|
969 | 969 | |
970 | - return $return_value; |
|
970 | + return $return_value; |
|
971 | 971 | } |
972 | 972 | |
973 | 973 | /** |
@@ -982,37 +982,37 @@ discard block |
||
982 | 982 | */ |
983 | 983 | function _elgg_admin_prepare_user_notification_make_admin($hook, $type, $return_value, $params) { |
984 | 984 | |
985 | - if (!($return_value instanceof \Elgg\Notifications\Notification)) { |
|
986 | - return; |
|
987 | - } |
|
985 | + if (!($return_value instanceof \Elgg\Notifications\Notification)) { |
|
986 | + return; |
|
987 | + } |
|
988 | 988 | |
989 | - $recipient = elgg_extract('recipient', $params); |
|
990 | - $object = elgg_extract('object', $params); |
|
991 | - $actor = elgg_extract('sender', $params); |
|
992 | - $language = elgg_extract('language', $params); |
|
989 | + $recipient = elgg_extract('recipient', $params); |
|
990 | + $object = elgg_extract('object', $params); |
|
991 | + $actor = elgg_extract('sender', $params); |
|
992 | + $language = elgg_extract('language', $params); |
|
993 | 993 | |
994 | - if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser) || !($actor instanceof ElggUser)) { |
|
995 | - return; |
|
996 | - } |
|
994 | + if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser) || !($actor instanceof ElggUser)) { |
|
995 | + return; |
|
996 | + } |
|
997 | 997 | |
998 | - if ($recipient->getGUID() !== $object->getGUID()) { |
|
999 | - // recipient is some other user, this is handled elsewhere |
|
1000 | - return; |
|
1001 | - } |
|
998 | + if ($recipient->getGUID() !== $object->getGUID()) { |
|
999 | + // recipient is some other user, this is handled elsewhere |
|
1000 | + return; |
|
1001 | + } |
|
1002 | 1002 | |
1003 | - $site = elgg_get_site_entity(); |
|
1003 | + $site = elgg_get_site_entity(); |
|
1004 | 1004 | |
1005 | - $return_value->subject = elgg_echo('admin:notification:make_admin:user:subject', [$site->name], $language); |
|
1006 | - $return_value->body = elgg_echo('admin:notification:make_admin:user:body', [ |
|
1007 | - $recipient->name, |
|
1008 | - $actor->name, |
|
1009 | - $site->name, |
|
1010 | - $site->getURL(), |
|
1011 | - ], $language); |
|
1012 | - |
|
1013 | - $return_value->url = elgg_normalize_url('admin'); |
|
1005 | + $return_value->subject = elgg_echo('admin:notification:make_admin:user:subject', [$site->name], $language); |
|
1006 | + $return_value->body = elgg_echo('admin:notification:make_admin:user:body', [ |
|
1007 | + $recipient->name, |
|
1008 | + $actor->name, |
|
1009 | + $site->name, |
|
1010 | + $site->getURL(), |
|
1011 | + ], $language); |
|
1012 | + |
|
1013 | + $return_value->url = elgg_normalize_url('admin'); |
|
1014 | 1014 | |
1015 | - return $return_value; |
|
1015 | + return $return_value; |
|
1016 | 1016 | } |
1017 | 1017 | |
1018 | 1018 | /** |
@@ -1027,39 +1027,39 @@ discard block |
||
1027 | 1027 | */ |
1028 | 1028 | function _elgg_admin_prepare_user_notification_remove_admin($hook, $type, $return_value, $params) { |
1029 | 1029 | |
1030 | - if (!($return_value instanceof \Elgg\Notifications\Notification)) { |
|
1031 | - return; |
|
1032 | - } |
|
1030 | + if (!($return_value instanceof \Elgg\Notifications\Notification)) { |
|
1031 | + return; |
|
1032 | + } |
|
1033 | 1033 | |
1034 | - $recipient = elgg_extract('recipient', $params); |
|
1035 | - $object = elgg_extract('object', $params); |
|
1036 | - $actor = elgg_extract('sender', $params); |
|
1037 | - $language = elgg_extract('language', $params); |
|
1034 | + $recipient = elgg_extract('recipient', $params); |
|
1035 | + $object = elgg_extract('object', $params); |
|
1036 | + $actor = elgg_extract('sender', $params); |
|
1037 | + $language = elgg_extract('language', $params); |
|
1038 | 1038 | |
1039 | - if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser) || !($actor instanceof ElggUser)) { |
|
1040 | - return; |
|
1041 | - } |
|
1039 | + if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser) || !($actor instanceof ElggUser)) { |
|
1040 | + return; |
|
1041 | + } |
|
1042 | 1042 | |
1043 | - if ($recipient->getGUID() !== $object->getGUID()) { |
|
1044 | - // recipient is some other user, this is handled elsewhere |
|
1045 | - return; |
|
1046 | - } |
|
1043 | + if ($recipient->getGUID() !== $object->getGUID()) { |
|
1044 | + // recipient is some other user, this is handled elsewhere |
|
1045 | + return; |
|
1046 | + } |
|
1047 | 1047 | |
1048 | - $site = elgg_get_site_entity(); |
|
1048 | + $site = elgg_get_site_entity(); |
|
1049 | 1049 | |
1050 | - $return_value->subject = elgg_echo('admin:notification:remove_admin:user:subject', [$site->name], $language); |
|
1051 | - $return_value->body = elgg_echo('admin:notification:remove_admin:user:body', [ |
|
1052 | - $recipient->name, |
|
1053 | - $actor->name, |
|
1054 | - $site->name, |
|
1055 | - $site->getURL(), |
|
1056 | - ], $language); |
|
1057 | - |
|
1058 | - $return_value->url = false; |
|
1050 | + $return_value->subject = elgg_echo('admin:notification:remove_admin:user:subject', [$site->name], $language); |
|
1051 | + $return_value->body = elgg_echo('admin:notification:remove_admin:user:body', [ |
|
1052 | + $recipient->name, |
|
1053 | + $actor->name, |
|
1054 | + $site->name, |
|
1055 | + $site->getURL(), |
|
1056 | + ], $language); |
|
1057 | + |
|
1058 | + $return_value->url = false; |
|
1059 | 1059 | |
1060 | - return $return_value; |
|
1060 | + return $return_value; |
|
1061 | 1061 | } |
1062 | 1062 | |
1063 | 1063 | return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
1064 | - $events->registerHandler('init', 'system', '_elgg_admin_init'); |
|
1064 | + $events->registerHandler('init', 'system', '_elgg_admin_init'); |
|
1065 | 1065 | }; |