コード例 #1
0
 public function index()
 {
     $name = trim($this->params['name']);
     $parent = $ret = false;
     if ($name == "") {
         $this->notice = "讨论区列表";
         $secs = Configure::read("section");
         foreach ($secs as $k => $v) {
             $ret[] = array("name" => $v[0], "desc" => $v[1], "url" => "/section/" . $k, "hot" => "/hot/" . $k, "dir" => true);
         }
     } else {
         try {
             $sec = Section::getInstance($name, Section::$NORMAL);
             $this->notice = "讨论区-" . $sec->getDesc();
             $brds = $sec->getAll();
             $ret = array();
             foreach ($brds as $b) {
                 $ret[] = array("name" => $b->DESC, "desc" => $b->NAME, "url" => ($b->isDir() ? "/section/" : "/board/") . $b->NAME, "dir" => $b->isDir());
             }
             if ($sec->isRoot()) {
                 $parent = "/section";
             } else {
                 $parent = $sec->getParent();
                 $parent = "/section/" . $parent->getName();
             }
         } catch (SectionNullException $e) {
             $this->error(ECode::$SEC_NOSECTION);
         }
     }
     $this->set("boards", $ret);
     $this->set("parent", $parent);
 }
コード例 #2
0
 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');
 }
コード例 #3
0
ファイル: widget_controller.php プロジェクト: rainsun/nForum
 public function ajax_list()
 {
     $this->requestLogin();
     if (!isset($this->params['url']['t'])) {
         $this->error();
     }
     $type = $this->params['url']['t'];
     if (!isset($this->params['url']['tt'])) {
         $this->error();
     }
     $ret = array();
     try {
         $widgets = Widget::wGet(User::getInstance());
         $my = array();
         foreach ($widgets as $v) {
             $my[] = $v["name"];
         }
         switch ($type) {
             case 'section':
                 //$tt is for 0:root or 1:dir
                 $tt = $this->params['url']['tt'];
                 if ($tt != 0 && $tt != 1) {
                     $this->error();
                 }
                 $secs = Configure::read('section');
                 foreach ($secs as $k => $v) {
                     $w = Widget::getInstance("section-" . $k);
                     if ($tt == 0) {
                         if (!in_array($w->wGetName(), $my)) {
                             $title = $w->wGetTitle();
                             $title = $title["text"];
                             $ret[] = array('wid' => $w->wGetName(), 'title' => $title, 'p' => file_exists(IMAGES . 'app/icon/' . $w->wGetName() . '.png') ? $w->wGetName() : "default");
                         }
                     } else {
                         if ($tt == 1) {
                             foreach ($w->getDir() as $dir) {
                                 $ww = Widget::getInstance("section-" . $dir->NAME);
                                 if (!in_array($ww->wGetName(), $my)) {
                                     $title = $ww->wGetTitle();
                                     $title = $title["text"];
                                     $ret[] = array('wid' => $ww->wGetName(), 'title' => $title, 'p' => file_exists(IMAGES . 'app/icon/' . $ww->wGetName() . '.png') ? $ww->wGetName() : "default");
                                 }
                             }
                         }
                     }
                 }
                 break;
             case 'favor':
                 //tt is for favor level
                 //favor is only one level!!! the structure error!!!
                 $tt = intval($this->params['url']['tt']);
                 $favor = Favor::getInstance($tt);
                 if (!in_array($favor->wGetName(), $my)) {
                     $title = $favor->wGetTitle();
                     $title = $title["text"];
                     $ret[] = array('wid' => $favor->wGetName(), 'title' => $title, 'p' => file_exists(IMAGES . 'app/icon/' . $favor->wGetName() . '.png') ? $favor->wGetName() : "default");
                 }
                 foreach ($favor->getDir() as $w) {
                     if (!in_array("favor-" . $w->BID, $my) && $w->NAME == "") {
                         $ret[] = array('wid' => "favor-" . $w->BID, 'title' => $w->DESC, 'p' => "default");
                     }
                 }
                 break;
             case 'board':
                 if (!isset($this->params['url']['tt'])) {
                     $this->error();
                 }
                 //$tt is for section num
                 $tt = intval($this->params['url']['tt']);
                 $secs = Configure::read('section');
                 if (!in_array($tt, array_keys($secs))) {
                     $this->error();
                 }
                 $w = Section::getInstance($tt, Section::$ALL);
                 foreach ($w->getList() as $brd) {
                     $ww = Widget::getInstance("board-" . $brd->NAME);
                     if (!in_array($ww->wGetName(), $my)) {
                         $title = $ww->wGetTitle();
                         $title = $title["text"];
                         $ret[] = array('wid' => $ww->wGetName(), 'title' => $title, 'p' => file_exists(IMAGES . 'app/icon/' . $ww->wGetName() . '.png') ? $ww->wGetName() : "default");
                     }
                 }
                 break;
             case 'ext':
                 if (!isset($this->params['url']['tt'])) {
                     $this->error();
                 }
                 //$tt is for category
                 $tt = $this->params['url']['tt'];
                 $ext = Configure::read('widget.ext');
                 if (!in_array($tt, array_keys($ext))) {
                     $this->error();
                 }
                 foreach ($ext[$tt][1] as $v) {
                     try {
                         $w = Widget::getInstance($v);
                     } catch (WidgetNullException $e) {
                         continue;
                     }
                     if (!in_array($w->wGetName(), $my)) {
                         $title = $w->wGetTitle();
                         $title = $title["text"];
                         $ret[] = array('wid' => $w->wGetName(), 'title' => $title, "p" => file_exists(IMAGES . 'app/icon/' . $w->wGetName() . '.png') ? $w->wGetName() : "default");
                     }
                 }
                 break;
             case 'search':
                 if (!isset($this->params['url']['tt'])) {
                     $this->error();
                 }
                 //$tt is for widget name
                 $tt = urldecode(urldecode($this->params['url']['tt']));
                 $tt = nforum_iconv('utf-8', $this->encoding, $tt);
                 $ext = Configure::read('widget.ext');
                 foreach ($ext as $v) {
                     foreach ($v[1] as $wid) {
                         try {
                             $w = Widget::getInstance($wid);
                         } catch (WidgetNullException $e) {
                             continue;
                         }
                         $title = $w->wGetTitle();
                         $title = $title["text"];
                         if (!in_array($w->wGetName(), $my) && strpos($title, $tt) !== false) {
                             $ret[] = array('wid' => $w->wGetName(), 'title' => $title, "p" => file_exists(IMAGES . 'app/icon/' . $w->wGetName() . '.png') ? $w->wGetName() : "default");
                         }
                     }
                 }
                 break;
         }
     } catch (Exception $e) {
         $this->error();
     }
     $this->set('no_html_data', $ret);
     //no ajax status info
     $this->set('no_ajax_info', true);
 }
コード例 #4
0
ファイル: favor_controller.php プロジェクト: tilitala/nForum
 public function ajax_list()
 {
     $ret = array();
     if (!isset($this->params['url']['root'])) {
         $this->_stop();
     }
     $root = $this->params['url']['root'];
     try {
         $sec = substr($root, 0, 2) == "s-" ? 1 : 0;
         $root = $root == "list-favor" ? 0 : substr($root, 2);
         try {
             if ($sec) {
                 $fav = Section::getInstance($root, Section::$NORMAL);
             } else {
                 $fav = Favor::getInstance($root);
             }
         } catch (SectionNullException $e) {
             $this->_stop();
         } catch (FavorNullException $e) {
             $this->_stop();
         }
         $ret = array();
         if (!$fav->isNull()) {
             $brds = $fav->getAll();
             foreach ($brds as $v) {
                 //user dir
                 if ($v->NAME == "") {
                     $ret[] = array("t" => "<a href=\"javascript:void(0)\" title=\"{$v->DESC}\">{$v->DESC}</a>", "id" => "f-" . $v->BID);
                 } elseif ($v->isDir()) {
                     $ret[] = array("t" => "<a href=\"{$this->base}/section/{$v->NAME}\" title=\"{$v->DESC}\">{$v->DESC}</a>", "id" => "s-" . $v->NAME);
                 } else {
                     $ret[] = array("t" => "<a href=\"{$this->base}/board/{$v->NAME}\" title=\"{$v->DESC}\">{$v->DESC}</a>");
                 }
             }
         }
         $this->cache(true, $fav->wGetTime(), 10);
         $this->set('no_html_data', $ret);
         $this->set('no_ajax_info', true);
     } catch (FavorNullException $e) {
         $this->_stop();
     }
 }
コード例 #5
0
ファイル: search_controller.php プロジェクト: tilitala/nForum
 public function article()
 {
     $this->js[] = "forum.board.js";
     $this->css[] = "board.css";
     $this->notice[] = array("url" => "", "text" => "ËÑË÷½á¹û");
     App::import('Sanitize');
     $day = $title1 = $title2 = $title3 = $author = $t = "";
     if (isset($this->params['url']['t1'])) {
         $title1 = trim(rawurldecode($this->params['url']['t1']));
     }
     if (isset($this->params['url']['t2'])) {
         $title2 = trim(rawurldecode($this->params['url']['t2']));
     }
     if (isset($this->params['url']['tn'])) {
         $title3 = trim(rawurldecode($this->params['url']['tn']));
     }
     if (isset($this->params['url']['au'])) {
         $author = trim($this->params['url']['au']);
     }
     if (isset($this->params['url']['d'])) {
         $day = intval($this->params['url']['d']);
     }
     $title1 = nforum_iconv('utf-8', $this->encoding, $title1);
     $title2 = nforum_iconv('utf-8', $this->encoding, $title2);
     $title3 = nforum_iconv('utf-8', $this->encoding, $title3);
     $m = isset($this->params['url']['m']);
     $a = isset($this->params['url']['a']);
     $full = isset($this->params['url']['f']);
     $site = Configure::read('search.site');
     $return = Configure::read("search.max");
     $res = array();
     $u = User::getInstance();
     if ($title1 == '' && $title3 == '' && $author == '' && !$m && !$a) {
         $res = array();
     } else {
         if ($full && $site && $u->isAdmin()) {
             App::import('vendor', 'model/section');
             $secs = array_keys(Configure::read("section"));
             foreach ($secs as $v) {
                 $sec = Section::getInstance($v, Section::$ALL);
                 foreach ($sec->getList() as $brd) {
                     if (!$brd->isNormal()) {
                         continue;
                     }
                     $res = array_merge($res, Threads::search($brd, $title1, $title2, $title3, $author, $day, $m, $a, $return));
                 }
             }
         } else {
             $b = @$this->params['url']['b'];
             try {
                 $brd = Board::getInstance($b);
             } catch (BoardNullException $e) {
                 $this->error(ECode::$BOARD_NONE);
             }
             $res = Threads::search($brd, $title1, $title2, $title3, $author, $day, $m, $a, $return);
         }
     }
     $p = 1;
     if (isset($this->params['url']['p'])) {
         $p = $this->params['url']['p'];
     }
     App::import("vendor", "inc/pagination");
     $page = new Pagination(new ArrayPageableAdapter($res), Configure::read("pagination.search"));
     $threads = $page->getPage($p);
     $info = false;
     $curTime = strtotime(date("Y-m-d", time()));
     $pageArticle = Configure::read("pagination.article");
     foreach ($threads as $v) {
         $tabs = ceil($v->articleNum / $pageArticle);
         $last = $v->LAST;
         $postTime = $curTime > $v->POSTTIME ? date("Y-m-d", $v->POSTTIME) : date("H:i:s", $v->POSTTIME) . "&emsp;";
         $replyTime = $curTime > $last->POSTTIME ? date("Y-m-d", $last->POSTTIME) : date("H:i:s", $last->POSTTIME) . "&emsp;";
         $info[] = array("title" => Sanitize::html($v->TITLE), "poster" => $v->isSubject() ? $v->OWNER : "Ô­ÌûÒÑɾ³ý", "postTime" => $postTime, "gid" => $v->ID, "last" => $last->OWNER, "replyTime" => $replyTime, "page" => $tabs, "bName" => $v->getBoard()->NAME, "num" => $v->articleNum - 1);
     }
     $this->set("info", $info);
     $query = $this->params['url'];
     unset($query['url']);
     unset($query['p']);
     unset($query['ext']);
     foreach ($query as $k => &$v) {
         $v = $k . '=' . rawurlencode($v);
     }
     $query[] = "p=%page%";
     $link = "{$this->base}/s/article?" . join("&", $query);
     $this->set("pageBar", $page->getPageBar($p, $link));
     $this->set("pagination", $page);
 }
コード例 #6
0
 public function ajax_list()
 {
     $this->cache(true, strtotime(date("Y-m-d", time() + 86400)));
     $ret = array();
     if (!isset($this->params['url']['root'])) {
         $this->_stop();
     }
     $root = $this->params['url']['root'];
     if ($root == "list-section") {
         $sections = Configure::read("section");
         foreach ($sections as $k => $v) {
             $ret[] = array("t" => "<a href=\"{$this->base}/section/{$k}\">{$v[0]}</a>", "id" => "sec-{$k}");
         }
         $this->set('no_html_data', $ret);
         $this->set('no_ajax_info', true);
         return;
     } else {
         try {
             $boardOnly = isset($this->params['url']['bo']);
             $root = Section::getInstance(substr($root, 4), $boardOnly ? Section::$ALL : Section::$NORMAL);
             $sections = $boardOnly ? $root->getList() : $root->getAll();
             foreach ($sections as $v) {
                 $tmp = array();
                 if ($boardOnly) {
                     $ret[] = array('name' => $v->NAME, 'desc' => $v->DESC);
                     continue;
                 }
                 if ($v->isDir()) {
                     $tmp['t'] = "<a href=\"{$this->base}/section/{$v->NAME}\" title=\"{$v->DESC}\">{$v->DESC}</a>";
                     $tmp['id'] = 'sec-' . $v->NAME;
                 } else {
                     $tmp['t'] = "<a href=\"{$this->base}/board/{$v->NAME}\" title=\"{$v->DESC}\">{$v->DESC}</a>";
                 }
                 $ret[] = $tmp;
             }
             $this->set('no_html_data', $ret);
             $this->set('no_ajax_info', true);
         } catch (SectionNullException $e) {
             $this->_stop();
         } catch (BoardNullException $e) {
             $this->_stop();
         }
     }
 }
コード例 #7
0
 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);
 }