diff --git a/xExtension-TwitterResolver/extension.php b/xExtension-TwitterResolver/extension.php index 852448e..dde4db2 100644 --- a/xExtension-TwitterResolver/extension.php +++ b/xExtension-TwitterResolver/extension.php @@ -1,34 +1,14 @@ registerHook('entry_before_display', array($this, 'embedYouTubeVideo')); - $this->registerHook('check_url_before_add', array($this, 'convertYoutubeFeedUrl')); $this->registerTranslates(); } @@ -48,233 +27,16 @@ public function convertYoutubeFeedUrl($url) { $matches = []; - if (preg_match('#^https?://www\.youtube\.com/channel/([0-9a-zA-Z_-]{6,36})#', $url, $matches) === 1) { - return 'https://www.youtube.com/feeds/videos.xml?channel_id=' . $matches[1]; - } - - if (preg_match('#^https?://www\.youtube\.com/user/([0-9a-zA-Z_-]{6,36})#', $url, $matches) === 1) { - return 'https://www.youtube.com/feeds/videos.xml?user=' . $matches[1]; + if (preg_match('#^https?://t\.co/([0-9a-zA-Z_-]{1,64})#', $url, $matches) === 1) { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_HEADER, true); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $a = curl_exec($ch); + $url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); } return $url; } - - /** - * Initializes the extension configuration, if the user context is available. - * Do not call that in your extensions init() method, it can't be used there. - */ - public function loadConfigValues() - { - if (!class_exists('FreshRSS_Context', false) || null === FreshRSS_Context::$user_conf) { - return; - } - - if (FreshRSS_Context::$user_conf->yt_player_width != '') { - $this->width = FreshRSS_Context::$user_conf->yt_player_width; - } - if (FreshRSS_Context::$user_conf->yt_player_height != '') { - $this->height = FreshRSS_Context::$user_conf->yt_player_height; - } - if (FreshRSS_Context::$user_conf->yt_show_content != '') { - $this->showContent = (bool)FreshRSS_Context::$user_conf->yt_show_content; - } - if (FreshRSS_Context::$user_conf->yt_nocookie != '') { - $this->useNoCookie = (bool)FreshRSS_Context::$user_conf->yt_nocookie; - } - } - - /** - * Returns the width in pixel for the youtube player iframe. - * You have to call loadConfigValues() before this one, otherwise you get default values. - * - * @return int - */ - public function getWidth() - { - return $this->width; - } - - /** - * Returns the height in pixel for the youtube player iframe. - * You have to call loadConfigValues() before this one, otherwise you get default values. - * - * @return int - */ - public function getHeight() - { - return $this->height; - } - - /** - * Returns whether this extensions displays the content of the youtube feed. - * You have to call loadConfigValues() before this one, otherwise you get default values. - * - * @return bool - */ - public function isShowContent() - { - return $this->showContent; - } - - /** - * Returns if this extension should use youtube-nocookie.com instead of youtube.com. - * You have to call loadConfigValues() before this one, otherwise you get default values. - * - * @return bool - */ - public function isUseNoCookieDomain() - { - return $this->useNoCookie; - } - - /** - * Inserts the YouTube video iframe into the content of an entry, if the entries link points to a YouTube watch URL. - * - * @param FreshRSS_Entry $entry - * @return mixed - */ - public function embedYouTubeVideo($entry) - { - $link = $entry->link(); - - if (preg_match('#^https?://www\.youtube\.com/watch\?v=|/videos/watch/[0-9a-f-]{36}$#', $link) !== 1) { - return $entry; - } - - $this->loadConfigValues(); - - if (stripos($entry->content(), ''; - - if ($this->showContent) { - $doc = new DOMDocument(); - $doc->encoding = 'UTF-8'; - $doc->recover = true; - $doc->strictErrorChecking = false; - - if ($doc->loadHTML('' . $entry->content())) - { - $xpath = new DOMXpath($doc); - - $titles = $xpath->evaluate("//*[@class='enclosure-title']"); - $thumbnails = $xpath->evaluate("//*[@class='enclosure-thumbnail']/@src"); - $descriptions = $xpath->evaluate("//*[@class='enclosure-description']"); - - $content = '
'; - - // We hide the title so it doesn't appear in the final article, which would be redundant with the RSS article title, - // but we keep it in the content anyway, so RSS clients can extract it if needed. - if ($titles->length > 0) { - $content .= ''; - } - - // We hide the thumbnail so it doesn't appear in the final article, which would be redundant with the YouTube player preview, - // but we keep it in the content anyway, so RSS clients can extract it to display a preview where it wants (in article listing, - // by example, like with Reeder). - if ($thumbnails->length > 0) { - $content .= ''; - } - - $content .= $iframe; - - if ($descriptions->length > 0) { - $content .= '

' . nl2br(htmlentities($descriptions[0]->nodeValue)) . '

'; - } - - $content .= "
\n"; - } - else { - $content = $iframe . $entry->content(); - } - } - else { - $content = $iframe; - } - - return $content; - } - - /** - * This function is called by FreshRSS when the configuration page is loaded, and when configuration is saved. - * - We save configuration in case of a post. - * - We (re)load configuration in all case, so they are in-sync after a save and before a page load. - */ - public function handleConfigureAction() - { - $this->registerTranslates(); - - if (Minz_Request::isPost()) { - FreshRSS_Context::$user_conf->yt_player_height = (int)Minz_Request::param('yt_height', ''); - FreshRSS_Context::$user_conf->yt_player_width = (int)Minz_Request::param('yt_width', ''); - FreshRSS_Context::$user_conf->yt_show_content = (bool)Minz_Request::param('yt_show_content', 0); - FreshRSS_Context::$user_conf->yt_nocookie = (int)Minz_Request::param('yt_nocookie', 0); - FreshRSS_Context::$user_conf->save(); - } - - $this->loadConfigValues(); - } }