public function beforeSave() { // Prebuild Previews for URLs in Message UrlOembed::preload($this->message); // Check if Post Contains an Url if (preg_match('/http(.*?)(\\s|$)/i', $this->message)) { // Set Filter Flag $this->url = 1; } return parent::beforeSave(); }
/** * Deletes OEmbed Provider */ public function actionOEmbedDelete() { $this->forcePostRequest(); $prefix = Yii::app()->request->getParam('prefix'); $providers = UrlOembed::getProviders(); if (isset($providers[$prefix])) { unset($providers[$prefix]); UrlOembed::setProviders($providers); } $this->redirect(Yii::app()->createUrl('//admin/setting/oembed')); }
/** * Checks if a given URL Supports OEmbed * * @param type $url * @return boolean */ public static function HasOEmbedSupport($url) { foreach (UrlOembed::getProviders() as $providerBaseUrl => $providerAPI) { if (strpos($url, $providerBaseUrl) !== false) { return true; } } return false; }
/** * Converts an given Ascii Text into a HTML Block * @param boolean $allowHtml transform user names in links * @param boolean $allowEmbed Sets if comitted video links will embedded * * Tasks: * nl2br * oembed urls */ public static function enrichText($text) { $maxOembedCount = 3; // Maximum OEmbeds $oembedCount = 0; // OEmbeds used $text = preg_replace_callback('/http(.*?)(\\s|$)/i', function ($match) use(&$oembedCount, &$maxOembedCount) { // Try use oembed if ($maxOembedCount > $oembedCount) { $oembed = UrlOembed::GetOembed($match[0]); if ($oembed) { $oembedCount++; return $oembed; } } return HHtml::link($match[0], $match[0], array('target' => '_blank')); }, $text); # breaks links!? #$text = nl2br($text); $text = str_replace("\n", "<br />\n", $text); // get user details from guids $text = self::translateUserMentioning($text, true); return $text; }
/** * Loads OEmbed Data from a given URL and writes them to the database * * @param type $url * @return string */ public static function loadUrl($url) { $urlOembed = new UrlOembed(); $urlOembed->url = $url; $html = ""; if ($urlOembed->getProviderUrl() != "") { // Build OEmbed Preview $jsonOut = UrlOembed::fetchUrl($urlOembed->getProviderUrl()); if ($jsonOut != "") { $data = CJSON::decode($jsonOut); if ($data['type'] === "video" || $data['type'] === 'rich') { $html = "<div class='oembed_snippet'>" . $data['html'] . "</div>"; } } } if ($html != "") { $urlOembed->preview = $html; $urlOembed->save(); } return $html; }
/** * Converts an given Ascii Text into a HTML Block * @param boolean $allowHtml transform user names in links * @param boolean $allowEmbed Sets if comitted video links will embedded * * Tasks: * nl2br * oembed urls */ public static function enrichText($text) { $maxOembedCount = 3; // Maximum OEmbeds $oembedCount = 0; // OEmbeds used $text = preg_replace_callback('/(https?:\\/\\/.*?)(\\s|$)/i', function ($match) use(&$oembedCount, &$maxOembedCount) { // Try use oembed if ($maxOembedCount > $oembedCount) { $oembed = UrlOembed::GetOembed($match[0]); if ($oembed) { $oembedCount++; return $oembed; } } return HHtml::link($match[1], $match[1], array('target' => '_blank')) . $match[2]; }, $text); // get user and space details from guids $text = self::translateMentioning($text, true); // create image tag for emojis $text = self::translateEmojis($text); return nl2br($text); }