コード例 #1
0
ファイル: PrintContorller.php プロジェクト: baiduXM/gbpen
 /**
  * 手机底部功能条
  */
 public function quickBarJson()
 {
     $CommonCont = new CommonController();
     $quickbar = $CommonCont->quickBarJsonInit();
     $quickbar = json_decode($quickbar, true);
     $quickbar = $quickbar['data'];
     foreach ($quickbar as $key => $value) {
         if ($value['type'] == "colors") {
             $colors = $value['data'];
             unset($quickbar[$key]);
             break;
         }
     }
     $config_str = file_get_contents(public_path('/templates/' . $this->themename) . '/config.ini');
     $search = "/QuickBar=(.*)/i";
     $searchtype = "/Type=(.*)/i";
     $result = preg_match($search, $config_str, $config_arr);
     if (!$result) {
         $result = 1;
         $config_arr = array();
         $config_arr[1] = '#AAA,#BBB,#FFF|totop';
     }
     $lang = CustomerInfo::where('cus_id', $this->cus_id)->pluck('lang');
     $templatesC = new TemplatesController();
     $tempname = $templatesC->getTemplatesName($this->type);
     $flagPlatform = substr($tempname, 0, 2);
     $flagLanguage = substr($tempname, 2, 1);
     $customerC = new CustomerController();
     $domain = $customerC->getSwitchCustomer();
     //双站用户
     if (!empty($domain)) {
         if ($flagPlatform == 'GM') {
             //===手机===
             $language_url = $domain['switch_mobile_domain'];
         } elseif ($flagPlatform == 'GP') {
             //===PC===
             $language_url = $domain['switch_pc_domain'];
         }
         if ($flagLanguage == 9) {
             //===英文===
             $language = '中文版';
         } elseif ($flagLanguage == 0) {
             //===中文===
             $language = 'English';
         }
     }
     if ($result != 0) {
         //===?===
         if (trim($config_arr[1]) != "custom") {
             //===非自定义===
             $quickbar_arr = explode('|', $config_arr[1]);
             $config['enable'] = true;
             if ($this->type == 'pc') {
                 $config['type'] = 'p1';
             } else {
                 if ($this->type == 'mobile') {
                     $config['type'] = 'm1';
                 } else {
                     $config['type'] = 'p1';
                 }
             }
             if ($lang == 'en') {
                 $config['language'] = 'en';
             } else {
                 $config['language'] = 'cn';
             }
             $config['style'] = array();
             if (!isset($colors[$this->type])) {
                 $tmpStyleConfigQuickbar = explode(',', $quickbar_arr[0]);
             } else {
                 $tmpStyleConfigQuickbar = $colors[$this->type];
             }
             if (count($tmpStyleConfigQuickbar)) {
                 $keys = array('mainColor', 'secondColor', 'textColor', 'iconColor');
                 foreach ($tmpStyleConfigQuickbar as $key => $val) {
                     $arr = explode('|', $val);
                     $config['style'][$keys[$key]] = $arr[0];
                 }
                 if (!key_exists('iconColor', $config['style'])) {
                     $config['style']['iconColor'] = $config['style']['textColor'] ? $config['style']['textColor'] : '';
                 }
             }
             $config['module'] = array();
             if (count($quickbar_arr) > 1) {
                 $tmpModulesConfigQuickbar = explode(',', trim($quickbar_arr[1]));
                 foreach ($tmpModulesConfigQuickbar as $key => $val) {
                     if ($val == 'tel') {
                         $tel = Customerinfo::where('cus_id', $this->cus_id)->pluck('telephone');
                         $config['module']['tel'] = $tel;
                         //数据库联系电话
                     } elseif ($val == 'totop') {
                         $config['module']['totop'] = 1;
                     }
                 }
             } else {
                 $config['module'] = array();
             }
             foreach ($quickbar as $key => $val) {
                 if ($this->type == 'pc') {
                     $quickbar[$key]['enable'] = intval($quickbar[$key]['enable_pc']);
                 } else {
                     $quickbar[$key]['enable'] = intval($quickbar[$key]['enable_mobile']);
                 }
                 if ($quickbar[$key]['type'] == 'tel') {
                     $quickbar[$key]['link'] = "tel:" . $quickbar[$key]['data'];
                 } elseif ($quickbar[$key]['type'] == 'sms') {
                     $quickbar[$key]['link'] = "sms:" . $quickbar[$key]['data'];
                 } elseif ($quickbar[$key]['type'] == 'im') {
                     $qq = explode('|', $quickbar[$key]['data']);
                     $qq = explode(':', $qq[0]);
                     $qq = explode('@', isset($qq[1]) ? $qq[1] : '');
                     if ($this->type == 'pc') {
                         $quickbar[$key]['link'] = 'http://wpa.qq.com/msgrd?v=3&uin=' . $qq[0] . '&site=qq&menu=yes';
                     } else {
                         $quickbar[$key]['link'] = 'http://wpd.b.qq.com/cgi/get_m_sign.php?uin=' . $qq[0];
                     }
                 } elseif ($quickbar[$key]['type'] == 'map') {
                     if ($quickbar[$key]['data'] != null) {
                         $location = explode('|', $quickbar[$key]['data']);
                         $address = explode(',', $location[1]);
                         $quickbar[$key]['link'] = 'http://api.map.baidu.com/marker?location=' . $address[1] . ',' . $address[0] . '&title=目标位置&content=' . $location[0] . '&output=html';
                     } else {
                         $address = CustomerInfo::where('cus_id', $this->cus_id)->pluck('address');
                         $quickbar[$key]['link'] = 'http://api.map.baidu.com/geocoder?address=' . $address . '&output=html';
                     }
                 } elseif ($quickbar[$key]['type'] == 'link') {
                     if ($quickbar[$key]['data'] != null) {
                         $url_arr = explode('|', $quickbar[$key]['data']);
                         $quickbar[$key]['link'] = $url_arr[0];
                     }
                 } elseif ($quickbar[$key]['type'] == 'search') {
                     if ($this->showtype == 'preview') {
                         $quickbar[$key]['data'] = 'http://' . $_SERVER['HTTP_HOST'] . '/search-preview';
                     } else {
                         $quickbar[$key]['data'] = $this->domain . '/search.php';
                     }
                 } elseif ($quickbar[$key]['type'] == 'follow') {
                     if ($this->showtype == 'preview') {
                         if (strpos($quickbar[$key]['data'], 'http://') === FALSE) {
                             $quickbar[$key]['data'] = $quickbar[$key]['serurl'];
                         }
                     }
                 }
                 //TODO:删除enable_pc/enable_mobile键值
                 unset($quickbar[$key]['enable_pc']);
                 unset($quickbar[$key]['enable_mobile']);
             }
             //快捷导航
             $navs = Classify::where('cus_id', $this->cus_id)->where('mobile_show', 1)->select('id', 'type', 'open_page', 'name', 'en_name', 'view_name', 'icon', 'url', 'p_id')->OrderBy('sort', 'asc')->get()->toArray();
             if (count($navs)) {
                 if ($this->showtype == 'preview') {
                     foreach ($navs as &$nav) {
                         $nav['icon'] = '<i class="iconfont">' . $nav['icon'] . '</i>';
                         if (in_array($nav['type'], array('1', '2', '3', '4', '5', '9'))) {
                             if ($nav['view_name']) {
                                 $nav['url'] = $this->domain . "/category/v/" . $nav['view_name'];
                             } else {
                                 $nav['url'] = $this->domain . "/category/" . $nav['id'];
                             }
                         }
                     }
                 } else {
                     foreach ($navs as &$nav) {
                         $nav['icon'] = '<i class="iconfont">' . $nav['icon'] . '</i>';
                         if (in_array($nav['type'], array('1', '2', '3', '4', '5', '9'))) {
                             if ($nav['view_name']) {
                                 $nav['url'] = $this->domain . "/category/v/" . $nav['view_name'] . '.html';
                             } else {
                                 $nav['url'] = $this->domain . "/category/" . $nav['id'] . '.html';
                             }
                         }
                     }
                 }
             }
             $classify = new Classify();
             $catlist = $classify->toTree($navs);
             if (!is_array($catlist)) {
                 $catlist = array();
             }
             array_unshift($catlist, array('id' => null, 'name' => '首页', 'en_name' => 'Home', 'url' => $this->site_url, 'childmenu' => null));
             $quickbarCallback = array('config' => $config, 'quickbar' => $quickbar, 'catlist' => $catlist);
             if ($this->showtype == 'preview') {
                 echo "quickbarCallback(" . json_encode($quickbarCallback) . ")";
                 //===返回===
             } else {
                 if ($this->type == 'pc') {
                     file_put_contents(public_path("customers/" . $this->customer . '/quickbar.json'), "quickbarCallback(" . json_encode($quickbarCallback) . ")");
                 } else {
                     file_put_contents(public_path("customers/" . $this->customer . '/mobile' . '/quickbar.json'), "quickbarCallback(" . json_encode($quickbarCallback) . ")");
                 }
             }
         } else {
             //===自定义===
             $config_arr[1] = '#AAA,#BBB,#FFF|tel';
             $quickbar_arr = explode('|', $config_arr[1]);
             $tmpStyleConfigQuickbar = explode(',', $quickbar_arr[0]);
             $config['enable'] = true;
             if ($this->type == 'pc') {
                 $config['type'] = 'custom';
             } else {
                 $config['type'] = 'custom';
             }
             $config['style'] = array();
             if (count($tmpStyleConfigQuickbar)) {
                 $keys = array('mainColor', 'secondColor', 'textColor', 'iconColor');
                 foreach ($tmpStyleConfigQuickbar as $key => $val) {
                     $arr = explode('|', $val);
                     $config['style'][$keys[$key]] = $arr[0];
                 }
                 if (!key_exists('iconColor', $config['style'])) {
                     $config['style']['iconColor'] = $config['style']['textColor'] ? $config['style']['textColor'] : '';
                 }
             }
             foreach ($quickbar as $key => $val) {
                 if ($this->type == 'pc') {
                     $quickbar[$key]['enable'] = intval($quickbar[$key]['enable_pc']);
                 } else {
                     $quickbar[$key]['enable'] = intval($quickbar[$key]['enable_mobile']);
                 }
                 //TODO:删除enable_pc/enable_mobile键值
                 unset($quickbar[$key]['enable_pc']);
                 unset($quickbar[$key]['enable_mobile']);
             }
             foreach ($quickbar as $key => $val) {
                 if ($quickbar[$key]['type'] == 'tel') {
                     $quickbar[$key]['link'] = "tel:" . $quickbar[$key]['data'];
                 } elseif ($quickbar[$key]['type'] == 'sms') {
                     $quickbar[$key]['link'] = "sms:" . $quickbar[$key]['data'];
                 } elseif ($quickbar[$key]['type'] == 'im') {
                     $qq = explode('|', $quickbar[$key]['data']);
                     $qq = explode(':', $qq[0]);
                     $qq = explode('@', $qq[1]);
                     if ($this->type == 'pc') {
                         $quickbar[$key]['link'] = 'http://wpa.qq.com/msgrd?v=3&uin=' . $qq[0] . '&site=qq&menu=yes';
                     } else {
                         $quickbar[$key]['link'] = 'http://wpd.b.qq.com/cgi/get_m_sign.php?uin=' . $qq[0];
                     }
                 } elseif ($quickbar[$key]['type'] == 'map') {
                     if ($quickbar[$key]['data'] != null) {
                         $location = explode('|', $quickbar[$key]['data']);
                         $address = explode(',', $location[1]);
                         $quickbar[$key]['link'] = 'http://api.map.baidu.com/marker?location=' . $address[1] . ',' . $address[0] . '&title=目标位置&content=' . $location[0] . '&output=html';
                     } else {
                         $address = CustomerInfo::where('cus_id', $this->cus_id)->pluck('address');
                         $quickbar[$key]['link'] = 'http://api.map.baidu.com/geocoder?address=' . $address . '&output=html';
                     }
                 } elseif ($quickbar[$key]['type'] == 'link') {
                     if ($quickbar[$key]['data'] != null) {
                         $url_arr = explode('|', $quickbar[$key]['data']);
                         $quickbar[$key]['link'] = $url_arr[0];
                     }
                 } elseif ($quickbar[$key]['type'] == 'search') {
                     if ($this->showtype == 'preview') {
                         $quickbar[$key]['data'] = 'http://' . $_SERVER['HTTP_HOST'] . '/search-preview';
                     } else {
                         $quickbar[$key]['data'] = $this->domain . '/search.php';
                     }
                 } elseif ($quickbar[$key]['type'] == 'follow') {
                     if ($this->showtype == 'preview') {
                         if (strpos($quickbar[$key]['data'], 'http://') === FALSE) {
                             $quickbar[$key]['data'] = $quickbar[$key]['serurl'];
                         }
                     }
                 }
             }
             $navs = Classify::where('cus_id', $this->cus_id)->where('mobile_show', 1)->select('id', 'type', 'name', 'en_name', 'view_name', 'icon', 'url', 'p_id', 'en_name')->OrderBy('sort', 'asc')->get()->toArray();
             if (count($navs)) {
                 if ($this->showtype == 'preview') {
                     foreach ($navs as &$nav) {
                         $nav['icon'] = '<i class="iconfont">' . $nav['icon'] . '</i>';
                         if (in_array($nav['type'], array('1', '2', '3', '4'))) {
                             if ($nav['view_name']) {
                                 $nav['url'] = $this->domain . "/category/v/" . $nav['view_name'];
                             } else {
                                 $nav['url'] = $this->domain . "/category/" . $nav['id'];
                             }
                         }
                     }
                 } else {
                     foreach ($navs as &$nav) {
                         $nav['icon'] = '<i class="iconfont">' . $nav['icon'] . '</i>';
                         if (in_array($nav['type'], array('1', '2', '3', '4'))) {
                             if ($nav['view_name']) {
                                 $nav['url'] = $this->domain . "/category/v/" . $nav['view_name'] . '.html';
                             } else {
                                 $nav['url'] = $this->domain . "/category/" . $nav['id'] . '.html';
                             }
                         }
                     }
                 }
             }
             $classify = new Classify();
             $catlist = $classify->toTree($navs);
             if (!is_array($catlist)) {
                 $catlist = array();
             }
             array_unshift($catlist, array('id' => null, 'name' => '首页', 'en_name' => 'Home', 'url' => $this->site_url, 'childmenu' => null));
             if (!empty($domain)) {
                 $catlist[] = array('id' => null, 'name' => $language, 'en_name' => 'language', 'url' => $language_url, 'childmenu' => null);
                 //===
             }
             $quickbarCallback = array('config' => $config, 'quickbar' => $quickbar, 'catlist' => $catlist);
             if ($this->showtype == 'preview') {
                 echo "quickbarCallback(" . json_encode($quickbarCallback) . ")";
             } else {
                 if ($this->type == 'pc') {
                     file_put_contents(public_path("customers/" . $this->customer . '/quickbar.json'), "quickbarCallback(" . json_encode($quickbarCallback) . ")");
                 } else {
                     file_put_contents(public_path("customers/" . $this->customer . '/mobile' . '/quickbar.json'), "quickbarCallback(" . json_encode($quickbarCallback) . ")");
                 }
             }
         }
     }
 }