Пример #1
1
 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 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;
 }
Пример #3
-1
    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("&nbsp;", strlen($m[1]));
        }, $output);
        $this->trigger(self::EVENT_BEFORE_OUTPUT, new ParameterEvent(['output' => &$output]));
        return trim($output);
    }