Exemplo n.º 1
0
 public function index()
 {
     $this->css[] = "xwidget.css";
     $this->notice = array(array("url" => Configure::read("site.notice.url"), "text" => Configure::read("site.notice.text")));
     App::import('Sanitize');
     App::import('vendor', 'model/widget');
     $u = User::getInstance();
     $ret = $w = array();
     $ret = Widget::wGet($u);
     if (empty($ret)) {
         $this->set("widget", array());
         return;
     }
     $persistent = Configure::read("widget.persistent");
     if ($persistent) {
         $time = (array) nforum_cache_read("widget_time");
         $update = false;
     }
     $w = array_fill(1, $u->getCustom("userdefine1", 31) == 1 ? 3 : 2, array());
     foreach ($ret as $v) {
         $w[$v['col']][$v['row']] = $v;
         if ($persistent) {
             try {
                 $ww = Widget::getInstance($v['name']);
                 if (!$ww->wHasPerm(User::getInstance())) {
                     $ww = new EWidget('你无权访问此应用');
                     $html = Widget::html($ww->wGetList());
                 } else {
                     if (strpos($v['name'], "favor-") === 0) {
                         $html = Widget::html($ww->wGetList());
                     } else {
                         if (!isset($time[$v['name']]) || $time[$v['name']] < $ww->wGetTime() || false === ($html = nforum_cache_read("widget_" . $v['name']))) {
                             $time[$v['name']] = $ww->wGetTime();
                             $html = Widget::html($ww->wGetList());
                             nforum_cache_write("widget_" . $v['name'], $html);
                             $update = true;
                         }
                     }
                 }
             } catch (WidgetNullException $e) {
                 $ww = new EWidget();
                 //if persistent,it will not check wiget time and will not update widget_time.
                 $html = Widget::html($ww->wGetList());
             }
             $w[$v['col']][$v['row']]['content'] = $html;
         }
     }
     if ($persistent && $update) {
         nforum_cache_write("widget_time", $time);
     }
     foreach ($w as &$v) {
         ksort($v);
     }
     $this->set("widget", $w);
     $this->jsr[] = 'SYS.widget.persistent=' . ($persistent ? 'true' : 'false');
     $this->jsr[] = "xWidget.init(SESSION.get('is_login'), SESSION.get('id'))";
 }
Exemplo n.º 2
0
 public function hot()
 {
     $this->notice = "热点推荐";
     $selected = $type = "topTen";
     $s = Configure::read("section");
     $secs["topTen"] = "十大";
     $secs["recommend"] = "活动";
     foreach ($s as $k => $v) {
         if ($k === 0) {
             continue;
         }
         $secs[$k] = $v[0];
     }
     if (isset($this->params['t'])) {
         $selected = trim($this->params['t']);
         if (!in_array($selected, array_keys($secs))) {
             $this->error(ECode::$SEC_NOSECTION);
         }
         if (!isset($selected[1])) {
             $type = "section-" . $selected;
         } else {
             $type = $selected;
         }
     }
     try {
         $w = Widget::getInstance($type);
         $res = $w->wGetList();
         $res = isset($res[0]['v']['v']) ? $res[0]['v']['v'] : $res['v'];
         if (!isset($selected[1])) {
             foreach ($res as $k => $v) {
                 $text = $v["text"];
                 $text = preg_replace("|\\[.*?\\]|", "", $text, 1);
                 if (preg_match("|href=\"(.*?)\"|", $text, $url)) {
                     $url = str_replace($this->base . "/article", "/article", $url[1]);
                 } else {
                     $url = "";
                 }
                 $text = trim(preg_replace("|<[^>]*?>|", "", $text));
                 $res[$k] = array("text" => $text, "url" => $url);
             }
         }
         $this->set("hot", $res);
     } catch (WidgetNullException $e) {
         $this->error(ECode::$SEC_NOSECTION);
     }
     $this->cache(true, $w->wGetTime());
     $this->set("secs", $secs);
     $this->set("selected", $selected);
 }
Exemplo n.º 3
0
     //Search the default one
     $layout_id = $lm->getDefaultLayoutId($owner_id, $owner_type);
 } else {
     $layout_id = (int) $request->get('layout_id');
 }
 if ($layout_id || $request->get('action') == 'preferences') {
     $name = null;
     if ($request->exist('name')) {
         $param = $request->get('name');
         $name = array_pop(array_keys($param));
         $instance_id = (int) $param[$name];
     }
     switch ($request->get('action')) {
         case 'widget':
             if ($name && $layout_id) {
                 if ($widget = Widget::getInstance($name)) {
                     if ($widget->isAvailable()) {
                         $action = array_pop(array_keys($param[$name]));
                         switch ($action) {
                             case 'remove':
                                 $instance_id = (int) $param[$name][$action];
                                 $lm->removeWidget($owner_id, $owner_type, $layout_id, $name, $instance_id, $widget);
                                 break;
                             case 'add':
                             default:
                                 $lm->addWidget($owner_id, $owner_type, $layout_id, $name, $widget, $request);
                                 break;
                         }
                     }
                 }
             }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
 /**
  * function wGet get user widget
  * it just get the properties of widget, no content
  *
  * @param User $user
  * @return array('color', 'title', 'name', 'url', 'col', 'row')
  * @static
  * @access public
  */
 public static function wGet($user)
 {
     App::import('Sanitize');
     $colors = Configure::read("widget.color");
     $uid = $user->userid;
     $ret = array();
     if ($uid == 'guest') {
         $widgets = Configure::read("widget.default");
         foreach ($widgets as $name => $v) {
             try {
                 $ww = Widget::getInstance($name);
                 $title = $ww->wGetTitle();
             } catch (WidgetNullException $e) {
                 $title = array('text' => 'WIDGET MISS', 'url' => '');
                 //it will show widget name,title
                 //but show error in content
             }
             $color = isset($v["color"]) ? $v["color"] : 0;
             $title = isset($v["title"]) ? $v["title"] : $title;
             $ret[] = array("color" => $colors[$color][0], "title" => Sanitize::html($title['text']), "url" => $title['url'], "name" => $name, "col" => $v['col'], "row" => $v['row']);
         }
     } else {
         //two columns
         $two = $user->getCustom("userdefine1", 31) == 0 ? " and (col=1 or col=2)" : "";
         $db = DB::getInstance();
         $sql = "select * from " . self::$table . " where uid=? {$two} order by col,row";
         $res = $db->all($sql, array($uid));
         if (empty($res)) {
             $res = self::wInit($user);
         }
         foreach ((array) $res as $v) {
             try {
                 $title = self::getInstance($v['wid'])->wGetTitle();
             } catch (WidgetNullException $e) {
                 $title = array('text' => 'WIDGET MISS', 'url' => '');
             }
             $ret[] = array("color" => $colors[$v['color']][0], "title" => empty($v['title']) ? $title['title'] : Sanitize::html($v['title']), "name" => $v['wid'], "url" => $title['url'], "col" => $v['col'], "row" => $v['row']);
         }
     }
     return (array) $ret;
 }
Exemplo n.º 6
0
 function getCategories($widgets)
 {
     $categ = array();
     foreach ($widgets as $widget_name) {
         if ($widget = Widget::getInstance($widget_name)) {
             if ($widget->isAvailable()) {
                 $cs = explode(',', $widget->getCategory());
                 foreach ($cs as $c) {
                     if ($c = trim($c)) {
                         if (!isset($categ[$c])) {
                             $categ[$c] = array();
                         }
                         $categ[$c][$widget_name] = $widget;
                     }
                 }
             }
         }
     }
     return $categ;
 }
Exemplo n.º 7
0
 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 Widget()
 {
     return Widget::getInstance();
 }