/** * op=g|m|;|top|%|x|sharp * top=m|um|x|ux|;|u;|d|dx */ public function ajax_manage() { if (!$this->RequestHandler->isPost()) { $this->error(ECode::$SYS_REQUESTERROR); } if (!isset($this->params['id'])) { $this->error(ECode::$ARTICLE_NONE); } if (!isset($this->params['form']['op']) && !isset($this->params['form']['top'])) { $this->error(); } $u = User::getInstance(); if (!($u->isBM($this->_board) || $u->isAdmin())) { $this->error(ECode::$ARTICLE_NOMANAGE); } $id = $this->params['id']; $ret['refresh'] = true; if (isset($this->params['form']['op'])) { $op = explode('|', $this->params['form']['op']); try { $a = Article::getInstance($id, $this->_board); foreach ($op as $v) { switch ($v) { case 'g': $a->manage(3); break; case 'm': $a->manage(2); break; case ';': $a->manage(4); break; case 'top': if (!$a->isSubject()) { $this->error(ECode::$ARTICLE_NOTORIGIN); } if ($a->isReallyTop()) { $a->manage(1, true); } else { $a->manage(5); } break; case '%': $a->manage(7); break; case 'x': $a->manage(8); break; case 'sharp': $a->manage(9); break; } } } catch (ArticleNullException $e) { $this->error(ECode::$ARTICLE_NONE); } catch (ArticleManageException $e) { $this->error($e->getMessage); } } if (isset($this->params['form']['top'])) { $top = explode('|', $this->params['form']['top']); $gid = isset($this->params['form']['gid']) ? $this->params['form']['gid'] : $id; try { $t = Threads::getInstance($gid, $this->_board); $s = $gid == $id ? null : $id; if (in_array('d', $top)) { $t->manage(1, $s); $ret['refresh'] = false; } else { foreach ($top as $v) { switch ($v) { case 'm': $t->manage(2, $s); break; case 'um': $t->manage(3, $s); break; case 'x': $t->manage(6, $s); break; case 'ux': $t->manage(7, $s); break; case ';': $t->manage(8, $s); break; case 'u;': $t->manage(9, $s); break; case 'dx': $t->manage(4, $s); $ret['refresh'] = false; break; } } } } catch (ThreadsNullException $e) { $this->error(ECode::$ARTICLE_NONE); } catch (ArticleManageException $e) { $this->error($e->getMessage); } } $ret['ajax_code'] = ECode::$SYS_AJAXOK; $ret['default'] = '/board/' . $this->_board->NAME; $mode = $this->Cookie->read('BMODE'); if ($mode != null && $mode != BOARD::$THREAD) { $ret['default'] .= '/mode/' . $this->Cookie->read('BMODE'); } $this->set('no_html_data', $ret); }
public function forward() { $this->requestLogin(); if (!isset($this->params['gid'])) { $this->error(ECode::$ARTICLE_NONE); } $single = isset($this->params['url']['s']) || isset($this->params['form']['s']); if ($this->RequestHandler->isPost()) { if (!isset($this->params['form']['target'])) { $this->error(ECode::$USER_NONE); } $gid = intval($this->params['gid']); $target = trim($this->params['form']['target']); $threads = isset($this->params['form']['threads']); $noref = isset($this->params['form']['noref']); $noatt = isset($this->params['form']['noatt']); $noansi = isset($this->params['form']['noansi']); $big5 = isset($this->params['form']['big5']); try { $gid = $this->params['gid']; $article = Article::getInstance($gid, $this->_board); if ($threads) { $t = Threads::getInstance($article->GROUPID, $this->_board); $t->forward($target, $t->ID, $noref, $noatt, $noansi, $big5); } else { $article->forward($target, $noatt, $noansi, $big5); } } catch (ArticleNullException $e) { $this->error(ECode::$ARTICLE_NONE); } catch (ArticleForwardException $e) { $this->error($e->getMessage()); } $this->redirect($this->_mbase . "/board/" . $this->_board->NAME . ($single ? "/0" : "") . "?m=" . ECode::$ARTICLE_FORWARDOK); } $this->notice = "{$this->_board->DESC}-转寄"; App::import("vendor", array("model/friend")); $f = new Friend(User::getInstance()); $friends = $f->getRecord(1, $f->getTotalNum()); $ret = array(); foreach ($friends as $v) { $ret[] = $v->userid; } $this->set('friends', $ret); $this->set('bName', $this->_board->NAME); $this->set('gid', $this->params['gid']); $this->set("single", $single); }
public function index() { if (!isset($this->params['name'])) { $this->error(); } $name = $this->params['name']; App::import('vendor', 'model/widget'); try { $widget = Widget::getInstance($name); } catch (WidgetNullException $e) { $this->error($e->getMessage()); } $wrapper = Wrapper::getInstance(); $data = $wrapper->widget($widget); $list = $widget->wGetList(); switch (array_shift(split('-', $name))) { case 'topten': case 'recommend': if (!is_array($list['v'])) { break; } App::import('vendor', array('model/board', 'model/threads')); $article = array(); foreach ($list['v'] as $v) { if (isset($v['url'])) { $ret = array(); preg_match("|^/article/(.*?)/(.*?)\$|", $v['url'], $ret); if (empty($ret[1]) || empty($ret[2])) { continue; } $board = rawurldecode($ret[1]); $id = (int) $ret[2]; if ($widget->wGetName() == 'topten') { $text = $v['text']; $text = preg_replace("|<[^>]*?>|", '', $text); if (preg_match("/\\((\\d+)\\)\$/", $text, $c)) { $c = $c[1]; } else { $c = 0; } } try { $t = $wrapper->article(Threads::getInstance($id, Board::getInstance($board)), array('threads' => true)); if ($widget->wGetName() == 'topten') { $t['id_count'] = $c; $t['title'] .= "({$c})"; } $article[] = $t; } catch (Exception $e) { continue; } } } $data['article'] = $article; break; case 'section': if (!is_array($list[0]['v']['v'])) { break; } App::import('vendor', array('model/board', 'model/threads')); $article = array(); foreach ($list[0]['v']['v'] as $v) { if (isset($v['text'])) { $ret = array(); preg_match("|/article/(.+?)/(\\d+)|", $v['text'], $ret); if (empty($ret[1]) || empty($ret[2])) { continue; } $board = rawurldecode($ret[1]); $id = (int) $ret[2]; try { $article[] = $wrapper->article(Threads::getInstance($id, Board::getInstance($board)), array('threads' => true)); } catch (Exception $e) { continue; } } } $data['article'] = $article; break; default: $this->error('no such widget'); } $this->set('data', $data); }
public function view() { $this->css[] = "xwidget.css"; $this->css['plugin']['vote'][] = "vote.css"; $this->js['plugin']['vote'][] = "vote.js"; $this->js[] = "forum.share.js"; $this->notice[] = array("url" => "", "text" => "查看投票"); $this->cache(false); 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); $voted = false; if ($myres !== false) { $voted = true; $myres['time'] = date("Y-m-d H:i:s", $myres['time']); $this->set("myres", $myres); } App::import('Sanitize'); $info = 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 $k => $v) { $item[$k]["label"] = Sanitize::html($v["label"]); $item[$k]["percent"] = $vote->total === 0 ? 0 : round(intval($v['num']) * 100 / $vote->total); $item[$k]["on"] = $myres !== false && in_array($v['viid'], $myres['items']); } $this->set("board", $this->_board); $this->set("admin", $u->userid === $vote->uid || $u->isAdmin()); $this->set("result_voted", $vote->result_voted); $this->set("no_result", !$vote->isEnd() && !$this->get('admin') && $vote->result_voted && !$voted); $this->set("vinfo", $info); $this->set("vitems", $item); try { $u = User::getInstance($vote->uid); $furl = $u->getFace(); } catch (UserNullException $e) { $furl = false; } $this->set("furl", Sanitize::html($furl)); $this->set("fwidth", $u->userface_width === 0 ? "" : $u->userface_width); $this->set("fheight", $u->userface_height === 0 ? "" : $u->userface_height); App::import('vendor', array('model/board', 'model/threads', 'inc/ubb')); try { $threads = Threads::getInstance($vote->aid, Board::getInstance($this->_board)); $s = $threads->getTotalNum() - $this->_commentNum + 1; $articles = $threads->getRecord($s > 1 ? $s : 1, $this->_commentNum); $info = array(); foreach ($articles as $v) { if ($v->OWNER === 'deliver') { continue; } $tmp = array(); try { $own = User::getInstance($v->OWNER); $tmp['uid'] = $own->userid; $tmp['furl'] = Sanitize::html($own->getFace()); } catch (UserNullException $e) { $tmp['uid'] = $v->OWNER; $tmp['furl'] = false; } $tmp['time'] = date("Y-m-d H:i:s", $v->POSTTIME); $content = $v->getPlant(); $content = preg_replace("|<br/>【 在 deliver[\\s\\S]+<br/>: \\.{5,}<br/>|", '', $content); $content = preg_replace("/ /", " ", $content); $content = preg_replace("/ /", " ", $content); $content = preg_replace("|※ 修改:·([\\S]+) .*?FROM:[\\s]*([0-9a-zA-Z.:*]+)|", '', $content); $content = preg_replace("|※ 来源:.*FROM:[\\s]*([0-9a-zA-Z.:*]+)|", '', $content); $s = ($pos = strpos($content, "<br/><br/>")) === false ? 0 : $pos + 10; $e = ($pos = strpos($content, "<br/>--<br/>")) === false ? strlen($content) : $pos + 7; $content = preg_replace(array("'^(<br/>)+'", "|(<br/>)+--\$|"), array("", ""), substr($content, $s, $e - $s)); if (Configure::read("ubb.parse")) { $content = XUBB::parse($content); } $tmp['content'] = $content; $info[] = $tmp; } if (!strncmp($threads->TITLE, "Re: ", 4)) { $this->set("title", $threads->TITLE); } else { $this->set("title", 'Re: ' . $threads->TITLE); } $this->set("ajax_title", urlencode('投票:' . $threads->TITLE)); $this->set("reid", $threads->ID); $this->set("more", $threads->getTotalNum() > $this->_commentNum + 1); $this->set("comments", $info); } catch (ThreadsNullException $e) { $this->set("comments", false); } }
public function forward() { if (!$this->RequestHandler->isPost()) { $this->error(ECode::$SYS_REQUESTERROR); } $this->requestLogin(); if (!isset($this->params['id'])) { $this->error(ECode::$ARTICLE_NONE); } if (!isset($this->params['form']['target'])) { $this->error(ECode::$USER_NONE); } $id = intval($this->params['id']); $target = trim($this->params['form']['target']); $threads = isset($this->params['form']['threads']) && $this->params['form']['threads'] == 1; $noref = isset($this->params['form']['noref']) && $this->params['form']['noref'] == 1; $noatt = isset($this->params['form']['noatt']) && $this->params['form']['noatt'] == 1; $noansi = isset($this->params['form']['noansi']) && $this->params['form']['noansi'] == 1; $big5 = isset($this->params['form']['big5']) && isset($this->params['form']['big5']) == 1; try { App::import('vendor', array('model/article', 'model/threads')); $article = Article::getInstance($id, $this->_board); if ($threads) { $t = Threads::getInstance($article->GROUPID, $this->_board); $t->forward($target, $t->ID, $noref, $noatt, $noansi, $big5); } else { $article->forward($target, $noatt, $noansi, $big5); } $wrapper = Wrapper::getInstance(); $this->set('data', $wrapper->article($article, array('content' => true))); } catch (ArticleNullException $e) { $this->error(ECode::$ARTICLE_NONE); } catch (ArticleForwardException $e) { $this->error($e->getMessage()); } }