public function logout() { $u = User::getInstance(); $wrapper = Wrapper::getInstance(); $this->set('data', $wrapper->user($u)); $this->ApiSession->logout(); }
public function root() { App::import("vendor", "model/section"); $secs = Configure::read('section'); $wrapper = Wrapper::getInstance(); $data = array(); foreach (array_keys($secs) as $v) { try { $sec = Section::getInstance($v, Section::$NORMAL); } catch (SectionNullException $e) { $this->error(ECode::$SEC_NOSECTION); } catch (BoardNullException $e) { $this->error(ECode::$BOARD_NOBOARD); } $data[] = $wrapper->section($sec, array('status' => true)); } $data = array('section_count' => count($data), 'section' => $data); $this->set('data', $data); $this->set('root', 'sections'); }
public function index() { $wrapper = Wrapper::getInstance(); $data = array(); $data = $wrapper->board($this->_board, array('status' => true)); App::import('vendor', 'inc/pagination'); $count = isset($this->params['url']['count']) ? $this->params['url']['count'] : Configure::read("pagination.threads"); $page = isset($this->params['url']['page']) ? $this->params['url']['page'] : 1; if (($count = intval($count)) <= 0) { $count = Configure::read("pagination.threads"); } if ($count > Configure::read('plugins.api.page_item_limit')) { $count = Configure::read("pagination.article"); } $page = intval($page); $pagination = new Pagination($this->_board, $count); $articles = $pagination->getPage($page); $data['pagination'] = $wrapper->page($pagination); foreach ($articles as $v) { $data['article'][] = $wrapper->article($v, array('threads' => $this->_board->getMode() == Board::$THREAD)); } $this->set('data', $data); }
public function category() { $category = $this->params['id']; $params = array(); $time = time(); $yes = $time - 86400; $u = User::getInstance(); switch ($category) { case 'hot': $sql = "select * from pl_vote where status=1 and end>? order by num desc, vid desc"; $params = array($yes); break; case 'me': case 'list': if ($category === 'me') { $user = $u->userid; } else { @($user = trim($this->params['url']['u'])); } $sql = "select * from pl_vote where status=1 and uid=? order by vid desc"; $params = array($user); break; case 'all': $sql = "select * from pl_vote where status=1 order by vid desc"; break; case 'join': $this->requestLogin(); $sql = "select * from pl_vote where status=1 and vid in (select vid from pl_vote_result where uid=?) order by vid desc"; $params = array($u->userid); break; case 'delete': if (!$u->isAdmin()) { $this->error('你无权查看此类投票'); } $sql = "select * from pl_vote where status=0 order by vid desc"; break; case 'new': $category = "new"; $sql = "select * from pl_vote where status=1 and end>? order by vid desc"; $params = array($yes); break; default: $this->error('错误的类别'); } $list = new VoteList($sql, $params); App::import('vendor', 'inc/pagination'); $count = isset($this->params['url']['count']) ? $this->params['url']['count'] : 10; $page = isset($this->params['url']['page']) ? $this->params['url']['page'] : 1; if (($count = intval($count)) <= 0) { $count = 10; } if ($count > Configure::read('plugins.api.page_item_limit')) { $count = Configure::read('plugins.api.page_item_limit'); } $page = intval($page); $pagination = new Pagination($list, $count); $votes = $pagination->getPage($page); $wrapper = Wrapper::getInstance(); $data = array(); $data['pagination'] = $wrapper->page($pagination); $data['votes'] = array(); foreach ($votes as $v) { $data['votes'][] = $wrapper->vote($v); } $this->set('data', $data); $this->set('root', 'list'); }
public function ajax_single() { if (!isset($this->params['id'])) { $this->error(ECode::$ARTICLE_NONE); } $id = $this->params['id']; try { $article = Article::getInstance($id, $this->_board); } catch (ArticleNullException $e) { $this->error(ECode::$ARTICLE_NONE); } App::import('vendor', 'inc/wrapper'); $wrapper = Wrapper::getInstance(); $ret = $wrapper->article($article, array('single' => true, 'content' => false)); $u = User::getInstance(); $ret['allow_post'] = $this->_board->hasPostPerm($u); $ret['is_bm'] = $u->isBM($this->_board) || $u->isAdmin(); $content = $article->getHtml(true); if (Configure::read("ubb.parse")) { //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); } $ret['content'] = $content; $this->set('no_html_data', $ret); }
public function delete() { if (!$this->RequestHandler->isPost()) { $this->error(ECode::$SYS_REQUESTERROR); } if (!isset($this->params['type'])) { $this->error(ECode::$MAIL_NOBOX); } if (!isset($this->params['num'])) { $this->error(ECode::$MAIL_NOMAIL); } $type = $this->params['type']; $num = $this->params['num']; try { $box = new MailBox(User::getInstance(), $type); $mail = Mail::getInstance($num, $box); $wrapper = Wrapper::getInstance(); $data = $wrapper->mail($mail); if (!$mail->delete()) { $this->error(ECode::$MAIL_DELETEERROR); } } catch (MailBoxNullException $e) { $this->error(ECode::$MAIL_NOBOX); } catch (MailNullException $e) { $this->error(ECode::$MAIL_NOMAIL); } catch (Exception $e) { $this->error(ECode::$MAIL_DELETEERROR); } $this->set('data', $data); }
public function ajax_show() { App::import('Sanitize'); $level = $this->params['num']; try { $fav = Favor::getInstance($level); } catch (FavorNullException $e) { $this->error(ECode::$USER_FAVERROR); } $this->cache(false); $ret = array(); App::import('vendor', 'inc/wrapper'); $wrapper = Wrapper::getInstance(); if (!$fav->isNull()) { $brds = $fav->getAll(); $u = User::getInstance(); foreach ($brds as $k => $v) { $last = array(); $last["id"] = $last["title"] = $last["owner"] = $last["date"] = false; if ($v->hasReadPerm($u)) { $threads = $v->getTypeArticles(0, 1, Board::$ORIGIN); if (!empty($threads)) { $threads = $threads[0]; $last = array("id" => $threads->ID, "title" => Sanitize::html($threads->TITLE), "owner" => $threads->isSubject() ? $threads->OWNER : "ÔÌûÒÑɾ³ý", "date" => date("Y-m-d H:i:s", $threads->POSTTIME)); } } if ($v->NAME == '') { $v = $wrapper->favorite($v); $v['type'] = 'fav'; $v['name'] = $v['level']; } else { if ($v->isDir()) { $v = $wrapper->section(Section::getInstance($v)); $v['type'] = 'section'; } else { $v = $wrapper->board($v, array('status' => true)); $v['type'] = 'board'; } } $v['last'] = $last; $ret[] = $v; continue; $ret[$k]['name'] = $v->NAME; $ret[$k]['desc'] = $v->DESC; $ret[$k]['dir'] = $v->isDir() ? 1 : 0; $ret[$k]['class'] = $v->CLASS; $ret[$k]['bm'] = $v->BM; $ret[$k]['pos'] = $v->NPOS; $ret[$k]['bid'] = $v->BID; $ret[$k]['num'] = $v->ARTCNT; //article num $ret[$k]['pnum'] = $v->CURRENTUSERS; //online $ret[$k]['tnum'] = $v->getTodayNum(); //totay article num $ret[$k]['thnum'] = $v->getThreadsNum(); //threads num $ret[$k]['last'] = $last; //last post $ret[$k]['link'] = ($v->isDir() ? "/fav/" : "/board/") . $v->BID; } } $this->set('no_html_data', $ret); //no ajax status info $this->set('no_ajax_info', true); }
public function threads() { App::import('vendor', array('model/board', 'model/threads', 'inc/pagination')); $day = 7; $title1 = $title2 = $title3 = $author = ''; if (isset($this->params['url']['title1'])) { $title1 = trim($this->params['url']['title1']); } if (isset($this->params['url']['title2'])) { $title2 = trim($this->params['url']['title2']); } if (isset($this->params['url']['titlen'])) { $title3 = trim($this->params['url']['titlen']); } if (isset($this->params['url']['author'])) { $author = trim($this->params['url']['author']); } if (isset($this->params['url']['day'])) { $day = intval($this->params['url']['day']); } $m = isset($this->params['url']['m']) && $this->params['url']['m'] == '1'; $a = isset($this->params['url']['a']) && $this->params['url']['a'] == '1'; $return = Configure::read('search.max'); $res = array(); if (!isset($this->params['url']['boards'])) { $this->error(ECode::$BOARD_UNKNOW); } $boards = $this->params['url']['boards']; foreach (explode('|', $boards) as $b) { try { $brd = Board::getInstance($b); $res = array_merge($res, Threads::search($brd, $title1, $title2, $title3, $author, $day, $m, $a, $return)); } catch (BoardNullException $e) { } } $count = isset($this->params['url']['count']) ? $this->params['url']['count'] : Configure::read("pagination.threads"); if (($count = intval($count)) <= 0) { $count = Configure::read("pagination.threads"); } if ($count > Configure::read('plugins.api.page_item_limit')) { $count = Configure::read("pagination.threads"); } $page = isset($this->params['url']['page']) ? $this->params['url']['page'] : 1; $page = intval($page); $pagination = new Pagination(new ArrayPageableAdapter($res), $count); $articles = $pagination->getPage($page); $wrapper = Wrapper::getInstance(); $data = array(); $data['pagination'] = $wrapper->page($pagination); foreach ($articles as $v) { $data['threads'][] = $wrapper->article($v, array('threads' => true)); } $this->set('data', $data); }
public function ajax_query() { App::import('Sanitize'); $id = trim($this->params['id']); try { $u = User::getInstance($id); } catch (UserNullException $e) { $this->error(ECode::$USER_NOID); } App::import("vendor", "inc/wrapper"); $wrapper = Wrapper::getInstance(); $ret = $wrapper->user($u); $ret['status'] = $u->getStatus(); $this->set('no_html_data', $ret); }
public function info() { if (!isset($this->params['type'])) { $this->error(ECode::$REFER_NONE); } $type = $this->params['type']; $u = User::getInstance(); try { $refer = new Refer($u, $type); } catch (ReferNullException $e) { $this->error(ECode::$REFER_NONE); } $data['enable'] = $u->getCustom('userdefine1', $type == Refer::$AT ? 2 : 3) == 1; $data['new_count'] = $refer->getNewNum(); $wrapper = Wrapper::getInstance(); $this->set('data', $data); }
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 delete() { if (!$this->RequestHandler->isPost()) { $this->error(ECode::$SYS_REQUESTERROR); } if (!isset($this->params['id'])) { $this->error(ECode::$ARTICLE_NONE); } $id = intval($this->params['id']); try { App::import('vendor', "model/article"); $article = Article::getInstance($id, $this->_board); } catch (ArticleNullException $e) { $this->error(ECode::$ARTICLE_NONE); } $u = User::getInstance(); if (!$article->hasEditPerm($u)) { $this->error(ECode::$ARTICLE_NODEL); } $wrapper = Wrapper::getInstance(); $this->set('data', $wrapper->article($article, array('content' => true))); if (!$article->delete()) { $this->error(ECode::$ARTICLE_NODEL); } }
public function delete() { if (!$this->RequestHandler->isPost()) { $this->error(ECode::$SYS_REQUESTERROR); } $this->_attOpInit(); $u = User::getInstance(); if (!isset($this->params['form']['name'])) { $this->error(ECode::$ATT_NAMEERROR); } $attName = strval($this->params['form']['name']); try { if (isset($this->params['id'])) { $id = $this->params['id']; $article = Article::getInstance($id, $this->_board); if (!$article->hasEditPerm($u)) { $this->error(ECode::$ARTICLE_NOEDIT); } $attNum = 0; foreach ($article->getAttList() as $k => $v) { if ($v['name'] == $attName) { $attNum = intval($k + 1); break; } } $article->delAttach($attNum); $article = Article::getInstance($id, $this->_board); } else { Forum::delAttach($attName); $article = Forum::listAttach(); } $wrapper = Wrapper::getInstance(); $this->set('data', $wrapper->attachment($article)); return; } catch (ArchiveAttException $e) { $msg = $e->getMessage(); } catch (AttException $e) { $msg = $e->getMessage(); } catch (Exception $e) { $this->error(); } }
private function _favor($fav) { App::import('vendor', 'model/section'); $wrapper = Wrapper::getInstance(); $f = $s = $b = array(); if (!$fav->isNull()) { $brds = $fav->getAll(); foreach ($brds as $k => $v) { if ($v->NAME == '') { $f[] = $wrapper->favorite($v); } else { if ($v->isDir()) { $s[] = $wrapper->section(Section::getInstance($v)); } else { $b[] = $wrapper->board($v); } } } } return array('sub_favorite' => $f, 'section' => $s, 'board' => $b); }