public function index() { $this->notice = "ÊղؼÐ"; App::import('Sanitize'); $level = (int) $this->params['num']; try { $fav = Favor::getInstance($level); } catch (FavorNullException $e) { $this->error(ECode::$USER_FAVERROR); } $p = $ret = false; if (!$fav->isNull()) { $brds = $fav->getAll(); foreach ($brds as $k => $v) { $ret[$k]['name'] = $v->NAME; $ret[$k]['desc'] = $v->DESC; $ret[$k]['dir'] = $v->isDir() ? 1 : 0; $ret[$k]['pos'] = $v->NPOS; $ret[$k]['url'] = $v->isDir() ? $v->NAME == "" ? "/favor/" . $v->BID : "/section/" . $v->NAME : "/board/" . $v->NAME; } } $parent = $fav->getParent(); if ($parent) { $p = "/favor/" . $parent->getLevel(); } $this->set("info", $ret); $this->set("parent", $p); }
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); }
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(); } }
public function delete() { if (!$this->RequestHandler->isPost()) { $this->error(ECode::$SYS_REQUESTERROR); } if (!isset($this->params['form']['dir']) || !isset($this->params['form']['name'])) { $this->error(); } $dir = $this->params['form']['dir'] == '1'; $val = trim($this->params['form']['name']); $level = $this->params['num']; try { $fav = Favor::getInstance($level); } catch (FavorNullException $e) { $this->error(ECode::$USER_FAVERROR); } if ($val == "") { $this->error(); } if ($dir) { if (!$fav->delete($val, Favor::$DIR)) { $this->error(); } } else { App::import('vendor', 'model/board'); try { $board = Board::getInstance($val); if (!$fav->delete($board, Favor::$BOARD)) { $this->error(); } } catch (BoardNullException $e) { $this->error(); } } try { $fav = Favor::getInstance($level); } catch (FavorNullException $e) { $this->error(ECode::$USER_FAVERROR); } $this->set('data', $this->_favor($fav)); }