/** * action访问控制,在 **登陆成功** 后执行的第一项权限检测任务 accessControl * @return boolean|null 返回值必须使用 `===` 进行判断 * 返回 **false**, 不允许任何人访问(超管除外) * 返回 **true**, 允许任何管理员访问,无需执行节点权限检测 * 返回 **null**, 需要继续执行节点权限检测决定是否允许访问 */ protected final function accessControl() { /* 管理员允许访问任何页面 */ if (IS_ROOT) { return true; } $deny = C('AUTH_CONFIG.AUTH_DENY_VISIT'); //非超管禁止访问的模块 $allow = C('AUTH_CONFIG.AUTH_ALLOW_VISIT'); //非超管可直接访问的模块 $allowAction = C('AUTH_CONFIG.AUTH_ALLOW_ACTION'); //非超管可直接访问的节点 $check = strtolower(CONTROLLER_NAME . '/' . ACTION_NAME); if (!empty($deny) && in_array_case($check, $deny)) { return false; } if (!empty($allow) && in_array_case($check, $allow)) { return true; } if (!empty($allowAction) && in_array_case(ACTION_NAME, $allowAction)) { return true; } /* 需要检测节点权限 */ return NULL; }
public function _initialize() { /* 检测需要验证 user_id,auth_token 的节点*/ $check = str_replace('_', '', strtolower(CONTROLLER_NAME)) . '/' . ACTION_NAME; if (in_array_case($check, C('AUTH_TOKEN_CHECK'))) { token_check(); } }
public function _initialize() { $ip = get_client_ip(); $iplist = array('127.0.0.1', '0.0.0.0', 'localhost'); if (!in_array_case($ip, $iplist)) { $this->error("非法来源"); } }
/** * action访问控制,在 **登陆成功** 后执行的第一项权限检测任务 * * @return boolean|null 返回值必须使用 `===` 进行判断 * * 返回 **false**, 不允许任何人访问(超管除外) * 返回 **true**, 允许任何管理员访问,无需执行节点权限检测 * 返回 **null**, 需要继续执行节点权限检测决定是否允许访问 */ protected final function accessControl() { if (IS_ROOT) { return true; //管理员允许访问任何页面 } $allow = C('ALLOW_VISIT'); $deny = C('DENY_VISIT'); $check = strtolower(CONTROLLER_NAME . '/' . ACTION_NAME); if (!empty($deny) && in_array_case($check, $deny)) { return false; //非超管禁止访问deny中的方法 } if (!empty($allow) && in_array_case($check, $allow)) { return true; } return null; //需要检测节点权限 }
/** * action访问控制,执行的第一项权限检测任务 * @return boolean|null 返回值必须使用 `===` 进行判断 * 返回 **false**, 不允许任何人访问(超管除外) * 返回 **true**, 允许任何管理员访问,无需执行节点权限检测 * 返回 **null**, 需要继续执行节点权限检测决定是否允许访问 * @author liuxiaolin <*****@*****.**> */ protected function accessControll() { if (IS_ROOT) { return true; } //不受权限管理的方法控制器 $allow = C('ALLOW_VISIT'); //只有Admin才能访问的方法控制器 $deny = C('DENY_VISIT'); $check = strtolower(MODULE_NAME . '_' . CONTROLLER_NAME . '_' . ACTION_NAME); if (!empty($deny) && in_array_case($check, $deny)) { return false; } if (!empty($allow) && in_array_case($check, $allow)) { return true; } //需要检测节点权限 return NULL; }
/** * 显示页面Trace信息 * * @access private */ private function showTrace() { // 系统默认显示信息 $files = get_included_files(); $info = array(); foreach ($files as $key => $file) { $info[] = $file . ' ( ' . number_format(filesize($file) / 1024, 2) . ' KB )'; } $trace = array(); $base = array('请求信息' => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']) . ' ' . $_SERVER['SERVER_PROTOCOL'] . ' ' . $_SERVER['REQUEST_METHOD'] . ' : ' . __SELF__, '运行时间' => $this->showTime(), '吞吐率' => number_format(1 / G('beginTime', 'viewEndTime'), 2) . 'req/s', '内存开销' => MEMORY_LIMIT_ON ? number_format((memory_get_usage() - $GLOBALS['_startUseMems']) / 1024, 2) . ' kb' : '不支持', '查询信息' => N('db_query') . ' queries ' . N('db_write') . ' writes ', '文件加载' => count(get_included_files()), '缓存信息' => N('cache_read') . ' gets ' . N('cache_write') . ' writes ', '配置加载' => count(C()), '会话信息' => 'SESSION_ID=' . session_id()); // 读取应用定义的Trace文件 $traceFile = COMMON_PATH . 'Conf/trace.php'; if (is_file($traceFile)) { $base = array_merge($base, include $traceFile); } $debug = trace(); $tabs = C('TRACE_PAGE_TABS', null, $this->tracePageTabs); foreach ($tabs as $name => $title) { switch (strtoupper($name)) { case 'BASE': // 基本信息 $trace[$title] = $base; break; case 'FILE': // 文件信息 $trace[$title] = $info; break; default: // 调试信息 $name = strtoupper($name); if (strpos($name, '|')) { // 多组信息 $names = explode('|', $name); $result = array(); foreach ($names as $name) { $result += isset($debug[$name]) ? $debug[$name] : array(); } $trace[$title] = $result; } else { $trace[$title] = isset($debug[$name]) ? $debug[$name] : ''; } } } if ($save = C('PAGE_TRACE_SAVE')) { // 保存页面Trace日志 if (is_array($save)) { // 选择选项卡保存 $tabs = C('TRACE_PAGE_TABS', null, $this->tracePageTabs); $array = array(); foreach ($save as $tab) { $array[] = $tabs[$tab]; } } $content = date('[ c ]') . ' ' . get_client_ip() . ' ' . $_SERVER['REQUEST_URI'] . "\r\n"; foreach ($trace as $key => $val) { if (!isset($array) || in_array_case($key, $array)) { $content .= '[ ' . $key . " ]\r\n"; if (is_array($val)) { foreach ($val as $k => $v) { $content .= (!is_numeric($k) ? $k . ':' : '') . print_r($v, true) . "\r\n"; } } else { $content .= print_r($val, true) . "\r\n"; } $content .= "\r\n"; } } error_log(str_replace('<br/>', "\r\n", $content), 3, C('LOG_PATH') . date('y_m_d') . '_trace.log'); } unset($files, $info, $base); // 调用Trace页面模板 ob_start(); include C('TMPL_TRACE_FILE') ? C('TMPL_TRACE_FILE') : THINK_PATH . 'Tpl/page_trace.tpl'; return ob_get_clean(); }
/** * 获得实际的模块名称 */ private static function getModule($var) { $module = !empty($_GET[$var]) ? $_GET[$var] : C('DEFAULT_MODULE'); unset($_GET[$var]); $allowList = C('MODULE_ALLOW_LIST'); // 允许的模块列表 if (!empty($allowList) && is_array($allowList) && !in_array_case($module, $allowList)) { E(L('_MODULE_NOT_EXIST_') . ':' . strip_tags(ucfirst($module))); } if ($maps = C('URL_MODULE_MAP')) { if (isset($maps[strtolower($module)])) { // 记录当前别名 define('MODULE_ALIAS', strtolower($module)); // 获取实际的模块名 return ucfirst($maps[MODULE_ALIAS]); } elseif (array_search(strtolower($module), $maps)) { // 禁止访问原始模块 return ''; } } return strip_tags(ucfirst($module)); }
/** * URL映射到控制器 * @access public * @return void */ public static function dispatch() { $varPath = C('VAR_PATHINFO'); $varModule = C('VAR_MODULE'); $varController = C('VAR_CONTROLLER'); $varAction = C('VAR_ACTION'); if (isset($_GET[$varPath])) { // 判断URL里面是否有兼容模式参数 $_SERVER['PATH_INFO'] = $_GET[$varPath]; unset($_GET[$varPath]); } elseif (IS_CLI) { // CLI模式下 index.php module/controller/action/params/... $_SERVER['PATH_INFO'] = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : ''; } // 开启子域名部署 if (C('APP_SUB_DOMAIN_DEPLOY')) { $rules = C('APP_SUB_DOMAIN_RULES'); if (isset($rules[$_SERVER['HTTP_HOST']])) { // 完整域名或者IP配置 define('APP_DOMAIN', $_SERVER['HTTP_HOST']); // 当前完整域名 $rule = $rules[APP_DOMAIN]; } else { if (strpos(C('APP_DOMAIN_SUFFIX'), '.')) { // com.cn net.cn $domain = array_slice(explode('.', $_SERVER['HTTP_HOST']), 0, -3); } else { $domain = array_slice(explode('.', $_SERVER['HTTP_HOST']), 0, -2); } if (!empty($domain)) { $subDomain = implode('.', $domain); define('SUB_DOMAIN', $subDomain); // 当前完整子域名 $domain2 = array_pop($domain); // 二级域名 if ($domain) { // 存在三级域名 $domain3 = array_pop($domain); } if (isset($rules[$subDomain])) { // 子域名 $rule = $rules[$subDomain]; } elseif (isset($rules['*.' . $domain2]) && !empty($domain3)) { // 泛三级域名 $rule = $rules['*.' . $domain2]; $panDomain = $domain3; } elseif (isset($rules['*']) && !empty($domain2) && 'www' != $domain2) { // 泛二级域名 $rule = $rules['*']; $panDomain = $domain2; } } } if (!empty($rule)) { // 子域名部署规则 '子域名'=>array('模块名[/控制器名]','var1=a&var2=b'); if (is_array($rule)) { list($rule, $vars) = $rule; } $array = explode('/', $rule); // 模块绑定 $_GET[$varModule] = array_shift($array); define('BIND_MODULE', $_GET[$varModule]); $domainModule = true; // 控制器绑定 if (!empty($array)) { $controller = array_shift($array); if ($controller) { $_GET[$varController] = $controller; $domainController = true; } } if (isset($vars)) { // 传入参数 parse_str($vars, $parms); if (isset($panDomain)) { $pos = array_search('*', $parms); if (false !== $pos) { // 泛域名作为参数 $parms[$pos] = $panDomain; } } $_GET = array_merge($_GET, $parms); } } } elseif (isset($_GET[$varModule])) { // 绑定模块 define('BIND_MODULE', $_GET[$varModule]); } // 分析PATHINFO信息 if (!isset($_SERVER['PATH_INFO'])) { $types = explode(',', C('URL_PATHINFO_FETCH')); foreach ($types as $type) { if (0 === strpos($type, ':')) { // 支持函数判断 $_SERVER['PATH_INFO'] = call_user_func(substr($type, 1)); break; } elseif (!empty($_SERVER[$type])) { $_SERVER['PATH_INFO'] = 0 === strpos($_SERVER[$type], $_SERVER['SCRIPT_NAME']) ? substr($_SERVER[$type], strlen($_SERVER['SCRIPT_NAME'])) : $_SERVER[$type]; break; } } } if (empty($_SERVER['PATH_INFO'])) { $_SERVER['PATH_INFO'] = ''; } $depr = C('URL_PATHINFO_DEPR'); define('MODULE_PATHINFO_DEPR', $depr); define('__INFO__', trim($_SERVER['PATH_INFO'], '/')); // URL后缀 define('__EXT__', strtolower(pathinfo($_SERVER['PATH_INFO'], PATHINFO_EXTENSION))); if (__INFO__ && C('MULTI_MODULE') && !isset($_GET[$varModule])) { // 获取模块 $paths = explode($depr, __INFO__, 2); $allowList = C('MODULE_ALLOW_LIST'); $module = preg_replace('/\\.' . __EXT__ . '$/i', '', $paths[0]); if (empty($allowList) || is_array($allowList) && in_array_case($module, $allowList)) { $_GET[$varModule] = $module; $_SERVER['PATH_INFO'] = isset($paths[1]) ? $paths[1] : ''; } else { $_SERVER['PATH_INFO'] = __INFO__; } } else { $_SERVER['PATH_INFO'] = __INFO__; } // 获取模块名称 define('MODULE_NAME', self::getModule($varModule)); // 检测模块是否存在 if (MODULE_NAME && (!in_array_case(MODULE_NAME, C('MODULE_DENY_LIST')) || $domainModule) && is_dir(APP_PATH . MODULE_NAME)) { // 定义当前模块路径 define('MODULE_PATH', APP_PATH . MODULE_NAME . '/'); // 加载模块配置文件 if (is_file(MODULE_PATH . 'Conf/config.php')) { C(include MODULE_PATH . 'Conf/config.php'); } /**加载模板公共配置文件 * 2015-5-14 13:43 * 增加模板配置文件加载 start * @author 郑钟良<*****@*****.**> */ if (is_file(OS_THEME_PATH . 'config.php')) { $TMPL_PARSE_STRING = C('TMPL_PARSE_STRING'); C(include OS_THEME_PATH . 'config.php'); $NEW_TMPL_PARSE_STRING = C('TMPL_PARSE_STRING'); $NEW_TMPL_PARSE_STRING = array_merge($NEW_TMPL_PARSE_STRING, $TMPL_PARSE_STRING); C('TMPL_PARSE_STRING', $NEW_TMPL_PARSE_STRING); } /** * 2015-5-14 13:43 * 增加模板配置文件加载 end * @author 郑钟良<*****@*****.**> */ // 加载模块别名定义 if (is_file(MODULE_PATH . 'Conf/alias.php')) { Think::addMap(include MODULE_PATH . 'Conf/alias.php'); } // 加载模块函数文件 if (is_file(MODULE_PATH . 'Common/function.php')) { include MODULE_PATH . 'Common/function.php'; } } else { E(L('_MODULE_NOT_EXIST_') . ':' . MODULE_NAME, 815); } if ('' != $_SERVER['PATH_INFO']) { // 检查禁止访问的URL后缀 if (C('URL_DENY_SUFFIX') && preg_match('/\\.(' . trim(C('URL_DENY_SUFFIX'), '.') . ')$/i', $_SERVER['PATH_INFO'])) { send_http_status(404); exit; } if (C('URL_HTML_SUFFIX')) { $_SERVER['PATH_INFO'] = preg_replace('/\\.(' . trim(C('URL_HTML_SUFFIX'), '.') . ')$/i', '', $_SERVER['PATH_INFO']); } else { $_SERVER['PATH_INFO'] = preg_replace('/\\.' . __EXT__ . '$/i', '', $_SERVER['PATH_INFO']); } $depr = C('URL_PATHINFO_DEPR'); $paths = explode($depr, trim($_SERVER['PATH_INFO'], $depr)); if (!isset($_GET[$varController])) { // 获取控制器 $_GET[$varController] = array_shift($paths); } // 获取操作 $_GET[$varAction] = array_shift($paths); // 解析剩余的URL参数 $var = array(); if (C('URL_PARAMS_BIND') && 1 == C('URL_PARAMS_BIND_TYPE')) { // URL参数按顺序绑定变量 $var = $paths; } else { preg_replace_callback('/(\\w+)\\/([^\\/]+)/', function ($match) use(&$var) { $var[$match[1]] = strip_tags($match[2]); }, implode('/', $paths)); } $_GET = array_merge($var, $_GET); } define('CONTROLLER_NAME', self::getController($varController)); define('ACTION_NAME', self::getAction($varAction)); //保证$_REQUEST正常取值 $_REQUEST = array_merge($_POST, $_GET); }
/** * Returns true if the card belongs to at least one of the categories. */ function inCategories(&$categories) { $our_categories = $this->getCategories(); foreach ($categories as $category) { if (in_array_case($category, $our_categories)) { return true; } } return false; }
/** * Prints the vCard as HTML. */ function print_vcard($card, $hide) { $names = array('FN', 'TITLE', 'ORG', 'TEL', 'EMAIL', 'URL', 'ADR', 'BDAY', 'NOTE', 'PHOTO'); $row = 0; foreach ($names as $name) { if (in_array_case($name, $hide)) { continue; } $properties = $card->getProperties($name); if ($properties) { foreach ($properties as $property) { $show = true; $types = $property->params['TYPE']; if ($types) { foreach ($types as $type) { if (in_array_case($type, $hide)) { $show = false; break; } } } if ($show) { $class = $row++ % 2 == 0 ? "property-even" : "property-odd"; $this->print_vcard_property($property, $class, $hide); } } } } }
private static function dispatch() { //解析路由 $varModule = C('VAR_MODULE'); $varController = C('VAR_CONTROLLER'); $varAction = C('VAR_ACTION'); $urlCase = C('URL_CASE_INSENSITIVE'); // 分析PATHINFO信息 if (!isset($_SERVER['PATH_INFO'])) { $types = explode(',', C('URL_PATHINFO_FETCH')); foreach ($types as $type) { if (0 === strpos($type, ':')) { // 支持函数判断 $_SERVER['PATH_INFO'] = call_user_func(substr($type, 1)); break; } elseif (!empty($_SERVER[$type])) { $_SERVER['PATH_INFO'] = 0 === strpos($_SERVER[$type], $_SERVER['SCRIPT_NAME']) ? substr($_SERVER[$type], strlen($_SERVER['SCRIPT_NAME'])) : $_SERVER[$type]; break; } } } $depr = C('URL_PATHINFO_DEPR'); define('MODULE_PATHINFO_DEPR', $depr); if (empty($_SERVER['PATH_INFO'])) { $_SERVER['PATH_INFO'] = ''; define('__INFO__', ''); define('__EXT__', ''); } else { //如果是path_info模式,则对链接进行解析 define('__INFO__', trim($_SERVER['PATH_INFO'], '/')); // 获取URL后缀,如html define('__EXT__', strtolower(pathinfo($_SERVER['PATH_INFO'], PATHINFO_EXTENSION))); $_SERVER['PATH_INFO'] = __INFO__; if (!Route::check()) { if (__INFO__ && C('MULTI_MODULE')) { // 获取模块名 $paths = explode($depr, __INFO__, 2); $module = preg_replace('/\\.' . __EXT__ . '$/i', '', $paths[0]); $_GET[$varModule] = $module; $_SERVER['PATH_INFO'] = isset($paths[1]) ? $paths[1] : ''; } } } // URL常量 define('__SELF__', strip_tags($_SERVER[C('URL_REQUEST_URI')])); // 获取模块名称 define('MODULE_NAME', self::getModule($varModule)); // 检测模块是否存在 if (!in_array_case(MODULE_NAME, C('MODULE_DENY_LIST')) && is_dir(APP_PATH . MODULE_NAME)) { // 定义当前模块路径 define('MODULE_PATH', APP_PATH . MODULE_NAME . '/'); // 定义当前模块的模版缓存路径 C('CACHE_PATH', CACHE_PATH . MODULE_NAME . '/'); // 定义当前模块的日志目录 C('LOG_PATH', realpath(LOG_PATH) . '/' . MODULE_NAME . '/'); //导入应用自定义的配置文件 if (is_file(MODULE_PATH . 'Conf/config.php')) { C(include MODULE_PATH . 'Conf/config.php'); } } else { exit("Not Found This Module!"); } if (!defined('__APP__')) { $urlMode = C('URL_MODEL'); if ($urlMode == URL_REWRITE) { //如果是重写模式,则去除index.php $url = dirname(_PHP_FILE_); if ($url == '/' || $url == '\\') { $url = ''; } define('PHP_FILE', $url); } else { define('PHP_FILE', _PHP_FILE_); } // 当前应用地址 define('__APP__', strip_tags(PHP_FILE)); } // 模块URL地址 define('__MODULE__', __APP__ . '/' . ($urlCase ? strtolower(MODULE_NAME) : MODULE_NAME)); if ('' != $_SERVER['PATH_INFO'] && !Route::check()) { // 检测路由规则 如果没有则按默认规则调度URL // 检查禁止访问的URL后缀 if (C('URL_DENY_SUFFIX') && preg_match('/\\.(' . trim(C('URL_DENY_SUFFIX'), '.') . ')$/i', $_SERVER['PATH_INFO'])) { exit("404 Not Found"); } // 去除URL后缀 $_SERVER['PATH_INFO'] = preg_replace(C('URL_HTML_SUFFIX') ? '/\\.(' . trim(C('URL_HTML_SUFFIX'), '.') . ')$/i' : '/\\.' . __EXT__ . '$/i', '', $_SERVER['PATH_INFO']); $depr = C('URL_PATHINFO_DEPR'); $paths = explode($depr, trim($_SERVER['PATH_INFO'], $depr)); $_GET[$varController] = array_shift($paths); // 获取操作 $_GET[$varAction] = array_shift($paths); // 解析剩余的URL参数 $var = array(); if (C('URL_PARAMS_BIND') && 1 == C('URL_PARAMS_BIND_TYPE')) { // URL参数按顺序绑定变量 $var = $paths; } else { preg_replace_callback('/(\\w+)\\/([^\\/]+)/', function ($match) use(&$var) { $var[$match[1]] = strip_tags($match[2]); }, implode('/', $paths)); } $_GET = array_merge($var, $_GET); } // 获取控制器和操作名 define('CONTROLLER_NAME', self::getController($varController, $urlCase)); define('ACTION_NAME', self::getAction($varAction, $urlCase)); // 当前控制器的UR地址 define('__CONTROLLER__', __MODULE__ . $depr . ($urlCase ? parse_name(CONTROLLER_NAME) : CONTROLLER_NAME)); // 当前操作的URL地址 define('__ACTION__', __CONTROLLER__ . $depr . ACTION_NAME); //保证$_REQUEST正常取值 $_REQUEST = array_merge($_POST, $_GET, $_COOKIE); // -- 加了$_COOKIE. 保证哦.. }
/** * auth接口 * @param array $options * @return false|string */ private function auth($options) { //请求参数 $signable_resource = ''; $string_to_sign = ''; $request_url = "https://{$this->hostname}/{$this->bucket}"; if (isset($options['object']) && '/' !== $options['object']) { $signable_resource .= '/' . str_replace(array('%2F', '%25'), array('/', '%'), rawurlencode($options['object'])); $request_url .= $signable_resource; } $headers = array('Content-Md5' => '', 'Content-Type' => isset($options['Content-Type']) ? $options['Content-Type'] : 'application/x-www-form-urlencoded', 'Date' => isset($options['Date']) ? $options['Date'] : gmdate('D, d M Y H:i:s \\G\\M\\T'), 'Host' => $this->hostname); //合并 HTTP headers if (isset($options['headers'])) { $headers = array_merge($headers, $options['headers']); } if (isset($options['Content-Md5'])) { $headers['Content-Md5'] = $options['Content-Md5']; } $method = 'GET'; if (isset($options['method'])) { $method = $options['method']; $string_to_sign .= $options['method'] . "\n"; } $request_body = ''; if (isset($options['content'])) { $request_body = $options['content']; if ($headers['Content-Type'] === 'application/x-www-form-urlencoded') { $headers['Content-Type'] = 'application/octet-stream'; } $headers['Content-Length'] = strlen($options['content']); $headers['Content-Md5'] = base64_encode(md5($options['content'], true)); } uksort($headers, 'strnatcasecmp'); $request_headers = array(); foreach ($headers as $header_key => $header_value) { $header_value = str_replace(array("\r", "\n"), '', $header_value); if ($header_value !== '') { $request_headers[$header_key] = $header_value; } if (in_array_case($header_key, array('content-md5', 'content-type', 'date'))) { $string_to_sign .= $header_value . "\n"; } elseif (substr(strtolower($header_key), 0, 6) === 'x-oss-') { $string_to_sign .= strtolower($header_key) . ':' . $header_value . "\n"; } } $string_to_sign .= '/' . $this->bucket . rawurldecode($signable_resource); $signature = base64_encode(hash_hmac('sha1', $string_to_sign, $this->access_key, true)); $request_headers['Authorization'] = 'OSS ' . $this->access_id . ':' . $signature; $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, $request_url); curl_setopt($curl_handle, CURLOPT_FILETIME, true); curl_setopt($curl_handle, CURLOPT_FRESH_CONNECT, false); curl_setopt($curl_handle, CURLOPT_CLOSEPOLICY, CURLCLOSEPOLICY_LEAST_RECENTLY_USED); curl_setopt($curl_handle, CURLOPT_MAXREDIRS, 5); curl_setopt($curl_handle, CURLOPT_HEADER, false); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl_handle, CURLOPT_TIMEOUT, $this->timeout); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 120); curl_setopt($curl_handle, CURLOPT_NOSIGNAL, true); curl_setopt($curl_handle, CURLOPT_REFERER, $request_url); curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查 curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在 if (!ini_get('safe_mode') && !ini_get('open_basedir')) { curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, true); } // 使用自动跳转 if (extension_loaded('zlib')) { curl_setopt($curl_handle, CURLOPT_ENCODING, ''); } $temp_headers = array(); foreach ($request_headers as $k => $v) { $temp_headers[] = "{$k}: {$v}"; } curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $temp_headers); switch ($method) { case 'PUT': curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $request_body); break; case 'POST': curl_setopt($curl_handle, CURLOPT_POST, true); curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $request_body); break; case 'HEAD': curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, 'HEAD'); curl_setopt($curl_handle, CURLOPT_NOBODY, 1); break; default: curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $request_body); } $data = curl_exec($curl_handle); $code = curl_getinfo($curl_handle, CURLINFO_HTTP_CODE); curl_close($curl_handle); if ($code == 200) { return $data; } else { \Think\Log::record(var_export(array('code' => $code, 'body' => $data), true), 'OSS_ERROR', true); return false; } }
/** * 取消订单 */ public function orderCancel($obj) { $userId = $obj["userId"]; $orderId = $obj["orderId"]; $rsdata = array(); $sql = "SELECT orderId,orderNo,orderStatus FROM __PREFIX__orders WHERE orderId = {$orderId} and orderFlag = 1 and userId=" . $userId; $rsv = $this->queryRow($sql); $cancelStatus = array(0, 1, 2, 3, -2); if (!in_array_case($rsv["orderStatus"], $cancelStatus)) { $rsdata["status"] = -1; return $rsdata; } $sql = "UPDATE __PREFIX__orders set orderStatus = -1 WHERE orderId = {$orderId} and userId=" . $userId; $rs = $this->query($sql); $sql = "select ord.deliverType, ord.orderId, og.goodsId ,og.goodsId, og.goodsNums \n\t\t\t\tfrom __PREFIX__orders ord , __PREFIX__order_goods og \n\t\t\t\tWHERE ord.orderId = og.orderId AND ord.orderId = {$orderId}"; $ogoodsList = $this->query($sql); for ($i = 0; $i < count($ogoodsList); $i++) { $sgoods = $ogoodsList[$i]; $sql = "update __PREFIX__goods set goodsStock=goodsStock+" . $sgoods['goodsNums'] . " where goodsId=" . $sgoods["goodsId"]; $this->query($sql); } $sql = "Delete From __PREFIX__order_reminds where orderId=" . $orderId . " AND remindType=0"; $this->query($sql); $data = array(); $m = M('log_orders'); $data["orderId"] = $orderId; $data["logContent"] = "用户已取消订单"; $data["logUserId"] = $userId; $data["logType"] = 0; $data["logTime"] = date('Y-m-d H:i:s'); $ra = $m->add($data); $rsdata["status"] = $ra; return $rsdata; }
/** * URL映射到控制器 * @access public * @return void */ public static function dispatch() { $varPath = C('VAR_PATHINFO'); $varAddon = C('VAR_ADDON'); $varModule = C('VAR_MODULE'); $varController = C('VAR_CONTROLLER'); $varAction = C('VAR_ACTION'); $urlCase = C('URL_CASE_INSENSITIVE'); if (isset($_GET[$varPath])) { // 判断URL里面是否有兼容模式参数 $_SERVER['PATH_INFO'] = $_GET[$varPath]; unset($_GET[$varPath]); } elseif (IS_CLI) { // CLI模式下 index.php module/controller/action/params/... $_SERVER['PATH_INFO'] = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : ''; } // 开启子域名部署 if (C('APP_SUB_DOMAIN_DEPLOY')) { $rules = C('APP_SUB_DOMAIN_RULES'); if (isset($rules[$_SERVER['HTTP_HOST']])) { // 完整域名或者IP配置 define('APP_DOMAIN', $_SERVER['HTTP_HOST']); // 当前完整域名 $rule = $rules[APP_DOMAIN]; } else { if (strpos(C('APP_DOMAIN_SUFFIX'), '.')) { // com.cn net.cn $domain = array_slice(explode('.', $_SERVER['HTTP_HOST']), 0, -3); } else { $domain = array_slice(explode('.', $_SERVER['HTTP_HOST']), 0, -2); } if (!empty($domain)) { $subDomain = implode('.', $domain); define('SUB_DOMAIN', $subDomain); // 当前完整子域名 $domain2 = array_pop($domain); // 二级域名 if ($domain) { // 存在三级域名 $domain3 = array_pop($domain); } if (isset($rules[$subDomain])) { // 子域名 $rule = $rules[$subDomain]; } elseif (isset($rules['*.' . $domain2]) && !empty($domain3)) { // 泛三级域名 $rule = $rules['*.' . $domain2]; $panDomain = $domain3; } elseif (isset($rules['*']) && !empty($domain2) && 'www' != $domain2) { // 泛二级域名 $rule = $rules['*']; $panDomain = $domain2; } } } if (!empty($rule)) { // 子域名部署规则 '子域名'=>array('模块名[/控制器名]','var1=a&var2=b'); if (is_array($rule)) { list($rule, $vars) = $rule; } $array = explode('/', $rule); // 模块绑定 define('BIND_MODULE', array_shift($array)); // 控制器绑定 if (!empty($array)) { $controller = array_shift($array); if ($controller) { define('BIND_CONTROLLER', $controller); } } if (isset($vars)) { // 传入参数 parse_str($vars, $parms); if (isset($panDomain)) { $pos = array_search('*', $parms); if (false !== $pos) { // 泛域名作为参数 $parms[$pos] = $panDomain; } } $_GET = array_merge($_GET, $parms); } } } // 分析PATHINFO信息 if (!isset($_SERVER['PATH_INFO'])) { $types = explode(',', C('URL_PATHINFO_FETCH')); foreach ($types as $type) { if (0 === strpos($type, ':')) { // 支持函数判断 $_SERVER['PATH_INFO'] = call_user_func(substr($type, 1)); break; } elseif (!empty($_SERVER[$type])) { $_SERVER['PATH_INFO'] = 0 === strpos($_SERVER[$type], $_SERVER['SCRIPT_NAME']) ? substr($_SERVER[$type], strlen($_SERVER['SCRIPT_NAME'])) : $_SERVER[$type]; break; } } } $depr = C('URL_PATHINFO_DEPR'); define('MODULE_PATHINFO_DEPR', $depr); if (empty($_SERVER['PATH_INFO'])) { $_SERVER['PATH_INFO'] = ''; define('__INFO__', ''); define('__EXT__', ''); } else { define('__INFO__', trim($_SERVER['PATH_INFO'], '/')); // URL后缀 define('__EXT__', strtolower(pathinfo($_SERVER['PATH_INFO'], PATHINFO_EXTENSION))); $_SERVER['PATH_INFO'] = __INFO__; if (!defined('BIND_MODULE') && (!C('URL_ROUTER_ON') || !Route::check())) { if (__INFO__ && C('MULTI_MODULE')) { // 获取模块名 $paths = explode($depr, __INFO__, 2); $allowList = C('MODULE_ALLOW_LIST'); // 允许的模块列表 $module = preg_replace('/\\.' . __EXT__ . '$/i', '', $paths[0]); if (empty($allowList) || is_array($allowList) && in_array_case($module, $allowList)) { $_GET[$varModule] = $module; $_SERVER['PATH_INFO'] = isset($paths[1]) ? $paths[1] : ''; } } } } // URL常量 define('__SELF__', strip_tags($_SERVER[C('URL_REQUEST_URI')])); // 获取模块名称 define('MODULE_NAME', defined('BIND_MODULE') ? BIND_MODULE : self::getModule($varModule)); // 检测模块是否存在 if (MODULE_NAME && (defined('BIND_MODULE') || !in_array_case(MODULE_NAME, C('MODULE_DENY_LIST'))) && is_dir(APP_PATH . MODULE_NAME)) { // 定义当前模块路径 define('MODULE_PATH', APP_PATH . MODULE_NAME . '/'); // 定义当前模块的模版缓存路径 C('CACHE_PATH', CACHE_PATH . MODULE_NAME . '/'); // 定义当前模块的日志目录 C('LOG_PATH', realpath(LOG_PATH) . '/' . MODULE_NAME . '/'); // 模块检测 Hook::listen('module_check'); // 加载模块配置文件 if (is_file(MODULE_PATH . 'Conf/config' . CONF_EXT)) { C(load_config(MODULE_PATH . 'Conf/config' . CONF_EXT)); } // 加载应用模式对应的配置文件 if ('common' != APP_MODE && is_file(MODULE_PATH . 'Conf/config_' . APP_MODE . CONF_EXT)) { C(load_config(MODULE_PATH . 'Conf/config_' . APP_MODE . CONF_EXT)); } // 当前应用状态对应的配置文件 if (APP_STATUS && is_file(MODULE_PATH . 'Conf/' . APP_STATUS . CONF_EXT)) { C(load_config(MODULE_PATH . 'Conf/' . APP_STATUS . CONF_EXT)); } // 加载模块别名定义 if (is_file(MODULE_PATH . 'Conf/alias.php')) { Think::addMap(include MODULE_PATH . 'Conf/alias.php'); } // 加载模块tags文件定义 if (is_file(MODULE_PATH . 'Conf/tags.php')) { Hook::import(include MODULE_PATH . 'Conf/tags.php'); } // 加载模块函数文件 if (is_file(MODULE_PATH . 'Common/function.php')) { include MODULE_PATH . 'Common/function.php'; } // 加载模块的扩展配置文件 load_ext_file(MODULE_PATH); } else { E(L('_MODULE_NOT_EXIST_') . ':' . MODULE_NAME); } if (!defined('__APP__')) { $urlMode = C('URL_MODEL'); if ($urlMode == URL_COMPAT) { // 兼容模式判断 define('PHP_FILE', _PHP_FILE_ . '?' . $varPath . '='); } elseif ($urlMode == URL_REWRITE) { $url = dirname(_PHP_FILE_); if ($url == '/' || $url == '\\') { $url = ''; } define('PHP_FILE', $url); } else { define('PHP_FILE', _PHP_FILE_); } // 当前应用地址 define('__APP__', strip_tags(PHP_FILE)); } // 模块URL地址 $moduleName = defined('MODULE_ALIAS') ? MODULE_ALIAS : MODULE_NAME; define('__MODULE__', defined('BIND_MODULE') || !C('MULTI_MODULE') ? __APP__ : __APP__ . '/' . ($urlCase ? strtolower($moduleName) : $moduleName)); if ('' != $_SERVER['PATH_INFO'] && (!C('URL_ROUTER_ON') || !Route::check())) { // 检测路由规则 如果没有则按默认规则调度URL Hook::listen('path_info'); // 检查禁止访问的URL后缀 if (C('URL_DENY_SUFFIX') && preg_match('/\\.(' . trim(C('URL_DENY_SUFFIX'), '.') . ')$/i', $_SERVER['PATH_INFO'])) { send_http_status(404); exit; } // 去除URL后缀 $_SERVER['PATH_INFO'] = preg_replace(C('URL_HTML_SUFFIX') ? '/\\.(' . trim(C('URL_HTML_SUFFIX'), '.') . ')$/i' : '/\\.' . __EXT__ . '$/i', '', $_SERVER['PATH_INFO']); $depr = C('URL_PATHINFO_DEPR'); $paths = explode($depr, trim($_SERVER['PATH_INFO'], $depr)); if (!defined('BIND_CONTROLLER')) { // 获取控制器 if (C('CONTROLLER_LEVEL') > 1) { // 控制器层次 $_GET[$varController] = implode('/', array_slice($paths, 0, C('CONTROLLER_LEVEL'))); $paths = array_slice($paths, C('CONTROLLER_LEVEL')); } else { $_GET[$varController] = array_shift($paths); } } // 获取操作 if (!defined('BIND_ACTION')) { $_GET[$varAction] = array_shift($paths); } // 解析剩余的URL参数 $var = array(); if (C('URL_PARAMS_BIND') && 1 == C('URL_PARAMS_BIND_TYPE')) { // URL参数按顺序绑定变量 $var = $paths; } else { preg_replace_callback('/(\\w+)\\/([^\\/]+)/', function ($match) use(&$var) { $var[$match[1]] = strip_tags($match[2]); }, implode('/', $paths)); } $_GET = array_merge($var, $_GET); } // 获取控制器的命名空间(路径) define('CONTROLLER_PATH', self::getSpace($varAddon, $urlCase)); // 获取控制器和操作名 define('CONTROLLER_NAME', defined('BIND_CONTROLLER') ? BIND_CONTROLLER : self::getController($varController, $urlCase)); define('ACTION_NAME', defined('BIND_ACTION') ? BIND_ACTION : self::getAction($varAction, $urlCase)); // 当前控制器的UR地址 $controllerName = defined('CONTROLLER_ALIAS') ? CONTROLLER_ALIAS : CONTROLLER_NAME; define('__CONTROLLER__', __MODULE__ . $depr . (defined('BIND_CONTROLLER') ? '' : ($urlCase ? parse_name($controllerName) : $controllerName))); // 当前操作的URL地址 define('__ACTION__', __CONTROLLER__ . $depr . (defined('ACTION_ALIAS') ? ACTION_ALIAS : ACTION_NAME)); //保证$_REQUEST正常取值 $_REQUEST = array_merge($_POST, $_GET, $_COOKIE); // -- 加了$_COOKIE. 保证哦.. }
/** * 获得实际的模块名称 * @param array $paths path_info数组 * @return string */ private static function getModule(&$paths) { if (defined('BIND_MODULE')) { return BIND_MODULE; } else { // 检查路由 if ($paths && C('URL_ROUTER_ON') && Route::check($paths)) { $paths = explode(MODULE_PATHINFO_DEPR, trim($_SERVER['PATH_INFO'], MODULE_PATHINFO_DEPR)); } if ($paths && C('MULTI_MODULE')) { // 获取模块名 $allowList = C('MODULE_ALLOW_LIST'); // 允许的模块列表 if (empty($allowList) || is_array($allowList) && in_array_case($paths[0], $allowList)) { $module = array_shift($paths); $_SERVER['PATH_INFO'] = implode(MODULE_PATHINFO_DEPR, $paths); } } else { $var = C('VAR_MODULE'); if (!empty($_GET[$var])) { $module = $_GET[$var]; unset($_GET[$var]); } } if (empty($module)) { $module = C('DEFAULT_MODULE'); } } if ($maps = C('URL_MODULE_MAP')) { if (isset($maps[strtolower($module)])) { // 记录当前别名 define('MODULE_ALIAS', strtolower($module)); // 获取实际的模块名 return ucfirst($maps[MODULE_ALIAS]); } elseif (array_search(strtolower($module), $maps) || in_array_case($module, C('MODULE_DENY_LIST'))) { // 禁止访问原始模块 return ''; } } return strip_tags(ucfirst($module)); }
/** * URL映射到控制器 * @access public * @return void */ public static function dispatch() { $varPath = C('VAR_PATHINFO'); $varModule = C('VAR_MODULE'); $varController = C('VAR_CONTROLLER'); $varAction = C('VAR_ACTION'); $urlCase = C('URL_CASE_INSENSITIVE'); if (isset($_GET[$varPath])) { // 判断URL里面是否有兼容模式参数 $_SERVER['PATH_INFO'] = $_GET[$varPath]; unset($_GET[$varPath]); } elseif (IS_CLI) { // CLI模式下 index.php module/controller/action/params/... $_SERVER['PATH_INFO'] = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : ''; } // 开启子域名部署 if (C('APP_SUB_DOMAIN_DEPLOY')) { $rules = C('APP_SUB_DOMAIN_RULES'); if (isset($rules[$_SERVER['HTTP_HOST']])) { // 完整域名或者IP配置 define('APP_DOMAIN', $_SERVER['HTTP_HOST']); // 当前完整域名 $rule = $rules[APP_DOMAIN]; } else { if (strpos(C('APP_DOMAIN_SUFFIX'), '.')) { // com.cn net.cn $domain = array_slice(explode('.', $_SERVER['HTTP_HOST']), 0, -3); } else { $domain = array_slice(explode('.', $_SERVER['HTTP_HOST']), 0, -2); } if (!empty($domain)) { $subDomain = implode('.', $domain); define('SUB_DOMAIN', $subDomain); // 当前完整子域名 $domain2 = array_pop($domain); // 二级域名 if ($domain) { // 存在三级域名 $domain3 = array_pop($domain); } if (isset($rules[$subDomain])) { // 子域名 $rule = $rules[$subDomain]; } elseif (isset($rules['*.' . $domain2]) && !empty($domain3)) { // 泛三级域名 $rule = $rules['*.' . $domain2]; $panDomain = $domain3; } elseif (isset($rules['*']) && !empty($domain2) && 'www' != $domain2) { // 泛二级域名 $rule = $rules['*']; $panDomain = $domain2; } } } if (!empty($rule)) { // 子域名部署规则 '子域名'=>array('模块名[/控制器名]','var1=a&var2=b'); if (is_array($rule)) { list($rule, $vars) = $rule; } $array = explode('/', $rule); // 模块绑定 define('BIND_MODULE', array_shift($array)); // 控制器绑定 if (!empty($array)) { $controller = array_shift($array); if ($controller) { define('BIND_CONTROLLER', $controller); } } if (isset($vars)) { // 传入参数 parse_str($vars, $parms); if (isset($panDomain)) { $pos = array_search('*', $parms); if (false !== $pos) { // 泛域名作为参数 $parms[$pos] = $panDomain; } } $_GET = array_merge($_GET, $parms); } } } // 分析PATHINFO信息 if (!isset($_SERVER['PATH_INFO'])) { $types = explode(',', C('URL_PATHINFO_FETCH')); foreach ($types as $type) { if (!empty($_SERVER[$type])) { $_SERVER['PATH_INFO'] = 0 === strpos($_SERVER[$type], $_SERVER['SCRIPT_NAME']) ? substr($_SERVER[$type], strlen($_SERVER['SCRIPT_NAME'])) : $_SERVER[$type]; break; } } } if (empty($_SERVER['PATH_INFO'])) { $_SERVER['PATH_INFO'] = ''; } $depr = C('URL_PATHINFO_DEPR'); define('MODULE_PATHINFO_DEPR', $depr); define('__INFO__', trim($_SERVER['PATH_INFO'], '/')); // URL后缀 define('__EXT__', strtolower(pathinfo($_SERVER['PATH_INFO'], PATHINFO_EXTENSION))); $_SERVER['PATH_INFO'] = __INFO__; if (__INFO__ && C('MULTI_MODULE') && !defined('BIND_MODULE')) { // 获取模块名 $paths = explode($depr, __INFO__, 2); $allowList = C('MODULE_ALLOW_LIST'); // 允许的模块列表 $module = preg_replace('/\\.' . __EXT__ . '$/i', '', $paths[0]); if (empty($allowList) || is_array($allowList) && in_array_case($module, $allowList)) { $_GET[$varModule] = $module; $_SERVER['PATH_INFO'] = isset($paths[1]) ? $paths[1] : ''; } } // 获取模块名称 define('MODULE_NAME', defined('BIND_MODULE') ? BIND_MODULE : self::getModule($varModule)); // 检测模块是否存在 if (MODULE_NAME && (defined('BIND_MODULE') || !in_array_case(MODULE_NAME, C('MODULE_DENY_LIST'))) && is_dir(APP_PATH . MODULE_NAME)) { // 定义当前模块路径 define('MODULE_PATH', APP_PATH . MODULE_NAME . '/'); // 定义当前模块的模版缓存路径 C('CACHE_PATH', CACHE_PATH . MODULE_NAME . '/'); // 加载模块配置文件 if (is_file(MODULE_PATH . 'Conf/config.php')) { C(include MODULE_PATH . 'Conf/config.php'); } // 加载模块别名定义 if (is_file(MODULE_PATH . 'Conf/alias.php')) { Think::addMap(include MODULE_PATH . 'Conf/alias.php'); } // 加载模块函数文件 if (is_file(MODULE_PATH . 'Common/function.php')) { include MODULE_PATH . 'Common/function.php'; } } else { E(L('_MODULE_NOT_EXIST_') . ':' . MODULE_NAME); } if ('' != $_SERVER['PATH_INFO'] && (!C('URL_ROUTER_ON') || !Route::check())) { // 检测路由规则 如果没有则按默认规则调度URL // 检查禁止访问的URL后缀 if (C('URL_DENY_SUFFIX') && preg_match('/\\.(' . trim(C('URL_DENY_SUFFIX'), '.') . ')$/i', $_SERVER['PATH_INFO'])) { send_http_status(404); exit; } // 去除URL后缀 $_SERVER['PATH_INFO'] = preg_replace(C('URL_HTML_SUFFIX') ? '/\\.(' . trim(C('URL_HTML_SUFFIX'), '.') . ')$/i' : '/\\.' . __EXT__ . '$/i', '', $_SERVER['PATH_INFO']); $depr = C('URL_PATHINFO_DEPR'); $paths = explode($depr, trim($_SERVER['PATH_INFO'], $depr)); if (!defined('BIND_CONTROLLER')) { // 获取控制器 $_GET[$varController] = array_shift($paths); } // 获取操作 if (!defined('BIND_ACTION')) { $_GET[$varAction] = array_shift($paths); } // 解析剩余的URL参数 $var = array(); if (C('URL_PARAMS_BIND') && 1 == C('URL_PARAMS_BIND_TYPE')) { // URL参数按顺序绑定变量 $var = $paths; } else { preg_replace_callback('/(\\w+)\\/([^\\/]+)/', function ($match) use(&$var) { $var[$match[1]] = strip_tags($match[2]); }, implode('/', $paths)); } $_GET = array_merge($var, $_GET); } // 获取控制器和操作名 define('CONTROLLER_NAME', defined('BIND_CONTROLLER') ? BIND_CONTROLLER : self::getController($varController, $urlCase)); define('ACTION_NAME', defined('BIND_ACTION') ? BIND_ACTION : self::getAction($varAction, $urlCase)); //保证$_REQUEST正常取值 $_REQUEST = array_merge($_POST, $_GET); }
/** * do the mapping and replacements * * @param VCard $card * @param array $_headline [optional] * @return array * * @todo split this into smaller parts */ protected function _doMapping($card) { $data = array(); $data = $this->_getName($card, $data); $data = $this->_getPhoto($card, $data); $data = $this->_getUrl($card, $data); // TODO check sample format support // BDAY:1996-04-15 // BDAY:1953-10-15T23:10:00Z // BDAY:1987-09-27T08:30:00-06:00 if ($card->getProperty('BDAY')) { $data['bday'] = $card->getProperty('BDAY')->value; } $addressProperty = $card->getProperty('ADR') ? 'ADR' : ($card->getProperty('ITEM1.ADR') ? 'ITEM1.ADR' : ''); if ($addressProperty) { $properties = $card->getProperties($addressProperty); foreach ($properties as $property) { // types available from RFC : 'dom', 'intl', 'postal', 'parcel', 'home', 'work', 'pref' $types = $property->params['TYPE']; //post office box; the extended address; the street //address; the locality (e.g., city); the region (e.g., state or //province); the postal code; the country name $components = $property->getComponents(); if ($types && in_array_case($types, 'home')) { //post office box : $components[0]; $data['adr_two_street2'] = $components[1]; $data['adr_two_street'] = $components[2]; $data['adr_two_locality'] = $components[3]; $data['adr_two_region'] = $components[4]; $data['adr_two_postalcode'] = $components[5]; $data['adr_two_countryname'] = $components[6]; } else { $data['adr_one_street2'] = $components[1]; $data['adr_one_street'] = $components[2]; $data['adr_one_locality'] = $components[3]; $data['adr_one_region'] = $components[4]; $data['adr_one_postalcode'] = $components[5]; $data['adr_one_countryname'] = $components[6]; } } } // $properties = $card->getProperties('LABEL'); //NOT_IMPLEMENTED if ($card->getProperty('TEL')) { $properties = $card->getProperties('TEL'); foreach ($properties as $property) { // types available from RFC : "home", "msg", "work", "pref", "voice", "fax", "cell", "video", "pager", "bbs", "modem", "car", "isdn", "pcs" $types = $property->params['TYPE']; $key = 'tel_work'; if ($types) { if (in_array_case($types, 'home') && !in_array_case($types, 'cell') && !in_array_case($types, 'fax')) { $key = 'tel_home'; } else { if (in_array_case($types, 'home') && in_array_case($types, 'cell')) { $key = 'tel_cell_private'; } else { if (in_array_case($types, 'home') && in_array_case($types, 'fax')) { $key = 'tel_fax_home'; } else { if (in_array_case($types, 'work') && !in_array_case($types, 'cell') && !in_array_case($types, 'fax')) { $key = 'tel_work'; } else { if (in_array_case($types, 'work') && in_array_case($types, 'cell')) { $key = 'tel_cell'; } else { if (in_array_case($types, 'work') && !in_array_case($types, 'fax')) { $key = 'tel_fax'; } else { if (in_array_case($types, 'car')) { $key = 'tel_car'; } else { if (in_array_case($types, 'pager')) { $key = 'tel_pager'; } else { if (in_array_case($types, 'fax')) { $key = 'tel_fax'; } else { if (in_array_case($types, 'cell')) { $key = 'tel_cell'; } } } } } } } } } } } $data[$key] = $property->value; //$data['tel_assistent'] = ''; //RFC has *a lot* of type, but not this one ^^ } } if ($card->getProperty('EMAIL')) { $properties = $card->getProperties('EMAIL'); foreach ($properties as $property) { // types available from RFC (custom allowed): "internet", "x400", "pref" // home and work are commons, so we manage them $types = $property->params['TYPE']; $key = 'email'; if ($types) { if (in_array_case($types, 'home')) { $key = 'email_home'; } } $data[$key] = $property->value; } } // $properties = $card->getProperties('MAILER'); //NOT_IMPLEMENTED // TODO Check samples are supported // TZ:-05:00 // TZ;VALUE=text:-05:00; EST; Raleigh/North America if ($card->getProperty('TZ')) { $data['tz'] = $card->getProperty('TZ')->value; } // $properties = $card->getProperties('GEO'); //NOT_IMPLEMENTED if ($card->getProperty('TITLE')) { $data['title'] = $card->getProperty('TITLE')->value; } if ($card->getProperty('ROLE')) { $data['role'] = $properties = $card->getProperty('ROLE')->value; } // $properties = $card->getProperties('LOGO'); // NOT_IMPLEMENTED // Type can be a specification "secretary", "assistant", etc. // Value can be a URI or a nested VCARD... // $data['assistent'] = $properties = $card->getProperties('AGENT'); // NESTED VCARD NOT SUPPORTED BY vcardphp if ($card->getProperty('ORG')) { $components = $card->getProperty('ORG')->getComponents(); $data['org_name'] = $components[0]; $data['org_unit'] = ''; for ($i = 1; $i < count($components); $i++) { $data['org_unit'] .= $components[$i] . ";"; } } // $properties = $card->getProperties('CATEGORIES'); // NOT_IMPLEMENTED if ($card->getProperty('NOTE')) { $data['note'] = $card->getProperty('NOTE')->value; } // $properties = $card->getProperties('PRODID'); // NOT_IMPLEMENTED // $properties = $card->getProperties('REV'); // NOT_IMPLEMENTED (could be with tine20 modification history) // $properties = $card->getProperties('SORT-STRING'); // NOT_IMPLEMENTED // $properties = $card->getProperties('SOUND'); // NOT_IMPLEMENTED // $properties = $card->getProperties('UID'); // NOT_IMPLEMENTED // $properties = $card->getProperties('VERSION'); // NOT_IMPLEMENTED // $properties = $card->getProperties('CLASS'); // NOT_IMPLEMENTED // TODO $data['pubkey'] = $properties = $card->getProperties('KEY'); // NOT_IMPLEMENTED // missing binary uncode return $data; }