Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * 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);
 }