コード例 #1
0
ファイル: functions.php プロジェクト: h3len/Project
/**
 * 验证text中搜含有用户名,是否含有话题,链接地址,并替换标签
 * @param $text 点滴内容
 * @return $text
 */
function hg_verify($text)
{
    $text = stripcslashes($text);
    $pattern = "/@([\\x{4e00}-\\x{9fa5}0-9A-Za-z_-]+)[\\s::,,.。\\'‘’\"“”、!!]/iu";
    //这里牵扯到用户名命名规则问题
    if (preg_match_all($pattern, $text . " ", $username)) {
        foreach ($username[1] as $value) {
            $nameH = '@' . $value;
            $names = '<a href="' . SNS_UCENTER . USER_URL . '?name=' . $value . '" target="_blank">' . $nameH . '</a>';
            $text = str_replace($nameH, $names, $text);
        }
    }
    $pattern = "/#([\\x{4e00}-\\x{9fa5}0-9A-Za-z_-‘’“”'\"]+)[\\s#]/iu";
    //		$pattern = "/#(.+)[\s#]/iu";
    //这里牵扯到话题规则问题
    if (preg_match_all($pattern, $text, $topic)) {
        foreach ($topic[1] as $key => $value) {
            $nameH = '#' . $value . '#';
            $names = '<a href="' . SNS_MBLOG . TOPIC_URL . '?q=' . $value . '">' . $nameH . '</a>';
            $text = str_replace($nameH, $names, $text);
        }
    }
    //超链接替换
    $pattern = "((((f|ht){1}tp|ftp|gopher|news|telnet|rtsp|mms)://|www\\.)[-a-zA-Z0-9@:%_\\+.~#?&//=]+)";
    $match = hg_match_links($text);
    if ($match) {
        $match = $match['all'];
        foreach ($match as $key => $value) {
            $key = "key_" . $key;
            $text = str_replace($value, $key, $text);
        }
        if (preg_match_all($pattern, $text, $url)) {
            foreach ($url[0] as $value) {
                $urls = '<a href="' . $value . '" target="_blank">' . $value . '</a>';
                $text = str_replace($value, $urls, $text);
            }
        }
        foreach ($match as $key => $value) {
            $key = "key_" . $key;
            $text = str_replace($key, $value, $text);
        }
    } else {
        if (preg_match_all($pattern, $text, $url)) {
            foreach ($url[0] as $value) {
                $urls = '<a href="' . $value . '" target="_blank">' . $value . '</a>';
                $text = str_replace($value, $urls, $text);
            }
        }
    }
    global $gGlobalConfig;
    $faces = $gGlobalConfig['smile_face'];
    foreach ($faces as $fk => $fv) {
        $f_pattern = "/\\:em" . $fk . "_(.*)\\:/Ui";
        preg_match_all($f_pattern, $text, $show);
        $facelist = hg_readdir($fv['dir']);
        if ($show[0]) {
            foreach ($show[1] as $key => $value) {
                $face[] = '<img alt="" src="' . $fv['url'] . $facelist[$value] . '"/>';
            }
            foreach ($show[0] as $k => $v) {
                $keys[] = "/" . $v . "/";
            }
            $text = preg_replace($keys, $face, $text);
        }
    }
    return $text;
}
コード例 #2
0
ファイル: user_dialog.tpl.php プロジェクト: h3len/Project
    echo $num;
    ?>
,'face_');" style="cursor:pointer;"><?php 
    echo $nv;
    ?>
</li>
														<?php 
    $j++;
}
?>
													</ul>
													<?php 
$face = $this->settings['smile_face'];
$i = 1;
foreach ($face as $fk => $fv) {
    $facelist = hg_readdir($fv['dir']);
    $style = "";
    if ($i > 1) {
        $style = ' style="display:none"';
    }
    ?>
											       		<ul id="face_<?php 
    echo $i;
    ?>
" <?php 
    echo $style;
    ?>
 style="clear: both;width:316px;">
														<?php 
    foreach ($facelist as $lk => $lv) {
        ?>