예제 #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'))";
 }
예제 #2
0
 public function ajax_widget()
 {
     if (!isset($this->params['name'])) {
         $this->error();
     }
     $name = $this->params['name'];
     if (!$this->ByrSession->isLogin && !in_array($name, array_keys(Configure::read("widget.default")))) {
         $this->error();
     }
     try {
         $widget = Widget::getInstance($name);
         if (!$widget->wHasPerm(User::getInstance())) {
             $widget = new EWidget('你无权访问此应用');
         }
     } catch (WidgetNullException $e) {
         $widget = new EWidget();
     }
     $this->cache(true, $widget->wGetTime(), 10);
     $arr = array("id" => $name, "list" => $widget->wGetList());
     $this->set('no_html_data', $arr);
 }