Skip to content

Commit

Permalink
Fix replace
Browse files Browse the repository at this point in the history
  • Loading branch information
c0ldplasma committed Jul 5, 2020
1 parent 4127eb2 commit 4274898
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions xExtension-TwitterResolver/extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 4274898

Please sign in to comment.