/** * @param $XAPP_BASE_DIRECTORY * @param $XAPP_APP_NAME * @param $XAPP_CLIENT_DIRECTORY * @param $REPOSITORY_ROOT * @param $REPOSITORY_START_PATH * @param $UPLOAD_EXTENSIONS * @param $XFILE_CONFIG * @param string $XAPP_JQUERY_THEME * @param $LOG_DIRECTORY * @param $CONF_FILE * @param $XAPP_SALT_KEY * @param $XF_PROHIBITED_PLUGINS * @param $RELATIVE_VARIABLES * @param $XAPP_COMPONENTS * @param $XAPP_RESOURCE_CONFIG * @param null $XAPP_BOOTSTRAP_OVERRIDE * * @return array */ function createApp($XAPP_BASE_DIRECTORY, $XAPP_APP_NAME, $XAPP_CLIENT_DIRECTORY, $REPOSITORY_ROOT, $REPOSITORY_START_PATH, $UPLOAD_EXTENSIONS, $XFILE_CONFIG, $XAPP_JQUERY_THEME = 'dot-luv', $LOG_DIRECTORY, $CONF_FILE, $XAPP_SALT_KEY, $XF_PROHIBITED_PLUGINS, $RELATIVE_VARIABLES, $XAPP_COMPONENTS, $XAPP_RESOURCE_CONFIG, $XAPP_BOOTSTRAP_OVERRIDE = null) { /*** * prepare and adjust bootstrapper for stand-alone */ if (!defined('XAPP_BASEDIR')) { define('XAPP_BASEDIR', $XAPP_BASE_DIRECTORY); } require_once XAPP_BASEDIR . 'XApp_Service_Entry_Utils.php'; XApp_Service_Entry_Utils::includeXAppCore(); XApp_Service_Entry_Utils::includeXAppRPC(); require_once XAPP_BASEDIR . 'app/Renderer.php'; require_once XAPP_BASEDIR . 'commander/Commander.php'; XApp_App_Commander::loadDependencies(); xapp_setup_language_standalone(); xapp_import('xapp.Utils.Strings'); xapp_import('xapp.Utils.Debugging'); $urlParams = array(); if (isset($_SERVER["QUERY_STRING"])) { XApp_Utils_Strings::parse_str($_SERVER["QUERY_STRING"], $urlParams); if (isset($urlParams['view'])) { unset($urlParams['view']); } } define('XAPP_INDEX', xapp_fix_index()); /*** * Quick'n dirty auth delegate * @TODO replace with new ACL/Permission system */ class XAPP_AUTH_DELEGATE { // salt key, passed from index.php public static $_salt; // xf config, passed from index.php public static $_config; /** * Reject RPC methods * @param $what * @return bool */ public static function authorize($what) { /** * Option 1. Use the xfile config passed from index.php */ if (self::$_config) { $data = (array) json_decode(self::$_config); $allowedActions = $data['ALLOWED_ACTIONS']; $intOp = intval(XApp_Service_Entry_Utils::opToInteger($what)); if ($intOp != XC_OPERATION_UNKOWN) { if ($intOp > 0 && $intOp < count($allowedActions)) { //boundary check return $allowedActions[$intOp]; } } } /** * Option 2. Reject via string match if you like */ switch ($what) { case XC_OPERATION_COPY_STR: case XC_OPERATION_MOVE_STR: case XC_OPERATION_DELETE_STR: case XC_OPERATION_READ_STR: case XC_OPERATION_EDIT_STR: case XC_OPERATION_COMPRESS_STR: case XC_OPERATION_RENAME_STR: case XC_OPERATION_DOWNLOAD_STR: case XC_OPERATION_FILE_UPDATE_STR: case XC_OPERATION_NEW_DIRECTORY_STR: case XC_OPERATION_NEW_FILE_STR: case XC_OPERATION_UPLOAD: case XC_OPERATION_DOWNLOAD: case XC_OPERATION_EXTRACT: return true; } return true; } public function getUserName() { return 'admin'; } public function getToken() { return md5(self::$_salt); } } XAPP_AUTH_DELEGATE::$_salt = $XAPP_SALT_KEY; XAPP_AUTH_DELEGATE::$_config = $XFILE_CONFIG; $authDelegate = new XAPP_AUTH_DELEGATE(); $XAPP_XFILE_CONFIG_ARRAY = array(); $XAPP_XFILE_CONFIG_ARRAY['XAPP_FILE_START_PATH'] = ''; $XAPP_XFILE_CONFIG_ARRAY['XAPP_FILE_ROOT'] = $REPOSITORY_ROOT; require_once XAPP_BASEDIR . 'lib/standalone/StoreDelegate.php'; $extraParams = count($urlParams) ? '&' . http_build_query($urlParams) : ''; if (!$XAPP_RESOURCE_CONFIG) { $XAPP_RESOURCE_CONFIG = ''; } $renderStruct = xapp_commander_render_app(XAPP_BASEDIR, 'xbox', $XAPP_CLIENT_DIRECTORY, $REPOSITORY_ROOT, $REPOSITORY_START_PATH, $UPLOAD_EXTENSIONS, $XFILE_CONFIG, $XAPP_JQUERY_THEME, dirname(XApp_Service_Entry_Utils::getUrl()) . '/', dirname(XApp_Service_Entry_Utils::getUrl()) . '/xapp/commander/plugins/', dirname(XApp_Service_Entry_Utils::getUrl()) . '/' . XAPP_INDEX . '?view=rpc', $authDelegate, '', '', $LOG_DIRECTORY, $XF_PROHIBITED_PLUGINS, 'standalone', 'XCOM_Resource_Renderer', '', new stdClass(), null, null, null, null, dirname(XApp_Service_Entry_Utils::getUrl()) . '/' . XAPP_INDEX . '?view=smdCall' . $extraParams, dirname(XApp_Service_Entry_Utils::getUrl()) . '/' . XAPP_INDEX . '?view=rpc' . $extraParams, 'XApp_Store_Delegate', $CONF_FILE, $XAPP_SALT_KEY, $RELATIVE_VARIABLES, XApp_Service_Entry_Utils::isDebug() === true, $XAPP_COMPONENTS, $XAPP_RESOURCE_CONFIG, $XAPP_BOOTSTRAP_OVERRIDE); return $renderStruct; }
/** * Parses PHP file. * @param string * @return array [class => [prop => comment (or 'use' => [alias => class])] */ public static function parsePhp($code) { if (XApp_Utils_Strings::match($code, '#//nette' . 'loader=(\\S*)#')) { return; // TODO: allways ignore? } $tokens = @token_get_all($code); $namespace = $class = $classLevel = $level = $docComment = NULL; $res = $uses = array(); while (list($key, $token) = each($tokens)) { switch (is_array($token) ? $token[0] : $token) { case T_DOC_COMMENT: $docComment = $token[1]; break; case T_NAMESPACE: $namespace = self::fetch($tokens, array(T_STRING, T_NS_SEPARATOR)) . '\\'; $uses = array(); break; case T_CLASS: case T_INTERFACE: case PHP_VERSION_ID < 50400 ? -1 : T_TRAIT: if ($name = self::fetch($tokens, T_STRING)) { $class = $namespace . $name; $classLevel = $level + 1; if ($docComment) { $res[$class]['class'] = $docComment; } if ($uses) { $res[$class]['use'] = $uses; } } break; case T_FUNCTION: self::fetch($tokens, '&'); if ($level === $classLevel && $docComment && ($name = self::fetch($tokens, T_STRING))) { $res[$class][$name] = $docComment; } break; case T_VAR: case T_PUBLIC: case T_PROTECTED: self::fetch($tokens, T_STATIC); if ($level === $classLevel && $docComment && ($name = self::fetch($tokens, T_VARIABLE))) { $res[$class][$name] = $docComment; } break; case T_USE: while (!$class && ($name = self::fetch($tokens, array(T_STRING, T_NS_SEPARATOR)))) { if (self::fetch($tokens, T_AS)) { $uses[self::fetch($tokens, T_STRING)] = ltrim($name, '\\'); } else { $tmp = explode('\\', $name); $uses[end($tmp)] = $name; } if (!self::fetch($tokens, ',')) { break; } } break; case T_CURLY_OPEN: case T_DOLLAR_OPEN_CURLY_BRACES: case '{': $level++; break; case '}': if ($level === $classLevel) { $class = $classLevel = NULL; } $level--; // break omitted // break omitted case ';': $docComment = NULL; } } return $res; }
/** * @brief Fix common problems with a file path * @param string $path * @param bool $stripTrailingSlash * @return string */ public static function normalizePath($path, $stripTrailingSlash = false, $addTrailingSlash = true) { if ($path == null || $path == '' || !is_string($path)) { return '/'; } //no windows style slashes $path = str_replace('\\', '/', $path); //add leading slash if (!self::isWindows() && $path[0] !== '/') { $path = '/' . $path; } // remove '/./' // ugly, but str_replace() can't replace them all in one go // as the replacement itself is part of the search string // which will only be found during the next iteration while (strpos($path, '/./') !== false) { $path = str_replace('/./', '/', $path); } //remove '/../' while (strpos($path, '/../') !== false) { $path = str_replace('/../', '/', $path); } //remove '..' while (strpos($path, '..') !== false) { $path = str_replace('..', '/', $path); } // remove sequences of slashes $path = preg_replace('#/{2,}#', '/', $path); if ($addTrailingSlash and strlen($path) > 1 and substr($path, -1, 1) !== '/') { $path = $path . '/'; } //remove trailing slash if ($stripTrailingSlash and strlen($path) > 1 and substr($path, -1, 1) === '/') { $path = substr($path, 0, -1); } // remove trailing '/.' if (substr($path, -2) == '/.') { $path = substr($path, 0, -2); } while (preg_match('/\\/\\//', $path)) { $path = str_replace('//', '/', $path); } //normalize unicode if possible $path = XApp_Utils_Strings::normalizeUnicode($path); return $path; }
/** * Creates current HttpRequest object. * @return Request */ public function createHttpRequest() { // DETECTS URI, base path and script path of the request. $url = new XApp_Http_UrlScript(); $url->scheme = !empty($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off') ? 'https' : 'http'; $url->user = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : ''; $url->password = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : ''; // host & port if ((isset($_SERVER[$tmp = 'HTTP_HOST']) || isset($_SERVER[$tmp = 'SERVER_NAME'])) && preg_match('#^([a-z0-9_.-]+|\\[[a-f0-9:]+\\])(:\\d+)?\\z#i', $_SERVER[$tmp], $pair)) { $url->host = strtolower($pair[1]); if (isset($pair[2])) { $url->port = (int) substr($pair[2], 1); } elseif (isset($_SERVER['SERVER_PORT'])) { $url->port = (int) $_SERVER['SERVER_PORT']; } } // path & query if (isset($_SERVER['REQUEST_URI'])) { // Apache, IIS 6.0 $requestUrl = $_SERVER['REQUEST_URI']; } elseif (isset($_SERVER['ORIG_PATH_INFO'])) { // IIS 5.0 (PHP as CGI ?) $requestUrl = $_SERVER['ORIG_PATH_INFO']; if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') { $requestUrl .= '?' . $_SERVER['QUERY_STRING']; } } else { $requestUrl = ''; } $requestUrl = XApp_Utils_Strings::replace($requestUrl, $this->urlFilters['url']); $tmp = explode('?', $requestUrl, 2); $url->path = XApp_Utils_Strings::replace($tmp[0], $this->urlFilters['path']); $url->query = isset($tmp[1]) ? $tmp[1] : ''; // normalized url $url->canonicalize(); $url->path = XApp_Utils_Strings::fixEncoding($url->path); // detect script path if (isset($_SERVER['SCRIPT_NAME'])) { $script = $_SERVER['SCRIPT_NAME']; } elseif (isset($_SERVER['DOCUMENT_ROOT'], $_SERVER['SCRIPT_FILENAME']) && strncmp($_SERVER['DOCUMENT_ROOT'], $_SERVER['SCRIPT_FILENAME'], strlen($_SERVER['DOCUMENT_ROOT'])) === 0) { $script = '/' . ltrim(strtr(substr($_SERVER['SCRIPT_FILENAME'], strlen($_SERVER['DOCUMENT_ROOT'])), '\\', '/'), '/'); } else { $script = '/'; } $path = strtolower($url->path) . '/'; $script = strtolower($script) . '/'; $max = min(strlen($path), strlen($script)); for ($i = 0; $i < $max; $i++) { if ($path[$i] !== $script[$i]) { break; } elseif ($path[$i] === '/') { $url->scriptPath = substr($url->path, 0, $i + 1); } } // GET, POST, COOKIE $useFilter = !in_array(ini_get('filter.default'), array('', 'unsafe_raw')) || ini_get('filter.default_flags'); parse_str($url->query, $query); if (!$query) { $query = $useFilter ? filter_input_array(INPUT_GET, FILTER_UNSAFE_RAW) : (empty($_GET) ? array() : $_GET); } $post = $useFilter ? filter_input_array(INPUT_POST, FILTER_UNSAFE_RAW) : (empty($_POST) ? array() : $_POST); $cookies = $useFilter ? filter_input_array(INPUT_COOKIE, FILTER_UNSAFE_RAW) : (empty($_COOKIE) ? array() : $_COOKIE); $gpc = (bool) get_magic_quotes_gpc(); // remove f*****g quotes, control characters and check encoding if ($gpc || !$this->binary) { $list = array(&$query, &$post, &$cookies); while (list($key, $val) = each($list)) { foreach ($val as $k => $v) { unset($list[$key][$k]); if ($gpc) { $k = stripslashes($k); } if (!$this->binary && is_string($k) && (preg_match(self::NONCHARS, $k) || preg_last_error())) { // invalid key -> ignore } elseif (is_array($v)) { $list[$key][$k] = $v; $list[] =& $list[$key][$k]; } else { if ($gpc && !$useFilter) { $v = stripSlashes($v); } if (!$this->binary && (preg_match(self::NONCHARS, $v) || preg_last_error())) { $v = ''; } $list[$key][$k] = $v; } } } unset($list, $key, $val, $k, $v); } // FILES and create FileUpload objects $files = array(); $list = array(); if (!empty($_FILES)) { foreach ($_FILES as $k => $v) { if (!$this->binary && is_string($k) && (preg_match(self::NONCHARS, $k) || preg_last_error())) { continue; } $v['@'] =& $files[$k]; $list[] = $v; } } while (list(, $v) = each($list)) { if (!isset($v['name'])) { continue; } elseif (!is_array($v['name'])) { if ($gpc) { $v['name'] = stripSlashes($v['name']); } if (!$this->binary && (preg_match(self::NONCHARS, $v['name']) || preg_last_error())) { $v['name'] = ''; } if ($v['error'] !== UPLOAD_ERR_NO_FILE) { $v['@'] = new FileUpload($v); } continue; } foreach ($v['name'] as $k => $foo) { if (!$this->binary && is_string($k) && (preg_match(self::NONCHARS, $k) || preg_last_error())) { continue; } $list[] = array('name' => $v['name'][$k], 'type' => $v['type'][$k], 'size' => $v['size'][$k], 'tmp_name' => $v['tmp_name'][$k], 'error' => $v['error'][$k], '@' => &$v['@'][$k]); } } // HEADERS if (function_exists('apache_request_headers')) { $headers = array_change_key_case(apache_request_headers(), CASE_LOWER); } else { $headers = array(); foreach ($_SERVER as $k => $v) { if (strncmp($k, 'HTTP_', 5) == 0) { $k = substr($k, 5); } elseif (strncmp($k, 'CONTENT_', 8)) { continue; } $headers[strtr(strtolower($k), '_', '-')] = $v; } } $remoteAddr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : NULL; $remoteHost = isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : NULL; // proxy foreach ($this->proxies as $proxy) { if (Helpers::ipMatch($remoteAddr, $proxy)) { if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $remoteAddr = trim(current(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']))); } if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { $remoteHost = trim(current(explode(',', $_SERVER['HTTP_X_FORWARDED_HOST']))); } break; } } $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : NULL; if ($method === 'POST' && isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']) && preg_match('#^[A-Z]+\\z#', $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) { $method = $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']; } return new XApp_Http_Request($url, $query, $post, $files, $cookies, $headers, $method, $remoteAddr, $remoteHost); }
/** * Convert VFS path into real local filesystem path * * @param $path : expected path /mount_point/relative_path/... * @return string : real local filesystem path */ public function toRealPath($path) { if (substr($path, 0, 1) == "/") { $path = substr($path, 1); } $split_path = explode("/", $path); $mount = reset($split_path); $relative = implode(DIRECTORY_SEPARATOR, array_slice($split_path, 1)); $absPart = $this->toAbsolutePath($mount); if (!XApp_Utils_Strings::endsWith($absPart, DIRECTORY_SEPARATOR)) { $absPart .= DIRECTORY_SEPARATOR; } return $absPart . $relative; }
/** * Merge user defined arguments into defaults array. * * This function is used throughout WordPress to allow for both string or array * to be merged into another array. * * @param string|array $args Value to merge with $defaults * @param array $defaults Optional. Array that serves as the defaults. Default empty. * @return array Merged user defined values with defaults. */ public static function parse_args($args, $defaults = '') { xapp_import('xapp.Utils.Strings'); if (is_object($args)) { $r = get_object_vars($args); } elseif (is_array($args)) { $r =& $args; } else { XApp_Utils_Strings::parse_str($args, $r); } if (is_array($defaults)) { return array_merge($defaults, $r); } return $r; }
/** * Starts and initializes session data. * @throws XApp_InvalidStateException * @return void */ public function start() { if (self::$started) { return; } $this->configure($this->options); $id =& $_COOKIE[session_name()]; if (!is_string($id) || !preg_match('#^[0-9a-zA-Z,-]{22,128}\\z#i', $id)) { unset($_COOKIE[session_name()]); } set_error_handler(function ($severity, $message) use(&$error) { // session_start returns FALSE on failure only sometimes if (($severity & error_reporting()) === $severity) { $error = $message; restore_error_handler(); } }); session_start(); if (!$error) { restore_error_handler(); } $this->response->removeDuplicateCookies(); if ($error) { @session_write_close(); // this is needed throw new Exception("session_start(): {$error}"); } self::$started = TRUE; /* structure: __NF: BrowserKey, Data, Meta, Time DATA: section->variable = data META: section->variable = Timestamp, Browser, Version */ $nf =& $_SESSION['__NF']; // regenerate empty session if (empty($nf['Time'])) { $nf['Time'] = time(); $this->regenerated = TRUE; } // browser closing detection $browserKey = $this->request->getCookie('nette-browser'); if (!$browserKey) { $browserKey = XApp_Utils_Strings::random(); } $browserClosed = !isset($nf['B']) || $nf['B'] !== $browserKey; $nf['B'] = $browserKey; // resend cookie $this->sendCookie(); // process meta metadata if (isset($nf['META'])) { $now = time(); // expire section variables foreach ($nf['META'] as $section => $metadata) { if (is_array($metadata)) { foreach ($metadata as $variable => $value) { if (!empty($value['B']) && $browserClosed || !empty($value['T']) && $now > $value['T'] || isset($nf['DATA'][$section][$variable]) && is_object($nf['DATA'][$section][$variable]) && (isset($value['V']) ? $value['V'] : NULL) != XApp_Reflection_ClassType::from($nf['DATA'][$section][$variable])->getAnnotation('serializationVersion')) { if ($variable === '') { // expire whole section unset($nf['META'][$section], $nf['DATA'][$section]); continue 2; } unset($nf['META'][$section][$variable], $nf['DATA'][$section][$variable]); } } } } } if ($this->regenerated) { $this->regenerated = FALSE; $this->regenerateId(); } register_shutdown_function(array($this, 'clean')); }
private function initVariables() { if (xapp_has_option(self::RELATIVE_VARIABLES)) { $rVariables = xapp_get_option(self::RELATIVE_VARIABLES, $this); if (count($rVariables)) { foreach ($rVariables as $variable => $value) { $this->registerRelative($variable, $value); } } } if (xapp_has_option(self::ABSOLUTE_VARIABLES)) { $variables = xapp_get_option(self::ABSOLUTE_VARIABLES, $this); if (count($variables)) { foreach ($variables as $variable => $value) { if (!XApp_Utils_Strings::endsWith($value, DIRECTORY_SEPARATOR)) { $value .= DIRECTORY_SEPARATOR; } $this->registerAbsolute($variable, $value); } } } }
/** * Determine a writable directory for temporary files. * * Function's preference is the return value of sys_get_temp_dir(), * followed by your PHP temporary upload directory, followed by XAppCONTENT_DIR, * before finally defaulting to /tmp/ * * In the event that this function does not find a writable location, * It may be overridden by the XAppTEMP_DIR constant. * * * @return string Writable temporary directory. */ public static function get_temp_dir() { static $temp; xapp_import('xapp.Utils.Strings'); if (defined('XAppTEMP_DIR')) { return XApp_Utils_Strings::trailingslashit(XAppTEMP_DIR); } if ($temp) { return XApp_Utils_Strings::trailingslashit($temp); } if (function_exists('sys_get_temp_dir')) { $temp = sys_get_temp_dir(); if (@is_dir($temp) && self::is_writable($temp)) { return XApp_Utils_Strings::trailingslashit($temp); } } $temp = ini_get('upload_tmp_dir'); if (@is_dir($temp) && self::is_writable($temp)) { return XApp_Utils_Strings::trailingslashit($temp); } $temp = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR); if (is_dir($temp) && self::is_writable($temp)) { return $temp; } $temp = '/tmp/'; return $temp; }
public function request($url, $args = array()) { xapp_import('xapp.Utils.Strings'); xapp_import('xapp.Utils.Arrays'); xapp_import('xapp.Commons.Error'); xapp_import('xapp.Directory.Utils'); $defaults = array('method' => 'GET', 'timeout' => 5, 'redirection' => 5, 'httpversion' => '1.0', 'user-agent' => 'no agent', 'reject_unsafe_urls' => false, 'blocking' => true, 'headers' => array(), 'cookies' => array(), 'body' => null, 'compress' => false, 'decompress' => true, 'sslverify' => true, 'sslcertificates' => null, 'stream' => false, 'filename' => null, 'limit_response_size' => null); // Pre-parse for the HEAD checks. $args = XApp_Utils_Array::parse_args($args); // By default, Head requests do not cause redirections. if (isset($args['method']) && 'HEAD' == $args['method']) { $defaults['redirection'] = 0; } $r = XApp_Utils_Array::parse_args($args, $defaults); // The transports decrement this, store a copy of the original value for loop purposes. if (!isset($r['_redirection'])) { $r['_redirection'] = $r['redirection']; } $arrURL = @parse_url($url); if (empty($url) || empty($arrURL['scheme'])) { return new XApp_Error('http_request_failed', 'A valid URL was not provided.'); } /* * Determine if this is a https call and pass that on to the transport functions * so that we can blacklist the transports that do not support ssl verification */ $r['ssl'] = $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl'; // Determine if this request is to OUR install of WordPress. $r['local'] = 'localhost' == $arrURL['host'] || isset($homeURL['host']) && $homeURL['host'] == $arrURL['host']; /* * If we are streaming to a file but no filename was given drop it in the WP temp dir * and pick its name using the basename of the $url. */ if ($r['stream'] && empty($r['filename'])) { $r['filename'] = XApp_Directory_Utils::get_temp_dir() . basename($url); } /* * Force some settings if we are streaming to a file and check for existence and perms * of destination directory. */ if ($r['stream']) { $r['blocking'] = true; if (!XApp_Directory_Utils::is_writable(dirname($r['filename']))) { return new XApp_Error('http_request_failed', 'Destination directory for file streaming does not exist or is not writable.'); } } if (is_null($r['headers'])) { $r['headers'] = array(); } if (isset($r['headers']['User-Agent'])) { $r['user-agent'] = $r['headers']['User-Agent']; unset($r['headers']['User-Agent']); } if (isset($r['headers']['user-agent'])) { $r['user-agent'] = $r['headers']['user-agent']; unset($r['headers']['user-agent']); } if ('1.1' == $r['httpversion'] && !isset($r['headers']['connection'])) { $r['headers']['connection'] = 'close'; } // Construct Cookie: header if any cookies are set. //XAppHttp::buildCookieHeader( $r ); // Avoid issues where mbstring.func_overload is enabled. XApp_Utils_Strings::mbstring_binary_safe_encoding(); if (!isset($r['headers']['Accept-Encoding'])) { //if ( $encoding = XAppHttp_Encoding::accept_encoding( $url, $r ) ) // $r['headers']['Accept-Encoding'] = $encoding; } if (!is_null($r['body']) && '' != $r['body'] || 'POST' == $r['method'] || 'PUT' == $r['method']) { if (is_array($r['body']) || is_object($r['body'])) { $r['body'] = http_build_query($r['body'], null, '&'); if (!isset($r['headers']['Content-Type'])) { $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'); } } if ('' === $r['body']) { $r['body'] = null; } if (!isset($r['headers']['Content-Length']) && !isset($r['headers']['content-length'])) { $r['headers']['Content-Length'] = strlen($r['body']); } } $response = $this->_dispatch_request($url, $r); XApp_Utils_Strings::reset_mbstring_encoding(); return $response; }
public static function isPictureService() { $domain = gethostbyaddr($_SERVER['REMOTE_ADDR']); $referer = XApp_Service_Entry_Utils::getReferer(false); $pageURL = self::getUrl(); if (self::isDownload() || strpos($pageURL, 'fileUpdate') !== false) { xapp_import('xapp.Utils.Strings'); if ($domain === 'ec2-75-101-241-140.compute-1.amazonaws.com') { return true; } if ($domain === 'ec2-50-19-185-53.compute-1.amazonaws.com') { return true; } if (XApp_Utils_Strings::startsWith($referer, 'http://cdn.pixlr.com/editor/')) { return true; } } return false; }
/** * Computes salted password hash. * @param string * @return string */ protected static function hashPassword($password, $options = NULL) { if ($password === XApp_Utils_Strings::upper($password)) { // perhaps caps lock is on $password = XApp_Utils_Strings::lower($password); } $password = substr($password, 0, self::PASSWORD_MAX_LENGTH); $options = $options ?: implode('$', array('algo' => '$2a', 'cost' => '07', 'salt' => XApp_Utils_Strings::random(22))); return crypt($password, $options); }