/** * This function is the same of array_change_key_case() except this does not care * if the array is multidimensional or not. * * @param array array * @param const case // Like CASE_UPPER or CASE_LOWER * @return array new array */ function array_change_key_case_recursive($array, $case) { $array = array_change_key_case($array, $case); foreach ($array as $key => $value) { if (is_array($value)) { $array[$key] = array_change_key_case_recursive($value, $case); } } return $array; }
public function setOptions(array $options) { $options = array_change_key_case_recursive($options); foreach ($options as $k => $v) { $this->config[$k] = $v; } if (!$this->config['path']) { throw new AXION_EXCEPTION('必须配置Cache文件存储路径'); } }
public function __call($method, $arg) { if (empty($this->url)) { error_log('libws: No url is configured.'); return; } if (!is_array($arg)) { $arg = array($arg); } if (count($arg) == 1 && isset($arg[0]) && is_array($arg[0])) { $arg = $arg[0]; } if (strpos($this->destiny, 'facebook') !== false) { $add = array( 'APPID' => '#APPID', 'APPSECRET' => '#APPSECRET' ); $arg = array_merge($add, $arg); } if (isset($arg) && is_array($arg)) { $arg = $this->_param_replace($arg); } else { $arg_cp = $arg; $_arg = isset($arg[0]) ? w($arg[0]) : w(); $arg = w(); foreach ($_arg as $v) { if (isset($_REQUEST[$v])) $arg[$v] = $_REQUEST[$v]; } $arg = (!$arg) ? $arg_cp : $arg; } $_bridge = $this->bridge; $count_bridge = count($_bridge); $_url = $this->url; $response = null; switch ($this->type) { case 'wsdl': $this->client = new nusoap_client($this->url, true); if ($error = $this->client->getError()) { $response = $error; } else { $response = $this->client->call($method, $arg); // Check if there were any call errors, and if so, return error messages. if ($error = $this->client->getError()) { $response = $this->client->response; $response = xml2array(substr($response, strpos($response, '<?xml'))); if (isset($response['soap:Envelope']['soap:Body']['soap:Fault']['faultstring'])) { $fault_string = $response['soap:Envelope']['soap:Body']['soap:Fault']['faultstring']; $response = explode("\n", $fault_string); $response = $response[0]; } else { $response = $error; } $response = array( 'error' => true, 'message' => $response ); } } $response = json_decode(json_encode($this->_filter($response))); break; case 'mysql': if (isset($arg['_mysql'])) { $this->params['_MYSQL'] = $arg['_mysql']; unset($arg['_mysql']); } $connect = (isset($this->params['_MYSQL']) && $this->params['_MYSQL']) ? $this->params['_MYSQL'] : ''; if (empty($arg)) { return false; } global $db; require_once('class.mysql.php'); $db = new database($connect); if (empty($db->message)) { switch ($method) { case 'sql_field': case 'sql_build': case 'sql_rowset': case 'sql_fieldrow': case 'sql_insert': case 'sql_cache': case 'sql_cache_limit': break; default: if (count($arg) > 1) { $sql = array_shift($arg); $arg = sql_filter($sql, $arg); } break; } $response = (@function_exists($method)) ? false : array('error' => true, 'message' => $method . ' is undefined'); if ($response === false) { switch ($method) { case 'sql_field': case 'sql_build': extract($arg, EXTR_PREFIX_ALL, 'sf'); $arg_v = ''; foreach ($arg as $i => $row) { $arg_v .= (($arg_v) ? ', ' : '') . '$sf_' . $i; } eval('$response = $method(' . $arg_v . ');'); break; default: $response = call_user_func_array($method, $arg); break; } if ($method !== 'sql_filter' && $method != 'sql_build') { $response = $this->recursive_htmlentities($response); } } } if (!empty($db->message)) { $response = $db->message; } break; case 'oracle': if (isset($arg['_oracle'])) { $this->params['_ORACLE'] = $arg['_oracle']; unset($arg['_oracle']); } $connect = (isset($this->params['_ORACLE']) && $this->params['_ORACLE']) ? $this->params['_ORACLE'] : ''; if (empty($arg)) { return false; } global $db; require_once('class.oracle.php'); $db = new database($connect); if (empty($db->message)) { switch ($method) { case 'sql_field': case 'sql_build': break; default: if (count($arg) > 1) { $sql = array_shift($arg); $arg = sql_filter($sql, $arg); } break; } //$response = (@function_exists($method)) ? $method($arg) : array('error' => true, 'message' => $method . ' is undefined'); $response = (@function_exists($method)) ? false : array('error' => true, 'message' => $method . ' is undefined'); if ($response === false) { switch ($method) { case 'sql_field': case 'sql_build': extract($arg, EXTR_PREFIX_ALL, 'sf'); $arg_v = ''; foreach ($arg as $i => $row) { $arg_v .= (($arg_v) ? ', ' : '') . '$sf_' . $i; } eval('$response = $method(' . $arg_v . ');'); break; default: $response = $method($arg); break; } } } if (!isset($response['error']) && is_array($response)) { if (isset($response[0]) && is_array($response[0])) { foreach ($response as $i => $row) { if (is_array($row)) { $response[$i] = array_change_key_case($row, CASE_LOWER); } } } else { $response = array_change_key_case($response, CASE_LOWER); } } if (!empty($db->message)) { $response = $db->message; } break; case 'php': if (isset($arg['_php'])) { unset($arg['_php']); } $print = w(); switch ($method) { case 'tail': case 'cat': if (!@is_readable($arg[0])) { $response = 'Can not read file: ' . $arg[0]; } break; case 'ping': $arg[1] = '-c' . ((isset($arg[1])) ? $arg[1] : 3); break; } switch ($method) { case 'write': $response = false; if ($fp = @fopen($arg[0], $arg[1])) { if (@fwrite($fp, $arg[2]) !== false) { @fclose($fp); $response = true; } } break; case 'tail': case 'cat': case 'ping': if ($response === null) { exec($method . ' ' . implode(' ', $arg), $print); $response = implode("\r\n", $print); } break; case 'exec': if ($response === null) { $method(implode(' ', $arg), $print); $response = implode("\r\n", $print); } break; default: ob_start(); if (@function_exists($method) || $method == 'eval') { eval(($method == 'eval') ? $arg[0] : 'echo @$method(' . (count($arg) ? "'" . implode("', '", $arg) . "'" : '') . ');'); $_arg = error_get_last(); } else { $_arg = array('message' => 'PHP Fatal error: Call to undefined function ' . $method . '()'); } $response = (null === $_arg) ? ob_get_contents() : array('url' => $_url . $method, 'error' => 500, 'message' => $_arg['message']); ob_end_clean(); break; } break; case 'facebook': if (isset($arg['_facebook'])) { unset($arg['_facebook']); } //header('Content-type: text/html; charset=utf-8'); require_once('class.facebook.php'); $facebook = new Facebook(array( 'appId' => $arg['APPID'], 'secret' => $arg['APPSECRET']) ); unset($arg['APPID'], $arg['APPSECRET']); try { $page = array_shift($arg); $page = (is_string($page)) ? '/' . $page : $page; $req = (isset($arg[0]) && is_string($arg[0])) ? array_shift($arg) : ''; $req = (empty($req)) ? 'get' : $req; $arg = (isset($arg[0])) ? $arg[0] : $arg; $response = (!empty($page)) ? (count($arg) ? $facebook->$method($page, $req, $arg) : $facebook->$method($page, $req)) : $facebook->$method(); } catch (FacebookApiException $e) { $response = array( 'url' => $_url, 'error' => 500, 'message' => trim(str_replace('OAuthException: ', '', $e)) ); error_log($e); } unset($facebook); break; case 'email': if (isset($arg['_email'])) { $this->params['_EMAIL'] = $arg['_email']; unset($arg['_email']); } $response = false; if (!isset($arg['to'])) { $response = 'NO_TO_ADDRESS'; } if ($response === false && !isset($arg['from'])) { $response = 'NO_FROM_ADDRESS'; } if ($response === false) { if (!is_array($arg['to'])) { $arg['to'] = array($arg['to']); } preg_match_all('!("(.*?)"\s+<\s*)?(.*?)(\s*>)?!', $arg['from'], $matches); /*$response = array(); for ($i=0; $i<count($matches[0]); $i++) { $response[] = array( 'name' => $matches[1][$i], 'email' => $matches[2][$i], ); }*/ $response = $matches; // Create Mail object /*$mail = new phpmailer(); $mail->PluginDir = ''; $mail->Mailer = 'smtp'; $mail->Host = $this->params['_EMAIL']; $mail->SMTPAuth = false; $mail->From = $from; $mail->FromName = "Claro"; $mail->Timeout = 30;*/ foreach ($arg['to'] as $row) { //$mail->AddAddress($row); } } //require_once('class.email.php'); //$emailer = new emailer(); //$response = print_r($arg, true); break; default: $send_var = w('sso mysql oracle php facebook email'); $send = new stdClass; if ($count_bridge == 1 && $_bridge[0] === $_url) { $count_bridge--; array_shift($_bridge); } foreach ($send_var as $row) { $val = '_' . strtoupper($row); $send->$row = (isset($this->params[$val]) && $this->params[$val]) ? $this->params[$val] : false; if (!$count_bridge && ($send->$row || isset($arg['_' . $row]))) { $this->type = $row; } } switch ($this->type) { case 'sso': $this->origin = false; $_url .= $method; unset($arg['_sso']); break; default: foreach ($send_var as $row) { if (isset($send->$row) && !empty($send->$row)) { $arg['_' . $row] = $send->$row; } } $arg['_method'] = $method; $arg['_unique'] = (!$this->unique) ? $this->unique : 1; if (isset($_bridge) && count($_bridge)) { array_shift($_bridge); $arg['_chain'] = implode('|', $_bridge); } break; } $_arg = $arg; $arg = ($this->type == 'sso') ? $this->_build($arg, false) : __encode($arg); $socket = @curl_init(); @curl_setopt($socket, CURLOPT_URL, $_url); @curl_setopt($socket, CURLOPT_VERBOSE, 0); @curl_setopt($socket, CURLOPT_HEADER, 0); @curl_setopt($socket, CURLOPT_RETURNTRANSFER, 1); @curl_setopt($socket, CURLOPT_POST, 1); @curl_setopt($socket, CURLOPT_POSTFIELDS, $arg); @curl_setopt($socket, CURLOPT_SSL_VERIFYPEER, 0); @curl_setopt($socket, CURLOPT_SSL_VERIFYHOST, 1); $response = @curl_exec($socket); $_curl = new stdClass; $_curl->err = @curl_errno($socket); $_curl->msg = @curl_error($socket); $_curl->inf = (object) @curl_getinfo($socket); @curl_close($socket); switch ($_curl->err) { /** If the request has no errors. */ case 0: switch ($this->type) { /** SSO type */ case 'sso': if (preg_match('#<body>(.*?)</body>#i', $response, $part)) { preg_match('#<p><b>description</b>(.*?)</p>#i', $part[1], $status); $response = array( 'url' => $_url, 'error' => $_curl->inf->http_code, 'message' => trim($status[1]) ); } else { switch($method) { case 'search': preg_match_all('/string\=(.*?)\n/i', $response, $response_all); $response = $response_all[1]; break; default: $response = $this->_format($response); break; } } break; /** Any other type */ default: $_json = json_decode($response); if ($_json === null) { $response = trim($response); $response = (!empty($response)) ? $response : $_curl->inf; $_json = $response; } $response = $_json; break; } break; /** Some error was generated after the request. */ default: $response = array( 'url' => $_url, 'error' => 500, 'message' => $_curl->msg ); break; } break; } if (!$this->origin || $this->unique) { $response = json_encode($response); } if (($this->type == 'sso' && $this->unique) || ($this->type != 'sso' && $this->unique)) { $response = json_decode($response); } if (is_array($response) && isset($response[0]) && is_string($response[0]) && strpos($response[0], '<?xml') !== false) { $response = array_change_key_case_recursive(xml2array($response[0])); $response = json_decode(json_encode($response)); } return $response; }
/** * new_module() * Module index. Show page for creating a new module. * @param boolean process * @return void */ public function new_module($process = false) { $this->validate_permission('CREATE_MODULE'); $path_permissions = $this->_check_path_permissions(); $timezone = $this->_check_timezone(); if (!$process) { // load all groups $groups = $this->db->select('id_user_group AS id, name')->from('acm_user_group')->order_by('name')->get()->result_array(); // build group options $args['groups'] = json_encode(array('results' => array_change_key_case_recursive($groups, CASE_LOWER))); // check permissions for all paths $args['path_permissions'] = $path_permissions; // timezone $args['timezone'] = $timezone; // Load view $this->template->load_page('_acme/app_module_maker/new_module', $args); } else { // set time process to zero set_time_limit(0); // controller used as a key $controller = strtolower($this->input->post('controller')); // Check if module already exist if (count($this->db->get_where('acm_module', array('controller' => $controller))->row_array(0)) > 0) { redirect('app_module_maker/new_module'); } // get table name $table = $this->input->post('table_name'); // Start building a new module! $module['def_file'] = json_encode($this->input->post()); $module['table_name'] = $table; $module['controller'] = $controller; $module['label'] = $this->input->post('label'); $module['description'] = $this->input->post('description'); $module['sql_list'] = $this->input->post('sql_list'); $module['url_img'] = $this->input->post('url_img'); $this->db->trans_start(); // Insert a module $this->db->insert('acm_module', $module); // get the module from db now $module = $this->db->from('acm_module')->where(array('controller' => $controller))->get()->row_array(0); // catch id_module now $id_module = get_value($module, 'id_module'); // check if table exists $table_exist = false; foreach ($this->db->list_tables() as $idx => $db_table) { if (strtolower($table) == strtolower($db_table)) { $table_exist = true; break; } } // create forms, menus, actions and permissions // only if table name was set $forms = $this->input->post('forms') == '' ? array() : $this->input->post('forms'); if ($table_exist) { foreach ($forms as $operation) { $form = array(); $form['id_module'] = $id_module; $form['operation'] = $operation; // Create form $this->db->insert('acm_module_form', $form); // Get form from db $form = $this->db->from('acm_module_form')->where(array('id_module' => $id_module, 'operation' => $operation))->get()->row_array(0); // now form id $id_form = get_value($form, 'id_module_form'); // table fields meta-data $fields = $this->db->field_data($table); // loop fields until find correct column foreach ($fields as $field) { // build field to insert on acm_module_form_field $field_data = $this->form->build_field($field, $table); $field_data['id_module_form'] = $id_form; // Loop fields to insert foreach ($field_data as $index => $value) { $escape = $value != 'NULL' ? true : false; $this->db->set($index, $value, $escape); } // Insert it! $this->db->insert('acm_module_form_field'); } // and also for each form we have to create menus, permissions and actions $data['id_module'] = $id_module; $data['label'] = lang(ucwords($operation)); $data['link'] = $operation == 'insert' ? '{URL_ROOT}/' . $controller . '/form/' . $operation : '{URL_ROOT}/' . $controller . '/form/' . $operation . '/{0}'; // now permission $permission['id_module'] = $id_module; $permission['label'] = lang(ucwords($operation) . ' form'); $permission['permission'] = strtoupper($operation); // adjust table name $table_ins = $operation == 'insert' ? 'acm_module_menu' : 'acm_module_action'; // do it! $this->db->insert($table_ins, $data); $this->db->insert('acm_module_permission', $permission); } } // insert one more permission for entering $permission['id_module'] = $id_module; $permission['permission'] = 'ENTER'; $permission['label'] = lang('Module entrance'); $this->db->insert('acm_module_permission', $permission); // automatically gives all permissions for the user creator $permissions = $this->db->get_where('acm_module_permission', array('id_module' => $id_module))->result_array(0); foreach ($permissions as $module_permission) { $usr_permission['id_user'] = $this->session->userdata('id_user'); $usr_permission['id_module_permission'] = get_value($module_permission, 'id_module_permission'); $this->db->insert('acm_user_permission', $usr_permission); } // now create menus for application for all groups matched $groups = $this->input->post('menu_groups') == '' ? array() : $this->input->post('menu_groups'); $menu['link'] = '{URL_ROOT}/' . $controller; foreach ($groups as $group) { $menu['id_user_group'] = $group; $menu['label'] = ucwords($this->input->post('label')); $this->db->insert('acm_menu', $menu); } // and finally, create all files needed // controller $file_controller = file_get_contents('application/core/acme/engine_files/maker_template_controller.php'); $file_controller = str_replace('<CLASS_NAME>', $controller, $file_controller); $file_controller = str_replace('<DESCRIPTION>', $this->input->post('description'), $file_controller); $file_controller = str_replace('<CREATION_DATE>', date('d/m/Y'), $file_controller); $file_controller = str_replace('<AUTHOR>', $this->session->userdata('email'), $file_controller); file_put_contents('application/controllers/' . $controller . '.php', $file_controller); // Model $file_model = file_get_contents('application/core/acme/engine_files/maker_template_model.php'); $file_model = str_replace('<CLASS_NAME>', $controller, $file_model); $file_model = str_replace('<DESCRIPTION>', $this->input->post('description'), $file_model); $file_model = str_replace('<CREATION_DATE>', date('d/m/Y'), $file_model); $file_model = str_replace('<AUTHOR>', $this->session->userdata('email'), $file_model); file_put_contents('application/models/' . $controller . '_model.php', $file_model); // View @mkdir('application/views/' . TEMPLATE . '/' . $controller); // complete all transaction $this->db->trans_complete(); // build args for view $args['module'] = $module; $args['link'] = $menu['link']; // Load view $this->template->load_page('_acme/app_module_maker/new_module_success', $args); } }
/** * Validates that a passed string is valid ini. * * @param string $input The input to validation * @param bool $processSections TRUE to process sections, FALSE to do not * * @author Benjamin Carl <*****@*****.**> * * @return mixed|bool Input on success, otherwise FALSE */ protected function validate($input, $processSections = self::PHP_INI_PARSER_PROCESS_SECTIONS) { if (true === is_string($input)) { $input = @parse_ini_string($input, $processSections); // Convert our associative array to an object $input = array_to_object(array_change_key_case_recursive($input)); } return $input; }
/** * Loads settings data from $settings array * As tasks needed - parental methods LoadSettings is can't be fully overriden * at PHP ('Strict standards') * * @param - array with Settings data * @result - TRUE/FALSE */ public function LoadSettingsExt($settings) { $result = TRUE; if (!is_array($settings)) { throw new Exception('Array required.'); } //DONE: ~ 03.04.2012 9:44:11 большие/маленькие //change all keys case to lower array_change_key_case_recursive($settings, CASE_LOWER); if (array_key_exists('local', $settings)) { // Set locale if (array_key_exists('default_locale', $settings['local'])) { $this->SetLocale($settings['local']['default_locale']); } else { $this->SetLocale(_APIADLIB_LOCAL_DEFAULT_LOCALE); } // Set no time limit for PHP operations. if (array_key_exists('php_time_limit', $settings['local'])) { set_time_limit($settings['local']['php_time_limit']); } else { set_time_limit(_APIADLIB_LOCAL_PHP_TIME_LIMIT); } // sets sockets streams timeouts to 8 minutes? if (array_key_exists('default_socket_timeout', $settings['local'])) { ini_set('default_socket_timeout', $settings['local']['default_socket_timeout']); } else { ini_set('default_socket_timeout', _APIADLIB_LOCAL_DEFAULT_SOCKET_TIMEOUT); } } // Logging settings. if (isset($settings['logging']['path_relative']) && $settings['logging']['path_relative'] == 1) { $path = realpath($this->_logsRelativePathBase . '/' . $settings['logging']['lib_log_dir_path']); $this->logsDirectory = $path === FALSE ? $this->_defaultLogsDir : $path; } else { $this->logsDirectory = isset($settings['logging']['lib_log_dir_path']) ? $settings['logging']['lib_log_dir_path'] : ''; } //TODO ~ 03.04.2012 14:20:47 check this $this->InitLogs(); // Server settings. if (array_key_exists('server', $settings)) { if (array_key_exists('default_version', $settings['server'])) { $this->SetDefaultVersion($settings['server']['default_version']); } else { $this->SetDefaultVersion(ADWORDS_VERSION); } if (array_key_exists('default_server', $settings['server'])) { $this->SetDefaultServer($settings['server']['default_server']); } else { $this->SetDefaultServer(self::$DEFAULT_SERVER); } } // SOAP settings. if (array_key_exists('soap', $settings)) { // SOAP Compression level if (array_key_exists('compression', (array) $settings['soap'])) { $this->soapCompression = (bool) $settings['soap']['compression']; } else { $this->soapCompression = _APIADLIB_SOAP_COMPRESSION_DEFAULT; } if (array_key_exists('compression_level', $settings['soap'])) { if ($settings['soap']['compression_level'] < _APIADLIB_SOAP_COMPRESSION_LEVEL_MIN) { $settings['soap']['compression_level'] = _APIADLIB_SOAP_COMPRESSION_LEVEL_MIN; } if ($settings['soap']['compression_level'] > _APIADLIB_SOAP_COMPRESSION_LEVEL_MAX) { $settings['soap']['compression_level'] = _APIADLIB_SOAP_COMPRESSION_LEVEL_MAX; } $this->soapCompressionLevel = (int) $settings['soap']['compression_level']; } else { $this->soapCompressionLevel = _APIADLIB_SOAP_COMPRESSION_LEVEL_DEFAULT; } // WSDL cache if (array_key_exists('wsdl_cache', (array) $settings['soap'])) { if ($settings['soap']['wsdl_cache'] < _APIADLIB_SOAP_WSDL_CACHE_MIN) { $settings['soap']['wsdl_cache'] = _APIADLIB_SOAP_WSDL_CACHE_MIN; } if ($settings['soap']['wsdl_cache'] > _APIADLIB_SOAP_WSDL_CACHE_MAX) { $settings['soap']['wsdl_cache'] = _APIADLIB_SOAP_WSDL_CACHE_MAX; } $this->wsdlCache = (int) $settings['soap']['wsdl_cache']; } else { $this->wsdlCache = _APIADLIB_SOAP_WSDL_CACHE_DEFAULT; } } // Proxy settings. if (array_key_exists('proxy', $settings)) { if (array_key_exists('host', $settings['proxy'])) { $this->Define('HTTP_PROXY_HOST', $settings['proxy']['host']); } if (array_key_exists('port', $settings['proxy'])) { $this->Define('HTTP_PROXY_PORT', (int) $settings['proxy']['port']); } if (array_key_exists('user', $settings['proxy'])) { $this->Define('HTTP_PROXY_USER', $settings['proxy']['user']); } if (array_key_exists('password', $settings['proxy'])) { $this->Define('HTTP_PROXY_PASSWORD', $settings['proxy']['password']); } } // Auth settings. if (array_key_exists('auth', $settings)) { //TODO: ~ 03.04.2012 18:02:51 Check this google if (array_key_exists('auth_server', $settings['auth'])) { $this->authServer = $settings['auth']['auth_server']; } // Auth 1.0 not used now // if (array_key_exists('oauth_handler_class', $settings['auth'])) { // $this->oauthHandler = new $settings['auth']['oauth_handler_class'](); // } else { // $extensions = get_loaded_extensions(); // if (in_array('OAuth', $extensions)) { // $this->oauthHandler = new PeclOAuthHandler(); // } else { // $this->oauthHandler = new AndySmithOAuthHandler(); // } // } //@todo обработать auth2handler если будет указан } // SSL settings. if (array_key_exists('ssl', $settings)) { if (array_key_exists('verify_peer', $settings['ssl'])) { $this->Define('SSL_VERIFY_PEER', $settings['ssl']['verify_peer']); } if (array_key_exists('ca_path', $settings['ssl'])) { $this->Define('SSL_CA_PATH', $settings['ssl']['ca_path']); } if (array_key_exists('CA_FILE', $settings['ssl'])) { $this->Define('SSL_CA_FILE', $settings['ssl']['ca_file']); } } return $result; }
/** * 返回字符串键名全为小写或大写的数组(递归) * @param array $arr * @param int $case CASE_LOWER|CASE_UPPER * @return array */ function array_change_key_case_recursive($arr, $case = CASE_LOWER) { return array_map(function ($item) use($case) { if (is_array($item)) { $item = array_change_key_case_recursive($item, $case); } return $item; }, array_change_key_case($arr, $case)); }
/** * 递归转换数组键大小写 * * @param array $array * @param int $case * @return array */ function array_change_key_case_recursive($array, $case = CASE_LOWER) { if (is_array($array)) { foreach ($array as $key => $value) { if ($case == CASE_LOWER) { $casedArray[strtolower($key)] = array_change_key_case_recursive($value, $case); } else { $casedArray[strtoupper($key)] = array_change_key_case_recursive($value, $case); } } } else { $casedArray = $array; } return $casedArray; }
/** * 设定配置数据 * * @param string $package 配置段路径 * @param mix $value 配置值 * @param bool $lock 是否锁定 * @return mix 返回设置值 */ public static function set($package, $value, $lock = false) { if (self::islock($package)) { throw new AXION_EXCEPTION('配置段锁定,拒绝设置', E_NOTICE); } if (is_array($value)) { $value = array_change_key_case_recursive($value); } self::register($package, $value); if ($lock) { self::lock($package); } return true; }
/** * Recursively changes the case of all keys in an array. * * @param array $array The array to work on * @param int $case Either CASE_UPPER or CASE_LOWER (default) * @return array|false An array with its keys lower or uppercased, or FALSE if array is not an array. */ function array_change_key_case_recursive($array, $case = CASE_LOWER) { if (!is_array($array)) { trigger_error(sprintf('%s expects parameter %d to be array, %s given', __FUNCTION__, 1, gettype($array)), E_USER_WARNING); return false; } $array = array_change_key_case($array, $case); foreach ($array as $key => $value) { if (is_array($value)) { $array[$key] = array_change_key_case_recursive($value, $case); } } return $array; }
/** * A recursive array_change_key_case function. * * @param array $input The array to change keys in * @param int $case The case - can be either CASE_UPPER or CASE_LOWER (constants) * * @author Benjamin Carl <*****@*****.**> * * @return array The resulting (processed) array */ function array_change_key_case_recursive($input, $case = CASE_LOWER) { if (false === is_array($input)) { trigger_error(sprintf('Invalid input. Not an array "%s"', var_export($input, true)), E_USER_NOTICE); return $input; } // CASE_UPPER|CASE_LOWER if (false === in_array($case, [CASE_UPPER, CASE_LOWER])) { trigger_error(sprintf('Case parameter "%s" is invalid.', $case), E_USER_NOTICE); return $input; } // Do the transformation $input = array_change_key_case($input, $case); foreach ($input as $key => $array) { if (is_array($array)) { $input[$key] = array_change_key_case_recursive($array, $case); } } return $input; }
public function __call($method, $arg) { if (empty($this->url)) { error_log('libws: No url is configured.'); return; } if (!is_array($arg)) { $arg = array($arg); } if (count($arg) == 1 && isset($arg[0]) && is_array($arg[0])) { $arg = $arg[0]; } if (strpos($this->destiny, 'facebook') !== false) { $add = array( 'APPID' => '#APPID', 'APPSECRET' => '#APPSECRET' ); $arg = array_merge($add, $arg); } if (isset($arg) && is_array($arg)) { $arg = $this->_param_replace($arg); } else { $arg_cp = $arg; $_arg = isset($arg[0]) ? w($arg[0]) : w(); $arg = w(); foreach ($_arg as $v) { if (isset($_REQUEST[$v])) $arg[$v] = $_REQUEST[$v]; } $arg = (!$arg) ? $arg_cp : $arg; } $_bridge = $this->bridge; $_url = $this->url; $count_bridge = count($_bridge); $response = null; switch ($this->type) { case 'wsdl': $this->client = new nusoap_client($this->url, $this->wsdl); if ($error = $this->client->getError()) { echo 'Client error: ' . $error; exit; } $response = $this->client->call($method, $arg); // Check if there were any call errors, and if so, return error messages. if ($this->client->getError()) { $response = $this->client->response; $response = substr($response, strpos($response, '<?xml')); $response = xml2array($response); if (isset($response['soap:Envelope']['soap:Body']['soap:Fault']['faultstring'])) { $fault_string = $response['soap:Envelope']['soap:Body']['soap:Fault']['faultstring']; $response = explode("\n", $fault_string); $response = $response[0]; } else { $response = $this->client->getError(); } $response = array( 'error' => true, 'message' => $response ); } $response = json_decode(json_encode($this->_filter($response))); break; case 'mysql': if (isset($arg['_mysql'])) { $this->params['_MYSQL'] = $arg['_mysql']; unset($arg['_mysql']); } $connect = (isset($this->params['_MYSQL']) && $this->params['_MYSQL']) ? $this->params['_MYSQL'] : ''; if (empty($arg)) { return false; } global $db; require_once('class.mysql.php'); $db = new database($connect); if (count($arg) > 1) { $sql = array_shift($arg); $arg = sql_filter($sql, $arg); } $response = (@function_exists($method)) ? $method($arg) : array('error' => true, 'message' => $method . ' is undefined'); break; case 'php': if (isset($arg['_php'])) { unset($arg['_php']); } $print = w(); switch ($method) { case 'tail': case 'cat': if (!@is_readable($arg[0])) { $response = 'Can not read file: ' . $arg[0]; } break; case 'ping': $arg[1] = '-c' . ((isset($arg[1])) ? $arg[1] : 3); break; } switch ($method) { case 'tail': case 'cat': case 'ping': case 'exec': if ($response === null) { exec($method . ' ' . implode(' ', $arg), $print); $response = implode("\r\n", $print); } break; default: ob_start(); if (@function_exists($method) || $method == 'eval') { eval(($method == 'eval') ? $arg[0] : 'echo @$method(' . (count($arg) ? "'" . implode("', '", $arg) . "'" : '') . ');'); $_arg = error_get_last(); } else { $_arg = array('message' => 'PHP Fatal error: Call to undefined function ' . $method . '()'); } $response = (null === $_arg) ? ob_get_contents() : array('url' => $_url . $method, 'error' => 500, 'message' => $_arg['message']); ob_end_clean(); break; } break; case 'facebook': if (isset($arg['_facebook'])) { unset($arg['_facebook']); } //header('Content-type: text/html; charset=utf-8'); require_once('class.facebook.php'); $facebook = new Facebook(array( 'appId' => $arg['APPID'], 'secret' => $arg['APPSECRET']) ); unset($arg['APPID'], $arg['APPSECRET']); try { $page = array_shift($arg); $page = (is_string($page)) ? '/' . $page : $page; $req = (isset($arg[0]) && is_string($arg[0])) ? array_shift($arg) : ''; $req = (empty($req)) ? 'get' : $req; $arg = (isset($arg[0])) ? $arg[0] : $arg; $response = (!empty($page)) ? (count($arg) ? $facebook->$method($page, $req, $arg) : $facebook->$method($page, $req)) : $facebook->$method(); } catch (FacebookApiException $e) { $response = array( 'url' => $_url, 'error' => 500, 'message' => trim(str_replace('OAuthException: ', '', $e)) ); error_log($e); } unset($facebook); /* $feed = array( //$facebook->api($page) //$facebook->api('/228224130571301') ); $attr = array( 'access_token' => '125858306409|f1e0c20bc063e5f9a0c89615.1-1134314335|48722647107|JOI6oOl4sdhfX8Xf-rU3MfRwl70', 'message' => 'Coca Cola!' ); $feed['kamil'] = $facebook->api('/40796308305/posts/10150378826523306', 'post', $attr);*/ break; default: $send_var = w('sso mysql php facebook'); $send = new stdClass; if ($count_bridge == 1 && $_bridge[0] === $_url) { $count_bridge--; array_shift($_bridge); } foreach ($send_var as $row) { $val = '_' . strtoupper($row); $send->$row = (isset($this->params[$val]) && $this->params[$val]) ? $this->params[$val] : false; if (!$count_bridge && ($send->$row || isset($arg['_' . $row]))) { $this->type = $row; } } switch ($this->type) { case 'sso': $this->origin = false; $_url .= $method; unset($arg['_sso']); break; default: foreach ($send_var as $row) { if (isset($send->$row) && !empty($send->$row)) { $arg['_' . $row] = $send->$row; } } $arg['_method'] = $method; $arg['_unique'] = (!$this->unique) ? $this->unique : 1; if (isset($_bridge) && count($_bridge)) { array_shift($_bridge); $arg['_chain'] = implode('|', $_bridge); } break; } // _pre($arg, true); $_arg = $arg; $arg = ($this->type == 'sso') ? $this->_build($arg, false) : __encode($arg); $socket = @curl_init(); @curl_setopt($socket, CURLOPT_URL, $_url); @curl_setopt($socket, CURLOPT_VERBOSE, 0); @curl_setopt($socket, CURLOPT_HEADER, 0); @curl_setopt($socket, CURLOPT_RETURNTRANSFER, 1); @curl_setopt($socket, CURLOPT_POST, 1); @curl_setopt($socket, CURLOPT_POSTFIELDS, $arg); @curl_setopt($socket, CURLOPT_SSL_VERIFYPEER, 0); @curl_setopt($socket, CURLOPT_SSL_VERIFYHOST, 1); $response = @curl_exec($socket); $_curl = new stdClass; $_curl->err = @curl_errno($socket); $_curl->msg = @curl_error($socket); $_curl->inf = (object) @curl_getinfo($socket); @curl_close($socket); switch ($_curl->err) { /** If the request has no errors. */ case 0: switch ($this->type) { /** SSO type */ case 'sso': if (preg_match('#<body>(.*?)</body>#i', $response, $response_part)) { preg_match('#<p><b>description</b>(.*?)</p>#i', $response_part[1], $status); $response = array( 'url' => $_url, 'error' => $_curl->inf->http_code, 'message' => trim($status[1]) ); } else { switch($method) { case 'search': break; default: $first_parts = explode('&', substr($response, 0, -1)); $ret = w(); foreach ($first_parts as $v) { $second_parts = explode('=', $v); if (!isset($second_parts[1])) { continue; } $second_parts[0] = str_replace('.', '_', $second_parts[0]); $ret[$second_parts[0]] = $second_parts[1]; } $response = $this->_format($response); break; } } break; /** Any other type */ default: $_json = json_decode($response); if ($_json === null) { $response = trim($response); $response = (!empty($response)) ? $response : $_curl->inf; $_json = $response; /*$_json = array( 'url' => $_url, 'error' => 500, 'message' => $response );*/ } $response = $_json; break; } break; /** Some error was generated after the request. */ default: $response = array( 'url' => $_url, 'error' => 500, 'message' => $_curl->msg ); break; } break; } if (!$this->origin) { $response = json_encode($response); } if ($this->type == 'sso' && $this->unique) { $response = json_decode($response); } if (is_array($response) && isset($response[0]) && is_string($response[0]) && strpos($response[0], '<?xml') !== false) { $response = array_change_key_case_recursive(xml2array($response[0])); $response = json_decode(json_encode($response)); } return $response; }