@@ -129,7 +129,7 @@ |
||
129 | 129 | * |
130 | 130 | * @param string $name The name of the config value |
131 | 131 | * |
132 | - * @return mixed|null |
|
132 | + * @return string|boolean |
|
133 | 133 | */ |
134 | 134 | function get($name) { |
135 | 135 | $sql = " |
@@ -11,99 +11,99 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class ConfigTable { |
13 | 13 | |
14 | - /** |
|
15 | - * @var \Elgg\Database |
|
16 | - */ |
|
17 | - protected $db; |
|
14 | + /** |
|
15 | + * @var \Elgg\Database |
|
16 | + */ |
|
17 | + protected $db; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @var \Elgg\BootService |
|
21 | - */ |
|
22 | - protected $boot; |
|
19 | + /** |
|
20 | + * @var \Elgg\BootService |
|
21 | + */ |
|
22 | + protected $boot; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @var \Elgg\Logger |
|
26 | - */ |
|
27 | - protected $logger; |
|
24 | + /** |
|
25 | + * @var \Elgg\Logger |
|
26 | + */ |
|
27 | + protected $logger; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Constructor |
|
31 | - * |
|
32 | - * @param \Elgg\Database $db Database |
|
33 | - * @param \Elgg\BootService $boot BootService |
|
34 | - * @param \Elgg\Logger $logger Logger |
|
35 | - */ |
|
36 | - public function __construct(\Elgg\Database $db, \Elgg\BootService $boot, \Elgg\Logger $logger) { |
|
37 | - $this->db = $db; |
|
38 | - $this->boot = $boot; |
|
39 | - $this->logger = $logger; |
|
40 | - } |
|
29 | + /** |
|
30 | + * Constructor |
|
31 | + * |
|
32 | + * @param \Elgg\Database $db Database |
|
33 | + * @param \Elgg\BootService $boot BootService |
|
34 | + * @param \Elgg\Logger $logger Logger |
|
35 | + */ |
|
36 | + public function __construct(\Elgg\Database $db, \Elgg\BootService $boot, \Elgg\Logger $logger) { |
|
37 | + $this->db = $db; |
|
38 | + $this->boot = $boot; |
|
39 | + $this->logger = $logger; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Removes a config setting. |
|
44 | - * |
|
45 | - * @param string $name The name of the field. |
|
46 | - * |
|
47 | - * @return bool Success or failure |
|
48 | - */ |
|
49 | - function remove($name) { |
|
50 | - $query = " |
|
42 | + /** |
|
43 | + * Removes a config setting. |
|
44 | + * |
|
45 | + * @param string $name The name of the field. |
|
46 | + * |
|
47 | + * @return bool Success or failure |
|
48 | + */ |
|
49 | + function remove($name) { |
|
50 | + $query = " |
|
51 | 51 | DELETE FROM {$this->db->prefix}config |
52 | 52 | WHERE name = :name |
53 | 53 | "; |
54 | 54 | |
55 | - $params = [ |
|
56 | - ':name' => $name, |
|
57 | - ]; |
|
55 | + $params = [ |
|
56 | + ':name' => $name, |
|
57 | + ]; |
|
58 | 58 | |
59 | - $this->boot->invalidateCache(); |
|
59 | + $this->boot->invalidateCache(); |
|
60 | 60 | |
61 | - return $this->db->deleteData($query, $params) !== false; |
|
62 | - } |
|
61 | + return $this->db->deleteData($query, $params) !== false; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Add or update a config setting. |
|
66 | - * |
|
67 | - * Plugin authors should use elgg_save_config(). |
|
68 | - * |
|
69 | - * If the config name already exists, it will be updated to the new value. |
|
70 | - * |
|
71 | - * @note Internal: These settings are stored in the dbprefix_config table and read |
|
72 | - * during system boot into the config service. |
|
73 | - * |
|
74 | - * @note Internal: The value is serialized so we maintain type information. |
|
75 | - * |
|
76 | - * @param string $name The name of the configuration value |
|
77 | - * @param mixed $value Its value |
|
78 | - * |
|
79 | - * @return bool |
|
80 | - */ |
|
81 | - function set($name, $value) { |
|
82 | - // cannot store anything longer than 255 characters in db, so catch before we set |
|
83 | - if (elgg_strlen($name) > 255) { |
|
84 | - $this->logger->error("The name length for configuration variables cannot be greater than 255"); |
|
85 | - return false; |
|
86 | - } |
|
64 | + /** |
|
65 | + * Add or update a config setting. |
|
66 | + * |
|
67 | + * Plugin authors should use elgg_save_config(). |
|
68 | + * |
|
69 | + * If the config name already exists, it will be updated to the new value. |
|
70 | + * |
|
71 | + * @note Internal: These settings are stored in the dbprefix_config table and read |
|
72 | + * during system boot into the config service. |
|
73 | + * |
|
74 | + * @note Internal: The value is serialized so we maintain type information. |
|
75 | + * |
|
76 | + * @param string $name The name of the configuration value |
|
77 | + * @param mixed $value Its value |
|
78 | + * |
|
79 | + * @return bool |
|
80 | + */ |
|
81 | + function set($name, $value) { |
|
82 | + // cannot store anything longer than 255 characters in db, so catch before we set |
|
83 | + if (elgg_strlen($name) > 255) { |
|
84 | + $this->logger->error("The name length for configuration variables cannot be greater than 255"); |
|
85 | + return false; |
|
86 | + } |
|
87 | 87 | |
88 | - $sql = " |
|
88 | + $sql = " |
|
89 | 89 | INSERT INTO {$this->db->prefix}config |
90 | 90 | SET name = :name, |
91 | 91 | value = :value |
92 | 92 | ON DUPLICATE KEY UPDATE value = :value |
93 | 93 | "; |
94 | 94 | |
95 | - $params = [ |
|
96 | - ':name' => $name, |
|
97 | - ':value' => serialize($value), |
|
98 | - ]; |
|
95 | + $params = [ |
|
96 | + ':name' => $name, |
|
97 | + ':value' => serialize($value), |
|
98 | + ]; |
|
99 | 99 | |
100 | - $version = (int) _elgg_config()->version; |
|
100 | + $version = (int) _elgg_config()->version; |
|
101 | 101 | |
102 | - if (!empty($version) && $version < 2016102500) { |
|
103 | - // need to do this the old way as long as site_guid columns have not been dropped |
|
104 | - // need to check if we are not updating version after removing the site_guid |
|
105 | - if ($name !== 'version' || $value !== 2016102500) { |
|
106 | - $sql = " |
|
102 | + if (!empty($version) && $version < 2016102500) { |
|
103 | + // need to do this the old way as long as site_guid columns have not been dropped |
|
104 | + // need to check if we are not updating version after removing the site_guid |
|
105 | + if ($name !== 'version' || $value !== 2016102500) { |
|
106 | + $sql = " |
|
107 | 107 | INSERT INTO {$this->db->prefix}config |
108 | 108 | SET name = :name, |
109 | 109 | value = :value, |
@@ -111,93 +111,93 @@ discard block |
||
111 | 111 | ON DUPLICATE KEY UPDATE value = :value |
112 | 112 | "; |
113 | 113 | |
114 | - $params[':site_guid'] = 1; |
|
115 | - } |
|
116 | - } |
|
114 | + $params[':site_guid'] = 1; |
|
115 | + } |
|
116 | + } |
|
117 | 117 | |
118 | - $result = $this->db->insertData($sql, $params); |
|
118 | + $result = $this->db->insertData($sql, $params); |
|
119 | 119 | |
120 | - $this->boot->invalidateCache(); |
|
120 | + $this->boot->invalidateCache(); |
|
121 | 121 | |
122 | - return $result !== false; |
|
123 | - } |
|
122 | + return $result !== false; |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * Gets a configuration value |
|
127 | - * |
|
128 | - * Plugin authors should use elgg_get_config(). |
|
129 | - * |
|
130 | - * @note Internal: These settings are stored in the dbprefix_config table and read |
|
131 | - * during system boot into the config service. |
|
132 | - * |
|
133 | - * @param string $name The name of the config value |
|
134 | - * |
|
135 | - * @return mixed|null |
|
136 | - */ |
|
137 | - function get($name) { |
|
138 | - $sql = " |
|
125 | + /** |
|
126 | + * Gets a configuration value |
|
127 | + * |
|
128 | + * Plugin authors should use elgg_get_config(). |
|
129 | + * |
|
130 | + * @note Internal: These settings are stored in the dbprefix_config table and read |
|
131 | + * during system boot into the config service. |
|
132 | + * |
|
133 | + * @param string $name The name of the config value |
|
134 | + * |
|
135 | + * @return mixed|null |
|
136 | + */ |
|
137 | + function get($name) { |
|
138 | + $sql = " |
|
139 | 139 | SELECT value |
140 | 140 | FROM {$this->db->prefix}config |
141 | 141 | WHERE name = :name |
142 | 142 | "; |
143 | 143 | |
144 | - $params[':name'] = $name; |
|
144 | + $params[':name'] = $name; |
|
145 | 145 | |
146 | - $result = $this->db->getDataRow($sql, null, $params); |
|
147 | - if ($result) { |
|
148 | - return unserialize($result->value); |
|
149 | - } |
|
146 | + $result = $this->db->getDataRow($sql, null, $params); |
|
147 | + if ($result) { |
|
148 | + return unserialize($result->value); |
|
149 | + } |
|
150 | 150 | |
151 | - return null; |
|
152 | - } |
|
151 | + return null; |
|
152 | + } |
|
153 | 153 | |
154 | - /** |
|
155 | - * Load all config values from the config table (and datalists if not yet |
|
156 | - * upgraded to 3.0) |
|
157 | - * |
|
158 | - * @todo move into BootData once we no longer have to support the 2.x schema |
|
159 | - * |
|
160 | - * @return array |
|
161 | - */ |
|
162 | - public function getAll() { |
|
163 | - $values = []; |
|
154 | + /** |
|
155 | + * Load all config values from the config table (and datalists if not yet |
|
156 | + * upgraded to 3.0) |
|
157 | + * |
|
158 | + * @todo move into BootData once we no longer have to support the 2.x schema |
|
159 | + * |
|
160 | + * @return array |
|
161 | + */ |
|
162 | + public function getAll() { |
|
163 | + $values = []; |
|
164 | 164 | |
165 | - $sql = " |
|
165 | + $sql = " |
|
166 | 166 | SELECT * |
167 | 167 | FROM {$this->db->prefix}config |
168 | 168 | "; |
169 | - foreach ($this->db->getData($sql) as $row) { |
|
170 | - $values[$row->name] = unserialize($row->value); |
|
171 | - } |
|
169 | + foreach ($this->db->getData($sql) as $row) { |
|
170 | + $values[$row->name] = unserialize($row->value); |
|
171 | + } |
|
172 | 172 | |
173 | - if (!array_key_exists('installed', $values)) { |
|
174 | - // try to fetch from old pre 3.0 datalists table |
|
175 | - // need to do this to be able to perform an upgrade from 2.x to 3.0 |
|
176 | - try { |
|
177 | - $sql = " |
|
173 | + if (!array_key_exists('installed', $values)) { |
|
174 | + // try to fetch from old pre 3.0 datalists table |
|
175 | + // need to do this to be able to perform an upgrade from 2.x to 3.0 |
|
176 | + try { |
|
177 | + $sql = " |
|
178 | 178 | SELECT * |
179 | 179 | FROM {$this->db->prefix}datalists |
180 | 180 | "; |
181 | - foreach ($this->db->getData($sql) as $row) { |
|
182 | - $value = $row->value; |
|
183 | - if ($row->name == 'processed_upgrades') { |
|
184 | - // config table already serializes data so no need to double serialize |
|
185 | - $value = unserialize($value); |
|
186 | - } |
|
187 | - $values[$row->name] = $value; |
|
188 | - } |
|
189 | - } catch (\Exception $e) { |
|
190 | - } |
|
191 | - } |
|
181 | + foreach ($this->db->getData($sql) as $row) { |
|
182 | + $value = $row->value; |
|
183 | + if ($row->name == 'processed_upgrades') { |
|
184 | + // config table already serializes data so no need to double serialize |
|
185 | + $value = unserialize($value); |
|
186 | + } |
|
187 | + $values[$row->name] = $value; |
|
188 | + } |
|
189 | + } catch (\Exception $e) { |
|
190 | + } |
|
191 | + } |
|
192 | 192 | |
193 | - // don't pull in old config values |
|
194 | - /** |
|
195 | - * @see \Elgg\Config::__construct sets this |
|
196 | - */ |
|
197 | - unset($values['path']); |
|
198 | - unset($values['dataroot']); |
|
199 | - unset($values['default_site']); |
|
193 | + // don't pull in old config values |
|
194 | + /** |
|
195 | + * @see \Elgg\Config::__construct sets this |
|
196 | + */ |
|
197 | + unset($values['path']); |
|
198 | + unset($values['dataroot']); |
|
199 | + unset($values['default_site']); |
|
200 | 200 | |
201 | - return $values; |
|
202 | - } |
|
201 | + return $values; |
|
202 | + } |
|
203 | 203 | } |
@@ -2,7 +2,6 @@ |
||
2 | 2 | namespace Elgg\Database; |
3 | 3 | |
4 | 4 | use Elgg\Cache\Pool; |
5 | -use Elgg\Config; |
|
6 | 5 | use Elgg\Profilable; |
7 | 6 | use Exception; |
8 | 7 | use Elgg\Cache\PluginSettingsCache; |
@@ -17,712 +17,712 @@ discard block |
||
17 | 17 | * @since 1.10.0 |
18 | 18 | */ |
19 | 19 | class Plugins { |
20 | - use Profilable; |
|
20 | + use Profilable; |
|
21 | 21 | |
22 | - /** |
|
23 | - * @var \ElggPlugin[] |
|
24 | - */ |
|
25 | - private $boot_plugins = []; |
|
22 | + /** |
|
23 | + * @var \ElggPlugin[] |
|
24 | + */ |
|
25 | + private $boot_plugins = []; |
|
26 | 26 | |
27 | - /** |
|
28 | - * @var array|null |
|
29 | - */ |
|
30 | - private $provides_cache; |
|
27 | + /** |
|
28 | + * @var array|null |
|
29 | + */ |
|
30 | + private $provides_cache; |
|
31 | 31 | |
32 | - /** |
|
33 | - * @var string[] Active plugins, with plugin ID => GUID. Missing keys imply inactive plugins. |
|
34 | - */ |
|
35 | - private $active_guids = []; |
|
32 | + /** |
|
33 | + * @var string[] Active plugins, with plugin ID => GUID. Missing keys imply inactive plugins. |
|
34 | + */ |
|
35 | + private $active_guids = []; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @var bool Has $active_guids been populated? |
|
39 | - */ |
|
40 | - private $active_guids_known = false; |
|
37 | + /** |
|
38 | + * @var bool Has $active_guids been populated? |
|
39 | + */ |
|
40 | + private $active_guids_known = false; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @var Pool |
|
44 | - */ |
|
45 | - private $plugins_by_id; |
|
42 | + /** |
|
43 | + * @var Pool |
|
44 | + */ |
|
45 | + private $plugins_by_id; |
|
46 | 46 | |
47 | - /** |
|
48 | - * @var PluginSettingsCache |
|
49 | - */ |
|
50 | - private $settings_cache; |
|
47 | + /** |
|
48 | + * @var PluginSettingsCache |
|
49 | + */ |
|
50 | + private $settings_cache; |
|
51 | 51 | |
52 | - /** |
|
53 | - * Constructor |
|
54 | - * |
|
55 | - * @param Pool $pool Cache for referencing plugins by ID |
|
56 | - * @param PluginSettingsCache $cache Plugin settings cache |
|
57 | - */ |
|
58 | - public function __construct(Pool $pool, PluginSettingsCache $cache) { |
|
59 | - $this->plugins_by_id = $pool; |
|
60 | - $this->settings_cache = $cache; |
|
61 | - } |
|
52 | + /** |
|
53 | + * Constructor |
|
54 | + * |
|
55 | + * @param Pool $pool Cache for referencing plugins by ID |
|
56 | + * @param PluginSettingsCache $cache Plugin settings cache |
|
57 | + */ |
|
58 | + public function __construct(Pool $pool, PluginSettingsCache $cache) { |
|
59 | + $this->plugins_by_id = $pool; |
|
60 | + $this->settings_cache = $cache; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Set the list of active plugins according to the boot data cache |
|
65 | - * |
|
66 | - * @param \ElggPlugin[] $plugins Set of active plugins |
|
67 | - * @return void |
|
68 | - */ |
|
69 | - public function setBootPlugins(array $plugins) { |
|
70 | - $this->boot_plugins = $plugins; |
|
71 | - foreach ($plugins as $plugin) { |
|
72 | - $this->plugins_by_id->put($plugin->getID(), $plugin); |
|
73 | - } |
|
74 | - } |
|
63 | + /** |
|
64 | + * Set the list of active plugins according to the boot data cache |
|
65 | + * |
|
66 | + * @param \ElggPlugin[] $plugins Set of active plugins |
|
67 | + * @return void |
|
68 | + */ |
|
69 | + public function setBootPlugins(array $plugins) { |
|
70 | + $this->boot_plugins = $plugins; |
|
71 | + foreach ($plugins as $plugin) { |
|
72 | + $this->plugins_by_id->put($plugin->getID(), $plugin); |
|
73 | + } |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Returns a list of plugin directory names from a base directory. |
|
78 | - * |
|
79 | - * @param string $dir A dir to scan for plugins. Defaults to config's plugins_path. |
|
80 | - * Must have a trailing slash. |
|
81 | - * |
|
82 | - * @return array Array of directory names (not full paths) |
|
83 | - * @access private |
|
84 | - */ |
|
85 | - function getDirsInDir($dir = null) { |
|
86 | - if (!$dir) { |
|
87 | - $dir = elgg_get_plugins_path(); |
|
88 | - } |
|
89 | - |
|
90 | - $plugin_dirs = []; |
|
91 | - $handle = opendir($dir); |
|
92 | - |
|
93 | - if ($handle) { |
|
94 | - while ($plugin_dir = readdir($handle)) { |
|
95 | - // must be directory and not begin with a . |
|
96 | - if (substr($plugin_dir, 0, 1) !== '.' && is_dir($dir . $plugin_dir)) { |
|
97 | - $plugin_dirs[] = $plugin_dir; |
|
98 | - } |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - sort($plugin_dirs); |
|
103 | - |
|
104 | - return $plugin_dirs; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Discovers plugins in the plugins_path setting and creates \ElggPlugin |
|
109 | - * entities for them if they don't exist. If there are plugins with entities |
|
110 | - * but not actual files, will disable the \ElggPlugin entities and mark as inactive. |
|
111 | - * The \ElggPlugin object holds config data, so don't delete. |
|
112 | - * |
|
113 | - * @return bool |
|
114 | - * @access private |
|
115 | - */ |
|
116 | - function generateEntities() { |
|
117 | - |
|
118 | - $mod_dir = elgg_get_plugins_path(); |
|
119 | - $db_prefix = _elgg_config()->dbprefix; |
|
120 | - |
|
121 | - // ignore access in case this is called with no admin logged in - needed for creating plugins perhaps? |
|
122 | - $old_ia = elgg_set_ignore_access(true); |
|
123 | - |
|
124 | - // show hidden entities so that we can enable them if appropriate |
|
125 | - $old_access = access_show_hidden_entities(true); |
|
126 | - |
|
127 | - $known_plugins = elgg_get_entities_from_relationship([ |
|
128 | - 'type' => 'object', |
|
129 | - 'subtype' => 'plugin', |
|
130 | - 'selects' => ['plugin_oe.*'], |
|
131 | - 'joins' => ["JOIN {$db_prefix}objects_entity plugin_oe on plugin_oe.guid = e.guid"], |
|
132 | - 'limit' => ELGG_ENTITIES_NO_VALUE, |
|
133 | - ]); |
|
134 | - /* @var \ElggPlugin[] $known_plugins */ |
|
135 | - |
|
136 | - if (!$known_plugins) { |
|
137 | - $known_plugins = []; |
|
138 | - } |
|
139 | - |
|
140 | - // map paths to indexes |
|
141 | - $id_map = []; |
|
142 | - foreach ($known_plugins as $i => $plugin) { |
|
143 | - // if the ID is wrong, delete the plugin because we can never load it. |
|
144 | - $id = $plugin->getID(); |
|
145 | - if (!$id) { |
|
146 | - $plugin->delete(); |
|
147 | - unset($known_plugins[$i]); |
|
148 | - continue; |
|
149 | - } |
|
150 | - $id_map[$plugin->getID()] = $i; |
|
151 | - } |
|
152 | - |
|
153 | - $physical_plugins = $this->getDirsInDir($mod_dir); |
|
154 | - if (!$physical_plugins) { |
|
155 | - return false; |
|
156 | - } |
|
157 | - |
|
158 | - // check real plugins against known ones |
|
159 | - foreach ($physical_plugins as $plugin_id) { |
|
160 | - // is this already in the db? |
|
161 | - if (array_key_exists($plugin_id, $id_map)) { |
|
162 | - $index = $id_map[$plugin_id]; |
|
163 | - $plugin = $known_plugins[$index]; |
|
164 | - // was this plugin deleted and its entity disabled? |
|
165 | - if (!$plugin->isEnabled()) { |
|
166 | - $plugin->enable(); |
|
167 | - $plugin->deactivate(); |
|
168 | - $plugin->setPriority('last'); |
|
169 | - } |
|
170 | - |
|
171 | - // remove from the list of plugins to disable |
|
172 | - unset($known_plugins[$index]); |
|
173 | - } else { |
|
174 | - // create new plugin |
|
175 | - // priority is forced to last in save() if not set. |
|
176 | - $plugin = new \ElggPlugin($mod_dir . $plugin_id); |
|
177 | - $plugin->save(); |
|
178 | - } |
|
179 | - } |
|
180 | - |
|
181 | - // everything remaining in $known_plugins needs to be disabled |
|
182 | - // because they are entities, but their dirs were removed. |
|
183 | - // don't delete the entities because they hold settings. |
|
184 | - foreach ($known_plugins as $plugin) { |
|
185 | - if ($plugin->isActive()) { |
|
186 | - $plugin->deactivate(); |
|
187 | - } |
|
188 | - // remove the priority. |
|
189 | - $name = $this->namespacePrivateSetting('internal', 'priority'); |
|
190 | - remove_private_setting($plugin->guid, $name); |
|
191 | - if ($plugin->isEnabled()) { |
|
192 | - $plugin->disable(); |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - access_show_hidden_entities($old_access); |
|
197 | - elgg_set_ignore_access($old_ia); |
|
198 | - |
|
199 | - return true; |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Cache a reference to this plugin by its ID |
|
204 | - * |
|
205 | - * @param \ElggPlugin $plugin |
|
206 | - * |
|
207 | - * @access private |
|
208 | - */ |
|
209 | - function cache(\ElggPlugin $plugin) { |
|
210 | - $this->plugins_by_id->put($plugin->getID(), $plugin); |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * Returns an \ElggPlugin object with the path $path. |
|
215 | - * |
|
216 | - * @param string $plugin_id The id (dir name) of the plugin. NOT the guid. |
|
217 | - * @return \ElggPlugin|null |
|
218 | - */ |
|
219 | - function get($plugin_id) { |
|
220 | - return $this->plugins_by_id->get($plugin_id, function () use ($plugin_id) { |
|
221 | - $plugin_id = sanitize_string($plugin_id); |
|
222 | - $db_prefix = _elgg_config()->dbprefix; |
|
76 | + /** |
|
77 | + * Returns a list of plugin directory names from a base directory. |
|
78 | + * |
|
79 | + * @param string $dir A dir to scan for plugins. Defaults to config's plugins_path. |
|
80 | + * Must have a trailing slash. |
|
81 | + * |
|
82 | + * @return array Array of directory names (not full paths) |
|
83 | + * @access private |
|
84 | + */ |
|
85 | + function getDirsInDir($dir = null) { |
|
86 | + if (!$dir) { |
|
87 | + $dir = elgg_get_plugins_path(); |
|
88 | + } |
|
89 | + |
|
90 | + $plugin_dirs = []; |
|
91 | + $handle = opendir($dir); |
|
92 | + |
|
93 | + if ($handle) { |
|
94 | + while ($plugin_dir = readdir($handle)) { |
|
95 | + // must be directory and not begin with a . |
|
96 | + if (substr($plugin_dir, 0, 1) !== '.' && is_dir($dir . $plugin_dir)) { |
|
97 | + $plugin_dirs[] = $plugin_dir; |
|
98 | + } |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + sort($plugin_dirs); |
|
103 | + |
|
104 | + return $plugin_dirs; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Discovers plugins in the plugins_path setting and creates \ElggPlugin |
|
109 | + * entities for them if they don't exist. If there are plugins with entities |
|
110 | + * but not actual files, will disable the \ElggPlugin entities and mark as inactive. |
|
111 | + * The \ElggPlugin object holds config data, so don't delete. |
|
112 | + * |
|
113 | + * @return bool |
|
114 | + * @access private |
|
115 | + */ |
|
116 | + function generateEntities() { |
|
117 | + |
|
118 | + $mod_dir = elgg_get_plugins_path(); |
|
119 | + $db_prefix = _elgg_config()->dbprefix; |
|
120 | + |
|
121 | + // ignore access in case this is called with no admin logged in - needed for creating plugins perhaps? |
|
122 | + $old_ia = elgg_set_ignore_access(true); |
|
123 | + |
|
124 | + // show hidden entities so that we can enable them if appropriate |
|
125 | + $old_access = access_show_hidden_entities(true); |
|
126 | + |
|
127 | + $known_plugins = elgg_get_entities_from_relationship([ |
|
128 | + 'type' => 'object', |
|
129 | + 'subtype' => 'plugin', |
|
130 | + 'selects' => ['plugin_oe.*'], |
|
131 | + 'joins' => ["JOIN {$db_prefix}objects_entity plugin_oe on plugin_oe.guid = e.guid"], |
|
132 | + 'limit' => ELGG_ENTITIES_NO_VALUE, |
|
133 | + ]); |
|
134 | + /* @var \ElggPlugin[] $known_plugins */ |
|
135 | + |
|
136 | + if (!$known_plugins) { |
|
137 | + $known_plugins = []; |
|
138 | + } |
|
139 | + |
|
140 | + // map paths to indexes |
|
141 | + $id_map = []; |
|
142 | + foreach ($known_plugins as $i => $plugin) { |
|
143 | + // if the ID is wrong, delete the plugin because we can never load it. |
|
144 | + $id = $plugin->getID(); |
|
145 | + if (!$id) { |
|
146 | + $plugin->delete(); |
|
147 | + unset($known_plugins[$i]); |
|
148 | + continue; |
|
149 | + } |
|
150 | + $id_map[$plugin->getID()] = $i; |
|
151 | + } |
|
152 | + |
|
153 | + $physical_plugins = $this->getDirsInDir($mod_dir); |
|
154 | + if (!$physical_plugins) { |
|
155 | + return false; |
|
156 | + } |
|
157 | + |
|
158 | + // check real plugins against known ones |
|
159 | + foreach ($physical_plugins as $plugin_id) { |
|
160 | + // is this already in the db? |
|
161 | + if (array_key_exists($plugin_id, $id_map)) { |
|
162 | + $index = $id_map[$plugin_id]; |
|
163 | + $plugin = $known_plugins[$index]; |
|
164 | + // was this plugin deleted and its entity disabled? |
|
165 | + if (!$plugin->isEnabled()) { |
|
166 | + $plugin->enable(); |
|
167 | + $plugin->deactivate(); |
|
168 | + $plugin->setPriority('last'); |
|
169 | + } |
|
170 | + |
|
171 | + // remove from the list of plugins to disable |
|
172 | + unset($known_plugins[$index]); |
|
173 | + } else { |
|
174 | + // create new plugin |
|
175 | + // priority is forced to last in save() if not set. |
|
176 | + $plugin = new \ElggPlugin($mod_dir . $plugin_id); |
|
177 | + $plugin->save(); |
|
178 | + } |
|
179 | + } |
|
180 | + |
|
181 | + // everything remaining in $known_plugins needs to be disabled |
|
182 | + // because they are entities, but their dirs were removed. |
|
183 | + // don't delete the entities because they hold settings. |
|
184 | + foreach ($known_plugins as $plugin) { |
|
185 | + if ($plugin->isActive()) { |
|
186 | + $plugin->deactivate(); |
|
187 | + } |
|
188 | + // remove the priority. |
|
189 | + $name = $this->namespacePrivateSetting('internal', 'priority'); |
|
190 | + remove_private_setting($plugin->guid, $name); |
|
191 | + if ($plugin->isEnabled()) { |
|
192 | + $plugin->disable(); |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + access_show_hidden_entities($old_access); |
|
197 | + elgg_set_ignore_access($old_ia); |
|
198 | + |
|
199 | + return true; |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Cache a reference to this plugin by its ID |
|
204 | + * |
|
205 | + * @param \ElggPlugin $plugin |
|
206 | + * |
|
207 | + * @access private |
|
208 | + */ |
|
209 | + function cache(\ElggPlugin $plugin) { |
|
210 | + $this->plugins_by_id->put($plugin->getID(), $plugin); |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * Returns an \ElggPlugin object with the path $path. |
|
215 | + * |
|
216 | + * @param string $plugin_id The id (dir name) of the plugin. NOT the guid. |
|
217 | + * @return \ElggPlugin|null |
|
218 | + */ |
|
219 | + function get($plugin_id) { |
|
220 | + return $this->plugins_by_id->get($plugin_id, function () use ($plugin_id) { |
|
221 | + $plugin_id = sanitize_string($plugin_id); |
|
222 | + $db_prefix = _elgg_config()->dbprefix; |
|
223 | 223 | |
224 | - $options = [ |
|
225 | - 'type' => 'object', |
|
226 | - 'subtype' => 'plugin', |
|
227 | - 'joins' => ["JOIN {$db_prefix}objects_entity oe on oe.guid = e.guid"], |
|
228 | - 'selects' => ["oe.title", "oe.description"], |
|
229 | - 'wheres' => ["oe.title = '$plugin_id'"], |
|
230 | - 'limit' => 1, |
|
231 | - 'distinct' => false, |
|
232 | - ]; |
|
224 | + $options = [ |
|
225 | + 'type' => 'object', |
|
226 | + 'subtype' => 'plugin', |
|
227 | + 'joins' => ["JOIN {$db_prefix}objects_entity oe on oe.guid = e.guid"], |
|
228 | + 'selects' => ["oe.title", "oe.description"], |
|
229 | + 'wheres' => ["oe.title = '$plugin_id'"], |
|
230 | + 'limit' => 1, |
|
231 | + 'distinct' => false, |
|
232 | + ]; |
|
233 | 233 | |
234 | - $plugins = elgg_get_entities($options); |
|
234 | + $plugins = elgg_get_entities($options); |
|
235 | 235 | |
236 | - if ($plugins) { |
|
237 | - return $plugins[0]; |
|
238 | - } |
|
236 | + if ($plugins) { |
|
237 | + return $plugins[0]; |
|
238 | + } |
|
239 | 239 | |
240 | - return null; |
|
241 | - }); |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * Returns if a plugin exists in the system. |
|
246 | - * |
|
247 | - * @warning This checks only plugins that are registered in the system! |
|
248 | - * If the plugin cache is outdated, be sure to regenerate it with |
|
249 | - * {@link _elgg_generate_plugin_objects()} first. |
|
250 | - * |
|
251 | - * @param string $id The plugin ID. |
|
252 | - * @return bool |
|
253 | - */ |
|
254 | - function exists($id) { |
|
255 | - return (bool) $this->get($id); |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Returns the highest priority of the plugins |
|
260 | - * |
|
261 | - * @return int |
|
262 | - * @access private |
|
263 | - */ |
|
264 | - function getMaxPriority() { |
|
265 | - $db_prefix = _elgg_config()->dbprefix; |
|
266 | - $priority = $this->namespacePrivateSetting('internal', 'priority'); |
|
267 | - $plugin_subtype = get_subtype_id('object', 'plugin'); |
|
268 | - |
|
269 | - $q = "SELECT MAX(CAST(ps.value AS unsigned)) as max |
|
240 | + return null; |
|
241 | + }); |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * Returns if a plugin exists in the system. |
|
246 | + * |
|
247 | + * @warning This checks only plugins that are registered in the system! |
|
248 | + * If the plugin cache is outdated, be sure to regenerate it with |
|
249 | + * {@link _elgg_generate_plugin_objects()} first. |
|
250 | + * |
|
251 | + * @param string $id The plugin ID. |
|
252 | + * @return bool |
|
253 | + */ |
|
254 | + function exists($id) { |
|
255 | + return (bool) $this->get($id); |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Returns the highest priority of the plugins |
|
260 | + * |
|
261 | + * @return int |
|
262 | + * @access private |
|
263 | + */ |
|
264 | + function getMaxPriority() { |
|
265 | + $db_prefix = _elgg_config()->dbprefix; |
|
266 | + $priority = $this->namespacePrivateSetting('internal', 'priority'); |
|
267 | + $plugin_subtype = get_subtype_id('object', 'plugin'); |
|
268 | + |
|
269 | + $q = "SELECT MAX(CAST(ps.value AS unsigned)) as max |
|
270 | 270 | FROM {$db_prefix}entities e, {$db_prefix}private_settings ps |
271 | 271 | WHERE ps.name = '$priority' |
272 | 272 | AND ps.entity_guid = e.guid |
273 | 273 | AND e.type = 'object' and e.subtype = $plugin_subtype"; |
274 | 274 | |
275 | - $data = get_data($q); |
|
276 | - if ($data) { |
|
277 | - $max = $data[0]->max; |
|
278 | - } else { |
|
279 | - $max = 1; |
|
280 | - } |
|
281 | - |
|
282 | - // can't have a priority of 0. |
|
283 | - return ($max) ? $max : 1; |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * Returns if a plugin is active for a current site. |
|
288 | - * |
|
289 | - * @param string $plugin_id The plugin ID |
|
290 | - * @return bool |
|
291 | - */ |
|
292 | - function isActive($plugin_id) { |
|
293 | - if ($this->active_guids_known) { |
|
294 | - return isset($this->active_guids[$plugin_id]); |
|
295 | - } |
|
275 | + $data = get_data($q); |
|
276 | + if ($data) { |
|
277 | + $max = $data[0]->max; |
|
278 | + } else { |
|
279 | + $max = 1; |
|
280 | + } |
|
281 | + |
|
282 | + // can't have a priority of 0. |
|
283 | + return ($max) ? $max : 1; |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * Returns if a plugin is active for a current site. |
|
288 | + * |
|
289 | + * @param string $plugin_id The plugin ID |
|
290 | + * @return bool |
|
291 | + */ |
|
292 | + function isActive($plugin_id) { |
|
293 | + if ($this->active_guids_known) { |
|
294 | + return isset($this->active_guids[$plugin_id]); |
|
295 | + } |
|
296 | 296 | |
297 | - $site = elgg_get_site_entity(); |
|
298 | - |
|
299 | - if (!($site instanceof \ElggSite)) { |
|
300 | - return false; |
|
301 | - } |
|
302 | - |
|
303 | - $plugin = $this->get($plugin_id); |
|
304 | - |
|
305 | - if (!$plugin) { |
|
306 | - return false; |
|
307 | - } |
|
308 | - |
|
309 | - return $plugin->isActive($site->guid); |
|
310 | - } |
|
311 | - |
|
312 | - /** |
|
313 | - * Loads all active plugins in the order specified in the tool admin panel. |
|
314 | - * |
|
315 | - * @note This is called on every page load. If a plugin is active and problematic, it |
|
316 | - * will be disabled and a visible error emitted. This does not check the deps system because |
|
317 | - * that was too slow. |
|
318 | - * |
|
319 | - * @return bool |
|
320 | - * @access private |
|
321 | - */ |
|
322 | - function load() { |
|
323 | - if ($this->timer) { |
|
324 | - $this->timer->begin([__METHOD__]); |
|
325 | - } |
|
297 | + $site = elgg_get_site_entity(); |
|
298 | + |
|
299 | + if (!($site instanceof \ElggSite)) { |
|
300 | + return false; |
|
301 | + } |
|
302 | + |
|
303 | + $plugin = $this->get($plugin_id); |
|
304 | + |
|
305 | + if (!$plugin) { |
|
306 | + return false; |
|
307 | + } |
|
308 | + |
|
309 | + return $plugin->isActive($site->guid); |
|
310 | + } |
|
311 | + |
|
312 | + /** |
|
313 | + * Loads all active plugins in the order specified in the tool admin panel. |
|
314 | + * |
|
315 | + * @note This is called on every page load. If a plugin is active and problematic, it |
|
316 | + * will be disabled and a visible error emitted. This does not check the deps system because |
|
317 | + * that was too slow. |
|
318 | + * |
|
319 | + * @return bool |
|
320 | + * @access private |
|
321 | + */ |
|
322 | + function load() { |
|
323 | + if ($this->timer) { |
|
324 | + $this->timer->begin([__METHOD__]); |
|
325 | + } |
|
326 | 326 | |
327 | - $plugins_path = elgg_get_plugins_path(); |
|
328 | - $start_flags = ELGG_PLUGIN_INCLUDE_START | |
|
329 | - ELGG_PLUGIN_REGISTER_VIEWS | |
|
330 | - ELGG_PLUGIN_REGISTER_ACTIONS | |
|
331 | - ELGG_PLUGIN_REGISTER_LANGUAGES | |
|
332 | - ELGG_PLUGIN_REGISTER_WIDGETS | |
|
333 | - ELGG_PLUGIN_REGISTER_CLASSES; |
|
334 | - |
|
335 | - if (!$plugins_path) { |
|
336 | - return false; |
|
337 | - } |
|
338 | - |
|
339 | - // temporary disable all plugins if there is a file called 'disabled' in the plugin dir |
|
340 | - if (file_exists("$plugins_path/disabled")) { |
|
341 | - if (elgg_is_admin_logged_in() && elgg_in_context('admin')) { |
|
342 | - system_message(_elgg_services()->translator->translate('plugins:disabled')); |
|
343 | - } |
|
344 | - return false; |
|
345 | - } |
|
327 | + $plugins_path = elgg_get_plugins_path(); |
|
328 | + $start_flags = ELGG_PLUGIN_INCLUDE_START | |
|
329 | + ELGG_PLUGIN_REGISTER_VIEWS | |
|
330 | + ELGG_PLUGIN_REGISTER_ACTIONS | |
|
331 | + ELGG_PLUGIN_REGISTER_LANGUAGES | |
|
332 | + ELGG_PLUGIN_REGISTER_WIDGETS | |
|
333 | + ELGG_PLUGIN_REGISTER_CLASSES; |
|
334 | + |
|
335 | + if (!$plugins_path) { |
|
336 | + return false; |
|
337 | + } |
|
338 | + |
|
339 | + // temporary disable all plugins if there is a file called 'disabled' in the plugin dir |
|
340 | + if (file_exists("$plugins_path/disabled")) { |
|
341 | + if (elgg_is_admin_logged_in() && elgg_in_context('admin')) { |
|
342 | + system_message(_elgg_services()->translator->translate('plugins:disabled')); |
|
343 | + } |
|
344 | + return false; |
|
345 | + } |
|
346 | 346 | |
347 | - $config = _elgg_config(); |
|
347 | + $config = _elgg_config(); |
|
348 | 348 | |
349 | - if ($config->system_cache_loaded) { |
|
350 | - $start_flags = $start_flags & ~ELGG_PLUGIN_REGISTER_VIEWS; |
|
351 | - } |
|
349 | + if ($config->system_cache_loaded) { |
|
350 | + $start_flags = $start_flags & ~ELGG_PLUGIN_REGISTER_VIEWS; |
|
351 | + } |
|
352 | 352 | |
353 | - if (_elgg_services()->translator->wasLoadedFromCache()) { |
|
354 | - $start_flags = $start_flags & ~ELGG_PLUGIN_REGISTER_LANGUAGES; |
|
355 | - } |
|
353 | + if (_elgg_services()->translator->wasLoadedFromCache()) { |
|
354 | + $start_flags = $start_flags & ~ELGG_PLUGIN_REGISTER_LANGUAGES; |
|
355 | + } |
|
356 | 356 | |
357 | - $plugins = $this->boot_plugins; |
|
358 | - if (!$plugins) { |
|
359 | - $this->active_guids_known = true; |
|
360 | - return true; |
|
361 | - } |
|
357 | + $plugins = $this->boot_plugins; |
|
358 | + if (!$plugins) { |
|
359 | + $this->active_guids_known = true; |
|
360 | + return true; |
|
361 | + } |
|
362 | 362 | |
363 | - $return = true; |
|
364 | - foreach ($plugins as $plugin) { |
|
365 | - $id = $plugin->getID(); |
|
366 | - try { |
|
367 | - $plugin->start($start_flags); |
|
368 | - $this->active_guids[$id] = $plugin->guid; |
|
369 | - } catch (Exception $e) { |
|
370 | - $disable_plugins = _elgg_config()->auto_disable_plugins; |
|
371 | - if ($disable_plugins === null) { |
|
372 | - $disable_plugins = true; |
|
373 | - } |
|
374 | - if ($disable_plugins) { |
|
375 | - $plugin->deactivate(); |
|
363 | + $return = true; |
|
364 | + foreach ($plugins as $plugin) { |
|
365 | + $id = $plugin->getID(); |
|
366 | + try { |
|
367 | + $plugin->start($start_flags); |
|
368 | + $this->active_guids[$id] = $plugin->guid; |
|
369 | + } catch (Exception $e) { |
|
370 | + $disable_plugins = _elgg_config()->auto_disable_plugins; |
|
371 | + if ($disable_plugins === null) { |
|
372 | + $disable_plugins = true; |
|
373 | + } |
|
374 | + if ($disable_plugins) { |
|
375 | + $plugin->deactivate(); |
|
376 | 376 | |
377 | - $msg = _elgg_services()->translator->translate('PluginException:CannotStart', |
|
378 | - [$id, $plugin->guid, $e->getMessage()]); |
|
379 | - elgg_add_admin_notice("cannot_start $id", $msg); |
|
380 | - $return = false; |
|
381 | - } |
|
382 | - } |
|
383 | - } |
|
377 | + $msg = _elgg_services()->translator->translate('PluginException:CannotStart', |
|
378 | + [$id, $plugin->guid, $e->getMessage()]); |
|
379 | + elgg_add_admin_notice("cannot_start $id", $msg); |
|
380 | + $return = false; |
|
381 | + } |
|
382 | + } |
|
383 | + } |
|
384 | 384 | |
385 | - $this->active_guids_known = true; |
|
385 | + $this->active_guids_known = true; |
|
386 | 386 | |
387 | - if ($this->timer) { |
|
388 | - $this->timer->end([__METHOD__]); |
|
389 | - } |
|
390 | - return $return; |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * Returns an ordered list of plugins |
|
395 | - * |
|
396 | - * @param string $status The status of the plugins. active, inactive, or all. |
|
397 | - * @return \ElggPlugin[] |
|
398 | - */ |
|
399 | - function find($status = 'active') { |
|
400 | - if (!_elgg_services()->db) { |
|
401 | - return []; |
|
402 | - } |
|
387 | + if ($this->timer) { |
|
388 | + $this->timer->end([__METHOD__]); |
|
389 | + } |
|
390 | + return $return; |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * Returns an ordered list of plugins |
|
395 | + * |
|
396 | + * @param string $status The status of the plugins. active, inactive, or all. |
|
397 | + * @return \ElggPlugin[] |
|
398 | + */ |
|
399 | + function find($status = 'active') { |
|
400 | + if (!_elgg_services()->db) { |
|
401 | + return []; |
|
402 | + } |
|
403 | 403 | |
404 | - $db_prefix = _elgg_config()->dbprefix; |
|
405 | - $priority = $this->namespacePrivateSetting('internal', 'priority'); |
|
406 | - $site_guid = 1; |
|
404 | + $db_prefix = _elgg_config()->dbprefix; |
|
405 | + $priority = $this->namespacePrivateSetting('internal', 'priority'); |
|
406 | + $site_guid = 1; |
|
407 | 407 | |
408 | - // grab plugins |
|
409 | - $options = [ |
|
410 | - 'type' => 'object', |
|
411 | - 'subtype' => 'plugin', |
|
412 | - 'limit' => ELGG_ENTITIES_NO_VALUE, |
|
413 | - 'selects' => ['plugin_oe.*', 'ps.value'], |
|
414 | - 'joins' => [ |
|
415 | - "JOIN {$db_prefix}private_settings ps on ps.entity_guid = e.guid", |
|
416 | - "JOIN {$db_prefix}objects_entity plugin_oe on plugin_oe.guid = e.guid" |
|
417 | - ], |
|
418 | - 'wheres' => ["ps.name = '$priority'"], |
|
419 | - // ORDER BY CAST(ps.value) is super slow. We usort() below. |
|
420 | - 'order_by' => false, |
|
421 | - 'distinct' => false, |
|
422 | - ]; |
|
423 | - |
|
424 | - switch ($status) { |
|
425 | - case 'active': |
|
426 | - $options['relationship'] = 'active_plugin'; |
|
427 | - $options['relationship_guid'] = $site_guid; |
|
428 | - $options['inverse_relationship'] = true; |
|
429 | - break; |
|
430 | - |
|
431 | - case 'inactive': |
|
432 | - $options['wheres'][] = "NOT EXISTS ( |
|
408 | + // grab plugins |
|
409 | + $options = [ |
|
410 | + 'type' => 'object', |
|
411 | + 'subtype' => 'plugin', |
|
412 | + 'limit' => ELGG_ENTITIES_NO_VALUE, |
|
413 | + 'selects' => ['plugin_oe.*', 'ps.value'], |
|
414 | + 'joins' => [ |
|
415 | + "JOIN {$db_prefix}private_settings ps on ps.entity_guid = e.guid", |
|
416 | + "JOIN {$db_prefix}objects_entity plugin_oe on plugin_oe.guid = e.guid" |
|
417 | + ], |
|
418 | + 'wheres' => ["ps.name = '$priority'"], |
|
419 | + // ORDER BY CAST(ps.value) is super slow. We usort() below. |
|
420 | + 'order_by' => false, |
|
421 | + 'distinct' => false, |
|
422 | + ]; |
|
423 | + |
|
424 | + switch ($status) { |
|
425 | + case 'active': |
|
426 | + $options['relationship'] = 'active_plugin'; |
|
427 | + $options['relationship_guid'] = $site_guid; |
|
428 | + $options['inverse_relationship'] = true; |
|
429 | + break; |
|
430 | + |
|
431 | + case 'inactive': |
|
432 | + $options['wheres'][] = "NOT EXISTS ( |
|
433 | 433 | SELECT 1 FROM {$db_prefix}entity_relationships active_er |
434 | 434 | WHERE active_er.guid_one = e.guid |
435 | 435 | AND active_er.relationship = 'active_plugin' |
436 | 436 | AND active_er.guid_two = $site_guid)"; |
437 | - break; |
|
437 | + break; |
|
438 | 438 | |
439 | - case 'all': |
|
440 | - default: |
|
441 | - break; |
|
442 | - } |
|
439 | + case 'all': |
|
440 | + default: |
|
441 | + break; |
|
442 | + } |
|
443 | 443 | |
444 | - $old_ia = elgg_set_ignore_access(true); |
|
445 | - $plugins = elgg_get_entities_from_relationship($options); |
|
446 | - elgg_set_ignore_access($old_ia); |
|
444 | + $old_ia = elgg_set_ignore_access(true); |
|
445 | + $plugins = elgg_get_entities_from_relationship($options); |
|
446 | + elgg_set_ignore_access($old_ia); |
|
447 | 447 | |
448 | - usort($plugins, function (\ElggPlugin $a, \ElggPlugin $b) { |
|
449 | - $a_value = $a->getVolatileData('select:value'); |
|
450 | - $b_value = $b->getVolatileData('select:value'); |
|
448 | + usort($plugins, function (\ElggPlugin $a, \ElggPlugin $b) { |
|
449 | + $a_value = $a->getVolatileData('select:value'); |
|
450 | + $b_value = $b->getVolatileData('select:value'); |
|
451 | 451 | |
452 | - if ($b_value !== $a_value) { |
|
453 | - return $a_value - $b_value; |
|
454 | - } else { |
|
455 | - return $a->guid - $b->guid; |
|
456 | - } |
|
457 | - }); |
|
458 | - |
|
459 | - return $plugins; |
|
460 | - } |
|
461 | - |
|
462 | - /** |
|
463 | - * Reorder plugins to an order specified by the array. |
|
464 | - * Plugins not included in this array will be appended to the end. |
|
465 | - * |
|
466 | - * @note This doesn't use the \ElggPlugin->setPriority() method because |
|
467 | - * all plugins are being changed and we don't want it to automatically |
|
468 | - * reorder plugins. |
|
469 | - * @todo Can this be done in a single sql command? |
|
470 | - * |
|
471 | - * @param array $order An array of plugin ids in the order to set them |
|
472 | - * @return bool |
|
473 | - * @access private |
|
474 | - */ |
|
475 | - function setPriorities(array $order) { |
|
476 | - $name = $this->namespacePrivateSetting('internal', 'priority'); |
|
477 | - |
|
478 | - $plugins = $this->find('any'); |
|
479 | - if (!$plugins) { |
|
480 | - return false; |
|
481 | - } |
|
482 | - |
|
483 | - // reindex to get standard counting. no need to increment by 10. |
|
484 | - // though we do start with 1 |
|
485 | - $order = array_values($order); |
|
486 | - |
|
487 | - $missing_plugins = []; |
|
488 | - /* @var \ElggPlugin[] $missing_plugins */ |
|
489 | - |
|
490 | - $priority = 0; |
|
491 | - foreach ($plugins as $plugin) { |
|
492 | - $plugin_id = $plugin->getID(); |
|
493 | - |
|
494 | - if (!in_array($plugin_id, $order)) { |
|
495 | - $missing_plugins[] = $plugin; |
|
496 | - continue; |
|
497 | - } |
|
498 | - |
|
499 | - $priority = array_search($plugin_id, $order) + 1; |
|
500 | - |
|
501 | - if (!$plugin->setPrivateSetting($name, $priority)) { |
|
502 | - return false; |
|
503 | - } |
|
504 | - } |
|
505 | - |
|
506 | - // set the missing plugins' priorities |
|
507 | - if (empty($missing_plugins)) { |
|
508 | - return true; |
|
509 | - } |
|
452 | + if ($b_value !== $a_value) { |
|
453 | + return $a_value - $b_value; |
|
454 | + } else { |
|
455 | + return $a->guid - $b->guid; |
|
456 | + } |
|
457 | + }); |
|
458 | + |
|
459 | + return $plugins; |
|
460 | + } |
|
461 | + |
|
462 | + /** |
|
463 | + * Reorder plugins to an order specified by the array. |
|
464 | + * Plugins not included in this array will be appended to the end. |
|
465 | + * |
|
466 | + * @note This doesn't use the \ElggPlugin->setPriority() method because |
|
467 | + * all plugins are being changed and we don't want it to automatically |
|
468 | + * reorder plugins. |
|
469 | + * @todo Can this be done in a single sql command? |
|
470 | + * |
|
471 | + * @param array $order An array of plugin ids in the order to set them |
|
472 | + * @return bool |
|
473 | + * @access private |
|
474 | + */ |
|
475 | + function setPriorities(array $order) { |
|
476 | + $name = $this->namespacePrivateSetting('internal', 'priority'); |
|
477 | + |
|
478 | + $plugins = $this->find('any'); |
|
479 | + if (!$plugins) { |
|
480 | + return false; |
|
481 | + } |
|
482 | + |
|
483 | + // reindex to get standard counting. no need to increment by 10. |
|
484 | + // though we do start with 1 |
|
485 | + $order = array_values($order); |
|
486 | + |
|
487 | + $missing_plugins = []; |
|
488 | + /* @var \ElggPlugin[] $missing_plugins */ |
|
489 | + |
|
490 | + $priority = 0; |
|
491 | + foreach ($plugins as $plugin) { |
|
492 | + $plugin_id = $plugin->getID(); |
|
493 | + |
|
494 | + if (!in_array($plugin_id, $order)) { |
|
495 | + $missing_plugins[] = $plugin; |
|
496 | + continue; |
|
497 | + } |
|
498 | + |
|
499 | + $priority = array_search($plugin_id, $order) + 1; |
|
500 | + |
|
501 | + if (!$plugin->setPrivateSetting($name, $priority)) { |
|
502 | + return false; |
|
503 | + } |
|
504 | + } |
|
505 | + |
|
506 | + // set the missing plugins' priorities |
|
507 | + if (empty($missing_plugins)) { |
|
508 | + return true; |
|
509 | + } |
|
510 | 510 | |
511 | - foreach ($missing_plugins as $plugin) { |
|
512 | - $priority++; |
|
513 | - if (!$plugin->setPrivateSetting($name, $priority)) { |
|
514 | - return false; |
|
515 | - } |
|
516 | - } |
|
517 | - |
|
518 | - return true; |
|
519 | - } |
|
520 | - |
|
521 | - /** |
|
522 | - * Reindexes all plugin priorities starting at 1. |
|
523 | - * |
|
524 | - * @return bool |
|
525 | - * @access private |
|
526 | - */ |
|
527 | - function reindexPriorities() { |
|
528 | - return $this->setPriorities([]); |
|
529 | - } |
|
530 | - |
|
531 | - /** |
|
532 | - * Namespaces a string to be used as a private setting name for a plugin. |
|
533 | - * |
|
534 | - * For user_settings, two namespaces are added: a user setting namespace and the |
|
535 | - * plugin id. |
|
536 | - * |
|
537 | - * For internal (plugin priority), there is a single internal namespace added. |
|
538 | - * |
|
539 | - * @param string $type The type of setting: user_setting or internal. |
|
540 | - * @param string $name The name to namespace. |
|
541 | - * @param string $id The plugin's ID to namespace with. Required for user_setting. |
|
542 | - * @return string |
|
543 | - * @access private |
|
544 | - */ |
|
545 | - function namespacePrivateSetting($type, $name, $id = null) { |
|
546 | - switch ($type) { |
|
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'); |
|
511 | + foreach ($missing_plugins as $plugin) { |
|
512 | + $priority++; |
|
513 | + if (!$plugin->setPrivateSetting($name, $priority)) { |
|
514 | + return false; |
|
515 | + } |
|
516 | + } |
|
517 | + |
|
518 | + return true; |
|
519 | + } |
|
520 | + |
|
521 | + /** |
|
522 | + * Reindexes all plugin priorities starting at 1. |
|
523 | + * |
|
524 | + * @return bool |
|
525 | + * @access private |
|
526 | + */ |
|
527 | + function reindexPriorities() { |
|
528 | + return $this->setPriorities([]); |
|
529 | + } |
|
530 | + |
|
531 | + /** |
|
532 | + * Namespaces a string to be used as a private setting name for a plugin. |
|
533 | + * |
|
534 | + * For user_settings, two namespaces are added: a user setting namespace and the |
|
535 | + * plugin id. |
|
536 | + * |
|
537 | + * For internal (plugin priority), there is a single internal namespace added. |
|
538 | + * |
|
539 | + * @param string $type The type of setting: user_setting or internal. |
|
540 | + * @param string $name The name to namespace. |
|
541 | + * @param string $id The plugin's ID to namespace with. Required for user_setting. |
|
542 | + * @return string |
|
543 | + * @access private |
|
544 | + */ |
|
545 | + function namespacePrivateSetting($type, $name, $id = null) { |
|
546 | + switch ($type) { |
|
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 | } |
@@ -3,8 +3,6 @@ |
||
3 | 3 | |
4 | 4 | use Elgg\Config; |
5 | 5 | use Elgg\Cache\Pool; |
6 | -use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; |
|
7 | -use Symfony\Component\HttpFoundation\Session\Session as SymfonySession; |
|
8 | 6 | use Zend\Mail\Transport\TransportInterface as Mailer; |
9 | 7 | |
10 | 8 | /** |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | $this->setClassName('externalFiles', \Elgg\Assets\ExternalFiles::class); |
242 | 242 | |
243 | 243 | $this->setFactory('fileCache', function(ServiceProvider $c) { |
244 | - return new \ElggFileCache($c->config->cacheroot . 'system_cache/'); |
|
244 | + return new \ElggFileCache($c->config->cacheroot.'system_cache/'); |
|
245 | 245 | }); |
246 | 246 | |
247 | 247 | $this->setFactory('filestore', function(ServiceProvider $c) { |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | return new \Elgg\ImageService($imagine, $c->config); |
278 | 278 | }); |
279 | 279 | |
280 | - $this->setFactory('logger', function (ServiceProvider $c) { |
|
280 | + $this->setFactory('logger', function(ServiceProvider $c) { |
|
281 | 281 | $logger = new \Elgg\Logger($c->hooks, $c->context); |
282 | 282 | $logger->setLevel($c->config->debug); |
283 | 283 | return $logger; |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | return new \Elgg\Menu\Service($c->hooks, $c->config); |
291 | 291 | }); |
292 | 292 | |
293 | - $this->setFactory('metadataCache', function (ServiceProvider $c) { |
|
293 | + $this->setFactory('metadataCache', function(ServiceProvider $c) { |
|
294 | 294 | $cache = _elgg_get_memcache('metadata'); |
295 | 295 | return new \Elgg\Cache\MetadataCache($cache); |
296 | 296 | }); |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | return new \Elgg\Database\SubtypeTable($c->db); |
427 | 427 | }); |
428 | 428 | |
429 | - $this->setFactory('systemCache', function (ServiceProvider $c) { |
|
429 | + $this->setFactory('systemCache', function(ServiceProvider $c) { |
|
430 | 430 | $cache = new \Elgg\Cache\SystemCache($c->fileCache, $c->config); |
431 | 431 | if ($c->config->enable_profiling) { |
432 | 432 | $cache->setTimer($c->timer); |
@@ -95,406 +95,406 @@ |
||
95 | 95 | */ |
96 | 96 | class ServiceProvider extends DiContainer { |
97 | 97 | |
98 | - /** |
|
99 | - * Constructor |
|
100 | - * |
|
101 | - * @param Config $config Elgg Config service |
|
102 | - */ |
|
103 | - public function __construct(Config $config) { |
|
104 | - |
|
105 | - $this->setFactory('autoloadManager', function(ServiceProvider $c) { |
|
106 | - $manager = new \Elgg\AutoloadManager($c->classLoader); |
|
107 | - if (!$c->config->AutoloaderManager_skip_storage) { |
|
108 | - $manager->setStorage($c->fileCache); |
|
109 | - $manager->loadCache(); |
|
110 | - } |
|
111 | - return $manager; |
|
112 | - }); |
|
113 | - |
|
114 | - $this->setFactory('accessCache', function(ServiceProvider $c) { |
|
115 | - return new \ElggStaticVariableCache('access'); |
|
116 | - }); |
|
117 | - |
|
118 | - $this->setFactory('accessCollections', function(ServiceProvider $c) { |
|
119 | - return new \Elgg\Database\AccessCollections( |
|
120 | - $c->config, $c->db, $c->entityTable, $c->accessCache, $c->hooks, $c->session, $c->translator); |
|
121 | - }); |
|
122 | - |
|
123 | - $this->setFactory('actions', function(ServiceProvider $c) { |
|
124 | - return new \Elgg\ActionsService($c->config, $c->session, $c->crypto); |
|
125 | - }); |
|
126 | - |
|
127 | - $this->setClassName('adminNotices', \Elgg\Database\AdminNotices::class); |
|
128 | - |
|
129 | - $this->setFactory('ajax', function(ServiceProvider $c) { |
|
130 | - return new \Elgg\Ajax\Service($c->hooks, $c->systemMessages, $c->input, $c->amdConfig); |
|
131 | - }); |
|
132 | - |
|
133 | - $this->setFactory('amdConfig', function(ServiceProvider $c) { |
|
134 | - $obj = new \Elgg\Amd\Config($c->hooks); |
|
135 | - $obj->setBaseUrl($c->simpleCache->getRoot()); |
|
136 | - return $obj; |
|
137 | - }); |
|
138 | - |
|
139 | - /** |
|
140 | - * "app" is set when the application is constructed |
|
141 | - * |
|
142 | - * @see \Elgg\Application::__construct "app" |
|
143 | - */ |
|
144 | - |
|
145 | - $this->setFactory('annotations', function(ServiceProvider $c) { |
|
146 | - return new \Elgg\Database\Annotations($c->db, $c->session, $c->hooks->getEvents()); |
|
147 | - }); |
|
148 | - |
|
149 | - $this->setClassName('autoP', \ElggAutoP::class); |
|
150 | - |
|
151 | - $this->setFactory('boot', function(ServiceProvider $c) { |
|
152 | - $boot = new \Elgg\BootService(); |
|
153 | - if ($c->config->enable_profiling) { |
|
154 | - $boot->setTimer($c->timer); |
|
155 | - } |
|
156 | - return $boot; |
|
157 | - }); |
|
158 | - |
|
159 | - $this->setFactory('batchUpgrader', function(ServiceProvider $c) { |
|
160 | - return new \Elgg\BatchUpgrader($c->config); |
|
161 | - }); |
|
162 | - |
|
163 | - $this->setFactory('cacheHandler', function(ServiceProvider $c) { |
|
164 | - $simplecache_enabled = $c->config->simplecache_enabled; |
|
165 | - if ($simplecache_enabled === null) { |
|
166 | - $simplecache_enabled = $c->configTable->get('simplecache_enabled'); |
|
167 | - } |
|
168 | - return new \Elgg\Application\CacheHandler($c->app, $c->config, $c->request, $simplecache_enabled); |
|
169 | - }); |
|
170 | - |
|
171 | - $this->setFactory('classLoader', function(ServiceProvider $c) { |
|
172 | - $loader = new \Elgg\ClassLoader(new \Elgg\ClassMap()); |
|
173 | - $loader->register(); |
|
174 | - return $loader; |
|
175 | - }); |
|
176 | - |
|
177 | - $this->setValue('config', $config); |
|
178 | - |
|
179 | - $this->setFactory('configTable', function(ServiceProvider $c) { |
|
180 | - return new \Elgg\Database\ConfigTable($c->db, $c->boot, $c->logger); |
|
181 | - }); |
|
182 | - |
|
183 | - $this->setFactory('context', function(ServiceProvider $c) { |
|
184 | - $context = new \Elgg\Context(); |
|
185 | - $context->initialize($c->request); |
|
186 | - return $context; |
|
187 | - }); |
|
188 | - |
|
189 | - $this->setClassName('crypto', \ElggCrypto::class); |
|
190 | - |
|
191 | - $this->setFactory('db', function(ServiceProvider $c) { |
|
192 | - $db = new \Elgg\Database($c->dbConfig); |
|
193 | - $db->setLogger($c->logger); |
|
194 | - |
|
195 | - if ($c->config->profiling_sql) { |
|
196 | - $db->setTimer($c->timer); |
|
197 | - } |
|
198 | - |
|
199 | - return $db; |
|
200 | - }); |
|
201 | - |
|
202 | - $this->setFactory('dbConfig', function(ServiceProvider $c) { |
|
203 | - $config = $c->config; |
|
204 | - $db_config = \Elgg\Database\DbConfig::fromElggConfig($config); |
|
205 | - |
|
206 | - // get this stuff out of config! |
|
207 | - unset($config->db); |
|
208 | - unset($config->dbname); |
|
209 | - unset($config->dbhost); |
|
210 | - unset($config->dbuser); |
|
211 | - unset($config->dbpass); |
|
212 | - |
|
213 | - return $db_config; |
|
214 | - }); |
|
215 | - |
|
216 | - $this->setFactory('deprecation', function(ServiceProvider $c) { |
|
217 | - return new \Elgg\DeprecationService($c->logger); |
|
218 | - }); |
|
219 | - |
|
220 | - $this->setFactory('emails', function(ServiceProvider $c) { |
|
221 | - return new \Elgg\EmailService($c->config, $c->hooks, $c->mailer, $c->logger); |
|
222 | - }); |
|
223 | - |
|
224 | - $this->setFactory('entityCache', function(ServiceProvider $c) { |
|
225 | - return new \Elgg\Cache\EntityCache($c->session, $c->metadataCache); |
|
226 | - }); |
|
227 | - |
|
228 | - $this->setFactory('entityPreloader', function(ServiceProvider $c) { |
|
229 | - return new \Elgg\EntityPreloader($c->entityCache, $c->entityTable); |
|
230 | - }); |
|
231 | - |
|
232 | - $this->setFactory('entityTable', function(ServiceProvider $c) { |
|
233 | - return new \Elgg\Database\EntityTable( |
|
234 | - $c->config, |
|
235 | - $c->db, |
|
236 | - $c->entityCache, |
|
237 | - $c->metadataCache, |
|
238 | - $c->subtypeTable, |
|
239 | - $c->hooks->getEvents(), |
|
240 | - $c->session, |
|
241 | - $c->translator, |
|
242 | - $c->logger |
|
243 | - ); |
|
244 | - }); |
|
245 | - |
|
246 | - $this->setClassName('externalFiles', \Elgg\Assets\ExternalFiles::class); |
|
247 | - |
|
248 | - $this->setFactory('fileCache', function(ServiceProvider $c) { |
|
249 | - return new \ElggFileCache($c->config->cacheroot . 'system_cache/'); |
|
250 | - }); |
|
251 | - |
|
252 | - $this->setFactory('filestore', function(ServiceProvider $c) { |
|
253 | - return new \ElggDiskFilestore($c->config->dataroot); |
|
254 | - }); |
|
255 | - |
|
256 | - $this->setFactory('forms', function(ServiceProvider $c) { |
|
257 | - return new \Elgg\FormsService($c->views, $c->logger); |
|
258 | - }); |
|
259 | - |
|
260 | - $this->setClassName('handlers', \Elgg\HandlersService::class); |
|
261 | - |
|
262 | - $this->setFactory('hmac', function(ServiceProvider $c) { |
|
263 | - return new \Elgg\Security\HmacFactory($c->siteSecret, $c->crypto); |
|
264 | - }); |
|
265 | - |
|
266 | - $this->setFactory('hooks', function(ServiceProvider $c) { |
|
267 | - $events = new \Elgg\EventsService($c->handlers); |
|
268 | - if ($c->config->enable_profiling) { |
|
269 | - $events->setTimer($c->timer); |
|
270 | - } |
|
271 | - return new \Elgg\PluginHooksService($events); |
|
272 | - }); |
|
273 | - |
|
274 | - $this->setFactory('iconService', function(ServiceProvider $c) { |
|
275 | - return new \Elgg\EntityIconService($c->config, $c->hooks, $c->request, $c->logger, $c->entityTable); |
|
276 | - }); |
|
277 | - |
|
278 | - $this->setClassName('input', \Elgg\Http\Input::class); |
|
279 | - |
|
280 | - $this->setFactory('imageService', function(ServiceProvider $c) { |
|
281 | - $imagine = new \Imagine\Gd\Imagine(); |
|
282 | - return new \Elgg\ImageService($imagine, $c->config); |
|
283 | - }); |
|
284 | - |
|
285 | - $this->setFactory('logger', function (ServiceProvider $c) { |
|
286 | - $logger = new \Elgg\Logger($c->hooks, $c->context); |
|
287 | - $logger->setLevel($c->config->debug); |
|
288 | - return $logger; |
|
289 | - }); |
|
290 | - |
|
291 | - // TODO(evan): Support configurable transports... |
|
292 | - $this->setClassName('mailer', 'Zend\Mail\Transport\Sendmail'); |
|
293 | - |
|
294 | - $this->setFactory('menus', function(ServiceProvider $c) { |
|
295 | - return new \Elgg\Menu\Service($c->hooks, $c->config); |
|
296 | - }); |
|
297 | - |
|
298 | - $this->setFactory('metadataCache', function (ServiceProvider $c) { |
|
299 | - $cache = _elgg_get_memcache('metadata'); |
|
300 | - return new \Elgg\Cache\MetadataCache($cache); |
|
301 | - }); |
|
302 | - |
|
303 | - $this->setFactory('memcacheStashPool', function(ServiceProvider $c) { |
|
304 | - if (!$c->config->memcache) { |
|
305 | - return null; |
|
306 | - } |
|
307 | - |
|
308 | - $servers = $c->config->memcache_servers; |
|
309 | - if (!$servers) { |
|
310 | - return null; |
|
311 | - } |
|
312 | - $driver = new \Stash\Driver\Memcache([ |
|
313 | - 'servers' => $servers, |
|
314 | - ]); |
|
315 | - return new \Stash\Pool($driver); |
|
316 | - }); |
|
317 | - |
|
318 | - $this->setFactory('metadataTable', function(ServiceProvider $c) { |
|
319 | - // TODO(ewinslow): Use Pool instead of MetadataCache for caching |
|
320 | - return new \Elgg\Database\MetadataTable( |
|
321 | - $c->metadataCache, $c->db, $c->entityTable, $c->hooks->getEvents(), $c->session); |
|
322 | - }); |
|
323 | - |
|
324 | - $this->setFactory('mutex', function(ServiceProvider $c) { |
|
325 | - return new \Elgg\Database\Mutex( |
|
326 | - $c->db, |
|
327 | - $c->logger |
|
328 | - ); |
|
329 | - }); |
|
330 | - |
|
331 | - $this->setFactory('notifications', function(ServiceProvider $c) { |
|
332 | - // @todo move queue in service provider |
|
333 | - $queue_name = \Elgg\Notifications\NotificationsService::QUEUE_NAME; |
|
334 | - $queue = new \Elgg\Queue\DatabaseQueue($queue_name, $c->db); |
|
335 | - $sub = new \Elgg\Notifications\SubscriptionsService($c->db); |
|
336 | - return new \Elgg\Notifications\NotificationsService($sub, $queue, $c->hooks, $c->session, $c->translator, $c->entityTable, $c->logger); |
|
337 | - }); |
|
338 | - |
|
339 | - $this->setClassName('nullCache', \Elgg\Cache\NullCache::class); |
|
340 | - |
|
341 | - $this->setFactory('persistentLogin', function(ServiceProvider $c) { |
|
342 | - $global_cookies_config = $c->config->getCookieConfig(); |
|
343 | - $cookie_config = $global_cookies_config['remember_me']; |
|
344 | - $cookie_name = $cookie_config['name']; |
|
345 | - $cookie_token = $c->request->cookies->get($cookie_name, ''); |
|
346 | - return new \Elgg\PersistentLoginService( |
|
347 | - $c->db, $c->session, $c->crypto, $cookie_config, $cookie_token); |
|
348 | - }); |
|
349 | - |
|
350 | - $this->setClassName('passwords', \Elgg\PasswordService::class); |
|
351 | - |
|
352 | - $this->setFactory('plugins', function(ServiceProvider $c) { |
|
353 | - $pool = new Pool\InMemory(); |
|
354 | - $plugins = new \Elgg\Database\Plugins($pool, $c->pluginSettingsCache); |
|
355 | - if ($c->config->enable_profiling) { |
|
356 | - $plugins->setTimer($c->timer); |
|
357 | - } |
|
358 | - return $plugins; |
|
359 | - }); |
|
360 | - |
|
361 | - $this->setClassName('pluginSettingsCache', \Elgg\Cache\PluginSettingsCache::class); |
|
362 | - |
|
363 | - $this->setFactory('privateSettings', function(ServiceProvider $c) { |
|
364 | - return new \Elgg\Database\PrivateSettingsTable($c->db, $c->entityTable, $c->pluginSettingsCache); |
|
365 | - }); |
|
366 | - |
|
367 | - $this->setFactory('publicDb', function(ServiceProvider $c) { |
|
368 | - return new \Elgg\Application\Database($c->db); |
|
369 | - }); |
|
370 | - |
|
371 | - $this->setFactory('queryCounter', function(ServiceProvider $c) { |
|
372 | - return new \Elgg\Database\QueryCounter($c->db); |
|
373 | - }, false); |
|
374 | - |
|
375 | - $this->setFactory('redirects', function(ServiceProvider $c) { |
|
376 | - $url = current_page_url(); |
|
377 | - $is_xhr = $c->request->isXmlHttpRequest(); |
|
378 | - return new \Elgg\RedirectService($c->session, $is_xhr, $c->config->wwwroot, $url); |
|
379 | - }); |
|
380 | - |
|
381 | - $this->setFactory('relationshipsTable', function(ServiceProvider $c) { |
|
382 | - return new \Elgg\Database\RelationshipsTable($c->db, $c->entityTable, $c->metadataTable, $c->hooks->getEvents()); |
|
383 | - }); |
|
384 | - |
|
385 | - $this->setFactory('request', [\Elgg\Http\Request::class, 'createFromGlobals']); |
|
386 | - |
|
387 | - $this->setFactory('responseFactory', function(ServiceProvider $c) { |
|
388 | - if (PHP_SAPI === 'cli') { |
|
389 | - $transport = new \Elgg\Http\OutputBufferTransport(); |
|
390 | - } else { |
|
391 | - $transport = new \Elgg\Http\HttpProtocolTransport(); |
|
392 | - } |
|
393 | - return new \Elgg\Http\ResponseFactory($c->request, $c->hooks, $c->ajax, $transport); |
|
394 | - }); |
|
395 | - |
|
396 | - $this->setFactory('router', function(ServiceProvider $c) { |
|
397 | - // TODO(evan): Init routes from plugins or cache |
|
398 | - $router = new \Elgg\Router($c->hooks); |
|
399 | - if ($c->config->enable_profiling) { |
|
400 | - $router->setTimer($c->timer); |
|
401 | - } |
|
402 | - return $router; |
|
403 | - }); |
|
404 | - |
|
405 | - $this->setFactory('serveFileHandler', function(ServiceProvider $c) { |
|
406 | - return new \Elgg\Application\ServeFileHandler($c->hmac, $c->config); |
|
407 | - }); |
|
408 | - |
|
409 | - $this->setFactory('session', function(ServiceProvider $c) { |
|
410 | - return \ElggSession::fromDatabase($c->config, $c->db); |
|
411 | - }); |
|
412 | - |
|
413 | - $this->setClassName('urlSigner', \Elgg\Security\UrlSigner::class); |
|
414 | - |
|
415 | - $this->setFactory('simpleCache', function(ServiceProvider $c) { |
|
416 | - return new \Elgg\Cache\SimpleCache($c->config); |
|
417 | - }); |
|
418 | - |
|
419 | - /** |
|
420 | - * If the key is in the settings file, this is injected early. |
|
421 | - * |
|
422 | - * @see \Elgg\Application::initConfig |
|
423 | - */ |
|
424 | - $this->setFactory('siteSecret', function(ServiceProvider $c) { |
|
425 | - return \Elgg\Database\SiteSecret::fromDatabase($c->configTable); |
|
426 | - }); |
|
427 | - |
|
428 | - $this->setClassName('stickyForms', \Elgg\Forms\StickyForms::class); |
|
429 | - |
|
430 | - $this->setFactory('subtypeTable', function(ServiceProvider $c) { |
|
431 | - return new \Elgg\Database\SubtypeTable($c->db); |
|
432 | - }); |
|
433 | - |
|
434 | - $this->setFactory('systemCache', function (ServiceProvider $c) { |
|
435 | - $cache = new \Elgg\Cache\SystemCache($c->fileCache, $c->config); |
|
436 | - if ($c->config->enable_profiling) { |
|
437 | - $cache->setTimer($c->timer); |
|
438 | - } |
|
439 | - return $cache; |
|
440 | - }); |
|
441 | - |
|
442 | - $this->setFactory('systemMessages', function(ServiceProvider $c) { |
|
443 | - return new \Elgg\SystemMessagesService($c->session); |
|
444 | - }); |
|
445 | - |
|
446 | - $this->setClassName('table_columns', \Elgg\Views\TableColumn\ColumnFactory::class); |
|
447 | - |
|
448 | - $this->setClassName('timer', \Elgg\Timer::class); |
|
449 | - |
|
450 | - $this->setFactory('translator', function(ServiceProvider $c) { |
|
451 | - return new \Elgg\I18n\Translator($c->config); |
|
452 | - }); |
|
453 | - |
|
454 | - $this->setFactory('uploads', function(ServiceProvider $c) { |
|
455 | - return new \Elgg\UploadService($c->request); |
|
456 | - }); |
|
457 | - |
|
458 | - $this->setFactory('upgrades', function(ServiceProvider $c) { |
|
459 | - return new \Elgg\UpgradeService( |
|
460 | - $c->translator, |
|
461 | - $c->hooks, |
|
462 | - $c->config, |
|
463 | - $c->logger, |
|
464 | - $c->mutex |
|
465 | - ); |
|
466 | - }); |
|
467 | - |
|
468 | - $this->setFactory('userCapabilities', function(ServiceProvider $c) { |
|
469 | - return new \Elgg\UserCapabilities($c->hooks, $c->entityTable, $c->session); |
|
470 | - }); |
|
471 | - |
|
472 | - $this->setFactory('usersTable', function(ServiceProvider $c) { |
|
473 | - return new \Elgg\Database\UsersTable( |
|
474 | - $c->config, |
|
475 | - $c->db, |
|
476 | - $c->entityTable, |
|
477 | - $c->entityCache, |
|
478 | - $c->hooks->getEvents() |
|
479 | - ); |
|
480 | - }); |
|
481 | - |
|
482 | - $this->setFactory('upgradeLocator', function(ServiceProvider $c) { |
|
483 | - return new \Elgg\Upgrade\Locator( |
|
484 | - $c->plugins, |
|
485 | - $c->logger, |
|
486 | - $c->privateSettings |
|
487 | - ); |
|
488 | - }); |
|
489 | - |
|
490 | - $this->setFactory('views', function(ServiceProvider $c) { |
|
491 | - return new \Elgg\ViewsService($c->hooks, $c->logger, $c->input); |
|
492 | - }); |
|
493 | - |
|
494 | - $this->setFactory('viewCacher', function(ServiceProvider $c) { |
|
495 | - return new \Elgg\Cache\ViewCacher($c->views, $c->config); |
|
496 | - }); |
|
497 | - |
|
498 | - $this->setClassName('widgets', \Elgg\WidgetsService::class); |
|
499 | - } |
|
98 | + /** |
|
99 | + * Constructor |
|
100 | + * |
|
101 | + * @param Config $config Elgg Config service |
|
102 | + */ |
|
103 | + public function __construct(Config $config) { |
|
104 | + |
|
105 | + $this->setFactory('autoloadManager', function(ServiceProvider $c) { |
|
106 | + $manager = new \Elgg\AutoloadManager($c->classLoader); |
|
107 | + if (!$c->config->AutoloaderManager_skip_storage) { |
|
108 | + $manager->setStorage($c->fileCache); |
|
109 | + $manager->loadCache(); |
|
110 | + } |
|
111 | + return $manager; |
|
112 | + }); |
|
113 | + |
|
114 | + $this->setFactory('accessCache', function(ServiceProvider $c) { |
|
115 | + return new \ElggStaticVariableCache('access'); |
|
116 | + }); |
|
117 | + |
|
118 | + $this->setFactory('accessCollections', function(ServiceProvider $c) { |
|
119 | + return new \Elgg\Database\AccessCollections( |
|
120 | + $c->config, $c->db, $c->entityTable, $c->accessCache, $c->hooks, $c->session, $c->translator); |
|
121 | + }); |
|
122 | + |
|
123 | + $this->setFactory('actions', function(ServiceProvider $c) { |
|
124 | + return new \Elgg\ActionsService($c->config, $c->session, $c->crypto); |
|
125 | + }); |
|
126 | + |
|
127 | + $this->setClassName('adminNotices', \Elgg\Database\AdminNotices::class); |
|
128 | + |
|
129 | + $this->setFactory('ajax', function(ServiceProvider $c) { |
|
130 | + return new \Elgg\Ajax\Service($c->hooks, $c->systemMessages, $c->input, $c->amdConfig); |
|
131 | + }); |
|
132 | + |
|
133 | + $this->setFactory('amdConfig', function(ServiceProvider $c) { |
|
134 | + $obj = new \Elgg\Amd\Config($c->hooks); |
|
135 | + $obj->setBaseUrl($c->simpleCache->getRoot()); |
|
136 | + return $obj; |
|
137 | + }); |
|
138 | + |
|
139 | + /** |
|
140 | + * "app" is set when the application is constructed |
|
141 | + * |
|
142 | + * @see \Elgg\Application::__construct "app" |
|
143 | + */ |
|
144 | + |
|
145 | + $this->setFactory('annotations', function(ServiceProvider $c) { |
|
146 | + return new \Elgg\Database\Annotations($c->db, $c->session, $c->hooks->getEvents()); |
|
147 | + }); |
|
148 | + |
|
149 | + $this->setClassName('autoP', \ElggAutoP::class); |
|
150 | + |
|
151 | + $this->setFactory('boot', function(ServiceProvider $c) { |
|
152 | + $boot = new \Elgg\BootService(); |
|
153 | + if ($c->config->enable_profiling) { |
|
154 | + $boot->setTimer($c->timer); |
|
155 | + } |
|
156 | + return $boot; |
|
157 | + }); |
|
158 | + |
|
159 | + $this->setFactory('batchUpgrader', function(ServiceProvider $c) { |
|
160 | + return new \Elgg\BatchUpgrader($c->config); |
|
161 | + }); |
|
162 | + |
|
163 | + $this->setFactory('cacheHandler', function(ServiceProvider $c) { |
|
164 | + $simplecache_enabled = $c->config->simplecache_enabled; |
|
165 | + if ($simplecache_enabled === null) { |
|
166 | + $simplecache_enabled = $c->configTable->get('simplecache_enabled'); |
|
167 | + } |
|
168 | + return new \Elgg\Application\CacheHandler($c->app, $c->config, $c->request, $simplecache_enabled); |
|
169 | + }); |
|
170 | + |
|
171 | + $this->setFactory('classLoader', function(ServiceProvider $c) { |
|
172 | + $loader = new \Elgg\ClassLoader(new \Elgg\ClassMap()); |
|
173 | + $loader->register(); |
|
174 | + return $loader; |
|
175 | + }); |
|
176 | + |
|
177 | + $this->setValue('config', $config); |
|
178 | + |
|
179 | + $this->setFactory('configTable', function(ServiceProvider $c) { |
|
180 | + return new \Elgg\Database\ConfigTable($c->db, $c->boot, $c->logger); |
|
181 | + }); |
|
182 | + |
|
183 | + $this->setFactory('context', function(ServiceProvider $c) { |
|
184 | + $context = new \Elgg\Context(); |
|
185 | + $context->initialize($c->request); |
|
186 | + return $context; |
|
187 | + }); |
|
188 | + |
|
189 | + $this->setClassName('crypto', \ElggCrypto::class); |
|
190 | + |
|
191 | + $this->setFactory('db', function(ServiceProvider $c) { |
|
192 | + $db = new \Elgg\Database($c->dbConfig); |
|
193 | + $db->setLogger($c->logger); |
|
194 | + |
|
195 | + if ($c->config->profiling_sql) { |
|
196 | + $db->setTimer($c->timer); |
|
197 | + } |
|
198 | + |
|
199 | + return $db; |
|
200 | + }); |
|
201 | + |
|
202 | + $this->setFactory('dbConfig', function(ServiceProvider $c) { |
|
203 | + $config = $c->config; |
|
204 | + $db_config = \Elgg\Database\DbConfig::fromElggConfig($config); |
|
205 | + |
|
206 | + // get this stuff out of config! |
|
207 | + unset($config->db); |
|
208 | + unset($config->dbname); |
|
209 | + unset($config->dbhost); |
|
210 | + unset($config->dbuser); |
|
211 | + unset($config->dbpass); |
|
212 | + |
|
213 | + return $db_config; |
|
214 | + }); |
|
215 | + |
|
216 | + $this->setFactory('deprecation', function(ServiceProvider $c) { |
|
217 | + return new \Elgg\DeprecationService($c->logger); |
|
218 | + }); |
|
219 | + |
|
220 | + $this->setFactory('emails', function(ServiceProvider $c) { |
|
221 | + return new \Elgg\EmailService($c->config, $c->hooks, $c->mailer, $c->logger); |
|
222 | + }); |
|
223 | + |
|
224 | + $this->setFactory('entityCache', function(ServiceProvider $c) { |
|
225 | + return new \Elgg\Cache\EntityCache($c->session, $c->metadataCache); |
|
226 | + }); |
|
227 | + |
|
228 | + $this->setFactory('entityPreloader', function(ServiceProvider $c) { |
|
229 | + return new \Elgg\EntityPreloader($c->entityCache, $c->entityTable); |
|
230 | + }); |
|
231 | + |
|
232 | + $this->setFactory('entityTable', function(ServiceProvider $c) { |
|
233 | + return new \Elgg\Database\EntityTable( |
|
234 | + $c->config, |
|
235 | + $c->db, |
|
236 | + $c->entityCache, |
|
237 | + $c->metadataCache, |
|
238 | + $c->subtypeTable, |
|
239 | + $c->hooks->getEvents(), |
|
240 | + $c->session, |
|
241 | + $c->translator, |
|
242 | + $c->logger |
|
243 | + ); |
|
244 | + }); |
|
245 | + |
|
246 | + $this->setClassName('externalFiles', \Elgg\Assets\ExternalFiles::class); |
|
247 | + |
|
248 | + $this->setFactory('fileCache', function(ServiceProvider $c) { |
|
249 | + return new \ElggFileCache($c->config->cacheroot . 'system_cache/'); |
|
250 | + }); |
|
251 | + |
|
252 | + $this->setFactory('filestore', function(ServiceProvider $c) { |
|
253 | + return new \ElggDiskFilestore($c->config->dataroot); |
|
254 | + }); |
|
255 | + |
|
256 | + $this->setFactory('forms', function(ServiceProvider $c) { |
|
257 | + return new \Elgg\FormsService($c->views, $c->logger); |
|
258 | + }); |
|
259 | + |
|
260 | + $this->setClassName('handlers', \Elgg\HandlersService::class); |
|
261 | + |
|
262 | + $this->setFactory('hmac', function(ServiceProvider $c) { |
|
263 | + return new \Elgg\Security\HmacFactory($c->siteSecret, $c->crypto); |
|
264 | + }); |
|
265 | + |
|
266 | + $this->setFactory('hooks', function(ServiceProvider $c) { |
|
267 | + $events = new \Elgg\EventsService($c->handlers); |
|
268 | + if ($c->config->enable_profiling) { |
|
269 | + $events->setTimer($c->timer); |
|
270 | + } |
|
271 | + return new \Elgg\PluginHooksService($events); |
|
272 | + }); |
|
273 | + |
|
274 | + $this->setFactory('iconService', function(ServiceProvider $c) { |
|
275 | + return new \Elgg\EntityIconService($c->config, $c->hooks, $c->request, $c->logger, $c->entityTable); |
|
276 | + }); |
|
277 | + |
|
278 | + $this->setClassName('input', \Elgg\Http\Input::class); |
|
279 | + |
|
280 | + $this->setFactory('imageService', function(ServiceProvider $c) { |
|
281 | + $imagine = new \Imagine\Gd\Imagine(); |
|
282 | + return new \Elgg\ImageService($imagine, $c->config); |
|
283 | + }); |
|
284 | + |
|
285 | + $this->setFactory('logger', function (ServiceProvider $c) { |
|
286 | + $logger = new \Elgg\Logger($c->hooks, $c->context); |
|
287 | + $logger->setLevel($c->config->debug); |
|
288 | + return $logger; |
|
289 | + }); |
|
290 | + |
|
291 | + // TODO(evan): Support configurable transports... |
|
292 | + $this->setClassName('mailer', 'Zend\Mail\Transport\Sendmail'); |
|
293 | + |
|
294 | + $this->setFactory('menus', function(ServiceProvider $c) { |
|
295 | + return new \Elgg\Menu\Service($c->hooks, $c->config); |
|
296 | + }); |
|
297 | + |
|
298 | + $this->setFactory('metadataCache', function (ServiceProvider $c) { |
|
299 | + $cache = _elgg_get_memcache('metadata'); |
|
300 | + return new \Elgg\Cache\MetadataCache($cache); |
|
301 | + }); |
|
302 | + |
|
303 | + $this->setFactory('memcacheStashPool', function(ServiceProvider $c) { |
|
304 | + if (!$c->config->memcache) { |
|
305 | + return null; |
|
306 | + } |
|
307 | + |
|
308 | + $servers = $c->config->memcache_servers; |
|
309 | + if (!$servers) { |
|
310 | + return null; |
|
311 | + } |
|
312 | + $driver = new \Stash\Driver\Memcache([ |
|
313 | + 'servers' => $servers, |
|
314 | + ]); |
|
315 | + return new \Stash\Pool($driver); |
|
316 | + }); |
|
317 | + |
|
318 | + $this->setFactory('metadataTable', function(ServiceProvider $c) { |
|
319 | + // TODO(ewinslow): Use Pool instead of MetadataCache for caching |
|
320 | + return new \Elgg\Database\MetadataTable( |
|
321 | + $c->metadataCache, $c->db, $c->entityTable, $c->hooks->getEvents(), $c->session); |
|
322 | + }); |
|
323 | + |
|
324 | + $this->setFactory('mutex', function(ServiceProvider $c) { |
|
325 | + return new \Elgg\Database\Mutex( |
|
326 | + $c->db, |
|
327 | + $c->logger |
|
328 | + ); |
|
329 | + }); |
|
330 | + |
|
331 | + $this->setFactory('notifications', function(ServiceProvider $c) { |
|
332 | + // @todo move queue in service provider |
|
333 | + $queue_name = \Elgg\Notifications\NotificationsService::QUEUE_NAME; |
|
334 | + $queue = new \Elgg\Queue\DatabaseQueue($queue_name, $c->db); |
|
335 | + $sub = new \Elgg\Notifications\SubscriptionsService($c->db); |
|
336 | + return new \Elgg\Notifications\NotificationsService($sub, $queue, $c->hooks, $c->session, $c->translator, $c->entityTable, $c->logger); |
|
337 | + }); |
|
338 | + |
|
339 | + $this->setClassName('nullCache', \Elgg\Cache\NullCache::class); |
|
340 | + |
|
341 | + $this->setFactory('persistentLogin', function(ServiceProvider $c) { |
|
342 | + $global_cookies_config = $c->config->getCookieConfig(); |
|
343 | + $cookie_config = $global_cookies_config['remember_me']; |
|
344 | + $cookie_name = $cookie_config['name']; |
|
345 | + $cookie_token = $c->request->cookies->get($cookie_name, ''); |
|
346 | + return new \Elgg\PersistentLoginService( |
|
347 | + $c->db, $c->session, $c->crypto, $cookie_config, $cookie_token); |
|
348 | + }); |
|
349 | + |
|
350 | + $this->setClassName('passwords', \Elgg\PasswordService::class); |
|
351 | + |
|
352 | + $this->setFactory('plugins', function(ServiceProvider $c) { |
|
353 | + $pool = new Pool\InMemory(); |
|
354 | + $plugins = new \Elgg\Database\Plugins($pool, $c->pluginSettingsCache); |
|
355 | + if ($c->config->enable_profiling) { |
|
356 | + $plugins->setTimer($c->timer); |
|
357 | + } |
|
358 | + return $plugins; |
|
359 | + }); |
|
360 | + |
|
361 | + $this->setClassName('pluginSettingsCache', \Elgg\Cache\PluginSettingsCache::class); |
|
362 | + |
|
363 | + $this->setFactory('privateSettings', function(ServiceProvider $c) { |
|
364 | + return new \Elgg\Database\PrivateSettingsTable($c->db, $c->entityTable, $c->pluginSettingsCache); |
|
365 | + }); |
|
366 | + |
|
367 | + $this->setFactory('publicDb', function(ServiceProvider $c) { |
|
368 | + return new \Elgg\Application\Database($c->db); |
|
369 | + }); |
|
370 | + |
|
371 | + $this->setFactory('queryCounter', function(ServiceProvider $c) { |
|
372 | + return new \Elgg\Database\QueryCounter($c->db); |
|
373 | + }, false); |
|
374 | + |
|
375 | + $this->setFactory('redirects', function(ServiceProvider $c) { |
|
376 | + $url = current_page_url(); |
|
377 | + $is_xhr = $c->request->isXmlHttpRequest(); |
|
378 | + return new \Elgg\RedirectService($c->session, $is_xhr, $c->config->wwwroot, $url); |
|
379 | + }); |
|
380 | + |
|
381 | + $this->setFactory('relationshipsTable', function(ServiceProvider $c) { |
|
382 | + return new \Elgg\Database\RelationshipsTable($c->db, $c->entityTable, $c->metadataTable, $c->hooks->getEvents()); |
|
383 | + }); |
|
384 | + |
|
385 | + $this->setFactory('request', [\Elgg\Http\Request::class, 'createFromGlobals']); |
|
386 | + |
|
387 | + $this->setFactory('responseFactory', function(ServiceProvider $c) { |
|
388 | + if (PHP_SAPI === 'cli') { |
|
389 | + $transport = new \Elgg\Http\OutputBufferTransport(); |
|
390 | + } else { |
|
391 | + $transport = new \Elgg\Http\HttpProtocolTransport(); |
|
392 | + } |
|
393 | + return new \Elgg\Http\ResponseFactory($c->request, $c->hooks, $c->ajax, $transport); |
|
394 | + }); |
|
395 | + |
|
396 | + $this->setFactory('router', function(ServiceProvider $c) { |
|
397 | + // TODO(evan): Init routes from plugins or cache |
|
398 | + $router = new \Elgg\Router($c->hooks); |
|
399 | + if ($c->config->enable_profiling) { |
|
400 | + $router->setTimer($c->timer); |
|
401 | + } |
|
402 | + return $router; |
|
403 | + }); |
|
404 | + |
|
405 | + $this->setFactory('serveFileHandler', function(ServiceProvider $c) { |
|
406 | + return new \Elgg\Application\ServeFileHandler($c->hmac, $c->config); |
|
407 | + }); |
|
408 | + |
|
409 | + $this->setFactory('session', function(ServiceProvider $c) { |
|
410 | + return \ElggSession::fromDatabase($c->config, $c->db); |
|
411 | + }); |
|
412 | + |
|
413 | + $this->setClassName('urlSigner', \Elgg\Security\UrlSigner::class); |
|
414 | + |
|
415 | + $this->setFactory('simpleCache', function(ServiceProvider $c) { |
|
416 | + return new \Elgg\Cache\SimpleCache($c->config); |
|
417 | + }); |
|
418 | + |
|
419 | + /** |
|
420 | + * If the key is in the settings file, this is injected early. |
|
421 | + * |
|
422 | + * @see \Elgg\Application::initConfig |
|
423 | + */ |
|
424 | + $this->setFactory('siteSecret', function(ServiceProvider $c) { |
|
425 | + return \Elgg\Database\SiteSecret::fromDatabase($c->configTable); |
|
426 | + }); |
|
427 | + |
|
428 | + $this->setClassName('stickyForms', \Elgg\Forms\StickyForms::class); |
|
429 | + |
|
430 | + $this->setFactory('subtypeTable', function(ServiceProvider $c) { |
|
431 | + return new \Elgg\Database\SubtypeTable($c->db); |
|
432 | + }); |
|
433 | + |
|
434 | + $this->setFactory('systemCache', function (ServiceProvider $c) { |
|
435 | + $cache = new \Elgg\Cache\SystemCache($c->fileCache, $c->config); |
|
436 | + if ($c->config->enable_profiling) { |
|
437 | + $cache->setTimer($c->timer); |
|
438 | + } |
|
439 | + return $cache; |
|
440 | + }); |
|
441 | + |
|
442 | + $this->setFactory('systemMessages', function(ServiceProvider $c) { |
|
443 | + return new \Elgg\SystemMessagesService($c->session); |
|
444 | + }); |
|
445 | + |
|
446 | + $this->setClassName('table_columns', \Elgg\Views\TableColumn\ColumnFactory::class); |
|
447 | + |
|
448 | + $this->setClassName('timer', \Elgg\Timer::class); |
|
449 | + |
|
450 | + $this->setFactory('translator', function(ServiceProvider $c) { |
|
451 | + return new \Elgg\I18n\Translator($c->config); |
|
452 | + }); |
|
453 | + |
|
454 | + $this->setFactory('uploads', function(ServiceProvider $c) { |
|
455 | + return new \Elgg\UploadService($c->request); |
|
456 | + }); |
|
457 | + |
|
458 | + $this->setFactory('upgrades', function(ServiceProvider $c) { |
|
459 | + return new \Elgg\UpgradeService( |
|
460 | + $c->translator, |
|
461 | + $c->hooks, |
|
462 | + $c->config, |
|
463 | + $c->logger, |
|
464 | + $c->mutex |
|
465 | + ); |
|
466 | + }); |
|
467 | + |
|
468 | + $this->setFactory('userCapabilities', function(ServiceProvider $c) { |
|
469 | + return new \Elgg\UserCapabilities($c->hooks, $c->entityTable, $c->session); |
|
470 | + }); |
|
471 | + |
|
472 | + $this->setFactory('usersTable', function(ServiceProvider $c) { |
|
473 | + return new \Elgg\Database\UsersTable( |
|
474 | + $c->config, |
|
475 | + $c->db, |
|
476 | + $c->entityTable, |
|
477 | + $c->entityCache, |
|
478 | + $c->hooks->getEvents() |
|
479 | + ); |
|
480 | + }); |
|
481 | + |
|
482 | + $this->setFactory('upgradeLocator', function(ServiceProvider $c) { |
|
483 | + return new \Elgg\Upgrade\Locator( |
|
484 | + $c->plugins, |
|
485 | + $c->logger, |
|
486 | + $c->privateSettings |
|
487 | + ); |
|
488 | + }); |
|
489 | + |
|
490 | + $this->setFactory('views', function(ServiceProvider $c) { |
|
491 | + return new \Elgg\ViewsService($c->hooks, $c->logger, $c->input); |
|
492 | + }); |
|
493 | + |
|
494 | + $this->setFactory('viewCacher', function(ServiceProvider $c) { |
|
495 | + return new \Elgg\Cache\ViewCacher($c->views, $c->config); |
|
496 | + }); |
|
497 | + |
|
498 | + $this->setClassName('widgets', \Elgg\WidgetsService::class); |
|
499 | + } |
|
500 | 500 | } |
@@ -1,6 +1,5 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -use Elgg\Filesystem\Directory; |
|
4 | 3 | use Elgg\Application; |
5 | 4 | use Elgg\Config; |
6 | 5 | use Elgg\Database\DbConfig; |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | |
99 | 99 | $params = $this->services->request->request->all(); |
100 | 100 | |
101 | - $method = "run" . ucwords($step); |
|
101 | + $method = "run".ucwords($step); |
|
102 | 102 | $this->$method($params); |
103 | 103 | } |
104 | 104 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $this->services->setValue('session', \ElggSession::getMock()); |
127 | 127 | $this->services->views->setViewtype('installation'); |
128 | 128 | $this->services->views->registerPluginViews(Paths::elgg()); |
129 | - $this->services->translator->registerTranslations(Paths::elgg() . "install/languages/", true); |
|
129 | + $this->services->translator->registerTranslations(Paths::elgg()."install/languages/", true); |
|
130 | 130 | |
131 | 131 | return $this->app; |
132 | 132 | } |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | } |
396 | 396 | |
397 | 397 | if ($this->is_action) { |
398 | - call_user_func(function () use ($submissionVars, $formVars) { |
|
398 | + call_user_func(function() use ($submissionVars, $formVars) { |
|
399 | 399 | // only create settings file if it doesn't exist |
400 | 400 | if (!$this->checkSettingsFile()) { |
401 | 401 | if (!$this->validateDatabaseVars($submissionVars, $formVars)) { |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | |
426 | 426 | $formVars = $this->makeFormSticky($formVars, $submissionVars); |
427 | 427 | |
428 | - $params = ['variables' => $formVars,]; |
|
428 | + $params = ['variables' => $formVars, ]; |
|
429 | 429 | |
430 | 430 | if ($this->checkSettingsFile()) { |
431 | 431 | // settings file exists and we're here so failed to create database |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | ]; |
465 | 465 | |
466 | 466 | if ($this->is_action) { |
467 | - call_user_func(function () use ($submissionVars, $formVars) { |
|
467 | + call_user_func(function() use ($submissionVars, $formVars) { |
|
468 | 468 | if (!$this->validateSettingsVars($submissionVars, $formVars)) { |
469 | 469 | return; |
470 | 470 | } |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | ]; |
525 | 525 | |
526 | 526 | if ($this->is_action) { |
527 | - call_user_func(function () use ($submissionVars, $formVars) { |
|
527 | + call_user_func(function() use ($submissionVars, $formVars) { |
|
528 | 528 | if (!$this->validateAdminVars($submissionVars, $formVars)) { |
529 | 529 | return; |
530 | 530 | } |
@@ -624,7 +624,7 @@ discard block |
||
624 | 624 | */ |
625 | 625 | protected function getNextStepUrl($currentStep) { |
626 | 626 | $nextStep = $this->getNextStep($currentStep); |
627 | - return $this->config->wwwroot . "install.php?step=$nextStep"; |
|
627 | + return $this->config->wwwroot."install.php?step=$nextStep"; |
|
628 | 628 | } |
629 | 629 | |
630 | 630 | /** |
@@ -992,7 +992,7 @@ discard block |
||
992 | 992 | protected function checkRewriteRules(&$report) { |
993 | 993 | $tester = new ElggRewriteTester(); |
994 | 994 | $url = $this->config->wwwroot; |
995 | - $url .= Request::REWRITE_TEST_TOKEN . '?' . http_build_query([ |
|
995 | + $url .= Request::REWRITE_TEST_TOKEN.'?'.http_build_query([ |
|
996 | 996 | Request::REWRITE_TEST_TOKEN => '1', |
997 | 997 | ]); |
998 | 998 | $report['rewrite'] = [$tester->run($url, Paths::project())]; |
@@ -1154,7 +1154,7 @@ discard block |
||
1154 | 1154 | } |
1155 | 1155 | |
1156 | 1156 | foreach ($params as $k => $v) { |
1157 | - $template = str_replace("{{" . $k . "}}", $v, $template); |
|
1157 | + $template = str_replace("{{".$k."}}", $v, $template); |
|
1158 | 1158 | } |
1159 | 1159 | |
1160 | 1160 | $result = file_put_contents(Paths::settingsFile(), $template); |
@@ -1189,7 +1189,7 @@ discard block |
||
1189 | 1189 | */ |
1190 | 1190 | protected function installDatabase() { |
1191 | 1191 | try { |
1192 | - $this->services->db->runSqlScript(Paths::elgg() . "engine/schema/mysql.sql"); |
|
1192 | + $this->services->db->runSqlScript(Paths::elgg()."engine/schema/mysql.sql"); |
|
1193 | 1193 | init_site_secret(); |
1194 | 1194 | } catch (Exception $e) { |
1195 | 1195 | $msg = $e->getMessage(); |
@@ -1226,7 +1226,7 @@ discard block |
||
1226 | 1226 | return true; |
1227 | 1227 | } |
1228 | 1228 | |
1229 | - $dir = sanitise_filepath($submissionVars['path']) . 'data'; |
|
1229 | + $dir = sanitise_filepath($submissionVars['path']).'data'; |
|
1230 | 1230 | if (file_exists($dir) || mkdir($dir, 0700)) { |
1231 | 1231 | $submissionVars['dataroot'] = $dir; |
1232 | 1232 | if (!file_exists("$dir/.htaccess")) { |
@@ -1294,7 +1294,7 @@ discard block |
||
1294 | 1294 | $this->config->site = $site; |
1295 | 1295 | |
1296 | 1296 | // new installations have run all the upgrades |
1297 | - $upgrades = elgg_get_upgrade_files(Paths::elgg() . "engine/lib/upgrades/"); |
|
1297 | + $upgrades = elgg_get_upgrade_files(Paths::elgg()."engine/lib/upgrades/"); |
|
1298 | 1298 | |
1299 | 1299 | $sets = [ |
1300 | 1300 | 'installed' => time(), |
@@ -34,1420 +34,1420 @@ |
||
34 | 34 | */ |
35 | 35 | class ElggInstaller { |
36 | 36 | |
37 | - private $steps = [ |
|
38 | - 'welcome', |
|
39 | - 'requirements', |
|
40 | - 'database', |
|
41 | - 'settings', |
|
42 | - 'admin', |
|
43 | - 'complete', |
|
44 | - ]; |
|
45 | - |
|
46 | - private $has_completed = [ |
|
47 | - 'config' => false, |
|
48 | - 'database' => false, |
|
49 | - 'settings' => false, |
|
50 | - 'admin' => false, |
|
51 | - ]; |
|
52 | - |
|
53 | - private $is_action = false; |
|
54 | - |
|
55 | - private $autoLogin = true; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var ServiceProvider |
|
59 | - */ |
|
60 | - private $services; |
|
61 | - |
|
62 | - /** |
|
63 | - * @var Config |
|
64 | - */ |
|
65 | - private $config; |
|
66 | - |
|
67 | - /** |
|
68 | - * @var Application |
|
69 | - */ |
|
70 | - private $app; |
|
71 | - |
|
72 | - /** |
|
73 | - * Dispatches a request to one of the step controllers |
|
74 | - * |
|
75 | - * @return void |
|
76 | - * @throws InstallationException |
|
77 | - */ |
|
78 | - public function run() { |
|
79 | - $this->getApp(); |
|
80 | - |
|
81 | - $this->is_action = $this->services->request->getMethod() === 'POST'; |
|
82 | - |
|
83 | - $step = get_input('step', 'welcome'); |
|
84 | - |
|
85 | - if (!in_array($step, $this->getSteps())) { |
|
86 | - $msg = elgg_echo('InstallationException:UnknownStep', [$step]); |
|
87 | - throw new InstallationException($msg); |
|
88 | - } |
|
89 | - |
|
90 | - $this->determineInstallStatus(); |
|
37 | + private $steps = [ |
|
38 | + 'welcome', |
|
39 | + 'requirements', |
|
40 | + 'database', |
|
41 | + 'settings', |
|
42 | + 'admin', |
|
43 | + 'complete', |
|
44 | + ]; |
|
45 | + |
|
46 | + private $has_completed = [ |
|
47 | + 'config' => false, |
|
48 | + 'database' => false, |
|
49 | + 'settings' => false, |
|
50 | + 'admin' => false, |
|
51 | + ]; |
|
52 | + |
|
53 | + private $is_action = false; |
|
54 | + |
|
55 | + private $autoLogin = true; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var ServiceProvider |
|
59 | + */ |
|
60 | + private $services; |
|
61 | + |
|
62 | + /** |
|
63 | + * @var Config |
|
64 | + */ |
|
65 | + private $config; |
|
66 | + |
|
67 | + /** |
|
68 | + * @var Application |
|
69 | + */ |
|
70 | + private $app; |
|
71 | + |
|
72 | + /** |
|
73 | + * Dispatches a request to one of the step controllers |
|
74 | + * |
|
75 | + * @return void |
|
76 | + * @throws InstallationException |
|
77 | + */ |
|
78 | + public function run() { |
|
79 | + $this->getApp(); |
|
80 | + |
|
81 | + $this->is_action = $this->services->request->getMethod() === 'POST'; |
|
82 | + |
|
83 | + $step = get_input('step', 'welcome'); |
|
84 | + |
|
85 | + if (!in_array($step, $this->getSteps())) { |
|
86 | + $msg = elgg_echo('InstallationException:UnknownStep', [$step]); |
|
87 | + throw new InstallationException($msg); |
|
88 | + } |
|
89 | + |
|
90 | + $this->determineInstallStatus(); |
|
91 | 91 | |
92 | - $this->checkInstallCompletion($step); |
|
93 | - |
|
94 | - // check if this is an install being resumed |
|
95 | - $this->resumeInstall($step); |
|
96 | - |
|
97 | - $this->finishBootstrapping($step); |
|
98 | - |
|
99 | - $params = $this->services->request->request->all(); |
|
100 | - |
|
101 | - $method = "run" . ucwords($step); |
|
102 | - $this->$method($params); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Build the application needed by the installer |
|
107 | - * |
|
108 | - * @return Application |
|
109 | - * @throws InstallationException |
|
110 | - */ |
|
111 | - protected function getApp() { |
|
112 | - if ($this->app) { |
|
113 | - return $this->app; |
|
114 | - } |
|
115 | - |
|
116 | - $config = new Config(); |
|
117 | - $config->elgg_config_locks = false; |
|
118 | - $config->installer_running = true; |
|
119 | - $config->dbencoding = 'utf8mb4'; |
|
120 | - |
|
121 | - $this->config = $config; |
|
122 | - $this->services = new ServiceProvider($config); |
|
123 | - |
|
124 | - $app = Application::factory([ |
|
125 | - 'service_provider' => $this->services, |
|
126 | - 'handle_exceptions' => false, |
|
127 | - 'handle_shutdown' => false, |
|
128 | - |
|
129 | - // allows settings.php to be loaded, which might try to write to global $CONFIG |
|
130 | - // which is only a problem due to the config values that deep-write to arrays, |
|
131 | - // like cookies. |
|
132 | - 'overwrite_global_config' => false, |
|
133 | - ]); |
|
134 | - $app->loadCore(); |
|
135 | - $this->app = $app; |
|
136 | - |
|
137 | - $this->services->setValue('session', \ElggSession::getMock()); |
|
138 | - $this->services->views->setViewtype('installation'); |
|
139 | - $this->services->views->registerPluginViews(Paths::elgg()); |
|
140 | - $this->services->translator->registerTranslations(Paths::elgg() . "install/languages/", true); |
|
141 | - |
|
142 | - return $this->app; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Set the auto login flag |
|
147 | - * |
|
148 | - * @param bool $flag Auto login |
|
149 | - * |
|
150 | - * @return void |
|
151 | - */ |
|
152 | - public function setAutoLogin($flag) { |
|
153 | - $this->autoLogin = (bool) $flag; |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * A batch install of Elgg |
|
158 | - * |
|
159 | - * All required parameters must be passed in as an associative array. See |
|
160 | - * $requiredParams for a list of them. This creates the necessary files, |
|
161 | - * loads the database, configures the site settings, and creates the admin |
|
162 | - * account. If it fails, an exception is thrown. It does not check any of |
|
163 | - * the requirements as the multiple step web installer does. |
|
164 | - * |
|
165 | - * @param array $params Array of key value pairs |
|
166 | - * @param bool $create_htaccess Should .htaccess be created |
|
167 | - * |
|
168 | - * @return void |
|
169 | - * @throws InstallationException |
|
170 | - */ |
|
171 | - public function batchInstall(array $params, $create_htaccess = false) { |
|
172 | - $this->getApp(); |
|
173 | - |
|
174 | - $defaults = [ |
|
175 | - 'dbhost' => 'localhost', |
|
176 | - 'dbprefix' => 'elgg_', |
|
177 | - 'language' => 'en', |
|
178 | - 'siteaccess' => ACCESS_PUBLIC, |
|
179 | - ]; |
|
180 | - $params = array_merge($defaults, $params); |
|
181 | - |
|
182 | - $required_params = [ |
|
183 | - 'dbuser', |
|
184 | - 'dbpassword', |
|
185 | - 'dbname', |
|
186 | - 'sitename', |
|
187 | - 'wwwroot', |
|
188 | - 'dataroot', |
|
189 | - 'displayname', |
|
190 | - 'email', |
|
191 | - 'username', |
|
192 | - 'password', |
|
193 | - ]; |
|
194 | - foreach ($required_params as $key) { |
|
195 | - if (empty($params[$key])) { |
|
196 | - $msg = elgg_echo('install:error:requiredfield', [$key]); |
|
197 | - throw new InstallationException($msg); |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - // password is passed in once |
|
202 | - $params['password1'] = $params['password2'] = $params['password']; |
|
203 | - |
|
204 | - if ($create_htaccess) { |
|
205 | - $rewrite_tester = new ElggRewriteTester(); |
|
206 | - if (!$rewrite_tester->createHtaccess($params['wwwroot'])) { |
|
207 | - throw new InstallationException(elgg_echo('install:error:htaccess')); |
|
208 | - } |
|
209 | - } |
|
210 | - |
|
211 | - $this->determineInstallStatus(); |
|
212 | - |
|
213 | - if (!$this->has_completed['config']) { |
|
214 | - if (!$this->createSettingsFile($params)) { |
|
215 | - throw new InstallationException(elgg_echo('install:error:settings')); |
|
216 | - } |
|
217 | - } |
|
218 | - |
|
219 | - $this->loadSettingsFile(); |
|
220 | - |
|
221 | - // Make sure settings file matches parameters |
|
222 | - $config = $this->config; |
|
223 | - $config_keys = [ |
|
224 | - // param key => config key |
|
225 | - 'dbhost' => 'dbhost', |
|
226 | - 'dbuser' => 'dbuser', |
|
227 | - 'dbpassword' => 'dbpass', |
|
228 | - 'dbname' => 'dbname', |
|
229 | - 'dataroot' => 'dataroot', |
|
230 | - 'dbprefix' => 'dbprefix', |
|
231 | - ]; |
|
232 | - foreach ($config_keys as $params_key => $config_key) { |
|
233 | - if ($params[$params_key] !== $config->$config_key) { |
|
234 | - throw new InstallationException(elgg_echo('install:error:settings_mismatch', [$config_key])); |
|
235 | - } |
|
236 | - } |
|
237 | - |
|
238 | - if (!$this->connectToDatabase()) { |
|
239 | - throw new InstallationException(elgg_echo('install:error:databasesettings')); |
|
240 | - } |
|
241 | - |
|
242 | - if (!$this->has_completed['database']) { |
|
243 | - if (!$this->installDatabase()) { |
|
244 | - throw new InstallationException(elgg_echo('install:error:cannotloadtables')); |
|
245 | - } |
|
246 | - } |
|
247 | - |
|
248 | - // load remaining core libraries |
|
249 | - $this->finishBootstrapping('settings'); |
|
250 | - |
|
251 | - if (!$this->saveSiteSettings($params)) { |
|
252 | - throw new InstallationException(elgg_echo('install:error:savesitesettings')); |
|
253 | - } |
|
254 | - |
|
255 | - if (!$this->createAdminAccount($params)) { |
|
256 | - throw new InstallationException(elgg_echo('install:admin:cannot_create')); |
|
257 | - } |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Renders the data passed by a controller |
|
262 | - * |
|
263 | - * @param string $step The current step |
|
264 | - * @param array $vars Array of vars to pass to the view |
|
265 | - * |
|
266 | - * @return void |
|
267 | - */ |
|
268 | - protected function render($step, $vars = []) { |
|
269 | - $vars['next_step'] = $this->getNextStep($step); |
|
270 | - |
|
271 | - $title = elgg_echo("install:$step"); |
|
272 | - $body = elgg_view("install/pages/$step", $vars); |
|
92 | + $this->checkInstallCompletion($step); |
|
93 | + |
|
94 | + // check if this is an install being resumed |
|
95 | + $this->resumeInstall($step); |
|
96 | + |
|
97 | + $this->finishBootstrapping($step); |
|
98 | + |
|
99 | + $params = $this->services->request->request->all(); |
|
100 | + |
|
101 | + $method = "run" . ucwords($step); |
|
102 | + $this->$method($params); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Build the application needed by the installer |
|
107 | + * |
|
108 | + * @return Application |
|
109 | + * @throws InstallationException |
|
110 | + */ |
|
111 | + protected function getApp() { |
|
112 | + if ($this->app) { |
|
113 | + return $this->app; |
|
114 | + } |
|
115 | + |
|
116 | + $config = new Config(); |
|
117 | + $config->elgg_config_locks = false; |
|
118 | + $config->installer_running = true; |
|
119 | + $config->dbencoding = 'utf8mb4'; |
|
120 | + |
|
121 | + $this->config = $config; |
|
122 | + $this->services = new ServiceProvider($config); |
|
123 | + |
|
124 | + $app = Application::factory([ |
|
125 | + 'service_provider' => $this->services, |
|
126 | + 'handle_exceptions' => false, |
|
127 | + 'handle_shutdown' => false, |
|
128 | + |
|
129 | + // allows settings.php to be loaded, which might try to write to global $CONFIG |
|
130 | + // which is only a problem due to the config values that deep-write to arrays, |
|
131 | + // like cookies. |
|
132 | + 'overwrite_global_config' => false, |
|
133 | + ]); |
|
134 | + $app->loadCore(); |
|
135 | + $this->app = $app; |
|
136 | + |
|
137 | + $this->services->setValue('session', \ElggSession::getMock()); |
|
138 | + $this->services->views->setViewtype('installation'); |
|
139 | + $this->services->views->registerPluginViews(Paths::elgg()); |
|
140 | + $this->services->translator->registerTranslations(Paths::elgg() . "install/languages/", true); |
|
141 | + |
|
142 | + return $this->app; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Set the auto login flag |
|
147 | + * |
|
148 | + * @param bool $flag Auto login |
|
149 | + * |
|
150 | + * @return void |
|
151 | + */ |
|
152 | + public function setAutoLogin($flag) { |
|
153 | + $this->autoLogin = (bool) $flag; |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * A batch install of Elgg |
|
158 | + * |
|
159 | + * All required parameters must be passed in as an associative array. See |
|
160 | + * $requiredParams for a list of them. This creates the necessary files, |
|
161 | + * loads the database, configures the site settings, and creates the admin |
|
162 | + * account. If it fails, an exception is thrown. It does not check any of |
|
163 | + * the requirements as the multiple step web installer does. |
|
164 | + * |
|
165 | + * @param array $params Array of key value pairs |
|
166 | + * @param bool $create_htaccess Should .htaccess be created |
|
167 | + * |
|
168 | + * @return void |
|
169 | + * @throws InstallationException |
|
170 | + */ |
|
171 | + public function batchInstall(array $params, $create_htaccess = false) { |
|
172 | + $this->getApp(); |
|
173 | + |
|
174 | + $defaults = [ |
|
175 | + 'dbhost' => 'localhost', |
|
176 | + 'dbprefix' => 'elgg_', |
|
177 | + 'language' => 'en', |
|
178 | + 'siteaccess' => ACCESS_PUBLIC, |
|
179 | + ]; |
|
180 | + $params = array_merge($defaults, $params); |
|
181 | + |
|
182 | + $required_params = [ |
|
183 | + 'dbuser', |
|
184 | + 'dbpassword', |
|
185 | + 'dbname', |
|
186 | + 'sitename', |
|
187 | + 'wwwroot', |
|
188 | + 'dataroot', |
|
189 | + 'displayname', |
|
190 | + 'email', |
|
191 | + 'username', |
|
192 | + 'password', |
|
193 | + ]; |
|
194 | + foreach ($required_params as $key) { |
|
195 | + if (empty($params[$key])) { |
|
196 | + $msg = elgg_echo('install:error:requiredfield', [$key]); |
|
197 | + throw new InstallationException($msg); |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + // password is passed in once |
|
202 | + $params['password1'] = $params['password2'] = $params['password']; |
|
203 | + |
|
204 | + if ($create_htaccess) { |
|
205 | + $rewrite_tester = new ElggRewriteTester(); |
|
206 | + if (!$rewrite_tester->createHtaccess($params['wwwroot'])) { |
|
207 | + throw new InstallationException(elgg_echo('install:error:htaccess')); |
|
208 | + } |
|
209 | + } |
|
210 | + |
|
211 | + $this->determineInstallStatus(); |
|
212 | + |
|
213 | + if (!$this->has_completed['config']) { |
|
214 | + if (!$this->createSettingsFile($params)) { |
|
215 | + throw new InstallationException(elgg_echo('install:error:settings')); |
|
216 | + } |
|
217 | + } |
|
218 | + |
|
219 | + $this->loadSettingsFile(); |
|
220 | + |
|
221 | + // Make sure settings file matches parameters |
|
222 | + $config = $this->config; |
|
223 | + $config_keys = [ |
|
224 | + // param key => config key |
|
225 | + 'dbhost' => 'dbhost', |
|
226 | + 'dbuser' => 'dbuser', |
|
227 | + 'dbpassword' => 'dbpass', |
|
228 | + 'dbname' => 'dbname', |
|
229 | + 'dataroot' => 'dataroot', |
|
230 | + 'dbprefix' => 'dbprefix', |
|
231 | + ]; |
|
232 | + foreach ($config_keys as $params_key => $config_key) { |
|
233 | + if ($params[$params_key] !== $config->$config_key) { |
|
234 | + throw new InstallationException(elgg_echo('install:error:settings_mismatch', [$config_key])); |
|
235 | + } |
|
236 | + } |
|
237 | + |
|
238 | + if (!$this->connectToDatabase()) { |
|
239 | + throw new InstallationException(elgg_echo('install:error:databasesettings')); |
|
240 | + } |
|
241 | + |
|
242 | + if (!$this->has_completed['database']) { |
|
243 | + if (!$this->installDatabase()) { |
|
244 | + throw new InstallationException(elgg_echo('install:error:cannotloadtables')); |
|
245 | + } |
|
246 | + } |
|
247 | + |
|
248 | + // load remaining core libraries |
|
249 | + $this->finishBootstrapping('settings'); |
|
250 | + |
|
251 | + if (!$this->saveSiteSettings($params)) { |
|
252 | + throw new InstallationException(elgg_echo('install:error:savesitesettings')); |
|
253 | + } |
|
254 | + |
|
255 | + if (!$this->createAdminAccount($params)) { |
|
256 | + throw new InstallationException(elgg_echo('install:admin:cannot_create')); |
|
257 | + } |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Renders the data passed by a controller |
|
262 | + * |
|
263 | + * @param string $step The current step |
|
264 | + * @param array $vars Array of vars to pass to the view |
|
265 | + * |
|
266 | + * @return void |
|
267 | + */ |
|
268 | + protected function render($step, $vars = []) { |
|
269 | + $vars['next_step'] = $this->getNextStep($step); |
|
270 | + |
|
271 | + $title = elgg_echo("install:$step"); |
|
272 | + $body = elgg_view("install/pages/$step", $vars); |
|
273 | 273 | |
274 | - echo elgg_view_page( |
|
275 | - $title, |
|
276 | - $body, |
|
277 | - 'default', |
|
278 | - [ |
|
279 | - 'step' => $step, |
|
280 | - 'steps' => $this->getSteps(), |
|
281 | - ] |
|
282 | - ); |
|
283 | - exit; |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * Step controllers |
|
288 | - */ |
|
289 | - |
|
290 | - /** |
|
291 | - * Welcome controller |
|
292 | - * |
|
293 | - * @param array $vars Not used |
|
294 | - * |
|
295 | - * @return void |
|
296 | - */ |
|
297 | - protected function runWelcome($vars) { |
|
298 | - $this->render('welcome'); |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * Requirements controller |
|
303 | - * |
|
304 | - * Checks version of php, libraries, permissions, and rewrite rules |
|
305 | - * |
|
306 | - * @param array $vars Vars |
|
307 | - * |
|
308 | - * @return void |
|
309 | - */ |
|
310 | - protected function runRequirements($vars) { |
|
311 | - |
|
312 | - $report = []; |
|
313 | - |
|
314 | - // check PHP parameters and libraries |
|
315 | - $this->checkPHP($report); |
|
316 | - |
|
317 | - // check URL rewriting |
|
318 | - $this->checkRewriteRules($report); |
|
319 | - |
|
320 | - // check for existence of settings file |
|
321 | - if ($this->checkSettingsFile($report) != true) { |
|
322 | - // no file, so check permissions on engine directory |
|
323 | - $this->isInstallDirWritable($report); |
|
324 | - } |
|
325 | - |
|
326 | - // check the database later |
|
327 | - $report['database'] = [[ |
|
328 | - 'severity' => 'info', |
|
329 | - 'message' => elgg_echo('install:check:database') |
|
330 | - ]]; |
|
331 | - |
|
332 | - // any failures? |
|
333 | - $numFailures = $this->countNumConditions($report, 'failure'); |
|
334 | - |
|
335 | - // any warnings |
|
336 | - $numWarnings = $this->countNumConditions($report, 'warning'); |
|
337 | - |
|
338 | - |
|
339 | - $params = [ |
|
340 | - 'report' => $report, |
|
341 | - 'num_failures' => $numFailures, |
|
342 | - 'num_warnings' => $numWarnings, |
|
343 | - ]; |
|
344 | - |
|
345 | - $this->render('requirements', $params); |
|
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * Database set up controller |
|
350 | - * |
|
351 | - * Creates the settings.php file and creates the database tables |
|
352 | - * |
|
353 | - * @param array $submissionVars Submitted form variables |
|
354 | - * |
|
355 | - * @return void |
|
356 | - */ |
|
357 | - protected function runDatabase($submissionVars) { |
|
358 | - |
|
359 | - $formVars = [ |
|
360 | - 'dbuser' => [ |
|
361 | - 'type' => 'text', |
|
362 | - 'value' => '', |
|
363 | - 'required' => true, |
|
364 | - ], |
|
365 | - 'dbpassword' => [ |
|
366 | - 'type' => 'password', |
|
367 | - 'value' => '', |
|
368 | - 'required' => false, |
|
369 | - ], |
|
370 | - 'dbname' => [ |
|
371 | - 'type' => 'text', |
|
372 | - 'value' => '', |
|
373 | - 'required' => true, |
|
374 | - ], |
|
375 | - 'dbhost' => [ |
|
376 | - 'type' => 'text', |
|
377 | - 'value' => 'localhost', |
|
378 | - 'required' => true, |
|
379 | - ], |
|
380 | - 'dbprefix' => [ |
|
381 | - 'type' => 'text', |
|
382 | - 'value' => 'elgg_', |
|
383 | - 'required' => true, |
|
384 | - ], |
|
385 | - 'dataroot' => [ |
|
386 | - 'type' => 'text', |
|
387 | - 'value' => '', |
|
388 | - 'required' => true, |
|
389 | - ], |
|
390 | - 'wwwroot' => [ |
|
391 | - 'type' => 'url', |
|
392 | - 'value' => _elgg_services()->config->wwwroot, |
|
393 | - 'required' => true, |
|
394 | - ], |
|
395 | - 'timezone' => [ |
|
396 | - 'type' => 'dropdown', |
|
397 | - 'value' => 'UTC', |
|
398 | - 'options' => \DateTimeZone::listIdentifiers(), |
|
399 | - 'required' => true |
|
400 | - ] |
|
401 | - ]; |
|
402 | - |
|
403 | - if ($this->checkSettingsFile()) { |
|
404 | - // user manually created settings file so we fake out action test |
|
405 | - $this->is_action = true; |
|
406 | - } |
|
407 | - |
|
408 | - if ($this->is_action) { |
|
409 | - call_user_func(function () use ($submissionVars, $formVars) { |
|
410 | - // only create settings file if it doesn't exist |
|
411 | - if (!$this->checkSettingsFile()) { |
|
412 | - if (!$this->validateDatabaseVars($submissionVars, $formVars)) { |
|
413 | - // error so we break out of action and serve same page |
|
414 | - return; |
|
415 | - } |
|
416 | - |
|
417 | - if (!$this->createSettingsFile($submissionVars)) { |
|
418 | - return; |
|
419 | - } |
|
420 | - } |
|
421 | - |
|
422 | - // check db version and connect |
|
423 | - if (!$this->connectToDatabase()) { |
|
424 | - return; |
|
425 | - } |
|
426 | - |
|
427 | - if (!$this->installDatabase()) { |
|
428 | - return; |
|
429 | - } |
|
430 | - |
|
431 | - system_message(elgg_echo('install:success:database')); |
|
432 | - |
|
433 | - $this->continueToNextStep('database'); |
|
434 | - }); |
|
435 | - } |
|
436 | - |
|
437 | - $formVars = $this->makeFormSticky($formVars, $submissionVars); |
|
438 | - |
|
439 | - $params = ['variables' => $formVars,]; |
|
440 | - |
|
441 | - if ($this->checkSettingsFile()) { |
|
442 | - // settings file exists and we're here so failed to create database |
|
443 | - $params['failure'] = true; |
|
444 | - } |
|
445 | - |
|
446 | - $this->render('database', $params); |
|
447 | - } |
|
448 | - |
|
449 | - /** |
|
450 | - * Site settings controller |
|
451 | - * |
|
452 | - * Sets the site name, URL, data directory, etc. |
|
453 | - * |
|
454 | - * @param array $submissionVars Submitted vars |
|
455 | - * |
|
456 | - * @return void |
|
457 | - */ |
|
458 | - protected function runSettings($submissionVars) { |
|
459 | - $formVars = [ |
|
460 | - 'sitename' => [ |
|
461 | - 'type' => 'text', |
|
462 | - 'value' => 'My New Community', |
|
463 | - 'required' => true, |
|
464 | - ], |
|
465 | - 'siteemail' => [ |
|
466 | - 'type' => 'email', |
|
467 | - 'value' => '', |
|
468 | - 'required' => false, |
|
469 | - ], |
|
470 | - 'siteaccess' => [ |
|
471 | - 'type' => 'access', |
|
472 | - 'value' => ACCESS_PUBLIC, |
|
473 | - 'required' => true, |
|
474 | - ], |
|
475 | - ]; |
|
476 | - |
|
477 | - if ($this->is_action) { |
|
478 | - call_user_func(function () use ($submissionVars, $formVars) { |
|
479 | - if (!$this->validateSettingsVars($submissionVars, $formVars)) { |
|
480 | - return; |
|
481 | - } |
|
482 | - |
|
483 | - if (!$this->saveSiteSettings($submissionVars)) { |
|
484 | - return; |
|
485 | - } |
|
486 | - |
|
487 | - system_message(elgg_echo('install:success:settings')); |
|
488 | - |
|
489 | - $this->continueToNextStep('settings'); |
|
490 | - }); |
|
491 | - } |
|
492 | - |
|
493 | - $formVars = $this->makeFormSticky($formVars, $submissionVars); |
|
494 | - |
|
495 | - $this->render('settings', ['variables' => $formVars]); |
|
496 | - } |
|
497 | - |
|
498 | - /** |
|
499 | - * Admin account controller |
|
500 | - * |
|
501 | - * Creates an admin user account |
|
502 | - * |
|
503 | - * @param array $submissionVars Submitted vars |
|
504 | - * |
|
505 | - * @return void |
|
506 | - */ |
|
507 | - protected function runAdmin($submissionVars) { |
|
508 | - $formVars = [ |
|
509 | - 'displayname' => [ |
|
510 | - 'type' => 'text', |
|
511 | - 'value' => '', |
|
512 | - 'required' => true, |
|
513 | - ], |
|
514 | - 'email' => [ |
|
515 | - 'type' => 'email', |
|
516 | - 'value' => '', |
|
517 | - 'required' => true, |
|
518 | - ], |
|
519 | - 'username' => [ |
|
520 | - 'type' => 'text', |
|
521 | - 'value' => '', |
|
522 | - 'required' => true, |
|
523 | - ], |
|
524 | - 'password1' => [ |
|
525 | - 'type' => 'password', |
|
526 | - 'value' => '', |
|
527 | - 'required' => true, |
|
528 | - 'pattern' => '.{6,}', |
|
529 | - ], |
|
530 | - 'password2' => [ |
|
531 | - 'type' => 'password', |
|
532 | - 'value' => '', |
|
533 | - 'required' => true, |
|
534 | - ], |
|
535 | - ]; |
|
536 | - |
|
537 | - if ($this->is_action) { |
|
538 | - call_user_func(function () use ($submissionVars, $formVars) { |
|
539 | - if (!$this->validateAdminVars($submissionVars, $formVars)) { |
|
540 | - return; |
|
541 | - } |
|
542 | - |
|
543 | - if (!$this->createAdminAccount($submissionVars, $this->autoLogin)) { |
|
544 | - return; |
|
545 | - } |
|
546 | - |
|
547 | - system_message(elgg_echo('install:success:admin')); |
|
548 | - |
|
549 | - $this->continueToNextStep('admin'); |
|
550 | - }); |
|
551 | - } |
|
552 | - |
|
553 | - // Bit of a hack to get the password help to show right number of characters |
|
554 | - // We burn the value into the stored translation. |
|
555 | - $lang = $this->services->translator->getCurrentLanguage(); |
|
556 | - $translations = $this->services->translator->getLoadedTranslations(); |
|
557 | - $this->services->translator->addTranslation($lang, [ |
|
558 | - 'install:admin:help:password1' => sprintf( |
|
559 | - $translations[$lang]['install:admin:help:password1'], |
|
560 | - $this->config->min_password_length |
|
561 | - ), |
|
562 | - ]); |
|
563 | - |
|
564 | - $formVars = $this->makeFormSticky($formVars, $submissionVars); |
|
565 | - |
|
566 | - $this->render('admin', ['variables' => $formVars]); |
|
567 | - } |
|
568 | - |
|
569 | - /** |
|
570 | - * Controller for last step |
|
571 | - * |
|
572 | - * @return void |
|
573 | - */ |
|
574 | - protected function runComplete() { |
|
575 | - |
|
576 | - // nudge to check out settings |
|
577 | - $link = elgg_format_element([ |
|
578 | - '#tag_name' => 'a', |
|
579 | - '#text' => elgg_echo('install:complete:admin_notice:link_text'), |
|
580 | - 'href' => elgg_normalize_url('admin/settings/basic'), |
|
581 | - ]); |
|
582 | - $notice = elgg_echo('install:complete:admin_notice', [$link]); |
|
583 | - elgg_add_admin_notice('fresh_install', $notice); |
|
584 | - |
|
585 | - $this->render('complete'); |
|
586 | - } |
|
587 | - |
|
588 | - /** |
|
589 | - * Step management |
|
590 | - */ |
|
591 | - |
|
592 | - /** |
|
593 | - * Get an array of steps |
|
594 | - * |
|
595 | - * @return array |
|
596 | - */ |
|
597 | - protected function getSteps() { |
|
598 | - return $this->steps; |
|
599 | - } |
|
600 | - |
|
601 | - /** |
|
602 | - * Forwards the browser to the next step |
|
603 | - * |
|
604 | - * @param string $currentStep Current installation step |
|
605 | - * |
|
606 | - * @return void |
|
607 | - */ |
|
608 | - protected function continueToNextStep($currentStep) { |
|
609 | - $this->is_action = false; |
|
610 | - forward($this->getNextStepUrl($currentStep)); |
|
611 | - } |
|
612 | - |
|
613 | - /** |
|
614 | - * Get the next step as a string |
|
615 | - * |
|
616 | - * @param string $currentStep Current installation step |
|
617 | - * |
|
618 | - * @return string |
|
619 | - */ |
|
620 | - protected function getNextStep($currentStep) { |
|
621 | - $index = 1 + array_search($currentStep, $this->steps); |
|
622 | - if (isset($this->steps[$index])) { |
|
623 | - return $this->steps[$index]; |
|
624 | - } else { |
|
625 | - return null; |
|
626 | - } |
|
627 | - } |
|
628 | - |
|
629 | - /** |
|
630 | - * Get the URL of the next step |
|
631 | - * |
|
632 | - * @param string $currentStep Current installation step |
|
633 | - * |
|
634 | - * @return string |
|
635 | - */ |
|
636 | - protected function getNextStepUrl($currentStep) { |
|
637 | - $nextStep = $this->getNextStep($currentStep); |
|
638 | - return $this->config->wwwroot . "install.php?step=$nextStep"; |
|
639 | - } |
|
640 | - |
|
641 | - /** |
|
642 | - * Updates $this->has_completed according to the current installation |
|
643 | - * |
|
644 | - * @return void |
|
645 | - * @throws InstallationException |
|
646 | - */ |
|
647 | - protected function determineInstallStatus() { |
|
648 | - $path = Paths::settingsFile(); |
|
649 | - if (!is_file($path) || !is_readable($path)) { |
|
650 | - return; |
|
651 | - } |
|
652 | - |
|
653 | - $this->loadSettingsFile(); |
|
654 | - |
|
655 | - $this->has_completed['config'] = true; |
|
656 | - |
|
657 | - // must be able to connect to database to jump install steps |
|
658 | - $dbSettingsPass = $this->checkDatabaseSettings( |
|
659 | - $this->config->dbuser, |
|
660 | - $this->config->dbpass, |
|
661 | - $this->config->dbname, |
|
662 | - $this->config->dbhost |
|
663 | - ); |
|
664 | - |
|
665 | - if (!$dbSettingsPass) { |
|
666 | - return; |
|
667 | - } |
|
668 | - |
|
669 | - $db = $this->services->db; |
|
670 | - |
|
671 | - // check that the config table has been created |
|
672 | - $result = $db->getData("SHOW TABLES"); |
|
673 | - if ($result) { |
|
674 | - foreach ($result as $table) { |
|
675 | - $table = (array) $table; |
|
676 | - if (in_array("{$db->prefix}config", $table)) { |
|
677 | - $this->has_completed['database'] = true; |
|
678 | - } |
|
679 | - } |
|
680 | - if ($this->has_completed['database'] == false) { |
|
681 | - return; |
|
682 | - } |
|
683 | - } else { |
|
684 | - // no tables |
|
685 | - return; |
|
686 | - } |
|
687 | - |
|
688 | - // check that the config table has entries |
|
689 | - $query = "SELECT COUNT(*) AS total FROM {$db->prefix}config"; |
|
690 | - $result = $db->getData($query); |
|
691 | - if ($result && $result[0]->total > 0) { |
|
692 | - $this->has_completed['settings'] = true; |
|
693 | - } else { |
|
694 | - return; |
|
695 | - } |
|
696 | - |
|
697 | - // check that the users entity table has an entry |
|
698 | - $query = "SELECT COUNT(*) AS total FROM {$db->prefix}users_entity"; |
|
699 | - $result = $db->getData($query); |
|
700 | - if ($result && $result[0]->total > 0) { |
|
701 | - $this->has_completed['admin'] = true; |
|
702 | - } else { |
|
703 | - return; |
|
704 | - } |
|
705 | - } |
|
706 | - |
|
707 | - /** |
|
708 | - * Security check to ensure the installer cannot be run after installation |
|
709 | - * has finished. If this is detected, the viewer is sent to the front page. |
|
710 | - * |
|
711 | - * @param string $step Installation step to check against |
|
712 | - * |
|
713 | - * @return void |
|
714 | - */ |
|
715 | - protected function checkInstallCompletion($step) { |
|
716 | - if ($step != 'complete') { |
|
717 | - if (!in_array(false, $this->has_completed)) { |
|
718 | - // install complete but someone is trying to view an install page |
|
719 | - forward(); |
|
720 | - } |
|
721 | - } |
|
722 | - } |
|
723 | - |
|
724 | - /** |
|
725 | - * Check if this is a case of a install being resumed and figure |
|
726 | - * out where to continue from. Returns the best guess on the step. |
|
727 | - * |
|
728 | - * @param string $step Installation step to resume from |
|
729 | - * |
|
730 | - * @return string |
|
731 | - */ |
|
732 | - protected function resumeInstall($step) { |
|
733 | - // only do a resume from the first step |
|
734 | - if ($step !== 'welcome') { |
|
735 | - return; |
|
736 | - } |
|
737 | - |
|
738 | - if ($this->has_completed['database'] == false) { |
|
739 | - return; |
|
740 | - } |
|
741 | - |
|
742 | - if ($this->has_completed['settings'] == false) { |
|
743 | - forward("install.php?step=settings"); |
|
744 | - } |
|
745 | - |
|
746 | - if ($this->has_completed['admin'] == false) { |
|
747 | - forward("install.php?step=admin"); |
|
748 | - } |
|
749 | - |
|
750 | - // everything appears to be set up |
|
751 | - forward("install.php?step=complete"); |
|
752 | - } |
|
753 | - |
|
754 | - /** |
|
755 | - * Bootstrapping |
|
756 | - */ |
|
757 | - |
|
758 | - /** |
|
759 | - * Load remaining engine libraries and complete bootstrapping |
|
760 | - * |
|
761 | - * @param string $step Which step to boot strap for. Required because |
|
762 | - * boot strapping is different until the DB is populated. |
|
763 | - * |
|
764 | - * @return void |
|
765 | - * @throws InstallationException |
|
766 | - */ |
|
767 | - protected function finishBootstrapping($step) { |
|
768 | - |
|
769 | - $index_db = array_search('database', $this->getSteps()); |
|
770 | - $index_settings = array_search('settings', $this->getSteps()); |
|
771 | - $index_admin = array_search('admin', $this->getSteps()); |
|
772 | - $index_complete = array_search('complete', $this->getSteps()); |
|
773 | - $index_step = array_search($step, $this->getSteps()); |
|
774 | - |
|
775 | - // To log in the user, we need to use the Elgg core session handling. |
|
776 | - // Otherwise, use default php session handling |
|
777 | - $use_elgg_session = ($index_step == $index_admin && $this->is_action) || ($index_step == $index_complete); |
|
778 | - if (!$use_elgg_session) { |
|
779 | - $session = ElggSession::fromFiles($this->config); |
|
780 | - $session->setName('Elgg_install'); |
|
781 | - $this->services->setValue('session', $session); |
|
782 | - } |
|
783 | - |
|
784 | - if ($index_step > $index_db) { |
|
785 | - // once the database has been created, load rest of engine |
|
786 | - |
|
787 | - // dummy site needed to boot |
|
788 | - $this->config->site = new ElggSite(); |
|
789 | - |
|
790 | - $this->app->bootCore(); |
|
791 | - } |
|
792 | - } |
|
793 | - |
|
794 | - /** |
|
795 | - * Load settings |
|
796 | - * |
|
797 | - * @return void |
|
798 | - * @throws InstallationException |
|
799 | - */ |
|
800 | - protected function loadSettingsFile() { |
|
801 | - try { |
|
802 | - $config = Config::fromFile(Paths::settingsFile()); |
|
803 | - $this->config->mergeValues($config->getValues()); |
|
804 | - |
|
805 | - // in case the DB instance is already captured in services, we re-inject its settings. |
|
806 | - $this->services->db->resetConnections(DbConfig::fromElggConfig($this->config)); |
|
807 | - } catch (\Exception $e) { |
|
808 | - $msg = elgg_echo('InstallationException:CannotLoadSettings'); |
|
809 | - throw new InstallationException($msg, 0, $e); |
|
810 | - } |
|
811 | - } |
|
812 | - |
|
813 | - /** |
|
814 | - * Action handling methods |
|
815 | - */ |
|
816 | - |
|
817 | - /** |
|
818 | - * If form is reshown, remember previously submitted variables |
|
819 | - * |
|
820 | - * @param array $formVars Vars int he form |
|
821 | - * @param array $submissionVars Submitted vars |
|
822 | - * |
|
823 | - * @return array |
|
824 | - */ |
|
825 | - protected function makeFormSticky($formVars, $submissionVars) { |
|
826 | - foreach ($submissionVars as $field => $value) { |
|
827 | - $formVars[$field]['value'] = $value; |
|
828 | - } |
|
829 | - return $formVars; |
|
830 | - } |
|
831 | - |
|
832 | - /* Requirement checks support methods */ |
|
833 | - |
|
834 | - /** |
|
835 | - * Indicates whether the webserver can add settings.php on its own or not. |
|
836 | - * |
|
837 | - * @param array $report The requirements report object |
|
838 | - * |
|
839 | - * @return bool |
|
840 | - */ |
|
841 | - protected function isInstallDirWritable(&$report) { |
|
842 | - if (!is_writable(Paths::projectConfig())) { |
|
843 | - $msg = elgg_echo('install:check:installdir', [Paths::PATH_TO_CONFIG]); |
|
844 | - $report['settings'] = [ |
|
845 | - [ |
|
846 | - 'severity' => 'failure', |
|
847 | - 'message' => $msg, |
|
848 | - ] |
|
849 | - ]; |
|
850 | - return false; |
|
851 | - } |
|
852 | - |
|
853 | - return true; |
|
854 | - } |
|
855 | - |
|
856 | - /** |
|
857 | - * Check that the settings file exists |
|
858 | - * |
|
859 | - * @param array $report The requirements report array |
|
860 | - * |
|
861 | - * @return bool |
|
862 | - */ |
|
863 | - protected function checkSettingsFile(&$report = []) { |
|
864 | - if (!is_file(Paths::settingsFile())) { |
|
865 | - return false; |
|
866 | - } |
|
867 | - |
|
868 | - if (!is_readable(Paths::settingsFile())) { |
|
869 | - $report['settings'] = [ |
|
870 | - [ |
|
871 | - 'severity' => 'failure', |
|
872 | - 'message' => elgg_echo('install:check:readsettings'), |
|
873 | - ] |
|
874 | - ]; |
|
875 | - } |
|
274 | + echo elgg_view_page( |
|
275 | + $title, |
|
276 | + $body, |
|
277 | + 'default', |
|
278 | + [ |
|
279 | + 'step' => $step, |
|
280 | + 'steps' => $this->getSteps(), |
|
281 | + ] |
|
282 | + ); |
|
283 | + exit; |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * Step controllers |
|
288 | + */ |
|
289 | + |
|
290 | + /** |
|
291 | + * Welcome controller |
|
292 | + * |
|
293 | + * @param array $vars Not used |
|
294 | + * |
|
295 | + * @return void |
|
296 | + */ |
|
297 | + protected function runWelcome($vars) { |
|
298 | + $this->render('welcome'); |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * Requirements controller |
|
303 | + * |
|
304 | + * Checks version of php, libraries, permissions, and rewrite rules |
|
305 | + * |
|
306 | + * @param array $vars Vars |
|
307 | + * |
|
308 | + * @return void |
|
309 | + */ |
|
310 | + protected function runRequirements($vars) { |
|
311 | + |
|
312 | + $report = []; |
|
313 | + |
|
314 | + // check PHP parameters and libraries |
|
315 | + $this->checkPHP($report); |
|
316 | + |
|
317 | + // check URL rewriting |
|
318 | + $this->checkRewriteRules($report); |
|
319 | + |
|
320 | + // check for existence of settings file |
|
321 | + if ($this->checkSettingsFile($report) != true) { |
|
322 | + // no file, so check permissions on engine directory |
|
323 | + $this->isInstallDirWritable($report); |
|
324 | + } |
|
325 | + |
|
326 | + // check the database later |
|
327 | + $report['database'] = [[ |
|
328 | + 'severity' => 'info', |
|
329 | + 'message' => elgg_echo('install:check:database') |
|
330 | + ]]; |
|
331 | + |
|
332 | + // any failures? |
|
333 | + $numFailures = $this->countNumConditions($report, 'failure'); |
|
334 | + |
|
335 | + // any warnings |
|
336 | + $numWarnings = $this->countNumConditions($report, 'warning'); |
|
337 | + |
|
338 | + |
|
339 | + $params = [ |
|
340 | + 'report' => $report, |
|
341 | + 'num_failures' => $numFailures, |
|
342 | + 'num_warnings' => $numWarnings, |
|
343 | + ]; |
|
344 | + |
|
345 | + $this->render('requirements', $params); |
|
346 | + } |
|
347 | + |
|
348 | + /** |
|
349 | + * Database set up controller |
|
350 | + * |
|
351 | + * Creates the settings.php file and creates the database tables |
|
352 | + * |
|
353 | + * @param array $submissionVars Submitted form variables |
|
354 | + * |
|
355 | + * @return void |
|
356 | + */ |
|
357 | + protected function runDatabase($submissionVars) { |
|
358 | + |
|
359 | + $formVars = [ |
|
360 | + 'dbuser' => [ |
|
361 | + 'type' => 'text', |
|
362 | + 'value' => '', |
|
363 | + 'required' => true, |
|
364 | + ], |
|
365 | + 'dbpassword' => [ |
|
366 | + 'type' => 'password', |
|
367 | + 'value' => '', |
|
368 | + 'required' => false, |
|
369 | + ], |
|
370 | + 'dbname' => [ |
|
371 | + 'type' => 'text', |
|
372 | + 'value' => '', |
|
373 | + 'required' => true, |
|
374 | + ], |
|
375 | + 'dbhost' => [ |
|
376 | + 'type' => 'text', |
|
377 | + 'value' => 'localhost', |
|
378 | + 'required' => true, |
|
379 | + ], |
|
380 | + 'dbprefix' => [ |
|
381 | + 'type' => 'text', |
|
382 | + 'value' => 'elgg_', |
|
383 | + 'required' => true, |
|
384 | + ], |
|
385 | + 'dataroot' => [ |
|
386 | + 'type' => 'text', |
|
387 | + 'value' => '', |
|
388 | + 'required' => true, |
|
389 | + ], |
|
390 | + 'wwwroot' => [ |
|
391 | + 'type' => 'url', |
|
392 | + 'value' => _elgg_services()->config->wwwroot, |
|
393 | + 'required' => true, |
|
394 | + ], |
|
395 | + 'timezone' => [ |
|
396 | + 'type' => 'dropdown', |
|
397 | + 'value' => 'UTC', |
|
398 | + 'options' => \DateTimeZone::listIdentifiers(), |
|
399 | + 'required' => true |
|
400 | + ] |
|
401 | + ]; |
|
402 | + |
|
403 | + if ($this->checkSettingsFile()) { |
|
404 | + // user manually created settings file so we fake out action test |
|
405 | + $this->is_action = true; |
|
406 | + } |
|
407 | + |
|
408 | + if ($this->is_action) { |
|
409 | + call_user_func(function () use ($submissionVars, $formVars) { |
|
410 | + // only create settings file if it doesn't exist |
|
411 | + if (!$this->checkSettingsFile()) { |
|
412 | + if (!$this->validateDatabaseVars($submissionVars, $formVars)) { |
|
413 | + // error so we break out of action and serve same page |
|
414 | + return; |
|
415 | + } |
|
416 | + |
|
417 | + if (!$this->createSettingsFile($submissionVars)) { |
|
418 | + return; |
|
419 | + } |
|
420 | + } |
|
421 | + |
|
422 | + // check db version and connect |
|
423 | + if (!$this->connectToDatabase()) { |
|
424 | + return; |
|
425 | + } |
|
426 | + |
|
427 | + if (!$this->installDatabase()) { |
|
428 | + return; |
|
429 | + } |
|
430 | + |
|
431 | + system_message(elgg_echo('install:success:database')); |
|
432 | + |
|
433 | + $this->continueToNextStep('database'); |
|
434 | + }); |
|
435 | + } |
|
436 | + |
|
437 | + $formVars = $this->makeFormSticky($formVars, $submissionVars); |
|
438 | + |
|
439 | + $params = ['variables' => $formVars,]; |
|
440 | + |
|
441 | + if ($this->checkSettingsFile()) { |
|
442 | + // settings file exists and we're here so failed to create database |
|
443 | + $params['failure'] = true; |
|
444 | + } |
|
445 | + |
|
446 | + $this->render('database', $params); |
|
447 | + } |
|
448 | + |
|
449 | + /** |
|
450 | + * Site settings controller |
|
451 | + * |
|
452 | + * Sets the site name, URL, data directory, etc. |
|
453 | + * |
|
454 | + * @param array $submissionVars Submitted vars |
|
455 | + * |
|
456 | + * @return void |
|
457 | + */ |
|
458 | + protected function runSettings($submissionVars) { |
|
459 | + $formVars = [ |
|
460 | + 'sitename' => [ |
|
461 | + 'type' => 'text', |
|
462 | + 'value' => 'My New Community', |
|
463 | + 'required' => true, |
|
464 | + ], |
|
465 | + 'siteemail' => [ |
|
466 | + 'type' => 'email', |
|
467 | + 'value' => '', |
|
468 | + 'required' => false, |
|
469 | + ], |
|
470 | + 'siteaccess' => [ |
|
471 | + 'type' => 'access', |
|
472 | + 'value' => ACCESS_PUBLIC, |
|
473 | + 'required' => true, |
|
474 | + ], |
|
475 | + ]; |
|
476 | + |
|
477 | + if ($this->is_action) { |
|
478 | + call_user_func(function () use ($submissionVars, $formVars) { |
|
479 | + if (!$this->validateSettingsVars($submissionVars, $formVars)) { |
|
480 | + return; |
|
481 | + } |
|
482 | + |
|
483 | + if (!$this->saveSiteSettings($submissionVars)) { |
|
484 | + return; |
|
485 | + } |
|
486 | + |
|
487 | + system_message(elgg_echo('install:success:settings')); |
|
488 | + |
|
489 | + $this->continueToNextStep('settings'); |
|
490 | + }); |
|
491 | + } |
|
492 | + |
|
493 | + $formVars = $this->makeFormSticky($formVars, $submissionVars); |
|
494 | + |
|
495 | + $this->render('settings', ['variables' => $formVars]); |
|
496 | + } |
|
497 | + |
|
498 | + /** |
|
499 | + * Admin account controller |
|
500 | + * |
|
501 | + * Creates an admin user account |
|
502 | + * |
|
503 | + * @param array $submissionVars Submitted vars |
|
504 | + * |
|
505 | + * @return void |
|
506 | + */ |
|
507 | + protected function runAdmin($submissionVars) { |
|
508 | + $formVars = [ |
|
509 | + 'displayname' => [ |
|
510 | + 'type' => 'text', |
|
511 | + 'value' => '', |
|
512 | + 'required' => true, |
|
513 | + ], |
|
514 | + 'email' => [ |
|
515 | + 'type' => 'email', |
|
516 | + 'value' => '', |
|
517 | + 'required' => true, |
|
518 | + ], |
|
519 | + 'username' => [ |
|
520 | + 'type' => 'text', |
|
521 | + 'value' => '', |
|
522 | + 'required' => true, |
|
523 | + ], |
|
524 | + 'password1' => [ |
|
525 | + 'type' => 'password', |
|
526 | + 'value' => '', |
|
527 | + 'required' => true, |
|
528 | + 'pattern' => '.{6,}', |
|
529 | + ], |
|
530 | + 'password2' => [ |
|
531 | + 'type' => 'password', |
|
532 | + 'value' => '', |
|
533 | + 'required' => true, |
|
534 | + ], |
|
535 | + ]; |
|
536 | + |
|
537 | + if ($this->is_action) { |
|
538 | + call_user_func(function () use ($submissionVars, $formVars) { |
|
539 | + if (!$this->validateAdminVars($submissionVars, $formVars)) { |
|
540 | + return; |
|
541 | + } |
|
542 | + |
|
543 | + if (!$this->createAdminAccount($submissionVars, $this->autoLogin)) { |
|
544 | + return; |
|
545 | + } |
|
546 | + |
|
547 | + system_message(elgg_echo('install:success:admin')); |
|
548 | + |
|
549 | + $this->continueToNextStep('admin'); |
|
550 | + }); |
|
551 | + } |
|
552 | + |
|
553 | + // Bit of a hack to get the password help to show right number of characters |
|
554 | + // We burn the value into the stored translation. |
|
555 | + $lang = $this->services->translator->getCurrentLanguage(); |
|
556 | + $translations = $this->services->translator->getLoadedTranslations(); |
|
557 | + $this->services->translator->addTranslation($lang, [ |
|
558 | + 'install:admin:help:password1' => sprintf( |
|
559 | + $translations[$lang]['install:admin:help:password1'], |
|
560 | + $this->config->min_password_length |
|
561 | + ), |
|
562 | + ]); |
|
563 | + |
|
564 | + $formVars = $this->makeFormSticky($formVars, $submissionVars); |
|
565 | + |
|
566 | + $this->render('admin', ['variables' => $formVars]); |
|
567 | + } |
|
568 | + |
|
569 | + /** |
|
570 | + * Controller for last step |
|
571 | + * |
|
572 | + * @return void |
|
573 | + */ |
|
574 | + protected function runComplete() { |
|
575 | + |
|
576 | + // nudge to check out settings |
|
577 | + $link = elgg_format_element([ |
|
578 | + '#tag_name' => 'a', |
|
579 | + '#text' => elgg_echo('install:complete:admin_notice:link_text'), |
|
580 | + 'href' => elgg_normalize_url('admin/settings/basic'), |
|
581 | + ]); |
|
582 | + $notice = elgg_echo('install:complete:admin_notice', [$link]); |
|
583 | + elgg_add_admin_notice('fresh_install', $notice); |
|
584 | + |
|
585 | + $this->render('complete'); |
|
586 | + } |
|
587 | + |
|
588 | + /** |
|
589 | + * Step management |
|
590 | + */ |
|
591 | + |
|
592 | + /** |
|
593 | + * Get an array of steps |
|
594 | + * |
|
595 | + * @return array |
|
596 | + */ |
|
597 | + protected function getSteps() { |
|
598 | + return $this->steps; |
|
599 | + } |
|
600 | + |
|
601 | + /** |
|
602 | + * Forwards the browser to the next step |
|
603 | + * |
|
604 | + * @param string $currentStep Current installation step |
|
605 | + * |
|
606 | + * @return void |
|
607 | + */ |
|
608 | + protected function continueToNextStep($currentStep) { |
|
609 | + $this->is_action = false; |
|
610 | + forward($this->getNextStepUrl($currentStep)); |
|
611 | + } |
|
612 | + |
|
613 | + /** |
|
614 | + * Get the next step as a string |
|
615 | + * |
|
616 | + * @param string $currentStep Current installation step |
|
617 | + * |
|
618 | + * @return string |
|
619 | + */ |
|
620 | + protected function getNextStep($currentStep) { |
|
621 | + $index = 1 + array_search($currentStep, $this->steps); |
|
622 | + if (isset($this->steps[$index])) { |
|
623 | + return $this->steps[$index]; |
|
624 | + } else { |
|
625 | + return null; |
|
626 | + } |
|
627 | + } |
|
628 | + |
|
629 | + /** |
|
630 | + * Get the URL of the next step |
|
631 | + * |
|
632 | + * @param string $currentStep Current installation step |
|
633 | + * |
|
634 | + * @return string |
|
635 | + */ |
|
636 | + protected function getNextStepUrl($currentStep) { |
|
637 | + $nextStep = $this->getNextStep($currentStep); |
|
638 | + return $this->config->wwwroot . "install.php?step=$nextStep"; |
|
639 | + } |
|
640 | + |
|
641 | + /** |
|
642 | + * Updates $this->has_completed according to the current installation |
|
643 | + * |
|
644 | + * @return void |
|
645 | + * @throws InstallationException |
|
646 | + */ |
|
647 | + protected function determineInstallStatus() { |
|
648 | + $path = Paths::settingsFile(); |
|
649 | + if (!is_file($path) || !is_readable($path)) { |
|
650 | + return; |
|
651 | + } |
|
652 | + |
|
653 | + $this->loadSettingsFile(); |
|
654 | + |
|
655 | + $this->has_completed['config'] = true; |
|
656 | + |
|
657 | + // must be able to connect to database to jump install steps |
|
658 | + $dbSettingsPass = $this->checkDatabaseSettings( |
|
659 | + $this->config->dbuser, |
|
660 | + $this->config->dbpass, |
|
661 | + $this->config->dbname, |
|
662 | + $this->config->dbhost |
|
663 | + ); |
|
664 | + |
|
665 | + if (!$dbSettingsPass) { |
|
666 | + return; |
|
667 | + } |
|
668 | + |
|
669 | + $db = $this->services->db; |
|
670 | + |
|
671 | + // check that the config table has been created |
|
672 | + $result = $db->getData("SHOW TABLES"); |
|
673 | + if ($result) { |
|
674 | + foreach ($result as $table) { |
|
675 | + $table = (array) $table; |
|
676 | + if (in_array("{$db->prefix}config", $table)) { |
|
677 | + $this->has_completed['database'] = true; |
|
678 | + } |
|
679 | + } |
|
680 | + if ($this->has_completed['database'] == false) { |
|
681 | + return; |
|
682 | + } |
|
683 | + } else { |
|
684 | + // no tables |
|
685 | + return; |
|
686 | + } |
|
687 | + |
|
688 | + // check that the config table has entries |
|
689 | + $query = "SELECT COUNT(*) AS total FROM {$db->prefix}config"; |
|
690 | + $result = $db->getData($query); |
|
691 | + if ($result && $result[0]->total > 0) { |
|
692 | + $this->has_completed['settings'] = true; |
|
693 | + } else { |
|
694 | + return; |
|
695 | + } |
|
696 | + |
|
697 | + // check that the users entity table has an entry |
|
698 | + $query = "SELECT COUNT(*) AS total FROM {$db->prefix}users_entity"; |
|
699 | + $result = $db->getData($query); |
|
700 | + if ($result && $result[0]->total > 0) { |
|
701 | + $this->has_completed['admin'] = true; |
|
702 | + } else { |
|
703 | + return; |
|
704 | + } |
|
705 | + } |
|
706 | + |
|
707 | + /** |
|
708 | + * Security check to ensure the installer cannot be run after installation |
|
709 | + * has finished. If this is detected, the viewer is sent to the front page. |
|
710 | + * |
|
711 | + * @param string $step Installation step to check against |
|
712 | + * |
|
713 | + * @return void |
|
714 | + */ |
|
715 | + protected function checkInstallCompletion($step) { |
|
716 | + if ($step != 'complete') { |
|
717 | + if (!in_array(false, $this->has_completed)) { |
|
718 | + // install complete but someone is trying to view an install page |
|
719 | + forward(); |
|
720 | + } |
|
721 | + } |
|
722 | + } |
|
723 | + |
|
724 | + /** |
|
725 | + * Check if this is a case of a install being resumed and figure |
|
726 | + * out where to continue from. Returns the best guess on the step. |
|
727 | + * |
|
728 | + * @param string $step Installation step to resume from |
|
729 | + * |
|
730 | + * @return string |
|
731 | + */ |
|
732 | + protected function resumeInstall($step) { |
|
733 | + // only do a resume from the first step |
|
734 | + if ($step !== 'welcome') { |
|
735 | + return; |
|
736 | + } |
|
737 | + |
|
738 | + if ($this->has_completed['database'] == false) { |
|
739 | + return; |
|
740 | + } |
|
741 | + |
|
742 | + if ($this->has_completed['settings'] == false) { |
|
743 | + forward("install.php?step=settings"); |
|
744 | + } |
|
745 | + |
|
746 | + if ($this->has_completed['admin'] == false) { |
|
747 | + forward("install.php?step=admin"); |
|
748 | + } |
|
749 | + |
|
750 | + // everything appears to be set up |
|
751 | + forward("install.php?step=complete"); |
|
752 | + } |
|
753 | + |
|
754 | + /** |
|
755 | + * Bootstrapping |
|
756 | + */ |
|
757 | + |
|
758 | + /** |
|
759 | + * Load remaining engine libraries and complete bootstrapping |
|
760 | + * |
|
761 | + * @param string $step Which step to boot strap for. Required because |
|
762 | + * boot strapping is different until the DB is populated. |
|
763 | + * |
|
764 | + * @return void |
|
765 | + * @throws InstallationException |
|
766 | + */ |
|
767 | + protected function finishBootstrapping($step) { |
|
768 | + |
|
769 | + $index_db = array_search('database', $this->getSteps()); |
|
770 | + $index_settings = array_search('settings', $this->getSteps()); |
|
771 | + $index_admin = array_search('admin', $this->getSteps()); |
|
772 | + $index_complete = array_search('complete', $this->getSteps()); |
|
773 | + $index_step = array_search($step, $this->getSteps()); |
|
774 | + |
|
775 | + // To log in the user, we need to use the Elgg core session handling. |
|
776 | + // Otherwise, use default php session handling |
|
777 | + $use_elgg_session = ($index_step == $index_admin && $this->is_action) || ($index_step == $index_complete); |
|
778 | + if (!$use_elgg_session) { |
|
779 | + $session = ElggSession::fromFiles($this->config); |
|
780 | + $session->setName('Elgg_install'); |
|
781 | + $this->services->setValue('session', $session); |
|
782 | + } |
|
783 | + |
|
784 | + if ($index_step > $index_db) { |
|
785 | + // once the database has been created, load rest of engine |
|
786 | + |
|
787 | + // dummy site needed to boot |
|
788 | + $this->config->site = new ElggSite(); |
|
789 | + |
|
790 | + $this->app->bootCore(); |
|
791 | + } |
|
792 | + } |
|
793 | + |
|
794 | + /** |
|
795 | + * Load settings |
|
796 | + * |
|
797 | + * @return void |
|
798 | + * @throws InstallationException |
|
799 | + */ |
|
800 | + protected function loadSettingsFile() { |
|
801 | + try { |
|
802 | + $config = Config::fromFile(Paths::settingsFile()); |
|
803 | + $this->config->mergeValues($config->getValues()); |
|
804 | + |
|
805 | + // in case the DB instance is already captured in services, we re-inject its settings. |
|
806 | + $this->services->db->resetConnections(DbConfig::fromElggConfig($this->config)); |
|
807 | + } catch (\Exception $e) { |
|
808 | + $msg = elgg_echo('InstallationException:CannotLoadSettings'); |
|
809 | + throw new InstallationException($msg, 0, $e); |
|
810 | + } |
|
811 | + } |
|
812 | + |
|
813 | + /** |
|
814 | + * Action handling methods |
|
815 | + */ |
|
816 | + |
|
817 | + /** |
|
818 | + * If form is reshown, remember previously submitted variables |
|
819 | + * |
|
820 | + * @param array $formVars Vars int he form |
|
821 | + * @param array $submissionVars Submitted vars |
|
822 | + * |
|
823 | + * @return array |
|
824 | + */ |
|
825 | + protected function makeFormSticky($formVars, $submissionVars) { |
|
826 | + foreach ($submissionVars as $field => $value) { |
|
827 | + $formVars[$field]['value'] = $value; |
|
828 | + } |
|
829 | + return $formVars; |
|
830 | + } |
|
831 | + |
|
832 | + /* Requirement checks support methods */ |
|
833 | + |
|
834 | + /** |
|
835 | + * Indicates whether the webserver can add settings.php on its own or not. |
|
836 | + * |
|
837 | + * @param array $report The requirements report object |
|
838 | + * |
|
839 | + * @return bool |
|
840 | + */ |
|
841 | + protected function isInstallDirWritable(&$report) { |
|
842 | + if (!is_writable(Paths::projectConfig())) { |
|
843 | + $msg = elgg_echo('install:check:installdir', [Paths::PATH_TO_CONFIG]); |
|
844 | + $report['settings'] = [ |
|
845 | + [ |
|
846 | + 'severity' => 'failure', |
|
847 | + 'message' => $msg, |
|
848 | + ] |
|
849 | + ]; |
|
850 | + return false; |
|
851 | + } |
|
852 | + |
|
853 | + return true; |
|
854 | + } |
|
855 | + |
|
856 | + /** |
|
857 | + * Check that the settings file exists |
|
858 | + * |
|
859 | + * @param array $report The requirements report array |
|
860 | + * |
|
861 | + * @return bool |
|
862 | + */ |
|
863 | + protected function checkSettingsFile(&$report = []) { |
|
864 | + if (!is_file(Paths::settingsFile())) { |
|
865 | + return false; |
|
866 | + } |
|
867 | + |
|
868 | + if (!is_readable(Paths::settingsFile())) { |
|
869 | + $report['settings'] = [ |
|
870 | + [ |
|
871 | + 'severity' => 'failure', |
|
872 | + 'message' => elgg_echo('install:check:readsettings'), |
|
873 | + ] |
|
874 | + ]; |
|
875 | + } |
|
876 | 876 | |
877 | - return true; |
|
878 | - } |
|
877 | + return true; |
|
878 | + } |
|
879 | 879 | |
880 | - /** |
|
881 | - * Check version of PHP, extensions, and variables |
|
882 | - * |
|
883 | - * @param array $report The requirements report array |
|
884 | - * |
|
885 | - * @return void |
|
886 | - */ |
|
887 | - protected function checkPHP(&$report) { |
|
888 | - $phpReport = []; |
|
889 | - |
|
890 | - $min_php_version = '5.6.0'; |
|
891 | - if (version_compare(PHP_VERSION, $min_php_version, '<')) { |
|
892 | - $phpReport[] = [ |
|
893 | - 'severity' => 'failure', |
|
894 | - 'message' => elgg_echo('install:check:php:version', [$min_php_version, PHP_VERSION]) |
|
895 | - ]; |
|
896 | - } |
|
897 | - |
|
898 | - $this->checkPhpExtensions($phpReport); |
|
899 | - |
|
900 | - $this->checkPhpDirectives($phpReport); |
|
901 | - |
|
902 | - if (count($phpReport) == 0) { |
|
903 | - $phpReport[] = [ |
|
904 | - 'severity' => 'pass', |
|
905 | - 'message' => elgg_echo('install:check:php:success') |
|
906 | - ]; |
|
907 | - } |
|
908 | - |
|
909 | - $report['php'] = $phpReport; |
|
910 | - } |
|
911 | - |
|
912 | - /** |
|
913 | - * Check the server's PHP extensions |
|
914 | - * |
|
915 | - * @param array $phpReport The PHP requirements report array |
|
916 | - * |
|
917 | - * @return void |
|
918 | - */ |
|
919 | - protected function checkPhpExtensions(&$phpReport) { |
|
920 | - $extensions = get_loaded_extensions(); |
|
921 | - $requiredExtensions = [ |
|
922 | - 'pdo_mysql', |
|
923 | - 'json', |
|
924 | - 'xml', |
|
925 | - 'gd', |
|
926 | - ]; |
|
927 | - foreach ($requiredExtensions as $extension) { |
|
928 | - if (!in_array($extension, $extensions)) { |
|
929 | - $phpReport[] = [ |
|
930 | - 'severity' => 'failure', |
|
931 | - 'message' => elgg_echo('install:check:php:extension', [$extension]) |
|
932 | - ]; |
|
933 | - } |
|
934 | - } |
|
935 | - |
|
936 | - $recommendedExtensions = [ |
|
937 | - 'mbstring', |
|
938 | - ]; |
|
939 | - foreach ($recommendedExtensions as $extension) { |
|
940 | - if (!in_array($extension, $extensions)) { |
|
941 | - $phpReport[] = [ |
|
942 | - 'severity' => 'warning', |
|
943 | - 'message' => elgg_echo('install:check:php:extension:recommend', [$extension]) |
|
944 | - ]; |
|
945 | - } |
|
946 | - } |
|
947 | - } |
|
948 | - |
|
949 | - /** |
|
950 | - * Check PHP parameters |
|
951 | - * |
|
952 | - * @param array $phpReport The PHP requirements report array |
|
953 | - * |
|
954 | - * @return void |
|
955 | - */ |
|
956 | - protected function checkPhpDirectives(&$phpReport) { |
|
957 | - if (ini_get('open_basedir')) { |
|
958 | - $phpReport[] = [ |
|
959 | - 'severity' => 'warning', |
|
960 | - 'message' => elgg_echo("install:check:php:open_basedir") |
|
961 | - ]; |
|
962 | - } |
|
963 | - |
|
964 | - if (ini_get('safe_mode')) { |
|
965 | - $phpReport[] = [ |
|
966 | - 'severity' => 'warning', |
|
967 | - 'message' => elgg_echo("install:check:php:safe_mode") |
|
968 | - ]; |
|
969 | - } |
|
970 | - |
|
971 | - if (ini_get('arg_separator.output') !== '&') { |
|
972 | - $separator = htmlspecialchars(ini_get('arg_separator.output')); |
|
973 | - $msg = elgg_echo("install:check:php:arg_separator", [$separator]); |
|
974 | - $phpReport[] = [ |
|
975 | - 'severity' => 'failure', |
|
976 | - 'message' => $msg, |
|
977 | - ]; |
|
978 | - } |
|
979 | - |
|
980 | - if (ini_get('register_globals')) { |
|
981 | - $phpReport[] = [ |
|
982 | - 'severity' => 'failure', |
|
983 | - 'message' => elgg_echo("install:check:php:register_globals") |
|
984 | - ]; |
|
985 | - } |
|
986 | - |
|
987 | - if (ini_get('session.auto_start')) { |
|
988 | - $phpReport[] = [ |
|
989 | - 'severity' => 'failure', |
|
990 | - 'message' => elgg_echo("install:check:php:session.auto_start") |
|
991 | - ]; |
|
992 | - } |
|
993 | - } |
|
994 | - |
|
995 | - /** |
|
996 | - * Confirm that the rewrite rules are firing |
|
997 | - * |
|
998 | - * @param array $report The requirements report array |
|
999 | - * |
|
1000 | - * @return void |
|
1001 | - */ |
|
1002 | - protected function checkRewriteRules(&$report) { |
|
1003 | - $tester = new ElggRewriteTester(); |
|
1004 | - $url = $this->config->wwwroot; |
|
1005 | - $url .= Request::REWRITE_TEST_TOKEN . '?' . http_build_query([ |
|
1006 | - Request::REWRITE_TEST_TOKEN => '1', |
|
1007 | - ]); |
|
1008 | - $report['rewrite'] = [$tester->run($url, Paths::project())]; |
|
1009 | - } |
|
1010 | - |
|
1011 | - /** |
|
1012 | - * Count the number of failures in the requirements report |
|
1013 | - * |
|
1014 | - * @param array $report The requirements report array |
|
1015 | - * @param string $condition 'failure' or 'warning' |
|
1016 | - * |
|
1017 | - * @return int |
|
1018 | - */ |
|
1019 | - protected function countNumConditions($report, $condition) { |
|
1020 | - $count = 0; |
|
1021 | - foreach ($report as $category => $checks) { |
|
1022 | - foreach ($checks as $check) { |
|
1023 | - if ($check['severity'] === $condition) { |
|
1024 | - $count++; |
|
1025 | - } |
|
1026 | - } |
|
1027 | - } |
|
1028 | - |
|
1029 | - return $count; |
|
1030 | - } |
|
1031 | - |
|
1032 | - |
|
1033 | - /** |
|
1034 | - * Database support methods |
|
1035 | - */ |
|
1036 | - |
|
1037 | - /** |
|
1038 | - * Validate the variables for the database step |
|
1039 | - * |
|
1040 | - * @param array $submissionVars Submitted vars |
|
1041 | - * @param array $formVars Vars in the form |
|
1042 | - * |
|
1043 | - * @return bool |
|
1044 | - */ |
|
1045 | - protected function validateDatabaseVars($submissionVars, $formVars) { |
|
1046 | - |
|
1047 | - foreach ($formVars as $field => $info) { |
|
1048 | - if ($info['required'] == true && !$submissionVars[$field]) { |
|
1049 | - $name = elgg_echo("install:database:label:$field"); |
|
1050 | - register_error(elgg_echo('install:error:requiredfield', [$name])); |
|
1051 | - return false; |
|
1052 | - } |
|
1053 | - } |
|
1054 | - |
|
1055 | - // check that data root is absolute path |
|
1056 | - if (stripos(PHP_OS, 'win') === 0) { |
|
1057 | - if (strpos($submissionVars['dataroot'], ':') !== 1) { |
|
1058 | - $msg = elgg_echo('install:error:relative_path', [$submissionVars['dataroot']]); |
|
1059 | - register_error($msg); |
|
1060 | - return false; |
|
1061 | - } |
|
1062 | - } else { |
|
1063 | - if (strpos($submissionVars['dataroot'], '/') !== 0) { |
|
1064 | - $msg = elgg_echo('install:error:relative_path', [$submissionVars['dataroot']]); |
|
1065 | - register_error($msg); |
|
1066 | - return false; |
|
1067 | - } |
|
1068 | - } |
|
1069 | - |
|
1070 | - // check that data root exists |
|
1071 | - if (!is_dir($submissionVars['dataroot'])) { |
|
1072 | - $msg = elgg_echo('install:error:datadirectoryexists', [$submissionVars['dataroot']]); |
|
1073 | - register_error($msg); |
|
1074 | - return false; |
|
1075 | - } |
|
1076 | - |
|
1077 | - // check that data root is writable |
|
1078 | - if (!is_writable($submissionVars['dataroot'])) { |
|
1079 | - $msg = elgg_echo('install:error:writedatadirectory', [$submissionVars['dataroot']]); |
|
1080 | - register_error($msg); |
|
1081 | - return false; |
|
1082 | - } |
|
1083 | - |
|
1084 | - if (!$this->config->data_dir_override) { |
|
1085 | - // check that data root is not subdirectory of Elgg root |
|
1086 | - if (stripos($submissionVars['dataroot'], $this->config->path) === 0) { |
|
1087 | - $msg = elgg_echo('install:error:locationdatadirectory', [$submissionVars['dataroot']]); |
|
1088 | - register_error($msg); |
|
1089 | - return false; |
|
1090 | - } |
|
1091 | - } |
|
1092 | - |
|
1093 | - // according to postgres documentation: SQL identifiers and key words must |
|
1094 | - // begin with a letter (a-z, but also letters with diacritical marks and |
|
1095 | - // non-Latin letters) or an underscore (_). Subsequent characters in an |
|
1096 | - // identifier or key word can be letters, underscores, digits (0-9), or dollar signs ($). |
|
1097 | - // Refs #4994 |
|
1098 | - if (!preg_match("/^[a-zA-Z_][\w]*$/", $submissionVars['dbprefix'])) { |
|
1099 | - register_error(elgg_echo('install:error:database_prefix')); |
|
1100 | - return false; |
|
1101 | - } |
|
1102 | - |
|
1103 | - return $this->checkDatabaseSettings( |
|
1104 | - $submissionVars['dbuser'], |
|
1105 | - $submissionVars['dbpassword'], |
|
1106 | - $submissionVars['dbname'], |
|
1107 | - $submissionVars['dbhost'] |
|
1108 | - ); |
|
1109 | - } |
|
1110 | - |
|
1111 | - /** |
|
1112 | - * Confirm the settings for the database |
|
1113 | - * |
|
1114 | - * @param string $user Username |
|
1115 | - * @param string $password Password |
|
1116 | - * @param string $dbname Database name |
|
1117 | - * @param string $host Host |
|
1118 | - * |
|
1119 | - * @return bool |
|
1120 | - */ |
|
1121 | - protected function checkDatabaseSettings($user, $password, $dbname, $host) { |
|
1122 | - $config = new DbConfig((object) [ |
|
1123 | - 'dbhost' => $host, |
|
1124 | - 'dbuser' => $user, |
|
1125 | - 'dbpass' => $password, |
|
1126 | - 'dbname' => $dbname, |
|
1127 | - 'dbencoding' => 'utf8mb4', |
|
1128 | - ]); |
|
1129 | - $db = new \Elgg\Database($config); |
|
1130 | - |
|
1131 | - try { |
|
1132 | - $db->getDataRow("SELECT 1"); |
|
1133 | - } catch (DatabaseException $e) { |
|
1134 | - if (0 === strpos($e->getMessage(), "Elgg couldn't connect")) { |
|
1135 | - register_error(elgg_echo('install:error:databasesettings')); |
|
1136 | - } else { |
|
1137 | - register_error(elgg_echo('install:error:nodatabase', [$dbname])); |
|
1138 | - } |
|
1139 | - return false; |
|
1140 | - } |
|
1141 | - |
|
1142 | - // check MySQL version |
|
1143 | - $version = $db->getServerVersion(DbConfig::READ_WRITE); |
|
1144 | - if (version_compare($version, '5.5.3', '<')) { |
|
1145 | - register_error(elgg_echo('install:error:oldmysql2', [$version])); |
|
1146 | - return false; |
|
1147 | - } |
|
1148 | - |
|
1149 | - return true; |
|
1150 | - } |
|
1151 | - |
|
1152 | - /** |
|
1153 | - * Writes the settings file to the engine directory |
|
1154 | - * |
|
1155 | - * @param array $params Array of inputted params from the user |
|
1156 | - * |
|
1157 | - * @return bool |
|
1158 | - */ |
|
1159 | - protected function createSettingsFile($params) { |
|
1160 | - $template = Application::elggDir()->getContents("elgg-config/settings.example.php"); |
|
1161 | - if (!$template) { |
|
1162 | - register_error(elgg_echo('install:error:readsettingsphp')); |
|
1163 | - return false; |
|
1164 | - } |
|
1165 | - |
|
1166 | - foreach ($params as $k => $v) { |
|
1167 | - $template = str_replace("{{" . $k . "}}", $v, $template); |
|
1168 | - } |
|
1169 | - |
|
1170 | - $result = file_put_contents(Paths::settingsFile(), $template); |
|
1171 | - if (!$result) { |
|
1172 | - register_error(elgg_echo('install:error:writesettingphp')); |
|
1173 | - return false; |
|
1174 | - } |
|
1175 | - |
|
1176 | - return true; |
|
1177 | - } |
|
1178 | - |
|
1179 | - /** |
|
1180 | - * Bootstrap database connection before entire engine is available |
|
1181 | - * |
|
1182 | - * @return bool |
|
1183 | - */ |
|
1184 | - protected function connectToDatabase() { |
|
1185 | - try { |
|
1186 | - $this->services->db->setupConnections(); |
|
1187 | - } catch (DatabaseException $e) { |
|
1188 | - register_error($e->getMessage()); |
|
1189 | - return false; |
|
1190 | - } |
|
1191 | - |
|
1192 | - return true; |
|
1193 | - } |
|
1194 | - |
|
1195 | - /** |
|
1196 | - * Create the database tables |
|
1197 | - * |
|
1198 | - * @return bool |
|
1199 | - */ |
|
1200 | - protected function installDatabase() { |
|
1201 | - try { |
|
1202 | - $this->services->db->runSqlScript(Paths::elgg() . "engine/schema/mysql.sql"); |
|
1203 | - init_site_secret(); |
|
1204 | - } catch (Exception $e) { |
|
1205 | - $msg = $e->getMessage(); |
|
1206 | - if (strpos($msg, 'already exists')) { |
|
1207 | - $msg = elgg_echo('install:error:tables_exist'); |
|
1208 | - } |
|
1209 | - register_error($msg); |
|
1210 | - return false; |
|
1211 | - } |
|
1212 | - |
|
1213 | - return true; |
|
1214 | - } |
|
1215 | - |
|
1216 | - /** |
|
1217 | - * Site settings support methods |
|
1218 | - */ |
|
1219 | - |
|
1220 | - /** |
|
1221 | - * Create the data directory if requested |
|
1222 | - * |
|
1223 | - * @param array $submissionVars Submitted vars |
|
1224 | - * @param array $formVars Variables in the form |
|
1225 | - * |
|
1226 | - * @return bool |
|
1227 | - */ |
|
1228 | - protected function createDataDirectory(&$submissionVars, $formVars) { |
|
1229 | - // did the user have option of Elgg creating the data directory |
|
1230 | - if ($formVars['dataroot']['type'] != 'combo') { |
|
1231 | - return true; |
|
1232 | - } |
|
1233 | - |
|
1234 | - // did the user select the option |
|
1235 | - if ($submissionVars['dataroot'] != 'dataroot-checkbox') { |
|
1236 | - return true; |
|
1237 | - } |
|
1238 | - |
|
1239 | - $dir = sanitise_filepath($submissionVars['path']) . 'data'; |
|
1240 | - if (file_exists($dir) || mkdir($dir, 0700)) { |
|
1241 | - $submissionVars['dataroot'] = $dir; |
|
1242 | - if (!file_exists("$dir/.htaccess")) { |
|
1243 | - $htaccess = "Order Deny,Allow\nDeny from All\n"; |
|
1244 | - if (!file_put_contents("$dir/.htaccess", $htaccess)) { |
|
1245 | - return false; |
|
1246 | - } |
|
1247 | - } |
|
1248 | - return true; |
|
1249 | - } |
|
1250 | - |
|
1251 | - return false; |
|
1252 | - } |
|
1253 | - |
|
1254 | - /** |
|
1255 | - * Validate the site settings form variables |
|
1256 | - * |
|
1257 | - * @param array $submissionVars Submitted vars |
|
1258 | - * @param array $formVars Vars in the form |
|
1259 | - * |
|
1260 | - * @return bool |
|
1261 | - */ |
|
1262 | - protected function validateSettingsVars($submissionVars, $formVars) { |
|
1263 | - foreach ($formVars as $field => $info) { |
|
1264 | - $submissionVars[$field] = trim($submissionVars[$field]); |
|
1265 | - if ($info['required'] == true && $submissionVars[$field] === '') { |
|
1266 | - $name = elgg_echo("install:settings:label:$field"); |
|
1267 | - register_error(elgg_echo('install:error:requiredfield', [$name])); |
|
1268 | - return false; |
|
1269 | - } |
|
1270 | - } |
|
1271 | - |
|
1272 | - // check that email address is email address |
|
1273 | - if ($submissionVars['siteemail'] && !is_email_address($submissionVars['siteemail'])) { |
|
1274 | - $msg = elgg_echo('install:error:emailaddress', [$submissionVars['siteemail']]); |
|
1275 | - register_error($msg); |
|
1276 | - return false; |
|
1277 | - } |
|
1278 | - |
|
1279 | - // @todo check that url is a url |
|
1280 | - // @note filter_var cannot be used because it doesn't work on international urls |
|
1281 | - |
|
1282 | - return true; |
|
1283 | - } |
|
1284 | - |
|
1285 | - /** |
|
1286 | - * Initialize the site including site entity, plugins, and configuration |
|
1287 | - * |
|
1288 | - * @param array $submissionVars Submitted vars |
|
1289 | - * |
|
1290 | - * @return bool |
|
1291 | - */ |
|
1292 | - protected function saveSiteSettings($submissionVars) { |
|
1293 | - $site = new ElggSite(); |
|
1294 | - $site->name = strip_tags($submissionVars['sitename']); |
|
1295 | - $site->access_id = ACCESS_PUBLIC; |
|
1296 | - $site->email = $submissionVars['siteemail']; |
|
1297 | - |
|
1298 | - $guid = $site->save(); |
|
1299 | - if ($guid !== 1) { |
|
1300 | - register_error(elgg_echo('install:error:createsite')); |
|
1301 | - return false; |
|
1302 | - } |
|
1303 | - |
|
1304 | - $this->config->site = $site; |
|
1305 | - |
|
1306 | - // new installations have run all the upgrades |
|
1307 | - $upgrades = elgg_get_upgrade_files(Paths::elgg() . "engine/lib/upgrades/"); |
|
1308 | - |
|
1309 | - $sets = [ |
|
1310 | - 'installed' => time(), |
|
1311 | - 'version' => elgg_get_version(), |
|
1312 | - 'simplecache_enabled' => 1, |
|
1313 | - 'system_cache_enabled' => 1, |
|
1314 | - 'simplecache_lastupdate' => time(), |
|
1315 | - 'processed_upgrades' => $upgrades, |
|
1316 | - 'language' => 'en', |
|
1317 | - 'default_access' => $submissionVars['siteaccess'], |
|
1318 | - 'allow_registration' => false, |
|
1319 | - 'walled_garden' => false, |
|
1320 | - 'allow_user_default_access' => '', |
|
1321 | - 'default_limit' => 10, |
|
1322 | - 'security_protect_upgrade' => true, |
|
1323 | - 'security_notify_admins' => true, |
|
1324 | - 'security_notify_user_password' => true, |
|
1325 | - 'security_email_require_password' => true, |
|
1326 | - ]; |
|
1327 | - foreach ($sets as $key => $value) { |
|
1328 | - elgg_save_config($key, $value); |
|
1329 | - } |
|
1330 | - |
|
1331 | - // Enable a set of default plugins |
|
1332 | - _elgg_generate_plugin_entities(); |
|
1333 | - |
|
1334 | - foreach (elgg_get_plugins('any') as $plugin) { |
|
1335 | - if ($plugin->getManifest()) { |
|
1336 | - if ($plugin->getManifest()->getActivateOnInstall()) { |
|
1337 | - $plugin->activate(); |
|
1338 | - } |
|
1339 | - if (in_array('theme', $plugin->getManifest()->getCategories())) { |
|
1340 | - $plugin->setPriority('last'); |
|
1341 | - } |
|
1342 | - } |
|
1343 | - } |
|
1344 | - |
|
1345 | - return true; |
|
1346 | - } |
|
1347 | - |
|
1348 | - /** |
|
1349 | - * Admin account support methods |
|
1350 | - */ |
|
1351 | - |
|
1352 | - /** |
|
1353 | - * Validate account form variables |
|
1354 | - * |
|
1355 | - * @param array $submissionVars Submitted vars |
|
1356 | - * @param array $formVars Form vars |
|
1357 | - * |
|
1358 | - * @return bool |
|
1359 | - */ |
|
1360 | - protected function validateAdminVars($submissionVars, $formVars) { |
|
1361 | - |
|
1362 | - foreach ($formVars as $field => $info) { |
|
1363 | - if ($info['required'] == true && !$submissionVars[$field]) { |
|
1364 | - $name = elgg_echo("install:admin:label:$field"); |
|
1365 | - register_error(elgg_echo('install:error:requiredfield', [$name])); |
|
1366 | - return false; |
|
1367 | - } |
|
1368 | - } |
|
1369 | - |
|
1370 | - if ($submissionVars['password1'] !== $submissionVars['password2']) { |
|
1371 | - register_error(elgg_echo('install:admin:password:mismatch')); |
|
1372 | - return false; |
|
1373 | - } |
|
1374 | - |
|
1375 | - if (trim($submissionVars['password1']) == "") { |
|
1376 | - register_error(elgg_echo('install:admin:password:empty')); |
|
1377 | - return false; |
|
1378 | - } |
|
1379 | - |
|
1380 | - $minLength = $this->services->configTable->get('min_password_length'); |
|
1381 | - if (strlen($submissionVars['password1']) < $minLength) { |
|
1382 | - register_error(elgg_echo('install:admin:password:tooshort')); |
|
1383 | - return false; |
|
1384 | - } |
|
1385 | - |
|
1386 | - // check that email address is email address |
|
1387 | - if ($submissionVars['email'] && !is_email_address($submissionVars['email'])) { |
|
1388 | - $msg = elgg_echo('install:error:emailaddress', [$submissionVars['email']]); |
|
1389 | - register_error($msg); |
|
1390 | - return false; |
|
1391 | - } |
|
1392 | - |
|
1393 | - return true; |
|
1394 | - } |
|
1395 | - |
|
1396 | - /** |
|
1397 | - * Create a user account for the admin |
|
1398 | - * |
|
1399 | - * @param array $submissionVars Submitted vars |
|
1400 | - * @param bool $login Login in the admin user? |
|
1401 | - * |
|
1402 | - * @return bool |
|
1403 | - */ |
|
1404 | - protected function createAdminAccount($submissionVars, $login = false) { |
|
1405 | - try { |
|
1406 | - $guid = register_user( |
|
1407 | - $submissionVars['username'], |
|
1408 | - $submissionVars['password1'], |
|
1409 | - $submissionVars['displayname'], |
|
1410 | - $submissionVars['email'] |
|
1411 | - ); |
|
1412 | - } catch (Exception $e) { |
|
1413 | - register_error($e->getMessage()); |
|
1414 | - return false; |
|
1415 | - } |
|
1416 | - |
|
1417 | - if (!$guid) { |
|
1418 | - register_error(elgg_echo('install:admin:cannot_create')); |
|
1419 | - return false; |
|
1420 | - } |
|
1421 | - |
|
1422 | - $user = get_entity($guid); |
|
1423 | - if (!$user instanceof ElggUser) { |
|
1424 | - register_error(elgg_echo('install:error:loadadmin')); |
|
1425 | - return false; |
|
1426 | - } |
|
1427 | - |
|
1428 | - elgg_set_ignore_access(true); |
|
1429 | - if ($user->makeAdmin() == false) { |
|
1430 | - register_error(elgg_echo('install:error:adminaccess')); |
|
1431 | - } else { |
|
1432 | - $this->services->configTable->set('admin_registered', 1); |
|
1433 | - } |
|
1434 | - elgg_set_ignore_access(false); |
|
1435 | - |
|
1436 | - // add validation data to satisfy user validation plugins |
|
1437 | - $user->validated = 1; |
|
1438 | - $user->validated_method = 'admin_user'; |
|
1439 | - |
|
1440 | - if (!$login) { |
|
1441 | - return true; |
|
1442 | - } |
|
1443 | - |
|
1444 | - $session = ElggSession::fromDatabase($this->config, $this->services->db); |
|
1445 | - $session->start(); |
|
1446 | - $this->services->setValue('session', $session); |
|
1447 | - if (login($user) == false) { |
|
1448 | - register_error(elgg_echo('install:error:adminlogin')); |
|
1449 | - } |
|
1450 | - |
|
1451 | - return true; |
|
1452 | - } |
|
880 | + /** |
|
881 | + * Check version of PHP, extensions, and variables |
|
882 | + * |
|
883 | + * @param array $report The requirements report array |
|
884 | + * |
|
885 | + * @return void |
|
886 | + */ |
|
887 | + protected function checkPHP(&$report) { |
|
888 | + $phpReport = []; |
|
889 | + |
|
890 | + $min_php_version = '5.6.0'; |
|
891 | + if (version_compare(PHP_VERSION, $min_php_version, '<')) { |
|
892 | + $phpReport[] = [ |
|
893 | + 'severity' => 'failure', |
|
894 | + 'message' => elgg_echo('install:check:php:version', [$min_php_version, PHP_VERSION]) |
|
895 | + ]; |
|
896 | + } |
|
897 | + |
|
898 | + $this->checkPhpExtensions($phpReport); |
|
899 | + |
|
900 | + $this->checkPhpDirectives($phpReport); |
|
901 | + |
|
902 | + if (count($phpReport) == 0) { |
|
903 | + $phpReport[] = [ |
|
904 | + 'severity' => 'pass', |
|
905 | + 'message' => elgg_echo('install:check:php:success') |
|
906 | + ]; |
|
907 | + } |
|
908 | + |
|
909 | + $report['php'] = $phpReport; |
|
910 | + } |
|
911 | + |
|
912 | + /** |
|
913 | + * Check the server's PHP extensions |
|
914 | + * |
|
915 | + * @param array $phpReport The PHP requirements report array |
|
916 | + * |
|
917 | + * @return void |
|
918 | + */ |
|
919 | + protected function checkPhpExtensions(&$phpReport) { |
|
920 | + $extensions = get_loaded_extensions(); |
|
921 | + $requiredExtensions = [ |
|
922 | + 'pdo_mysql', |
|
923 | + 'json', |
|
924 | + 'xml', |
|
925 | + 'gd', |
|
926 | + ]; |
|
927 | + foreach ($requiredExtensions as $extension) { |
|
928 | + if (!in_array($extension, $extensions)) { |
|
929 | + $phpReport[] = [ |
|
930 | + 'severity' => 'failure', |
|
931 | + 'message' => elgg_echo('install:check:php:extension', [$extension]) |
|
932 | + ]; |
|
933 | + } |
|
934 | + } |
|
935 | + |
|
936 | + $recommendedExtensions = [ |
|
937 | + 'mbstring', |
|
938 | + ]; |
|
939 | + foreach ($recommendedExtensions as $extension) { |
|
940 | + if (!in_array($extension, $extensions)) { |
|
941 | + $phpReport[] = [ |
|
942 | + 'severity' => 'warning', |
|
943 | + 'message' => elgg_echo('install:check:php:extension:recommend', [$extension]) |
|
944 | + ]; |
|
945 | + } |
|
946 | + } |
|
947 | + } |
|
948 | + |
|
949 | + /** |
|
950 | + * Check PHP parameters |
|
951 | + * |
|
952 | + * @param array $phpReport The PHP requirements report array |
|
953 | + * |
|
954 | + * @return void |
|
955 | + */ |
|
956 | + protected function checkPhpDirectives(&$phpReport) { |
|
957 | + if (ini_get('open_basedir')) { |
|
958 | + $phpReport[] = [ |
|
959 | + 'severity' => 'warning', |
|
960 | + 'message' => elgg_echo("install:check:php:open_basedir") |
|
961 | + ]; |
|
962 | + } |
|
963 | + |
|
964 | + if (ini_get('safe_mode')) { |
|
965 | + $phpReport[] = [ |
|
966 | + 'severity' => 'warning', |
|
967 | + 'message' => elgg_echo("install:check:php:safe_mode") |
|
968 | + ]; |
|
969 | + } |
|
970 | + |
|
971 | + if (ini_get('arg_separator.output') !== '&') { |
|
972 | + $separator = htmlspecialchars(ini_get('arg_separator.output')); |
|
973 | + $msg = elgg_echo("install:check:php:arg_separator", [$separator]); |
|
974 | + $phpReport[] = [ |
|
975 | + 'severity' => 'failure', |
|
976 | + 'message' => $msg, |
|
977 | + ]; |
|
978 | + } |
|
979 | + |
|
980 | + if (ini_get('register_globals')) { |
|
981 | + $phpReport[] = [ |
|
982 | + 'severity' => 'failure', |
|
983 | + 'message' => elgg_echo("install:check:php:register_globals") |
|
984 | + ]; |
|
985 | + } |
|
986 | + |
|
987 | + if (ini_get('session.auto_start')) { |
|
988 | + $phpReport[] = [ |
|
989 | + 'severity' => 'failure', |
|
990 | + 'message' => elgg_echo("install:check:php:session.auto_start") |
|
991 | + ]; |
|
992 | + } |
|
993 | + } |
|
994 | + |
|
995 | + /** |
|
996 | + * Confirm that the rewrite rules are firing |
|
997 | + * |
|
998 | + * @param array $report The requirements report array |
|
999 | + * |
|
1000 | + * @return void |
|
1001 | + */ |
|
1002 | + protected function checkRewriteRules(&$report) { |
|
1003 | + $tester = new ElggRewriteTester(); |
|
1004 | + $url = $this->config->wwwroot; |
|
1005 | + $url .= Request::REWRITE_TEST_TOKEN . '?' . http_build_query([ |
|
1006 | + Request::REWRITE_TEST_TOKEN => '1', |
|
1007 | + ]); |
|
1008 | + $report['rewrite'] = [$tester->run($url, Paths::project())]; |
|
1009 | + } |
|
1010 | + |
|
1011 | + /** |
|
1012 | + * Count the number of failures in the requirements report |
|
1013 | + * |
|
1014 | + * @param array $report The requirements report array |
|
1015 | + * @param string $condition 'failure' or 'warning' |
|
1016 | + * |
|
1017 | + * @return int |
|
1018 | + */ |
|
1019 | + protected function countNumConditions($report, $condition) { |
|
1020 | + $count = 0; |
|
1021 | + foreach ($report as $category => $checks) { |
|
1022 | + foreach ($checks as $check) { |
|
1023 | + if ($check['severity'] === $condition) { |
|
1024 | + $count++; |
|
1025 | + } |
|
1026 | + } |
|
1027 | + } |
|
1028 | + |
|
1029 | + return $count; |
|
1030 | + } |
|
1031 | + |
|
1032 | + |
|
1033 | + /** |
|
1034 | + * Database support methods |
|
1035 | + */ |
|
1036 | + |
|
1037 | + /** |
|
1038 | + * Validate the variables for the database step |
|
1039 | + * |
|
1040 | + * @param array $submissionVars Submitted vars |
|
1041 | + * @param array $formVars Vars in the form |
|
1042 | + * |
|
1043 | + * @return bool |
|
1044 | + */ |
|
1045 | + protected function validateDatabaseVars($submissionVars, $formVars) { |
|
1046 | + |
|
1047 | + foreach ($formVars as $field => $info) { |
|
1048 | + if ($info['required'] == true && !$submissionVars[$field]) { |
|
1049 | + $name = elgg_echo("install:database:label:$field"); |
|
1050 | + register_error(elgg_echo('install:error:requiredfield', [$name])); |
|
1051 | + return false; |
|
1052 | + } |
|
1053 | + } |
|
1054 | + |
|
1055 | + // check that data root is absolute path |
|
1056 | + if (stripos(PHP_OS, 'win') === 0) { |
|
1057 | + if (strpos($submissionVars['dataroot'], ':') !== 1) { |
|
1058 | + $msg = elgg_echo('install:error:relative_path', [$submissionVars['dataroot']]); |
|
1059 | + register_error($msg); |
|
1060 | + return false; |
|
1061 | + } |
|
1062 | + } else { |
|
1063 | + if (strpos($submissionVars['dataroot'], '/') !== 0) { |
|
1064 | + $msg = elgg_echo('install:error:relative_path', [$submissionVars['dataroot']]); |
|
1065 | + register_error($msg); |
|
1066 | + return false; |
|
1067 | + } |
|
1068 | + } |
|
1069 | + |
|
1070 | + // check that data root exists |
|
1071 | + if (!is_dir($submissionVars['dataroot'])) { |
|
1072 | + $msg = elgg_echo('install:error:datadirectoryexists', [$submissionVars['dataroot']]); |
|
1073 | + register_error($msg); |
|
1074 | + return false; |
|
1075 | + } |
|
1076 | + |
|
1077 | + // check that data root is writable |
|
1078 | + if (!is_writable($submissionVars['dataroot'])) { |
|
1079 | + $msg = elgg_echo('install:error:writedatadirectory', [$submissionVars['dataroot']]); |
|
1080 | + register_error($msg); |
|
1081 | + return false; |
|
1082 | + } |
|
1083 | + |
|
1084 | + if (!$this->config->data_dir_override) { |
|
1085 | + // check that data root is not subdirectory of Elgg root |
|
1086 | + if (stripos($submissionVars['dataroot'], $this->config->path) === 0) { |
|
1087 | + $msg = elgg_echo('install:error:locationdatadirectory', [$submissionVars['dataroot']]); |
|
1088 | + register_error($msg); |
|
1089 | + return false; |
|
1090 | + } |
|
1091 | + } |
|
1092 | + |
|
1093 | + // according to postgres documentation: SQL identifiers and key words must |
|
1094 | + // begin with a letter (a-z, but also letters with diacritical marks and |
|
1095 | + // non-Latin letters) or an underscore (_). Subsequent characters in an |
|
1096 | + // identifier or key word can be letters, underscores, digits (0-9), or dollar signs ($). |
|
1097 | + // Refs #4994 |
|
1098 | + if (!preg_match("/^[a-zA-Z_][\w]*$/", $submissionVars['dbprefix'])) { |
|
1099 | + register_error(elgg_echo('install:error:database_prefix')); |
|
1100 | + return false; |
|
1101 | + } |
|
1102 | + |
|
1103 | + return $this->checkDatabaseSettings( |
|
1104 | + $submissionVars['dbuser'], |
|
1105 | + $submissionVars['dbpassword'], |
|
1106 | + $submissionVars['dbname'], |
|
1107 | + $submissionVars['dbhost'] |
|
1108 | + ); |
|
1109 | + } |
|
1110 | + |
|
1111 | + /** |
|
1112 | + * Confirm the settings for the database |
|
1113 | + * |
|
1114 | + * @param string $user Username |
|
1115 | + * @param string $password Password |
|
1116 | + * @param string $dbname Database name |
|
1117 | + * @param string $host Host |
|
1118 | + * |
|
1119 | + * @return bool |
|
1120 | + */ |
|
1121 | + protected function checkDatabaseSettings($user, $password, $dbname, $host) { |
|
1122 | + $config = new DbConfig((object) [ |
|
1123 | + 'dbhost' => $host, |
|
1124 | + 'dbuser' => $user, |
|
1125 | + 'dbpass' => $password, |
|
1126 | + 'dbname' => $dbname, |
|
1127 | + 'dbencoding' => 'utf8mb4', |
|
1128 | + ]); |
|
1129 | + $db = new \Elgg\Database($config); |
|
1130 | + |
|
1131 | + try { |
|
1132 | + $db->getDataRow("SELECT 1"); |
|
1133 | + } catch (DatabaseException $e) { |
|
1134 | + if (0 === strpos($e->getMessage(), "Elgg couldn't connect")) { |
|
1135 | + register_error(elgg_echo('install:error:databasesettings')); |
|
1136 | + } else { |
|
1137 | + register_error(elgg_echo('install:error:nodatabase', [$dbname])); |
|
1138 | + } |
|
1139 | + return false; |
|
1140 | + } |
|
1141 | + |
|
1142 | + // check MySQL version |
|
1143 | + $version = $db->getServerVersion(DbConfig::READ_WRITE); |
|
1144 | + if (version_compare($version, '5.5.3', '<')) { |
|
1145 | + register_error(elgg_echo('install:error:oldmysql2', [$version])); |
|
1146 | + return false; |
|
1147 | + } |
|
1148 | + |
|
1149 | + return true; |
|
1150 | + } |
|
1151 | + |
|
1152 | + /** |
|
1153 | + * Writes the settings file to the engine directory |
|
1154 | + * |
|
1155 | + * @param array $params Array of inputted params from the user |
|
1156 | + * |
|
1157 | + * @return bool |
|
1158 | + */ |
|
1159 | + protected function createSettingsFile($params) { |
|
1160 | + $template = Application::elggDir()->getContents("elgg-config/settings.example.php"); |
|
1161 | + if (!$template) { |
|
1162 | + register_error(elgg_echo('install:error:readsettingsphp')); |
|
1163 | + return false; |
|
1164 | + } |
|
1165 | + |
|
1166 | + foreach ($params as $k => $v) { |
|
1167 | + $template = str_replace("{{" . $k . "}}", $v, $template); |
|
1168 | + } |
|
1169 | + |
|
1170 | + $result = file_put_contents(Paths::settingsFile(), $template); |
|
1171 | + if (!$result) { |
|
1172 | + register_error(elgg_echo('install:error:writesettingphp')); |
|
1173 | + return false; |
|
1174 | + } |
|
1175 | + |
|
1176 | + return true; |
|
1177 | + } |
|
1178 | + |
|
1179 | + /** |
|
1180 | + * Bootstrap database connection before entire engine is available |
|
1181 | + * |
|
1182 | + * @return bool |
|
1183 | + */ |
|
1184 | + protected function connectToDatabase() { |
|
1185 | + try { |
|
1186 | + $this->services->db->setupConnections(); |
|
1187 | + } catch (DatabaseException $e) { |
|
1188 | + register_error($e->getMessage()); |
|
1189 | + return false; |
|
1190 | + } |
|
1191 | + |
|
1192 | + return true; |
|
1193 | + } |
|
1194 | + |
|
1195 | + /** |
|
1196 | + * Create the database tables |
|
1197 | + * |
|
1198 | + * @return bool |
|
1199 | + */ |
|
1200 | + protected function installDatabase() { |
|
1201 | + try { |
|
1202 | + $this->services->db->runSqlScript(Paths::elgg() . "engine/schema/mysql.sql"); |
|
1203 | + init_site_secret(); |
|
1204 | + } catch (Exception $e) { |
|
1205 | + $msg = $e->getMessage(); |
|
1206 | + if (strpos($msg, 'already exists')) { |
|
1207 | + $msg = elgg_echo('install:error:tables_exist'); |
|
1208 | + } |
|
1209 | + register_error($msg); |
|
1210 | + return false; |
|
1211 | + } |
|
1212 | + |
|
1213 | + return true; |
|
1214 | + } |
|
1215 | + |
|
1216 | + /** |
|
1217 | + * Site settings support methods |
|
1218 | + */ |
|
1219 | + |
|
1220 | + /** |
|
1221 | + * Create the data directory if requested |
|
1222 | + * |
|
1223 | + * @param array $submissionVars Submitted vars |
|
1224 | + * @param array $formVars Variables in the form |
|
1225 | + * |
|
1226 | + * @return bool |
|
1227 | + */ |
|
1228 | + protected function createDataDirectory(&$submissionVars, $formVars) { |
|
1229 | + // did the user have option of Elgg creating the data directory |
|
1230 | + if ($formVars['dataroot']['type'] != 'combo') { |
|
1231 | + return true; |
|
1232 | + } |
|
1233 | + |
|
1234 | + // did the user select the option |
|
1235 | + if ($submissionVars['dataroot'] != 'dataroot-checkbox') { |
|
1236 | + return true; |
|
1237 | + } |
|
1238 | + |
|
1239 | + $dir = sanitise_filepath($submissionVars['path']) . 'data'; |
|
1240 | + if (file_exists($dir) || mkdir($dir, 0700)) { |
|
1241 | + $submissionVars['dataroot'] = $dir; |
|
1242 | + if (!file_exists("$dir/.htaccess")) { |
|
1243 | + $htaccess = "Order Deny,Allow\nDeny from All\n"; |
|
1244 | + if (!file_put_contents("$dir/.htaccess", $htaccess)) { |
|
1245 | + return false; |
|
1246 | + } |
|
1247 | + } |
|
1248 | + return true; |
|
1249 | + } |
|
1250 | + |
|
1251 | + return false; |
|
1252 | + } |
|
1253 | + |
|
1254 | + /** |
|
1255 | + * Validate the site settings form variables |
|
1256 | + * |
|
1257 | + * @param array $submissionVars Submitted vars |
|
1258 | + * @param array $formVars Vars in the form |
|
1259 | + * |
|
1260 | + * @return bool |
|
1261 | + */ |
|
1262 | + protected function validateSettingsVars($submissionVars, $formVars) { |
|
1263 | + foreach ($formVars as $field => $info) { |
|
1264 | + $submissionVars[$field] = trim($submissionVars[$field]); |
|
1265 | + if ($info['required'] == true && $submissionVars[$field] === '') { |
|
1266 | + $name = elgg_echo("install:settings:label:$field"); |
|
1267 | + register_error(elgg_echo('install:error:requiredfield', [$name])); |
|
1268 | + return false; |
|
1269 | + } |
|
1270 | + } |
|
1271 | + |
|
1272 | + // check that email address is email address |
|
1273 | + if ($submissionVars['siteemail'] && !is_email_address($submissionVars['siteemail'])) { |
|
1274 | + $msg = elgg_echo('install:error:emailaddress', [$submissionVars['siteemail']]); |
|
1275 | + register_error($msg); |
|
1276 | + return false; |
|
1277 | + } |
|
1278 | + |
|
1279 | + // @todo check that url is a url |
|
1280 | + // @note filter_var cannot be used because it doesn't work on international urls |
|
1281 | + |
|
1282 | + return true; |
|
1283 | + } |
|
1284 | + |
|
1285 | + /** |
|
1286 | + * Initialize the site including site entity, plugins, and configuration |
|
1287 | + * |
|
1288 | + * @param array $submissionVars Submitted vars |
|
1289 | + * |
|
1290 | + * @return bool |
|
1291 | + */ |
|
1292 | + protected function saveSiteSettings($submissionVars) { |
|
1293 | + $site = new ElggSite(); |
|
1294 | + $site->name = strip_tags($submissionVars['sitename']); |
|
1295 | + $site->access_id = ACCESS_PUBLIC; |
|
1296 | + $site->email = $submissionVars['siteemail']; |
|
1297 | + |
|
1298 | + $guid = $site->save(); |
|
1299 | + if ($guid !== 1) { |
|
1300 | + register_error(elgg_echo('install:error:createsite')); |
|
1301 | + return false; |
|
1302 | + } |
|
1303 | + |
|
1304 | + $this->config->site = $site; |
|
1305 | + |
|
1306 | + // new installations have run all the upgrades |
|
1307 | + $upgrades = elgg_get_upgrade_files(Paths::elgg() . "engine/lib/upgrades/"); |
|
1308 | + |
|
1309 | + $sets = [ |
|
1310 | + 'installed' => time(), |
|
1311 | + 'version' => elgg_get_version(), |
|
1312 | + 'simplecache_enabled' => 1, |
|
1313 | + 'system_cache_enabled' => 1, |
|
1314 | + 'simplecache_lastupdate' => time(), |
|
1315 | + 'processed_upgrades' => $upgrades, |
|
1316 | + 'language' => 'en', |
|
1317 | + 'default_access' => $submissionVars['siteaccess'], |
|
1318 | + 'allow_registration' => false, |
|
1319 | + 'walled_garden' => false, |
|
1320 | + 'allow_user_default_access' => '', |
|
1321 | + 'default_limit' => 10, |
|
1322 | + 'security_protect_upgrade' => true, |
|
1323 | + 'security_notify_admins' => true, |
|
1324 | + 'security_notify_user_password' => true, |
|
1325 | + 'security_email_require_password' => true, |
|
1326 | + ]; |
|
1327 | + foreach ($sets as $key => $value) { |
|
1328 | + elgg_save_config($key, $value); |
|
1329 | + } |
|
1330 | + |
|
1331 | + // Enable a set of default plugins |
|
1332 | + _elgg_generate_plugin_entities(); |
|
1333 | + |
|
1334 | + foreach (elgg_get_plugins('any') as $plugin) { |
|
1335 | + if ($plugin->getManifest()) { |
|
1336 | + if ($plugin->getManifest()->getActivateOnInstall()) { |
|
1337 | + $plugin->activate(); |
|
1338 | + } |
|
1339 | + if (in_array('theme', $plugin->getManifest()->getCategories())) { |
|
1340 | + $plugin->setPriority('last'); |
|
1341 | + } |
|
1342 | + } |
|
1343 | + } |
|
1344 | + |
|
1345 | + return true; |
|
1346 | + } |
|
1347 | + |
|
1348 | + /** |
|
1349 | + * Admin account support methods |
|
1350 | + */ |
|
1351 | + |
|
1352 | + /** |
|
1353 | + * Validate account form variables |
|
1354 | + * |
|
1355 | + * @param array $submissionVars Submitted vars |
|
1356 | + * @param array $formVars Form vars |
|
1357 | + * |
|
1358 | + * @return bool |
|
1359 | + */ |
|
1360 | + protected function validateAdminVars($submissionVars, $formVars) { |
|
1361 | + |
|
1362 | + foreach ($formVars as $field => $info) { |
|
1363 | + if ($info['required'] == true && !$submissionVars[$field]) { |
|
1364 | + $name = elgg_echo("install:admin:label:$field"); |
|
1365 | + register_error(elgg_echo('install:error:requiredfield', [$name])); |
|
1366 | + return false; |
|
1367 | + } |
|
1368 | + } |
|
1369 | + |
|
1370 | + if ($submissionVars['password1'] !== $submissionVars['password2']) { |
|
1371 | + register_error(elgg_echo('install:admin:password:mismatch')); |
|
1372 | + return false; |
|
1373 | + } |
|
1374 | + |
|
1375 | + if (trim($submissionVars['password1']) == "") { |
|
1376 | + register_error(elgg_echo('install:admin:password:empty')); |
|
1377 | + return false; |
|
1378 | + } |
|
1379 | + |
|
1380 | + $minLength = $this->services->configTable->get('min_password_length'); |
|
1381 | + if (strlen($submissionVars['password1']) < $minLength) { |
|
1382 | + register_error(elgg_echo('install:admin:password:tooshort')); |
|
1383 | + return false; |
|
1384 | + } |
|
1385 | + |
|
1386 | + // check that email address is email address |
|
1387 | + if ($submissionVars['email'] && !is_email_address($submissionVars['email'])) { |
|
1388 | + $msg = elgg_echo('install:error:emailaddress', [$submissionVars['email']]); |
|
1389 | + register_error($msg); |
|
1390 | + return false; |
|
1391 | + } |
|
1392 | + |
|
1393 | + return true; |
|
1394 | + } |
|
1395 | + |
|
1396 | + /** |
|
1397 | + * Create a user account for the admin |
|
1398 | + * |
|
1399 | + * @param array $submissionVars Submitted vars |
|
1400 | + * @param bool $login Login in the admin user? |
|
1401 | + * |
|
1402 | + * @return bool |
|
1403 | + */ |
|
1404 | + protected function createAdminAccount($submissionVars, $login = false) { |
|
1405 | + try { |
|
1406 | + $guid = register_user( |
|
1407 | + $submissionVars['username'], |
|
1408 | + $submissionVars['password1'], |
|
1409 | + $submissionVars['displayname'], |
|
1410 | + $submissionVars['email'] |
|
1411 | + ); |
|
1412 | + } catch (Exception $e) { |
|
1413 | + register_error($e->getMessage()); |
|
1414 | + return false; |
|
1415 | + } |
|
1416 | + |
|
1417 | + if (!$guid) { |
|
1418 | + register_error(elgg_echo('install:admin:cannot_create')); |
|
1419 | + return false; |
|
1420 | + } |
|
1421 | + |
|
1422 | + $user = get_entity($guid); |
|
1423 | + if (!$user instanceof ElggUser) { |
|
1424 | + register_error(elgg_echo('install:error:loadadmin')); |
|
1425 | + return false; |
|
1426 | + } |
|
1427 | + |
|
1428 | + elgg_set_ignore_access(true); |
|
1429 | + if ($user->makeAdmin() == false) { |
|
1430 | + register_error(elgg_echo('install:error:adminaccess')); |
|
1431 | + } else { |
|
1432 | + $this->services->configTable->set('admin_registered', 1); |
|
1433 | + } |
|
1434 | + elgg_set_ignore_access(false); |
|
1435 | + |
|
1436 | + // add validation data to satisfy user validation plugins |
|
1437 | + $user->validated = 1; |
|
1438 | + $user->validated_method = 'admin_user'; |
|
1439 | + |
|
1440 | + if (!$login) { |
|
1441 | + return true; |
|
1442 | + } |
|
1443 | + |
|
1444 | + $session = ElggSession::fromDatabase($this->config, $this->services->db); |
|
1445 | + $session->start(); |
|
1446 | + $this->services->setValue('session', $session); |
|
1447 | + if (login($user) == false) { |
|
1448 | + register_error(elgg_echo('install:error:adminlogin')); |
|
1449 | + } |
|
1450 | + |
|
1451 | + return true; |
|
1452 | + } |
|
1453 | 1453 | } |
@@ -1,7 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | use Elgg\Filesystem\Directory; |
4 | -use Elgg\Application; |
|
5 | 4 | use Elgg\Project\Paths; |
6 | 5 | use Elgg\Http\Request; |
7 | 6 |
@@ -10,252 +10,252 @@ |
||
10 | 10 | * Test if URL rewriting is working. |
11 | 11 | */ |
12 | 12 | class ElggRewriteTester { |
13 | - protected $webserver; |
|
14 | - protected $serverSupportsRemoteRead; |
|
15 | - protected $rewriteTestPassed; |
|
16 | - protected $htaccessIssue; |
|
13 | + protected $webserver; |
|
14 | + protected $serverSupportsRemoteRead; |
|
15 | + protected $rewriteTestPassed; |
|
16 | + protected $htaccessIssue; |
|
17 | 17 | |
18 | - /** |
|
19 | - * Set the webserver as unknown. |
|
20 | - */ |
|
21 | - public function __construct() { |
|
22 | - $this->webserver = 'unknown'; |
|
23 | - } |
|
18 | + /** |
|
19 | + * Set the webserver as unknown. |
|
20 | + */ |
|
21 | + public function __construct() { |
|
22 | + $this->webserver = 'unknown'; |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * Run the rewrite test and return a status array |
|
27 | - * |
|
28 | - * @param string $url URL of rewrite test |
|
29 | - * @param string $path Root directory of Elgg with trailing slash |
|
30 | - * |
|
31 | - * @return array |
|
32 | - */ |
|
33 | - public function run($url, $path) { |
|
25 | + /** |
|
26 | + * Run the rewrite test and return a status array |
|
27 | + * |
|
28 | + * @param string $url URL of rewrite test |
|
29 | + * @param string $path Root directory of Elgg with trailing slash |
|
30 | + * |
|
31 | + * @return array |
|
32 | + */ |
|
33 | + public function run($url, $path) { |
|
34 | 34 | |
35 | - $this->webserver = \ElggRewriteTester::guessWebServer(); |
|
35 | + $this->webserver = \ElggRewriteTester::guessWebServer(); |
|
36 | 36 | |
37 | - $this->rewriteTestPassed = $this->runRewriteTest($url); |
|
37 | + $this->rewriteTestPassed = $this->runRewriteTest($url); |
|
38 | 38 | |
39 | - if ($this->rewriteTestPassed == false) { |
|
40 | - if ($this->webserver == 'apache' || $this->webserver == 'unknown') { |
|
41 | - if ($this->createHtaccess($url, $path)) { |
|
42 | - $this->rewriteTestPassed = $this->runRewriteTest($url); |
|
43 | - } |
|
44 | - } |
|
45 | - } |
|
39 | + if ($this->rewriteTestPassed == false) { |
|
40 | + if ($this->webserver == 'apache' || $this->webserver == 'unknown') { |
|
41 | + if ($this->createHtaccess($url, $path)) { |
|
42 | + $this->rewriteTestPassed = $this->runRewriteTest($url); |
|
43 | + } |
|
44 | + } |
|
45 | + } |
|
46 | 46 | |
47 | - return $this->returnStatus($url); |
|
48 | - } |
|
47 | + return $this->returnStatus($url); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Guess the web server from $_SERVER['SERVER_SOFTWARE'] |
|
52 | - * |
|
53 | - * @return string |
|
54 | - */ |
|
55 | - public static function guessWebServer() { |
|
56 | - $serverString = strtolower($_SERVER['SERVER_SOFTWARE']); |
|
57 | - $possibleServers = ['apache', 'nginx', 'lighttpd', 'iis']; |
|
58 | - foreach ($possibleServers as $server) { |
|
59 | - if (strpos($serverString, $server) !== false) { |
|
60 | - return $server; |
|
61 | - } |
|
62 | - } |
|
63 | - return 'unknown'; |
|
64 | - } |
|
50 | + /** |
|
51 | + * Guess the web server from $_SERVER['SERVER_SOFTWARE'] |
|
52 | + * |
|
53 | + * @return string |
|
54 | + */ |
|
55 | + public static function guessWebServer() { |
|
56 | + $serverString = strtolower($_SERVER['SERVER_SOFTWARE']); |
|
57 | + $possibleServers = ['apache', 'nginx', 'lighttpd', 'iis']; |
|
58 | + foreach ($possibleServers as $server) { |
|
59 | + if (strpos($serverString, $server) !== false) { |
|
60 | + return $server; |
|
61 | + } |
|
62 | + } |
|
63 | + return 'unknown'; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Guess if url contains subdirectory or not. |
|
68 | - * |
|
69 | - * @param string $url Rewrite test URL |
|
70 | - * |
|
71 | - * @return string|bool Subdirectory string with beginning and trailing slash or false if were unable to determine subdirectory |
|
72 | - * or pointing at root of domain already |
|
73 | - */ |
|
74 | - public function guessSubdirectory($url) { |
|
75 | - $elements = parse_url($url); |
|
76 | - if (!$elements || !isset($elements['path'])) { |
|
77 | - return false; |
|
78 | - } |
|
79 | - $subdir = trim(dirname($elements['path']), '/'); |
|
80 | - if (!$subdir) { |
|
81 | - return false; |
|
82 | - } else { |
|
83 | - return "/$subdir/"; |
|
84 | - } |
|
85 | - } |
|
66 | + /** |
|
67 | + * Guess if url contains subdirectory or not. |
|
68 | + * |
|
69 | + * @param string $url Rewrite test URL |
|
70 | + * |
|
71 | + * @return string|bool Subdirectory string with beginning and trailing slash or false if were unable to determine subdirectory |
|
72 | + * or pointing at root of domain already |
|
73 | + */ |
|
74 | + public function guessSubdirectory($url) { |
|
75 | + $elements = parse_url($url); |
|
76 | + if (!$elements || !isset($elements['path'])) { |
|
77 | + return false; |
|
78 | + } |
|
79 | + $subdir = trim(dirname($elements['path']), '/'); |
|
80 | + if (!$subdir) { |
|
81 | + return false; |
|
82 | + } else { |
|
83 | + return "/$subdir/"; |
|
84 | + } |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * Hit the rewrite test URL to determine if the rewrite rules are working |
|
89 | - * |
|
90 | - * @param string $url Rewrite test URL |
|
91 | - * |
|
92 | - * @return bool |
|
93 | - */ |
|
94 | - public function runRewriteTest($url) { |
|
95 | - $this->serverSupportsRemoteRead = ($this->fetchUrl($url) === Request::REWRITE_TEST_OUTPUT); |
|
96 | - return $this->serverSupportsRemoteRead; |
|
97 | - } |
|
87 | + /** |
|
88 | + * Hit the rewrite test URL to determine if the rewrite rules are working |
|
89 | + * |
|
90 | + * @param string $url Rewrite test URL |
|
91 | + * |
|
92 | + * @return bool |
|
93 | + */ |
|
94 | + public function runRewriteTest($url) { |
|
95 | + $this->serverSupportsRemoteRead = ($this->fetchUrl($url) === Request::REWRITE_TEST_OUTPUT); |
|
96 | + return $this->serverSupportsRemoteRead; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * Check whether the site homepage can be fetched via curl |
|
101 | - * |
|
102 | - * @return boolean |
|
103 | - */ |
|
104 | - public function runLocalhostAccessTest() { |
|
105 | - $url = _elgg_config()->wwwroot; |
|
106 | - return (bool) $this->fetchUrl($url); |
|
107 | - } |
|
99 | + /** |
|
100 | + * Check whether the site homepage can be fetched via curl |
|
101 | + * |
|
102 | + * @return boolean |
|
103 | + */ |
|
104 | + public function runLocalhostAccessTest() { |
|
105 | + $url = _elgg_config()->wwwroot; |
|
106 | + return (bool) $this->fetchUrl($url); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Fetch a URL |
|
111 | - * |
|
112 | - * @param string $url The URL |
|
113 | - * |
|
114 | - * @return string Note that empty string may imply failure in fetching or empty response |
|
115 | - */ |
|
116 | - private function fetchUrl($url) { |
|
117 | - $response = ''; |
|
109 | + /** |
|
110 | + * Fetch a URL |
|
111 | + * |
|
112 | + * @param string $url The URL |
|
113 | + * |
|
114 | + * @return string Note that empty string may imply failure in fetching or empty response |
|
115 | + */ |
|
116 | + private function fetchUrl($url) { |
|
117 | + $response = ''; |
|
118 | 118 | |
119 | - if (ini_get('allow_url_fopen')) { |
|
120 | - $ctx = stream_context_create([ |
|
121 | - 'http' => [ |
|
122 | - 'follow_location' => 0, |
|
123 | - 'timeout' => 5, |
|
124 | - ], |
|
125 | - ]); |
|
126 | - $response = @file_get_contents($url, null, $ctx); |
|
127 | - } |
|
119 | + if (ini_get('allow_url_fopen')) { |
|
120 | + $ctx = stream_context_create([ |
|
121 | + 'http' => [ |
|
122 | + 'follow_location' => 0, |
|
123 | + 'timeout' => 5, |
|
124 | + ], |
|
125 | + ]); |
|
126 | + $response = @file_get_contents($url, null, $ctx); |
|
127 | + } |
|
128 | 128 | |
129 | - if (!$response && function_exists('curl_init')) { |
|
130 | - $ch = curl_init(); |
|
131 | - curl_setopt($ch, CURLOPT_URL, $url); |
|
132 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
133 | - curl_setopt($ch, CURLOPT_TIMEOUT, 5); |
|
134 | - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
|
135 | - $response = curl_exec($ch); |
|
136 | - curl_close($ch); |
|
137 | - } |
|
129 | + if (!$response && function_exists('curl_init')) { |
|
130 | + $ch = curl_init(); |
|
131 | + curl_setopt($ch, CURLOPT_URL, $url); |
|
132 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
133 | + curl_setopt($ch, CURLOPT_TIMEOUT, 5); |
|
134 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
|
135 | + $response = curl_exec($ch); |
|
136 | + curl_close($ch); |
|
137 | + } |
|
138 | 138 | |
139 | - return (string) $response; |
|
140 | - } |
|
139 | + return (string) $response; |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * Create Elgg's .htaccess file or confirm that it exists |
|
144 | - * |
|
145 | - * @param string $url URL of rewrite test |
|
146 | - * |
|
147 | - * @return bool |
|
148 | - */ |
|
149 | - public function createHtaccess($url) { |
|
150 | - $root = Directory\Local::projectRoot(); |
|
151 | - $file = $root->getFile(".htaccess"); |
|
142 | + /** |
|
143 | + * Create Elgg's .htaccess file or confirm that it exists |
|
144 | + * |
|
145 | + * @param string $url URL of rewrite test |
|
146 | + * |
|
147 | + * @return bool |
|
148 | + */ |
|
149 | + public function createHtaccess($url) { |
|
150 | + $root = Directory\Local::projectRoot(); |
|
151 | + $file = $root->getFile(".htaccess"); |
|
152 | 152 | |
153 | - if ($file->exists()) { |
|
154 | - // check that this is the Elgg .htaccess |
|
155 | - $data = $file->getContents(); |
|
156 | - if ($data === false) { |
|
157 | - // don't have permission to read the file |
|
158 | - $this->htaccessIssue = 'read_permission'; |
|
159 | - return false; |
|
160 | - } |
|
153 | + if ($file->exists()) { |
|
154 | + // check that this is the Elgg .htaccess |
|
155 | + $data = $file->getContents(); |
|
156 | + if ($data === false) { |
|
157 | + // don't have permission to read the file |
|
158 | + $this->htaccessIssue = 'read_permission'; |
|
159 | + return false; |
|
160 | + } |
|
161 | 161 | |
162 | - if (strpos($data, 'Elgg') === false) { |
|
163 | - $this->htaccessIssue = 'non_elgg_htaccess'; |
|
164 | - return false; |
|
165 | - } |
|
162 | + if (strpos($data, 'Elgg') === false) { |
|
163 | + $this->htaccessIssue = 'non_elgg_htaccess'; |
|
164 | + return false; |
|
165 | + } |
|
166 | 166 | |
167 | - // check if this is an old Elgg htaccess |
|
168 | - if (strpos($data, 'RewriteRule ^rewrite.php$ install.php') == false) { |
|
169 | - $this->htaccessIssue = 'old_elgg_htaccess'; |
|
170 | - return false; |
|
171 | - } |
|
172 | - return true; |
|
173 | - } |
|
167 | + // check if this is an old Elgg htaccess |
|
168 | + if (strpos($data, 'RewriteRule ^rewrite.php$ install.php') == false) { |
|
169 | + $this->htaccessIssue = 'old_elgg_htaccess'; |
|
170 | + return false; |
|
171 | + } |
|
172 | + return true; |
|
173 | + } |
|
174 | 174 | |
175 | - if (!is_writable($root->getPath())) { |
|
176 | - $this->htaccessIssue = 'write_permission'; |
|
177 | - return false; |
|
178 | - } |
|
175 | + if (!is_writable($root->getPath())) { |
|
176 | + $this->htaccessIssue = 'write_permission'; |
|
177 | + return false; |
|
178 | + } |
|
179 | 179 | |
180 | - // create the .htaccess file |
|
181 | - $result = copy(Paths::elgg() . "install/config/htaccess.dist", $file->getPath()); |
|
182 | - if (!$result) { |
|
183 | - $this->htaccessIssue = 'cannot_copy'; |
|
184 | - return false; |
|
185 | - } |
|
180 | + // create the .htaccess file |
|
181 | + $result = copy(Paths::elgg() . "install/config/htaccess.dist", $file->getPath()); |
|
182 | + if (!$result) { |
|
183 | + $this->htaccessIssue = 'cannot_copy'; |
|
184 | + return false; |
|
185 | + } |
|
186 | 186 | |
187 | - // does default RewriteBase work already? |
|
188 | - if (!$this->runRewriteTest($url)) { |
|
189 | - //try to rewrite to guessed subdirectory |
|
190 | - if ($subdir = $this->guessSubdirectory($url)) { |
|
191 | - $contents = $file->getContents(); |
|
192 | - $contents = preg_replace("/#RewriteBase \/(\r?\n)/", "RewriteBase $subdir\$1", $contents); |
|
193 | - if ($contents) { |
|
194 | - $file->putContents($contents); |
|
195 | - } |
|
196 | - } |
|
197 | - } |
|
187 | + // does default RewriteBase work already? |
|
188 | + if (!$this->runRewriteTest($url)) { |
|
189 | + //try to rewrite to guessed subdirectory |
|
190 | + if ($subdir = $this->guessSubdirectory($url)) { |
|
191 | + $contents = $file->getContents(); |
|
192 | + $contents = preg_replace("/#RewriteBase \/(\r?\n)/", "RewriteBase $subdir\$1", $contents); |
|
193 | + if ($contents) { |
|
194 | + $file->putContents($contents); |
|
195 | + } |
|
196 | + } |
|
197 | + } |
|
198 | 198 | |
199 | - return true; |
|
200 | - } |
|
199 | + return true; |
|
200 | + } |
|
201 | 201 | |
202 | - /** |
|
203 | - * Create the status array required by the ElggInstaller |
|
204 | - * |
|
205 | - * @param string $url Rewrite test URL |
|
206 | - * |
|
207 | - * @return array |
|
208 | - */ |
|
209 | - protected function returnStatus($url) { |
|
210 | - if ($this->rewriteTestPassed) { |
|
211 | - return [ |
|
212 | - 'severity' => 'pass', |
|
213 | - 'message' => _elgg_services()->translator->translate('install:check:rewrite:success'), |
|
214 | - ]; |
|
215 | - } |
|
202 | + /** |
|
203 | + * Create the status array required by the ElggInstaller |
|
204 | + * |
|
205 | + * @param string $url Rewrite test URL |
|
206 | + * |
|
207 | + * @return array |
|
208 | + */ |
|
209 | + protected function returnStatus($url) { |
|
210 | + if ($this->rewriteTestPassed) { |
|
211 | + return [ |
|
212 | + 'severity' => 'pass', |
|
213 | + 'message' => _elgg_services()->translator->translate('install:check:rewrite:success'), |
|
214 | + ]; |
|
215 | + } |
|
216 | 216 | |
217 | - if ($this->serverSupportsRemoteRead == false) { |
|
218 | - $msg = _elgg_services()->translator->translate('install:warning:rewrite:unknown', [$url]); |
|
219 | - $msg .= elgg_view('install/js_rewrite_check', ['url' => $url]); |
|
217 | + if ($this->serverSupportsRemoteRead == false) { |
|
218 | + $msg = _elgg_services()->translator->translate('install:warning:rewrite:unknown', [$url]); |
|
219 | + $msg .= elgg_view('install/js_rewrite_check', ['url' => $url]); |
|
220 | 220 | |
221 | - return [ |
|
222 | - 'severity' => 'warning', |
|
223 | - 'message' => $msg, |
|
224 | - ]; |
|
225 | - } |
|
221 | + return [ |
|
222 | + 'severity' => 'warning', |
|
223 | + 'message' => $msg, |
|
224 | + ]; |
|
225 | + } |
|
226 | 226 | |
227 | - if ($this->webserver == 'apache') { |
|
228 | - $serverString = _elgg_services()->translator->translate('install:error:rewrite:apache'); |
|
229 | - $msg = "$serverString\n\n"; |
|
230 | - if (!isset($this->htaccessIssue)) { |
|
231 | - $msg .= _elgg_services()->translator->translate('install:error:rewrite:allowoverride'); |
|
232 | - $msg .= elgg_view('install/js_rewrite_check', ['url' => $url]); |
|
227 | + if ($this->webserver == 'apache') { |
|
228 | + $serverString = _elgg_services()->translator->translate('install:error:rewrite:apache'); |
|
229 | + $msg = "$serverString\n\n"; |
|
230 | + if (!isset($this->htaccessIssue)) { |
|
231 | + $msg .= _elgg_services()->translator->translate('install:error:rewrite:allowoverride'); |
|
232 | + $msg .= elgg_view('install/js_rewrite_check', ['url' => $url]); |
|
233 | 233 | |
234 | - return [ |
|
235 | - 'severity' => 'warning', |
|
236 | - 'message' => $msg, |
|
237 | - ]; |
|
238 | - } |
|
239 | - $msg .= _elgg_services()->translator->translate("install:error:rewrite:htaccess:{$this->htaccessIssue}"); |
|
240 | - return [ |
|
241 | - 'severity' => 'warning', |
|
242 | - 'message' => $msg, |
|
243 | - ]; |
|
244 | - } |
|
234 | + return [ |
|
235 | + 'severity' => 'warning', |
|
236 | + 'message' => $msg, |
|
237 | + ]; |
|
238 | + } |
|
239 | + $msg .= _elgg_services()->translator->translate("install:error:rewrite:htaccess:{$this->htaccessIssue}"); |
|
240 | + return [ |
|
241 | + 'severity' => 'warning', |
|
242 | + 'message' => $msg, |
|
243 | + ]; |
|
244 | + } |
|
245 | 245 | |
246 | - if ($this->webserver != 'unknown') { |
|
247 | - $serverString = _elgg_services()->translator->translate("install:error:rewrite:{$this->webserver}"); |
|
248 | - $msg = "$serverString\n\n"; |
|
249 | - $msg .= _elgg_services()->translator->translate("install:error:rewrite:altserver"); |
|
250 | - return [ |
|
251 | - 'severity' => 'warning', |
|
252 | - 'message' => $msg, |
|
253 | - ]; |
|
254 | - } |
|
246 | + if ($this->webserver != 'unknown') { |
|
247 | + $serverString = _elgg_services()->translator->translate("install:error:rewrite:{$this->webserver}"); |
|
248 | + $msg = "$serverString\n\n"; |
|
249 | + $msg .= _elgg_services()->translator->translate("install:error:rewrite:altserver"); |
|
250 | + return [ |
|
251 | + 'severity' => 'warning', |
|
252 | + 'message' => $msg, |
|
253 | + ]; |
|
254 | + } |
|
255 | 255 | |
256 | - return [ |
|
257 | - 'severity' => 'warning', |
|
258 | - 'message' => _elgg_services()->translator->translate('install:error:rewrite:unknown'), |
|
259 | - ]; |
|
260 | - } |
|
256 | + return [ |
|
257 | + 'severity' => 'warning', |
|
258 | + 'message' => _elgg_services()->translator->translate('install:error:rewrite:unknown'), |
|
259 | + ]; |
|
260 | + } |
|
261 | 261 | } |
@@ -178,7 +178,7 @@ |
||
178 | 178 | } |
179 | 179 | |
180 | 180 | // create the .htaccess file |
181 | - $result = copy(Paths::elgg() . "install/config/htaccess.dist", $file->getPath()); |
|
181 | + $result = copy(Paths::elgg()."install/config/htaccess.dist", $file->getPath()); |
|
182 | 182 | if (!$result) { |
183 | 183 | $this->htaccessIssue = 'cannot_copy'; |
184 | 184 | return false; |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | * |
250 | 250 | * @param string $location 'head' or 'footer' |
251 | 251 | * |
252 | - * @return array |
|
252 | + * @return string[] |
|
253 | 253 | * @since 1.8.0 |
254 | 254 | */ |
255 | 255 | function elgg_get_loaded_js($location = 'head') { |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | /** |
301 | 301 | * Get the loaded CSS URLs |
302 | 302 | * |
303 | - * @return array |
|
303 | + * @return string[] |
|
304 | 304 | * @since 1.8.0 |
305 | 305 | */ |
306 | 306 | function elgg_get_loaded_css() { |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | * @param string $type Type of file: js or css |
356 | 356 | * @param string $location Page location |
357 | 357 | * |
358 | - * @return array |
|
358 | + * @return string[] |
|
359 | 359 | * @since 1.8.0 |
360 | 360 | */ |
361 | 361 | function elgg_get_loaded_external_files($type, $location) { |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | * @param string $directory Directory to look in |
371 | 371 | * @param array $exceptions Array of filenames to ignore |
372 | 372 | * @param array $list Array of files to append to |
373 | - * @param mixed $extensions Array of extensions to allow, null for all. Use a dot: array('.php'). |
|
373 | + * @param string[] $extensions Array of extensions to allow, null for all. Use a dot: array('.php'). |
|
374 | 374 | * |
375 | 375 | * @return array Filenames in $directory, in the form $directory/filename. |
376 | 376 | */ |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | /** |
439 | 439 | * Display a system message on next page load. |
440 | 440 | * |
441 | - * @param string|array $message Message or messages to add |
|
441 | + * @param string $message Message or messages to add |
|
442 | 442 | * |
443 | 443 | * @return bool |
444 | 444 | */ |
@@ -635,7 +635,7 @@ discard block |
||
635 | 635 | * @param string $object_type The object type |
636 | 636 | * @param string $object The object involved in the event |
637 | 637 | * |
638 | - * @return true |
|
638 | + * @return boolean |
|
639 | 639 | * |
640 | 640 | * @see elgg_trigger_before_event |
641 | 641 | */ |
@@ -816,7 +816,7 @@ discard block |
||
816 | 816 | * @param string $hook Hook name |
817 | 817 | * @param string $type Hook type |
818 | 818 | * |
819 | - * @return array |
|
819 | + * @return callable[] |
|
820 | 820 | * |
821 | 821 | * @since 2.0.0 |
822 | 822 | */ |
@@ -830,7 +830,7 @@ discard block |
||
830 | 830 | * @param string $event Event name |
831 | 831 | * @param string $type Object type |
832 | 832 | * |
833 | - * @return array |
|
833 | + * @return callable[] |
|
834 | 834 | * |
835 | 835 | * @since 2.0.0 |
836 | 836 | */ |
@@ -880,7 +880,7 @@ discard block |
||
880 | 880 | * A {@elgg_plugin_hook debug log} is called. If a handler returns |
881 | 881 | * false, it will stop the default logging method. |
882 | 882 | * |
883 | - * @param mixed $value The value |
|
883 | + * @param string $value The value |
|
884 | 884 | * @param bool $to_screen Display to screen? |
885 | 885 | * @return void |
886 | 886 | * @since 1.7.0 |
@@ -1222,7 +1222,7 @@ discard block |
||
1222 | 1222 | * Extract class names from an array with key "class", optionally merging into a preexisting set. |
1223 | 1223 | * |
1224 | 1224 | * @param array $array Source array |
1225 | - * @param string|string[] $existing Existing name(s) |
|
1225 | + * @param string[] $existing Existing name(s) |
|
1226 | 1226 | * @return string[] |
1227 | 1227 | * |
1228 | 1228 | * @since 2.3.0 |
@@ -1787,7 +1787,7 @@ discard block |
||
1787 | 1787 | * @param array $params empty |
1788 | 1788 | * |
1789 | 1789 | * @elgg_plugin_hook unit_tests system |
1790 | - * @return array |
|
1790 | + * @return string[] |
|
1791 | 1791 | * @access private |
1792 | 1792 | */ |
1793 | 1793 | function _elgg_api_test($hook, $type, $value, $params) { |
@@ -379,16 +379,16 @@ discard block |
||
379 | 379 | $directory = sanitise_filepath($directory); |
380 | 380 | if ($handle = opendir($directory)) { |
381 | 381 | while (($file = readdir($handle)) !== false) { |
382 | - if (!is_file($directory . $file) || in_array($file, $exceptions)) { |
|
382 | + if (!is_file($directory.$file) || in_array($file, $exceptions)) { |
|
383 | 383 | continue; |
384 | 384 | } |
385 | 385 | |
386 | 386 | if (is_array($extensions)) { |
387 | 387 | if (in_array(strrchr($file, '.'), $extensions)) { |
388 | - $list[] = $directory . $file; |
|
388 | + $list[] = $directory.$file; |
|
389 | 389 | } |
390 | 390 | } else { |
391 | - $list[] = $directory . $file; |
|
391 | + $list[] = $directory.$file; |
|
392 | 392 | } |
393 | 393 | } |
394 | 394 | closedir($handle); |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | $path = rtrim($path, " \n\t\0\x0B/"); |
419 | 419 | |
420 | 420 | if ($append_slash) { |
421 | - $path = $path . '/'; |
|
421 | + $path = $path.'/'; |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | return $path; |
@@ -951,7 +951,7 @@ discard block |
||
951 | 951 | $query = isset($parts['query']) ? "?{$parts['query']}" : ''; |
952 | 952 | $fragment = isset($parts['fragment']) ? "#{$parts['fragment']}" : ''; |
953 | 953 | |
954 | - $string = $scheme . $host . $port . $path . $query . $fragment; |
|
954 | + $string = $scheme.$host.$port.$path.$query.$fragment; |
|
955 | 955 | |
956 | 956 | if ($html_encode) { |
957 | 957 | return htmlspecialchars($string, ENT_QUOTES, 'UTF-8', false); |
@@ -1360,7 +1360,7 @@ discard block |
||
1360 | 1360 | */ |
1361 | 1361 | function _elgg_normalize_plural_options_array($options, $singulars) { |
1362 | 1362 | foreach ($singulars as $singular) { |
1363 | - $plural = $singular . 's'; |
|
1363 | + $plural = $singular.'s'; |
|
1364 | 1364 | |
1365 | 1365 | if (array_key_exists($singular, $options)) { |
1366 | 1366 | if ($options[$singular] === ELGG_ENTITIES_ANY_VALUE) { |
@@ -1408,7 +1408,7 @@ discard block |
||
1408 | 1408 | // demoted to NOTICE from DEBUG so javascript is not corrupted |
1409 | 1409 | elgg_log("Page {$uri} generated in $time seconds", 'INFO'); |
1410 | 1410 | } catch (Exception $e) { |
1411 | - $message = 'Error: ' . get_class($e) . ' thrown within the shutdown handler. '; |
|
1411 | + $message = 'Error: '.get_class($e).' thrown within the shutdown handler. '; |
|
1412 | 1412 | $message .= "Message: '{$e->getMessage()}' in file {$e->getFile()} (line {$e->getLine()})"; |
1413 | 1413 | error_log($message); |
1414 | 1414 | error_log("Exception trace stack: {$e->getTraceAsString()}"); |
@@ -1444,7 +1444,7 @@ discard block |
||
1444 | 1444 | $view = implode('/', array_slice($segments, 1)); |
1445 | 1445 | } else { |
1446 | 1446 | // form views start with "forms", not "form" |
1447 | - $view = 'forms/' . implode('/', array_slice($segments, 1)); |
|
1447 | + $view = 'forms/'.implode('/', array_slice($segments, 1)); |
|
1448 | 1448 | } |
1449 | 1449 | |
1450 | 1450 | $ajax_api = _elgg_services()->ajax; |
@@ -1510,7 +1510,7 @@ discard block |
||
1510 | 1510 | function _elgg_favicon_page_handler($segments) { |
1511 | 1511 | header("HTTP/1.1 404 Not Found", true, 404); |
1512 | 1512 | |
1513 | - header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+1 week")), true); |
|
1513 | + header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', strtotime("+1 week")), true); |
|
1514 | 1514 | header("Pragma: public", true); |
1515 | 1515 | header("Cache-Control: public", true); |
1516 | 1516 | |
@@ -1540,7 +1540,7 @@ discard block |
||
1540 | 1540 | $return = str_replace(' desc', ' asc', $order_by); |
1541 | 1541 | } else { |
1542 | 1542 | // no order specified, so default to desc since mysql defaults to asc |
1543 | - $return = $order_by . ' desc'; |
|
1543 | + $return = $order_by.' desc'; |
|
1544 | 1544 | } |
1545 | 1545 | |
1546 | 1546 | return $return; |
@@ -1791,10 +1791,10 @@ discard block |
||
1791 | 1791 | * @access private |
1792 | 1792 | */ |
1793 | 1793 | function _elgg_api_test($hook, $type, $value, $params) { |
1794 | - $value[] = Paths::elgg() . 'engine/tests/ElggTravisInstallTest.php'; |
|
1795 | - $value[] = Paths::elgg() . 'engine/tests/ElggCoreHelpersTest.php'; |
|
1796 | - $value[] = Paths::elgg() . 'engine/tests/ElggCoreRegressionBugsTest.php'; |
|
1797 | - $value[] = Paths::elgg() . 'engine/tests/ElggBatchTest.php'; |
|
1794 | + $value[] = Paths::elgg().'engine/tests/ElggTravisInstallTest.php'; |
|
1795 | + $value[] = Paths::elgg().'engine/tests/ElggCoreHelpersTest.php'; |
|
1796 | + $value[] = Paths::elgg().'engine/tests/ElggCoreRegressionBugsTest.php'; |
|
1797 | + $value[] = Paths::elgg().'engine/tests/ElggBatchTest.php'; |
|
1798 | 1798 | return $value; |
1799 | 1799 | } |
1800 | 1800 | |
@@ -1802,7 +1802,7 @@ discard block |
||
1802 | 1802 | * @see \Elgg\Application::loadCore Do not do work here. Just register for events. |
1803 | 1803 | */ |
1804 | 1804 | return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
1805 | - $events->registerHandler('cache:flush', 'system', function () { |
|
1805 | + $events->registerHandler('cache:flush', 'system', function() { |
|
1806 | 1806 | _elgg_services()->boot->invalidateCache(); |
1807 | 1807 | }); |
1808 | 1808 |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * @since 2.0.0 |
20 | 20 | */ |
21 | 21 | function elgg() { |
22 | - return Elgg\Application::$_instance; |
|
22 | + return Elgg\Application::$_instance; |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -34,12 +34,12 @@ discard block |
||
34 | 34 | * @since 1.8.0 |
35 | 35 | */ |
36 | 36 | function elgg_register_library($name, $location) { |
37 | - $libraries = _elgg_config()->libraries; |
|
38 | - if ($libraries === null) { |
|
39 | - $libraries = []; |
|
40 | - } |
|
41 | - $libraries[$name] = $location; |
|
42 | - _elgg_config()->libraries = $libraries; |
|
37 | + $libraries = _elgg_config()->libraries; |
|
38 | + if ($libraries === null) { |
|
39 | + $libraries = []; |
|
40 | + } |
|
41 | + $libraries[$name] = $location; |
|
42 | + _elgg_config()->libraries = $libraries; |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -54,25 +54,25 @@ discard block |
||
54 | 54 | * @since 1.8.0 |
55 | 55 | */ |
56 | 56 | function elgg_load_library($name) { |
57 | - static $loaded_libraries = []; |
|
57 | + static $loaded_libraries = []; |
|
58 | 58 | |
59 | - if (in_array($name, $loaded_libraries)) { |
|
60 | - return; |
|
61 | - } |
|
59 | + if (in_array($name, $loaded_libraries)) { |
|
60 | + return; |
|
61 | + } |
|
62 | 62 | |
63 | - $libraries = _elgg_config()->libraries; |
|
63 | + $libraries = _elgg_config()->libraries; |
|
64 | 64 | |
65 | - if (!isset($libraries[$name])) { |
|
66 | - $error = "$name is not a registered library"; |
|
67 | - throw new \InvalidParameterException($error); |
|
68 | - } |
|
65 | + if (!isset($libraries[$name])) { |
|
66 | + $error = "$name is not a registered library"; |
|
67 | + throw new \InvalidParameterException($error); |
|
68 | + } |
|
69 | 69 | |
70 | - if (!include_once($libraries[$name])) { |
|
71 | - $error = "Could not load the $name library from {$libraries[$name]}"; |
|
72 | - throw new \InvalidParameterException($error); |
|
73 | - } |
|
70 | + if (!include_once($libraries[$name])) { |
|
71 | + $error = "Could not load the $name library from {$libraries[$name]}"; |
|
72 | + throw new \InvalidParameterException($error); |
|
73 | + } |
|
74 | 74 | |
75 | - $loaded_libraries[] = $name; |
|
75 | + $loaded_libraries[] = $name; |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -90,13 +90,13 @@ discard block |
||
90 | 90 | * @throws SecurityException|InvalidParameterException |
91 | 91 | */ |
92 | 92 | function forward($location = "", $reason = 'system') { |
93 | - if (headers_sent($file, $line)) { |
|
94 | - throw new \SecurityException("Redirect could not be issued due to headers already being sent. Halting execution for security. " |
|
95 | - . "Output started in file $file at line $line. Search http://learn.elgg.org/ for more information."); |
|
96 | - } |
|
93 | + if (headers_sent($file, $line)) { |
|
94 | + throw new \SecurityException("Redirect could not be issued due to headers already being sent. Halting execution for security. " |
|
95 | + . "Output started in file $file at line $line. Search http://learn.elgg.org/ for more information."); |
|
96 | + } |
|
97 | 97 | |
98 | - _elgg_services()->responseFactory->redirect($location, $reason); |
|
99 | - exit; |
|
98 | + _elgg_services()->responseFactory->redirect($location, $reason); |
|
99 | + exit; |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -110,17 +110,17 @@ discard block |
||
110 | 110 | * @since 2.3 |
111 | 111 | */ |
112 | 112 | function elgg_set_http_header($header, $replace = true) { |
113 | - if (headers_sent($file, $line)) { |
|
114 | - _elgg_services()->logger->error("Cannot modify header information - headers already sent by |
|
113 | + if (headers_sent($file, $line)) { |
|
114 | + _elgg_services()->logger->error("Cannot modify header information - headers already sent by |
|
115 | 115 | (output started at $file:$line)"); |
116 | - } else { |
|
117 | - header($header, $replace); |
|
118 | - } |
|
116 | + } else { |
|
117 | + header($header, $replace); |
|
118 | + } |
|
119 | 119 | |
120 | - if (!preg_match('~^HTTP/\\d\\.\\d~', $header)) { |
|
121 | - list($name, $value) = explode(':', $header, 2); |
|
122 | - _elgg_services()->responseFactory->setHeader($name, ltrim($value), $replace); |
|
123 | - } |
|
120 | + if (!preg_match('~^HTTP/\\d\\.\\d~', $header)) { |
|
121 | + list($name, $value) = explode(':', $header, 2); |
|
122 | + _elgg_services()->responseFactory->setHeader($name, ltrim($value), $replace); |
|
123 | + } |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * @since 1.8.0 |
152 | 152 | */ |
153 | 153 | function elgg_register_js($name, $url, $location = 'head', $priority = null) { |
154 | - return elgg_register_external_file('js', $name, $url, $location, $priority); |
|
154 | + return elgg_register_external_file('js', $name, $url, $location, $priority); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -179,17 +179,17 @@ discard block |
||
179 | 179 | * @return void |
180 | 180 | */ |
181 | 181 | function elgg_define_js($name, $config) { |
182 | - $src = elgg_extract('src', $config); |
|
182 | + $src = elgg_extract('src', $config); |
|
183 | 183 | |
184 | - if ($src) { |
|
185 | - $url = elgg_normalize_url($src); |
|
186 | - _elgg_services()->amdConfig->addPath($name, $url); |
|
187 | - } |
|
184 | + if ($src) { |
|
185 | + $url = elgg_normalize_url($src); |
|
186 | + _elgg_services()->amdConfig->addPath($name, $url); |
|
187 | + } |
|
188 | 188 | |
189 | - // shimmed module |
|
190 | - if (isset($config['deps']) || isset($config['exports'])) { |
|
191 | - _elgg_services()->amdConfig->addShim($name, $config); |
|
192 | - } |
|
189 | + // shimmed module |
|
190 | + if (isset($config['deps']) || isset($config['exports'])) { |
|
191 | + _elgg_services()->amdConfig->addShim($name, $config); |
|
192 | + } |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * @since 1.8.0 |
202 | 202 | */ |
203 | 203 | function elgg_unregister_js($name) { |
204 | - return elgg_unregister_external_file('js', $name); |
|
204 | + return elgg_unregister_external_file('js', $name); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | * @since 1.8.0 |
217 | 217 | */ |
218 | 218 | function elgg_load_js($name) { |
219 | - elgg_load_external_file('js', $name); |
|
219 | + elgg_load_external_file('js', $name); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | * @since 1.9.0 |
229 | 229 | */ |
230 | 230 | function elgg_require_js($name) { |
231 | - _elgg_services()->amdConfig->addDependency($name); |
|
231 | + _elgg_services()->amdConfig->addDependency($name); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * @since 2.1.0 |
242 | 242 | */ |
243 | 243 | function elgg_unrequire_js($name) { |
244 | - _elgg_services()->amdConfig->removeDependency($name); |
|
244 | + _elgg_services()->amdConfig->removeDependency($name); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * @since 1.8.0 |
254 | 254 | */ |
255 | 255 | function elgg_get_loaded_js($location = 'head') { |
256 | - return elgg_get_loaded_external_files('js', $location); |
|
256 | + return elgg_get_loaded_external_files('js', $location); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | * @since 1.8.0 |
268 | 268 | */ |
269 | 269 | function elgg_register_css($name, $url, $priority = null) { |
270 | - return elgg_register_external_file('css', $name, $url, 'head', $priority); |
|
270 | + return elgg_register_external_file('css', $name, $url, 'head', $priority); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | * @since 1.8.0 |
280 | 280 | */ |
281 | 281 | function elgg_unregister_css($name) { |
282 | - return elgg_unregister_external_file('css', $name); |
|
282 | + return elgg_unregister_external_file('css', $name); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | * @since 1.8.0 |
295 | 295 | */ |
296 | 296 | function elgg_load_css($name) { |
297 | - elgg_load_external_file('css', $name); |
|
297 | + elgg_load_external_file('css', $name); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | /** |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | * @since 1.8.0 |
305 | 305 | */ |
306 | 306 | function elgg_get_loaded_css() { |
307 | - return elgg_get_loaded_external_files('css', 'head'); |
|
307 | + return elgg_get_loaded_external_files('css', 'head'); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | * @since 1.8.0 |
321 | 321 | */ |
322 | 322 | function elgg_register_external_file($type, $name, $url, $location, $priority = 500) { |
323 | - return _elgg_services()->externalFiles->register($type, $name, $url, $location, $priority); |
|
323 | + return _elgg_services()->externalFiles->register($type, $name, $url, $location, $priority); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | * @since 1.8.0 |
334 | 334 | */ |
335 | 335 | function elgg_unregister_external_file($type, $name) { |
336 | - return _elgg_services()->externalFiles->unregister($type, $name); |
|
336 | + return _elgg_services()->externalFiles->unregister($type, $name); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | /** |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | * @since 1.8.0 |
347 | 347 | */ |
348 | 348 | function elgg_load_external_file($type, $name) { |
349 | - _elgg_services()->externalFiles->load($type, $name); |
|
349 | + _elgg_services()->externalFiles->load($type, $name); |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | /** |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | * @since 1.8.0 |
360 | 360 | */ |
361 | 361 | function elgg_get_loaded_external_files($type, $location) { |
362 | - return _elgg_services()->externalFiles->getLoadedFiles($type, $location); |
|
362 | + return _elgg_services()->externalFiles->getLoadedFiles($type, $location); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | /** |
@@ -376,25 +376,25 @@ discard block |
||
376 | 376 | */ |
377 | 377 | function elgg_get_file_list($directory, $exceptions = [], $list = [], $extensions = null) { |
378 | 378 | |
379 | - $directory = sanitise_filepath($directory); |
|
380 | - if ($handle = opendir($directory)) { |
|
381 | - while (($file = readdir($handle)) !== false) { |
|
382 | - if (!is_file($directory . $file) || in_array($file, $exceptions)) { |
|
383 | - continue; |
|
384 | - } |
|
379 | + $directory = sanitise_filepath($directory); |
|
380 | + if ($handle = opendir($directory)) { |
|
381 | + while (($file = readdir($handle)) !== false) { |
|
382 | + if (!is_file($directory . $file) || in_array($file, $exceptions)) { |
|
383 | + continue; |
|
384 | + } |
|
385 | 385 | |
386 | - if (is_array($extensions)) { |
|
387 | - if (in_array(strrchr($file, '.'), $extensions)) { |
|
388 | - $list[] = $directory . $file; |
|
389 | - } |
|
390 | - } else { |
|
391 | - $list[] = $directory . $file; |
|
392 | - } |
|
393 | - } |
|
394 | - closedir($handle); |
|
395 | - } |
|
386 | + if (is_array($extensions)) { |
|
387 | + if (in_array(strrchr($file, '.'), $extensions)) { |
|
388 | + $list[] = $directory . $file; |
|
389 | + } |
|
390 | + } else { |
|
391 | + $list[] = $directory . $file; |
|
392 | + } |
|
393 | + } |
|
394 | + closedir($handle); |
|
395 | + } |
|
396 | 396 | |
397 | - return $list; |
|
397 | + return $list; |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | /** |
@@ -406,22 +406,22 @@ discard block |
||
406 | 406 | * @return string |
407 | 407 | */ |
408 | 408 | function sanitise_filepath($path, $append_slash = true) { |
409 | - // Convert to correct UNIX paths |
|
410 | - $path = str_replace('\\', '/', $path); |
|
411 | - $path = str_replace('../', '/', $path); |
|
412 | - // replace // with / except when preceeded by : |
|
413 | - $path = preg_replace("/([^:])\/\//", "$1/", $path); |
|
409 | + // Convert to correct UNIX paths |
|
410 | + $path = str_replace('\\', '/', $path); |
|
411 | + $path = str_replace('../', '/', $path); |
|
412 | + // replace // with / except when preceeded by : |
|
413 | + $path = preg_replace("/([^:])\/\//", "$1/", $path); |
|
414 | 414 | |
415 | - // Sort trailing slash |
|
416 | - $path = trim($path); |
|
417 | - // rtrim defaults plus / |
|
418 | - $path = rtrim($path, " \n\t\0\x0B/"); |
|
415 | + // Sort trailing slash |
|
416 | + $path = trim($path); |
|
417 | + // rtrim defaults plus / |
|
418 | + $path = rtrim($path, " \n\t\0\x0B/"); |
|
419 | 419 | |
420 | - if ($append_slash) { |
|
421 | - $path = $path . '/'; |
|
422 | - } |
|
420 | + if ($append_slash) { |
|
421 | + $path = $path . '/'; |
|
422 | + } |
|
423 | 423 | |
424 | - return $path; |
|
424 | + return $path; |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | * @return integer The number of messages |
433 | 433 | */ |
434 | 434 | function count_messages($register = "") { |
435 | - return _elgg_services()->systemMessages->count($register); |
|
435 | + return _elgg_services()->systemMessages->count($register); |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | /** |
@@ -443,8 +443,8 @@ discard block |
||
443 | 443 | * @return bool |
444 | 444 | */ |
445 | 445 | function system_message($message) { |
446 | - _elgg_services()->systemMessages->addSuccessMessage($message); |
|
447 | - return true; |
|
446 | + _elgg_services()->systemMessages->addSuccessMessage($message); |
|
447 | + return true; |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | /** |
@@ -455,8 +455,8 @@ discard block |
||
455 | 455 | * @return bool |
456 | 456 | */ |
457 | 457 | function register_error($error) { |
458 | - _elgg_services()->systemMessages->addErrorMessage($error); |
|
459 | - return true; |
|
458 | + _elgg_services()->systemMessages->addErrorMessage($error); |
|
459 | + return true; |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | /** |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | * @since 2.1 |
467 | 467 | */ |
468 | 468 | function elgg_get_system_messages() { |
469 | - return _elgg_services()->systemMessages->loadRegisters(); |
|
469 | + return _elgg_services()->systemMessages->loadRegisters(); |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | /** |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | * @since 2.1 |
478 | 478 | */ |
479 | 479 | function elgg_set_system_messages(\Elgg\SystemMessages\RegisterSet $set) { |
480 | - _elgg_services()->systemMessages->saveRegisters($set); |
|
480 | + _elgg_services()->systemMessages->saveRegisters($set); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | /** |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | * @example documentation/events/all.php |
537 | 537 | */ |
538 | 538 | function elgg_register_event_handler($event, $object_type, $callback, $priority = 500) { |
539 | - return _elgg_services()->hooks->getEvents()->registerHandler($event, $object_type, $callback, $priority); |
|
539 | + return _elgg_services()->hooks->getEvents()->registerHandler($event, $object_type, $callback, $priority); |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | /** |
@@ -550,7 +550,7 @@ discard block |
||
550 | 550 | * @since 1.7 |
551 | 551 | */ |
552 | 552 | function elgg_unregister_event_handler($event, $object_type, $callback) { |
553 | - return _elgg_services()->hooks->getEvents()->unregisterHandler($event, $object_type, $callback); |
|
553 | + return _elgg_services()->hooks->getEvents()->unregisterHandler($event, $object_type, $callback); |
|
554 | 554 | } |
555 | 555 | |
556 | 556 | /** |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | * @since 2.3 |
564 | 564 | */ |
565 | 565 | function elgg_clear_event_handlers($event, $object_type) { |
566 | - _elgg_services()->hooks->getEvents()->clearHandlers($event, $object_type); |
|
566 | + _elgg_services()->hooks->getEvents()->clearHandlers($event, $object_type); |
|
567 | 567 | } |
568 | 568 | |
569 | 569 | /** |
@@ -600,7 +600,7 @@ discard block |
||
600 | 600 | * @example documentation/examples/events/trigger.php |
601 | 601 | */ |
602 | 602 | function elgg_trigger_event($event, $object_type, $object = null) { |
603 | - return _elgg_services()->hooks->getEvents()->trigger($event, $object_type, $object); |
|
603 | + return _elgg_services()->hooks->getEvents()->trigger($event, $object_type, $object); |
|
604 | 604 | } |
605 | 605 | |
606 | 606 | /** |
@@ -621,7 +621,7 @@ discard block |
||
621 | 621 | * @see elgg_trigger_after_event |
622 | 622 | */ |
623 | 623 | function elgg_trigger_before_event($event, $object_type, $object = null) { |
624 | - return _elgg_services()->hooks->getEvents()->triggerBefore($event, $object_type, $object); |
|
624 | + return _elgg_services()->hooks->getEvents()->triggerBefore($event, $object_type, $object); |
|
625 | 625 | } |
626 | 626 | |
627 | 627 | /** |
@@ -640,7 +640,7 @@ discard block |
||
640 | 640 | * @see elgg_trigger_before_event |
641 | 641 | */ |
642 | 642 | function elgg_trigger_after_event($event, $object_type, $object = null) { |
643 | - return _elgg_services()->hooks->getEvents()->triggerAfter($event, $object_type, $object); |
|
643 | + return _elgg_services()->hooks->getEvents()->triggerAfter($event, $object_type, $object); |
|
644 | 644 | } |
645 | 645 | |
646 | 646 | /** |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | * @see elgg_trigger_event |
658 | 658 | */ |
659 | 659 | function elgg_trigger_deprecated_event($event, $object_type, $object = null, $message = null, $version = null) { |
660 | - return _elgg_services()->hooks->getEvents()->triggerDeprecated($event, $object_type, $object, $message, $version); |
|
660 | + return _elgg_services()->hooks->getEvents()->triggerDeprecated($event, $object_type, $object, $message, $version); |
|
661 | 661 | } |
662 | 662 | |
663 | 663 | /** |
@@ -721,7 +721,7 @@ discard block |
||
721 | 721 | * @since 1.8.0 |
722 | 722 | */ |
723 | 723 | function elgg_register_plugin_hook_handler($hook, $type, $callback, $priority = 500) { |
724 | - return _elgg_services()->hooks->registerHandler($hook, $type, $callback, $priority); |
|
724 | + return _elgg_services()->hooks->registerHandler($hook, $type, $callback, $priority); |
|
725 | 725 | } |
726 | 726 | |
727 | 727 | /** |
@@ -736,7 +736,7 @@ discard block |
||
736 | 736 | * @since 1.8.0 |
737 | 737 | */ |
738 | 738 | function elgg_unregister_plugin_hook_handler($hook, $entity_type, $callback) { |
739 | - _elgg_services()->hooks->unregisterHandler($hook, $entity_type, $callback); |
|
739 | + _elgg_services()->hooks->unregisterHandler($hook, $entity_type, $callback); |
|
740 | 740 | } |
741 | 741 | |
742 | 742 | /** |
@@ -749,7 +749,7 @@ discard block |
||
749 | 749 | * @since 2.0 |
750 | 750 | */ |
751 | 751 | function elgg_clear_plugin_hook_handlers($hook, $type) { |
752 | - _elgg_services()->hooks->clearHandlers($hook, $type); |
|
752 | + _elgg_services()->hooks->clearHandlers($hook, $type); |
|
753 | 753 | } |
754 | 754 | |
755 | 755 | /** |
@@ -807,7 +807,7 @@ discard block |
||
807 | 807 | * @since 1.8.0 |
808 | 808 | */ |
809 | 809 | function elgg_trigger_plugin_hook($hook, $type, $params = null, $returnvalue = null) { |
810 | - return _elgg_services()->hooks->trigger($hook, $type, $params, $returnvalue); |
|
810 | + return _elgg_services()->hooks->trigger($hook, $type, $params, $returnvalue); |
|
811 | 811 | } |
812 | 812 | |
813 | 813 | /** |
@@ -821,7 +821,7 @@ discard block |
||
821 | 821 | * @since 2.0.0 |
822 | 822 | */ |
823 | 823 | function elgg_get_ordered_hook_handlers($hook, $type) { |
824 | - return _elgg_services()->hooks->getOrderedHandlers($hook, $type); |
|
824 | + return _elgg_services()->hooks->getOrderedHandlers($hook, $type); |
|
825 | 825 | } |
826 | 826 | |
827 | 827 | /** |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | * @since 2.0.0 |
836 | 836 | */ |
837 | 837 | function elgg_get_ordered_event_handlers($event, $type) { |
838 | - return _elgg_services()->hooks->getEvents()->getOrderedHandlers($event, $type); |
|
838 | + return _elgg_services()->hooks->getEvents()->getOrderedHandlers($event, $type); |
|
839 | 839 | } |
840 | 840 | |
841 | 841 | /** |
@@ -856,19 +856,19 @@ discard block |
||
856 | 856 | * @since 1.7.0 |
857 | 857 | */ |
858 | 858 | function elgg_log($message, $level = 'NOTICE') { |
859 | - static $levels = [ |
|
860 | - 'INFO' => 200, |
|
861 | - 'NOTICE' => 250, |
|
862 | - 'WARNING' => 300, |
|
863 | - 'ERROR' => 400, |
|
864 | - ]; |
|
859 | + static $levels = [ |
|
860 | + 'INFO' => 200, |
|
861 | + 'NOTICE' => 250, |
|
862 | + 'WARNING' => 300, |
|
863 | + 'ERROR' => 400, |
|
864 | + ]; |
|
865 | 865 | |
866 | - if (!isset($levels[$level])) { |
|
867 | - throw new \InvalidArgumentException("Invalid \$level value"); |
|
868 | - } |
|
866 | + if (!isset($levels[$level])) { |
|
867 | + throw new \InvalidArgumentException("Invalid \$level value"); |
|
868 | + } |
|
869 | 869 | |
870 | - $level = $levels[$level]; |
|
871 | - return _elgg_services()->logger->log($message, $level); |
|
870 | + $level = $levels[$level]; |
|
871 | + return _elgg_services()->logger->log($message, $level); |
|
872 | 872 | } |
873 | 873 | |
874 | 874 | /** |
@@ -886,7 +886,7 @@ discard block |
||
886 | 886 | * @since 1.7.0 |
887 | 887 | */ |
888 | 888 | function elgg_dump($value, $to_screen = true) { |
889 | - _elgg_services()->logger->dump($value, $to_screen); |
|
889 | + _elgg_services()->logger->dump($value, $to_screen); |
|
890 | 890 | } |
891 | 891 | |
892 | 892 | /** |
@@ -898,17 +898,17 @@ discard block |
||
898 | 898 | * @since 1.9 |
899 | 899 | */ |
900 | 900 | function elgg_get_version($human_readable = false) { |
901 | - static $version, $release; |
|
901 | + static $version, $release; |
|
902 | 902 | |
903 | - if (!isset($version) || !isset($release)) { |
|
904 | - $path = \Elgg\Application::elggDir()->getPath('version.php'); |
|
905 | - if (!is_file($path)) { |
|
906 | - return false; |
|
907 | - } |
|
908 | - include $path; |
|
909 | - } |
|
903 | + if (!isset($version) || !isset($release)) { |
|
904 | + $path = \Elgg\Application::elggDir()->getPath('version.php'); |
|
905 | + if (!is_file($path)) { |
|
906 | + return false; |
|
907 | + } |
|
908 | + include $path; |
|
909 | + } |
|
910 | 910 | |
911 | - return $human_readable ? $release : $version; |
|
911 | + return $human_readable ? $release : $version; |
|
912 | 912 | } |
913 | 913 | |
914 | 914 | /** |
@@ -925,8 +925,8 @@ discard block |
||
925 | 925 | * @since 1.7.0 |
926 | 926 | */ |
927 | 927 | function elgg_deprecated_notice($msg, $dep_version, $backtrace_level = 1) { |
928 | - $backtrace_level += 1; |
|
929 | - return _elgg_services()->deprecation->sendNotice($msg, $dep_version, $backtrace_level); |
|
928 | + $backtrace_level += 1; |
|
929 | + return _elgg_services()->deprecation->sendNotice($msg, $dep_version, $backtrace_level); |
|
930 | 930 | } |
931 | 931 | |
932 | 932 | /** |
@@ -943,21 +943,21 @@ discard block |
||
943 | 943 | * @since 1.7.0 |
944 | 944 | */ |
945 | 945 | function elgg_http_build_url(array $parts, $html_encode = true) { |
946 | - // build only what's given to us. |
|
947 | - $scheme = isset($parts['scheme']) ? "{$parts['scheme']}://" : ''; |
|
948 | - $host = isset($parts['host']) ? "{$parts['host']}" : ''; |
|
949 | - $port = isset($parts['port']) ? ":{$parts['port']}" : ''; |
|
950 | - $path = isset($parts['path']) ? "{$parts['path']}" : ''; |
|
951 | - $query = isset($parts['query']) ? "?{$parts['query']}" : ''; |
|
952 | - $fragment = isset($parts['fragment']) ? "#{$parts['fragment']}" : ''; |
|
946 | + // build only what's given to us. |
|
947 | + $scheme = isset($parts['scheme']) ? "{$parts['scheme']}://" : ''; |
|
948 | + $host = isset($parts['host']) ? "{$parts['host']}" : ''; |
|
949 | + $port = isset($parts['port']) ? ":{$parts['port']}" : ''; |
|
950 | + $path = isset($parts['path']) ? "{$parts['path']}" : ''; |
|
951 | + $query = isset($parts['query']) ? "?{$parts['query']}" : ''; |
|
952 | + $fragment = isset($parts['fragment']) ? "#{$parts['fragment']}" : ''; |
|
953 | 953 | |
954 | - $string = $scheme . $host . $port . $path . $query . $fragment; |
|
954 | + $string = $scheme . $host . $port . $path . $query . $fragment; |
|
955 | 955 | |
956 | - if ($html_encode) { |
|
957 | - return htmlspecialchars($string, ENT_QUOTES, 'UTF-8', false); |
|
958 | - } else { |
|
959 | - return $string; |
|
960 | - } |
|
956 | + if ($html_encode) { |
|
957 | + return htmlspecialchars($string, ENT_QUOTES, 'UTF-8', false); |
|
958 | + } else { |
|
959 | + return $string; |
|
960 | + } |
|
961 | 961 | } |
962 | 962 | |
963 | 963 | /** |
@@ -978,26 +978,26 @@ discard block |
||
978 | 978 | * @since 1.7.0 |
979 | 979 | */ |
980 | 980 | function elgg_add_action_tokens_to_url($url, $html_encode = false) { |
981 | - $url = elgg_normalize_url($url); |
|
982 | - $components = parse_url($url); |
|
981 | + $url = elgg_normalize_url($url); |
|
982 | + $components = parse_url($url); |
|
983 | 983 | |
984 | - if (isset($components['query'])) { |
|
985 | - $query = elgg_parse_str($components['query']); |
|
986 | - } else { |
|
987 | - $query = []; |
|
988 | - } |
|
984 | + if (isset($components['query'])) { |
|
985 | + $query = elgg_parse_str($components['query']); |
|
986 | + } else { |
|
987 | + $query = []; |
|
988 | + } |
|
989 | 989 | |
990 | - if (isset($query['__elgg_ts']) && isset($query['__elgg_token'])) { |
|
991 | - return $url; |
|
992 | - } |
|
990 | + if (isset($query['__elgg_ts']) && isset($query['__elgg_token'])) { |
|
991 | + return $url; |
|
992 | + } |
|
993 | 993 | |
994 | - // append action tokens to the existing query |
|
995 | - $query['__elgg_ts'] = time(); |
|
996 | - $query['__elgg_token'] = generate_action_token($query['__elgg_ts']); |
|
997 | - $components['query'] = http_build_query($query); |
|
994 | + // append action tokens to the existing query |
|
995 | + $query['__elgg_ts'] = time(); |
|
996 | + $query['__elgg_token'] = generate_action_token($query['__elgg_ts']); |
|
997 | + $components['query'] = http_build_query($query); |
|
998 | 998 | |
999 | - // rebuild the full url |
|
1000 | - return elgg_http_build_url($components, $html_encode); |
|
999 | + // rebuild the full url |
|
1000 | + return elgg_http_build_url($components, $html_encode); |
|
1001 | 1001 | } |
1002 | 1002 | |
1003 | 1003 | /** |
@@ -1012,7 +1012,7 @@ discard block |
||
1012 | 1012 | * @since 1.7.0 |
1013 | 1013 | */ |
1014 | 1014 | function elgg_http_remove_url_query_element($url, $element) { |
1015 | - return elgg_http_add_url_query_elements($url, [$element => null]); |
|
1015 | + return elgg_http_add_url_query_elements($url, [$element => null]); |
|
1016 | 1016 | } |
1017 | 1017 | |
1018 | 1018 | /** |
@@ -1026,38 +1026,38 @@ discard block |
||
1026 | 1026 | * @since 1.7.0 |
1027 | 1027 | */ |
1028 | 1028 | function elgg_http_add_url_query_elements($url, array $elements) { |
1029 | - $url_array = parse_url($url); |
|
1030 | - |
|
1031 | - if (isset($url_array['query'])) { |
|
1032 | - $query = elgg_parse_str($url_array['query']); |
|
1033 | - } else { |
|
1034 | - $query = []; |
|
1035 | - } |
|
1036 | - |
|
1037 | - foreach ($elements as $k => $v) { |
|
1038 | - if ($v === null) { |
|
1039 | - unset($query[$k]); |
|
1040 | - } else { |
|
1041 | - $query[$k] = $v; |
|
1042 | - } |
|
1043 | - } |
|
1044 | - |
|
1045 | - // why check path? A: if no path, this may be a relative URL like "?foo=1". In this case, |
|
1046 | - // the output "" would be interpreted the current URL, so in this case we *must* set |
|
1047 | - // a query to make sure elements are removed. |
|
1048 | - if ($query || empty($url_array['path'])) { |
|
1049 | - $url_array['query'] = http_build_query($query); |
|
1050 | - } else { |
|
1051 | - unset($url_array['query']); |
|
1052 | - } |
|
1053 | - $string = elgg_http_build_url($url_array, false); |
|
1054 | - |
|
1055 | - // Restore relative protocol to url if missing and is provided as part of the initial url (see #9874) |
|
1056 | - if (!isset($url['scheme']) && (substr($url, 0, 2) == '//')) { |
|
1057 | - $string = "//{$string}"; |
|
1058 | - } |
|
1029 | + $url_array = parse_url($url); |
|
1030 | + |
|
1031 | + if (isset($url_array['query'])) { |
|
1032 | + $query = elgg_parse_str($url_array['query']); |
|
1033 | + } else { |
|
1034 | + $query = []; |
|
1035 | + } |
|
1036 | + |
|
1037 | + foreach ($elements as $k => $v) { |
|
1038 | + if ($v === null) { |
|
1039 | + unset($query[$k]); |
|
1040 | + } else { |
|
1041 | + $query[$k] = $v; |
|
1042 | + } |
|
1043 | + } |
|
1044 | + |
|
1045 | + // why check path? A: if no path, this may be a relative URL like "?foo=1". In this case, |
|
1046 | + // the output "" would be interpreted the current URL, so in this case we *must* set |
|
1047 | + // a query to make sure elements are removed. |
|
1048 | + if ($query || empty($url_array['path'])) { |
|
1049 | + $url_array['query'] = http_build_query($query); |
|
1050 | + } else { |
|
1051 | + unset($url_array['query']); |
|
1052 | + } |
|
1053 | + $string = elgg_http_build_url($url_array, false); |
|
1054 | + |
|
1055 | + // Restore relative protocol to url if missing and is provided as part of the initial url (see #9874) |
|
1056 | + if (!isset($url['scheme']) && (substr($url, 0, 2) == '//')) { |
|
1057 | + $string = "//{$string}"; |
|
1058 | + } |
|
1059 | 1059 | |
1060 | - return $string; |
|
1060 | + return $string; |
|
1061 | 1061 | } |
1062 | 1062 | |
1063 | 1063 | /** |
@@ -1075,83 +1075,83 @@ discard block |
||
1075 | 1075 | * @since 1.8.0 |
1076 | 1076 | */ |
1077 | 1077 | function elgg_http_url_is_identical($url1, $url2, $ignore_params = ['offset', 'limit']) { |
1078 | - $url1 = elgg_normalize_url($url1); |
|
1079 | - $url2 = elgg_normalize_url($url2); |
|
1080 | - |
|
1081 | - // @todo - should probably do something with relative URLs |
|
1082 | - |
|
1083 | - if ($url1 == $url2) { |
|
1084 | - return true; |
|
1085 | - } |
|
1086 | - |
|
1087 | - $url1_info = parse_url($url1); |
|
1088 | - $url2_info = parse_url($url2); |
|
1089 | - |
|
1090 | - if (isset($url1_info['path'])) { |
|
1091 | - $url1_info['path'] = trim($url1_info['path'], '/'); |
|
1092 | - } |
|
1093 | - if (isset($url2_info['path'])) { |
|
1094 | - $url2_info['path'] = trim($url2_info['path'], '/'); |
|
1095 | - } |
|
1096 | - |
|
1097 | - // compare basic bits |
|
1098 | - $parts = ['scheme', 'host', 'path']; |
|
1099 | - |
|
1100 | - foreach ($parts as $part) { |
|
1101 | - if ((isset($url1_info[$part]) && isset($url2_info[$part])) |
|
1102 | - && $url1_info[$part] != $url2_info[$part]) { |
|
1103 | - return false; |
|
1104 | - } elseif (isset($url1_info[$part]) && !isset($url2_info[$part])) { |
|
1105 | - return false; |
|
1106 | - } elseif (!isset($url1_info[$part]) && isset($url2_info[$part])) { |
|
1107 | - return false; |
|
1108 | - } |
|
1109 | - } |
|
1110 | - |
|
1111 | - // quick compare of get params |
|
1112 | - if (isset($url1_info['query']) && isset($url2_info['query']) |
|
1113 | - && $url1_info['query'] == $url2_info['query']) { |
|
1114 | - return true; |
|
1115 | - } |
|
1116 | - |
|
1117 | - // compare get params that might be out of order |
|
1118 | - $url1_params = []; |
|
1119 | - $url2_params = []; |
|
1120 | - |
|
1121 | - if (isset($url1_info['query'])) { |
|
1122 | - if ($url1_info['query'] = html_entity_decode($url1_info['query'])) { |
|
1123 | - $url1_params = elgg_parse_str($url1_info['query']); |
|
1124 | - } |
|
1125 | - } |
|
1126 | - |
|
1127 | - if (isset($url2_info['query'])) { |
|
1128 | - if ($url2_info['query'] = html_entity_decode($url2_info['query'])) { |
|
1129 | - $url2_params = elgg_parse_str($url2_info['query']); |
|
1130 | - } |
|
1131 | - } |
|
1132 | - |
|
1133 | - // drop ignored params |
|
1134 | - foreach ($ignore_params as $param) { |
|
1135 | - if (isset($url1_params[$param])) { |
|
1136 | - unset($url1_params[$param]); |
|
1137 | - } |
|
1138 | - if (isset($url2_params[$param])) { |
|
1139 | - unset($url2_params[$param]); |
|
1140 | - } |
|
1141 | - } |
|
1142 | - |
|
1143 | - // array_diff_assoc only returns the items in arr1 that aren't in arrN |
|
1144 | - // but not the items that ARE in arrN but NOT in arr1 |
|
1145 | - // if arr1 is an empty array, this function will return 0 no matter what. |
|
1146 | - // since we only care if they're different and not how different, |
|
1147 | - // add the results together to get a non-zero (ie, different) result |
|
1148 | - $diff_count = count(array_diff_assoc($url1_params, $url2_params)); |
|
1149 | - $diff_count += count(array_diff_assoc($url2_params, $url1_params)); |
|
1150 | - if ($diff_count > 0) { |
|
1151 | - return false; |
|
1152 | - } |
|
1153 | - |
|
1154 | - return true; |
|
1078 | + $url1 = elgg_normalize_url($url1); |
|
1079 | + $url2 = elgg_normalize_url($url2); |
|
1080 | + |
|
1081 | + // @todo - should probably do something with relative URLs |
|
1082 | + |
|
1083 | + if ($url1 == $url2) { |
|
1084 | + return true; |
|
1085 | + } |
|
1086 | + |
|
1087 | + $url1_info = parse_url($url1); |
|
1088 | + $url2_info = parse_url($url2); |
|
1089 | + |
|
1090 | + if (isset($url1_info['path'])) { |
|
1091 | + $url1_info['path'] = trim($url1_info['path'], '/'); |
|
1092 | + } |
|
1093 | + if (isset($url2_info['path'])) { |
|
1094 | + $url2_info['path'] = trim($url2_info['path'], '/'); |
|
1095 | + } |
|
1096 | + |
|
1097 | + // compare basic bits |
|
1098 | + $parts = ['scheme', 'host', 'path']; |
|
1099 | + |
|
1100 | + foreach ($parts as $part) { |
|
1101 | + if ((isset($url1_info[$part]) && isset($url2_info[$part])) |
|
1102 | + && $url1_info[$part] != $url2_info[$part]) { |
|
1103 | + return false; |
|
1104 | + } elseif (isset($url1_info[$part]) && !isset($url2_info[$part])) { |
|
1105 | + return false; |
|
1106 | + } elseif (!isset($url1_info[$part]) && isset($url2_info[$part])) { |
|
1107 | + return false; |
|
1108 | + } |
|
1109 | + } |
|
1110 | + |
|
1111 | + // quick compare of get params |
|
1112 | + if (isset($url1_info['query']) && isset($url2_info['query']) |
|
1113 | + && $url1_info['query'] == $url2_info['query']) { |
|
1114 | + return true; |
|
1115 | + } |
|
1116 | + |
|
1117 | + // compare get params that might be out of order |
|
1118 | + $url1_params = []; |
|
1119 | + $url2_params = []; |
|
1120 | + |
|
1121 | + if (isset($url1_info['query'])) { |
|
1122 | + if ($url1_info['query'] = html_entity_decode($url1_info['query'])) { |
|
1123 | + $url1_params = elgg_parse_str($url1_info['query']); |
|
1124 | + } |
|
1125 | + } |
|
1126 | + |
|
1127 | + if (isset($url2_info['query'])) { |
|
1128 | + if ($url2_info['query'] = html_entity_decode($url2_info['query'])) { |
|
1129 | + $url2_params = elgg_parse_str($url2_info['query']); |
|
1130 | + } |
|
1131 | + } |
|
1132 | + |
|
1133 | + // drop ignored params |
|
1134 | + foreach ($ignore_params as $param) { |
|
1135 | + if (isset($url1_params[$param])) { |
|
1136 | + unset($url1_params[$param]); |
|
1137 | + } |
|
1138 | + if (isset($url2_params[$param])) { |
|
1139 | + unset($url2_params[$param]); |
|
1140 | + } |
|
1141 | + } |
|
1142 | + |
|
1143 | + // array_diff_assoc only returns the items in arr1 that aren't in arrN |
|
1144 | + // but not the items that ARE in arrN but NOT in arr1 |
|
1145 | + // if arr1 is an empty array, this function will return 0 no matter what. |
|
1146 | + // since we only care if they're different and not how different, |
|
1147 | + // add the results together to get a non-zero (ie, different) result |
|
1148 | + $diff_count = count(array_diff_assoc($url1_params, $url2_params)); |
|
1149 | + $diff_count += count(array_diff_assoc($url2_params, $url1_params)); |
|
1150 | + if ($diff_count > 0) { |
|
1151 | + return false; |
|
1152 | + } |
|
1153 | + |
|
1154 | + return true; |
|
1155 | 1155 | } |
1156 | 1156 | |
1157 | 1157 | /** |
@@ -1166,7 +1166,7 @@ discard block |
||
1166 | 1166 | * @return string |
1167 | 1167 | */ |
1168 | 1168 | function elgg_http_get_signed_url($url, $expires = false) { |
1169 | - return _elgg_services()->urlSigner->sign($url, $expires); |
|
1169 | + return _elgg_services()->urlSigner->sign($url, $expires); |
|
1170 | 1170 | } |
1171 | 1171 | |
1172 | 1172 | /** |
@@ -1176,7 +1176,7 @@ discard block |
||
1176 | 1176 | * @return bool |
1177 | 1177 | */ |
1178 | 1178 | function elgg_http_validate_signed_url($url) { |
1179 | - return _elgg_services()->urlSigner->isValid($url); |
|
1179 | + return _elgg_services()->urlSigner->isValid($url); |
|
1180 | 1180 | } |
1181 | 1181 | |
1182 | 1182 | /** |
@@ -1185,10 +1185,10 @@ discard block |
||
1185 | 1185 | * @return void |
1186 | 1186 | */ |
1187 | 1187 | function elgg_signed_request_gatekeeper() { |
1188 | - if (!elgg_http_validate_signed_url(current_page_url())) { |
|
1189 | - register_error(elgg_echo('invalid_request_signature')); |
|
1190 | - forward('', '403'); |
|
1191 | - } |
|
1188 | + if (!elgg_http_validate_signed_url(current_page_url())) { |
|
1189 | + register_error(elgg_echo('invalid_request_signature')); |
|
1190 | + forward('', '403'); |
|
1191 | + } |
|
1192 | 1192 | } |
1193 | 1193 | |
1194 | 1194 | /** |
@@ -1207,15 +1207,15 @@ discard block |
||
1207 | 1207 | * @since 1.8.0 |
1208 | 1208 | */ |
1209 | 1209 | function elgg_extract($key, $array, $default = null, $strict = true) { |
1210 | - if (!is_array($array)) { |
|
1211 | - return $default; |
|
1212 | - } |
|
1210 | + if (!is_array($array)) { |
|
1211 | + return $default; |
|
1212 | + } |
|
1213 | 1213 | |
1214 | - if ($strict) { |
|
1215 | - return (isset($array[$key])) ? $array[$key] : $default; |
|
1216 | - } else { |
|
1217 | - return (isset($array[$key]) && !empty($array[$key])) ? $array[$key] : $default; |
|
1218 | - } |
|
1214 | + if ($strict) { |
|
1215 | + return (isset($array[$key])) ? $array[$key] : $default; |
|
1216 | + } else { |
|
1217 | + return (isset($array[$key]) && !empty($array[$key])) ? $array[$key] : $default; |
|
1218 | + } |
|
1219 | 1219 | } |
1220 | 1220 | |
1221 | 1221 | /** |
@@ -1228,13 +1228,13 @@ discard block |
||
1228 | 1228 | * @since 2.3.0 |
1229 | 1229 | */ |
1230 | 1230 | function elgg_extract_class(array $array, $existing = []) { |
1231 | - $existing = empty($existing) ? [] : (array) $existing; |
|
1231 | + $existing = empty($existing) ? [] : (array) $existing; |
|
1232 | 1232 | |
1233 | - $merge = (array) elgg_extract('class', $array, []); |
|
1233 | + $merge = (array) elgg_extract('class', $array, []); |
|
1234 | 1234 | |
1235 | - array_splice($existing, count($existing), 0, $merge); |
|
1235 | + array_splice($existing, count($existing), 0, $merge); |
|
1236 | 1236 | |
1237 | - return array_values(array_unique($existing)); |
|
1237 | + return array_values(array_unique($existing)); |
|
1238 | 1238 | } |
1239 | 1239 | |
1240 | 1240 | /** |
@@ -1259,17 +1259,17 @@ discard block |
||
1259 | 1259 | */ |
1260 | 1260 | function elgg_sort_3d_array_by_value(&$array, $element, $sort_order = SORT_ASC, $sort_type = SORT_LOCALE_STRING) { |
1261 | 1261 | |
1262 | - $sort = []; |
|
1262 | + $sort = []; |
|
1263 | 1263 | |
1264 | - foreach ($array as $v) { |
|
1265 | - if (isset($v[$element])) { |
|
1266 | - $sort[] = strtolower($v[$element]); |
|
1267 | - } else { |
|
1268 | - $sort[] = null; |
|
1269 | - } |
|
1270 | - }; |
|
1264 | + foreach ($array as $v) { |
|
1265 | + if (isset($v[$element])) { |
|
1266 | + $sort[] = strtolower($v[$element]); |
|
1267 | + } else { |
|
1268 | + $sort[] = null; |
|
1269 | + } |
|
1270 | + }; |
|
1271 | 1271 | |
1272 | - return array_multisort($sort, $sort_order, $sort_type, $array); |
|
1272 | + return array_multisort($sort, $sort_order, $sort_type, $array); |
|
1273 | 1273 | } |
1274 | 1274 | |
1275 | 1275 | /** |
@@ -1283,12 +1283,12 @@ discard block |
||
1283 | 1283 | * @return bool Depending on whether it's on or off |
1284 | 1284 | */ |
1285 | 1285 | function ini_get_bool($ini_get_arg) { |
1286 | - $temp = strtolower(ini_get($ini_get_arg)); |
|
1286 | + $temp = strtolower(ini_get($ini_get_arg)); |
|
1287 | 1287 | |
1288 | - if ($temp == '1' || $temp == 'on' || $temp == 'true') { |
|
1289 | - return true; |
|
1290 | - } |
|
1291 | - return false; |
|
1288 | + if ($temp == '1' || $temp == 'on' || $temp == 'true') { |
|
1289 | + return true; |
|
1290 | + } |
|
1291 | + return false; |
|
1292 | 1292 | } |
1293 | 1293 | |
1294 | 1294 | /** |
@@ -1303,28 +1303,28 @@ discard block |
||
1303 | 1303 | * @link http://www.php.net/manual/en/function.ini-get.php |
1304 | 1304 | */ |
1305 | 1305 | function elgg_get_ini_setting_in_bytes($setting) { |
1306 | - // retrieve INI setting |
|
1307 | - $val = ini_get($setting); |
|
1308 | - |
|
1309 | - // convert INI setting when shorthand notation is used |
|
1310 | - $last = strtolower($val[strlen($val) - 1]); |
|
1311 | - if (in_array($last, ['g', 'm', 'k'])) { |
|
1312 | - $val = substr($val, 0, -1); |
|
1313 | - } |
|
1314 | - $val = (int) $val; |
|
1315 | - switch ($last) { |
|
1316 | - case 'g': |
|
1317 | - $val *= 1024; |
|
1318 | - // fallthrough intentional |
|
1319 | - case 'm': |
|
1320 | - $val *= 1024; |
|
1321 | - // fallthrough intentional |
|
1322 | - case 'k': |
|
1323 | - $val *= 1024; |
|
1324 | - } |
|
1325 | - |
|
1326 | - // return byte value |
|
1327 | - return $val; |
|
1306 | + // retrieve INI setting |
|
1307 | + $val = ini_get($setting); |
|
1308 | + |
|
1309 | + // convert INI setting when shorthand notation is used |
|
1310 | + $last = strtolower($val[strlen($val) - 1]); |
|
1311 | + if (in_array($last, ['g', 'm', 'k'])) { |
|
1312 | + $val = substr($val, 0, -1); |
|
1313 | + } |
|
1314 | + $val = (int) $val; |
|
1315 | + switch ($last) { |
|
1316 | + case 'g': |
|
1317 | + $val *= 1024; |
|
1318 | + // fallthrough intentional |
|
1319 | + case 'm': |
|
1320 | + $val *= 1024; |
|
1321 | + // fallthrough intentional |
|
1322 | + case 'k': |
|
1323 | + $val *= 1024; |
|
1324 | + } |
|
1325 | + |
|
1326 | + // return byte value |
|
1327 | + return $val; |
|
1328 | 1328 | } |
1329 | 1329 | |
1330 | 1330 | /** |
@@ -1338,11 +1338,11 @@ discard block |
||
1338 | 1338 | * @todo This is used once in metadata.php. Use a lambda function instead. |
1339 | 1339 | */ |
1340 | 1340 | function is_not_null($string) { |
1341 | - if (($string === '') || ($string === false) || ($string === null)) { |
|
1342 | - return false; |
|
1343 | - } |
|
1341 | + if (($string === '') || ($string === false) || ($string === null)) { |
|
1342 | + return false; |
|
1343 | + } |
|
1344 | 1344 | |
1345 | - return true; |
|
1345 | + return true; |
|
1346 | 1346 | } |
1347 | 1347 | |
1348 | 1348 | /** |
@@ -1359,26 +1359,26 @@ discard block |
||
1359 | 1359 | * @access private |
1360 | 1360 | */ |
1361 | 1361 | function _elgg_normalize_plural_options_array($options, $singulars) { |
1362 | - foreach ($singulars as $singular) { |
|
1363 | - $plural = $singular . 's'; |
|
1362 | + foreach ($singulars as $singular) { |
|
1363 | + $plural = $singular . 's'; |
|
1364 | 1364 | |
1365 | - if (array_key_exists($singular, $options)) { |
|
1366 | - if ($options[$singular] === ELGG_ENTITIES_ANY_VALUE) { |
|
1367 | - $options[$plural] = $options[$singular]; |
|
1368 | - } else { |
|
1369 | - // Test for array refs #2641 |
|
1370 | - if (!is_array($options[$singular])) { |
|
1371 | - $options[$plural] = [$options[$singular]]; |
|
1372 | - } else { |
|
1373 | - $options[$plural] = $options[$singular]; |
|
1374 | - } |
|
1375 | - } |
|
1376 | - } |
|
1365 | + if (array_key_exists($singular, $options)) { |
|
1366 | + if ($options[$singular] === ELGG_ENTITIES_ANY_VALUE) { |
|
1367 | + $options[$plural] = $options[$singular]; |
|
1368 | + } else { |
|
1369 | + // Test for array refs #2641 |
|
1370 | + if (!is_array($options[$singular])) { |
|
1371 | + $options[$plural] = [$options[$singular]]; |
|
1372 | + } else { |
|
1373 | + $options[$plural] = $options[$singular]; |
|
1374 | + } |
|
1375 | + } |
|
1376 | + } |
|
1377 | 1377 | |
1378 | - unset($options[$singular]); |
|
1379 | - } |
|
1378 | + unset($options[$singular]); |
|
1379 | + } |
|
1380 | 1380 | |
1381 | - return $options; |
|
1381 | + return $options; |
|
1382 | 1382 | } |
1383 | 1383 | |
1384 | 1384 | /** |
@@ -1399,23 +1399,23 @@ discard block |
||
1399 | 1399 | * @access private |
1400 | 1400 | */ |
1401 | 1401 | function _elgg_shutdown_hook() { |
1402 | - try { |
|
1403 | - _elgg_services()->logger->setDisplay(false); |
|
1404 | - elgg_trigger_event('shutdown', 'system'); |
|
1402 | + try { |
|
1403 | + _elgg_services()->logger->setDisplay(false); |
|
1404 | + elgg_trigger_event('shutdown', 'system'); |
|
1405 | 1405 | |
1406 | - $time = (float) (microtime(true) - $GLOBALS['START_MICROTIME']); |
|
1407 | - $uri = _elgg_services()->request->server->get('REQUEST_URI', 'CLI'); |
|
1408 | - // demoted to NOTICE from DEBUG so javascript is not corrupted |
|
1409 | - elgg_log("Page {$uri} generated in $time seconds", 'INFO'); |
|
1410 | - } catch (Exception $e) { |
|
1411 | - $message = 'Error: ' . get_class($e) . ' thrown within the shutdown handler. '; |
|
1412 | - $message .= "Message: '{$e->getMessage()}' in file {$e->getFile()} (line {$e->getLine()})"; |
|
1413 | - error_log($message); |
|
1414 | - error_log("Exception trace stack: {$e->getTraceAsString()}"); |
|
1415 | - } |
|
1406 | + $time = (float) (microtime(true) - $GLOBALS['START_MICROTIME']); |
|
1407 | + $uri = _elgg_services()->request->server->get('REQUEST_URI', 'CLI'); |
|
1408 | + // demoted to NOTICE from DEBUG so javascript is not corrupted |
|
1409 | + elgg_log("Page {$uri} generated in $time seconds", 'INFO'); |
|
1410 | + } catch (Exception $e) { |
|
1411 | + $message = 'Error: ' . get_class($e) . ' thrown within the shutdown handler. '; |
|
1412 | + $message .= "Message: '{$e->getMessage()}' in file {$e->getFile()} (line {$e->getLine()})"; |
|
1413 | + error_log($message); |
|
1414 | + error_log("Exception trace stack: {$e->getTraceAsString()}"); |
|
1415 | + } |
|
1416 | 1416 | |
1417 | - // Prevent an APC session bug: https://bugs.php.net/bug.php?id=60657 |
|
1418 | - session_write_close(); |
|
1417 | + // Prevent an APC session bug: https://bugs.php.net/bug.php?id=60657 |
|
1418 | + session_write_close(); |
|
1419 | 1419 | } |
1420 | 1420 | |
1421 | 1421 | /** |
@@ -1432,71 +1432,71 @@ discard block |
||
1432 | 1432 | * @access private |
1433 | 1433 | */ |
1434 | 1434 | function _elgg_ajax_page_handler($segments) { |
1435 | - elgg_ajax_gatekeeper(); |
|
1436 | - |
|
1437 | - if (count($segments) < 2) { |
|
1438 | - return false; |
|
1439 | - } |
|
1440 | - |
|
1441 | - if ($segments[0] === 'view' || $segments[0] === 'form') { |
|
1442 | - if ($segments[0] === 'view') { |
|
1443 | - // ignore 'view/' |
|
1444 | - $view = implode('/', array_slice($segments, 1)); |
|
1445 | - } else { |
|
1446 | - // form views start with "forms", not "form" |
|
1447 | - $view = 'forms/' . implode('/', array_slice($segments, 1)); |
|
1448 | - } |
|
1449 | - |
|
1450 | - $ajax_api = _elgg_services()->ajax; |
|
1451 | - $allowed_views = $ajax_api->getViews(); |
|
1435 | + elgg_ajax_gatekeeper(); |
|
1436 | + |
|
1437 | + if (count($segments) < 2) { |
|
1438 | + return false; |
|
1439 | + } |
|
1440 | + |
|
1441 | + if ($segments[0] === 'view' || $segments[0] === 'form') { |
|
1442 | + if ($segments[0] === 'view') { |
|
1443 | + // ignore 'view/' |
|
1444 | + $view = implode('/', array_slice($segments, 1)); |
|
1445 | + } else { |
|
1446 | + // form views start with "forms", not "form" |
|
1447 | + $view = 'forms/' . implode('/', array_slice($segments, 1)); |
|
1448 | + } |
|
1449 | + |
|
1450 | + $ajax_api = _elgg_services()->ajax; |
|
1451 | + $allowed_views = $ajax_api->getViews(); |
|
1452 | 1452 | |
1453 | - // cacheable views are always allowed |
|
1454 | - if (!in_array($view, $allowed_views) && !_elgg_services()->views->isCacheableView($view)) { |
|
1455 | - return elgg_error_response("Ajax view '$view' was not registered", REFERRER, ELGG_HTTP_FORBIDDEN); |
|
1456 | - } |
|
1457 | - |
|
1458 | - // pull out GET parameters through filter |
|
1459 | - $vars = []; |
|
1460 | - foreach (_elgg_services()->request->query->keys() as $name) { |
|
1461 | - $vars[$name] = get_input($name); |
|
1462 | - } |
|
1463 | - |
|
1464 | - if (isset($vars['guid'])) { |
|
1465 | - $vars['entity'] = get_entity($vars['guid']); |
|
1466 | - } |
|
1467 | - |
|
1468 | - $content_type = ''; |
|
1469 | - if ($segments[0] === 'view') { |
|
1470 | - $output = elgg_view($view, $vars); |
|
1471 | - |
|
1472 | - // Try to guess the mime-type |
|
1473 | - switch ($segments[1]) { |
|
1474 | - case "js": |
|
1475 | - $content_type = 'text/javascript;charset=utf-8'; |
|
1476 | - break; |
|
1477 | - case "css": |
|
1478 | - $content_type = 'text/css;charset=utf-8'; |
|
1479 | - break; |
|
1480 | - default : |
|
1481 | - if (_elgg_services()->views->isCacheableView($view)) { |
|
1482 | - $file = _elgg_services()->views->findViewFile($view, elgg_get_viewtype()); |
|
1483 | - $content_type = (new \Elgg\Filesystem\MimeTypeDetector())->getType($file, 'text/html'); |
|
1484 | - } |
|
1485 | - break; |
|
1486 | - } |
|
1487 | - } else { |
|
1488 | - $action = implode('/', array_slice($segments, 1)); |
|
1489 | - $output = elgg_view_form($action, [], $vars); |
|
1490 | - } |
|
1491 | - |
|
1492 | - if ($content_type) { |
|
1493 | - elgg_set_http_header("Content-Type: $content_type"); |
|
1494 | - } |
|
1453 | + // cacheable views are always allowed |
|
1454 | + if (!in_array($view, $allowed_views) && !_elgg_services()->views->isCacheableView($view)) { |
|
1455 | + return elgg_error_response("Ajax view '$view' was not registered", REFERRER, ELGG_HTTP_FORBIDDEN); |
|
1456 | + } |
|
1457 | + |
|
1458 | + // pull out GET parameters through filter |
|
1459 | + $vars = []; |
|
1460 | + foreach (_elgg_services()->request->query->keys() as $name) { |
|
1461 | + $vars[$name] = get_input($name); |
|
1462 | + } |
|
1463 | + |
|
1464 | + if (isset($vars['guid'])) { |
|
1465 | + $vars['entity'] = get_entity($vars['guid']); |
|
1466 | + } |
|
1467 | + |
|
1468 | + $content_type = ''; |
|
1469 | + if ($segments[0] === 'view') { |
|
1470 | + $output = elgg_view($view, $vars); |
|
1471 | + |
|
1472 | + // Try to guess the mime-type |
|
1473 | + switch ($segments[1]) { |
|
1474 | + case "js": |
|
1475 | + $content_type = 'text/javascript;charset=utf-8'; |
|
1476 | + break; |
|
1477 | + case "css": |
|
1478 | + $content_type = 'text/css;charset=utf-8'; |
|
1479 | + break; |
|
1480 | + default : |
|
1481 | + if (_elgg_services()->views->isCacheableView($view)) { |
|
1482 | + $file = _elgg_services()->views->findViewFile($view, elgg_get_viewtype()); |
|
1483 | + $content_type = (new \Elgg\Filesystem\MimeTypeDetector())->getType($file, 'text/html'); |
|
1484 | + } |
|
1485 | + break; |
|
1486 | + } |
|
1487 | + } else { |
|
1488 | + $action = implode('/', array_slice($segments, 1)); |
|
1489 | + $output = elgg_view_form($action, [], $vars); |
|
1490 | + } |
|
1491 | + |
|
1492 | + if ($content_type) { |
|
1493 | + elgg_set_http_header("Content-Type: $content_type"); |
|
1494 | + } |
|
1495 | 1495 | |
1496 | - return elgg_ok_response($output); |
|
1497 | - } |
|
1496 | + return elgg_ok_response($output); |
|
1497 | + } |
|
1498 | 1498 | |
1499 | - return false; |
|
1499 | + return false; |
|
1500 | 1500 | } |
1501 | 1501 | |
1502 | 1502 | /** |
@@ -1508,16 +1508,16 @@ discard block |
||
1508 | 1508 | * @since 1.10 |
1509 | 1509 | */ |
1510 | 1510 | function _elgg_favicon_page_handler($segments) { |
1511 | - header("HTTP/1.1 404 Not Found", true, 404); |
|
1511 | + header("HTTP/1.1 404 Not Found", true, 404); |
|
1512 | 1512 | |
1513 | - header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+1 week")), true); |
|
1514 | - header("Pragma: public", true); |
|
1515 | - header("Cache-Control: public", true); |
|
1513 | + header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+1 week")), true); |
|
1514 | + header("Pragma: public", true); |
|
1515 | + header("Cache-Control: public", true); |
|
1516 | 1516 | |
1517 | - header('Content-Type: image/x-icon'); |
|
1518 | - echo elgg_view('graphics/favicon.ico'); |
|
1517 | + header('Content-Type: image/x-icon'); |
|
1518 | + echo elgg_view('graphics/favicon.ico'); |
|
1519 | 1519 | |
1520 | - return true; |
|
1520 | + return true; |
|
1521 | 1521 | } |
1522 | 1522 | |
1523 | 1523 | /** |
@@ -1532,18 +1532,18 @@ discard block |
||
1532 | 1532 | * @access private |
1533 | 1533 | */ |
1534 | 1534 | function _elgg_sql_reverse_order_by_clause($order_by) { |
1535 | - $order_by = strtolower($order_by); |
|
1535 | + $order_by = strtolower($order_by); |
|
1536 | 1536 | |
1537 | - if (strpos($order_by, ' asc') !== false) { |
|
1538 | - $return = str_replace(' asc', ' desc', $order_by); |
|
1539 | - } elseif (strpos($order_by, ' desc') !== false) { |
|
1540 | - $return = str_replace(' desc', ' asc', $order_by); |
|
1541 | - } else { |
|
1542 | - // no order specified, so default to desc since mysql defaults to asc |
|
1543 | - $return = $order_by . ' desc'; |
|
1544 | - } |
|
1537 | + if (strpos($order_by, ' asc') !== false) { |
|
1538 | + $return = str_replace(' asc', ' desc', $order_by); |
|
1539 | + } elseif (strpos($order_by, ' desc') !== false) { |
|
1540 | + $return = str_replace(' desc', ' asc', $order_by); |
|
1541 | + } else { |
|
1542 | + // no order specified, so default to desc since mysql defaults to asc |
|
1543 | + $return = $order_by . ' desc'; |
|
1544 | + } |
|
1545 | 1545 | |
1546 | - return $return; |
|
1546 | + return $return; |
|
1547 | 1547 | } |
1548 | 1548 | |
1549 | 1549 | /** |
@@ -1558,8 +1558,8 @@ discard block |
||
1558 | 1558 | * @access private |
1559 | 1559 | */ |
1560 | 1560 | function elgg_batch_enable_callback($object) { |
1561 | - // our db functions return the number of rows affected... |
|
1562 | - return $object->enable() ? true : false; |
|
1561 | + // our db functions return the number of rows affected... |
|
1562 | + return $object->enable() ? true : false; |
|
1563 | 1563 | } |
1564 | 1564 | |
1565 | 1565 | /** |
@@ -1572,8 +1572,8 @@ discard block |
||
1572 | 1572 | * @access private |
1573 | 1573 | */ |
1574 | 1574 | function elgg_batch_disable_callback($object) { |
1575 | - // our db functions return the number of rows affected... |
|
1576 | - return $object->disable() ? true : false; |
|
1575 | + // our db functions return the number of rows affected... |
|
1576 | + return $object->disable() ? true : false; |
|
1577 | 1577 | } |
1578 | 1578 | |
1579 | 1579 | /** |
@@ -1586,8 +1586,8 @@ discard block |
||
1586 | 1586 | * @access private |
1587 | 1587 | */ |
1588 | 1588 | function elgg_batch_delete_callback($object) { |
1589 | - // our db functions return the number of rows affected... |
|
1590 | - return $object->delete() ? true : false; |
|
1589 | + // our db functions return the number of rows affected... |
|
1590 | + return $object->delete() ? true : false; |
|
1591 | 1591 | } |
1592 | 1592 | |
1593 | 1593 | /** |
@@ -1600,62 +1600,62 @@ discard block |
||
1600 | 1600 | * @access private |
1601 | 1601 | */ |
1602 | 1602 | function _elgg_is_valid_options_for_batch_operation($options, $type) { |
1603 | - if (!$options || !is_array($options)) { |
|
1604 | - return false; |
|
1605 | - } |
|
1606 | - |
|
1607 | - // at least one of these is required. |
|
1608 | - $required = [ |
|
1609 | - // generic restraints |
|
1610 | - 'guid', 'guids' |
|
1611 | - ]; |
|
1612 | - |
|
1613 | - switch ($type) { |
|
1614 | - case 'metadata': |
|
1615 | - $metadata_required = [ |
|
1616 | - 'metadata_owner_guid', 'metadata_owner_guids', |
|
1617 | - 'metadata_name', 'metadata_names', |
|
1618 | - 'metadata_value', 'metadata_values' |
|
1619 | - ]; |
|
1620 | - |
|
1621 | - $required = array_merge($required, $metadata_required); |
|
1622 | - break; |
|
1623 | - |
|
1624 | - case 'annotations': |
|
1625 | - case 'annotation': |
|
1626 | - $annotations_required = [ |
|
1627 | - 'annotation_owner_guid', 'annotation_owner_guids', |
|
1628 | - 'annotation_name', 'annotation_names', |
|
1629 | - 'annotation_value', 'annotation_values' |
|
1630 | - ]; |
|
1631 | - |
|
1632 | - $required = array_merge($required, $annotations_required); |
|
1633 | - break; |
|
1634 | - |
|
1635 | - case 'river': |
|
1636 | - // overriding generic restraints as guids isn't supported in river |
|
1637 | - $required = [ |
|
1638 | - 'id', 'ids', |
|
1639 | - 'subject_guid', 'subject_guids', |
|
1640 | - 'object_guid', 'object_guids', |
|
1641 | - 'target_guid', 'target_guids', |
|
1642 | - 'annotation_id', 'annotation_ids', |
|
1643 | - 'view', 'views', |
|
1644 | - ]; |
|
1645 | - break; |
|
1603 | + if (!$options || !is_array($options)) { |
|
1604 | + return false; |
|
1605 | + } |
|
1606 | + |
|
1607 | + // at least one of these is required. |
|
1608 | + $required = [ |
|
1609 | + // generic restraints |
|
1610 | + 'guid', 'guids' |
|
1611 | + ]; |
|
1612 | + |
|
1613 | + switch ($type) { |
|
1614 | + case 'metadata': |
|
1615 | + $metadata_required = [ |
|
1616 | + 'metadata_owner_guid', 'metadata_owner_guids', |
|
1617 | + 'metadata_name', 'metadata_names', |
|
1618 | + 'metadata_value', 'metadata_values' |
|
1619 | + ]; |
|
1620 | + |
|
1621 | + $required = array_merge($required, $metadata_required); |
|
1622 | + break; |
|
1623 | + |
|
1624 | + case 'annotations': |
|
1625 | + case 'annotation': |
|
1626 | + $annotations_required = [ |
|
1627 | + 'annotation_owner_guid', 'annotation_owner_guids', |
|
1628 | + 'annotation_name', 'annotation_names', |
|
1629 | + 'annotation_value', 'annotation_values' |
|
1630 | + ]; |
|
1631 | + |
|
1632 | + $required = array_merge($required, $annotations_required); |
|
1633 | + break; |
|
1634 | + |
|
1635 | + case 'river': |
|
1636 | + // overriding generic restraints as guids isn't supported in river |
|
1637 | + $required = [ |
|
1638 | + 'id', 'ids', |
|
1639 | + 'subject_guid', 'subject_guids', |
|
1640 | + 'object_guid', 'object_guids', |
|
1641 | + 'target_guid', 'target_guids', |
|
1642 | + 'annotation_id', 'annotation_ids', |
|
1643 | + 'view', 'views', |
|
1644 | + ]; |
|
1645 | + break; |
|
1646 | 1646 | |
1647 | - default: |
|
1648 | - return false; |
|
1649 | - } |
|
1647 | + default: |
|
1648 | + return false; |
|
1649 | + } |
|
1650 | 1650 | |
1651 | - foreach ($required as $key) { |
|
1652 | - // check that it exists and is something. |
|
1653 | - if (isset($options[$key]) && $options[$key]) { |
|
1654 | - return true; |
|
1655 | - } |
|
1656 | - } |
|
1651 | + foreach ($required as $key) { |
|
1652 | + // check that it exists and is something. |
|
1653 | + if (isset($options[$key]) && $options[$key]) { |
|
1654 | + return true; |
|
1655 | + } |
|
1656 | + } |
|
1657 | 1657 | |
1658 | - return false; |
|
1658 | + return false; |
|
1659 | 1659 | } |
1660 | 1660 | |
1661 | 1661 | /** |
@@ -1665,7 +1665,7 @@ discard block |
||
1665 | 1665 | * @access private |
1666 | 1666 | */ |
1667 | 1667 | function _elgg_walled_garden_index() { |
1668 | - return elgg_ok_response(elgg_view_resource('walled_garden')); |
|
1668 | + return elgg_ok_response(elgg_view_resource('walled_garden')); |
|
1669 | 1669 | } |
1670 | 1670 | |
1671 | 1671 | /** |
@@ -1682,26 +1682,26 @@ discard block |
||
1682 | 1682 | * @access private |
1683 | 1683 | */ |
1684 | 1684 | function _elgg_walled_garden_init() { |
1685 | - if (!_elgg_config()->walled_garden) { |
|
1686 | - return; |
|
1687 | - } |
|
1685 | + if (!_elgg_config()->walled_garden) { |
|
1686 | + return; |
|
1687 | + } |
|
1688 | 1688 | |
1689 | - elgg_register_css('elgg.walled_garden', elgg_get_simplecache_url('walled_garden.css')); |
|
1689 | + elgg_register_css('elgg.walled_garden', elgg_get_simplecache_url('walled_garden.css')); |
|
1690 | 1690 | |
1691 | - elgg_register_plugin_hook_handler('register', 'menu:walled_garden', '_elgg_walled_garden_menu'); |
|
1691 | + elgg_register_plugin_hook_handler('register', 'menu:walled_garden', '_elgg_walled_garden_menu'); |
|
1692 | 1692 | |
1693 | - elgg_register_page_handler('walled_garden', '_elgg_walled_garden_ajax_handler'); |
|
1693 | + elgg_register_page_handler('walled_garden', '_elgg_walled_garden_ajax_handler'); |
|
1694 | 1694 | |
1695 | - if (_elgg_config()->default_access == ACCESS_PUBLIC) { |
|
1696 | - elgg_set_config('default_access', ACCESS_LOGGED_IN); |
|
1697 | - } |
|
1695 | + if (_elgg_config()->default_access == ACCESS_PUBLIC) { |
|
1696 | + elgg_set_config('default_access', ACCESS_LOGGED_IN); |
|
1697 | + } |
|
1698 | 1698 | |
1699 | - elgg_register_plugin_hook_handler('access:collections:write', 'all', '_elgg_walled_garden_remove_public_access', 9999); |
|
1699 | + elgg_register_plugin_hook_handler('access:collections:write', 'all', '_elgg_walled_garden_remove_public_access', 9999); |
|
1700 | 1700 | |
1701 | - if (!elgg_is_logged_in()) { |
|
1702 | - // override the front page |
|
1703 | - elgg_register_page_handler('', '_elgg_walled_garden_index'); |
|
1704 | - } |
|
1701 | + if (!elgg_is_logged_in()) { |
|
1702 | + // override the front page |
|
1703 | + elgg_register_page_handler('', '_elgg_walled_garden_index'); |
|
1704 | + } |
|
1705 | 1705 | } |
1706 | 1706 | |
1707 | 1707 | /** |
@@ -1718,18 +1718,18 @@ discard block |
||
1718 | 1718 | */ |
1719 | 1719 | function _elgg_walled_garden_menu($hook, $type, $return_value, $params) { |
1720 | 1720 | |
1721 | - if (current_page_url() === elgg_get_site_url()) { |
|
1722 | - return; |
|
1723 | - } |
|
1721 | + if (current_page_url() === elgg_get_site_url()) { |
|
1722 | + return; |
|
1723 | + } |
|
1724 | 1724 | |
1725 | - $return_value[] = \ElggMenuItem::factory([ |
|
1726 | - 'name' => 'home', |
|
1727 | - 'href' => '/', |
|
1728 | - 'text' => elgg_echo('walled_garden:home'), |
|
1729 | - 'priority' => 10, |
|
1730 | - ]); |
|
1725 | + $return_value[] = \ElggMenuItem::factory([ |
|
1726 | + 'name' => 'home', |
|
1727 | + 'href' => '/', |
|
1728 | + 'text' => elgg_echo('walled_garden:home'), |
|
1729 | + 'priority' => 10, |
|
1730 | + ]); |
|
1731 | 1731 | |
1732 | - return $return_value; |
|
1732 | + return $return_value; |
|
1733 | 1733 | } |
1734 | 1734 | |
1735 | 1735 | /** |
@@ -1742,10 +1742,10 @@ discard block |
||
1742 | 1742 | * @access private |
1743 | 1743 | */ |
1744 | 1744 | function _elgg_walled_garden_remove_public_access($hook, $type, $accesses) { |
1745 | - if (isset($accesses[ACCESS_PUBLIC])) { |
|
1746 | - unset($accesses[ACCESS_PUBLIC]); |
|
1747 | - } |
|
1748 | - return $accesses; |
|
1745 | + if (isset($accesses[ACCESS_PUBLIC])) { |
|
1746 | + unset($accesses[ACCESS_PUBLIC]); |
|
1747 | + } |
|
1748 | + return $accesses; |
|
1749 | 1749 | } |
1750 | 1750 | |
1751 | 1751 | /** |
@@ -1758,36 +1758,36 @@ discard block |
||
1758 | 1758 | * @access private |
1759 | 1759 | */ |
1760 | 1760 | function _elgg_init() { |
1761 | - elgg_register_action('entity/delete'); |
|
1762 | - elgg_register_action('comment/save'); |
|
1763 | - elgg_register_action('comment/delete'); |
|
1761 | + elgg_register_action('entity/delete'); |
|
1762 | + elgg_register_action('comment/save'); |
|
1763 | + elgg_register_action('comment/delete'); |
|
1764 | 1764 | |
1765 | - elgg_register_page_handler('ajax', '_elgg_ajax_page_handler'); |
|
1766 | - elgg_register_page_handler('favicon.ico', '_elgg_favicon_page_handler'); |
|
1765 | + elgg_register_page_handler('ajax', '_elgg_ajax_page_handler'); |
|
1766 | + elgg_register_page_handler('favicon.ico', '_elgg_favicon_page_handler'); |
|
1767 | 1767 | |
1768 | - elgg_register_page_handler('manifest.json', function() { |
|
1769 | - $site = elgg_get_site_entity(); |
|
1770 | - $resource = new \Elgg\Http\WebAppManifestResource($site); |
|
1771 | - header('Content-Type: application/json;charset=utf-8'); |
|
1772 | - echo json_encode($resource->get()); |
|
1773 | - return true; |
|
1774 | - }); |
|
1768 | + elgg_register_page_handler('manifest.json', function() { |
|
1769 | + $site = elgg_get_site_entity(); |
|
1770 | + $resource = new \Elgg\Http\WebAppManifestResource($site); |
|
1771 | + header('Content-Type: application/json;charset=utf-8'); |
|
1772 | + echo json_encode($resource->get()); |
|
1773 | + return true; |
|
1774 | + }); |
|
1775 | 1775 | |
1776 | - elgg_register_plugin_hook_handler('head', 'page', function($hook, $type, array $result) { |
|
1777 | - $result['links']['manifest'] = [ |
|
1778 | - 'rel' => 'manifest', |
|
1779 | - 'href' => elgg_normalize_url('/manifest.json'), |
|
1780 | - ]; |
|
1776 | + elgg_register_plugin_hook_handler('head', 'page', function($hook, $type, array $result) { |
|
1777 | + $result['links']['manifest'] = [ |
|
1778 | + 'rel' => 'manifest', |
|
1779 | + 'href' => elgg_normalize_url('/manifest.json'), |
|
1780 | + ]; |
|
1781 | 1781 | |
1782 | - return $result; |
|
1783 | - }); |
|
1782 | + return $result; |
|
1783 | + }); |
|
1784 | 1784 | |
1785 | - if (_elgg_config()->enable_profiling) { |
|
1786 | - /** |
|
1787 | - * @see \Elgg\Profiler::handlePageOutput |
|
1788 | - */ |
|
1789 | - elgg_register_plugin_hook_handler('output', 'page', [\Elgg\Profiler::class, 'handlePageOutput'], 999); |
|
1790 | - } |
|
1785 | + if (_elgg_config()->enable_profiling) { |
|
1786 | + /** |
|
1787 | + * @see \Elgg\Profiler::handlePageOutput |
|
1788 | + */ |
|
1789 | + elgg_register_plugin_hook_handler('output', 'page', [\Elgg\Profiler::class, 'handlePageOutput'], 999); |
|
1790 | + } |
|
1791 | 1791 | } |
1792 | 1792 | |
1793 | 1793 | /** |
@@ -1803,23 +1803,23 @@ discard block |
||
1803 | 1803 | * @access private |
1804 | 1804 | */ |
1805 | 1805 | function _elgg_api_test($hook, $type, $value, $params) { |
1806 | - $value[] = Paths::elgg() . 'engine/tests/ElggTravisInstallTest.php'; |
|
1807 | - $value[] = Paths::elgg() . 'engine/tests/ElggCoreHelpersTest.php'; |
|
1808 | - $value[] = Paths::elgg() . 'engine/tests/ElggCoreRegressionBugsTest.php'; |
|
1809 | - $value[] = Paths::elgg() . 'engine/tests/ElggBatchTest.php'; |
|
1810 | - return $value; |
|
1806 | + $value[] = Paths::elgg() . 'engine/tests/ElggTravisInstallTest.php'; |
|
1807 | + $value[] = Paths::elgg() . 'engine/tests/ElggCoreHelpersTest.php'; |
|
1808 | + $value[] = Paths::elgg() . 'engine/tests/ElggCoreRegressionBugsTest.php'; |
|
1809 | + $value[] = Paths::elgg() . 'engine/tests/ElggBatchTest.php'; |
|
1810 | + return $value; |
|
1811 | 1811 | } |
1812 | 1812 | |
1813 | 1813 | /** |
1814 | 1814 | * @see \Elgg\Application::loadCore Do not do work here. Just register for events. |
1815 | 1815 | */ |
1816 | 1816 | return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
1817 | - $events->registerHandler('cache:flush', 'system', function () { |
|
1818 | - _elgg_services()->boot->invalidateCache(); |
|
1819 | - }); |
|
1817 | + $events->registerHandler('cache:flush', 'system', function () { |
|
1818 | + _elgg_services()->boot->invalidateCache(); |
|
1819 | + }); |
|
1820 | 1820 | |
1821 | - $events->registerHandler('init', 'system', '_elgg_init'); |
|
1822 | - $events->registerHandler('init', 'system', '_elgg_walled_garden_init', 1000); |
|
1821 | + $events->registerHandler('init', 'system', '_elgg_init'); |
|
1822 | + $events->registerHandler('init', 'system', '_elgg_walled_garden_init', 1000); |
|
1823 | 1823 | |
1824 | - $hooks->registerHandler('unit_test', 'system', '_elgg_api_test'); |
|
1824 | + $hooks->registerHandler('unit_test', 'system', '_elgg_api_test'); |
|
1825 | 1825 | }; |
@@ -532,7 +532,7 @@ |
||
532 | 532 | * @param string[] $value Test files |
533 | 533 | * @param array $params Hook params |
534 | 534 | * |
535 | - * @return array |
|
535 | + * @return string[] |
|
536 | 536 | */ |
537 | 537 | function _elgg_htmlawed_test($hook, $type, $value, $params) { |
538 | 538 | $value[] = Paths::elgg() . 'engine/tests/ElggHtmLawedTest.php'; |
@@ -67,10 +67,10 @@ discard block |
||
67 | 67 | function current_page_url() { |
68 | 68 | $url = parse_url(elgg_get_site_url()); |
69 | 69 | |
70 | - $page = $url['scheme'] . "://" . $url['host']; |
|
70 | + $page = $url['scheme']."://".$url['host']; |
|
71 | 71 | |
72 | 72 | if (isset($url['port']) && $url['port']) { |
73 | - $page .= ":" . $url['port']; |
|
73 | + $page .= ":".$url['port']; |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | $page = trim($page, "/"); |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | 'input_name' => $input_name, |
281 | 281 | ]), |
282 | 282 | ]; |
283 | - $results[$entity->name . rand(1, 100)] = $result; |
|
283 | + $results[$entity->name.rand(1, 100)] = $result; |
|
284 | 284 | } |
285 | 285 | } |
286 | 286 | break; |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | 'url' => $entity->getURL(), |
328 | 328 | ]; |
329 | 329 | |
330 | - $results[$entity->name . rand(1, 100)] = $result; |
|
330 | + $results[$entity->name.rand(1, 100)] = $result; |
|
331 | 331 | } |
332 | 332 | } |
333 | 333 | break; |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | 'input_name' => $input_name, |
374 | 374 | ]), |
375 | 375 | ]; |
376 | - $results[$entity->name . rand(1, 100)] = $result; |
|
376 | + $results[$entity->name.rand(1, 100)] = $result; |
|
377 | 377 | } |
378 | 378 | } |
379 | 379 | break; |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | 'font-weight', 'font-style', 'border', 'border-top', 'background-color', |
480 | 480 | 'border-bottom', 'border-left', 'border-right', |
481 | 481 | 'margin', 'margin-top', 'margin-bottom', 'margin-left', |
482 | - 'margin-right', 'padding', 'float', 'text-decoration' |
|
482 | + 'margin-right', 'padding', 'float', 'text-decoration' |
|
483 | 483 | ]; |
484 | 484 | |
485 | 485 | $params = ['tag' => $element]; |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | * @return array |
536 | 536 | */ |
537 | 537 | function _elgg_htmlawed_test($hook, $type, $value, $params) { |
538 | - $value[] = Paths::elgg() . 'engine/tests/ElggHtmLawedTest.php'; |
|
538 | + $value[] = Paths::elgg().'engine/tests/ElggHtmLawedTest.php'; |
|
539 | 539 | return $value; |
540 | 540 | } |
541 | 541 |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * @return mixed |
28 | 28 | */ |
29 | 29 | function get_input($variable, $default = null, $filter_result = true) { |
30 | - return _elgg_services()->input->get($variable, $default, $filter_result); |
|
30 | + return _elgg_services()->input->get($variable, $default, $filter_result); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * @return void |
42 | 42 | */ |
43 | 43 | function set_input($variable, $value) { |
44 | - _elgg_services()->input->set($variable, $value); |
|
44 | + _elgg_services()->input->set($variable, $value); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @return mixed The filtered result - everything will be strings |
54 | 54 | */ |
55 | 55 | function filter_tags($var) { |
56 | - return elgg_trigger_plugin_hook('validate', 'input', null, $var); |
|
56 | + return elgg_trigger_plugin_hook('validate', 'input', null, $var); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -65,19 +65,19 @@ discard block |
||
65 | 65 | * @return string The current page URL. |
66 | 66 | */ |
67 | 67 | function current_page_url() { |
68 | - $url = parse_url(elgg_get_site_url()); |
|
68 | + $url = parse_url(elgg_get_site_url()); |
|
69 | 69 | |
70 | - $page = $url['scheme'] . "://" . $url['host']; |
|
70 | + $page = $url['scheme'] . "://" . $url['host']; |
|
71 | 71 | |
72 | - if (isset($url['port']) && $url['port']) { |
|
73 | - $page .= ":" . $url['port']; |
|
74 | - } |
|
72 | + if (isset($url['port']) && $url['port']) { |
|
73 | + $page .= ":" . $url['port']; |
|
74 | + } |
|
75 | 75 | |
76 | - $page = trim($page, "/"); |
|
76 | + $page = trim($page, "/"); |
|
77 | 77 | |
78 | - $page .= _elgg_services()->request->getRequestUri(); |
|
78 | + $page .= _elgg_services()->request->getRequestUri(); |
|
79 | 79 | |
80 | - return $page; |
|
80 | + return $page; |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * @return bool |
89 | 89 | */ |
90 | 90 | function is_email_address($address) { |
91 | - return filter_var($address, FILTER_VALIDATE_EMAIL) === $address; |
|
91 | + return filter_var($address, FILTER_VALIDATE_EMAIL) === $address; |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * @since 1.8.0 |
104 | 104 | */ |
105 | 105 | function elgg_make_sticky_form($form_name) { |
106 | - _elgg_services()->stickyForms->makeStickyForm($form_name); |
|
106 | + _elgg_services()->stickyForms->makeStickyForm($form_name); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @since 1.8.0 |
120 | 120 | */ |
121 | 121 | function elgg_clear_sticky_form($form_name) { |
122 | - _elgg_services()->stickyForms->clearStickyForm($form_name); |
|
122 | + _elgg_services()->stickyForms->clearStickyForm($form_name); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | * @since 1.8.0 |
132 | 132 | */ |
133 | 133 | function elgg_is_sticky_form($form_name) { |
134 | - return _elgg_services()->stickyForms->isStickyForm($form_name); |
|
134 | + return _elgg_services()->stickyForms->isStickyForm($form_name); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | * @since 1.8.0 |
149 | 149 | */ |
150 | 150 | function elgg_get_sticky_value($form_name, $variable = '', $default = null, $filter_result = true) { |
151 | - return _elgg_services()->stickyForms->getStickyValue($form_name, $variable, $default, $filter_result); |
|
151 | + return _elgg_services()->stickyForms->getStickyValue($form_name, $variable, $default, $filter_result); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | * @since 1.8.0 |
162 | 162 | */ |
163 | 163 | function elgg_get_sticky_values($form_name, $filter_result = true) { |
164 | - return _elgg_services()->stickyForms->getStickyValues($form_name, $filter_result); |
|
164 | + return _elgg_services()->stickyForms->getStickyValues($form_name, $filter_result); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | * @since 1.8.0 |
175 | 175 | */ |
176 | 176 | function elgg_clear_sticky_value($form_name, $variable) { |
177 | - _elgg_services()->stickyForms->clearStickyValue($form_name, $variable); |
|
177 | + _elgg_services()->stickyForms->clearStickyValue($form_name, $variable); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -195,201 +195,201 @@ discard block |
||
195 | 195 | * @access private |
196 | 196 | */ |
197 | 197 | function input_livesearch_page_handler($page) { |
198 | - $dbprefix = _elgg_config()->dbprefix; |
|
199 | - |
|
200 | - // only return results to logged in users. |
|
201 | - if (!$user = elgg_get_logged_in_user_entity()) { |
|
202 | - exit; |
|
203 | - } |
|
204 | - |
|
205 | - if (!$q = get_input('term', get_input('q'))) { |
|
206 | - exit; |
|
207 | - } |
|
208 | - |
|
209 | - $input_name = get_input('name', 'members'); |
|
210 | - |
|
211 | - $q = sanitise_string($q); |
|
212 | - |
|
213 | - // replace mysql vars with escaped strings |
|
214 | - $q = str_replace(['_', '%'], ['\_', '\%'], $q); |
|
215 | - |
|
216 | - $match_on = get_input('match_on', 'all'); |
|
217 | - |
|
218 | - if (!is_array($match_on)) { |
|
219 | - $match_on = [$match_on]; |
|
220 | - } |
|
221 | - |
|
222 | - // all = users and groups |
|
223 | - if (in_array('all', $match_on)) { |
|
224 | - $match_on = ['users', 'groups']; |
|
225 | - } |
|
226 | - |
|
227 | - $owner_guid = ELGG_ENTITIES_ANY_VALUE; |
|
228 | - if (get_input('match_owner', false)) { |
|
229 | - $owner_guid = $user->getGUID(); |
|
230 | - } |
|
231 | - |
|
232 | - $limit = sanitise_int(get_input('limit', _elgg_config()->default_limit)); |
|
233 | - |
|
234 | - // grab a list of entities and send them in json. |
|
235 | - $results = []; |
|
236 | - foreach ($match_on as $match_type) { |
|
237 | - switch ($match_type) { |
|
238 | - case 'users': |
|
239 | - $options = [ |
|
240 | - 'type' => 'user', |
|
241 | - 'limit' => $limit, |
|
242 | - 'joins' => ["JOIN {$dbprefix}users_entity ue ON e.guid = ue.guid"], |
|
243 | - 'wheres' => [ |
|
244 | - "ue.banned = 'no'", |
|
245 | - "(ue.name LIKE '$q%' OR ue.name LIKE '% $q%' OR ue.username LIKE '$q%')" |
|
246 | - ] |
|
247 | - ]; |
|
198 | + $dbprefix = _elgg_config()->dbprefix; |
|
199 | + |
|
200 | + // only return results to logged in users. |
|
201 | + if (!$user = elgg_get_logged_in_user_entity()) { |
|
202 | + exit; |
|
203 | + } |
|
204 | + |
|
205 | + if (!$q = get_input('term', get_input('q'))) { |
|
206 | + exit; |
|
207 | + } |
|
208 | + |
|
209 | + $input_name = get_input('name', 'members'); |
|
210 | + |
|
211 | + $q = sanitise_string($q); |
|
212 | + |
|
213 | + // replace mysql vars with escaped strings |
|
214 | + $q = str_replace(['_', '%'], ['\_', '\%'], $q); |
|
215 | + |
|
216 | + $match_on = get_input('match_on', 'all'); |
|
217 | + |
|
218 | + if (!is_array($match_on)) { |
|
219 | + $match_on = [$match_on]; |
|
220 | + } |
|
221 | + |
|
222 | + // all = users and groups |
|
223 | + if (in_array('all', $match_on)) { |
|
224 | + $match_on = ['users', 'groups']; |
|
225 | + } |
|
226 | + |
|
227 | + $owner_guid = ELGG_ENTITIES_ANY_VALUE; |
|
228 | + if (get_input('match_owner', false)) { |
|
229 | + $owner_guid = $user->getGUID(); |
|
230 | + } |
|
231 | + |
|
232 | + $limit = sanitise_int(get_input('limit', _elgg_config()->default_limit)); |
|
233 | + |
|
234 | + // grab a list of entities and send them in json. |
|
235 | + $results = []; |
|
236 | + foreach ($match_on as $match_type) { |
|
237 | + switch ($match_type) { |
|
238 | + case 'users': |
|
239 | + $options = [ |
|
240 | + 'type' => 'user', |
|
241 | + 'limit' => $limit, |
|
242 | + 'joins' => ["JOIN {$dbprefix}users_entity ue ON e.guid = ue.guid"], |
|
243 | + 'wheres' => [ |
|
244 | + "ue.banned = 'no'", |
|
245 | + "(ue.name LIKE '$q%' OR ue.name LIKE '% $q%' OR ue.username LIKE '$q%')" |
|
246 | + ] |
|
247 | + ]; |
|
248 | 248 | |
249 | - $entities = elgg_get_entities($options); |
|
250 | - if (!empty($entities)) { |
|
251 | - foreach ($entities as $entity) { |
|
252 | - if (in_array('groups', $match_on)) { |
|
253 | - $value = $entity->guid; |
|
254 | - } else { |
|
255 | - $value = $entity->username; |
|
256 | - } |
|
257 | - |
|
258 | - $output = elgg_view_list_item($entity, [ |
|
259 | - 'use_hover' => false, |
|
260 | - 'use_link' => false, |
|
261 | - 'class' => 'elgg-autocomplete-item', |
|
262 | - 'title' => $entity->name, // Default title would be a link |
|
263 | - ]); |
|
264 | - |
|
265 | - $icon = elgg_view_entity_icon($entity, 'tiny', [ |
|
266 | - 'use_hover' => false, |
|
267 | - ]); |
|
268 | - |
|
269 | - $result = [ |
|
270 | - 'type' => 'user', |
|
271 | - 'name' => $entity->name, |
|
272 | - 'desc' => $entity->username, |
|
273 | - 'guid' => $entity->guid, |
|
274 | - 'label' => $output, |
|
275 | - 'value' => $value, |
|
276 | - 'icon' => $icon, |
|
277 | - 'url' => $entity->getURL(), |
|
278 | - 'html' => elgg_view('input/userpicker/item', [ |
|
279 | - 'entity' => $entity, |
|
280 | - 'input_name' => $input_name, |
|
281 | - ]), |
|
282 | - ]; |
|
283 | - $results[$entity->name . rand(1, 100)] = $result; |
|
284 | - } |
|
285 | - } |
|
286 | - break; |
|
287 | - |
|
288 | - case 'groups': |
|
289 | - // don't return results if groups aren't enabled. |
|
290 | - if (!elgg_is_active_plugin('groups')) { |
|
291 | - continue; |
|
292 | - } |
|
249 | + $entities = elgg_get_entities($options); |
|
250 | + if (!empty($entities)) { |
|
251 | + foreach ($entities as $entity) { |
|
252 | + if (in_array('groups', $match_on)) { |
|
253 | + $value = $entity->guid; |
|
254 | + } else { |
|
255 | + $value = $entity->username; |
|
256 | + } |
|
257 | + |
|
258 | + $output = elgg_view_list_item($entity, [ |
|
259 | + 'use_hover' => false, |
|
260 | + 'use_link' => false, |
|
261 | + 'class' => 'elgg-autocomplete-item', |
|
262 | + 'title' => $entity->name, // Default title would be a link |
|
263 | + ]); |
|
264 | + |
|
265 | + $icon = elgg_view_entity_icon($entity, 'tiny', [ |
|
266 | + 'use_hover' => false, |
|
267 | + ]); |
|
268 | + |
|
269 | + $result = [ |
|
270 | + 'type' => 'user', |
|
271 | + 'name' => $entity->name, |
|
272 | + 'desc' => $entity->username, |
|
273 | + 'guid' => $entity->guid, |
|
274 | + 'label' => $output, |
|
275 | + 'value' => $value, |
|
276 | + 'icon' => $icon, |
|
277 | + 'url' => $entity->getURL(), |
|
278 | + 'html' => elgg_view('input/userpicker/item', [ |
|
279 | + 'entity' => $entity, |
|
280 | + 'input_name' => $input_name, |
|
281 | + ]), |
|
282 | + ]; |
|
283 | + $results[$entity->name . rand(1, 100)] = $result; |
|
284 | + } |
|
285 | + } |
|
286 | + break; |
|
287 | + |
|
288 | + case 'groups': |
|
289 | + // don't return results if groups aren't enabled. |
|
290 | + if (!elgg_is_active_plugin('groups')) { |
|
291 | + continue; |
|
292 | + } |
|
293 | 293 | |
294 | - $options = [ |
|
295 | - 'type' => 'group', |
|
296 | - 'limit' => $limit, |
|
297 | - 'owner_guid' => $owner_guid, |
|
298 | - 'joins' => ["JOIN {$dbprefix}groups_entity ge ON e.guid = ge.guid"], |
|
299 | - 'wheres' => [ |
|
300 | - "(ge.name LIKE '$q%' OR ge.name LIKE '% $q%' OR ge.description LIKE '% $q%')" |
|
301 | - ] |
|
302 | - ]; |
|
294 | + $options = [ |
|
295 | + 'type' => 'group', |
|
296 | + 'limit' => $limit, |
|
297 | + 'owner_guid' => $owner_guid, |
|
298 | + 'joins' => ["JOIN {$dbprefix}groups_entity ge ON e.guid = ge.guid"], |
|
299 | + 'wheres' => [ |
|
300 | + "(ge.name LIKE '$q%' OR ge.name LIKE '% $q%' OR ge.description LIKE '% $q%')" |
|
301 | + ] |
|
302 | + ]; |
|
303 | 303 | |
304 | - $entities = elgg_get_entities($options); |
|
305 | - if (!empty($entities)) { |
|
306 | - foreach ($entities as $entity) { |
|
307 | - $output = elgg_view_list_item($entity, [ |
|
308 | - 'use_hover' => false, |
|
309 | - 'class' => 'elgg-autocomplete-item', |
|
310 | - 'full_view' => false, |
|
311 | - 'href' => false, |
|
312 | - 'title' => $entity->name, // Default title would be a link |
|
313 | - ]); |
|
314 | - |
|
315 | - $icon = elgg_view_entity_icon($entity, 'tiny', [ |
|
316 | - 'use_hover' => false, |
|
317 | - ]); |
|
318 | - |
|
319 | - $result = [ |
|
320 | - 'type' => 'group', |
|
321 | - 'name' => $entity->name, |
|
322 | - 'desc' => strip_tags($entity->description), |
|
323 | - 'guid' => $entity->guid, |
|
324 | - 'label' => $output, |
|
325 | - 'value' => $entity->guid, |
|
326 | - 'icon' => $icon, |
|
327 | - 'url' => $entity->getURL(), |
|
328 | - ]; |
|
329 | - |
|
330 | - $results[$entity->name . rand(1, 100)] = $result; |
|
331 | - } |
|
332 | - } |
|
333 | - break; |
|
334 | - |
|
335 | - case 'friends': |
|
336 | - $options = [ |
|
337 | - 'type' => 'user', |
|
338 | - 'limit' => $limit, |
|
339 | - 'relationship' => 'friend', |
|
340 | - 'relationship_guid' => $user->getGUID(), |
|
341 | - 'joins' => ["JOIN {$dbprefix}users_entity ue ON e.guid = ue.guid"], |
|
342 | - 'wheres' => [ |
|
343 | - "ue.banned = 'no'", |
|
344 | - "(ue.name LIKE '$q%' OR ue.name LIKE '% $q%' OR ue.username LIKE '$q%')" |
|
345 | - ] |
|
346 | - ]; |
|
304 | + $entities = elgg_get_entities($options); |
|
305 | + if (!empty($entities)) { |
|
306 | + foreach ($entities as $entity) { |
|
307 | + $output = elgg_view_list_item($entity, [ |
|
308 | + 'use_hover' => false, |
|
309 | + 'class' => 'elgg-autocomplete-item', |
|
310 | + 'full_view' => false, |
|
311 | + 'href' => false, |
|
312 | + 'title' => $entity->name, // Default title would be a link |
|
313 | + ]); |
|
314 | + |
|
315 | + $icon = elgg_view_entity_icon($entity, 'tiny', [ |
|
316 | + 'use_hover' => false, |
|
317 | + ]); |
|
318 | + |
|
319 | + $result = [ |
|
320 | + 'type' => 'group', |
|
321 | + 'name' => $entity->name, |
|
322 | + 'desc' => strip_tags($entity->description), |
|
323 | + 'guid' => $entity->guid, |
|
324 | + 'label' => $output, |
|
325 | + 'value' => $entity->guid, |
|
326 | + 'icon' => $icon, |
|
327 | + 'url' => $entity->getURL(), |
|
328 | + ]; |
|
329 | + |
|
330 | + $results[$entity->name . rand(1, 100)] = $result; |
|
331 | + } |
|
332 | + } |
|
333 | + break; |
|
334 | + |
|
335 | + case 'friends': |
|
336 | + $options = [ |
|
337 | + 'type' => 'user', |
|
338 | + 'limit' => $limit, |
|
339 | + 'relationship' => 'friend', |
|
340 | + 'relationship_guid' => $user->getGUID(), |
|
341 | + 'joins' => ["JOIN {$dbprefix}users_entity ue ON e.guid = ue.guid"], |
|
342 | + 'wheres' => [ |
|
343 | + "ue.banned = 'no'", |
|
344 | + "(ue.name LIKE '$q%' OR ue.name LIKE '% $q%' OR ue.username LIKE '$q%')" |
|
345 | + ] |
|
346 | + ]; |
|
347 | 347 | |
348 | - $entities = elgg_get_entities_from_relationship($options); |
|
349 | - if (!empty($entities)) { |
|
350 | - foreach ($entities as $entity) { |
|
351 | - $output = elgg_view_list_item($entity, [ |
|
352 | - 'use_hover' => false, |
|
353 | - 'use_link' => false, |
|
354 | - 'class' => 'elgg-autocomplete-item', |
|
355 | - 'title' => $entity->name, // Default title would be a link |
|
356 | - ]); |
|
357 | - |
|
358 | - $icon = elgg_view_entity_icon($entity, 'tiny', [ |
|
359 | - 'use_hover' => false, |
|
360 | - ]); |
|
361 | - |
|
362 | - $result = [ |
|
363 | - 'type' => 'user', |
|
364 | - 'name' => $entity->name, |
|
365 | - 'desc' => $entity->username, |
|
366 | - 'guid' => $entity->guid, |
|
367 | - 'label' => $output, |
|
368 | - 'value' => $entity->username, |
|
369 | - 'icon' => $icon, |
|
370 | - 'url' => $entity->getURL(), |
|
371 | - 'html' => elgg_view('input/userpicker/item', [ |
|
372 | - 'entity' => $entity, |
|
373 | - 'input_name' => $input_name, |
|
374 | - ]), |
|
375 | - ]; |
|
376 | - $results[$entity->name . rand(1, 100)] = $result; |
|
377 | - } |
|
378 | - } |
|
379 | - break; |
|
380 | - |
|
381 | - default: |
|
382 | - header("HTTP/1.0 400 Bad Request", true); |
|
383 | - echo "livesearch: unknown match_on of $match_type"; |
|
384 | - exit; |
|
385 | - break; |
|
386 | - } |
|
387 | - } |
|
388 | - |
|
389 | - ksort($results); |
|
390 | - header("Content-Type: application/json;charset=utf-8"); |
|
391 | - echo json_encode(array_values($results)); |
|
392 | - exit; |
|
348 | + $entities = elgg_get_entities_from_relationship($options); |
|
349 | + if (!empty($entities)) { |
|
350 | + foreach ($entities as $entity) { |
|
351 | + $output = elgg_view_list_item($entity, [ |
|
352 | + 'use_hover' => false, |
|
353 | + 'use_link' => false, |
|
354 | + 'class' => 'elgg-autocomplete-item', |
|
355 | + 'title' => $entity->name, // Default title would be a link |
|
356 | + ]); |
|
357 | + |
|
358 | + $icon = elgg_view_entity_icon($entity, 'tiny', [ |
|
359 | + 'use_hover' => false, |
|
360 | + ]); |
|
361 | + |
|
362 | + $result = [ |
|
363 | + 'type' => 'user', |
|
364 | + 'name' => $entity->name, |
|
365 | + 'desc' => $entity->username, |
|
366 | + 'guid' => $entity->guid, |
|
367 | + 'label' => $output, |
|
368 | + 'value' => $entity->username, |
|
369 | + 'icon' => $icon, |
|
370 | + 'url' => $entity->getURL(), |
|
371 | + 'html' => elgg_view('input/userpicker/item', [ |
|
372 | + 'entity' => $entity, |
|
373 | + 'input_name' => $input_name, |
|
374 | + ]), |
|
375 | + ]; |
|
376 | + $results[$entity->name . rand(1, 100)] = $result; |
|
377 | + } |
|
378 | + } |
|
379 | + break; |
|
380 | + |
|
381 | + default: |
|
382 | + header("HTTP/1.0 400 Bad Request", true); |
|
383 | + echo "livesearch: unknown match_on of $match_type"; |
|
384 | + exit; |
|
385 | + break; |
|
386 | + } |
|
387 | + } |
|
388 | + |
|
389 | + ksort($results); |
|
390 | + header("Content-Type: application/json;charset=utf-8"); |
|
391 | + echo json_encode(array_values($results)); |
|
392 | + exit; |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | /** |
@@ -411,38 +411,38 @@ discard block |
||
411 | 411 | * @return mixed |
412 | 412 | */ |
413 | 413 | function _elgg_htmlawed_filter_tags($hook, $type, $result, $params = null) { |
414 | - $var = $result; |
|
415 | - |
|
416 | - $config = [ |
|
417 | - // seems to handle about everything we need. |
|
418 | - 'safe' => true, |
|
419 | - |
|
420 | - // remove comments/CDATA instead of converting to text |
|
421 | - 'comment' => 1, |
|
422 | - 'cdata' => 1, |
|
423 | - |
|
424 | - 'deny_attribute' => 'class, on*', |
|
425 | - 'hook_tag' => '_elgg_htmlawed_tag_post_processor', |
|
426 | - |
|
427 | - 'schemes' => '*:http,https,ftp,news,mailto,rtsp,teamspeak,gopher,mms,callto', |
|
428 | - // apparent this doesn't work. |
|
429 | - // 'style:color,cursor,text-align,font-size,font-weight,font-style,border,margin,padding,float' |
|
430 | - ]; |
|
431 | - |
|
432 | - // add nofollow to all links on output |
|
433 | - if (!elgg_in_context('input')) { |
|
434 | - $config['anti_link_spam'] = ['/./', '']; |
|
435 | - } |
|
436 | - |
|
437 | - $config = elgg_trigger_plugin_hook('config', 'htmlawed', null, $config); |
|
438 | - $spec = elgg_trigger_plugin_hook('spec', 'htmlawed', null, ''); |
|
439 | - |
|
440 | - if (!is_array($var)) { |
|
441 | - return Htmlawed::filter($var, $config, $spec); |
|
442 | - } else { |
|
443 | - array_walk_recursive($var, '_elgg_htmLawedArray', [$config, $spec]); |
|
444 | - return $var; |
|
445 | - } |
|
414 | + $var = $result; |
|
415 | + |
|
416 | + $config = [ |
|
417 | + // seems to handle about everything we need. |
|
418 | + 'safe' => true, |
|
419 | + |
|
420 | + // remove comments/CDATA instead of converting to text |
|
421 | + 'comment' => 1, |
|
422 | + 'cdata' => 1, |
|
423 | + |
|
424 | + 'deny_attribute' => 'class, on*', |
|
425 | + 'hook_tag' => '_elgg_htmlawed_tag_post_processor', |
|
426 | + |
|
427 | + 'schemes' => '*:http,https,ftp,news,mailto,rtsp,teamspeak,gopher,mms,callto', |
|
428 | + // apparent this doesn't work. |
|
429 | + // 'style:color,cursor,text-align,font-size,font-weight,font-style,border,margin,padding,float' |
|
430 | + ]; |
|
431 | + |
|
432 | + // add nofollow to all links on output |
|
433 | + if (!elgg_in_context('input')) { |
|
434 | + $config['anti_link_spam'] = ['/./', '']; |
|
435 | + } |
|
436 | + |
|
437 | + $config = elgg_trigger_plugin_hook('config', 'htmlawed', null, $config); |
|
438 | + $spec = elgg_trigger_plugin_hook('spec', 'htmlawed', null, ''); |
|
439 | + |
|
440 | + if (!is_array($var)) { |
|
441 | + return Htmlawed::filter($var, $config, $spec); |
|
442 | + } else { |
|
443 | + array_walk_recursive($var, '_elgg_htmLawedArray', [$config, $spec]); |
|
444 | + return $var; |
|
445 | + } |
|
446 | 446 | } |
447 | 447 | |
448 | 448 | // @codingStandardsIgnoreStart |
@@ -450,8 +450,8 @@ discard block |
||
450 | 450 | * wrapper function for htmlawed for handling arrays |
451 | 451 | */ |
452 | 452 | function _elgg_htmLawedArray(&$v, $k, $config_spec) { |
453 | - list ($config, $spec) = $config_spec; |
|
454 | - $v = Htmlawed::filter($v, $config, $spec); |
|
453 | + list ($config, $spec) = $config_spec; |
|
454 | + $v = Htmlawed::filter($v, $config, $spec); |
|
455 | 455 | } |
456 | 456 | // @codingStandardsIgnoreEnd |
457 | 457 | |
@@ -468,60 +468,60 @@ discard block |
||
468 | 468 | * @return string |
469 | 469 | */ |
470 | 470 | function _elgg_htmlawed_tag_post_processor($element, $attributes = false) { |
471 | - if ($attributes === false) { |
|
472 | - // This is a closing tag. Prevent further processing to avoid inserting a duplicate tag |
|
473 | - return "</${element}>"; |
|
474 | - } |
|
475 | - |
|
476 | - // this list should be coordinated with the WYSIWYG editor used (tinymce, ckeditor, etc.) |
|
477 | - $allowed_styles = [ |
|
478 | - 'color', 'cursor', 'text-align', 'vertical-align', 'font-size', |
|
479 | - 'font-weight', 'font-style', 'border', 'border-top', 'background-color', |
|
480 | - 'border-bottom', 'border-left', 'border-right', |
|
481 | - 'margin', 'margin-top', 'margin-bottom', 'margin-left', |
|
482 | - 'margin-right', 'padding', 'float', 'text-decoration' |
|
483 | - ]; |
|
484 | - |
|
485 | - $params = ['tag' => $element]; |
|
486 | - $allowed_styles = elgg_trigger_plugin_hook('allowed_styles', 'htmlawed', $params, $allowed_styles); |
|
487 | - |
|
488 | - // must return something. |
|
489 | - $string = ''; |
|
490 | - |
|
491 | - foreach ($attributes as $attr => $value) { |
|
492 | - if ($attr == 'style') { |
|
493 | - $styles = explode(';', $value); |
|
494 | - |
|
495 | - $style_str = ''; |
|
496 | - foreach ($styles as $style) { |
|
497 | - if (!trim($style)) { |
|
498 | - continue; |
|
499 | - } |
|
500 | - list($style_attr, $style_value) = explode(':', trim($style)); |
|
501 | - $style_attr = trim($style_attr); |
|
502 | - $style_value = trim($style_value); |
|
503 | - |
|
504 | - if (in_array($style_attr, $allowed_styles)) { |
|
505 | - $style_str .= "$style_attr: $style_value; "; |
|
506 | - } |
|
507 | - } |
|
508 | - |
|
509 | - if ($style_str) { |
|
510 | - $style_str = trim($style_str); |
|
511 | - $string .= " style=\"$style_str\""; |
|
512 | - } |
|
513 | - } else { |
|
514 | - $string .= " $attr=\"$value\""; |
|
515 | - } |
|
516 | - } |
|
517 | - |
|
518 | - // Some WYSIWYG editors do not like tags like <p > so only add a space if needed. |
|
519 | - if ($string = trim($string)) { |
|
520 | - $string = " $string"; |
|
521 | - } |
|
522 | - |
|
523 | - $r = "<$element$string>"; |
|
524 | - return $r; |
|
471 | + if ($attributes === false) { |
|
472 | + // This is a closing tag. Prevent further processing to avoid inserting a duplicate tag |
|
473 | + return "</${element}>"; |
|
474 | + } |
|
475 | + |
|
476 | + // this list should be coordinated with the WYSIWYG editor used (tinymce, ckeditor, etc.) |
|
477 | + $allowed_styles = [ |
|
478 | + 'color', 'cursor', 'text-align', 'vertical-align', 'font-size', |
|
479 | + 'font-weight', 'font-style', 'border', 'border-top', 'background-color', |
|
480 | + 'border-bottom', 'border-left', 'border-right', |
|
481 | + 'margin', 'margin-top', 'margin-bottom', 'margin-left', |
|
482 | + 'margin-right', 'padding', 'float', 'text-decoration' |
|
483 | + ]; |
|
484 | + |
|
485 | + $params = ['tag' => $element]; |
|
486 | + $allowed_styles = elgg_trigger_plugin_hook('allowed_styles', 'htmlawed', $params, $allowed_styles); |
|
487 | + |
|
488 | + // must return something. |
|
489 | + $string = ''; |
|
490 | + |
|
491 | + foreach ($attributes as $attr => $value) { |
|
492 | + if ($attr == 'style') { |
|
493 | + $styles = explode(';', $value); |
|
494 | + |
|
495 | + $style_str = ''; |
|
496 | + foreach ($styles as $style) { |
|
497 | + if (!trim($style)) { |
|
498 | + continue; |
|
499 | + } |
|
500 | + list($style_attr, $style_value) = explode(':', trim($style)); |
|
501 | + $style_attr = trim($style_attr); |
|
502 | + $style_value = trim($style_value); |
|
503 | + |
|
504 | + if (in_array($style_attr, $allowed_styles)) { |
|
505 | + $style_str .= "$style_attr: $style_value; "; |
|
506 | + } |
|
507 | + } |
|
508 | + |
|
509 | + if ($style_str) { |
|
510 | + $style_str = trim($style_str); |
|
511 | + $string .= " style=\"$style_str\""; |
|
512 | + } |
|
513 | + } else { |
|
514 | + $string .= " $attr=\"$value\""; |
|
515 | + } |
|
516 | + } |
|
517 | + |
|
518 | + // Some WYSIWYG editors do not like tags like <p > so only add a space if needed. |
|
519 | + if ($string = trim($string)) { |
|
520 | + $string = " $string"; |
|
521 | + } |
|
522 | + |
|
523 | + $r = "<$element$string>"; |
|
524 | + return $r; |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | /** |
@@ -535,8 +535,8 @@ discard block |
||
535 | 535 | * @return array |
536 | 536 | */ |
537 | 537 | function _elgg_htmlawed_test($hook, $type, $value, $params) { |
538 | - $value[] = Paths::elgg() . 'engine/tests/ElggHtmLawedTest.php'; |
|
539 | - return $value; |
|
538 | + $value[] = Paths::elgg() . 'engine/tests/ElggHtmLawedTest.php'; |
|
539 | + return $value; |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | /** |
@@ -551,13 +551,13 @@ discard block |
||
551 | 551 | */ |
552 | 552 | function _elgg_disable_password_autocomplete($hook, $type, $return_value, $params) { |
553 | 553 | |
554 | - if (!_elgg_config()->security_disable_password_autocomplete) { |
|
555 | - return; |
|
556 | - } |
|
554 | + if (!_elgg_config()->security_disable_password_autocomplete) { |
|
555 | + return; |
|
556 | + } |
|
557 | 557 | |
558 | - $return_value['autocomplete'] = 'off'; |
|
558 | + $return_value['autocomplete'] = 'off'; |
|
559 | 559 | |
560 | - return $return_value; |
|
560 | + return $return_value; |
|
561 | 561 | } |
562 | 562 | |
563 | 563 | /** |
@@ -567,19 +567,19 @@ discard block |
||
567 | 567 | * @access private |
568 | 568 | */ |
569 | 569 | function _elgg_input_init() { |
570 | - // register an endpoint for live search / autocomplete. |
|
571 | - elgg_register_page_handler('livesearch', 'input_livesearch_page_handler'); |
|
570 | + // register an endpoint for live search / autocomplete. |
|
571 | + elgg_register_page_handler('livesearch', 'input_livesearch_page_handler'); |
|
572 | 572 | |
573 | - elgg_register_plugin_hook_handler('validate', 'input', '_elgg_htmlawed_filter_tags', 1); |
|
573 | + elgg_register_plugin_hook_handler('validate', 'input', '_elgg_htmlawed_filter_tags', 1); |
|
574 | 574 | |
575 | - elgg_register_plugin_hook_handler('unit_test', 'system', '_elgg_htmlawed_test'); |
|
575 | + elgg_register_plugin_hook_handler('unit_test', 'system', '_elgg_htmlawed_test'); |
|
576 | 576 | |
577 | - elgg_register_plugin_hook_handler('view_vars', 'input/password', '_elgg_disable_password_autocomplete'); |
|
577 | + elgg_register_plugin_hook_handler('view_vars', 'input/password', '_elgg_disable_password_autocomplete'); |
|
578 | 578 | } |
579 | 579 | |
580 | 580 | /** |
581 | 581 | * @see \Elgg\Application::loadCore Do not do work here. Just register for events. |
582 | 582 | */ |
583 | 583 | return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
584 | - $events->registerHandler('init', 'system', '_elgg_input_init'); |
|
584 | + $events->registerHandler('init', 'system', '_elgg_input_init'); |
|
585 | 585 | }; |
@@ -4,7 +4,6 @@ |
||
4 | 4 | * Contains functions for managing plugins |
5 | 5 | */ |
6 | 6 | |
7 | -use Elgg\Filesystem\Directory; |
|
8 | 7 | use Elgg\Project\Paths; |
9 | 8 | |
10 | 9 | /** |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @access private |
19 | 19 | */ |
20 | 20 | function _elgg_generate_plugin_entities() { |
21 | - return _elgg_services()->plugins->generateEntities(); |
|
21 | + return _elgg_services()->plugins->generateEntities(); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @access private |
30 | 30 | */ |
31 | 31 | function _elgg_cache_plugin_by_id(\ElggPlugin $plugin) { |
32 | - _elgg_services()->plugins->cache($plugin); |
|
32 | + _elgg_services()->plugins->cache($plugin); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * @since 1.8.0 |
41 | 41 | */ |
42 | 42 | function elgg_get_plugin_from_id($plugin_id) { |
43 | - return _elgg_services()->plugins->get($plugin_id); |
|
43 | + return _elgg_services()->plugins->get($plugin_id); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @return bool |
56 | 56 | */ |
57 | 57 | function elgg_plugin_exists($id) { |
58 | - return _elgg_services()->plugins->exists($id); |
|
58 | + return _elgg_services()->plugins->exists($id); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @access private |
67 | 67 | */ |
68 | 68 | function _elgg_get_max_plugin_priority() { |
69 | - return _elgg_services()->plugins->getMaxPriority(); |
|
69 | + return _elgg_services()->plugins->getMaxPriority(); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @return bool |
78 | 78 | */ |
79 | 79 | function elgg_is_active_plugin($plugin_id) { |
80 | - return _elgg_services()->plugins->isActive($plugin_id); |
|
80 | + return _elgg_services()->plugins->isActive($plugin_id); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * @since 1.8.0 |
89 | 89 | */ |
90 | 90 | function elgg_get_plugins($status = 'active') { |
91 | - return _elgg_services()->plugins->find($status); |
|
91 | + return _elgg_services()->plugins->find($status); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | * @access private |
108 | 108 | */ |
109 | 109 | function _elgg_namespace_plugin_private_setting($type, $name, $id = null) { |
110 | - return _elgg_services()->plugins->namespacePrivateSetting($type, $name, $id); |
|
110 | + return _elgg_services()->plugins->namespacePrivateSetting($type, $name, $id); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * @access private |
119 | 119 | */ |
120 | 120 | function _elgg_invalidate_plugins_provides_cache() { |
121 | - return _elgg_services()->plugins->invalidateProvidesCache(); |
|
121 | + return _elgg_services()->plugins->invalidateProvidesCache(); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | * @access private |
139 | 139 | */ |
140 | 140 | function _elgg_check_plugins_provides($type, $name, $version = null, $comparison = 'ge') { |
141 | - return _elgg_services()->plugins->checkProvides($type, $name, $version, $comparison); |
|
141 | + return _elgg_services()->plugins->checkProvides($type, $name, $version, $comparison); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @access private |
158 | 158 | */ |
159 | 159 | function _elgg_get_plugin_dependency_strings($dep) { |
160 | - return _elgg_services()->plugins->getDependencyStrings($dep); |
|
160 | + return _elgg_services()->plugins->getDependencyStrings($dep); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * @see \ElggPlugin::getAllUserSettings() |
173 | 173 | */ |
174 | 174 | function elgg_get_all_plugin_user_settings($user_guid = 0, $plugin_id = null, $return_obj = false) { |
175 | - return _elgg_services()->plugins->getAllUserSettings($user_guid, $plugin_id, $return_obj); |
|
175 | + return _elgg_services()->plugins->getAllUserSettings($user_guid, $plugin_id, $return_obj); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @see \ElggPlugin::setUserSetting() |
189 | 189 | */ |
190 | 190 | function elgg_set_plugin_user_setting($name, $value, $user_guid = 0, $plugin_id = null) { |
191 | - return _elgg_services()->plugins->setUserSetting($name, $value, $user_guid, $plugin_id); |
|
191 | + return _elgg_services()->plugins->setUserSetting($name, $value, $user_guid, $plugin_id); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @see \ElggPlugin::unsetUserSetting() |
204 | 204 | */ |
205 | 205 | function elgg_unset_plugin_user_setting($name, $user_guid = 0, $plugin_id = null) { |
206 | - return _elgg_services()->plugins->unsetUserSetting($name, $user_guid, $plugin_id); |
|
206 | + return _elgg_services()->plugins->unsetUserSetting($name, $user_guid, $plugin_id); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | * @see \ElggPlugin::getUserSetting() |
220 | 220 | */ |
221 | 221 | function elgg_get_plugin_user_setting($name, $user_guid = 0, $plugin_id = null, $default = null) { |
222 | - return _elgg_services()->plugins->getUserSetting($name, $user_guid, $plugin_id, $default); |
|
222 | + return _elgg_services()->plugins->getUserSetting($name, $user_guid, $plugin_id, $default); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | * @see \ElggPlugin::setSetting() |
235 | 235 | */ |
236 | 236 | function elgg_set_plugin_setting($name, $value, $plugin_id) { |
237 | - return _elgg_services()->plugins->setSetting($name, $value, $plugin_id); |
|
237 | + return _elgg_services()->plugins->setSetting($name, $value, $plugin_id); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | * @see \ElggPlugin::getSetting() |
250 | 250 | */ |
251 | 251 | function elgg_get_plugin_setting($name, $plugin_id, $default = null) { |
252 | - return _elgg_services()->plugins->getSetting($name, $plugin_id, $default); |
|
252 | + return _elgg_services()->plugins->getSetting($name, $plugin_id, $default); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | * @see \ElggPlugin::unsetSetting() |
264 | 264 | */ |
265 | 265 | function elgg_unset_plugin_setting($name, $plugin_id) { |
266 | - return _elgg_services()->plugins->unsetSetting($name, $plugin_id); |
|
266 | + return _elgg_services()->plugins->unsetSetting($name, $plugin_id); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | * @see \ElggPlugin::unsetAllSettings() |
277 | 277 | */ |
278 | 278 | function elgg_unset_all_plugin_settings($plugin_id) { |
279 | - return _elgg_services()->plugins->unsetAllSettings($plugin_id); |
|
279 | + return _elgg_services()->plugins->unsetAllSettings($plugin_id); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | /** |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | * @since 1.8.0 |
309 | 309 | */ |
310 | 310 | function elgg_get_entities_from_plugin_user_settings(array $options = []) { |
311 | - return _elgg_services()->plugins->getEntitiesFromUserSettings($options); |
|
311 | + return _elgg_services()->plugins->getEntitiesFromUserSettings($options); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | /** |
@@ -323,8 +323,8 @@ discard block |
||
323 | 323 | * @access private |
324 | 324 | */ |
325 | 325 | function _elgg_plugins_test($hook, $type, $value, $params) { |
326 | - $value[] = Paths::elgg() . 'engine/tests/ElggCorePluginsAPITest.php'; |
|
327 | - return $value; |
|
326 | + $value[] = Paths::elgg() . 'engine/tests/ElggCorePluginsAPITest.php'; |
|
327 | + return $value; |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
@@ -335,34 +335,34 @@ discard block |
||
335 | 335 | */ |
336 | 336 | function _elgg_plugins_init() { |
337 | 337 | |
338 | - if (elgg_is_admin_logged_in()) { |
|
339 | - elgg_register_ajax_view('object/plugin/full'); |
|
340 | - elgg_register_ajax_view('object/plugin/details'); |
|
341 | - } |
|
338 | + if (elgg_is_admin_logged_in()) { |
|
339 | + elgg_register_ajax_view('object/plugin/full'); |
|
340 | + elgg_register_ajax_view('object/plugin/details'); |
|
341 | + } |
|
342 | 342 | |
343 | - elgg_register_plugin_hook_handler('unit_test', 'system', '_elgg_plugins_test'); |
|
343 | + elgg_register_plugin_hook_handler('unit_test', 'system', '_elgg_plugins_test'); |
|
344 | 344 | |
345 | - /** |
|
346 | - * @see \Elgg\Database\Plugins::invalidateIsActiveCache |
|
347 | - */ |
|
348 | - $svc = _elgg_services()->plugins; |
|
349 | - elgg_register_event_handler('deactivate', 'plugin', [$svc, 'invalidateIsActiveCache']); |
|
350 | - elgg_register_event_handler('activate', 'plugin', [$svc, 'invalidateIsActiveCache']); |
|
345 | + /** |
|
346 | + * @see \Elgg\Database\Plugins::invalidateIsActiveCache |
|
347 | + */ |
|
348 | + $svc = _elgg_services()->plugins; |
|
349 | + elgg_register_event_handler('deactivate', 'plugin', [$svc, 'invalidateIsActiveCache']); |
|
350 | + elgg_register_event_handler('activate', 'plugin', [$svc, 'invalidateIsActiveCache']); |
|
351 | 351 | |
352 | - elgg_register_action("plugins/settings/save", '', 'admin'); |
|
353 | - elgg_register_action("plugins/usersettings/save"); |
|
352 | + elgg_register_action("plugins/settings/save", '', 'admin'); |
|
353 | + elgg_register_action("plugins/usersettings/save"); |
|
354 | 354 | |
355 | - elgg_register_action('admin/plugins/activate', '', 'admin'); |
|
356 | - elgg_register_action('admin/plugins/deactivate', '', 'admin'); |
|
357 | - elgg_register_action('admin/plugins/activate_all', '', 'admin'); |
|
358 | - elgg_register_action('admin/plugins/deactivate_all', '', 'admin'); |
|
355 | + elgg_register_action('admin/plugins/activate', '', 'admin'); |
|
356 | + elgg_register_action('admin/plugins/deactivate', '', 'admin'); |
|
357 | + elgg_register_action('admin/plugins/activate_all', '', 'admin'); |
|
358 | + elgg_register_action('admin/plugins/deactivate_all', '', 'admin'); |
|
359 | 359 | |
360 | - elgg_register_action('admin/plugins/set_priority', '', 'admin'); |
|
360 | + elgg_register_action('admin/plugins/set_priority', '', 'admin'); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | /** |
364 | 364 | * @see \Elgg\Application::loadCore Do not do work here. Just register for events. |
365 | 365 | */ |
366 | 366 | return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
367 | - $events->registerHandler('init', 'system', '_elgg_plugins_init'); |
|
367 | + $events->registerHandler('init', 'system', '_elgg_plugins_init'); |
|
368 | 368 | }; |
@@ -323,7 +323,7 @@ |
||
323 | 323 | * @access private |
324 | 324 | */ |
325 | 325 | function _elgg_plugins_test($hook, $type, $value, $params) { |
326 | - $value[] = Paths::elgg() . 'engine/tests/ElggCorePluginsAPITest.php'; |
|
326 | + $value[] = Paths::elgg().'engine/tests/ElggCorePluginsAPITest.php'; |
|
327 | 327 | return $value; |
328 | 328 | } |
329 | 329 |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | * @param bool $allow_multiple_emails Allow the same email address to be |
293 | 293 | * registered multiple times? |
294 | 294 | * |
295 | - * @return int|false The new user's GUID; false on failure |
|
295 | + * @return integer The new user's GUID; false on failure |
|
296 | 296 | * @throws RegistrationException |
297 | 297 | */ |
298 | 298 | function register_user($username, $password, $name, $email, $allow_multiple_emails = false) { |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | /** |
415 | 415 | * Sets the last action time of the given user to right now. |
416 | 416 | * |
417 | - * @param ElggUser|int $user The user or GUID |
|
417 | + * @param ElggUser $user The user or GUID |
|
418 | 418 | * @return void |
419 | 419 | */ |
420 | 420 | function set_last_action($user) { |
@@ -695,7 +695,7 @@ discard block |
||
695 | 695 | * /avatar/edit/<username> |
696 | 696 | * |
697 | 697 | * @param array $page |
698 | - * @return bool |
|
698 | + * @return boolean|null |
|
699 | 699 | * @access private |
700 | 700 | */ |
701 | 701 | function elgg_avatar_page_handler($page) { |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * @return bool Depending on success |
18 | 18 | */ |
19 | 19 | function disable_user_entities($owner_guid) { |
20 | - return _elgg_services()->usersTable->disableEntities($owner_guid); |
|
20 | + return _elgg_services()->usersTable->disableEntities($owner_guid); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | /** |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @return bool |
30 | 30 | */ |
31 | 31 | function ban_user($user_guid, $reason = "") { |
32 | - return _elgg_services()->usersTable->ban($user_guid, $reason); |
|
32 | + return _elgg_services()->usersTable->ban($user_guid, $reason); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * @return bool |
41 | 41 | */ |
42 | 42 | function unban_user($user_guid) { |
43 | - return _elgg_services()->usersTable->unban($user_guid); |
|
43 | + return _elgg_services()->usersTable->unban($user_guid); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * @return bool |
52 | 52 | */ |
53 | 53 | function make_user_admin($user_guid) { |
54 | - return _elgg_services()->usersTable->makeAdmin($user_guid); |
|
54 | + return _elgg_services()->usersTable->makeAdmin($user_guid); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @return bool |
63 | 63 | */ |
64 | 64 | function remove_user_admin($user_guid) { |
65 | - return _elgg_services()->usersTable->removeAdmin($user_guid); |
|
65 | + return _elgg_services()->usersTable->removeAdmin($user_guid); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * @return \ElggUser|false |
76 | 76 | */ |
77 | 77 | function get_user($guid) { |
78 | - return _elgg_services()->entityTable->get($guid, 'user'); |
|
78 | + return _elgg_services()->entityTable->get($guid, 'user'); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @return \ElggUser|false Depending on success |
87 | 87 | */ |
88 | 88 | function get_user_by_username($username) { |
89 | - return _elgg_services()->usersTable->getByUsername($username); |
|
89 | + return _elgg_services()->usersTable->getByUsername($username); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * @return \ElggUser |
98 | 98 | */ |
99 | 99 | function get_user_by_code($hash) { |
100 | - return _elgg_services()->persistentLogin->getUserFromHash($hash); |
|
100 | + return _elgg_services()->persistentLogin->getUserFromHash($hash); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * @return array |
109 | 109 | */ |
110 | 110 | function get_user_by_email($email) { |
111 | - return _elgg_services()->usersTable->getByEmail($email); |
|
111 | + return _elgg_services()->usersTable->getByEmail($email); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | * @return \ElggUser[]|int |
125 | 125 | */ |
126 | 126 | function find_active_users(array $options = []) { |
127 | - return _elgg_services()->usersTable->findActive($options); |
|
127 | + return _elgg_services()->usersTable->findActive($options); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * @return bool |
136 | 136 | */ |
137 | 137 | function send_new_password_request($user_guid) { |
138 | - return _elgg_services()->passwords->sendNewPasswordRequest($user_guid); |
|
138 | + return _elgg_services()->passwords->sendNewPasswordRequest($user_guid); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @return bool |
150 | 150 | */ |
151 | 151 | function force_user_password_reset($user_guid, $password) { |
152 | - return _elgg_services()->passwords->forcePasswordReset($user_guid, $password); |
|
152 | + return _elgg_services()->passwords->forcePasswordReset($user_guid, $password); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * @return bool True on success |
163 | 163 | */ |
164 | 164 | function execute_new_password_request($user_guid, $conf_code, $password = null) { |
165 | - return _elgg_services()->passwords->executeNewPasswordReset($user_guid, $conf_code, $password); |
|
165 | + return _elgg_services()->passwords->executeNewPasswordReset($user_guid, $conf_code, $password); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | * @return string |
172 | 172 | */ |
173 | 173 | function generate_random_cleartext_password() { |
174 | - return _elgg_services()->crypto->getRandomString(12, \ElggCrypto::CHARS_PASSWORD); |
|
174 | + return _elgg_services()->crypto->getRandomString(12, \ElggCrypto::CHARS_PASSWORD); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
@@ -185,57 +185,57 @@ discard block |
||
185 | 185 | * @throws RegistrationException on invalid |
186 | 186 | */ |
187 | 187 | function validate_username($username) { |
188 | - $config = _elgg_config(); |
|
189 | - |
|
190 | - // Basic, check length |
|
191 | - if (!isset($config->minusername)) { |
|
192 | - $config->minusername = 4; |
|
193 | - } |
|
194 | - |
|
195 | - if (strlen($username) < $config->minusername) { |
|
196 | - $msg = elgg_echo('registration:usernametooshort', [$config->minusername]); |
|
197 | - throw new \RegistrationException($msg); |
|
198 | - } |
|
199 | - |
|
200 | - // username in the database has a limit of 128 characters |
|
201 | - if (strlen($username) > 128) { |
|
202 | - $msg = elgg_echo('registration:usernametoolong', [128]); |
|
203 | - throw new \RegistrationException($msg); |
|
204 | - } |
|
205 | - |
|
206 | - // Blacklist for bad characters (partially nicked from mediawiki) |
|
207 | - $blacklist = '/[' . |
|
208 | - '\x{0080}-\x{009f}' . // iso-8859-1 control chars |
|
209 | - '\x{00a0}' . // non-breaking space |
|
210 | - '\x{2000}-\x{200f}' . // various whitespace |
|
211 | - '\x{2028}-\x{202f}' . // breaks and control chars |
|
212 | - '\x{3000}' . // ideographic space |
|
213 | - '\x{e000}-\x{f8ff}' . // private use |
|
214 | - ']/u'; |
|
215 | - |
|
216 | - if (preg_match($blacklist, $username)) { |
|
217 | - // @todo error message needs work |
|
218 | - throw new \RegistrationException(elgg_echo('registration:invalidchars')); |
|
219 | - } |
|
220 | - |
|
221 | - // Belts and braces |
|
222 | - // @todo Tidy into main unicode |
|
223 | - $blacklist2 = '\'/\\"*& ?#%^(){}[]~?<>;|¬`@+='; |
|
224 | - |
|
225 | - $blacklist2 = elgg_trigger_plugin_hook('username:character_blacklist', 'user', |
|
226 | - ['blacklist' => $blacklist2], $blacklist2); |
|
227 | - |
|
228 | - for ($n = 0; $n < strlen($blacklist2); $n++) { |
|
229 | - if (strpos($username, $blacklist2[$n]) !== false) { |
|
230 | - $msg = elgg_echo('registration:invalidchars', [$blacklist2[$n], $blacklist2]); |
|
231 | - $msg = htmlspecialchars($msg, ENT_QUOTES, 'UTF-8'); |
|
232 | - throw new \RegistrationException($msg); |
|
233 | - } |
|
234 | - } |
|
235 | - |
|
236 | - $result = true; |
|
237 | - return elgg_trigger_plugin_hook('registeruser:validate:username', 'all', |
|
238 | - ['username' => $username], $result); |
|
188 | + $config = _elgg_config(); |
|
189 | + |
|
190 | + // Basic, check length |
|
191 | + if (!isset($config->minusername)) { |
|
192 | + $config->minusername = 4; |
|
193 | + } |
|
194 | + |
|
195 | + if (strlen($username) < $config->minusername) { |
|
196 | + $msg = elgg_echo('registration:usernametooshort', [$config->minusername]); |
|
197 | + throw new \RegistrationException($msg); |
|
198 | + } |
|
199 | + |
|
200 | + // username in the database has a limit of 128 characters |
|
201 | + if (strlen($username) > 128) { |
|
202 | + $msg = elgg_echo('registration:usernametoolong', [128]); |
|
203 | + throw new \RegistrationException($msg); |
|
204 | + } |
|
205 | + |
|
206 | + // Blacklist for bad characters (partially nicked from mediawiki) |
|
207 | + $blacklist = '/[' . |
|
208 | + '\x{0080}-\x{009f}' . // iso-8859-1 control chars |
|
209 | + '\x{00a0}' . // non-breaking space |
|
210 | + '\x{2000}-\x{200f}' . // various whitespace |
|
211 | + '\x{2028}-\x{202f}' . // breaks and control chars |
|
212 | + '\x{3000}' . // ideographic space |
|
213 | + '\x{e000}-\x{f8ff}' . // private use |
|
214 | + ']/u'; |
|
215 | + |
|
216 | + if (preg_match($blacklist, $username)) { |
|
217 | + // @todo error message needs work |
|
218 | + throw new \RegistrationException(elgg_echo('registration:invalidchars')); |
|
219 | + } |
|
220 | + |
|
221 | + // Belts and braces |
|
222 | + // @todo Tidy into main unicode |
|
223 | + $blacklist2 = '\'/\\"*& ?#%^(){}[]~?<>;|¬`@+='; |
|
224 | + |
|
225 | + $blacklist2 = elgg_trigger_plugin_hook('username:character_blacklist', 'user', |
|
226 | + ['blacklist' => $blacklist2], $blacklist2); |
|
227 | + |
|
228 | + for ($n = 0; $n < strlen($blacklist2); $n++) { |
|
229 | + if (strpos($username, $blacklist2[$n]) !== false) { |
|
230 | + $msg = elgg_echo('registration:invalidchars', [$blacklist2[$n], $blacklist2]); |
|
231 | + $msg = htmlspecialchars($msg, ENT_QUOTES, 'UTF-8'); |
|
232 | + throw new \RegistrationException($msg); |
|
233 | + } |
|
234 | + } |
|
235 | + |
|
236 | + $result = true; |
|
237 | + return elgg_trigger_plugin_hook('registeruser:validate:username', 'all', |
|
238 | + ['username' => $username], $result); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | /** |
@@ -247,20 +247,20 @@ discard block |
||
247 | 247 | * @throws RegistrationException on invalid |
248 | 248 | */ |
249 | 249 | function validate_password($password) { |
250 | - $config = _elgg_config(); |
|
250 | + $config = _elgg_config(); |
|
251 | 251 | |
252 | - if (!isset($config->min_password_length)) { |
|
253 | - $config->min_password_length = 6; |
|
254 | - } |
|
252 | + if (!isset($config->min_password_length)) { |
|
253 | + $config->min_password_length = 6; |
|
254 | + } |
|
255 | 255 | |
256 | - if (strlen($password) < $config->min_password_length) { |
|
257 | - $msg = elgg_echo('registration:passwordtooshort', [$config->min_password_length]); |
|
258 | - throw new \RegistrationException($msg); |
|
259 | - } |
|
256 | + if (strlen($password) < $config->min_password_length) { |
|
257 | + $msg = elgg_echo('registration:passwordtooshort', [$config->min_password_length]); |
|
258 | + throw new \RegistrationException($msg); |
|
259 | + } |
|
260 | 260 | |
261 | - $result = true; |
|
262 | - return elgg_trigger_plugin_hook('registeruser:validate:password', 'all', |
|
263 | - ['password' => $password], $result); |
|
261 | + $result = true; |
|
262 | + return elgg_trigger_plugin_hook('registeruser:validate:password', 'all', |
|
263 | + ['password' => $password], $result); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
@@ -272,14 +272,14 @@ discard block |
||
272 | 272 | * @return bool |
273 | 273 | */ |
274 | 274 | function validate_email_address($address) { |
275 | - if (!is_email_address($address)) { |
|
276 | - throw new \RegistrationException(elgg_echo('registration:notemail')); |
|
277 | - } |
|
275 | + if (!is_email_address($address)) { |
|
276 | + throw new \RegistrationException(elgg_echo('registration:notemail')); |
|
277 | + } |
|
278 | 278 | |
279 | - // Got here, so lets try a hook (defaulting to ok) |
|
280 | - $result = true; |
|
281 | - return elgg_trigger_plugin_hook('registeruser:validate:email', 'all', |
|
282 | - ['email' => $address], $result); |
|
279 | + // Got here, so lets try a hook (defaulting to ok) |
|
280 | + $result = true; |
|
281 | + return elgg_trigger_plugin_hook('registeruser:validate:email', 'all', |
|
282 | + ['email' => $address], $result); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | * @throws RegistrationException |
297 | 297 | */ |
298 | 298 | function register_user($username, $password, $name, $email, $allow_multiple_emails = false) { |
299 | - return _elgg_services()->usersTable->register($username, $password, $name, $email, $allow_multiple_emails); |
|
299 | + return _elgg_services()->usersTable->register($username, $password, $name, $email, $allow_multiple_emails); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | * @see elgg_validate_invite_code |
309 | 309 | */ |
310 | 310 | function generate_invite_code($username) { |
311 | - return _elgg_services()->usersTable->generateInviteCode($username); |
|
311 | + return _elgg_services()->usersTable->generateInviteCode($username); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | /** |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | * @since 1.10 |
323 | 323 | */ |
324 | 324 | function elgg_validate_invite_code($username, $code) { |
325 | - return _elgg_services()->usersTable->validateInviteCode($username, $code); |
|
325 | + return _elgg_services()->usersTable->validateInviteCode($username, $code); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | * @since 1.8.0 |
336 | 336 | */ |
337 | 337 | function elgg_set_user_validation_status($user_guid, $status, $method = '') { |
338 | - return _elgg_services()->usersTable->setValidationStatus($user_guid, $status, $method); |
|
338 | + return _elgg_services()->usersTable->setValidationStatus($user_guid, $status, $method); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | * @since 1.8.0 |
347 | 347 | */ |
348 | 348 | function elgg_get_user_validation_status($user_guid) { |
349 | - return _elgg_services()->usersTable->getValidationStatus($user_guid); |
|
349 | + return _elgg_services()->usersTable->getValidationStatus($user_guid); |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | /** |
@@ -360,24 +360,24 @@ discard block |
||
360 | 360 | */ |
361 | 361 | function elgg_user_account_page_handler($page_elements, $handler) { |
362 | 362 | |
363 | - switch ($handler) { |
|
364 | - case 'login': |
|
365 | - echo elgg_view_resource("account/login"); |
|
366 | - break; |
|
367 | - case 'forgotpassword': |
|
368 | - echo elgg_view_resource("account/forgotten_password"); |
|
369 | - break; |
|
370 | - case 'changepassword': |
|
371 | - echo elgg_view_resource("account/change_password"); |
|
372 | - break; |
|
373 | - case 'register': |
|
374 | - echo elgg_view_resource("account/register"); |
|
375 | - break; |
|
376 | - default: |
|
377 | - return false; |
|
378 | - } |
|
363 | + switch ($handler) { |
|
364 | + case 'login': |
|
365 | + echo elgg_view_resource("account/login"); |
|
366 | + break; |
|
367 | + case 'forgotpassword': |
|
368 | + echo elgg_view_resource("account/forgotten_password"); |
|
369 | + break; |
|
370 | + case 'changepassword': |
|
371 | + echo elgg_view_resource("account/change_password"); |
|
372 | + break; |
|
373 | + case 'register': |
|
374 | + echo elgg_view_resource("account/register"); |
|
375 | + break; |
|
376 | + default: |
|
377 | + return false; |
|
378 | + } |
|
379 | 379 | |
380 | - return true; |
|
380 | + return true; |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
@@ -391,9 +391,9 @@ discard block |
||
391 | 391 | * @return string |
392 | 392 | */ |
393 | 393 | function elgg_get_registration_url(array $query = [], $fragment = '') { |
394 | - $url = elgg_normalize_url('register'); |
|
395 | - $url = elgg_http_add_url_query_elements($url, $query) . $fragment; |
|
396 | - return elgg_trigger_plugin_hook('registration_url', 'site', $query, $url); |
|
394 | + $url = elgg_normalize_url('register'); |
|
395 | + $url = elgg_http_add_url_query_elements($url, $query) . $fragment; |
|
396 | + return elgg_trigger_plugin_hook('registration_url', 'site', $query, $url); |
|
397 | 397 | } |
398 | 398 | |
399 | 399 | /** |
@@ -406,9 +406,9 @@ discard block |
||
406 | 406 | * @return string |
407 | 407 | */ |
408 | 408 | function elgg_get_login_url(array $query = [], $fragment = '') { |
409 | - $url = elgg_normalize_url('login'); |
|
410 | - $url = elgg_http_add_url_query_elements($url, $query) . $fragment; |
|
411 | - return elgg_trigger_plugin_hook('login_url', 'site', $query, $url); |
|
409 | + $url = elgg_normalize_url('login'); |
|
410 | + $url = elgg_http_add_url_query_elements($url, $query) . $fragment; |
|
411 | + return elgg_trigger_plugin_hook('login_url', 'site', $query, $url); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | /** |
@@ -418,16 +418,16 @@ discard block |
||
418 | 418 | * @return void |
419 | 419 | */ |
420 | 420 | function set_last_action($user) { |
421 | - if (!$user) { |
|
422 | - return; |
|
423 | - } |
|
424 | - if (!$user instanceof ElggUser) { |
|
425 | - $user = get_user($user); |
|
426 | - } |
|
427 | - if (!$user) { |
|
428 | - return; |
|
429 | - } |
|
430 | - _elgg_services()->usersTable->setLastAction($user); |
|
421 | + if (!$user) { |
|
422 | + return; |
|
423 | + } |
|
424 | + if (!$user instanceof ElggUser) { |
|
425 | + $user = get_user($user); |
|
426 | + } |
|
427 | + if (!$user) { |
|
428 | + return; |
|
429 | + } |
|
430 | + _elgg_services()->usersTable->setLastAction($user); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | /** |
@@ -437,11 +437,11 @@ discard block |
||
437 | 437 | * @return void |
438 | 438 | */ |
439 | 439 | function set_last_login($user_guid) { |
440 | - $user = get_user($user_guid); |
|
441 | - if (!$user) { |
|
442 | - return; |
|
443 | - } |
|
444 | - _elgg_services()->usersTable->setLastLogin($user); |
|
440 | + $user = get_user($user_guid); |
|
441 | + if (!$user) { |
|
442 | + return; |
|
443 | + } |
|
444 | + _elgg_services()->usersTable->setLastLogin($user); |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | /** |
@@ -456,23 +456,23 @@ discard block |
||
456 | 456 | * @access private |
457 | 457 | */ |
458 | 458 | function user_avatar_hook($hook, $type, $return, $params) { |
459 | - $user = elgg_extract('entity', $params); |
|
460 | - $size = elgg_extract('size', $params, 'medium'); |
|
459 | + $user = elgg_extract('entity', $params); |
|
460 | + $size = elgg_extract('size', $params, 'medium'); |
|
461 | 461 | |
462 | - if (!$user instanceof ElggUser) { |
|
463 | - return; |
|
464 | - } |
|
462 | + if (!$user instanceof ElggUser) { |
|
463 | + return; |
|
464 | + } |
|
465 | 465 | |
466 | - if (_elgg_config()->walled_garden) { |
|
467 | - return; |
|
468 | - } |
|
466 | + if (_elgg_config()->walled_garden) { |
|
467 | + return; |
|
468 | + } |
|
469 | 469 | |
470 | - if (!$user->hasIcon($size, 'icon')) { |
|
471 | - return; |
|
472 | - } |
|
470 | + if (!$user->hasIcon($size, 'icon')) { |
|
471 | + return; |
|
472 | + } |
|
473 | 473 | |
474 | - $icon = $user->getIcon($size, 'icon'); |
|
475 | - return elgg_get_inline_url($icon, false); |
|
474 | + $icon = $user->getIcon($size, 'icon'); |
|
475 | + return elgg_get_inline_url($icon, false); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | /** |
@@ -480,104 +480,104 @@ discard block |
||
480 | 480 | * @access private |
481 | 481 | */ |
482 | 482 | function elgg_user_hover_menu($hook, $type, $return, $params) { |
483 | - $user = elgg_extract('entity', $params); |
|
484 | - /* @var \ElggUser $user */ |
|
485 | - |
|
486 | - if (!$user instanceof \ElggUser) { |
|
487 | - return; |
|
488 | - } |
|
489 | - |
|
490 | - if (!elgg_is_logged_in()) { |
|
491 | - return; |
|
492 | - } |
|
493 | - |
|
494 | - if ($user->canEdit()) { |
|
495 | - $return[] = ElggMenuItem::factory([ |
|
496 | - 'name' => 'avatar:edit', |
|
497 | - 'text' => elgg_echo('avatar:edit'), |
|
498 | - 'icon' => 'image', |
|
499 | - 'href' => "avatar/edit/$user->username", |
|
500 | - 'section' => (elgg_get_logged_in_user_guid() == $user->guid)? 'action' : 'admin', |
|
501 | - ]); |
|
502 | - } |
|
503 | - |
|
504 | - // prevent admins from banning or deleting themselves |
|
505 | - if (elgg_get_logged_in_user_guid() == $user->guid) { |
|
506 | - return $return; |
|
507 | - } |
|
508 | - |
|
509 | - if (!elgg_is_admin_logged_in()) { |
|
510 | - return $return; |
|
511 | - } |
|
512 | - |
|
513 | - // following items are admin only |
|
514 | - if (!$user->isBanned()) { |
|
515 | - $return[] = ElggMenuItem::factory([ |
|
516 | - 'name' => 'ban', |
|
517 | - 'text' => elgg_echo('ban'), |
|
518 | - 'icon' => 'ban', |
|
519 | - 'href' => "action/admin/user/ban?guid={$user->guid}", |
|
520 | - 'confirm' => true, |
|
521 | - 'section' => 'admin', |
|
522 | - ]); |
|
523 | - } else { |
|
524 | - $return[] = ElggMenuItem::factory([ |
|
525 | - 'name' => 'unban', |
|
526 | - 'text' => elgg_echo('unban'), |
|
527 | - 'icon' => 'ban', |
|
528 | - 'href' => "action/admin/user/unban?guid={$user->guid}", |
|
529 | - 'confirm' => true, |
|
530 | - 'section' => 'admin', |
|
531 | - ]); |
|
532 | - } |
|
533 | - |
|
534 | - $return[] = ElggMenuItem::factory([ |
|
535 | - 'name' => 'delete', |
|
536 | - 'text' => elgg_echo('delete'), |
|
537 | - 'icon' => 'delete', |
|
538 | - 'href' => "action/admin/user/delete?guid={$user->guid}", |
|
539 | - 'confirm' => true, |
|
540 | - 'section' => 'admin', |
|
541 | - ]); |
|
542 | - |
|
543 | - $return[] = ElggMenuItem::factory([ |
|
544 | - 'name' => 'resetpassword', |
|
545 | - 'text' => elgg_echo('resetpassword'), |
|
546 | - 'icon' => 'refresh', |
|
547 | - 'href' => "action/admin/user/resetpassword?guid={$user->guid}", |
|
548 | - 'confirm' => true, |
|
549 | - 'section' => 'admin', |
|
550 | - ]); |
|
551 | - |
|
552 | - if (!$user->isAdmin()) { |
|
553 | - $return[] = ElggMenuItem::factory([ |
|
554 | - 'name' => 'makeadmin', |
|
555 | - 'text' => elgg_echo('makeadmin'), |
|
556 | - 'icon' => 'level-up', |
|
557 | - 'href' => "action/admin/user/makeadmin?guid={$user->guid}", |
|
558 | - 'confirm' => true, |
|
559 | - 'section' => 'admin', |
|
560 | - ]); |
|
561 | - } else { |
|
562 | - $return[] = ElggMenuItem::factory([ |
|
563 | - 'name' => 'removeadmin', |
|
564 | - 'text' => elgg_echo('removeadmin'), |
|
565 | - 'icon' => 'level-down', |
|
566 | - 'href' => "action/admin/user/removeadmin?guid={$user->guid}", |
|
567 | - 'confirm' => true, |
|
568 | - 'section' => 'admin', |
|
569 | - ]); |
|
570 | - } |
|
571 | - |
|
572 | - $return[] = ElggMenuItem::factory([ |
|
573 | - 'name' => 'settings:edit', |
|
574 | - 'text' => elgg_echo('settings:edit'), |
|
575 | - 'icon' => 'cogs', |
|
576 | - 'href' => "settings/user/$user->username", |
|
577 | - 'section' => 'admin', |
|
578 | - ]); |
|
579 | - |
|
580 | - return $return; |
|
483 | + $user = elgg_extract('entity', $params); |
|
484 | + /* @var \ElggUser $user */ |
|
485 | + |
|
486 | + if (!$user instanceof \ElggUser) { |
|
487 | + return; |
|
488 | + } |
|
489 | + |
|
490 | + if (!elgg_is_logged_in()) { |
|
491 | + return; |
|
492 | + } |
|
493 | + |
|
494 | + if ($user->canEdit()) { |
|
495 | + $return[] = ElggMenuItem::factory([ |
|
496 | + 'name' => 'avatar:edit', |
|
497 | + 'text' => elgg_echo('avatar:edit'), |
|
498 | + 'icon' => 'image', |
|
499 | + 'href' => "avatar/edit/$user->username", |
|
500 | + 'section' => (elgg_get_logged_in_user_guid() == $user->guid)? 'action' : 'admin', |
|
501 | + ]); |
|
502 | + } |
|
503 | + |
|
504 | + // prevent admins from banning or deleting themselves |
|
505 | + if (elgg_get_logged_in_user_guid() == $user->guid) { |
|
506 | + return $return; |
|
507 | + } |
|
508 | + |
|
509 | + if (!elgg_is_admin_logged_in()) { |
|
510 | + return $return; |
|
511 | + } |
|
512 | + |
|
513 | + // following items are admin only |
|
514 | + if (!$user->isBanned()) { |
|
515 | + $return[] = ElggMenuItem::factory([ |
|
516 | + 'name' => 'ban', |
|
517 | + 'text' => elgg_echo('ban'), |
|
518 | + 'icon' => 'ban', |
|
519 | + 'href' => "action/admin/user/ban?guid={$user->guid}", |
|
520 | + 'confirm' => true, |
|
521 | + 'section' => 'admin', |
|
522 | + ]); |
|
523 | + } else { |
|
524 | + $return[] = ElggMenuItem::factory([ |
|
525 | + 'name' => 'unban', |
|
526 | + 'text' => elgg_echo('unban'), |
|
527 | + 'icon' => 'ban', |
|
528 | + 'href' => "action/admin/user/unban?guid={$user->guid}", |
|
529 | + 'confirm' => true, |
|
530 | + 'section' => 'admin', |
|
531 | + ]); |
|
532 | + } |
|
533 | + |
|
534 | + $return[] = ElggMenuItem::factory([ |
|
535 | + 'name' => 'delete', |
|
536 | + 'text' => elgg_echo('delete'), |
|
537 | + 'icon' => 'delete', |
|
538 | + 'href' => "action/admin/user/delete?guid={$user->guid}", |
|
539 | + 'confirm' => true, |
|
540 | + 'section' => 'admin', |
|
541 | + ]); |
|
542 | + |
|
543 | + $return[] = ElggMenuItem::factory([ |
|
544 | + 'name' => 'resetpassword', |
|
545 | + 'text' => elgg_echo('resetpassword'), |
|
546 | + 'icon' => 'refresh', |
|
547 | + 'href' => "action/admin/user/resetpassword?guid={$user->guid}", |
|
548 | + 'confirm' => true, |
|
549 | + 'section' => 'admin', |
|
550 | + ]); |
|
551 | + |
|
552 | + if (!$user->isAdmin()) { |
|
553 | + $return[] = ElggMenuItem::factory([ |
|
554 | + 'name' => 'makeadmin', |
|
555 | + 'text' => elgg_echo('makeadmin'), |
|
556 | + 'icon' => 'level-up', |
|
557 | + 'href' => "action/admin/user/makeadmin?guid={$user->guid}", |
|
558 | + 'confirm' => true, |
|
559 | + 'section' => 'admin', |
|
560 | + ]); |
|
561 | + } else { |
|
562 | + $return[] = ElggMenuItem::factory([ |
|
563 | + 'name' => 'removeadmin', |
|
564 | + 'text' => elgg_echo('removeadmin'), |
|
565 | + 'icon' => 'level-down', |
|
566 | + 'href' => "action/admin/user/removeadmin?guid={$user->guid}", |
|
567 | + 'confirm' => true, |
|
568 | + 'section' => 'admin', |
|
569 | + ]); |
|
570 | + } |
|
571 | + |
|
572 | + $return[] = ElggMenuItem::factory([ |
|
573 | + 'name' => 'settings:edit', |
|
574 | + 'text' => elgg_echo('settings:edit'), |
|
575 | + 'icon' => 'cogs', |
|
576 | + 'href' => "settings/user/$user->username", |
|
577 | + 'section' => 'admin', |
|
578 | + ]); |
|
579 | + |
|
580 | + return $return; |
|
581 | 581 | } |
582 | 582 | |
583 | 583 | /** |
@@ -590,15 +590,15 @@ discard block |
||
590 | 590 | * @access private |
591 | 591 | */ |
592 | 592 | function elgg_avatar_page_handler($page) { |
593 | - $user = get_user_by_username(elgg_extract(1, $page)); |
|
594 | - if ($user) { |
|
595 | - elgg_set_page_owner_guid($user->getGUID()); |
|
596 | - } |
|
593 | + $user = get_user_by_username(elgg_extract(1, $page)); |
|
594 | + if ($user) { |
|
595 | + elgg_set_page_owner_guid($user->getGUID()); |
|
596 | + } |
|
597 | 597 | |
598 | - if ($page[0] == 'edit') { |
|
599 | - echo elgg_view_resource("avatar/edit"); |
|
600 | - return true; |
|
601 | - } |
|
598 | + if ($page[0] == 'edit') { |
|
599 | + echo elgg_view_resource("avatar/edit"); |
|
600 | + return true; |
|
601 | + } |
|
602 | 602 | } |
603 | 603 | |
604 | 604 | /** |
@@ -611,10 +611,10 @@ discard block |
||
611 | 611 | * @access private |
612 | 612 | */ |
613 | 613 | function _elgg_user_page_handler($page) { |
614 | - echo elgg_view_resource('user/view', [ |
|
615 | - 'guid' => (int) elgg_extract(1, $page), |
|
616 | - ]); |
|
617 | - return true; |
|
614 | + echo elgg_view_resource('user/view', [ |
|
615 | + 'guid' => (int) elgg_extract(1, $page), |
|
616 | + ]); |
|
617 | + return true; |
|
618 | 618 | } |
619 | 619 | |
620 | 620 | /** |
@@ -633,20 +633,20 @@ discard block |
||
633 | 633 | */ |
634 | 634 | function _elgg_user_page_menu($hook, $type, $return, $params) { |
635 | 635 | |
636 | - $owner = elgg_get_page_owner_entity(); |
|
637 | - if (!$owner) { |
|
638 | - return; |
|
639 | - } |
|
636 | + $owner = elgg_get_page_owner_entity(); |
|
637 | + if (!$owner) { |
|
638 | + return; |
|
639 | + } |
|
640 | 640 | |
641 | - $return[] = \ElggMenuItem::factory([ |
|
642 | - 'name' => 'edit_avatar', |
|
643 | - 'href' => "avatar/edit/{$owner->username}", |
|
644 | - 'text' => elgg_echo('avatar:edit'), |
|
645 | - 'section' => '1_profile', |
|
646 | - 'contexts' => ['settings'], |
|
647 | - ]); |
|
641 | + $return[] = \ElggMenuItem::factory([ |
|
642 | + 'name' => 'edit_avatar', |
|
643 | + 'href' => "avatar/edit/{$owner->username}", |
|
644 | + 'text' => elgg_echo('avatar:edit'), |
|
645 | + 'section' => '1_profile', |
|
646 | + 'contexts' => ['settings'], |
|
647 | + ]); |
|
648 | 648 | |
649 | - return $return; |
|
649 | + return $return; |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | /** |
@@ -665,68 +665,68 @@ discard block |
||
665 | 665 | */ |
666 | 666 | function _elgg_user_topbar_menu($hook, $type, $return, $params) { |
667 | 667 | |
668 | - $viewer = elgg_get_logged_in_user_entity(); |
|
669 | - if (!$viewer) { |
|
670 | - return; |
|
671 | - } |
|
672 | - |
|
673 | - $toggle = elgg_view_icon('chevron-down', ['class' => 'elgg-state-closed']); |
|
674 | - $toggle .= elgg_view_icon('chevron-up', ['class' => 'elgg-state-opened']); |
|
675 | - |
|
676 | - // If JS fails here, allow easy access to place where they can upgrade/flush caches |
|
677 | - $href = elgg_is_admin_logged_in() ? 'admin' : '#'; |
|
678 | - |
|
679 | - $return[] = \ElggMenuItem::factory([ |
|
680 | - 'name' => 'account', |
|
681 | - 'text' => elgg_echo('account') . $toggle, |
|
682 | - 'href' => $href, |
|
683 | - 'priority' => 800, |
|
684 | - 'section' => 'alt', |
|
685 | - 'child_menu' => [ |
|
686 | - 'display' => 'dropdown', |
|
687 | - 'class' => 'elgg-topbar-child-menu', |
|
688 | - 'data-position' => json_encode([ |
|
689 | - 'at' => 'right+10px bottom', |
|
690 | - 'my' => 'right top', |
|
691 | - 'collision' => 'fit fit', |
|
692 | - ]), |
|
693 | - ], |
|
694 | - ]); |
|
695 | - |
|
696 | - $return[] = \ElggMenuItem::factory([ |
|
697 | - 'name' => 'usersettings', |
|
698 | - 'parent_name' => 'account', |
|
699 | - 'href' => "settings/user/{$viewer->username}", |
|
700 | - 'text' => elgg_echo('settings'), |
|
701 | - 'icon' => 'cogs', |
|
702 | - 'priority' => 300, |
|
703 | - 'section' => 'alt', |
|
704 | - ]); |
|
705 | - |
|
706 | - if ($viewer->isAdmin()) { |
|
707 | - $return[] = \ElggMenuItem::factory([ |
|
708 | - 'name' => 'administration', |
|
709 | - 'parent_name' => 'account', |
|
710 | - 'href' => 'admin', |
|
711 | - 'text' => elgg_echo('admin'), |
|
712 | - 'icon' => 'tasks', |
|
713 | - 'priority' => 800, |
|
714 | - 'section' => 'alt', |
|
715 | - ]); |
|
716 | - } |
|
717 | - |
|
718 | - $return[] = \ElggMenuItem::factory([ |
|
719 | - 'name' => 'logout', |
|
720 | - 'parent_name' => 'account', |
|
721 | - 'href' => 'action/logout', |
|
722 | - 'text' => elgg_echo('logout'), |
|
723 | - 'icon' => 'sign-out', |
|
724 | - 'is_action' => true, |
|
725 | - 'priority' => 900, |
|
726 | - 'section' => 'alt', |
|
727 | - ]); |
|
728 | - |
|
729 | - return $return; |
|
668 | + $viewer = elgg_get_logged_in_user_entity(); |
|
669 | + if (!$viewer) { |
|
670 | + return; |
|
671 | + } |
|
672 | + |
|
673 | + $toggle = elgg_view_icon('chevron-down', ['class' => 'elgg-state-closed']); |
|
674 | + $toggle .= elgg_view_icon('chevron-up', ['class' => 'elgg-state-opened']); |
|
675 | + |
|
676 | + // If JS fails here, allow easy access to place where they can upgrade/flush caches |
|
677 | + $href = elgg_is_admin_logged_in() ? 'admin' : '#'; |
|
678 | + |
|
679 | + $return[] = \ElggMenuItem::factory([ |
|
680 | + 'name' => 'account', |
|
681 | + 'text' => elgg_echo('account') . $toggle, |
|
682 | + 'href' => $href, |
|
683 | + 'priority' => 800, |
|
684 | + 'section' => 'alt', |
|
685 | + 'child_menu' => [ |
|
686 | + 'display' => 'dropdown', |
|
687 | + 'class' => 'elgg-topbar-child-menu', |
|
688 | + 'data-position' => json_encode([ |
|
689 | + 'at' => 'right+10px bottom', |
|
690 | + 'my' => 'right top', |
|
691 | + 'collision' => 'fit fit', |
|
692 | + ]), |
|
693 | + ], |
|
694 | + ]); |
|
695 | + |
|
696 | + $return[] = \ElggMenuItem::factory([ |
|
697 | + 'name' => 'usersettings', |
|
698 | + 'parent_name' => 'account', |
|
699 | + 'href' => "settings/user/{$viewer->username}", |
|
700 | + 'text' => elgg_echo('settings'), |
|
701 | + 'icon' => 'cogs', |
|
702 | + 'priority' => 300, |
|
703 | + 'section' => 'alt', |
|
704 | + ]); |
|
705 | + |
|
706 | + if ($viewer->isAdmin()) { |
|
707 | + $return[] = \ElggMenuItem::factory([ |
|
708 | + 'name' => 'administration', |
|
709 | + 'parent_name' => 'account', |
|
710 | + 'href' => 'admin', |
|
711 | + 'text' => elgg_echo('admin'), |
|
712 | + 'icon' => 'tasks', |
|
713 | + 'priority' => 800, |
|
714 | + 'section' => 'alt', |
|
715 | + ]); |
|
716 | + } |
|
717 | + |
|
718 | + $return[] = \ElggMenuItem::factory([ |
|
719 | + 'name' => 'logout', |
|
720 | + 'parent_name' => 'account', |
|
721 | + 'href' => 'action/logout', |
|
722 | + 'text' => elgg_echo('logout'), |
|
723 | + 'icon' => 'sign-out', |
|
724 | + 'is_action' => true, |
|
725 | + 'priority' => 900, |
|
726 | + 'section' => 'alt', |
|
727 | + ]); |
|
728 | + |
|
729 | + return $return; |
|
730 | 730 | } |
731 | 731 | |
732 | 732 | /** |
@@ -740,13 +740,13 @@ discard block |
||
740 | 740 | */ |
741 | 741 | function _elgg_user_set_icon_file($hook, $type, $icon, $params) { |
742 | 742 | |
743 | - $entity = elgg_extract('entity', $params); |
|
744 | - $size = elgg_extract('size', $params, 'medium'); |
|
743 | + $entity = elgg_extract('entity', $params); |
|
744 | + $size = elgg_extract('size', $params, 'medium'); |
|
745 | 745 | |
746 | - $icon->owner_guid = $entity->guid; |
|
747 | - $icon->setFilename("profile/{$entity->guid}{$size}.jpg"); |
|
746 | + $icon->owner_guid = $entity->guid; |
|
747 | + $icon->setFilename("profile/{$entity->guid}{$size}.jpg"); |
|
748 | 748 | |
749 | - return $icon; |
|
749 | + return $icon; |
|
750 | 750 | } |
751 | 751 | |
752 | 752 | /** |
@@ -761,27 +761,27 @@ discard block |
||
761 | 761 | */ |
762 | 762 | function _elgg_user_get_subscriber_unban_action($hook, $type, $return_value, $params) { |
763 | 763 | |
764 | - if (!_elgg_config()->security_notify_user_ban) { |
|
765 | - return; |
|
766 | - } |
|
764 | + if (!_elgg_config()->security_notify_user_ban) { |
|
765 | + return; |
|
766 | + } |
|
767 | 767 | |
768 | - $event = elgg_extract('event', $params); |
|
769 | - if (!($event instanceof \Elgg\Notifications\Event)) { |
|
770 | - return; |
|
771 | - } |
|
768 | + $event = elgg_extract('event', $params); |
|
769 | + if (!($event instanceof \Elgg\Notifications\Event)) { |
|
770 | + return; |
|
771 | + } |
|
772 | 772 | |
773 | - if ($event->getAction() !== 'unban') { |
|
774 | - return; |
|
775 | - } |
|
773 | + if ($event->getAction() !== 'unban') { |
|
774 | + return; |
|
775 | + } |
|
776 | 776 | |
777 | - $user = $event->getObject(); |
|
778 | - if (!($user instanceof \ElggUser)) { |
|
779 | - return; |
|
780 | - } |
|
777 | + $user = $event->getObject(); |
|
778 | + if (!($user instanceof \ElggUser)) { |
|
779 | + return; |
|
780 | + } |
|
781 | 781 | |
782 | - $return_value[$user->getGUID()] = ['email']; |
|
782 | + $return_value[$user->getGUID()] = ['email']; |
|
783 | 783 | |
784 | - return $return_value; |
|
784 | + return $return_value; |
|
785 | 785 | } |
786 | 786 | |
787 | 787 | /** |
@@ -797,30 +797,30 @@ discard block |
||
797 | 797 | */ |
798 | 798 | function _elgg_user_ban_notification($event, $type, $user) { |
799 | 799 | |
800 | - if (!_elgg_config()->security_notify_user_ban) { |
|
801 | - return; |
|
802 | - } |
|
800 | + if (!_elgg_config()->security_notify_user_ban) { |
|
801 | + return; |
|
802 | + } |
|
803 | 803 | |
804 | - if (!($user instanceof \ElggUser)) { |
|
805 | - return; |
|
806 | - } |
|
804 | + if (!($user instanceof \ElggUser)) { |
|
805 | + return; |
|
806 | + } |
|
807 | 807 | |
808 | - $site = elgg_get_site_entity(); |
|
809 | - $language = $user->getLanguage(); |
|
808 | + $site = elgg_get_site_entity(); |
|
809 | + $language = $user->getLanguage(); |
|
810 | 810 | |
811 | - $subject = elgg_echo('user:notification:ban:subject', [$site->name], $language); |
|
812 | - $body = elgg_echo('user:notification:ban:body', [ |
|
813 | - $user->name, |
|
814 | - $site->name, |
|
815 | - $site->getURL(), |
|
816 | - ], $language); |
|
811 | + $subject = elgg_echo('user:notification:ban:subject', [$site->name], $language); |
|
812 | + $body = elgg_echo('user:notification:ban:body', [ |
|
813 | + $user->name, |
|
814 | + $site->name, |
|
815 | + $site->getURL(), |
|
816 | + ], $language); |
|
817 | 817 | |
818 | - $params = [ |
|
819 | - 'action' => 'ban', |
|
820 | - 'object' => $user, |
|
821 | - ]; |
|
818 | + $params = [ |
|
819 | + 'action' => 'ban', |
|
820 | + 'object' => $user, |
|
821 | + ]; |
|
822 | 822 | |
823 | - notify_user($user->getGUID(), $site->getGUID(), $subject, $body, $params, ['email']); |
|
823 | + notify_user($user->getGUID(), $site->getGUID(), $subject, $body, $params, ['email']); |
|
824 | 824 | } |
825 | 825 | |
826 | 826 | /** |
@@ -835,34 +835,34 @@ discard block |
||
835 | 835 | */ |
836 | 836 | function _elgg_user_prepare_unban_notification($hook, $type, $return_value, $params) { |
837 | 837 | |
838 | - if (!($return_value instanceof \Elgg\Notifications\Notification)) { |
|
839 | - return; |
|
840 | - } |
|
838 | + if (!($return_value instanceof \Elgg\Notifications\Notification)) { |
|
839 | + return; |
|
840 | + } |
|
841 | 841 | |
842 | - $recipient = elgg_extract('recipient', $params); |
|
843 | - $object = elgg_extract('object', $params); |
|
844 | - $language = elgg_extract('language', $params); |
|
842 | + $recipient = elgg_extract('recipient', $params); |
|
843 | + $object = elgg_extract('object', $params); |
|
844 | + $language = elgg_extract('language', $params); |
|
845 | 845 | |
846 | - if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser)) { |
|
847 | - return; |
|
848 | - } |
|
846 | + if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser)) { |
|
847 | + return; |
|
848 | + } |
|
849 | 849 | |
850 | - if ($recipient->getGUID() !== $object->getGUID()) { |
|
851 | - return; |
|
852 | - } |
|
850 | + if ($recipient->getGUID() !== $object->getGUID()) { |
|
851 | + return; |
|
852 | + } |
|
853 | 853 | |
854 | - $site = elgg_get_site_entity(); |
|
854 | + $site = elgg_get_site_entity(); |
|
855 | 855 | |
856 | - $return_value->subject = elgg_echo('user:notification:unban:subject', [$site->name], $language); |
|
857 | - $return_value->body = elgg_echo('user:notification:unban:body', [ |
|
858 | - $recipient->name, |
|
859 | - $site->name, |
|
860 | - $site->getURL(), |
|
861 | - ], $language); |
|
856 | + $return_value->subject = elgg_echo('user:notification:unban:subject', [$site->name], $language); |
|
857 | + $return_value->body = elgg_echo('user:notification:unban:body', [ |
|
858 | + $recipient->name, |
|
859 | + $site->name, |
|
860 | + $site->getURL(), |
|
861 | + ], $language); |
|
862 | 862 | |
863 | - $return_value->url = $recipient->getURL(); |
|
863 | + $return_value->url = $recipient->getURL(); |
|
864 | 864 | |
865 | - return $return_value; |
|
865 | + return $return_value; |
|
866 | 866 | } |
867 | 867 | |
868 | 868 | /** |
@@ -873,39 +873,39 @@ discard block |
||
873 | 873 | */ |
874 | 874 | function users_init() { |
875 | 875 | |
876 | - elgg_register_page_handler('register', 'elgg_user_account_page_handler'); |
|
877 | - elgg_register_page_handler('forgotpassword', 'elgg_user_account_page_handler'); |
|
878 | - elgg_register_page_handler('changepassword', 'elgg_user_account_page_handler'); |
|
879 | - elgg_register_page_handler('login', 'elgg_user_account_page_handler'); |
|
880 | - elgg_register_page_handler('avatar', 'elgg_avatar_page_handler'); |
|
881 | - elgg_register_page_handler('user', '_elgg_user_page_handler'); |
|
876 | + elgg_register_page_handler('register', 'elgg_user_account_page_handler'); |
|
877 | + elgg_register_page_handler('forgotpassword', 'elgg_user_account_page_handler'); |
|
878 | + elgg_register_page_handler('changepassword', 'elgg_user_account_page_handler'); |
|
879 | + elgg_register_page_handler('login', 'elgg_user_account_page_handler'); |
|
880 | + elgg_register_page_handler('avatar', 'elgg_avatar_page_handler'); |
|
881 | + elgg_register_page_handler('user', '_elgg_user_page_handler'); |
|
882 | 882 | |
883 | - elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'elgg_user_hover_menu'); |
|
884 | - elgg_register_plugin_hook_handler('register', 'menu:page', '_elgg_user_page_menu'); |
|
885 | - elgg_register_plugin_hook_handler('register', 'menu:topbar', '_elgg_user_topbar_menu'); |
|
883 | + elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'elgg_user_hover_menu'); |
|
884 | + elgg_register_plugin_hook_handler('register', 'menu:page', '_elgg_user_page_menu'); |
|
885 | + elgg_register_plugin_hook_handler('register', 'menu:topbar', '_elgg_user_topbar_menu'); |
|
886 | 886 | |
887 | - elgg_register_action('login', '', 'public'); |
|
888 | - elgg_register_action('logout'); |
|
889 | - elgg_register_action('register', '', 'public'); |
|
890 | - elgg_register_action('useradd', '', 'admin'); |
|
891 | - elgg_register_action('avatar/upload'); |
|
892 | - elgg_register_action('avatar/crop'); |
|
893 | - elgg_register_action('avatar/remove'); |
|
887 | + elgg_register_action('login', '', 'public'); |
|
888 | + elgg_register_action('logout'); |
|
889 | + elgg_register_action('register', '', 'public'); |
|
890 | + elgg_register_action('useradd', '', 'admin'); |
|
891 | + elgg_register_action('avatar/upload'); |
|
892 | + elgg_register_action('avatar/crop'); |
|
893 | + elgg_register_action('avatar/remove'); |
|
894 | 894 | |
895 | - elgg_register_plugin_hook_handler('entity:icon:url', 'user', 'user_avatar_hook'); |
|
895 | + elgg_register_plugin_hook_handler('entity:icon:url', 'user', 'user_avatar_hook'); |
|
896 | 896 | |
897 | - elgg_register_action('user/changepassword', '', 'public'); |
|
898 | - elgg_register_action('user/requestnewpassword', '', 'public'); |
|
897 | + elgg_register_action('user/changepassword', '', 'public'); |
|
898 | + elgg_register_action('user/requestnewpassword', '', 'public'); |
|
899 | 899 | |
900 | - // Register the user type |
|
901 | - elgg_register_entity_type('user', ''); |
|
900 | + // Register the user type |
|
901 | + elgg_register_entity_type('user', ''); |
|
902 | 902 | |
903 | - elgg_register_plugin_hook_handler('entity:icon:file', 'user', '_elgg_user_set_icon_file'); |
|
903 | + elgg_register_plugin_hook_handler('entity:icon:file', 'user', '_elgg_user_set_icon_file'); |
|
904 | 904 | |
905 | - elgg_register_notification_event('user', '', ['unban']); |
|
906 | - elgg_register_plugin_hook_handler('get', 'subscriptions', '_elgg_user_get_subscriber_ban_action'); |
|
907 | - elgg_register_event_handler('ban', 'user', '_elgg_user_ban_notification'); |
|
908 | - elgg_register_plugin_hook_handler('prepare', 'notification:unban:user:', '_elgg_user_prepare_unban_notification'); |
|
905 | + elgg_register_notification_event('user', '', ['unban']); |
|
906 | + elgg_register_plugin_hook_handler('get', 'subscriptions', '_elgg_user_get_subscriber_ban_action'); |
|
907 | + elgg_register_event_handler('ban', 'user', '_elgg_user_ban_notification'); |
|
908 | + elgg_register_plugin_hook_handler('prepare', 'notification:unban:user:', '_elgg_user_prepare_unban_notification'); |
|
909 | 909 | |
910 | 910 | } |
911 | 911 | |
@@ -921,14 +921,14 @@ discard block |
||
921 | 921 | * @access private |
922 | 922 | */ |
923 | 923 | function users_test($hook, $type, $value, $params) { |
924 | - $value[] = Paths::elgg() . "engine/tests/ElggUserTest.php"; |
|
925 | - return $value; |
|
924 | + $value[] = Paths::elgg() . "engine/tests/ElggUserTest.php"; |
|
925 | + return $value; |
|
926 | 926 | } |
927 | 927 | |
928 | 928 | /** |
929 | 929 | * @see \Elgg\Application::loadCore Do not do work here. Just register for events. |
930 | 930 | */ |
931 | 931 | return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
932 | - $events->registerHandler('init', 'system', 'users_init', 0); |
|
933 | - $hooks->registerHandler('unit_test', 'system', 'users_test'); |
|
932 | + $events->registerHandler('init', 'system', 'users_init', 0); |
|
933 | + $hooks->registerHandler('unit_test', 'system', 'users_test'); |
|
934 | 934 | }; |
@@ -204,13 +204,13 @@ discard block |
||
204 | 204 | } |
205 | 205 | |
206 | 206 | // Blacklist for bad characters (partially nicked from mediawiki) |
207 | - $blacklist = '/[' . |
|
208 | - '\x{0080}-\x{009f}' . // iso-8859-1 control chars |
|
209 | - '\x{00a0}' . // non-breaking space |
|
210 | - '\x{2000}-\x{200f}' . // various whitespace |
|
211 | - '\x{2028}-\x{202f}' . // breaks and control chars |
|
212 | - '\x{3000}' . // ideographic space |
|
213 | - '\x{e000}-\x{f8ff}' . // private use |
|
207 | + $blacklist = '/['. |
|
208 | + '\x{0080}-\x{009f}'.// iso-8859-1 control chars |
|
209 | + '\x{00a0}'.// non-breaking space |
|
210 | + '\x{2000}-\x{200f}'.// various whitespace |
|
211 | + '\x{2028}-\x{202f}'.// breaks and control chars |
|
212 | + '\x{3000}'.// ideographic space |
|
213 | + '\x{e000}-\x{f8ff}'.// private use |
|
214 | 214 | ']/u'; |
215 | 215 | |
216 | 216 | if (preg_match($blacklist, $username)) { |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | */ |
393 | 393 | function elgg_get_registration_url(array $query = [], $fragment = '') { |
394 | 394 | $url = elgg_normalize_url('register'); |
395 | - $url = elgg_http_add_url_query_elements($url, $query) . $fragment; |
|
395 | + $url = elgg_http_add_url_query_elements($url, $query).$fragment; |
|
396 | 396 | return elgg_trigger_plugin_hook('registration_url', 'site', $query, $url); |
397 | 397 | } |
398 | 398 | |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | */ |
408 | 408 | function elgg_get_login_url(array $query = [], $fragment = '') { |
409 | 409 | $url = elgg_normalize_url('login'); |
410 | - $url = elgg_http_add_url_query_elements($url, $query) . $fragment; |
|
410 | + $url = elgg_http_add_url_query_elements($url, $query).$fragment; |
|
411 | 411 | return elgg_trigger_plugin_hook('login_url', 'site', $query, $url); |
412 | 412 | } |
413 | 413 | |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | 'text' => elgg_echo('avatar:edit'), |
498 | 498 | 'icon' => 'image', |
499 | 499 | 'href' => "avatar/edit/$user->username", |
500 | - 'section' => (elgg_get_logged_in_user_guid() == $user->guid)? 'action' : 'admin', |
|
500 | + 'section' => (elgg_get_logged_in_user_guid() == $user->guid) ? 'action' : 'admin', |
|
501 | 501 | ]); |
502 | 502 | } |
503 | 503 | |
@@ -678,7 +678,7 @@ discard block |
||
678 | 678 | |
679 | 679 | $return[] = \ElggMenuItem::factory([ |
680 | 680 | 'name' => 'account', |
681 | - 'text' => elgg_echo('account') . $toggle, |
|
681 | + 'text' => elgg_echo('account').$toggle, |
|
682 | 682 | 'href' => $href, |
683 | 683 | 'priority' => 800, |
684 | 684 | 'section' => 'alt', |
@@ -921,7 +921,7 @@ discard block |
||
921 | 921 | * @access private |
922 | 922 | */ |
923 | 923 | function users_test($hook, $type, $value, $params) { |
924 | - $value[] = Paths::elgg() . "engine/tests/ElggUserTest.php"; |
|
924 | + $value[] = Paths::elgg()."engine/tests/ElggUserTest.php"; |
|
925 | 925 | return $value; |
926 | 926 | } |
927 | 927 |