Пример #1
0
 public function index()
 {
     $id = intval($this->params['id']);
     try {
         $vote = new Vote($id);
     } catch (VoteNullException $e) {
         $this->error("未知的投票");
     }
     $u = User::getInstance();
     if ($this->RequestHandler->isPost()) {
         $this->requestLogin();
         if ($vote->isDeleted()) {
             $this->error("此投票已删除");
         }
         if ($vote->isEnd()) {
             $this->error("此投票已截止");
         }
         if ($vote->getResult($u->userid) !== false) {
             $this->error("你已经投过票了");
         }
         if (!isset($this->params['form']['vote'])) {
             $this->error("未知的参数");
         }
         if ($vote->type == "0") {
             $viid = intval($this->params['form']['vote']);
             if (!$vote->hasItem($viid)) {
                 $this->error("未知的选项,投票失败");
             }
             $vote->vote($u->userid, $viid);
         } else {
             if ($vote->type == "1") {
                 $items = array_values((array) $this->params['form']['vote']);
                 if (count($items) == 0) {
                     $this->error("请至少选择一个选项");
                 }
                 if (count($items) > $vote->limit && $vote->limit != 0) {
                     $this->error("投票个数超过限制,投票失败");
                 }
                 foreach ($items as $v) {
                     if (!$vote->hasItem(intval($v))) {
                         $this->error("未知的选项,投票失败");
                     }
                 }
                 $vote->vote($u->userid, $items);
             } else {
                 $this->error("错误的投票");
             }
         }
     }
     if ($vote->isDeleted() && !$u->isAdmin()) {
         $this->error("此投票已删除");
     }
     $wrapper = Wrapper::getInstance();
     $data['vote'] = $wrapper->vote($vote, array('items' => true));
     $this->set('data', $data);
 }
Пример #2
0
 public function index()
 {
     $this->cache(false);
     $this->css[] = "article.css";
     $this->js[] = "forum.share.js";
     $this->js[] = "forum.article.js";
     $this->_getNotice();
     $this->notice[] = array("url" => "", "text" => "阅读文章");
     App::import('Sanitize');
     App::import('vendor', array("inc/pagination", "inc/astro"));
     if (!isset($this->params['gid']) || $this->params['gid'] == '0') {
         $this->error(ECode::$ARTICLE_NONE);
     }
     try {
         $gid = $this->params['gid'];
         $this->_threads = Threads::getInstance($gid, $this->_board);
     } catch (ThreadsNullException $e) {
         $this->error(ECode::$ARTICLE_NONE);
     }
     //article jump
     if (isset($this->params['url']['s'])) {
         $article = $this->_threads->getArticleById(intval($this->params['url']['s']));
         if (null !== $article) {
             $pos = $article->getPos();
             $page = ceil(($pos + 1) / Configure::read("pagination.article"));
             $this->redirect("/article/{$this->_board->NAME}/{$gid}?p={$page}#a{$pos}");
         }
         $this->redirect("/article/{$this->_board->NAME}/{$gid}");
     }
     //filter author
     $auF = $au = false;
     if (isset($this->params['url']['au'])) {
         $tmp = $this->_threads->getRecord(1, $this->_threads->getTotalNum());
         $auF = array();
         $au = trim($this->params['url']['au']);
         foreach ($tmp as $v) {
             if ($v->OWNER == $au) {
                 $auF[] = $v;
             }
         }
         $auF = new ArrayPageableAdapter($auF);
     }
     $p = isset($this->params['url']['p']) ? $this->params['url']['p'] : 1;
     $pagination = new Pagination(false !== $au ? $auF : $this->_threads, Configure::read("pagination.article"));
     $articles = $pagination->getPage($p);
     $u = User::getInstance();
     if ($bm = $u->isBM($this->_board) || $u->isAdmin()) {
         $this->js[] = "forum.manage.js";
     }
     $info = array();
     $curTime = strtotime(date("Y-m-d", time()));
     $isUbb = Configure::read("ubb.parse");
     $isSyn = Configure::read("ubb.syntax");
     $hasSyn = false;
     foreach ($articles as $v) {
         try {
             $own = User::getInstance($v->OWNER);
             $astro = Astro::getAstro($own->birthmonth, $own->birthday);
             if ($own->getCustom("userdefine0", 29) == 0) {
                 $hide = true;
                 $gender = -1;
             } else {
                 $hide = false;
                 $gender = $own->gender == "77" ? 0 : 1;
             }
             $user = array("id" => $own->userid, "name" => Sanitize::html($own->username), "gender" => $gender, "furl" => Sanitize::html($own->getFace()), "width" => $own->userface_width === 0 ? "" : $own->userface_width, "height" => $own->userface_height === 0 ? "" : $own->userface_height, "post" => $own->numposts, "astro" => $astro['name'], "online" => $own->isOnline(), "level" => $own->getLevel(), "time" => date($curTime > $own->lastlogin ? "Y-m-d" : "H:i:s", $own->lastlogin), "first" => date("Y-m-d", $own->firstlogin), "hide" => $hide);
         } catch (UserNullException $e) {
             $user = false;
         }
         $content = $v->getHtml(true);
         //hard to match all the format of ip
         //$pattern = '/<font class="f[0-9]+">※( |&nbsp;)来源:·.+?\[FROM:( |&nbsp;)[0-9a-zA-Z.:*]+\]<\/font><font class="f000">( +<br \/>)+ +<\/font>/';
         //preg_match($pattern, $content, $match);
         //$content = preg_replace($pattern, "", $content);
         if ($isUbb) {
             //remove ubb of nickname in first and title second line
             preg_match("'^(.*?<br \\/>.*?<br \\/>)'", $content, $res);
             $content = preg_replace("'(^.*?<br \\/>.*?<br \\/>)'", '', $content);
             $content = XUBB::remove($res[1]) . $content;
             $content = XUBB::parse($content);
             //check syntax
             if (!empty($isSyn) && preg_match("/<pre class=\"brush:/", $content)) {
                 $hasSyn = true;
             }
             //parse vote
             if ($v->OWNER === 'deliver' && in_array('vote', Configure::read('plugins.install'))) {
                 $vid = array();
                 if (preg_match("'\\[vote=(\\d+)\\]\\[/vote\\]'", $content, $vid)) {
                     $content = preg_replace("'\\[vote=\\d+\\]\\[/vote\\]'", '', $content);
                     App::import("vendor", array("inc/db", "vote.vote"));
                     $vid = $vid[1];
                     try {
                         $vote = new Vote($vid);
                         if (!$vote->isDeleted()) {
                             $this->css['plugin']['vote'][] = "vote.css";
                             $this->js['plugin']['vote'][] = "vote.js";
                             $myres = $vote->getResult($u->userid);
                             $voted = false;
                             if ($myres !== false) {
                                 $voted = true;
                                 $myres['time'] = date("Y-m-d H:i:s", $myres['time']);
                                 $this->set("myres", $myres);
                             }
                             $vinfo = array("vid" => $vote->vid, "title" => Sanitize::html($vote->subject), "desc" => nl2br(Sanitize::html($vote->desc)), "start" => date("Y-m-d H:i:s", $vote->start), "end" => date("Y-m-d", $vote->end), "num" => $vote->num, "type" => $vote->type, "limit" => $vote->limit, "aid" => $vote->aid, "isEnd" => $vote->isEnd(), "isDel" => $vote->isDeleted(), "voted" => $voted, "uid" => $vote->uid);
                             $item = $vote->items;
                             foreach ($item as $kk => $vv) {
                                 $item[$kk]["label"] = Sanitize::html($vv["label"]);
                                 $item[$kk]["percent"] = $vote->total === 0 ? 0 : round(intval($vv['num']) * 100 / $vote->total);
                                 $item[$kk]["on"] = $myres !== false && in_array($vv['viid'], $myres['items']);
                             }
                             $this->set("vinfo", $vinfo);
                             $this->set("vitems", $item);
                             $this->set("result_voted", $vote->result_voted);
                             $this->set("no_result", !($u->userid === $vote->uid || $u->isAdmin()) && $vote->result_voted && !$voted);
                         }
                     } catch (VoteNullException $e) {
                     }
                 }
             }
         }
         $info[] = array("id" => $v->ID, "owner" => $user, "op" => $v->OWNER == $u->userid || $bm ? 1 : 0, "pos" => $v->getPos(), "poster" => $v->OWNER, "content" => $content, "subject" => $v->isSubject(), 'g' => $v->isG(), 'm' => $v->isM(), 'l' => $v->isNoRe(), 'p' => $v->isPercent(), 's' => $v->isSharp(), 'x' => $v->isX());
     }
     $this->title = Sanitize::html($this->_threads->TITLE);
     $link = "{$this->base}/article/{$this->_board->NAME}/{$gid}?p=%page%";
     if (false !== $auF) {
         $link .= "&au={$au}";
     }
     $this->set("pageBar", $pagination->getPageBar($p, $link));
     $this->set("pagination", $pagination);
     $this->set("bName", $this->_board->NAME);
     $this->set("gid", $gid);
     $this->set("anony", $this->_board->isAnony());
     $this->set("tmpl", $this->_board->isTmplPost());
     $this->set("info", $info);
     $this->set("title", $this->title);
     $this->set('hasSyn', $hasSyn);
     $this->set("au", $au);
     $this->set("bm", $bm);
     //for the quick reply, raw encode the space
     $this->set("reid", $this->_threads->ID);
     if (!strncmp($this->_threads->TITLE, "Re: ", 4)) {
         $reTitle = $this->_threads->TITLE;
     } else {
         $reTitle = "Re: " . $this->_threads->TITLE;
     }
     //hack for post with ajax,need utf-8 encoding
     $reTitle = nforum_iconv($this->encoding, 'utf-8', $reTitle);
     $this->set("reTitle", rawurlencode($reTitle));
     //for default search day
     $this->set("searchDay", Configure::read("search.day"));
     $this->set("searchDay", Configure::read("search.day"));
     $this->jsr[] = "window.user_post=" . ($this->_board->hasPostPerm($u) && !$this->_board->isDeny($u) ? "true" : "false") . ";";
 }
Пример #3
0
 public function ajax_vote()
 {
     if (!$this->RequestHandler->isPost()) {
         $this->error(ECode::$SYS_REQUESTERROR);
     }
     $this->requestLogin();
     if (!isset($this->params['vid'])) {
         $this->error("未知的投票");
     }
     $vid = intval($this->params['vid']);
     try {
         $vote = new Vote($vid);
     } catch (VoteNullException $e) {
         $this->error("未知的投票");
     }
     $u = User::getInstance();
     if ($vote->isDeleted() && !$u->isAdmin()) {
         $this->error("此投票已删除");
     }
     $myres = $vote->getResult($u->userid);
     if ($myres !== false) {
         $this->error("你已经投过票了");
     }
     if ($vote->isDeleted()) {
         $this->error("此投票已删除");
     }
     if ($vote->isEnd()) {
         $this->error("此投票已截止");
     }
     if ($vote->type == "0") {
         @($viid = $this->params['form']['v' . $vote->vid]);
         if (!$vote->hasItem($viid)) {
             $this->error("未知的选项,投票失败");
         }
         $vote->vote($u->userid, $viid);
     } else {
         if ($vote->type == "1") {
             $items = array_keys($this->params['form']);
             if (count($items) > $vote->limit && $vote->limit != 0) {
                 $this->error("投票个数超过限制,投票失败");
             }
             $items = preg_replace("/v{$vote->vid}_/", "", $items);
             foreach ($items as $v) {
                 if (!$vote->hasItem($v)) {
                     $this->error("未知的选项,投票失败");
                 }
             }
             $vote->vote($u->userid, $items);
         } else {
             $this->error("错误的投票");
         }
     }
 }