示例#1
0
文件: Posts.php 项目: ph7pal/naodong
 /**
  * 处理内容
  * @param type $content
  * @return type
  */
 public static function handleContent($content)
 {
     $pattern = "/<[img|IMG].*?data=[\\'|\"](.*?)[\\'|\"].*?[\\/]?>/i";
     preg_match_all($pattern, $content, $match);
     $arr_attachids = array();
     if (!empty($match[0])) {
         $arr = array();
         foreach ($match[0] as $key => $val) {
             $_key = $match[1][$key];
             $arr[$_key] = $val;
             $arr_attachids[] = $match[1][$key];
         }
         if (!empty($arr)) {
             foreach ($arr as $thekey => $imgsrc) {
                 $content = str_ireplace("{$imgsrc}", '[attach]' . $thekey . '[/attach]', $content);
             }
         }
     }
     $content = strip_tags($content, '<b><strong><em><span><a><p><u><i><img><br><br/>');
     $replace = array('/<a.*?href="(.*?)".*?>(.+?)<\\/a>/ie', '/(((http|https):\\/\\/)[a-z0-9;&#@=_~%\\?\\/\\.\\,\\+\\-\\!\\:]+)/ie', "/style=\"[^\"]*?\"/i");
     $to = array("self::autoUrl('\\1','\\2')", "self::textUrl('\\1')", '');
     $content = preg_replace($replace, $to, $content);
     if (zmf::config('checkBadWords')) {
         $h_style = zmf::config("badwordsHandleStyle");
         //仅过滤
         if ($h_style === 'filter') {
             $content = zmf::badWordsReplace($content);
             //仅通知 过滤通知
         } elseif ($h_style === 'notice' or $h_style === 'filterNotice') {
             $status = Yii::app()->session['checkHasBadword'];
             if ($status != 'yes') {
                 $keywords = zmf::getBadwords();
                 foreach ($keywords as $word) {
                     if (mb_strpos($content, $word) !== false) {
                         Yii::app()->session['checkHasBadword'] = 'yes';
                     }
                 }
             }
             if ($h_style === 'filterNotice') {
                 $content = zmf::badWordsReplace($content);
             }
         }
     }
     $data = array('content' => $content, 'attachids' => $arr_attachids);
     return $data;
 }