mCids = array(); self::load_xml(); } private function load_xml() { libxml_use_internal_errors(true); $xml = simplexml_load_string($this->content()); if($xml === false) { $err_msg = json_encode(libxml_get_errors(),JSON_UNESCAPED_UNICODE); Log::record("{$err_msg}", Log::ERR); libxml_clear_errors(); throw new Exception("无法解析XML."); } $url = RESOURCE_SITE_URL . self::img_path; $this->mCategories = array(); foreach($xml->children() as $xitem) { $item = array(); $attrs = $xitem->attributes(); $title = $attrs['title']->__toString(); $pid = $attrs['id']->__toString(); $cids = $attrs['cids']->__toString(); $img = $attrs['img']->__toString(); $item['name'] = $title; $item['hot_id'] = $pid; $item['img'] = $url . '/' . $img; $item['subitem'] = array(); $this->add_cids($pid,$cids); foreach($xitem->children() as $xsubitem) { $subitem = array(); $sattrs = $xsubitem->attributes(); $title = $sattrs['title']->__toString(); $sid = $sattrs['id']->__toString(); $cids = $sattrs['cids']->__toString(); $img = $sattrs['img']->__toString(); $subitem['name'] = $title; $subitem['hot_id'] = $sid; $subitem['img'] = $url . '/' . $img; array_push($item['subitem'],$subitem); $this->add_cids($sid,$cids); $this->add_cids($pid,$cids); } array_push($this->mCategories,$item); } } private function add_cids($id,$cids) { if(!array_key_exists($id,$this->mCids)) { $this->mCids[$id] = array(); } $cids = explode(',',$cids); foreach($cids as $val) { $cur_cids = &$this->mCids[$id]; if(!empty($val) && !in_array($val,$cur_cids)) { array_push($cur_cids,$val); } } } public function categories() { try { return $this->mCategories; } catch (Exception $ex) { return array(); } } public function cids($id) { try { if(!array_key_exists($id,$this->mCids)) { return array(); } else { return $this->mCids[$id]; } } catch (Exception $ex) { return array(); } } private function content() { $content = << EOD; return $content; } } class brand_helper { static function brandex() { $prefix = 'mb_'; $ret = rcache('brandex', $prefix); if(empty($ret)) { $model = Model('brand'); $items = $model->field('brand_id,brand_logo,brand_name')->where(array('brand_apply' => '1'))->order('brand_sort asc')->limit(false)->select(); $brands = []; foreach ($items as $brand) { $image = UPLOAD_SITE_URL . $brand['brand_logo']; $ret = getimagesize($image,$info); if($ret != false) { $brand['brand_logo'] = $image; $brands[] = $brand; } } $block = special_helper::format_grid_brands($brands); wcache("brandex", array("brands" => serialize($brands),"block" => serialize($block)), $prefix); $result = array("brands" => $brands,"block" => $block); } else { $brands = unserialize($ret['brands']); $block = unserialize($ret['block']); $result = array("brands" => $brands,"block" => $block); } return $result; } static function brands() { $prefix = 'mb_'; $ret = rcache('brand', $prefix); if(empty($ret)) { $model = Model(); $brand_area_list = $model->table('brand_area')->order('area_sort asc')->limit(false)->select(); $filed = 'brand_id,brand_name,brand_pic,brand_img_bg,brand_img_logo,brand_area_id'; $brand_c_list = $model->table('brand')->field($filed)->where(array('brand_apply' => '1'))->order('brand_sort asc')->limit(false)->select(); $brands = array(); foreach ($brand_area_list as $brand_area) { foreach ($brand_c_list as $brand) { $brand['brand_pic'] = image_helper::format_brand_img_rect($brand['brand_pic']); $brand['brand_img_bg'] = image_helper::format_brand_img_bg($brand['brand_img_bg']); $brand['brand_img_logo'] = image_helper::format_brand_img_circle($brand['brand_img_logo']); if ($brand['brand_area_id'] == $brand_area['area_id']) { if (empty($brand_area['data'])) { $brand_area['data'] = array(); } array_push($brand_area['data'], $brand); } } if (!empty($brand_area['data'])) { array_push($brands, $brand_area); } } wcache("brand", array("brands" => serialize($brands)), $prefix); } else { $brands = unserialize($ret['brands']); } return $brands; } }