예제 #1
0
파일: manager.php 프로젝트: vincenttone/daf
 /**
  * @return array
  */
 function gen_nav_from_module()
 {
     $modules = Module_ModuleManager_Register::get_instance()->get_modules_with_register('web');
     $nav_info = [];
     foreach ($modules as $_m) {
         if (!isset($_m['entry_class']) || !isset($_m['indentify'])) {
             continue;
         }
         $pre_path = $_m['indentify'];
         $entry_class = $_m['entry_class'];
         if (!method_exists($entry_class, 'register_router')) {
             continue;
         }
         $_router = call_user_func([$entry_class, 'register_router']);
         foreach ($_router as $__p => $__i) {
             if (!isset($__i[3][Const_DataAccess::URL_NAME])) {
                 continue;
             }
             $__info = $__i[3];
             $nav_info['/' . $pre_path . '/' . $__p] = $__info;
         }
     }
     $convert_nav = function ($url, $info) {
         $nav = ['name' => $info[Const_DataAccess::URL_NAME], 'path' => $url, 'weight' => isset($info[Const_DataAccess::URL_WEIGHT]) ? $info[Const_DataAccess::URL_WEIGHT] : 0];
         isset($info[Const_DataAccess::URL_PERM]) && ($nav['perm'] = $info[Const_DataAccess::URL_PERM]);
         $nav['show'] = isset($info[Const_DataAccess::URL_NAV]) && $info[Const_DataAccess::URL_NAV] ? true : false;
         return $nav;
     };
     $nav = [];
     foreach ($nav_info as $_url => $_info) {
         if (isset($_info[Const_DataAccess::URL_CATALOG])) {
             $_catalog = $_info[Const_DataAccess::URL_CATALOG];
             isset($nav[$_catalog]) || ($nav[$_catalog] = ['name' => $_info[Const_DataAccess::URL_CATALOG], 'children' => [], 'weight' => 0]);
             isset($_info[Const_DataAccess::URL_WEIGHT]) && $nav[$_catalog]['weight'] < $_info[Const_DataAccess::URL_WEIGHT] && ($nav[$_catalog]['weight'] = $_info[Const_DataAccess::URL_WEIGHT]);
             $nav[$_info[Const_DataAccess::URL_CATALOG]]['children'][$_url] = $convert_nav($_url, $_info);
         } else {
             isset($_info[Const_DataAccess::URL_WEIGHT]) && ($_info['weight'] = $_info[Const_DataAccess::URL_WEIGHT]);
             $nav[$_info[Const_DataAccess::URL_NAME]] = $convert_nav($_url, $_info);
         }
     }
     $nav[] = ['name' => '首页', 'path' => '/', 'weight' => 3000];
     foreach ($nav as &$_v) {
         if (isset($_v['children'])) {
             Lib_Array::sort_two_dimension_array($_v['children'], 'weight', false, true);
             $_f = reset($_v['children']);
             $_v['path'] = $_f['path'];
         }
     }
     Lib_Array::sort_two_dimension_array($nav, 'weight', false, false);
     $this->_nav = $nav;
     return $nav;
 }
예제 #2
0
파일: curl.php 프로젝트: vincenttone/daf
 /**
  * 通过curl post数据
  * @param string $url
  * @param array $post_data
  * @param array $header
  * @param string $cookie
  * @param int $timeout
  * @param int $retry_times
  * @param array $curl_status
  * @return mixed
  */
 public static function curlPost($url, $post_data = array(), $header = array(), $cookie = '', $timeout = 5, $retry_times = 0, &$curl_status = array())
 {
     //print_r(array("url"=>$url, "post_data" => $post_data, "header" => $header,"cookie"=>$cookie));
     $post_string = is_array($post_data) ? http_build_query($post_data) : $post_data;
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
     curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
     // 模拟的header头
     //设置连接结束后保存cookie信息的文件
     curl_setopt($ch, CURLOPT_COOKIE, $cookie);
     $retry_times < 0 && ($retry_times = 0);
     for ($i = 0; $i <= $retry_times; $i++) {
         if ($i > 0) {
             Lib_Log::info("the request of {$url} time out after {$timeout} sec and retrying the {$i} times and post_data is " . Lib_Array::varExport($post_data));
         }
         $result = curl_exec($ch);
         if ($result !== false) {
             break;
         }
     }
     $curl_status = curl_getinfo($ch);
     curl_close($ch);
     return $result;
 }