/** * Initializes the globalcache module. * * @return void */ function globalcache_init() { global $CONFIG; if (!isset($CONFIG['globalcache'])) { $CONFIG['globalcache'] = array(); } $servername = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : "SCAVIX_WDF_SERVER"; if (!isset($CONFIG['globalcache']['CACHE']) || !$CONFIG['globalcache']['CACHE']) { $CONFIG['globalcache']['CACHE'] = function_exists('apc_store') ? globalcache_CACHE_APC : globalcache_CACHE_OFF; } if (isset($CONFIG['globalcache']['key_prefix'])) { $GLOBALS['globalcache_key_prefix'] = "K" . md5($servername . "-" . $CONFIG['globalcache']['key_prefix'] . "-" . getAppVersion('nc')); } else { $GLOBALS["globalcache_key_prefix"] = "K" . md5($servername . "-" . session_name() . "-" . getAppVersion('nc')); } register_hook_function(HOOK_POST_INIT, 'globalcache_initialize'); }
/** * @attribute[RequestParam('submitter','bool',false)] * @attribute[RequestParam('skip_minify','bool',false)] * @attribute[RequestParam('random_nc','bool',false)] */ function Start($submitter, $skip_minify, $random_nc) { global $CONFIG; if (!$submitter) { $this->_contentdiv->content("<h1>Select what to minify</h1>"); $form = $this->_contentdiv->content(new Form()); $form->AddHidden('submitter', '1'); $form->AddCheckbox('skip_minify', 'Skip minify (only collect and combine)<br/>'); $form->AddCheckbox('random_nc', 'Generate random name (instead of app version)<br/>'); $form->AddSubmit('Go'); return; } $this->_contentdiv->content("<h1>Minify DONE</h1>"); $parts = array_diff($CONFIG['class_path']['order'], array('system', 'model', 'content')); $paths = array(); foreach ($parts as $part) { $paths = array_merge($paths, $CONFIG['class_path'][$part]); } sort($paths); $root_paths = array(); foreach ($paths as $i => $cp) { $root = true; for ($j = 0; $j < $i && $root; $j++) { if (starts_with($cp, $paths[$j])) { $root = false; } } if ($root) { $root_paths[] = $cp; } } if ($skip_minify) { $GLOBALS['nominify'] = '1'; } $target_path = cfg_get('minify', 'target_path'); system_ensure_path_ending($target_path, true); $target = $target_path . cfg_get('minify', 'base_name'); minify_all($root_paths, $target, $random_nc ? md5(time()) : getAppVersion('nc')); }
<tr> <td colspan="2"> <div id="top"> <table width="100%" cellpadding="8" cellspacing="0"> <tr> <td> <h1>Administration</h1> </td> </tr> </table> </div> <div id="sub"> <div class="BlogStats">Version: <?php getAppVersion(); ?> </div></div> </td> </tr> <tr> <td rowspan="2" class="LeftCell"> <? include_once(dirname(__FILE__).'/includes/menu.inc');?> </td> <td class="MainCell"> <div id="main">
/** * Returns the timezone for an IP address. * * @param string $ip IP address to check (defaults to <get_ip_address>) * @return string Timezone identifier or false on error */ function get_timezone_by_ip($ip = false) { if ($ip === false) { $ip = $GLOBALS['current_ip_addr']; } if (starts_with($ip, "1.1 ") || starts_with($ip, "192.168.")) { return false; } $key = "get_timezone_by_ip." . getAppVersion('nc') . "-" . $ip; $ret = cache_get($key); if ($ret) { return $ret; } /* // new url with api key: $url = "https://api.ipinfodb.com/v3/ip-city/?key=ae4dea477cd8a36cc678c582c3f990fb57a5aae696f878b4e0eee70afa53bf1e&ip=".$GLOBALS['current_ip_addr']."&format=xml"; try { $xml = downloadData($url, false, false, 60 * 60, 2); }catch(Exception $ex){ WdfException::Log("Unable to get Timezone for ".$ip." ($url)",$ex); return false; } if( preg_match_all('/<timeZone>([^<]*)<\/timeZone>/', $xml, $zone, PREG_SET_ORDER) ) { $zone = $zone[0]; if($zone[1] != "") { cache_set($key,$zone[1], 24 * 60 * 60); return $zone[1]; } } // log_error("No timezone found for ".$GLOBALS['current_ip_addr']." via ipinfodb.com"); */ $url = "http://ip-api.com/php/" . $ip; try { $data = @unserialize(downloadData($url, false, false, 60 * 60, 2)); } catch (Exception $ex) { WdfException::Log("Unable to get Timezone for " . $ip . " ({$url}) " . $ex->getMessage(), $ex); return false; } if ($data && $data['status'] == 'success') { $zone = $data['timezone']; cache_set($key, $zone, 24 * 60 * 60); return $zone; } log_error("No timezone found for " . $ip . " via ip-api.com"); $coords = get_coordinates_by_ip($ip); if ($coords === false) { log_error("No timezone found for IP " . $ip . " (missing coordinates)"); // disaster-fallback: use our timezone: return "Etc/GMT+2"; } // ALTERNATIVE 1: // ws.geonames.org had only timeouts on 2/10/2010... // $url = "http://ws.geonames.org/timezone?lat=".$coords['latitude'].'&lng='.$coords['longitude']; $url = "http://api.geonames.org/timezone?lat=" . $coords['latitude'] . '&lng=' . $coords['longitude'] . "&username=scavix"; try { $xml = downloadData($url, false, false, 60 * 60, 2); } catch (Exception $ex) { WdfException::Log("Unable to get Timezone for " . $ip . " ({$url}) " . $ex->getMessage(), $ex); return false; } if (preg_match_all('/<timezoneId>([^<]*)<\\/timezoneId>/', $xml, $zone, PREG_SET_ORDER)) { $zone = $zone[0]; cache_set($key, $zone[1], 24 * 60 * 60); return $zone[1]; } log_error("No timezone found for " . $ip . " via geonames.org"); // ALTERNATIVE 2: $url = "http://www.earthtools.org/timezone/" . $coords['latitude'] . '/' . $coords['longitude']; try { $xml = downloadData($url, false, false, 60 * 60, 2); } catch (Exception $ex) { WdfException::Log("Unable to get Timezone for " . $ip . " ({$url})", $ex); return false; } if (preg_match_all('/<offset>([^<]*)<\\/offset>/', $xml, $zone, PREG_SET_ORDER)) { $zone = $zone[0]; $zone[1] = round($zone[1], 0); $ret = "Etc/GMT" . ($zone[1] < 0 ? $zone[1] : "+" . $zone[1]); cache_set($key, $ret, 24 * 60 * 60); return $ret; } log_error("No timezone found for " . $ip . " via earthtools.org"); // disaster-fallback: use our timezone: return "Etc/GMT+2"; }
/** * searches the $CLASS_PATH for the file that defines the class * @param <type> $class_name * @param <type> $extension * @param <type> $classpath_limit * @return <type> */ function __search_file_for_class($class_name, $extension = "class.php", $classpath_limit = false) { global $CONFIG; $key = "autoload_class-" . getAppVersion('nc') . $class_name . $extension . $classpath_limit; $r = cache_get($key); if ($r !== false) { return $r; } $class_name_lc = strtolower($class_name); $short_class_name = ""; if (strpos($class_name, "_") !== false) { $short_class_name = array_pop(explode("_", $class_name)); $short_class_name_lc = strtolower($short_class_name); } elseif (strpos($class_name, "\\") !== false) { $short_class_name = array_pop(explode("\\", $class_name)); $short_class_name_lc = strtolower($short_class_name); } foreach ($CONFIG['class_path']['order'] as $cp_part) { if (!isset($CONFIG['class_path'][$cp_part])) { continue; } //WdfException::Raise("Invalid ClassPath! No entry for '$cp_part'."); if ($classpath_limit && $cp_part != $classpath_limit) { continue; } foreach ($CONFIG['class_path'][$cp_part] as $path) { if (file_exists("{$path}{$class_name}.{$extension}")) { $ret = "{$path}{$class_name}.{$extension}"; cache_set($key, $ret, $CONFIG['system']['cache_ttl']); return $ret; } if (file_exists("{$path}{$class_name_lc}.{$extension}")) { $ret = "{$path}{$class_name_lc}.{$extension}"; cache_set($key, $ret, $CONFIG['system']['cache_ttl']); return $ret; } if ($short_class_name != "") { if (file_exists("{$path}{$short_class_name}.{$extension}")) { $ret = "{$path}{$short_class_name}.{$extension}"; cache_set($key, $ret, $CONFIG['system']['cache_ttl']); return $ret; } if (file_exists("{$path}{$short_class_name_lc}.{$extension}")) { $ret = "{$path}{$short_class_name_lc}.{$extension}"; cache_set($key, $ret, $CONFIG['system']['cache_ttl']); return $ret; } } } } return false; }
/** * Returns the timezone for an IP address. * * @param string $ip IP address to check (defaults to <get_ip_address>) * @return string Timezone identifier or false on error */ function get_timezone_by_ip($ip = false) { if ($ip === false) { $ip = $GLOBALS['current_ip_addr']; } if (starts_with($ip, "1.1 ") || starts_with($ip, "192.168.1.")) { return false; } $key = "get_timezone_by_ip." . getAppVersion('nc') . "-" . $ip; $ret = cache_get($key); if ($ret) { return $ret; } // new url with api key: $url = "http://api.ipinfodb.com/v2/ip_query.php?key=6a6ef9d4d82491036a4f3dbd465d52d2e2d5253d1285a3dda02b65752b5474f8&ip=" . $GLOBALS['current_ip_addr'] . "&timezone=true"; try { $xml = downloadData($url, false, false, 60 * 60, 2); } catch (Exception $ex) { WdfException::Log("Unable to get Timezone for " . $ip . " ({$url})", $ex); return false; } if (preg_match_all('/<TimezoneName>([^<]*)<\\/TimezoneName>/', $xml, $zone, PREG_SET_ORDER)) { $zone = $zone[0]; if ($zone[1] != "") { cache_set($key, $zone[1], 24 * 60 * 60); return $zone[1]; } } // log_error("No timezone found for ".$GLOBALS['current_ip_addr']." via ipinfodb.com"); $coords = get_coordinates_by_ip($ip); if ($coords === false) { log_error("No timezone found for IP " . $ip . " (missing coordinates)"); // disaster-fallback: use our timezone: return "Etc/GMT+2"; } // ALTERNATIVE 1: // ws.geonames.org had only timeouts on 2/10/2010... // $url = "http://ws.geonames.org/timezone?lat=".$coords['latitude'].'&lng='.$coords['longitude']; $url = "http://api.geonames.org/timezone?lat=" . $coords['latitude'] . '&lng=' . $coords['longitude'] . "&username=scendix"; try { $xml = downloadData($url, false, false, 60 * 60, 2); } catch (Exception $ex) { WdfException::Log("Unable to get Timezone for " . $ip . " ({$url}) " . $ex->getMessage(), $ex); return false; } if (preg_match_all('/<timezoneId>([^<]*)<\\/timezoneId>/', $xml, $zone, PREG_SET_ORDER)) { $zone = $zone[0]; cache_set($key, $zone[1], 24 * 60 * 60); return $zone[1]; } log_error("No timezone found for " . $ip . " via geonames.org"); // ALTERNATIVE 2: $url = "http://www.earthtools.org/timezone/" . $coords['latitude'] . '/' . $coords['longitude']; try { $xml = downloadData($url, false, false, 60 * 60, 2); } catch (Exception $ex) { WdfException::Log("Unable to get Timezone for " . $ip . " ({$url})", $ex); return false; } if (preg_match_all('/<offset>([^<]*)<\\/offset>/', $xml, $zone, PREG_SET_ORDER)) { $zone = $zone[0]; $zone[1] = round($zone[1], 0); $ret = "Etc/GMT" . ($zone[1] < 0 ? $zone[1] : "+" . $zone[1]); cache_set($key, $ret, 24 * 60 * 60); return $ret; } log_error("No timezone found for " . $ip . " via earthtools.org"); // disaster-fallback: use our timezone: return "Etc/GMT+2"; }