diff --git a/lib/util/default.php b/lib/util/default.php index d6f2639f48..e5864fd211 100644 --- a/lib/util/default.php +++ b/lib/util/default.php @@ -337,7 +337,9 @@ $default = 'Favorite' => [], 'HTMLPurifierSchemes' => [], 'Share' => [], - 'TheFreeNetwork' => [], + 'TheFreeNetwork' => [ + 'protocols' => ['ActivityPub' => 'Activitypub_profile', 'OStatus' => 'Ostatus_profile'] + ], ], 'default' => [ 'AccountManager' => [], diff --git a/modules/TheFreeNetwork/EVENTS.txt b/modules/TheFreeNetwork/EVENTS.txt index 1046b2323d..55bcbdefc2 100644 --- a/modules/TheFreeNetwork/EVENTS.txt +++ b/modules/TheFreeNetwork/EVENTS.txt @@ -1,6 +1,3 @@ -StartTFNCensus: when all plugins have been initialized; federation plugins must populate this event's array with their profile class name -@param array $free_network - StartTFNLookup: tries to locate a duplicated remote profile by URI; federation plugins must trigger this event before profile insertion @param string $uri URI of the remote profile to be inserted @param string $class profile class of the federation protocol that triggered the event diff --git a/modules/TheFreeNetwork/TheFreeNetworkModule.php b/modules/TheFreeNetwork/TheFreeNetworkModule.php index 7353535429..9706bddd85 100644 --- a/modules/TheFreeNetwork/TheFreeNetworkModule.php +++ b/modules/TheFreeNetwork/TheFreeNetworkModule.php @@ -41,23 +41,27 @@ class TheFreeNetworkModule extends Module { const MODULE_VERSION = '0.1.0alpha0'; - private $free_network = []; // name of the profile classes of the active federation protocols - private $lrdd = false; // whether LRDD plugin is active or not + public $protocols = null; // protocols TFN should handle + + private $lrdd = false; // whether LRDD plugin is active or not /** - * Called when all plugins have been initialized - * We'll populate our variables here + * Initialize TFN * * @return bool hook value */ public function onInitializePlugin(): bool { - // $free_network array - Event::handle('StartTFNCensus', [&$this->free_network]); + // some protocol plugins can be unactivated, + // require needed classes + $plugin_dir = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins'; + + foreach ($this->protocols as $protocol => $class) { + require_once $plugin_dir . DIRECTORY_SEPARATOR . $protocol . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . $class . '.php'; + } // $lrdd flag $this->lrdd = PluginList::isPluginActive("LRDD"); - $this->log(LOG_INFO, 'LRDD IS ' . ($this->lrdd ? 'ON' : 'OFF')); return true; } @@ -75,13 +79,14 @@ class TheFreeNetworkModule extends Module { $profile_id = $this->lookup($uri, $class); - if ($profile_id == null && $this->lrdd) { + $perf = common_config('performance', 'high'); + + if (is_null($profile_id) && !$perf && $this->lrdd) { // Force lookup with online resources - // TODO: Add settings to control whether we do this or not $profile_id = $this->lookup($uri, $class, true); } - return ($profile_id == null); + return is_null($profile_id); } /** @@ -94,7 +99,7 @@ class TheFreeNetworkModule extends Module */ public function onEndTFNLookup(string $class, int $profile_id): bool { - foreach ($this->free_network as $cls) { + foreach ($this->protocols as $p => $cls) { if ($cls != $class) { $profile = $cls::getKV('profile_id', $profile_id); if ($profile instanceof $cls) { @@ -156,7 +161,7 @@ class TheFreeNetworkModule extends Module return null; } - foreach ($this->free_network as $cls) { + foreach ($this->protocols as $p => $cls) { if ($cls != $class) { foreach ($all_ids as $alias) { $profile = $cls::getKV('uri', $alias);