类微博功能设计-PHP源码
php代码
userList = $userDb->field('account_id,nicename')->where($map)->select();
//合并数组,方便操作
$userListGroup = array();
foreach($this->userList as $userListTemp){
$userListGroup[$userListTemp['account_id']] = $userListTemp['nicename'];
}
//生成替换格式
if($isConstructUrl){
$replaceArr = array();
foreach($userListGroup as $account_id =>$nicename){
$replace = $this->_constructUrl($account_id,$nicename);
$replaceArr += array("@".$nicename.' ' => $replace ); //这里空格也替换
}
//替换
$content = strtr($content,$replaceArr);
}
//标签处理
$tagPattarn = '/#(.*)#/U';
$tagMatch = array();
//是否需要格式化标签
if($isConstructTag && preg_match_all($tagPattarn , $content , $tagMatch) ){
$tagIn = '';
$tagReplacArr = array();
foreach ($tagMatch[1] as $tagTmp){
if($constructTmp = $this->_constructTag($tagTmp)){
$tagReplacArr += array('#'.$tagTmp.'#' => $constructTmp);
}
}
//替换
$content = strtr($content,$tagReplacArr);
}
return $content;
}
/**
* 格式提及用户,格式未定。
* @param $account_id
* @param $nicename
* @return string 返回格式的的用户链接
*/
private function _constructUrl($account_id,$nicename){
return '@'.$nicename.' ';
}
/**
* 格式提及标签,格式未定。
* @param $tagName 标签名
* @return boolean|string 返回格式的的标签
*/
private function _constructTag( $tagName ){
/*不需查询数据库,
$tagDb = M('tages_info ');
$map['cnname'] = $tagName;
$map['enname'] = $tagName;
$map['_logic'] = 'OR';
if(! $tag = $tagDb->where($map)->field("tage_id")->find()){
//没有该标签
return false;
}
*/
return '#' . $tagName . '#';
}
/**
* 添加到提及数据库,暂未完成
*/
public function addToMention($type , $id){
if(! $this->userList || !$type || !$id){
return false;
}
dump($this->userList);
}
}
class TestAction extends Action {
public function index(){
$mentionDb = D("mention");
$content = "#百搭#@ @小红 @小明 @sdfklj @dsf #英伦##英伦##英伦# #english##英伦##sdf#";
//构造content
$content = $mentionDb->convertContent($content , true , true);
echo $content;
//......将分享或评论什么的插入数据库,并获取其id $id与对应类别 $type
$type = 2; //假设类别为2
$id = 1;//假设插入数据库的分享或评论的id为1
$mentionDb->addToMention($type,$id);
}
}
/php/34673.htmlwww.phpzy.comtrue/php/34673.htmlTechArticle类微博功能设计-PHP源码 php代码 userList = $userDb->field(account_id,nicename)->where($map)->select();//合并数组,方便操作 $userListGroup = array(); foreach($this->userList as $userListTemp){$userListGroup[$userListTemp[a...
PHP之友评论