Example #1
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;
 }