array( array('host' => 'livestockmem.r2bd3q.cfg.cnn1.cache.amazonaws.com.cn', 'port' => 11211), ), 'prefix' => 'zjcj', 'expire' => 900, ); function __construct() { $this->cache = new CMemcache($this->memcache); } function constr() { $this->con = new dbconn("172.20.1.153", "cnfol_zjcjapp", "pho32!8n43x", "cnfolv3_fol_admin", "utf8");//查 博客后台 return $this->con; } function convideo() { $this->strcon = new dbconn("10.1.4.31", "cnfol_zjcjapp", "pho32!8n43x", "cnfolCMS", "utf8");//查 cms return $this->strcon; } function conmap() { $this->mapcon = new dbconn("172.20.1.211", "cnfol_zjcjapp", "pho32!8n43x", "fol_review", "utf8");//查 评论库 return $this->mapcon; } function conshou(){ $this->shoucon = new dbconn("10.1.1.233", "cnfol_zjcjapp", "pho32!8n43x", "cnfol_phone", "utf8");//增删改查 收藏 //$this->shoucon = new dbconn("10.1.1.220", "cnfol_zjcjapp", "pho32!8n43x", "cnfol_phone", "utf8");//增删改查 收藏 return $this->shoucon; } function quanzi(){ //$this->strquanzi =new dbconn("10.1.1.90", "cnfol_zjcjapp", "pho32!8n43x", "cnfol_zjcj", "utf8");//增删改查 中金财经121.207.231.206 //$this->strquanzi =new dbconn("10.1.1.90", "cnfol_zjcjapp", "pho32!8n43x", "cnfol_zjcj", "utf8");//增删改查 中金财经121.207.231.206 $this->strquanzi =new dbconn("10.1.3.150", "cnfol_zjcjapp", "pho32!8n43x", "cnfol_zjcj", "utf8");//增删改查 中金财经121.207.231.206 return $this->strquanzi; } function conpic() { $this->piccon = new dbconn("10.1.1.253", "cnfol_zjcjapp", "pho32!8n43x", "cnfol_pic", "utf8");//增删改查 图片库 return $this->piccon; } function selshoucount($userid,$aid){ $sql="select count(*) as num from cnfol_collect where uid=".$userid." and aid=".$aid." and type=3"; $this->conshou(); $data=$this->shoucon->fetch_all($sql); $this->shoucon->close(); $rtn=$data[0]; return $rtn; } function shoucByAid($aid){ $ckey="shoucByAid".$aid; $rtn=$this->cache->get($ckey); if(!$rtn){ $sql="select count(*) as count from cnfol_collect where aid=".$aid; $this->conshou(); $rtn=$this->shoucon->fetch_all($sql); $this->shoucon->close(); $this->cache->set($ckey, $rtn); } return $rtn; } function blogaid($aid){ $ckey="blogaid_3g".$aid; $rtn=$this->cache->get($ckey); if(!$rtn){ $sql="select name from blogaid where type=1 and aid=".$aid; $this->conshou(); $rtn=$this->shoucon->fetch_all($sql); $this->shoucon->close(); $this->cache->set($ckey, $rtn); } return $rtn; } function selquanzicount($userid){ $ckey="selquanzicount".$userid; $rtn=$this->cache->get($ckey); if(!$rtn){ $sql="select count(id) as num from zjcj_userjoin where joinstate=0 and state=0 and userid=".$userid; $this->quanzi(); $data1=$this->strquanzi->fetch_all($sql); $sql="select count(id) as num from zjcj_group where state=0 and createuid=".$userid; $data2=$this->strquanzi->fetch_all($sql); $this->strquanzi->close(); $rtns=$data1[0]["num"]+$data2[0]["num"]; $rtn["num"]=$rtns; $this->cache->set($ckey, $rtn); } return $rtn; } function selnumreview($start, $end, $classid) { $ckey = "selnumreview" . $start . $end . $classid; $rtn = $this->cache->get($ckey); if (!$rtn) { $sql = "select count(*) as num,ContId from review_3g where CreatedTime between $start and $end and ContId < 10000000 group by ContId"; $this->conmap(); $data = $this->mapcon->fetch_all($sql); $this->mapcon->close(); $this->conpic(); if (empty($data)) { $sqls = "select `articleId`,`title`,`show`,`partId` from cnfol_content where partId in (" . $classid . ") order by updatetime DESC limit 6"; $rtn = $this->piccon->fetch_all($sqls); } else { $value = " ( "; foreach ($data as $key => $val) { $value .=$val["ContId"] . ","; } $value = rtrim($value, ","); $value = $value . " )"; $sql = "select `articleId`,`title`,`show`,`partId` from cnfol_content where partId in (" . $classid . ") and articleId in $value"; $attr = $this->piccon->fetch_all($sql); $count = count($attr); if ($count <= 6) { $limit = 6 - $count; if ($limit != 0) { $sqlcount = "select `articleId`,`title`,`show`,`partId` from cnfol_content where partId in (" . $classid . ") and articleId not in $value order by updatetime DESC limit " . $limit; $at = $this->piccon->fetch_all($sqlcount); } if ($count == 0) { $rtn = $at; } else if ($count == 6) { $rtn = $attr; } else { $rtn = array_merge($attr, $at); } } else { foreach ($attr as $keys => $vals) { foreach ($data as $key => $val) { if ($vals["ContId"] == $val["articleId"]) { $attr[$keys]["num"] = $val["num"]; } } } $common = new common_user(); $sort = $common->array_sort($attr, "num"); $i = 0; $rtn = null; foreach ($sort as $key => $val) { if ($i == 6) { break; } $rtn[$i] = $val; $i++; } } } if ($rtn) { $this->cache->set($ckey, $rtn); } $this->piccon->close(); } return $rtn; } function selreviewnum($comid){ $sql="select count(*) as num from review_3g where ContId=".$comid." AND Isdelete=0"; $this->conmap(); $data=$this->mapcon->fetch_all($sql); $this->mapcon->close(); return $data[0]; } function rtnRowByContId($ContId, $time) { $ckey = _FUNCTION_ . $ContId . $time . "rtnRowByContId"; $year = date("Y", time()); $rtn = $this->cache->get($ckey); $istoday = false; if (!$rtn) { if ($time == $year) { $table = "cnfol_content"; $istoday = true; } else { $table = "cnfol_arcontent_" . $time; } $this->convideo(); if ($istoday) { $sql = "SELECT c.`ContId`,c.`Title`,c.`CreatedTime`,c.`Source`,a.`Content`,c.`Author`,a.`FlvUrl` FROM cnfol_content AS c LEFT JOIN cnfol_article AS a ON c.`ContId`=a.ContId WHERE c.`ContId`=" . $ContId; $data = $this->strcon->fetch_all($sql); if (empty($data)) { $sql = "select ContId,Title,CreatedTime,Source,Content,Author,FlvUrl from cnfol_arcontent_" . $year . " where ContId=" . $ContId; $data = $this->strcon->fetch_all($sql); } } else { $sql = "select ContId,Title,CreatedTime,Source,Content,Author,FlvUrl from $table where ContId=" . $ContId; $data = $this->strcon->fetch_all($sql); if (empty($data)) { $sql = "SELECT c.`ContId`,c.`Title`,c.`CreatedTime`,c.`Source`,a.`Content`,c.`Author`,a.`FlvUrl` FROM cnfol_content AS c LEFT JOIN cnfol_article AS a ON c.`ContId`=a.ContId WHERE c.`ContId`=" . $ContId; $data = $this->strcon->fetch_all($sql); } } $this->strcon->close(); if (isset($data) && !empty($data)) { $rtn = $data[0]; $this->cache->set($ckey, $rtn); } else { return false; } } return $rtn; } function rtndatanews($type, $start, $pagesize, $time, $ist, $page) { if (ISCACHE) { $ckey = _FUNCTION_ . $type . $start . $pagesize . $time . $ist . $page; //memcache键值 $rtn = $this->cache->get($ckey); if (!$rtn) { $istable = false; $year = date("Y", time()); if ($year == $time) { $istable = true; $table = "cnfol_content"; } else { $table = "cnfol_arcontent_" . $time; } $this->convideo(); $rtndata = null; if ($istable) { if (!$ist) { $sqlCount = "select count(ContId) as rcdCount from cnfol_content where (1=1) and Catid=" . $type; $sql = "select ContId,Catid,Title,CreatedTime from cnfol_content where 1=1 and CatId=" . $type . " order by CreatedTime desc limit $start,$pagesize"; $rctCount = $this->strcon->fetch_all($sqlCount); $rtndatas = $this->strcon->fetch_all($sql); if (empty($rtndatas)) { $start = 0; $page = 1; $ist = true; } else { $rtn["ist"] = false; $rtn["page"] = ++$page; $rtn["year"] = $year; } } } else { $sqlCount = "select count(ContId) as rcdCount from $table where (1=1) and Catid=" . $type; $sql = "select ContId,Catid,Title,CreatedTime from $table where 1=1 and CatId=" . $type . " order by CreatedTime desc limit $start,$pagesize"; $rctCount = $this->strcon->fetch_all($sqlCount); $rtndatas = $this->strcon->fetch_all($sql); $rtn["ist"] = false; $rtn["year"] = $time; $rtn["page"] = ++$page; } if ($istable) { if ($ist) { $sqlCount = "select count(ContId) as rcdCount from cnfol_arcontent_$year where (1=1) and Catid=" . $type; $sql = "select ContId,Catid,Title,CreatedTime from cnfol_arcontent_$year where 1=1 and CatId=" . $type . " order by CreatedTime desc limit $start,$pagesize"; $rctCount = $this->strcon->fetch_all($sqlCount); $rtndatas = $this->strcon->fetch_all($sql); $rtn["ist"] = true; $rtn["year"] = $year; if (empty($rtndatas)) { $y = $year - 1; $start = 0; $page = 1; $sqlCount = "select count(ContId) as rcdCount from cnfol_arcontent_$y where (1=1) and Catid=" . $type; $sql = "select ContId,Catid,Title,CreatedTime from cnfol_arcontent_$y where 1=1 and CatId=" . $type . " order by CreatedTime desc limit $start,$pagesize"; $rctCount = $this->strcon->fetch_all($sqlCount); $rtndatas = $this->strcon->fetch_all($sql); $rtn["year"] = $y; } $rtn["page"] = ++$page; } } $this->strcon->close(); if (!empty($rtndatas)) { foreach ($rtndatas as $key => $val) { $rtndata[$key]["CreatedTime"] = date("Y-m-d H:i:s", $val["CreatedTime"]); $rtndata[$key]["Title"] = $val["Title"]; $rtndata[$key]["ContId"] = $val["ContId"]; } $rtn["rcd"] = $rctCount[0]; $rtn["data"] = $rtndata; } else { $rtn["rcd"] = 0; } $this->cache->set($ckey, $rtn); } return $rtn; } } function lunbolist() { if (ISCACHE) { $ckey = "lunbolist_usermodel"; $rs = $this->cache->get($ckey); if (!$rs) { $sql = "select title from hwitem where bid=320"; //图片 $this->constr(); $titlelb = $this->con->fetch_all($sql); $this->con->close(); if (!empty($titlelb)) { $lunbo = str_replace("\n", "", $titlelb[0]["title"]); $lunbo = str_replace("\r", "", $lunbo); preg_match_all('`\s+\s+(.*?)<\/span>\s+<\/a>`', $lunbo, $arr); $title = $arr[1]; if (!empty($title)) { $lb = null; $d = 0; foreach ($title as $key => $val) { $len= strlen($val); if($len>30){ preg_match_all('` \s+`',$arr[0][$key],$tt); $val=$tt[1][0]; } $lb[] = array("uri" => $val . "-" . $arr[2][$key], "img" => $arr[3][$key], "title" => $arr[4][$key]); $d++; } $rtn = array_merge(array("RetRecords" => $d), array("title" => $lb)); //图片 $this->cache->set($ckey, $rtn); } else { $rtn["RetRecords"] = 0; } } else { $rtn["RetRecords"] = 0; } return $rtn; } return $rs; } else { $sql = "select title from hwitem where bid=320"; //图片 $this->constr(); $titlelb = $this->con->fetch_all($sql); $this->con->close(); if (!empty($title)) { $lunbo = str_replace("\n", "", $titlelb[0]["title"]); $lunbo = str_replace("\r", "", $lunbo); preg_match_all('`\s+\s+(.*?)<\/span>\s+<\/a>`', $lunbo, $arr); $title = $arr[1]; if (!empty($title)) { $lb = null; $d = 0; foreach ($title as $key => $val) { $lb[] = array("uri" => $val . "-" . $arr[2][$key], "img" => $arr[3][$key], "title" => $arr[4][$key]); $d++; } $rtn = array_merge(array("RetRecords" => $d), array("title" => $lb)); //图片 } else { $rtn["RetRecords"] = 0; } } else { $rtn["RetRecords"] = 0; } return $rtn; } } function tupianlist($y=2) { if (ISCACHE) { $ckey = "tupianlist_usermodel"; $rs = $this->cache->get($ckey); if (!$rs) { $sql = "select title from hwitem where bid=321"; //头条 $this->constr(); $titlebk = $this->con->fetch_all($sql); $this->con->close(); if (empty($titlebk)) { $taglist = array("RetRecords" => 0); } else { foreach ($titlebk as $key => $val) { $str .=$val["title"]; } preg_match_all("/

(.*?)<\/p>/", $str, $artUseList); $artUseList = implode(" ", $artUseList[1]); $pattern = '/(.+?)<\/a.*?>/sim'; preg_match_all($pattern, $artUseList, $matResult); if (!empty($matResult)) { $i = 0; $recomList = array(); foreach ($matResult[1] as $k => $v) { if ($i < 3) { preg_match("/http:\/\/.*blog\.cnfol\.com\/(.*)\.html/", $v, $val); if (!empty($val)) { $item = explode('/', $val[1]); if ($item[2] && strstr($item[2], '-')) { $itemTap = explode('-', $item[2]); $recInfo['time'] = $itemTap[0]; $recInfo['title'] = $matResult[2][$k]; $recInfo['artUrl'] = $item[0] . "-" . $item[2]; //if($y==1){ //echo $item[0]; //$recInfo['userID']=getUserID($item[0]); //} $i++; } if ($recInfo) { $recomList[] = $recInfo; } unset($recInfo); } } } $taglist = array("RetRecords" => $i, "title" => $recomList); $this->cache->set($ckey, $taglist); } else { $taglist = array("RetRecords" => 0); } } } else { $taglist = $rs; } return $taglist; } } function selfamouslist($classid, $num) { $ckey = _FUNCTION_ . $classid . $num . "selfamouslist"; $rtn = $this->cache->get($ckey); if (!$rtn) { $sql = "select title from cnfol_hwitem where bid=$classid limit $num"; $this->convideo(); $data = $this->strcon->fetch_all($sql); $this->strcon->close(); $i = 0; $regnt = '/^

<\/a><\/div\>\s?
(.*?)<\/strong><\/a>
(.*?)<\/div>$/'; if (!empty($data)) { foreach ($data as $key => $val) { $val = str_replace("\n", "", $val["title"]); $val = str_replace("\r", "", $val); preg_match_all($regnt, $val, $matches); $attr = explode("/", $matches[1][0]); if (!empty($attr[1])) { $ar = explode(".", $attr[2]); $rtn[$i]["Id"] = $ar[0]; $rtn[$i]["year"] = substr($attr[1], 0, 4); $rtn[$i]["src"] = $matches[2][0]; $rtn[$i]["name"] = $matches[5][0]; $rtn[$i]["title"] = $matches[6][0]; $rtn[$i]["alt"] = $matches[4][0]; $i++; } else { //$rtn[$key]["id"] = rtrim($matches[1][0], "/"); } } $this->cache->set($ckey, $rtn); } } return $rtn; } function selpicturelist($id, $start, $end) { $ckey = _FUNCTION_ . $id . $start . $end . "selpicturelist"; $rtn = $this->cache->get($ckey); if (!$rtn) { $this->conpic(); $sqlContent = "select count(*) from cnfol_content where partId in (" . $id . ")"; $sql = "select `articleId`,`title`,`show`,`partId` from cnfol_content where partId in (" . $id . ") order by updatetime DESC limit $start,$end"; $count = $this->piccon->fetch_all($sqlContent); $rtns = $this->piccon->fetch_all($sql); if (!empty($rtns) && $rtns) { $rtn['data'] = $rtns; $rtn['rcdcount'] = $count[0] ["count(*)"]; $this->cache->set($ckey, $rtn); } } return $rtn; } function selpictureid($id) { $ckey = _FUNCTION_ . "selpictureid" . $id; $rtn = $this->cache->get($ckey); if (!$rtn) { $this->conpic(); $sql = "select a.`articleId`,a.`src`,a.`memo`,b.`title` from cnfol_pic a left join cnfol_content b on a.articleId=b.articleId where a.articleId=" . $id; $rtns = $this->piccon->fetch_all($sql); if (!empty($rtns) && $rtns) { $rtn["error"] = 10000; $rtn["data"] = $rtns; foreach ($rtns as $key => $val) { $rtn["allsrc"][$key] = $val["src"]; } $this->cache->set($ckey, $rtn); } else { $rtn["error"] = 10010; } } return $rtn; } }