/** * Downloads remote contents into a string. * * @param string $url URL to download * @param array|string $postdata Data to POST, associative array or string from <http_build_query> * @param array $request_header Headers to send along with the request (one entry per header) * @param int $cacheTTLsec If set: time to life in cache * @param int $request_timeout Timeout in seconds * @param array $response_header <b>OUT</b> Will contain the reponse headers * @param string $cookie_file Name of the cookie file to use * @return string The downloaded data */ function downloadData($url, $postdata = false, $request_header = array(), $cacheTTLsec = false, $request_timeout = 120, &$response_header = false, $cookie_file = false) { if (starts_with($url, '//')) { $url = urlScheme() . ':' . $url; } if ($cacheTTLsec) { $hash = md5($url . "|" . ($postdata ? serialize($postdata) : "")); $ret = cache_get("CURL_{$hash}"); if ($ret !== false) { return $ret; } } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($ch, CURLOPT_TIMEOUT, abs($request_timeout)); if ($postdata) { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); if (is_string($postdata)) { if (!is_array($request_header)) { $request_header = array(); } $request_header[] = "Content-Length: " . strlen($postdata); } } curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); if ($cookie_file) { curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); } if (is_array($request_header) && count($request_header) > 0) { curl_setopt($ch, CURLOPT_HTTPHEADER, $request_header); } $result = curl_exec($ch); $info = curl_getinfo($ch); if ($result === false) { log_error('Curl error: ' . curl_error($ch), "url = ", $url, "curl_info = ", $info); curl_close($ch); return $result; } //log_info($info); curl_close($ch); if ($response_header !== false) { $response_header = substr($result, 0, $info['header_size']); } $result = substr($result, $info['header_size']); if ($cacheTTLsec) { cache_set("CURL_{$hash}", $result, $cacheTTLsec); } return $result; }
/** * @internal Translates an URL in a CSS file into something absolute */ function minify_css_translate_url($match) { global $current_url; $url = trim($match[1], "\"' "); if (starts_with($url, 'data:')) { return $match[0]; } $copy = $current_url; $url = parse_url($url); $url = array_merge($copy, $url); if (isset($url['host'])) { if (!isset($url['scheme']) || !$url['scheme']) { $url['scheme'] = urlScheme(); } $url = $url['scheme'] . "://" . $url['host'] . (isset($url['port']) ? ":{$url['port']}" : "") . $url['onlypath'] . $url['path']; } else { $url = $url['onlypath'] . $url['path']; } return "url({$url})"; }
/** * Resets the global $CONFIG variable to defauls values. * * Just sets some useful default values. This is also a good reference of the basic system variables. * @param bool $reset If true resets the config completely to default, extends/overwrites only if false * @return void */ function system_config_default($reset = true) { global $CONFIG; # see http://www.php.net/manual/de/session.configuration.php ini_set('session.hash_function', 1); ini_set('session.hash_bits_per_character', 5); if ($reset) { $CONFIG = array(); } $CONFIG['class_path']['system'][] = __DIR__ . '/reflection/'; $CONFIG['class_path']['system'][] = __DIR__ . '/base/'; $CONFIG['class_path']['content'][] = __DIR__ . '/lib/'; $CONFIG['class_path']['content'][] = __DIR__ . '/lib/controls/'; $CONFIG['class_path']['content'][] = __DIR__ . '/lib/controls/'; $CONFIG['class_path']['content'][] = __DIR__ . '/lib/controls/form/'; $CONFIG['class_path']['content'][] = __DIR__ . '/lib/controls/table/'; $CONFIG['class_path']['content'][] = __DIR__ . '/lib/controls/locale/'; $CONFIG['class_path']['content'][] = __DIR__ . '/lib/jquery-ui/'; $CONFIG['class_path']['content'][] = __DIR__ . '/lib/jquery-ui/dialog/'; $CONFIG['class_path']['content'][] = __DIR__ . '/lib/jquery-ui/slider/'; $CONFIG['class_path']['content'][] = __DIR__ . '/lib/widgets/'; $CONFIG['class_path']['content'][] = __DIR__ . '/lib/google/'; $CONFIG['class_path']['content'][] = __DIR__ . '/lib/fusioncharts/'; $CONFIG['class_path']['order'] = array('system', 'model', 'content'); $CONFIG['system']['path_root'] = __DIR__; $CONFIG['requestparam']['ignore_case'] = true; $CONFIG['requestparam']['tagstostrip'] = array('script'); $CONFIG['model']['internal']['auto_create_tables'] = true; $CONFIG['model']['internal']['datasource_type'] = 'DataSource'; $CONFIG['model']['internal']['debug'] = false; $CONFIG['system']['application_name'] = 'wdf_application'; $CONFIG['system']['cache_datasource'] = 'internal'; $CONFIG['system']['cache_ttl'] = 3600; // secs $CONFIG['system']['hook_logging'] = false; $CONFIG['system']['attach_session_to_ajax'] = false; $CONFIG['system']['ajax_debug_argument'] = false; $CONFIG['system']['header']['Content-Type'] = "text/html; charset=utf-8"; $CONFIG['system']['header']['X-XSS-Protection'] = "1; mode=block"; $path = explode("index.php", $_SERVER['PHP_SELF']); if (!isset($_SERVER['REQUEST_SCHEME'])) { $_SERVER['REQUEST_SCHEME'] = urlScheme(false); } if (!isset($_SERVER['HTTP_HOST'])) { $_SERVER['HTTP_HOST'] = '127.0.0.1'; } $CONFIG['system']['url_root'] = "{$_SERVER['REQUEST_SCHEME']}://{$_SERVER['HTTP_HOST']}{$path[0]}"; $CONFIG['system']['modules'] = array(); $CONFIG['system']['default_page'] = "HtmlPage"; $CONFIG['system']['default_event'] = false; $CONFIG['system']['tpl_ext'] = array("tpl.php"); $CONFIG['system']['admin']['enabled'] = false; $CONFIG['system']['admin']['username'] = false; $CONFIG['system']['admin']['password'] = false; $CONFIG['system']['htmlpage']['doctype'] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'; $CONFIG['system']['htmlpage']['render_noscript'] = true; }