public function run() { if ($this->encode) { $this->text = Html::encode($this->text); } if (!$this->minimal) { $maxOembedCount = 3; // Maximum OEmbeds $oembedCount = 0; // OEmbeds used $this->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 Html::a($match[1], Html::decode($match[1]), array('target' => '_blank')) . $match[2]; }, $this->text); } // get user and space details from guids $this->text = self::translateMentioning($this->text, $this->minimal ? false : true); // create image tag for emojis $this->text = self::translateEmojis($this->text, $this->minimal ? false : true); if ($this->maxLength != 0) { $this->text = \humhub\libs\Helpers::truncateText($this->text, $this->maxLength); } return nl2br($this->text); }
public function beforeSave($insert) { // Prebuild Previews for URLs in Message \humhub\models\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($insert); }
public function run() { if ($this->encode) { $this->text = Html::encode($this->text); } if (!$this->minimal) { $maxOembedCount = 3; // Maximum OEmbeds $oembedCount = 0; // OEmbeds used $that = $this; $this->text = preg_replace_callback('/(https?:\\/\\/.*?)(\\s|$)/i', function ($match) use(&$oembedCount, &$maxOembedCount, &$that) { if ($that->edit) { return Html::a($match[0], Html::decode($match[0]), array('target' => '_blank')); } // Try use oembed if ($maxOembedCount > $oembedCount) { $oembed = UrlOembed::GetOembed($match[0]); if ($oembed) { $oembedCount++; return $oembed; } } return Html::a($match[1], Html::decode($match[1]), array('target' => '_blank')) . $match[2]; }, $this->text); // mark emails $this->text = preg_replace_callback('/[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*(\\.[a-zA-Z]{2,3})/', function ($match) { return Html::mailto($match[0]); }, $this->text); } // get user and space details from guids $this->text = self::translateMentioning($this->text, $this->minimal ? false : true); // create image tag for emojis $this->text = self::translateEmojis($this->text, $this->minimal ? false : true); if ($this->maxLength != 0) { $this->text = \humhub\libs\Helpers::truncateText($this->text, $this->maxLength); } $output = nl2br($this->text); $this->trigger(self::EVENT_BEFORE_OUTPUT, new ParameterEvent(['output' => &$output])); return $output; }
/** * Deletes OEmbed Provider */ public function actionOembedDelete() { $this->forcePostRequest(); $prefix = Yii::$app->request->get('prefix'); $providers = UrlOembed::getProviders(); if (isset($providers[$prefix])) { unset($providers[$prefix]); UrlOembed::setProviders($providers); } return Yii::$app->response->redirect(Url::toRoute('/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; }
public function run() { if ($this->encode) { $this->text = Html::encode($this->text); } if (!$this->minimal) { $maxOembedCount = 3; // Maximum OEmbeds $oembedCount = 0; // OEmbeds used $that = $this; $pattern = <<<REGEXP /(?(R) # in case of recursion match parentheses \t\t\t\t \\(((?>[^\\s()]+)|(?R))*\\) \t\t\t| # else match a link with title \t\t\t\t(https?|ftp):\\/\\/(([^\\s()]+)|(?R))+(?<![\\.,:;\\'"!\\?\\s]) \t\t\t)/x REGEXP; $this->text = preg_replace_callback($pattern, function ($match) use(&$oembedCount, &$maxOembedCount, &$that) { // Try use oembed if ($maxOembedCount > $oembedCount) { $oembed = UrlOembed::GetOembed($match[0]); if ($oembed) { $oembedCount++; return $oembed; } } return Html::a($match[0], Html::decode($match[0]), array('target' => '_blank')); }, $this->text); // mark emails $this->text = preg_replace_callback('/[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*(\\.[a-zA-Z]{2,3})/', function ($match) { return Html::mailto($match[0]); }, $this->text); } // get user and space details from guids $this->text = self::translateMentioning($this->text, $this->minimal ? false : true); // create image tag for emojis $this->text = self::translateEmojis($this->text, $this->minimal ? false : true); if ($this->maxLength != 0) { $this->text = \humhub\libs\Helpers::truncateText($this->text, $this->maxLength); } $this->text = trim($this->text); if (!$this->minimal) { $output = nl2br($this->text); } else { $output = $this->text; } // replace leading spaces with no break spaces to keep the text format $output = preg_replace_callback('/^( +)/m', function ($m) { return str_repeat(" ", strlen($m[1])); }, $output); $this->trigger(self::EVENT_BEFORE_OUTPUT, new ParameterEvent(['output' => &$output])); return trim($output); }