/** * 获取指定资源,并格式化输出 * @param string $table 资源表名 * @param integer $row_id 资源ID * @param boolean $_forApi 是否提供API,默认为false * @param string $appname 自定应用名称,默认为public * @return [type] [description] */ public function getSourceInfo($table, $row_id, $_forApi = false, $appname = 'public') { static $forApi = '0'; $forApi == '0' && ($forApi = intval($_forApi)); $key = $forApi ? $table . $row_id . '_api' : $table . $row_id; if ($info = static_cache('source_info_' . $key)) { return $info; } switch ($table) { case 'feed': $info = $this->getInfoFromFeed($table, $row_id, $_forApi); break; case 'comment': $info = $this->getInfoFromComment($table, $row_id, $_forApi); break; default: $modelArr = explode('_', $table); $model = ''; foreach ($modelArr as $v) { $model .= ucfirst($v); } // 单独的内容,通过此路径获取资源信息 if (file_exists(SITE_PATH . '/apps/' . $appname . '/Lib/Model/' . $model . 'Model.class.php')) { $info = D($model, $appname)->getSourceInfo($row_id, $_forApi); } break; } $info['source_table'] = $table; $info['source_id'] = $row_id; static_cache('source_info_' . $key, $info); return $info; }
/** * 获取用户可用的应用列表 * @param integer $uid 用户UID * @param integer $inweb 是否是Web端,默认为1 * @return array 用户可用的应用列表数据 */ public function getUserApp($uid, $inweb = 1) { // 默认应用 if ($appList = static_cache('userApp_uapp_' . $uid . '_' . $inweb)) { return $appList; } if (($appList = model('Cache')->get('userApp_uapp_' . $uid . '_' . $inweb)) === false) { $appList = array(); //$return = model('App')->getDefaultApp(); $imap['a.uid'] = $uid; $imap['a.inweb'] = intval($inweb); $imap['b.status'] = 1; $table = $this->tablePrefix . 'user_app AS a LEFT JOIN ' . $this->tablePrefix . 'app AS b ON a.app_id = b.app_id'; if ($list = $this->table($table)->where($imap)->field('a.app_id')->order('a.display_order ASC')->getAsFieldArray('app_id')) { foreach ($list as $v) { $appList[] = model('App')->getAppById($v); } } /* if(!empty($return)){ $appList = empty($appList) ? $return :array_merge($return,$appList); }*/ model('Cache')->set('userApp_uapp_' . $uid . '_' . $inweb, $appList, 120); } static_cache('userApp_uapp_' . $uid . '_' . $inweb, $appList); return $appList; }
/** * 通过单个附件ID获取其附件信息 * @param int $id 附件ID * @return array 指定附件ID的附件信息 */ public function getAttachById($id) { $id = intval($id); if (empty($id)) { return false; } $name = 'ts_attach_id_' . $id; $sc = S($name); if (!$sc) { // 获取静态缓存 $sc = static_cache('attach_infoHash_' . $id); if (!empty($sc)) { return $sc; } // 获取缓存 $sc = model('Cache')->get('Attach_' . $id); if (empty($sc)) { $map['attach_id'] = $id; $sc = $this->where($map)->find(); empty($sc) && ($sc = array()); model('Cache')->set('Attach_' . $id, $sc, 3600); } static_cache('attach_infoHash_' . $id, $sc); S($name, $sc); } return $sc; }
/** * 获取用户资料配置信息 - 不分页型 * @param array $map 查询条件 * @param string $order 排序条件 * @return array 用户资料配置信息 */ public function getUserProfileSetting($map = null, $order = 'field_key, display_order ASC') { $key = md5(implode("", $map) . $order); if ($setting = static_cache('profile_' . $key)) { return $setting; } $setting = $this->_getUserProfileSetting($map, $order); $setting = $this->_formatUserProfileSetting($setting); static_cache('profile_' . $key, $setting); return $setting; }
/** * 获取节点列表 * @return array 节点列表数据 */ public function getNodeList() { // 缓存处理 if ($list = static_cache('notify_node')) { return $list; } if (($list = model('Cache')->get('notify_node')) == false) { $list = $this->getHashList('node', '*'); model('Cache')->set('notify_node', $list); } static_cache('notify_node', $list); return $list; }
/** * 获取指定用户的备注列表 * @param integer $uid 用户ID * @return array 指定用户的备注列表 */ public function getRemarkHash($uid) { if (empty($uid)) { return false; } if ($list = static_cache('follow_remark_' . $uid)) { return $list; } $map['uid'] = $uid; $map['remark'] = array('NEQ', ''); $list = $this->where($map)->getHashList('fid', 'remark'); static_cache('follow_remark_' . $uid, $list); return $list; }
/** * 清除指定Game数据 * */ public function cleanCache($ids) { if (empty($ids)) { return false; } !is_array($ids) && ($ids = explode(',', $ids)); foreach ($ids as $id) { static_cache('master_info_' . $id, false); $keys = S('master_info_' . $id); foreach ($keys as $k) { S($k, null); } S('master_info_' . $id, null); } return true; }
/** * 返回解析空间地址 * @param integer $uid 用户ID * @param string $class 样式类 * @param string $target 是否进行跳转 * @param string $text 标签内的相关内容 * @param boolen $icon 是否显示用户组图标,默认为true * @return string 解析空间地址HTML */ function getUserSpace($uid, $class, $target, $text, $icon = true) { // 2.8转移 // 静态变量 static $_userinfo = array(); // 判断是否有缓存 if (!isset($_userinfo[$uid])) { $_userinfo[$uid] = model('User')->getUserInfo($uid); } // 配置相关参数 empty($target) && ($target = '_self'); empty($text) && ($text = $_userinfo[$uid]['uname']); // 判断是否存在替换信息 preg_match('|{(.*?)}|isU', $text, $match); if ($match) { if ($match[1] == 'uname') { $text = str_replace('{uname}', $_userinfo[$uid]['uname'], $text); //empty($class) && $class = 'username'; //2013/2/28 wanghaiquan empty($class) && ($class = 'name'); } else { preg_match("/{uavatar}|{uavatar\\=(.*?)}/e", $text, $face_type); switch ($face_type[1]) { case 'b': $userface = 'big'; break; case 'm': $userface = 'middle'; break; default: $userface = 'small'; break; } $face = $_userinfo[$uid]['avatar_' . $userface]; $text = '<img src="' . $face . '" />'; empty($class) && ($class = 'userface'); $icon = false; } } // 组装返回信息 $user_space_info = '<a event-node="face_card" uid="' . $uid . '" href="' . $_userinfo[$uid]['space_url'] . '" class="' . $class . '" target="' . $target . '">' . $text . '</a>'; // 用户认证图标信息 if ($icon) { $group_icon = array(); $user_group = static_cache('usergrouplink_' . $uid); if (!$user_group) { $user_group = model('UserGroupLink')->getUserGroupData($uid); static_cache('usergrouplink_' . $uid, $user_group); } // if(!empty($user_group)) { // foreach($user_group[$uid] as $value) { // $group_icon[] = '<img title="'.$value['user_group_name'].'" src="'.$value['user_group_icon_url'].'" class="space-group-icon" />'; // } // $user_space_info .= ' '.implode(' ', $group_icon); // } $union = model('Union')->getUnionState($GLOBALS['mid'], $uid); if ($union['unioning'] == 1 && $union['unioner'] == 1) { $user_space_info .= ' <img title="联盟" src="' . SITE_URL . '/addons/theme/stv1/_static/image/usergroup/union.png" class="space-group-icon" />'; } } return $user_space_info; }
/** * 获取指定用户的相关信息 * * @param array $map * 查询条件 * @return array 指定用户的相关信息 */ private function _getUserInfo($map, $field = "*") { $user = $this->getUserDataByCache($map, $field); unset($user['password']); if (!$user) { $this->error = L('PUBLIC_GET_INFORMATION_FAIL'); // 获取用户信息失败 return false; } else { $uid = $user['uid']; $user = array_merge($user, model('Avatar')->init($user['uid'])->getUserAvatar()); $user['avatar_url'] = U('public/Attach/avatar', array('uid' => $user["uid"])); $user['space_url'] = !empty($user['domain']) ? U('public/Profile/index', array('uid' => $user["domain"])) : U('public/Profile/index', array('uid' => $user["uid"])); $user['space_link'] = "<a href='" . $user['space_url'] . "' target='_blank' uid='{$user['uid']}' event-node='face_card'>" . $user['uname'] . "</a>"; $user['space_link_no'] = "<a href='" . $user['space_url'] . "' title='" . $user['uname'] . "' target='_blank'>" . $user['uname'] . "</a>"; // 用户勋章 $user['medals'] = model('Medal')->getMedalByUid($user['uid']); // 用户认证图标 $groupIcon = array(); $userGroup = model('UserGroupLink')->getUserGroupData($uid); $user['user_group'] = $userGroup[$uid]; foreach ($userGroup[$uid] as $value) { $groupIcon[] = '<img title="' . $value['user_group_name'] . '" src="' . $value['user_group_icon_url'] . '" style="width:auto;height:auto;display:inline;cursor:pointer;" />'; } $user['group_icon'] = implode(' ', $groupIcon); model('Cache')->set('ui_' . $uid, $user, 600); static_cache('user_info_' . $uid, $user); return $user; } }
/** * 获取评论信息 * @param integer $id 评论ID * @param boolean $source 是否显示资源信息,默认为true * @return array 获取评论信息 */ public function getCommentInfo($id, $source = true) { $id = intval($id); if (empty($id)) { $this->error = L('PUBLIC_WRONG_DATA'); // 错误的参数 return false; } if ($info = static_cache('comment_info_' . $id)) { return $info; } $map['comment_id'] = $id; $info = $this->where($map)->find(); $info['user_info'] = model('User')->getUserInfo($info['uid']); $info['content'] = $info['content']; /* 解析出emoji */ $info['content'] = formatEmoji(false, $info['content']); $source && ($info['sourceInfo'] = model('Source')->getCommentSource($info)); static_cache('comment_info_' . $id, $info); return $info; }
/** * 返回缓存数据操作,方法中,将数据缓存到静态缓存中 * @param mix $data 缓存数据 * @param string $key 缓存Key值 * @return mix 缓存数据 */ private function _returnData($data, $key) { // TODO:可以在此对空值进行处理判断 static_cache('cache_' . $key, $data); return $data; }
/** * 获取评论信息 * @param integer $id 评论ID * @param boolean $source 是否显示资源信息,默认为true * @return array 获取评论信息 */ public function getCommentInfo($id, $source = true) { if (empty($id)) { $this->error = L('PUBLIC_WRONG_DATA'); // 错误的参数 return false; } if ($info = static_cache('comment_info_' . $id)) { return $info; } $map['comment_id'] = $id; $info = $this->where($map)->find(); $info['user_info'] = model('User')->getUserInfo($info['uid']); //$info['content'] = parse_html($info['content']); $info['content'] = $info['content']; // 2012/12/7修改 $source && ($info['sourceInfo'] = model('Source')->getSourceInfo($info['table'], $info['row_id'], false, $info['app'])); static_cache('comment_info_' . $id, $info); return $info; }
/** * 将用户的UID转换为三级路径 * @param integer $uid 用户UID * @return string 用户路径 */ public function convertUidToPath($uid) { // 静态缓存 $sc = static_cache('avatar_uidpath_' . $uid); if (!empty($sc)) { return $sc; } $md5 = md5($uid); $sc = '/' . substr($md5, 0, 2) . '/' . substr($md5, 2, 2) . '/' . substr($md5, 4, 2); static_cache('avatar_uidpath_' . $uid, $sc); return $sc; }
/** * 获取指定用户的相关信息 * * @param array $map * 查询条件 * @return array 指定用户的相关信息 */ private function _getUserInfo(array $map, $field = '*') { $user = $this->getUserDataByCache($map, $field); unset($user['password']); if (!$user) { $this->error = L('PUBLIC_GET_INFORMATION_FAIL'); // 获取用户信息失败 return false; } else { $uid = $user['uid']; $user = array_merge($user, model('Avatar')->init($user['uid'])->getUserAvatar()); $user['avatar_url'] = U('public/Attach/avatar', array('uid' => $user["uid"])); $user['space_url'] = !empty($user['domain']) ? U('public/Profile/index', array('uid' => $user["domain"])) : U('public/Profile/index', array('uid' => $user["uid"])); $user['space_link'] = "<a href='" . $user['space_url'] . "' target='_blank' uid='{$user['uid']}' event-node='face_card'>" . $user['uname'] . "</a>"; $user['space_link_no'] = "<a href='" . $user['space_url'] . "' title='" . $user['uname'] . "' target='_blank'>" . $user['uname'] . "</a>"; // 用户勋章 $user['medals'] = model('Medal')->getMedalByUid($user['uid']); // 用户认证图标 $groupIcon = $authIcon = array(); $aIcon[5] = '<i class="type-trade"></i>'; $aIcon[6] = '<i class="type-hangjia"></i>'; $aIcon[7] = '<i class="type-daren"></i>'; $userGroup = model('UserGroupLink')->getUserGroupData($uid); $user['api_user_group'] = $userGroup[$uid]; $user['user_group'] = $userGroup[$uid]; $only = array(array(), array()); // $authenticate = array(); foreach ($userGroup[$uid] as $value) { ($value['user_group_id'] == 5 || $value['user_group_id'] == 6) && ($value['company'] = M('user_verified')->where("uid={$uid} and usergroup_id=" . $value['user_group_id'])->getField('company')); if ($value['is_authenticate'] == 1) { $authIcon[] = $aIcon[$value['user_group_id']]; $authenticate[$value['user_group_id']] = $value; } $groupIcon[] = '<img title="' . $value['user_group_name'] . '" src="' . $value['user_group_icon_url'] . '" style="width:auto;height:auto;display:inline;cursor:pointer;" />'; $type = $value['is_authenticate'] ? 1 : 0; if (empty($only[$type])) { $only[$type] = $value; } elseif ($only[$type]['ctime'] < $value['ctime']) { $only[$type] = $value; } } if (!empty($only[0])) { $user['group_icon_only'] = $only[0]; } elseif (!empty($only[1])) { $user['group_icon_only'] = $only[1]; } else { $user['group_icon_only'] = array(); } /*group_icon_only end*/ $user['group_icon'] = implode(' ', $groupIcon); //$user ['auth_icon'] = implode ( ' ', $authIcon ); $user['credit_info'] = model('Credit')->getUserCredit($uid); model('Cache')->set('ui_' . $uid, $user, 600); static_cache('user_info_' . $uid, $user); return $user; } }
/** * 通过指定用户组ID获取用户组信息 * @param string|array $gids 用户组ID * @return array 指定用户组ID获取用户组信息 */ public function getUserGroupByGids($gids) { $data = static_cache('UserGroupByGid' . implode(',', $gids)); if ($data) { return $data; } !is_array($gids) && ($gids = explode(',', $gids)); if (empty($gids)) { return false; } $map['user_group_id'] = array('IN', $gids); $data = $this->where($map)->findAll(); static_cache('UserGroupByGid' . implode(',', $gids), $data); return $data; }
# }}} # STYLE_URL_FORM {{{ # The default value for $STYLE_URL_FORM is to be completely blank. Add entries # as you please. global $STYLE_URL_FORM; $STYLE_URL_FORM = array(); # }}} # CSS STATIC CONTENT {{{ # CSS MAIN {{{ if (QUERY_STRING == 'css_main') { header('Content-Type: text/css'); static_cache(); foreach ($STYLE as $id => $style) { echo "{$id} {{$style}}\n\n"; } echo ".display_none { display: none !important; }\n"; echo ".display_tr { display: table-row !important; }\n"; exit; } # }}} # CSS URL FRAME {{{ if (QUERY_STRING == 'css_url_frame') { header('Content-Type: text/css'); static_cache(); foreach ($STYLE_URL_FORM as $id => $style) { echo "{$id} {{$style}}\n\n"; } exit; } # }}} # }}}
public static function parseWapAtByUname($name) { $info = static_cache("user_info_uname_" . $name[1]); if (!$info) { $info = model("User")->getUserInfoByName($name[1]); if (!$info) { $info = 1; } static_cache("user_info_uname_" . $name[1], $info); } if ($info && $info["is_active"] && $info["is_audit"] && $info["is_init"]) { return "<a href=\"" . u("wap/Index/weibo", array("uid" => $info["uid"])) . "\" >" . $name[0] . "</a>"; } else { return $name[0]; } }
/** * 获取系统默认配置应用列表 * * @return array 系统默认应用列表 */ public function getDefaultApp() { // 获取静态缓存 $list = static_cache('app_defaultapp'); if (!empty($list)) { return $list; } // 获取缓存 $list = model('Cache')->get('defaultApp'); if (empty($list)) { $map['status'] = 1; $list = $this->where($map)->field('app_id')->findAll(); if (empty($list)) { $list = array(); } else { $list = $this->getInfoByList($list); } model('Cache')->set('defaultApp', $list); } static_cache('app_defaultapp', $list); return $list; }
/** * 获取评论列表,已在后台被使用 * @param array $map 查询条件 * @param string $order 排序条件,默认为comment_id ASC * @param integer $limit 结果集数目,默认为10 * @param boolean $isReply 是否显示回复信息 * @return array 评论列表信息 */ public function getCommentList($map = null, $order = 'reply_id ASC', $limit = 10, $isReply = false) { !isset($map['is_del']) && ($map['is_del'] = 0); $data = D('weiba_reply')->where($map)->order($order)->findPage($limit); // dump($data);exit; foreach ($data['data'] as $k => &$v) { $v['user_info'] = model('User')->getUserInfo($v['uid']); $groupData = static_cache('groupdata' . $v['uid']); if (!$groupData) { $groupData = model('UserGroupLink')->getUserGroupData($v['uid']); if (!$groupData) { $groupData = 1; } static_cache('groupdata' . $v['uid'], $groupData); } $v['user_info']['groupData'] = $groupData; //获取用户组信息 $v['content'] = parse_html($v['content'] . $v['replyInfo']); $v['sourceInfo'] = model('Source')->getCommentSource($v); //$v['data'] = unserialize($v['data']); $order = strtolower($order); if (strpos($order, 'desc')) { $v['storey'] = $data['count'] - $k - ($data['nowPage'] - 1) * $limit; } else { $v['storey'] = $k + 1 + ($data['nowPage'] - 1) * $limit; } } return $data; }
/** * 获取指定资源,并格式化输出 * * @param string $table * 资源表名 * @param int $row_id * 资源ID * @param bool $_forApi * 是否提供API,默认为false * @param string $appname * 自定应用名称,默认为public * @return [type] [description] */ public function getSourceInfo($table, $row_id, $_forApi = false, $appname = 'public') { static $forApi = '0'; $forApi == '0' && ($forApi = intval($_forApi)); $key = $forApi ? $table . $row_id . '_api' : $table . $row_id; if ($info = static_cache('source_info_' . $key)) { return $info; } switch ($table) { case 'feed': $info = $this->getInfoFromFeed($table, $row_id, $_forApi); break; case 'comment': $info = $this->getInfoFromComment($table, $row_id, $_forApi); break; case 'poster': $poster = D('poster')->where('id=' . $row_id)->field('title,uid,pid')->find(); $info['title'] = $poster['title']; $info['source_user_info'] = model('User')->getUserInfo($poster['uid']); $info['source_url'] = U('poster/Index/posterDetail', array('id' => $row_id)); $info['source_body'] = $poster['title'] . '<a class="ico-details" href="' . U('poster/Index/posterDetail', array('id' => $row_id)) . '"></a>'; $info['category_id'] = $poster['pid']; $info['category_name'] = D('poster_type')->where('id=' . $poster['pid'])->getField('name'); break; case 'event': $event = D('event')->where('id=' . $row_id)->field('title,uid,sTime,eTime,address,joinCount,attentionCount,coverId,feed_id')->find(); $info['source_user_info'] = model('User')->getUserInfo($event['uid']); $info['source_url'] = U('event/Index/eventDetail', array('id' => $row_id, 'uid' => $event['uid'])); $info['source_content'] = $info['source_user_info'] !== false ? '发表了一个活动' : '内容已被删除'; $info['source_body'] = $event['title'] . '<a class="ico-details" href="' . U('event/Index/eventDetail', array('id' => $row_id, 'uid' => $event['uid'])) . '"></a>'; $info['title'] = $event['title']; $info['feed_id'] = $event['feed_id']; $info['start_time'] = $event['sTime']; $info['end_time'] = $event['eTime']; $info['address'] = $event['address']; $info['join_count'] = $event['joinCount']; $info['attention_count'] = $event['attentionCount']; if (empty($event['coverId'])) { $info['pic_url_small'] = THEME_PUBLIC_URL . '/image/event.png'; $info['pic_url'] = THEME_PUBLIC_URL . '/image/event.png'; } else { $attach = model('Attach')->getAttachById($event['coverId']); $info['pic_url_small'] = getImageUrl($attach['save_path'] . $attach['save_name'], 100, 100, true); $info['pic_url'] = getImageUrl($attach['save_path'] . $attach['save_name'], 200, 200, true); } break; case 'blog': $blog = D('blog')->where('id=' . $row_id . ' AND `status` = 1')->field('title,category,uid,content,feed_id')->find(); $info['source_user_info'] = model('User')->getUserInfo($blog['uid']); $info['source_url'] = U('blog/Index/show', array('id' => $row_id, 'mid' => $blog['uid'])); $info['source_content'] = $info['source_user_info'] !== false ? '发表了一篇知识' : '内容已被删除'; $info['source_body'] = $blog['title'] . '<a class="ico-details" href="' . U('blog/Index/show', array('id' => $row_id, 'mid' => $blog['uid'])) . '"></a>'; $info['title'] = $blog['title']; $info['content'] = strip_tags($blog['content']); $info['feed_id'] = $blog['feed_id']; $info['category_id'] = $blog['category']; $info['category_name'] = D('blog_category')->where('id=' . $blog['category'])->getField('name'); // 获取编辑器中的图片内容 $editorImage = $this->getEditorImages($blog['content']); $info['pic_url_small'] = $editorImage['pic_url_small']; $info['pic_url'] = $editorImage['pic_url']; break; case 'photo': $photo = D('photo')->where('id=' . $row_id)->field('name, albumId, userId, savepath, feed_id')->find(); $info['source_user_info'] = model('User')->getUserInfo($photo['userId']); $info['source_url'] = U('photo/Index/photo', array('id' => $row_id, 'aid' => $photo['albumId'], 'uid' => $photo['userId'])); $uploadCount = D('photo')->where('feed_id=' . $photo['feed_id'])->count(); $info['photo_upload_count'] = $uploadCount; $info['source_content'] = $info['source_user_info'] !== false ? '上传了' . $uploadCount . '张照片' : '内容已被删除'; $info['source_body'] = $photo['name'] . '<a class="ico-details" href="' . $info['source_url'] . '"></a>'; $album = D('photo_album')->where('id=' . $photo['albumId'])->find(); $info['title'] = $album['name']; $info['feed_id'] = $photo['feed_id']; $info['photo_count'] = $album['photoCount']; $info['cover_image_path_small'] = getImageUrl($photo['savepath'], 100, 100, true); $info['cover_image_path'] = getImageUrl($photo['savepath'], 200, 200, true); $info['album_url'] = U('photo/Index/album', array('uid' => $photo['userId'], 'id' => $photo['albumId'])); break; case 'vote': $vote = D('vote')->where('id=' . $row_id)->field('title, uid, vote_num, cTime,feed_id')->find(); $info['source_user_info'] = model('User')->getUserInfo($vote['uid']); $info['source_url'] = U('vote/Index/pollDetail', array('id' => $row_id)); $info['source_content'] = $info['source_user_info'] !== false ? '发表了一个投票' : '内容已被删除'; $info['source_body'] = $vote['title'] . '<a class="ico-details" href="' . U('vote/Index/pollDetail', array('id' => $row_id)) . '"></a>'; $info['feed_id'] = $vote['feed_id']; $voteOpts = D('VoteOpt')->where('vote_id=' . $row_id)->order('id ASC')->findAll(); $info['vote_opts'] = $voteOpts; $info['title'] = $vote['title']; $info['ctime'] = $vote['cTime']; $info['vote_num'] = $vote['vote_num']; break; case 'develop': $develop = D('develop')->where('develop_id=' . $row_id)->field('title, uid')->find(); $info['source_user_info'] = model('User')->getUserInfo($develop['uid']); $info['source_url'] = U('develop/Index/detail', array('id' => $row_id)); $info['source_body'] = $develop['title'] . '<a class="ico-details" href="' . U('develop/Index/detail', array('id' => $row_id)) . '"></a>'; break; case 'weiba_post': $weiba = D('weiba_post')->where('post_id=' . $row_id . ' AND is_del = 0')->field('weiba_id, post_uid, title, content,feed_id,post_time')->find(); $info['publish_time'] = $weiba['post_time']; $info['source_user_info'] = model('User')->getUserInfo($weiba['post_uid']); $info['source_url'] = U('weiba/Index/postDetail', array('post_id' => $row_id)); $info['source_content'] = $info['source_user_info'] !== false ? '发表了一个帖子' : '内容已被删除'; $info['source_body'] = $weiba['title'] . '<a class="ico-details" href="' . U('weiba/Index/postDetail', array('post_id' => $row_id)) . '"></a>'; $info['title'] = $weiba['title']; $info['content'] = trim(strip_tags($weiba['content'])); $info['feed_id'] = $weiba['feed_id']; $info['weiba_name'] = D('weiba')->where('weiba_id=' . $weiba['weiba_id'])->getField('weiba_name'); $info['weiba_url'] = U('weiba/Index/detail', array('weiba_id' => $weiba['weiba_id'])); // 获取编辑器中的图片内容 $editorImage = $this->getEditorImages($weiba['content']); $info['pic_url_small'] = $editorImage['pic_url_small']; $info['pic_url_medium'] = $editorImage['pic_url_medium']; $info['pic_url'] = $editorImage['pic_url']; break; default: // 单独的内容,通过此路径获取资源信息 // 通过应用下的{$appname}ProtocolModel.Class.php模型里的getSourceInfo方法,来写各应用的来源数据获取方法 $appname = strtolower($appname); $name = ucfirst($appname); $dao = D($name . 'Protocol', $appname, false); if (method_exists($dao, 'getSourceInfo')) { $info = $dao->getSourceInfo($row_id, $_forApi); } unset($dao); // 兼容旧方案 if (!$info) { $modelArr = explode('_', $table); $model = ''; foreach ($modelArr as $v) { $model .= ucfirst($v); } $dao = D($model, $appname); if (method_exists($dao, 'getSourceInfo')) { $info = $dao->getSourceInfo($row_id, $_forApi); } } break; } $info['source_table'] = $table; $info['source_id'] = $row_id; static_cache('source_info_' . $key, $info); return $info; }
/** * 获取指定资源,并格式化输出 * * @param string $table * 资源表名 * @param integer $row_id * 资源ID * @param boolean $_forApi * 是否提供API,默认为false * @param string $appname * 自定应用名称,默认为public * @return [type] [description] */ public function getSourceInfo($table, $row_id, $_forApi = false, $appname = 'public') { static $forApi = '0'; $forApi == '0' && ($forApi = intval($_forApi)); $key = $forApi ? $table . $row_id . '_api' : $table . $row_id; if ($info = static_cache('source_info_' . $key)) { return $info; } switch ($table) { case 'feed': $info = $this->getInfoFromFeed($table, $row_id, $_forApi); break; case 'comment': $info = $this->getInfoFromComment($table, $row_id, $_forApi); break; case 'poster': $poster = D('poster')->where('id=' . $row_id)->field('title,uid')->find(); $info['source_user_info'] = model('User')->getUserInfo($poster['uid']); $info['source_url'] = U('poster/Index/posterDetail', array('id' => $row_id)); $info['source_body'] = $poster['title'] . '<a class="ico-details" href="' . U('poster/Index/posterDetail', array('id' => $row_id)) . '"></a>'; break; case 'event': $event = D('event')->where('id=' . $row_id)->field('title,uid')->find(); $info['source_user_info'] = model('User')->getUserInfo($event['uid']); $info['source_url'] = U('event/Index/eventDetail', array('id' => $row_id, 'uid' => $event['uid'])); $info['source_body'] = $event['title'] . '<a class="ico-details" href="' . U('event/Index/eventDetail', array('id' => $row_id, 'uid' => $event['uid'])) . '"></a>'; break; case 'blog': $blog = D('blog')->where('id=' . $row_id)->field('title,uid')->find(); $info['source_user_info'] = model('User')->getUserInfo($blog['uid']); $info['source_url'] = U('blog/Index/show', array('id' => $row_id, 'mid' => $blog['uid'])); $info['source_body'] = $blog['title'] . '<a class="ico-details" href="' . U('blog/Index/show', array('id' => $row_id, 'mid' => $blog['uid'])) . '"></a>'; break; case 'photo': $photo = D('photo')->where('id=' . $row_id)->field('name, albumId, userId')->find(); $info['source_user_info'] = model('User')->getUserInfo($photo['userId']); $info['source_url'] = U('photo/Index/photo', array('id' => $row_id, 'aid' => $photo['albumId'], 'uid' => $photo['userId'])); $info['source_body'] = $photo['name'] . '<a class="ico-details" href="' . $info['source_url'] . '"></a>'; break; case 'vote': $vote = D('vote')->where('id=' . $row_id)->field('title,uid')->find(); $info['source_user_info'] = model('User')->getUserInfo($vote['uid']); $info['source_url'] = U('vote/Index/pollDetail', array('id' => $row_id)); $info['source_body'] = $vote['title'] . '<a class="ico-details" href="' . U('vote/Index/pollDetail', array('id' => $row_id)) . '"></a>'; break; case 'develop': $develop = D('develop')->where('develop_id=' . $row_id)->field('title, uid')->find(); $info['source_user_info'] = model('User')->getUserInfo($develop['uid']); $info['source_url'] = U('develop/Index/detail', array('id' => $row_id)); $info['source_body'] = $develop['title'] . '<a class="ico-details" href="' . U('develop/Index/detail', array('id' => $row_id)) . '"></a>'; break; default: // 单独的内容,通过此路径获取资源信息 $appname = strtolower($appname); $name = ucfirst($appname); $dao = D($name . 'Protocol', $appname, false); if (method_exists($dao, 'getSourceInfo')) { $info = $dao->getSourceInfo($row_id, $_forApi); } unset($dao); // 兼容旧方案 if (!$info) { $modelArr = explode('_', $table); $model = ''; foreach ($modelArr as $v) { $model .= ucfirst($v); } $dao = D($model, $appname); if (method_exists($dao, 'getSourceInfo')) { $info = $dao->getSourceInfo($row_id, $_forApi); } } break; } $info['source_table'] = $table; $info['source_id'] = $row_id; static_cache('source_info_' . $key, $info); return $info; }