diff --git a/xExtension-TwitterResolver/extension.php b/xExtension-TwitterResolver/extension.php index dde4db2..5e5a9b8 100644 --- a/xExtension-TwitterResolver/extension.php +++ b/xExtension-TwitterResolver/extension.php @@ -15,28 +15,29 @@ class TwitterResolverExtension extends Minz_Extension */ public function init() { - $this->registerHook('entry_before_display', array($this, 'embedYouTubeVideo')); + $this->registerHook('entry_before_display', array($this, 'convertTwitterUrls')); $this->registerTranslates(); } /** - * @param string $url + * @param FreshRSS_Entry $entry * @return string */ - public function convertYoutubeFeedUrl($url) + public function convertTwitterUrls($entry) { $matches = []; - if (preg_match('#^https?://t\.co/([0-9a-zA-Z_-]{1,64})#', $url, $matches) === 1) { + while (preg_match('#https?://t\.co/[0-9a-zA-Z_-]{1,64}#', $entry->content(), $matches) === 1) { $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_URL, $matches[0]); 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); + $entry->content() = str_replace($match, $url, $entry->content()); } - return $url; + return $entry; } }