From f085cdff77c7b6b47cf7c39fc4263a599068ef44 Mon Sep 17 00:00:00 2001 From: Xurxo Fresco Date: Sat, 11 Nov 2017 18:55:09 +0100 Subject: [PATCH 1/4] [IvooxBridge] new bridge for podcast plataform --- bridges/IvooxBridge.php | 140 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 bridges/IvooxBridge.php diff --git a/bridges/IvooxBridge.php b/bridges/IvooxBridge.php new file mode 100644 index 00000000000..d67e1028d7f --- /dev/null +++ b/bridges/IvooxBridge.php @@ -0,0 +1,140 @@ + array( + 's' => array( + 'name' => 'keyword', + 'exampleValue' => 'test' + ) + ) + ); + private function ivGetSimpleHTMLDOM($url) + { + return getSimpleHTMLDOM( + $url, + $use_include_path = false, + $context = null, + $offset = 0, + $maxLen = null, + $lowercase = true, + $forceTagsClosed = true, + $target_charset = DEFAULT_TARGET_CHARSET, + $stripRN = false, + $defaultBRText = DEFAULT_BR_TEXT, + $defaultSpanText = DEFAULT_SPAN_TEXT); + } + + private function printIfDebug($text) + { + if(defined('DEBUG') && DEBUG === true) { + print_r($text . '
' . "\r\n"); + } + } + + private function ivBridgeAddItem($episode_link, $podcast_name, $episode_title, $author_name, $episode_description, $publication_date, $episode_duration) + { + $item = array(); + $item['title'] = $podcast_name . ':' . $episode_title; + $item['author'] = $author_name; + $item['timestamp'] = $publication_date; + $item['uri'] = $episode_link; + $item['content'] = '' . $podcast_name . ': ' . $episode_title . '
Duration: ' . $episode_duration . '"
Description:
' . $episode_description; + $this->items[] = $item; + } + + private function ivBridgeParseHtmlListing($html) + { + $limit = 4; + $count = 0; + + foreach($html->find('div.flip-container') as $flipper) { + $linkcount = 0; + if(!empty($flipper->find( 'div.modulo-type-banner' ))) { + // ad + continue; + } + + if($count < $limit) { + foreach($flipper->find('div.header-modulo') as $element) { + foreach($element->find('a') as $link) { + if ($linkcount == 0) { + $episode_link = $link->href; + $episode_title = $link->title; + } + elseif ($linkcount == 1) { + $author_link = $link->href; + $author_name = $link->title; + } + elseif ($linkcount == 2) { + $podcast_link = $link->href; + $podcast_name = $link->title; + } + + $linkcount++; + } + } + + $episode_description = $flipper->find('button.btn-link', 0)->getAttribute('data-content'); + $episode_duration = $flipper->find('p.time', 0)->innertext; + $publication_date = $flipper->find('li.date', 0)->getAttribute('title'); + + // alternative date_parse_from_format or DateTime::createFromFormat('G:i - d \d\e M \d\e Y', $publication); // TODO: month name translations, due funciton doesn't support locale + + $a = strptime($publication_date, '%H:%M - %d de %b. de %Y'); // obsolete function, uses c libraries + $publication_date = mktime(0, 0, 0, $a['tm_mon'] + 1, $a['tm_mday'], $a['tm_year'] + 1900); + + $this->ivBridgeAddItem($episode_link, $podcast_name, $episode_title, $author_name, $episode_description, $publication_date, $episode_duration); + $count++; + } + } + } + + public function collectData() + { + + // store locale, change to spanish + $originalLocales = explode(";", setlocale(LC_ALL, 0)); + setlocale(LC_ALL, "es_ES.utf8"); + + $this->printIfDebug('debug mode active'); + $xml = ''; + $html = ''; + $url_feed = ''; + if($this->getInput('s')) { /* Search modes */ + $this->request = str_replace(' ', '-', $this->getInput('s')); + $url_feed = self::URI . urlencode($this->request) . '_sb_f_1.html?o=uploaddate'; + $this->printIfDebug($url_feed); + } + else { + returnClientError("Not valid mode at IvooxBridge"); + } + + $dom = $this->ivGetSimpleHTMLDOM($url_feed) or returnServerError("Could not request iVoox. Tried:\n - $url_feed"); + $this->ivBridgeParseHtmlListing($dom); + + // restore locale + + foreach($originalLocales as $localeSetting) { + if(strpos($localeSetting, "=") !== false) { + list($category, $locale) = explode("=", $localeSetting); + } + else { + $category = LC_ALL; + $locale = $localeSetting; + } + + setlocale($category, $locale); + } + } +} From 97d87f3432ef47ba1e839c7ae9050ef225e25769 Mon Sep 17 00:00:00 2001 From: Xurxo Fresco Date: Sat, 3 Feb 2018 12:12:24 +0100 Subject: [PATCH 2/4] [IvooxBridge] format issues --- bridges/IvooxBridge.php | 42 +++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/bridges/IvooxBridge.php b/bridges/IvooxBridge.php index d67e1028d7f..24200bc072d 100644 --- a/bridges/IvooxBridge.php +++ b/bridges/IvooxBridge.php @@ -22,16 +22,16 @@ class IvooxBridge extends BridgeAbstract private function ivGetSimpleHTMLDOM($url) { return getSimpleHTMLDOM( - $url, - $use_include_path = false, + $url, + $use_include_path = false, $context = null, - $offset = 0, - $maxLen = null, - $lowercase = true, - $forceTagsClosed = true, - $target_charset = DEFAULT_TARGET_CHARSET, - $stripRN = false, - $defaultBRText = DEFAULT_BR_TEXT, + $offset = 0, + $maxLen = null, + $lowercase = true, + $forceTagsClosed = true, + $target_charset = DEFAULT_TARGET_CHARSET, + $stripRN = false, + $defaultBRText = DEFAULT_BR_TEXT, $defaultSpanText = DEFAULT_SPAN_TEXT); } @@ -42,14 +42,17 @@ private function printIfDebug($text) } } - private function ivBridgeAddItem($episode_link, $podcast_name, $episode_title, $author_name, $episode_description, $publication_date, $episode_duration) + private function ivBridgeAddItem($episode_link, $podcast_name, $episode_title, $author_name, + $episode_description, $publication_date, $episode_duration) { $item = array(); $item['title'] = $podcast_name . ':' . $episode_title; $item['author'] = $author_name; $item['timestamp'] = $publication_date; $item['uri'] = $episode_link; - $item['content'] = '' . $podcast_name . ': ' . $episode_title . '
Duration: ' . $episode_duration . '"
Description:
' . $episode_description; + $item['content'] = '' . $podcast_name . ': ' . $episode_title . '' + . '
Duration: ' . $episode_duration . '"' + . "
Description:
' . $episode_description; $this->items[] = $item; } @@ -57,14 +60,14 @@ private function ivBridgeParseHtmlListing($html) { $limit = 4; $count = 0; - + foreach($html->find('div.flip-container') as $flipper) { $linkcount = 0; - if(!empty($flipper->find( 'div.modulo-type-banner' ))) { + if(!empty($flipper->find( 'div.modulo-type-banner' ))) { // ad continue; } - + if($count < $limit) { foreach($flipper->find('div.header-modulo') as $element) { foreach($element->find('a') as $link) { @@ -89,12 +92,15 @@ private function ivBridgeParseHtmlListing($html) $episode_duration = $flipper->find('p.time', 0)->innertext; $publication_date = $flipper->find('li.date', 0)->getAttribute('title'); - // alternative date_parse_from_format or DateTime::createFromFormat('G:i - d \d\e M \d\e Y', $publication); // TODO: month name translations, due funciton doesn't support locale + // alternative date_parse_from_format + // or DateTime::createFromFormat('G:i - d \d\e M \d\e Y', $publication); + // TODO: month name translations, due function doesn't support locale $a = strptime($publication_date, '%H:%M - %d de %b. de %Y'); // obsolete function, uses c libraries $publication_date = mktime(0, 0, 0, $a['tm_mon'] + 1, $a['tm_mday'], $a['tm_year'] + 1900); - - $this->ivBridgeAddItem($episode_link, $podcast_name, $episode_title, $author_name, $episode_description, $publication_date, $episode_duration); + + $this->ivBridgeAddItem($episode_link, $podcast_name, $episode_title, $author_name, $episode_description, + $publication_date, $episode_duration); $count++; } } @@ -106,7 +112,7 @@ public function collectData() // store locale, change to spanish $originalLocales = explode(";", setlocale(LC_ALL, 0)); setlocale(LC_ALL, "es_ES.utf8"); - + $this->printIfDebug('debug mode active'); $xml = ''; $html = ''; From 6b9f76cc7df574db13a51b68500caf6971dbdf2b Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Fri, 22 Mar 2019 21:26:11 +0100 Subject: [PATCH 3/4] [IvooxBridge] Rebase and apply fixes --- bridges/IvooxBridge.php | 71 ++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/bridges/IvooxBridge.php b/bridges/IvooxBridge.php index 24200bc072d..9afd1d2f9c2 100644 --- a/bridges/IvooxBridge.php +++ b/bridges/IvooxBridge.php @@ -4,8 +4,7 @@ * Returns the latest search result * TODO: support podcast episodes list */ -class IvooxBridge extends BridgeAbstract -{ +class IvooxBridge extends BridgeAbstract { const NAME = 'Ivoox Bridge'; const URI = 'https://www.ivoox.com/'; const CACHE_TIMEOUT = 10800; // 3h @@ -19,8 +18,8 @@ class IvooxBridge extends BridgeAbstract ) ) ); - private function ivGetSimpleHTMLDOM($url) - { + + private function ivGetSimpleHTMLDOM($url) { return getSimpleHTMLDOM( $url, $use_include_path = false, @@ -35,29 +34,32 @@ private function ivGetSimpleHTMLDOM($url) $defaultSpanText = DEFAULT_SPAN_TEXT); } - private function printIfDebug($text) - { + private function printIfDebug($text) { if(defined('DEBUG') && DEBUG === true) { print_r($text . '
' . "\r\n"); } } - private function ivBridgeAddItem($episode_link, $podcast_name, $episode_title, $author_name, - $episode_description, $publication_date, $episode_duration) - { + private function ivBridgeAddItem( + $episode_link, + $podcast_name, + $episode_title, + $author_name, + $episode_description, + $publication_date, + $episode_duration) { $item = array(); - $item['title'] = $podcast_name . ':' . $episode_title; + $item['title'] = htmlspecialchars_decode($podcast_name . ': ' . $episode_title); $item['author'] = $author_name; $item['timestamp'] = $publication_date; $item['uri'] = $episode_link; - $item['content'] = '' . $podcast_name . ': ' . $episode_title . '' - . '
Duration: ' . $episode_duration . '"' - . "
Description:
' . $episode_description; + $item['content'] = '' . $podcast_name . ': ' . $episode_title + . '
Duration: ' . $episode_duration + . '
Description:
' . $episode_description; $this->items[] = $item; } - private function ivBridgeParseHtmlListing($html) - { + private function ivBridgeParseHtmlListing($html) { $limit = 4; $count = 0; @@ -74,12 +76,10 @@ private function ivBridgeParseHtmlListing($html) if ($linkcount == 0) { $episode_link = $link->href; $episode_title = $link->title; - } - elseif ($linkcount == 1) { + } elseif ($linkcount == 1) { $author_link = $link->href; $author_name = $link->title; - } - elseif ($linkcount == 2) { + } elseif ($linkcount == 2) { $podcast_link = $link->href; $podcast_name = $link->title; } @@ -99,19 +99,25 @@ private function ivBridgeParseHtmlListing($html) $a = strptime($publication_date, '%H:%M - %d de %b. de %Y'); // obsolete function, uses c libraries $publication_date = mktime(0, 0, 0, $a['tm_mon'] + 1, $a['tm_mday'], $a['tm_year'] + 1900); - $this->ivBridgeAddItem($episode_link, $podcast_name, $episode_title, $author_name, $episode_description, - $publication_date, $episode_duration); + $this->ivBridgeAddItem( + $episode_link, + $podcast_name, + $episode_title, + $author_name, + $episode_description, + $publication_date, + $episode_duration + ); $count++; } } } - public function collectData() - { + public function collectData() { // store locale, change to spanish - $originalLocales = explode(";", setlocale(LC_ALL, 0)); - setlocale(LC_ALL, "es_ES.utf8"); + $originalLocales = explode(';', setlocale(LC_ALL, 0)); + setlocale(LC_ALL, 'es_ES.utf8'); $this->printIfDebug('debug mode active'); $xml = ''; @@ -121,21 +127,20 @@ public function collectData() $this->request = str_replace(' ', '-', $this->getInput('s')); $url_feed = self::URI . urlencode($this->request) . '_sb_f_1.html?o=uploaddate'; $this->printIfDebug($url_feed); - } - else { - returnClientError("Not valid mode at IvooxBridge"); + } else { + returnClientError('Not valid mode at IvooxBridge'); } - $dom = $this->ivGetSimpleHTMLDOM($url_feed) or returnServerError("Could not request iVoox. Tried:\n - $url_feed"); + $dom = getSimpleHTMLDOM($url_feed) + or returnServerError('Could not request ' . $url_feed); $this->ivBridgeParseHtmlListing($dom); // restore locale foreach($originalLocales as $localeSetting) { - if(strpos($localeSetting, "=") !== false) { - list($category, $locale) = explode("=", $localeSetting); - } - else { + if(strpos($localeSetting, '=') !== false) { + list($category, $locale) = explode('=', $localeSetting); + } else { $category = LC_ALL; $locale = $localeSetting; } From 3a5e6543bb99f1fad37641aa6466a04f8144c758 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Fri, 22 Mar 2019 21:30:02 +0100 Subject: [PATCH 4/4] [IvooxBridge] Remove unused functions --- bridges/IvooxBridge.php | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/bridges/IvooxBridge.php b/bridges/IvooxBridge.php index 9afd1d2f9c2..3cdf74bce3d 100644 --- a/bridges/IvooxBridge.php +++ b/bridges/IvooxBridge.php @@ -19,27 +19,6 @@ class IvooxBridge extends BridgeAbstract { ) ); - private function ivGetSimpleHTMLDOM($url) { - return getSimpleHTMLDOM( - $url, - $use_include_path = false, - $context = null, - $offset = 0, - $maxLen = null, - $lowercase = true, - $forceTagsClosed = true, - $target_charset = DEFAULT_TARGET_CHARSET, - $stripRN = false, - $defaultBRText = DEFAULT_BR_TEXT, - $defaultSpanText = DEFAULT_SPAN_TEXT); - } - - private function printIfDebug($text) { - if(defined('DEBUG') && DEBUG === true) { - print_r($text . '
' . "\r\n"); - } - } - private function ivBridgeAddItem( $episode_link, $podcast_name, @@ -119,14 +98,12 @@ public function collectData() { $originalLocales = explode(';', setlocale(LC_ALL, 0)); setlocale(LC_ALL, 'es_ES.utf8'); - $this->printIfDebug('debug mode active'); $xml = ''; $html = ''; $url_feed = ''; if($this->getInput('s')) { /* Search modes */ $this->request = str_replace(' ', '-', $this->getInput('s')); $url_feed = self::URI . urlencode($this->request) . '_sb_f_1.html?o=uploaddate'; - $this->printIfDebug($url_feed); } else { returnClientError('Not valid mode at IvooxBridge'); }