From 52d3cce59dae1b5b8adb5497450e396473ebf6b2 Mon Sep 17 00:00:00 2001 From: sysadminstory Date: Wed, 9 Aug 2023 22:40:24 +0200 Subject: [PATCH] bridges: add context to detectParameters (#3607) * bridges: add context to detectParameters Some bridges did not return the context parameter but they used it in the parameters * bridges: add context to detectParameters Fix test for InstagramBridge --- bridges/BadDragonBridge.php | 2 + bridges/BandcampBridge.php | 3 + bridges/FacebookBridge.php | 3 + bridges/FreeTelechargerBridge.php | 151 +++++++++++++++--------------- bridges/FunkBridge.php | 1 + bridges/FurAffinityBridge.php | 4 + bridges/GithubIssueBridge.php | 4 + bridges/ImgsedBridge.php | 1 + bridges/InstagramBridge.php | 7 +- bridges/RedditBridge.php | 2 + bridges/SkimfeedBridge.php | 3 +- bridges/TrelloBridge.php | 10 +- bridges/TwitterBridge.php | 4 + 13 files changed, 115 insertions(+), 80 deletions(-) diff --git a/bridges/BadDragonBridge.php b/bridges/BadDragonBridge.php index 2260bbd6..d38e3408 100644 --- a/bridges/BadDragonBridge.php +++ b/bridges/BadDragonBridge.php @@ -138,6 +138,7 @@ class BadDragonBridge extends BridgeAbstract // Sale $regex = '/^(https?:\/\/)?bad-dragon\.com\/sales/'; if (preg_match($regex, $url, $matches) > 0) { + $params['context'] = 'Sales'; return $params; } @@ -192,6 +193,7 @@ class BadDragonBridge extends BridgeAbstract isset($urlParams['noAccessories']) && $urlParams['noAccessories'] === '1' && $params['noAccessories'] = 'on'; + $params['context'] = 'Clearance'; return $params; } diff --git a/bridges/BandcampBridge.php b/bridges/BandcampBridge.php index c041b2b3..a9bd2ea1 100644 --- a/bridges/BandcampBridge.php +++ b/bridges/BandcampBridge.php @@ -397,6 +397,7 @@ class BandcampBridge extends BridgeAbstract // By tag $regex = '/^(https?:\/\/)?bandcamp\.com\/tag\/([^\/.&?\n]+)/'; if (preg_match($regex, $url, $matches) > 0) { + $params['context'] = 'By tag'; $params['tag'] = urldecode($matches[2]); return $params; } @@ -404,6 +405,7 @@ class BandcampBridge extends BridgeAbstract // By band $regex = '/^(https?:\/\/)?([^\/.&?\n]+?)\.bandcamp\.com/'; if (preg_match($regex, $url, $matches) > 0) { + $params['context'] = 'By band'; $params['band'] = urldecode($matches[2]); return $params; } @@ -411,6 +413,7 @@ class BandcampBridge extends BridgeAbstract // By album $regex = '/^(https?:\/\/)?([^\/.&?\n]+?)\.bandcamp\.com\/album\/([^\/.&?\n]+)/'; if (preg_match($regex, $url, $matches) > 0) { + $params['context'] = 'By album'; $params['band'] = urldecode($matches[2]); $params['album'] = urldecode($matches[3]); return $params; diff --git a/bridges/FacebookBridge.php b/bridges/FacebookBridge.php index 9ccf6dcd..3e693a38 100644 --- a/bridges/FacebookBridge.php +++ b/bridges/FacebookBridge.php @@ -88,6 +88,7 @@ class FacebookBridge extends BridgeAbstract // By profile $regex = '/^(https?:\/\/)?(www\.)?facebook\.com\/profile\.php\?id\=([^\/?&\n]+)?(.*)/'; if (preg_match($regex, $url, $matches) > 0) { + $params['context'] = 'User'; $params['u'] = urldecode($matches[3]); return $params; } @@ -95,6 +96,7 @@ class FacebookBridge extends BridgeAbstract // By group $regex = '/^(https?:\/\/)?(www\.)?facebook\.com\/groups\/([^\/?\n]+)?(.*)/'; if (preg_match($regex, $url, $matches) > 0) { + $params['context'] = 'Group'; $params['g'] = urldecode($matches[3]); return $params; } @@ -103,6 +105,7 @@ class FacebookBridge extends BridgeAbstract $regex = '/^(https?:\/\/)?(www\.)?facebook\.com\/([^\/?\n]+)/'; if (preg_match($regex, $url, $matches) > 0) { + $params['context'] = ''; $params['u'] = urldecode($matches[3]); return $params; } diff --git a/bridges/FreeTelechargerBridge.php b/bridges/FreeTelechargerBridge.php index b94ff835..8362b4ff 100644 --- a/bridges/FreeTelechargerBridge.php +++ b/bridges/FreeTelechargerBridge.php @@ -2,89 +2,90 @@ class FreeTelechargerBridge extends BridgeAbstract { - const NAME = 'Free-Telecharger'; - const URI = 'https://www.free-telecharger.live/'; - const DESCRIPTION = 'Suivi de série sur Free-Telecharger'; - const MAINTAINER = 'sysadminstory'; - const PARAMETERS = [ - 'Suivi de publication de série' => [ - 'url' => [ - 'name' => 'URL de la série', - 'type' => 'text', - 'required' => true, - 'title' => 'URL d\'une série sans le https://www.free-telecharger.live/', - 'pattern' => 'series.*\.html', - 'exampleValue' => 'series-vf-hd/145458-the-last-of-us-saison-1-web-dl-720p.html' - ], - ] - ]; - const CACHE_TIMEOUT = 3600; - public function collectData() - { - $html = getSimpleHTMLDOM(self::URI . $this->getInput('url')); + const NAME = 'Free-Telecharger'; + const URI = 'https://www.free-telecharger.live/'; + const DESCRIPTION = 'Suivi de série sur Free-Telecharger'; + const MAINTAINER = 'sysadminstory'; + const PARAMETERS = [ + 'Suivi de publication de série' => [ + 'url' => [ + 'name' => 'URL de la série', + 'type' => 'text', + 'required' => true, + 'title' => 'URL d\'une série sans le https://www.free-telecharger.live/', + 'pattern' => 'series.*\.html', + 'exampleValue' => 'series-vf-hd/145458-the-last-of-us-saison-1-web-dl-720p.html' + ], + ] + ]; + const CACHE_TIMEOUT = 3600; + public function collectData() + { + $html = getSimpleHTMLDOM(self::URI . $this->getInput('url')); - // Find all block content of the page - $blocks = $html->find('div[class=block1]'); + // Find all block content of the page + $blocks = $html->find('div[class=block1]'); - // Global Infos block - $infosBlock = $blocks[0]; - // Links block - $linksBlock = $blocks[2]; + // Global Infos block + $infosBlock = $blocks[0]; + // Links block + $linksBlock = $blocks[2]; - // Extract Global Show infos - $this->showTitle = trim($infosBlock->find('div[class=titre1]', 0)->find('font', 0)->plaintext); - $this->showTechDetails = trim($infosBlock->find('div[align=center]', 0)->find('b', 0)->plaintext); + // Extract Global Show infos + $this->showTitle = trim($infosBlock->find('div[class=titre1]', 0)->find('font', 0)->plaintext); + $this->showTechDetails = trim($infosBlock->find('div[align=center]', 0)->find('b', 0)->plaintext); - // Get Episodes names and links - $episodes = $linksBlock->find('div[id=link]', 0)->find('font[color=#ff6600]'); - $links = $linksBlock->find('div[id=link]', 0)->find('a'); + // Get Episodes names and links + $episodes = $linksBlock->find('div[id=link]', 0)->find('font[color=#ff6600]'); + $links = $linksBlock->find('div[id=link]', 0)->find('a'); - foreach ($episodes as $index => $episode) { - $item = []; // Create an empty item - $item['title'] = $this->showTitle . ' ' . $this->showTechDetails . ' - ' . ltrim(trim($episode->plaintext), '-'); - $item['uri'] = $links[$index]->href; - $item['content'] = '' . $item['title'] . ''; - $item['uid'] = hash('md5', $item['uri']); + foreach ($episodes as $index => $episode) { + $item = []; // Create an empty item + $item['title'] = $this->showTitle . ' ' . $this->showTechDetails . ' - ' . ltrim(trim($episode->plaintext), '-'); + $item['uri'] = $links[$index]->href; + $item['content'] = '' . $item['title'] . ''; + $item['uid'] = hash('md5', $item['uri']); - $this->items[] = $item; // Add this item to the list - } + $this->items[] = $item; // Add this item to the list + } + } + + public function getName() + { + switch ($this->queriedContext) { + case 'Suivi de publication de série': + return $this->showTitle . ' ' . $this->showTechDetails . ' - ' . self::NAME; + break; + default: + return self::NAME; + } + } + + public function getURI() + { + switch ($this->queriedContext) { + case 'Suivi de publication de série': + return self::URI . $this->getInput('url'); + break; + default: + return self::URI; + } + } + + public function detectParameters($url) + { + // Example: https://www.free-telecharger.live/series-vf-hd/145458-the-last-of-us-saison-1-web-dl-720p.html + + $params = []; + $regex = '/^https:\/\/www.*\.free-telecharger\.live\/(series.*\.html)/'; + if (preg_match($regex, $url, $matches) > 0) { + $params['context'] = 'Suivi de publication de série'; + $params['url'] = urldecode($matches[1]); + return $params; } - public function getName() - { - switch ($this->queriedContext) { - case 'Suivi de publication de série': - return $this->showTitle . ' ' . $this->showTechDetails . ' - ' . self::NAME; - break; - default: - return self::NAME; - } - } - - public function getURI() - { - switch ($this->queriedContext) { - case 'Suivi de publication de série': - return self::URI . $this->getInput('url'); - break; - default: - return self::URI; - } - } - - public function detectParameters($url) - { - // Example: https://www.free-telecharger.live/series-vf-hd/145458-the-last-of-us-saison-1-web-dl-720p.html - - $params = []; - $regex = '/^https:\/\/www.*\.free-telecharger\.live\/(series.*\.html)/'; - if (preg_match($regex, $url, $matches) > 0) { - $params['url'] = urldecode($matches[1]); - return $params; - } - - return null; - } + return null; + } } diff --git a/bridges/FunkBridge.php b/bridges/FunkBridge.php index 69be4928..df499035 100644 --- a/bridges/FunkBridge.php +++ b/bridges/FunkBridge.php @@ -64,6 +64,7 @@ class FunkBridge extends BridgeAbstract $regex = '/^https?:\/\/(?:www\.)?funk\.net\/channel\/([^\/]+).*$/'; if (preg_match($regex, $url, $urlMatches) > 0) { return [ + 'context' => 'Channel', 'channel' => $urlMatches[1] ]; } else { diff --git a/bridges/FurAffinityBridge.php b/bridges/FurAffinityBridge.php index c548ff65..6c2d7b52 100644 --- a/bridges/FurAffinityBridge.php +++ b/bridges/FurAffinityBridge.php @@ -603,6 +603,7 @@ class FurAffinityBridge extends BridgeAbstract // Single journal $regex = '/^(https?:\/\/)?(www\.)?furaffinity.net\/journal\/(\d+)/'; if (preg_match($regex, $url, $matches) > 0) { + $params['context'] = 'Single Journal'; $params['journal-id'] = urldecode($matches[3]); return $params; } @@ -610,6 +611,7 @@ class FurAffinityBridge extends BridgeAbstract // Journals $regex = '/^(https?:\/\/)?(www\.)?furaffinity.net\/journals\/([^\/&?\n]+)/'; if (preg_match($regex, $url, $matches) > 0) { + $params['context'] = 'Journals'; $params['username-journals'] = urldecode($matches[3]); return $params; } @@ -617,6 +619,7 @@ class FurAffinityBridge extends BridgeAbstract // Gallery folder $regex = '/^(https?:\/\/)?(www\.)?furaffinity.net\/gallery\/([^\/&?\n]+)\/folder\/(\d+)/'; if (preg_match($regex, $url, $matches) > 0) { + $params['context'] = 'Gallery Folder'; $params['username-folder'] = urldecode($matches[3]); $params['folder-id'] = urldecode($matches[4]); $params['full'] = 'on'; @@ -626,6 +629,7 @@ class FurAffinityBridge extends BridgeAbstract // Gallery (must be after gallery folder) $regex = '/^(https?:\/\/)?(www\.)?furaffinity.net\/(gallery|scraps|favorites)\/([^\/&?\n]+)/'; if (preg_match($regex, $url, $matches) > 0) { + $params['context'] = 'Gallery'; $params['username-' . $matches[3]] = urldecode($matches[4]); $params['full'] = 'on'; return $params; diff --git a/bridges/GithubIssueBridge.php b/bridges/GithubIssueBridge.php index e4e995e3..7f56abbd 100644 --- a/bridges/GithubIssueBridge.php +++ b/bridges/GithubIssueBridge.php @@ -277,6 +277,7 @@ class GithubIssueBridge extends BridgeAbstract case 2: // Project issues [$user, $project] = $path_segments; $show_comments = 'off'; + $context = 'Project Issues'; break; case 3: // Project issues with issue comments if ($path_segments[2] !== static::URL_PATH) { @@ -284,15 +285,18 @@ class GithubIssueBridge extends BridgeAbstract } [$user, $project] = $path_segments; $show_comments = 'on'; + $context = 'Project Issues'; break; case 4: // Issue comments [$user, $project, /* issues */, $issue] = $path_segments; + $context = 'Issue comments'; break; default: return null; } return [ + 'context' => $context, 'u' => $user, 'p' => $project, 'c' => $show_comments ?? null, diff --git a/bridges/ImgsedBridge.php b/bridges/ImgsedBridge.php index 5fe3eee8..cf17acb4 100644 --- a/bridges/ImgsedBridge.php +++ b/bridges/ImgsedBridge.php @@ -267,6 +267,7 @@ HTML, $regex = '/^http(s|):\/\/((www\.|)(instagram.com)\/([a-zA-Z0-9_\.]{1,30})\/(reels\/|tagged\/|) |(www\.|)(imgsed.com)\/(stories\/|tagged\/|)([a-zA-Z0-9_\.]{1,30})\/)/'; if (preg_match($regex, $url, $matches) > 0) { + $params['context'] = 'Username'; // Extract detected domain using the regex $domain = $matches[8] ?? $matches[4]; if ($domain == 'imgsed.com') { diff --git a/bridges/InstagramBridge.php b/bridges/InstagramBridge.php index 71431906..0f644c4a 100644 --- a/bridges/InstagramBridge.php +++ b/bridges/InstagramBridge.php @@ -63,9 +63,9 @@ class InstagramBridge extends BridgeAbstract ]; const TEST_DETECT_PARAMETERS = [ - 'https://www.instagram.com/metaverse' => ['u' => 'metaverse'], - 'https://instagram.com/metaverse' => ['u' => 'metaverse'], - 'http://www.instagram.com/metaverse' => ['u' => 'metaverse'], + 'https://www.instagram.com/metaverse' => ['context' => 'Username', 'u' => 'metaverse'], + 'https://instagram.com/metaverse' => ['context' => 'Username', 'u' => 'metaverse'], + 'http://www.instagram.com/metaverse' => ['context' => 'Username', 'u' => 'metaverse'], ]; const USER_QUERY_HASH = '58b6785bea111c67129decbe6a448951'; @@ -323,6 +323,7 @@ class InstagramBridge extends BridgeAbstract $regex = '/^(https?:\/\/)?(www\.)?instagram\.com\/([^\/?\n]+)/'; if (preg_match($regex, $url, $matches) > 0) { + $params['context'] = 'Username'; $params['u'] = urldecode($matches[3]); return $params; } diff --git a/bridges/RedditBridge.php b/bridges/RedditBridge.php index 86d7884b..bd60243f 100644 --- a/bridges/RedditBridge.php +++ b/bridges/RedditBridge.php @@ -301,10 +301,12 @@ class RedditBridge extends BridgeAbstract if ($path[1] == 'r') { return [ + 'context' => 'single', 'r' => $path[2] ]; } elseif ($path[1] == 'user') { return [ + 'context' => 'user', 'u' => $path[2] ]; } else { diff --git a/bridges/SkimfeedBridge.php b/bridges/SkimfeedBridge.php index 19d4c823..a224cdf4 100644 --- a/bridges/SkimfeedBridge.php +++ b/bridges/SkimfeedBridge.php @@ -455,11 +455,12 @@ class SkimfeedBridge extends BridgeAbstract return null; } - foreach (self::PARAMETERS as $channels) { + foreach (self::PARAMETERS as $context => $channels) { foreach ($channels as $box_name => $box) { foreach ($box['values'] as $name => $channel_url) { if (static::URI . $channel_url === $url) { return [ + 'context' => $context, $box_name => $name, ]; } diff --git a/bridges/TrelloBridge.php b/bridges/TrelloBridge.php index ea7eb71b..a1b5cfb8 100644 --- a/bridges/TrelloBridge.php +++ b/bridges/TrelloBridge.php @@ -670,7 +670,15 @@ class TrelloBridge extends BridgeAbstract { $regex = '/^(https?:\/\/)?trello\.com\/([bc])\/([^\/?\n]+)/'; if (preg_match($regex, $url, $matches) > 0) { - return [$matches[2] => $matches[3]]; + if ($matches[2] == 'b') { + $context = 'Board'; + } else if ($matches[2] == 'c') { + $context = 'Card'; + } + return [ + 'context' => $context, + $matches[2] => $matches[3] + ]; } else { return null; } diff --git a/bridges/TwitterBridge.php b/bridges/TwitterBridge.php index 1ba00c66..1f115be8 100644 --- a/bridges/TwitterBridge.php +++ b/bridges/TwitterBridge.php @@ -133,6 +133,7 @@ EOD // By keyword or hashtag (search) $regex = '/^(https?:\/\/)?(www\.)?twitter\.com\/search.*(\?|&)q=([^\/&?\n]+)/'; if (preg_match($regex, $url, $matches) > 0) { + $params['context'] = 'By keyword or hashtag'; $params['q'] = urldecode($matches[4]); return $params; } @@ -140,6 +141,7 @@ EOD // By hashtag $regex = '/^(https?:\/\/)?(www\.)?twitter\.com\/hashtag\/([^\/?\n]+)/'; if (preg_match($regex, $url, $matches) > 0) { + $params['context'] = 'By keyword or hashtag'; $params['q'] = urldecode($matches[3]); return $params; } @@ -147,6 +149,7 @@ EOD // By list $regex = '/^(https?:\/\/)?(www\.)?twitter\.com\/([^\/?\n]+)\/lists\/([^\/?\n]+)/'; if (preg_match($regex, $url, $matches) > 0) { + $params['context'] = 'By list'; $params['user'] = urldecode($matches[3]); $params['list'] = urldecode($matches[4]); return $params; @@ -155,6 +158,7 @@ EOD // By username $regex = '/^(https?:\/\/)?(www\.)?twitter\.com\/([^\/?\n]+)/'; if (preg_match($regex, $url, $matches) > 0) { + $params['context'] = 'By username'; $params['u'] = urldecode($matches[3]); return $params; }