| 
									
										
										
										
											2013-09-30 17:13:03 +02:00
										 |  |  | <?php | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  |  * GNU Social - a federating social network | 
					
						
							|  |  |  |  * Copyright (C) 2013, Free Software Foundation, Inc. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU Affero General Public License as published by | 
					
						
							|  |  |  |  * the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  |  * (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU Affero General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Affero General Public License | 
					
						
							|  |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Implements Link-based Resource Descriptor Discovery based on RFC6415, | 
					
						
							|  |  |  |  * Web Host Metadata, i.e. the predecessor to WebFinger resource discovery. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-10-15 00:20:36 +02:00
										 |  |  |  * @package GNUsocial | 
					
						
							| 
									
										
										
										
											2013-09-30 17:13:03 +02:00
										 |  |  |  * @author  Mikael Nordfeldth <mmn@hethane.se> | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (!defined('GNUSOCIAL')) { exit(1); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ . '/extlib/'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class LRDDPlugin extends Plugin | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-06-03 01:56:52 +01:00
										 |  |  |     const PLUGIN_VERSION = '2.0.0'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-30 17:13:03 +02:00
										 |  |  |     public function onAutoload($cls) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         switch ($cls) { | 
					
						
							|  |  |  |         case 'XML_XRD': | 
					
						
							|  |  |  |             require_once __DIR__ . '/extlib/XML/XRD.php'; | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return parent::onAutoload($cls); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-10-04 15:57:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-30 17:13:03 +02:00
										 |  |  |     public function onStartDiscoveryMethodRegistration(Discovery $disco) { | 
					
						
							|  |  |  |         $disco->registerMethod('LRDDMethod_WebFinger'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function onEndDiscoveryMethodRegistration(Discovery $disco) { | 
					
						
							|  |  |  |         $disco->registerMethod('LRDDMethod_HostMeta'); | 
					
						
							|  |  |  |         $disco->registerMethod('LRDDMethod_LinkHeader'); | 
					
						
							|  |  |  |         $disco->registerMethod('LRDDMethod_LinkHTML'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 15:03:30 +01:00
										 |  |  |     public function onPluginVersion(array &$versions): bool | 
					
						
							| 
									
										
										
										
											2013-09-30 17:13:03 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         $versions[] = array('name' => 'LRDD', | 
					
						
							| 
									
										
										
										
											2019-06-03 01:56:52 +01:00
										 |  |  |                             'version' => self::PLUGIN_VERSION, | 
					
						
							| 
									
										
										
										
											2013-09-30 17:13:03 +02:00
										 |  |  |                             'author' => 'Mikael Nordfeldth', | 
					
						
							| 
									
										
										
										
											2019-11-21 00:21:22 +00:00
										 |  |  |                             'homepage' => GNUSOCIAL_ENGINE_URL, | 
					
						
							| 
									
										
										
										
											2013-09-30 17:13:03 +02:00
										 |  |  |                             // TRANS: Plugin description.
 | 
					
						
							|  |  |  |                             'rawdescription' => _m('Implements LRDD support for GNU Social.')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-03-31 08:07:35 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Fetch all the aliases of some remote profile | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param string $uri profile's URI | 
					
						
							|  |  |  |      * @return array|null aliases | 
					
						
							|  |  |  |      * @throws Exception (If the Discovery's HTTP requests fail) | 
					
						
							|  |  |  |      * @author Bruno Casteleiro <brunoccast@fc.up.pt> | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public static function grab_profile_aliases(string $uri): ?array | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $disco = new Discovery(); | 
					
						
							|  |  |  |         $xrd = $disco->lookup($uri); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $all_ids = array_merge([$xrd->subject], $xrd->aliases); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!in_array($uri, $all_ids)) { | 
					
						
							|  |  |  |             $this->log(LOG_INFO, 'The original URI was not listed itself when doing discovery on it!'); | 
					
						
							|  |  |  |             return null; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $all_ids; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-09-30 17:13:03 +02:00
										 |  |  | } |