/** * Modul to localize ip-adresses. * * Uses the [free version of GeoIP](http://www.maxmind.com/app/geolitecity) from maxmind. * In the majority of cases maxmind publishes updates for the GeoLiteCity.dat on the first day each month. * @return void */ function geoip_init() { global $CONFIG; if (!function_exists('geoip_country_code_by_name')) { require_once __DIR__ . "/geoip/geoip.inc"; require_once __DIR__ . "/geoip/geoipcity.inc"; } if (!system_is_module_loaded('curlwrapper')) { WdfException::Raise("Missing module: curlwrapper!"); } if (!isset($GLOBALS['current_ip_addr'])) { $GLOBALS['current_ip_addr'] = get_ip_address(); } if (!isset($CONFIG['geoip']['city_dat_file'])) { $CONFIG['geoip']['city_dat_file'] = __DIR__ . "/geoip/GeoLiteCity.dat"; } if (!file_exists($CONFIG['geoip']['city_dat_file'])) { WdfException::Raise("GeoIP module: missing GeoLiteCity.dat! Get it from http://dev.maxmind.com/geoip/legacy/geolite/"); } }
/** * Returns a list of all keys in the cache * * Note that the returned array contains all key that are in one of the requested stores. * Means that there may be keys that are only in SESSION, but not in globalcache. * @param bool $global_cache If true checks the global cache (see globalcache module) * @param bool $session_cache If true checks the SESSION cache * @return array All defined keys */ function cache_list_keys($global_cache = true, $session_cache = true) { $res = $session_cache ? array_keys($_SESSION["system_internal_cache"]) : array(); if ($global_cache && system_is_module_loaded('globalcache')) { $res = array_merge($res, globalcache_list_keys()); } sort($res); return array_unique($res); }
/** * @override */ function WdfRender() { if (!$this->get('isrtl') && system_is_module_loaded('localization')) { $ci = Localization::detectCulture(); if ($ci->IsRTL) { $this->set("isrtl", " dir='rtl'"); } } $res = $this->__collectResources(); $this->js = array_reverse($this->js, true); foreach (array_reverse($res) as $r) { if (starts_with(pathinfo($r, PATHINFO_EXTENSION), 'css')) { $this->addCss($r); } else { $this->addjs($r); } } $this->js = array_reverse($this->js, true); $this->set("css", $this->css); $this->set("js", $this->js); $this->set("meta", $this->meta); $this->set("content", $this->_content); return parent::WdfRender(); }
/** * Same as ExecuteScalar, but uses the cache. * * @param string $sql SQL statement * @param array $prms Arguments for $sql * @param int $lifetime Lifetime in seconds * @return mixed The first scalar */ function CacheExecuteScalar($sql, $prms = array(), $lifetime = 300) { if (!system_is_module_loaded('globalcache')) { return $this->ExecuteScalar($sql, $prms); } $key = 'SB_Cache_Scalar_' . md5($sql . serialize($prms)); $null = null; if (is_null($res = cache_get($key, $null, true, false))) { $res = $this->ExecuteScalar($sql, $prms); cache_set($key, $res, $lifetime, true, false); } return $res; }
/** * @internal Renders the response for output. */ function Render() { if ($this->_data) { if (isset($this->_data->script)) { $this->_data->script = "<script>" . implode("\n", $this->_data->script) . "</script>"; } $res = system_to_json($this->_data); } elseif ($this->_text) { $res = json_encode($this->_text); } else { return '""'; } // return an empty string JSON encoded to not kill the app JS side return !$this->_translated && system_is_module_loaded("translation") ? __translate($res) : $res; }
/** * @internal SysAdmin cache manager. * @attribute[RequestParam('search','string',false)] * @attribute[RequestParam('show_info','bool',false)] * @attribute[RequestParam('kind','string','Search key')] */ function Cache($search, $show_info, $kind) { $this->content("<h1>Cache contents</h1>"); $form = $this->content(new Form()); $form->AddText('search', $search); $form->AddSubmit('Search key')->name = 'kind'; $form->AddSubmit('Search content')->name = 'kind'; $form->content(' '); $form->content(new Anchor(buildQuery('sysadmin', 'cacheclear'), 'Clear the complete cache')); if (system_is_module_loaded('globalcache')) { $form->content(' '); $form->content(new Anchor(buildQuery('sysadmin', 'cache', 'show_info=1'), 'Global cache info')); } $form->content('<div><b>Predefined searches:</b><br/>'); foreach ($this->PrefedinedCacheSearches as $s) { $form->content(new Anchor(buildQuery('sysadmin', 'cache', "search={$s}"), "{$s}")); $form->content(' '); } $form->content('</div>'); if (!isset($_SESSION['admin_handler_last_cache_searches'])) { $_SESSION['admin_handler_last_cache_searches'] = array(); } if (count($_SESSION['admin_handler_last_cache_searches']) > 0) { $form->content('<div><b>Last searches:</b><br/>'); foreach ($_SESSION['admin_handler_last_cache_searches'] as $s) { list($k, $s) = explode(":", $s); $form->content(new Anchor(buildQuery('sysadmin', 'cache', "search={$s}" . ($k != 'key' ? '&kind=Search content' : '')), "{$k}:{$s}")); $form->content(' '); } $form->content('</div>'); } if ($show_info && system_is_module_loaded('globalcache')) { $form->content("<pre>" . globalcache_info() . "</pre>"); } if ($search) { if (!in_array($search, $this->PrefedinedCacheSearches)) { $_SESSION['admin_handler_last_cache_searches'][] = $kind == 'Search content' ? "content:{$search}" : "key:{$search}"; $_SESSION['admin_handler_last_cache_searches'] = array_unique($_SESSION['admin_handler_last_cache_searches']); } $this->content("<br/>"); $tabform = $this->content(new Form()); $tabform->action = buildQuery('sysadmin', 'cachedelmany'); $tab = $tabform->content(new Table())->addClass('bordered'); $tab->SetHeader('', 'key', 'action'); $q = buildQuery('sysadmin', 'cachedel'); foreach (cache_list_keys() as $key) { $found = $kind == 'Search content' ? stripos(render_var(cache_get($key, "")), $search) !== false : stripos($key, $search) !== false; if ($found) { $cb = new CheckBox('keys[]'); $cb->value = $key; $del = new Anchor('', 'delete'); $del->onclick = "\$.post('{$q}',{key:'" . addslashes($key) . "'},function(){ \$('#{$del->id}').parents('.tr').fadeOut(function(){ \$(this).remove(); }); })"; $tab->AddNewRow($cb, $key, $del); } } $footer = $tab->Footer()->NewCell(); $footer->colspan = 2; $footer->content(new Anchor('', 'all'))->onclick = "\$('#{$tab->id} .tbody input').prop('checked',true);"; $footer->content(' '); $footer->content(new Anchor('', 'none'))->onclick = "\$('#{$tab->id} .tbody input').prop('checked',false)"; $footer = $tab->Footer()->NewCell(); $footer->content(new Anchor('', 'delete'))->onclick = "\$('#{$tabform->id}').submit()"; } }