예제 #1
0
/**
 * @desc Prepare the string (add the a to the links and show the smileys)
 *
 * @param string $string
 * @param boolean display large emojis
 * @param check the links and convert them to pictures (heavy)
 * @return string
 */
function prepareString($string, $large = false, $preview = false)
{
    $string = addUrls($string, $preview);
    // We remove all the style attributes
    $string = preg_replace_callback('/(<[^>]+) style=".*?"/i', function ($match) {
        return $match[1];
    }, $string);
    // Twitter hashtags
    $string = preg_replace_callback("/ #[a-zA-Z0-9_-]{3,}/", function ($match) {
        return ' <a class="twitter hastag" href="http://twitter.com/search?q=' . urlencode(trim($match[0])) . '&src=hash" target="_blank">' . trim($match[0]) . '</a>';
    }, ' ' . $string);
    $string = preg_replace_callback("/ @[a-zA-Z0-9_-]{3,}/", function ($match) {
        return ' <a class="twitter at" href="http://twitter.com/' . trim($match[0]) . '" target="_blank">' . trim($match[0]) . '</a>';
    }, ' ' . $string);
    //remove all scripts
    $string = preg_replace_callback('#<[/]?script[^>]*>#is', function ($match) {
        return '';
    }, ' ' . $string);
    //remove all iframe
    $string = preg_replace_callback('#<[/]?iframe[^>]*>#is', function ($match) {
        return '';
    }, ' ' . $string);
    //remove all iframe
    $string = preg_replace_callback('#<[/]?ss[^>]*>#is', function ($match) {
        return '';
    }, ' ' . $string);
    // We add some smileys...
    $emoji = MovimEmoji::getInstance();
    $string = $emoji->replace($string, $large);
    return trim($string);
}
예제 #2
0
파일: StringHelper.php 프로젝트: Trim/movim
/**
 * @desc Prepare the string (add the a to the links and show the smileys)
 *
 * @param string $string
 * @param boolean display large emojis
 * @param check the links and convert them to pictures (heavy)
 * @return string
 */
function prepareString($string, $large = false, $preview = false)
{
    // Add missing links
    $string = preg_replace_callback("/([\\w\"'>]+\\:\\/\\/[\\w-?&;#+%:~=\\.\\/\\@]+[\\w\\/])/", function ($match) use($preview) {
        if (!in_array(substr($match[0], 0, 1), array('>', '"', '\''))) {
            $content = $match[0];
            if ($preview) {
                try {
                    $embed = Embed\Embed::create($match[0]);
                    if ($embed->type == 'photo' && $embed->images[0]['width'] <= 1024 && $embed->images[0]['height'] <= 1024) {
                        $content = '<img src="' . $match[0] . '"/>';
                    } elseif ($embed->type == 'link') {
                        $content .= ' - ' . $embed->title . ' - ' . $embed->providerName;
                    }
                } catch (Exception $e) {
                    error_log($e->getMessage());
                }
            }
            return stripslashes('<a href=\\"' . $match[0] . '\\" target=\\"_blank\\">' . $content . '</a>');
        } else {
            return $match[0];
        }
    }, $string);
    // We remove all the style attributes
    $string = preg_replace_callback('/(<[^>]+) style=".*?"/i', function ($match) {
        return $match[1];
    }, $string);
    // Twitter hashtags
    $string = preg_replace_callback("/ #[a-zA-Z0-9_-]{3,}/", function ($match) {
        return ' <a class="twitter hastag" href="http://twitter.com/search?q=' . urlencode(trim($match[0])) . '&src=hash" target="_blank">' . trim($match[0]) . '</a>';
    }, ' ' . $string);
    $string = preg_replace_callback("/ @[a-zA-Z0-9_-]{3,}/", function ($match) {
        return ' <a class="twitter at" href="http://twitter.com/' . trim($match[0]) . '" target="_blank">' . trim($match[0]) . '</a>';
    }, ' ' . $string);
    //remove all scripts
    $string = preg_replace_callback('#<[/]?script[^>]*>#is', function ($match) {
        return '';
    }, ' ' . $string);
    //remove all iframe
    $string = preg_replace_callback('#<[/]?iframe[^>]*>#is', function ($match) {
        return '';
    }, ' ' . $string);
    //remove all iframe
    $string = preg_replace_callback('#<[/]?ss[^>]*>#is', function ($match) {
        return '';
    }, ' ' . $string);
    // We add some smileys...
    $emoji = MovimEmoji::getInstance();
    $string = $emoji->replace($string, $large);
    return trim($string);
}
예제 #3
0
파일: Message.php 프로젝트: Anon215/movim
 public function convertEmojis()
 {
     $emoji = \MovimEmoji::getInstance();
     $this->body = addHFR($emoji->replace($this->body));
 }
예제 #4
0
파일: Api.php 프로젝트: Anon215/movim
 public function addEmojis($post)
 {
     $string = $post['string'];
     $emoji = \MovimEmoji::getInstance();
     return $emoji->replace($string);
 }