Rev 1449 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1449 | Rev 1463 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * OIDplus 2.0 |
4 | * OIDplus 2.0 |
5 | * Copyright 2022 - 2023 Daniel Marschall, ViaThinkSoft / Till Wehowski, Frdlweb |
5 | * Copyright 2022 - 2024 Daniel Marschall, ViaThinkSoft / Till Wehowski, Frdlweb |
6 | * |
6 | * |
7 | * Licensed under the MIT License. |
7 | * Licensed under the MIT License. |
8 | */ |
8 | */ |
9 | 9 | ||
10 | namespace Frdlweb\OIDplus; |
10 | namespace Frdlweb\OIDplus; |
11 | 11 | ||
- | 12 | use ViaThinkSoft\OIDplus\INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3; |
|
12 | use ViaThinkSoft\OIDplus\INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_4; |
13 | use ViaThinkSoft\OIDplus\INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_4; |
13 | use ViaThinkSoft\OIDplus\INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7; |
14 | use ViaThinkSoft\OIDplus\INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7; |
- | 15 | use ViaThinkSoft\OIDplus\INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8; |
|
14 | use ViaThinkSoft\OIDplus\OIDplus; |
16 | use ViaThinkSoft\OIDplus\OIDplus; |
15 | use ViaThinkSoft\OIDplus\OIDplusObject; |
17 | use ViaThinkSoft\OIDplus\OIDplusObject; |
16 | use ViaThinkSoft\OIDplus\OIDplusPagePluginPublic; |
18 | use ViaThinkSoft\OIDplus\OIDplusPagePluginPublic; |
- | 19 | use ViaThinkSoft\OIDplus\OIDplusNotification; |
|
17 | 20 | ||
18 | // phpcs:disable PSR1.Files.SideEffects |
21 | // phpcs:disable PSR1.Files.SideEffects |
19 | \defined('INSIDE_OIDPLUS') or die; |
22 | \defined('INSIDE_OIDPLUS') or die; |
20 | // phpcs:enable PSR1.Files.SideEffects |
23 | // phpcs:enable PSR1.Files.SideEffects |
21 | 24 | ||
22 | class OIDplusPagePublicAltIds extends OIDplusPagePluginPublic |
25 | class OIDplusPagePublicAltIds extends OIDplusPagePluginPublic |
23 | implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_4, /* whois*Attributes */ |
26 | implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_4, /* whois*Attributes */ |
24 | INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7 /* getAlternativesForQuery */ |
27 | INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7, /* getAlternativesForQuery */ |
- | 28 | INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8, /* getNotifications */ |
|
- | 29 | INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3 /* *objects* */ |
|
25 | { |
30 | { |
26 | 31 | ||
27 | /** |
32 | /** |
28 | * @param string $actionID |
- | |
29 | * @param array $params |
- | |
30 | * @return array |
33 | * @var bool |
31 | * @throws \ViaThinkSoft\OIDplus\OIDplusException |
- | |
32 | */ |
34 | */ |
33 | public function action(string $actionID, array $params): array { |
- | |
34 | return parent::action($actionID, $params); |
35 | private $db_table_exists; |
35 | } |
36 | |
36 | 37 | ||
37 | /** |
38 | /** |
- | 39 | * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3 |
|
38 | * @param string $id |
40 | * @param string $id |
39 | * @param array $out |
- | |
40 | * @param bool $handled |
- | |
41 | * @return void |
41 | * @return void |
42 | */ |
42 | */ |
43 | public function gui(string $id, array &$out, bool &$handled) { |
43 | public function beforeObjectDelete(string $id){ |
44 | 44 | ||
45 | } |
45 | } |
46 | 46 | ||
47 | /** |
47 | /** |
- | 48 | * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3 |
|
48 | * @param array $out |
49 | * @param string $id |
49 | * @return void |
50 | * @return void |
50 | */ |
51 | */ |
51 | public function publicSitemap(array &$out) { |
52 | public function afterObjectDelete(string $id){ |
- | 53 | if (!$this->db_table_exists) return; |
|
- | 54 | OIDplus::db()->query("DELETE FROM ###altids WHERE origin = ?", [$id]); |
|
- | 55 | } |
|
- | 56 | ||
- | 57 | /** |
|
- | 58 | * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3 |
|
- | 59 | * @param string $id |
|
- | 60 | * @param array $params |
|
- | 61 | * @return void |
|
- | 62 | */ |
|
- | 63 | public function beforeObjectUpdateSuperior(string $id, array &$params){ |
|
52 | 64 | ||
53 | } |
65 | } |
54 | 66 | ||
55 | /** |
67 | /** |
56 | * @param array $json |
- | |
57 | * @param string|null $ra_email |
68 | * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3 |
58 | * @param bool $nonjs |
69 | * @param string $id |
59 | * @param string $req_goto |
70 | * @param array $params |
60 | * @return bool |
71 | * @return void |
61 | */ |
72 | */ |
62 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
73 | public function afterObjectUpdateSuperior(string $id, array &$params){ |
63 | return false; |
74 | $this->saveAltIdsForQuery($id); |
64 | } |
75 | } |
65 | 76 | ||
66 | /** |
77 | /** |
- | 78 | * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3 |
|
67 | * @return string|null |
79 | * @param string $id |
68 | * @throws \ViaThinkSoft\OIDplus\OIDplusException |
80 | * @param array $params |
- | 81 | * @return void |
|
69 | */ |
82 | */ |
70 | private function cache_id() { |
- | |
71 | static $cache_id = null; |
- | |
72 | if (!is_null($cache_id)) return $cache_id; |
- | |
73 | $cache_id = 'Create='.OIDplus::db()->getScalar("select max(created) as ts from ###objects where created is not null;"); |
- | |
74 | $cache_id .= '/Update='.OIDplus::db()->getScalar("select max(updated) as ts from ###objects where updated is not null;"); |
- | |
75 | $cache_id .= '/Count='.OIDplus::db()->getScalar("select count(id) as cnt from ###objects;"); |
- | |
76 | $plugin_versions = array(); |
- | |
77 | foreach (OIDplus::getObjectTypePluginsEnabled() as $otp) { |
83 | public function beforeObjectUpdateSelf(string $id, array &$params){ |
78 | $plugin_versions[] = '/'.$otp->getManifest()->getOid().'='.$otp->getManifest()->getVersion(); |
- | |
79 | } |
84 | |
80 | sort($plugin_versions); |
- | |
81 | $cache_id .= implode('',$plugin_versions); |
- | |
82 | return $cache_id; |
- | |
83 | } |
85 | } |
84 | 86 | ||
85 | /** |
87 | /** |
- | 88 | * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3 |
|
- | 89 | * @param string $id |
|
86 | * @param bool $noCache |
90 | * @param array $params |
87 | * @return array[]|mixed|null |
91 | * @return void |
- | 92 | */ |
|
- | 93 | public function afterObjectUpdateSelf(string $id, array &$params){ |
|
- | 94 | $this->saveAltIdsForQuery($id); |
|
- | 95 | } |
|
- | 96 | ||
- | 97 | /** |
|
88 | * @throws \ViaThinkSoft\OIDplus\OIDplusException |
98 | * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3 |
- | 99 | * @param string $id |
|
- | 100 | * @param array $params |
|
- | 101 | * @return void |
|
89 | */ |
102 | */ |
90 | public function readAll(bool $noCache = false) { |
103 | public function beforeObjectInsert(string $id, array &$params){ |
91 | static $local_cache = null; |
- | |
92 | 104 | ||
93 | $cache_file = OIDplus::localpath().'/userdata/cache/frdl_alt_id.ser'; |
- | |
94 | if ($noCache === false) { |
105 | } |
95 | // Local cache (to save time for multiple calls during the same HTTP request) |
- | |
96 | if (!is_null($local_cache)) return $local_cache; |
- | |
97 | 106 | ||
- | 107 | /** |
|
98 | // File cache (to save time between HTTP requests) |
108 | * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3 |
99 | if (file_exists($cache_file)) { |
109 | * @param string $id |
100 | $cache_data = unserialize(file_get_contents($cache_file)); |
110 | * @param array $params |
101 | $cache_id = $cache_data[0]; |
111 | * @return void |
- | 112 | */ |
|
102 | if ($cache_id == $this->cache_id()) { |
113 | public function afterObjectInsert(string $id, array &$params){ |
103 | return $cache_data[1]; |
114 | $this->saveAltIdsForQuery($id); |
104 | } |
115 | } |
- | 116 | ||
- | 117 | ||
- | 118 | /** |
|
- | 119 | * Adds the required database table if DBMS is known |
|
- | 120 | * @param bool $html |
|
- | 121 | * @return void |
|
- | 122 | * @throws \ViaThinkSoft\OIDplus\OIDplusConfigInitializationException |
|
- | 123 | * @throws \ViaThinkSoft\OIDplus\OIDplusException |
|
- | 124 | */ |
|
- | 125 | public function init(bool $html=true) { |
|
- | 126 | if (!OIDplus::db()->tableExists("###altids")) { |
|
- | 127 | if (OIDplus::db()->getSlang()->id() == 'mysql') { |
|
- | 128 | OIDplus::db()->query("CREATE TABLE ###altids ( `origin` varchar(255) NOT NULL, `alternative` varchar(255) NOT NULL, UNIQUE KEY (`origin`, `alternative`) )"); |
|
- | 129 | $this->db_table_exists = true; |
|
- | 130 | } else if (OIDplus::db()->getSlang()->id() == 'mssql') { |
|
- | 131 | // We use nvarchar(225) instead of varchar(255), see https://github.com/frdl/oidplus-plugin-alternate-id-tracking/issues/18 |
|
- | 132 | // Unfortunately, we cannot use nvarchar(255), because we need two of them for the primary key, and an index must not be greater than 900 bytes in SQL Server. |
|
- | 133 | // Therefore we can only use 225 Unicode characters instead of 255. |
|
- | 134 | // It is very unlikely that someone has such giant identifiers. But if they do, then saveAltIdsForQuery() will reject the INSERT commands to avoid that an SQL Exception is thrown. |
|
- | 135 | OIDplus::db()->query("CREATE TABLE ###altids ( [origin] nvarchar(225) NOT NULL, [alternative] nvarchar(225) NOT NULL, CONSTRAINT [PK_###altids] PRIMARY KEY CLUSTERED( [origin] ASC, [alternative] ASC ) )"); |
|
- | 136 | $this->db_table_exists = true; |
|
- | 137 | } else if (OIDplus::db()->getSlang()->id() == 'oracle') { |
|
- | 138 | // TODO: Implement Table Creation for this DBMS (see CREATE TABLE syntax at plugins/viathinksoft/sqlSlang/oracle/sql/*.sql) |
|
- | 139 | $this->db_table_exists = false; |
|
- | 140 | } else if (OIDplus::db()->getSlang()->id() == 'pgsql') { |
|
- | 141 | // TODO: Implement Table Creation for this DBMS (see CREATE TABLE syntax at plugins/viathinksoft/sqlSlang/pgsql/sql/*.sql) |
|
- | 142 | $this->db_table_exists = false; |
|
- | 143 | } else if (OIDplus::db()->getSlang()->id() == 'access') { |
|
- | 144 | // TODO: Implement Table Creation for this DBMS (see CREATE TABLE syntax at plugins/viathinksoft/sqlSlang/access/sql/*.sql) |
|
- | 145 | $this->db_table_exists = false; |
|
- | 146 | } else if (OIDplus::db()->getSlang()->id() == 'sqlite') { |
|
- | 147 | // TODO: Implement Table Creation for this DBMS (see CREATE TABLE syntax at plugins/viathinksoft/sqlSlang/sqlite/sql/*.sql) |
|
- | 148 | $this->db_table_exists = false; |
|
- | 149 | } else if (OIDplus::db()->getSlang()->id() == 'firebird') { |
|
- | 150 | // TODO: Implement Table Creation for this DBMS (see CREATE TABLE syntax at plugins/viathinksoft/sqlSlang/firebird/sql/*.sql) |
|
- | 151 | $this->db_table_exists = false; |
|
- | 152 | } else { |
|
- | 153 | // DBMS not supported |
|
- | 154 | $this->db_table_exists = false; |
|
- | 155 | } |
|
- | 156 | } else { |
|
- | 157 | $this->db_table_exists = true; |
|
- | 158 | } |
|
- | 159 | ||
- | 160 | // Whenever a user visits a page, we need to update our cache, so that reverse-lookups are possible later |
|
- | 161 | // TODO! Dirty hack. We need a cleaner solution... |
|
- | 162 | if (isset($_REQUEST['goto'])) $this->saveAltIdsForQuery($_REQUEST['goto']); // => solve using implementing gui()? |
|
- | 163 | if (isset($_REQUEST['query'])) $this->saveAltIdsForQuery($_REQUEST['query']); // for webwhois.php?query=... and rdap.php?query=... |
|
- | 164 | if (isset($_REQUEST['id'])) $this->saveAltIdsForQuery($_REQUEST['id']); // => solve using implementing action()? |
|
- | 165 | } |
|
- | 166 | ||
- | 167 | // TODO: call this via cronjob https://github.com/frdl/oidplus-plugin-alternate-id-tracking/issues/20 |
|
- | 168 | public function renewAll() { |
|
- | 169 | if (!$this->db_table_exists) return; |
|
- | 170 | ||
- | 171 | OIDplus::db()->query("DELETE FROM ###altids"); |
|
- | 172 | $resQ = OIDplus::db()->query("SELECT * FROM ###objects"); |
|
- | 173 | while ($row = $resQ->fetch_array()) { |
|
- | 174 | $this->saveAltIdsForQuery($row['id']); |
|
105 | } |
175 | } |
106 | } |
176 | } |
107 | 177 | ||
108 | $alt_ids = array(); |
178 | protected function saveAltIdsForQuery(string $id){ |
109 | $rev_lookup = array(); |
179 | if (!$this->db_table_exists) return; |
110 | 180 | ||
111 | $res = OIDplus::db()->query("select id from ###objects ". |
- | |
112 | "where parent <> 'oid:1.3.6.1.4.1.37476.1.2.3.1'"); // TODO FIXME! readAll() is TOOOOO slow if a system has more than 50.000 OIDs!!! DEADLOCK!!! |
- | |
113 | while ($row = $res->fetch_array()) { |
- | |
114 | $obj = OIDplusObject::parse($row['id']); |
181 | $obj = OIDplusObject::parse($id); |
115 | if (!$obj) continue; // e.g. if plugin is disabled |
182 | if (!$obj) return; // e.g. if plugin is disabled |
116 | $ary = $obj->getAltIds(); |
183 | $ary = $obj->getAltIds(); |
117 | foreach ($ary as $a) { |
- | |
118 | $origin = $obj->nodeId(true); |
184 | $origin = $obj->nodeId(true); |
119 | $alternative = $a->getNamespace() . ':' . $a->getId(); |
- | |
120 | 185 | ||
121 | if (!isset($alt_ids[$origin])) $alt_ids[$origin] = array(); |
186 | OIDplus::db()->query("DELETE FROM ###altids WHERE origin = ?", [$id]); |
122 | $alt_ids[$origin][] = $alternative; |
- | |
123 | 187 | ||
- | 188 | // Why prefiltering? Consider the following testcase: |
|
- | 189 | // "oid:1.3.6.1.4.1.37553.8.8.2" defines alt ID "mac:63-CF-E4-AE-C5-66" which is NOT canonized (otherwise it would not look good)! |
|
- | 190 | // You must be able to enter "mac:63-CF-E4-AE-C5-66" in the search box, which gets canonized |
|
- | 191 | // to mac:63CFE4AEC566 and must be resolved to "oid:1.3.6.1.4.1.37553.8.8.2" by this plugin. |
|
- | 192 | // Therefore we use self::special_in_array(). |
|
- | 193 | // However, it is mandatory, that previously saveAltIdsForQuery("oid:1.3.6.1.4.1.37553.8.8.2") was called once! |
|
- | 194 | // Please also note that the "weid:" to "oid:" converting is handled by prefilterQuery(), but only if the OID plugin is installed. |
|
124 | if (!isset($rev_lookup[$alternative])) $rev_lookup[$alternative] = array(); |
195 | $origin_prefiltered = OIDplus::prefilterQuery($origin, false); |
125 | $rev_lookup[$alternative][] = $origin; |
196 | if($origin_prefiltered !== $origin){ |
- | 197 | $ok = true; |
|
- | 198 | if (OIDplus::db()->getSlang()->id() == 'mssql') { |
|
- | 199 | // Explanation: See comment in the init() method. |
|
- | 200 | if ((strlen($origin) > 225) || (strlen($origin_prefiltered) > 225)) $ok = false; |
|
- | 201 | } |
|
- | 202 | if ($ok) { |
|
- | 203 | try { |
|
- | 204 | OIDplus::db()->query("INSERT INTO ###altids (origin, alternative) VALUES (?,?);", [$origin, $origin_prefiltered]); |
|
- | 205 | } catch (\Exception $e) { |
|
- | 206 | // There could be a Primary Key collission if this method is called simultaneously at the same moment |
|
- | 207 | // Ignore it. The last caller will eventually execute all INSERTs after its call to DELETE. |
|
- | 208 | } |
|
126 | } |
209 | } |
127 | } |
210 | } |
128 | 211 | ||
129 | $data = array($alt_ids, $rev_lookup); |
212 | foreach ($ary as $a) { |
130 | - | ||
131 | // File cache (to save time between HTTP requests) |
213 | $alternative = $a->getNamespace() . ':' . $a->getId(); |
- | 214 | $ok = true; |
|
132 | $cache_data = array($this->cache_id(), $data); |
215 | if (OIDplus::db()->getSlang()->id() == 'mssql') { |
133 | @file_put_contents($cache_file, serialize($cache_data)); |
216 | // Explanation: See comment in the init() method. |
- | 217 | if ((strlen($origin) > 225) || (strlen($alternative) > 225)) $ok = false; |
|
134 | 218 | } |
|
- | 219 | if ($ok) { |
|
- | 220 | try { |
|
135 | // Local cache (to save time for multiple calls during the same HTTP request) |
221 | OIDplus::db()->query("INSERT INTO ###altids (origin, alternative) VALUES (?,?);", [$origin, $alternative]); |
136 | $local_cache = $data; |
222 | } catch (\Exception $e) { |
137 | - | ||
- | 223 | // There could be a Primary Key collission if this method is called simultaneously at the same moment |
|
- | 224 | // Ignore it. The last caller will eventually execute all INSERTs after its call to DELETE. |
|
138 | return $data; |
225 | } |
139 | } |
226 | } |
140 | 227 | ||
141 | /** |
- | |
142 | * Acts like in_array(), but allows includes prefilterQuery, e.g. `mac:AA-BB-CC-DD-EE-FF` can be found in an array containing `mac:AABBCCDDEEFF`. |
228 | $alternative_prefiltered = OIDplus::prefilterQuery($alternative, false); |
143 | * @param string $needle |
229 | if($alternative_prefiltered !== $alternative){ |
144 | * @param array $haystack |
230 | $ok = true; |
145 | * @return bool |
231 | if (OIDplus::db()->getSlang()->id() == 'mssql') { |
146 | */ |
- | |
147 | private static function special_in_array(string $needle, array $haystack) { |
232 | // Explanation: See comment in the init() method. |
148 | $needle_prefiltered = OIDplus::prefilterQuery($needle,false); |
233 | if ((strlen($origin) > 225) || (strlen($alternative_prefiltered) > 225)) $ok = false; |
- | 234 | } |
|
149 | foreach ($haystack as $straw) { |
235 | if ($ok) { |
- | 236 | try { |
|
150 | $straw_prefiltered = OIDplus::prefilterQuery($straw, false); |
237 | OIDplus::db()->query("INSERT INTO ###altids (origin, alternative) VALUES (?,?);", [$origin, $alternative_prefiltered]); |
151 | if ($needle == $straw) return true; |
238 | } catch (\Exception $e) { |
152 | else if ($needle == $straw_prefiltered) return true; |
239 | // There could be a Primary Key collission if this method is called simultaneously at the same moment |
153 | else if ($needle_prefiltered == $straw) return true; |
- | |
154 | else if ($needle_prefiltered == $straw_prefiltered) return true; |
240 | // Ignore it. The last caller will eventually execute all INSERTs after its call to DELETE. |
- | 241 | } |
|
- | 242 | } |
|
- | 243 | } |
|
155 | } |
244 | } |
156 | return false; |
- | |
157 | } |
245 | } |
158 | 246 | ||
159 | /** |
247 | /** |
- | 248 | * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7 |
|
160 | * @param string $id |
249 | * @param string $id |
161 | * @return string[] |
250 | * @return array|string[] |
- | 251 | * @throws \ReflectionException |
|
- | 252 | * @throws \ViaThinkSoft\OIDplus\OIDplusConfigInitializationException |
|
162 | * @throws \ViaThinkSoft\OIDplus\OIDplusException |
253 | * @throws \ViaThinkSoft\OIDplus\OIDplusException |
163 | */ |
254 | */ |
164 | public function getAlternativesForQuery(string $id/* INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7 signature takes just 1 param!? , $noCache = false*/): array { |
255 | public function getAlternativesForQuery(string $id): array { |
- | 256 | if (!$this->db_table_exists) return []; |
|
165 | 257 | ||
166 | static $caches = array(); |
- | |
167 | - | ||
168 | if(/*$noCache === false && */isset($caches[$id]) ){ |
- | |
169 | return $caches[$id]; |
- | |
170 | } |
- | |
171 | - | ||
172 | if (strpos($id,':') !== false) { |
- | |
173 | list($ns, $altIdRaw) = explode(':', $id, 2); |
- | |
174 | if($ns === 'weid'){ |
- | |
175 | $id='oid:'.\Frdl\Weid\WeidOidConverter::weid2oid($id); |
- | |
176 | } |
- | |
177 | } |
- | |
178 | - | ||
179 | list($alt_ids, $rev_lookup) = $this->readAll(false); |
258 | $id_prefiltered = OIDplus::prefilterQuery($id, false); |
180 | 259 | ||
181 | $res = [ |
260 | $res = [ |
182 | $id, |
261 | $id, |
- | 262 | $id_prefiltered |
|
183 | ]; |
263 | ]; |
- | 264 | ||
- | 265 | $resQ = OIDplus::db()->query("SELECT origin, alternative FROM ###altids WHERE origin = ? OR alternative = ? OR origin = ? OR alternative = ?", [$res[0],$res[0],$res[1],$res[1]]); |
|
184 | if(isset($rev_lookup[$id])){ |
266 | while ($row = $resQ->fetch_array()) { |
185 | $res = array_merge($res, $rev_lookup[$id]); |
267 | if(!in_array($row['origin'], $res)){ |
- | 268 | $res[]=$row['origin']; |
|
186 | } |
269 | } |
187 | foreach($alt_ids as $original => $altIds){ |
- | |
188 | // Why self::special_in_array() instead of in_array()? Consider the following testcase: |
- | |
189 | // "oid:1.3.6.1.4.1.37553.8.8.2" defines alt ID "mac:63-CF-E4-AE-C5-66" which is NOT canonized! |
- | |
190 | // You must be able to enter "mac:63-CF-E4-AE-C5-66" in the search box, which gets canonized |
- | |
191 | // to mac:63CFE4AEC566 and must be solved to "oid:1.3.6.1.4.1.37553.8.8.2" by this plugin. |
- | |
192 | // Therefore we use self::special_in_array(). |
- | |
193 | // However, it is mandatory, that previously saveAltIdsForQuery("oid:1.3.6.1.4.1.37553.8.8.2") was called once! |
- | |
194 | // Please also note that the "weid:" to "oid:" converting is handled by prefilterQuery(), but only if the OID plugin is installed. |
- | |
195 | if($id === $original || self::special_in_array($id, $altIds) ){ |
- | |
196 | $res = array_merge($res, $altIds); |
270 | if(!in_array($row['alternative'], $res)){ |
197 | $res = array_merge($res, [$original]); |
271 | $res[]=$row['alternative']; |
198 | } |
272 | } |
199 | } |
273 | } |
200 | 274 | ||
201 | $weid = false; |
- | |
202 | foreach($res as $alt){ |
275 | return array_unique($res); |
203 | if (strpos($alt,':') !== false) { |
- | |
204 | list($ns, $altIdRaw) = explode(':', $alt, 2); |
- | |
205 | if($ns === 'oid'){ |
- | |
206 | $weid=\Frdl\Weid\WeidOidConverter::oid2weid($altIdRaw); |
- | |
207 | break; |
- | |
208 | } |
- | |
209 | } |
- | |
210 | } |
276 | } |
211 | 277 | ||
- | 278 | /** |
|
- | 279 | * @param string $id |
|
- | 280 | * @param array $out |
|
212 | if ($weid !== false) { |
281 | * @param bool $handled |
213 | $res[]=$weid; |
282 | * @return void |
- | 283 | */ |
|
- | 284 | public function gui(string $id, array &$out, bool &$handled) { |
|
- | 285 | // $this->saveAltIdsForQuery($id); |
|
214 | } |
286 | } |
215 | $res = array_unique($res); |
- | |
216 | 287 | ||
- | 288 | /** |
|
217 | $caches[$id] = $res; |
289 | * @param array $out |
- | 290 | * @return void |
|
- | 291 | */ |
|
- | 292 | public function publicSitemap(array &$out) { |
|
- | 293 | ||
- | 294 | } |
|
218 | 295 | ||
- | 296 | /** |
|
- | 297 | * @param array $json |
|
- | 298 | * @param string|null $ra_email |
|
- | 299 | * @param bool $nonjs |
|
- | 300 | * @param string $req_goto |
|
- | 301 | * @return bool |
|
- | 302 | */ |
|
- | 303 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
|
219 | return $res; |
304 | return false; |
220 | } |
305 | } |
221 | 306 | ||
222 | /** |
307 | /** |
223 | * @param string $request |
308 | * @param string $request |
224 | * @return array|false |
309 | * @return array|false |
Line 239... | Line 324... | ||
239 | if($ns === 'oid'){ |
324 | if($ns === 'oid'){ |
240 | return $alt; |
325 | return $alt; |
241 | } |
326 | } |
242 | } |
327 | } |
243 | } |
328 | } |
244 | - | ||
245 | return false; |
329 | return false; |
246 | } |
330 | } |
247 | 331 | ||
248 | /** |
332 | /** |
249 | * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_4 |
333 | * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_4 |
Line 261... | Line 345... | ||
261 | $canonicalShown = false; |
345 | $canonicalShown = false; |
262 | 346 | ||
263 | $out1 = array(); |
347 | $out1 = array(); |
264 | $out2 = array(); |
348 | $out2 = array(); |
265 | 349 | ||
266 | $tmp = $this->getAlternativesForQuery($id); |
350 | //$tmp = $this->getAlternativesForQuery($id); |
- | 351 | $obj = OIDplusObject::parse($id); |
|
- | 352 | $tmp = [ |
|
- | 353 | $this->getCanonical($id), |
|
- | 354 | ]; |
|
- | 355 | foreach ($obj->getAltIds() as $altId) { |
|
267 | sort($tmp); // DM 26.03.2023 : Added sorting (intended to sort "alternate-identifier") |
356 | $tmp[] = $altId->getNamespace().':'.$altId->getId(); |
- | 357 | } |
|
268 | 358 | ||
- | 359 | sort($tmp); // DM 26.03.2023 : Added sorting (intended to sort "alternate-identifier") |
|
269 | foreach($tmp as $alt) { |
360 | foreach($tmp as $alt) { |
270 | if (strpos($alt,':') === false) continue; |
361 | if (strpos($alt,':') === false) continue; |
271 | 362 | ||
272 | list($ns, $altIdRaw) = explode(':', $alt, 2); |
363 | list($ns, $altIdRaw) = explode(':', $alt, 2); |
273 | 364 | ||
Line 323... | Line 414... | ||
323 | */ |
414 | */ |
324 | public function whoisRaAttributes(string $email, array &$out) { |
415 | public function whoisRaAttributes(string $email, array &$out) { |
325 | 416 | ||
326 | } |
417 | } |
327 | 418 | ||
- | 419 | /** |
|
- | 420 | * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8 |
|
- | 421 | * @param string|null $user |
|
- | 422 | * @return array |
|
- | 423 | * @throws \ViaThinkSoft\OIDplus\OIDplusException |
|
- | 424 | */ |
|
- | 425 | public function getNotifications(string $user=null): array { |
|
- | 426 | $notifications = array(); |
|
- | 427 | if ((!$user || ($user == 'admin')) && OIDplus::authUtils()->isAdminLoggedIn()) { |
|
- | 428 | if (!$this->db_table_exists) { |
|
- | 429 | $title = _L('Alt ID Plugin'); |
|
- | 430 | $notifications[] = new OIDplusNotification('ERR', _L('OIDplus plugin "%1" is enabled, but it does not know how to create its database tables to this DBMS. Therefore the plugin does not work.', htmlentities($title))); |
|
- | 431 | } |
|
- | 432 | } |
|
- | 433 | return $notifications; |
|
- | 434 | } |
|
- | 435 | ||
328 | } |
436 | } |