* 负责处理新发表文章的逻辑 * Createed By C860 at 2014-1-19 */ if (!class_exists('sys')) { include_once '../conf/config.php'; } //需要登录 sys::needLog('../login.php'); //检测数据合法性 if (isset($_POST['title']) && !empty($_POST['title']) && isset($_POST['content']) && !empty($_POST['content']) && isset($_POST['tags']) && !empty($_POST['tags'])) { //引入相关模型类 include_once '../Models/article.php'; include_once '../Models/tag_relate_article.php'; include_once '../Models/user_info.php'; $currentTime = date('Y-m-d H:i:s'); //新增文章 if (article::add($_POST['title'], $_POST['content'], $currentTime, $_SESSION['userId'])) { $ID = article::getId($_POST['title'], $_SESSION['userId'], $currentTime); $tags = explode('|', $_POST['tags']); foreach ($tags as $tag) { tag_relate_article::add($tag, $ID); } user_info::increaseArticleCount($_SESSION['userId']); sys::alert('发表成功!'); sys::redirect('../index.php'); } } else { //引入相关模型类 include_once 'Models/tag.php'; $taglist = tag::getAllTags(); }
public function tagAction() { //封装header $tuser = new user(); $auth = Zend_Auth::getinstance(); #获取auth用户实例 $auth->getIdentity(); #取得当前用户信息 $email = $auth->getIdentity(); $tuser = new user(); $user = $tuser->getAllbyEmail($email); $header = array("UID" => $user[0]["UID"], "image" => $user[0]["image"]); //封装tag $ttag = new tag(); $tans = new answer(); $task = new ask(); $tquestion = new question(); $tfollowq = new followQ(); $tags = $ttag->getAllTags(); $tagnum = count($tags); $this->view->tags = $tags; //print_r($tags); for ($i = 0; $i < count($tags); $i++) { //第i个tag $QIDs = $ttag->getQIDsbyTag($tags[$i]); $questionnum = count($QIDs); $tag[$i]["tag"] = $tags[$i]; $questiontmp[0] = 0; $answernum[0] = 0; for ($j = 0; $j < $questionnum; $j++) { //第j个question $question = $tquestion->getAllbyQID($QIDs[$j]); $QID = $QIDs[$j]; $title = $question["qtitle"]; if (strlen($title) > 75) { $title = substr($title, 0, 72); $title = $title . "..."; } $follownum = $tfollowq->getFollownumbyQID($QID); $answernum[$j] = $tans->getAnswernumbyQID($QID); $questiontmp[$j] = array("QID" => $QID, "title" => $title, "follownum" => $follownum, "answernum" => $answernum[$j]); } array_multisort($answernum, SORT_DESC, $questiontmp); for ($j = 0; $j < min(3, count($questiontmp)); $j++) { $Qresult[$i][$j] = $questiontmp[$j]; } } $this->view->tag = $tags; $this->view->Qresult = $Qresult; $this->view->header = $header; $this->render('tag'); }
public function tagAction() { if ($_GET) { $key = $this->getRequest()->getParam('tag', ''); $P = $this->getRequest()->getParam('P', '1'); } $perpage = 10; //question number per page $answer = new answer(); $followQ = new followQ(); $question = new question(); $tag = new tag(); $ask = new ask(); $QID = $tag->getQIDsbyTag($key); $result = array(); for ($i = 0; $i < count($QID); $i++) { $result[$i] = $question->getAllbyQID($QID[$i]); $result[$i]['time'] = $ask->getAskTimebyQID($result[$i]['QID']); $result[$i]['answernum'] = $answer->getAnswernumbyQID($result[$i]['QID']); $result[$i]['follownum'] = $followQ->getFollownumbyQID($result[$i]['QID']); $result[$i]['tag'] = $tag->getTagbyQID($result[$i]['QID']); } $answer = new answer(); $likeA = new likeA(); $user = new user(); for ($i = 0; $i < count($result); $i++) { $maxansid = -1; $maxsum = -1; //the id of most liked answer, the like number of the answer $AID = $answer->getAIDsbyQID($QID[$i]); for ($j = 0; $j < count($AID); $j++) { $likenum = $likeA->getLikenumbyAID($AID[$j]); if ($likenum > $maxsum) { $maxansid = $AID[$j]; $maxsum = $likenum; } } if ($maxansid != -1) { $result[$i]['AAbstract'] = $answer->getAbstractbyAID($maxansid); $tmp = $user->getAllbyUID($answer->getUIDbyAID($maxansid)); $result[$i]['image'] = $tmp['image']; } } $sum = count($result); //divide into several pages $Pnum = floor($sum / $perpage); if ($sum % $perpage > 0) { $Pnum++; } $presult = array(); $length = min($P * $perpage, $sum); for ($i = ($P - 1) * $perpage; $i < $length; $i++) { $presult[$i] = $result[$i]; } $this->view->P = $P; $this->view->Pnum = $Pnum; $this->view->Qresult = $presult; $tmp = $tag->getAllTags(); //warning: bad situation:$tmp[1] is empty,but $tmp[0] && $tmp[2] is exist $i = 0; foreach ($tmp as $a) { $result[$i++] = $a; } $this->view->tag = $result; //HotQlist $mans = new answer(); $mquestion = new question(); $mfollowq = new followQ(); $hquestion = $mans->getMostAnsweredQID(1, 6); for ($i = 0; $i < count($hquestion); $i++) { $qq = $mquestion->getAllbyQID($hquestion[$i]); $HotQlist[$i]["QID"] = $qq["QID"]; $HotQlist[$i]["title"] = $qq["qtitle"]; $HotQlist[$i]["follownum"] = $mfollowq->getFollownumbyQID($qq["QID"]); $HotQlist[$i]["answernum"] = $mans->getAnswernumbyQID($qq["QID"]); } $lefter = array("hotQlist" => $HotQlist); $this->view->lefter = $lefter; $this->view->url = "/search/tag"; $this->render('tagresult'); // }
function getAllTags() { return tag::getAllTags(); }
public function tagAction() { //封装header $auth = Zend_Auth::getinstance(); #获取当前用户实例 $UID = $auth->getIdentity(); #取得当前用户信息 if ($auth->hasIdentity() == false) { $this->render('index'); } $tuser = new user(); $user = $tuser->getAllbyUID($UID); $header = array("UID" => $user["UID"], "image" => $user["image"]); //封装tag $ttag = new tag(); $tans = new answer(); $task = new ask(); $tquestion = new question(); $tfollowq = new followQ(); $tagnum = $ttag->gerRequest()->getParam("tagnum"); $tags = $ttag->getAllTags(); for ($i = 0; $i < $tagnum; $i++) { //第i个tag $QIDs = $ttag->getQIDsbyTags($tags[$i]); for ($j = 0; $j < tagnum; $j++) { //第j个question $mUID = $task->getUIDbyQID($QIDs[$j]); $person = $tuser->getAllbyUID($mUID); $image1[$j] = $person['image']; $question = $tquestion->getAllbyQID($QIDs[$j]); $QID1[$j] = $QIDs[$i]; $title1[$j] = $question["title"]; $abstract1[$j] = $question["Qabstract"]; $follownum[$j] = $tfollowq->getFollownumbyQID($QID1[$j]); $answernum[$j] = $tans->getAnswernumbyQID($QID1[$j]); $tag1[$j] = $ttag->getTagbyQID($QID1[$j]); $time1[$j] = $task->getAskTimebyQID($QIDs[$j]); $tag[$i][$j] = array("image" => $image1[$j], "QID" => $QIDs[$j], "title" => $title1[$j], "abstract" => $abstract1[$j], "follownum" => $follownum[$j], "answernum" => $answernum[$j], "tag" => $tag1[$j], "time" => $time1[$j]); } } //传递变量,render $this->view->tag = $tag; $this->view->header = $header; $this->render('tag'); }
<?php /* * menu.php * 处理侧栏菜单的动态数据 * Created By C860 at 2014-1-29 */ include_once 'conf/config.php'; //引入相关模型类 include_once 'Models/tag.php'; //菜单栏 $menus = tag::getAllTags(1);