function t($text) { //过滤标签 $text = nl2br($text); $text = real_strip_tags($text); $text = addslashes($text); $text = trim($text); return addslashes($text); }
function wapFormatComment($content, $url = false, $from_url = '') { $content = real_strip_tags($content); if ($url) { $content = preg_replace('/((?:https?|ftp):\\/\\/(?:www\\.)?(?:[a-zA-Z0-9][a-zA-Z0-9\\-]*\\.)?[a-zA-Z0-9][a-zA-Z0-9\\-]*(?:\\.[a-zA-Z]+)+(?:\\:[0-9]*)?(?:\\/[^\\x{2e80}-\\x{9fff}\\s<\'\\"“”‘’]*)?)/ue', "'<a class=\"c_a\" href=\"'.U('w3g/Index/urlalert').'&from_url={$from_url}&url='.urlencode('\\1').'\">\\1</a>\\2'", $content); } $content = preg_replace_callback("/(?:#[^#]*[^#^\\s][^#]*#|(\\[.+?\\]))/is", replaceEmot, $content); $content = preg_replace_callback("/@([\\w\\x{2e80}-\\x{9fff}\\-]+)/u", wapFormatUser, $content); return $content; }
/** * t函数用于过滤标签,输出没有html的干净的文本 * @param string text 文本内容 * @return string 处理后内容 */ function tt($text) { $text = nl2br($text); $text = real_strip_tags($text); $text = addslashes($text); $text = trim($text); return $text; }
/** * h函数用于过滤不安全的html标签,输出安全的html * @param string $text 待过滤的字符串 * @param string $type 保留的标签格式 * @return string 处理后内容 */ function op_h($text, $type = 'html') { // 无标签格式 $text_tags = ''; //只保留链接 $link_tags = '<a>'; //只保留图片 $image_tags = '<img>'; //只存在字体样式 $font_tags = '<i><b><u><s><em><strong><font><big><small><sup><sub><bdo><h1><h2><h3><h4><h5><h6>'; //标题摘要基本格式 $base_tags = $font_tags . '<p><br><hr><a><img><map><area><pre><code><q><blockquote><acronym><cite><ins><del><center><strike>'; //兼容Form格式 $form_tags = $base_tags . '<form><input><textarea><button><select><optgroup><option><label><fieldset><legend>'; //内容等允许HTML的格式 $html_tags = $base_tags . '<ul><ol><li><dl><dd><dt><table><caption><td><th><tr><thead><tbody><tfoot><col><colgroup><div><span><object><embed><param>'; //专题等全HTML格式 $all_tags = $form_tags . $html_tags . '<!DOCTYPE><meta><html><head><title><body><base><basefont><script><noscript><applet><object><param><style><frame><frameset><noframes><iframe>'; //过滤标签 $text = real_strip_tags($text, ${$type . '_tags'}); // 过滤攻击代码 if ($type != 'all') { // 过滤危险的属性,如:过滤on事件lang js while (preg_match('/(<[^><]+)(ondblclick|onclick|onload|onerror|unload|onmouseover|onmouseup|onmouseout|onmousedown|onkeydown|onkeypress|onkeyup|onblur|onchange|onfocus|action|background|codebase|dynsrc|lowsrc)([^><]*)/i', $text, $mat)) { $text = str_ireplace($mat[0], $mat[1] . $mat[3], $text); } while (preg_match('/(<[^><]+)(window\\.|javascript:|js:|about:|file:|document\\.|vbs:|cookie)([^><]*)/i', $text, $mat)) { $text = str_ireplace($mat[0], $mat[1] . $mat[3], $text); } } return $text; }
/** * 获取指定微博的信息,用于资源模型输出??? * @param integer $id 微博ID * @param boolean $forApi 是否提供API数据,默认为false * @return array 指定微博数据 */ public function getFeedInfo($id, $forApi = false) { $data = model('Cache')->get('feed_info_' . $id); if ($data !== false && ($forApi === false || $forApi === true && isset($data['iscoll']))) { return $data; } $map['a.feed_id'] = $id; // //过滤已删除的微博 wap 版收藏 // if($forApi){ // $map['a.is_del'] = 0; // } $data = $this->where($map)->table("{$this->tablePrefix}feed AS a LEFT JOIN {$this->tablePrefix}feed_data AS b ON a.feed_id = b.feed_id ")->find(); $fd = unserialize($data['feed_data']); $userInfo = model('User')->getUserInfo($data['uid']); $data['ctime'] = date('Y-m-d H:i', $data['publish_time']); $data['content'] = $forApi ? parseForApi($fd['body']) : $fd['body']; $data['uname'] = $userInfo['uname']; $data['user_group'] = $userInfo['api_user_group']; $data['avatar_big'] = $userInfo['avatar_big']; $data['avatar_middle'] = $userInfo['avatar_middle']; $data['avatar_small'] = $userInfo['avatar_small']; unset($data['feed_data']); // 微博转发 if ($data['type'] == 'repost') { $data['transpond_id'] = $data['app_row_id']; $data['transpond_data'] = $this->getFeedInfo($data['transpond_id'], $forApi); } // 附件处理 if (!empty($fd['attach_id'])) { $data['has_attach'] = 1; $attach = model('Attach')->getAttachByIds($fd['attach_id']); foreach ($attach as $ak => $av) { $_attach = array('attach_id' => $av['attach_id'], 'attach_name' => $av['name'], 'attach_url' => getImageUrl($av['save_path'] . $av['save_name']), 'extension' => $av['extension'], 'size' => $av['size']); if ($data['type'] == 'postimage') { $_attach['attach_small'] = getImageUrl($av['save_path'] . $av['save_name'], 100, 100, true); $_attach['attach_middle'] = getImageUrl($av['save_path'] . $av['save_name'], 550); } $data['attach'][] = $_attach; } } else { $data['has_attach'] = 0; } if ($data['type'] == 'postvideo') { $data['host'] = $fd['host']; $data['flashvar'] = $fd['flashvar']; $data['source'] = $fd['source']; $data['flashimg'] = $fd['flashimg']; $data['title'] = $fd['title']; } $data['feedType'] = $data['type']; // 是否收藏微博 if ($forApi) { $data['iscoll'] = model('Collection')->getCollection($data['feed_id'], 'feed'); if (empty($data['iscoll'])) { $data['iscoll']['colled'] = 0; } else { $data['iscoll']['colled'] = 1; } } // 微博详细信息 $feedInfo = $this->get($id); $data['source_body'] = $feedInfo['body']; $data['api_source'] = $feedInfo['api_source']; //一分钟缓存 model('Cache')->set('feed_info_' . $id, $data, 60); if ($forApi) { $data['content'] = real_strip_tags($data['content']); unset($data['is_audit'], $data['from_data'], $data['app_row_table'], $data['app_row_id']); unset($data['source_body']); } return $data; }
/** * 获取资源信息 --using * * @param * varchar app 应用名称 * @param * integer app_row_table 资源所在表 * @param * integer app_row_id 资源ID * @return array 资源信息 */ private function get_source_info($app, $app_row_table, $app_row_id) { switch ($app) { case 'weiba': $weiba_post = D('weiba_post')->where('post_id=' . $app_row_id . ' AND is_del = 0')->field('weiba_id,post_uid,title,content')->find(); if ($weiba_post) { $source_info['user_info'] = $this->get_user_info($weiba_post['post_uid']); $source_info['title'] = $weiba_post['title']; $source_info['content'] = real_strip_tags($weiba_post['content']); $source_info['url'] = 'mod=Weibo&act=weibo_detail&id=' . $app_row_id; $source_info['source_name'] = D('weiba')->where('weiba_id=' . $weiba_post['weiba_id'])->getField('weiba_name'); $source_info['source_url'] = 'api.php?mod=Weiba&act=post_detail&id=' . $app_row_id; $source_info['source_imgs'] = array(); //获取微吧转发的图片 if (!empty($app_row_id)) { $source_info['source_imgs'] = $this->getEditorImages($weiba_post['content']); } } else { $source_info['is_del'] = 1; } break; default: $tablePrefix = C('DB_PREFIX'); $map['a.feed_id'] = $app_row_id; $map['a.is_del'] = 0; $data = model('Feed')->where($map)->table("{$tablePrefix}feed AS a LEFT JOIN {$tablePrefix}feed_data AS b ON a.feed_id = b.feed_id ")->find(); if ($data['feed_id']) { $source_info['publish_time'] = $data['publish_time']; $source_info['feed_id'] = $app_row_id; $source_info['user_info'] = $this->get_user_info($data['uid']); $source_info['type'] = real_strip_tags($data['type']); $source_info['content'] = real_strip_tags($data['feed_content']); $source_info['content'] = parseForApi($source_info['content']); $source_info['url'] = 'mod=Weibo&act=weibo_detail&id=' . $app_row_id; // 附件处理 $feed_data = unserialize($data['feed_data']); if (!empty($feed_data['attach_id'])) { $attach = model('Attach')->getAttachByIds($feed_data['attach_id']); foreach ($attach as $ak => $av) { $_attach = array('attach_id' => $av['attach_id'], 'attach_name' => $av['name']); if ($data['type'] == 'postimage') { $_attach['attach_origin'] = getImageUrl($av['save_path'] . $av['save_name']); $_attach['attach_origin_width'] = $av['width']; $_attach['attach_origin_height'] = $av['height']; if ($av['width'] > 550 && $av['height'] > 550) { $_attach['attach_small'] = getImageUrl($av['save_path'] . $av['save_name'], 550, 550, true); } else { $_attach['attach_small'] = $_attach['attach_origin']; } } $source_info['attach_info'][] = $_attach; } } else { $source_info['attach_info'] = array(); } if ($data['type'] == 'postvideo') { if ($feed_data['video_id']) { $video_config = model('Xdata')->get('admin_Content:video_config'); $video_server = $video_config['video_server'] ? $video_config['video_server'] : SITE_URL; $video_info['video_id'] = $feed_data['video_id']; $video_info['flashimg'] = $video_server . $feed_data['image_path']; $video_info['flash_width'] = $feed_data['image_width']; $video_info['flash_height'] = $feed_data['image_height']; if ($feed_data['transfer_id'] && !D('video_transfer')->where('transfer_id=' . $feed_data['transfer_id'])->getField('status')) { $video_info['transfering'] = 1; } else { $video_info['flashvar'] = $feed_data['video_mobile_path'] ? $video_server . $feed_data['video_mobile_path'] : $video_server . $feed_data['video_path']; $video_info['flashvar_part'] = $video_server . $feed_data['video_part_path']; } } else { $video_info['host'] = $feed_data['host']; $video_info['flashvar'] = $feed_data['source']; $video_info['source'] = $feed_data['source']; $video_info['flashimg'] = UPLOAD_URL . $feed_data['flashimg']; $video_info['title'] = $feed_data['title']; } $source_info['attach_info'][] = $video_info; } } else { $source_info['is_del'] = 1; } break; } return $source_info; }
/** * getTaskShort * 截取task的长度 * @param mixed $content * @param mixed $length * @access public * @return void */ function getTaskShort($content, $length = 60) { $content = real_strip_tags($content); $content = getShort($content, $length); return $content; }
/** * 获取指定分享的信息,用于资源模型输出??? * @param integer $id 分享ID * @param boolean $forApi 是否提供API数据,默认为false * @return array 指定分享数据 */ public function getFeedInfo($id, $forApi = false) { $data = model('Cache')->get('feed_info_' . $id); if ($data !== false && ($forApi === false || $forApi === true && isset($data['iscoll']))) { return $data; } $map['a.feed_id'] = $id; // //过滤已删除的分享 wap 版收藏 // if($forApi){ // $map['a.is_del'] = 0; // } $data = $this->where($map)->table("{$this->tablePrefix}feed AS a LEFT JOIN {$this->tablePrefix}feed_data AS b ON a.feed_id = b.feed_id ")->find(); $fd = unserialize($data['feed_data']); $userInfo = model('User')->getUserInfo($data['uid']); $data['ctime'] = date('Y-m-d H:i', $data['publish_time']); $data['content'] = $forApi ? parseForApi($fd['body']) : $fd['body']; $data['uname'] = $userInfo['uname']; $data['user_group'] = $userInfo['api_user_group']; $data['user_gicon'] = $userInfo['group_icon_only']; $data['avatar_big'] = $userInfo['avatar_big']; $data['avatar_middle'] = $userInfo['avatar_middle']; $data['avatar_small'] = $userInfo['avatar_small']; unset($data['feed_data']); // 分享转发 if ($data['type'] == 'repost') { $data['transpond_id'] = $data['app_row_id']; $data['transpond_data'] = $this->getFeedInfo($data['transpond_id'], $forApi); } // 附件处理 if (!empty($fd['attach_id'])) { $data['has_attach'] = 1; $attach = model('Attach')->getAttachByIds($fd['attach_id']); foreach ($attach as $ak => $av) { $_attach = array('attach_id' => $av['attach_id'], 'attach_name' => $av['name'], 'attach_url' => getImageUrl($av['save_path'] . $av['save_name']), 'extension' => $av['extension'], 'size' => $av['size']); if ($data['type'] == 'postimage') { $_attach['attach_small'] = getImageUrl($av['save_path'] . $av['save_name'], 120, 120, true); $_attach['attach_medium'] = getImageUrl($av['save_path'] . $av['save_name'], 240); $_attach['attach_middle'] = getImageUrl($av['save_path'] . $av['save_name'], 740); $_attach['attach_middle_box'] = getImageUrl($av['save_path'] . $av['save_name'], 240, 240, true); } $data['attach'][] = $_attach; } } else { $data['has_attach'] = 0; } if ($data['type'] == 'postvideo') { if ($fd['video_id']) { $video_config = model('Xdata')->get('admin_Content:video_config'); $video_server = $video_config['video_server'] ? $video_config['video_server'] : SITE_URL; $data['video_id'] = $fd['video_id']; if ($forApi) { $data['flashvar'] = $fd['video_mobile_path'] ? $video_server . $fd['video_mobile_path'] : $video_server . $fd['video_path']; $data['flashvar_part'] = $video_server . $fd['video_part_path']; } else { $data['flashvar'] = $video_server . $fd['video_path']; } $data['flashimg'] = $video_server . $fd['image_path']; $data['flash_width'] = $fd['image_width']; $data['flash_height'] = $fd['image_height']; if ($fd['transfer_id'] && !D('video_transfer')->where('transfer_id=' . $fd['transfer_id'])->getField('status')) { $data['transfering'] = 1; } } else { $data['host'] = $fd['host']; if ($forApi) { $data['flashvar'] = $fd['source']; } else { $data['flashvar'] = $fd['flashvar']; } $data['source'] = $fd['source']; $data['flashimg'] = $fd['flashimg']; $data['title'] = $fd['title']; } } $data['feedType'] = $data['type']; // 是否收藏分享 if ($forApi) { $data['iscoll'] = model('Collection')->getCollection($data['feed_id'], 'feed'); if (empty($data['iscoll'])) { $data['iscoll']['colled'] = 0; } else { $data['iscoll']['colled'] = 1; } //是否赞过 $diggarr = model('FeedDigg')->checkIsDigg($data['feed_id'], $GLOBALS['ts']['mid']); $data['is_digg'] = $diggarr[$data['feed_id']] ? 1 : 0; } //获取赞过分享的人 $diggs = model('FeedDigg')->where("feed_id=" . $id)->order('id desc')->limit(10)->findAll(); foreach ($diggs as &$v) { $v['user'] = model('User')->getUserInfo($v['uid']); } $data['diggs'] = $diggs; // 分享详细信息 $feedInfo = $this->get($id); $data['source_body'] = $feedInfo['body']; $data['api_source'] = $feedInfo['api_source']; //一分钟缓存 model('Cache')->set('feed_info_' . $id, $data, 60); if ($forApi) { $data['content'] = real_strip_tags($data['content']); unset($data['is_audit'], $data['from_data'], $data['app_row_table'], $data['app_row_id']); unset($data['source_body']); } return $data; }