function _init_map_values() { $cache_key = AMP_CACHE_TOKEN_XML_DATA . get_class($this); //check for cached version of map if ($map =& AMP_cache_get($cache_key)) { return $map; } //load map values from XML $map_source = new AMPSystem_XMLEngine('Map'); $map = $map_source->readData(); if (!$map) { return array(); } //load custom extensions to XML map $map_extensions_source = new AMPSystem_XMLEngine('Map_Override'); $map_extensions = $map_extensions_source->readData(); if (!$map_extensions) { $complete_map =& $map; } else { $complete_map = array_merge($map, $map_extensions); } //cache the map AMP_cache_set($cache_key, $complete_map); return $complete_map; }
function _update_image_cache_delete($image_name) { $imageRef =& new AMP_System_File_Image(AMP_image_path($image_name, AMP_IMAGE_CLASS_ORIGINAL)); $image_cache_key = $imageRef->getCacheKeySearch(); $image_cache =& AMP_cache_get($image_cache_key); if (!$image_cache) { return; } unset($image_cache[$image_name]); AMP_cache_set($image_cache_key, $image_cache); }
function loadNavs() { //check for cached version $cache_key = AMP_CACHE_TOKEN_XML_DATA . $this->_filename_navs; $nav_set =& AMP_cache_get($cache_key); if (!$nav_set) { $nav_set = $this->_init_nav_values(); if (!$nav_set) { return false; } $this->convertPermissions($nav_set); AMP_cache_set($cache_key, $nav_set); } foreach ($nav_set as $name => $item) { $new_nav =& $this->addNav($name, $item); } }
function readFields() { if (!($file_name = $this->getFieldFile())) { return false; } //check for cached field defs $cache_key = AMP_CACHE_TOKEN_XML_DATA . $file_name; if ($fields =& AMP_cache_get($cache_key)) { return $fields; } //reload def from XML file $fields = $this->_readXML($file_name); if ($fields) { $fields = array_merge($fields, $this->_getFieldOverrides($file_name)); AMP_cache_set($cache_key, $fields); return $fields; } return false; }
function putmemcache($key, $rs, $host, $port, $compress, $debug = false) { $false = false; $true = true; $AMP_key = AMP_CACHE_TOKEN_ADODB . $key; if ($success = AMP_cache_set($AMP_key, $rs)) { return $true; } else { return false; } /*** * ADODB standard library memcache code * not used by AMP **/ if (!function_exists('memcache_pconnect')) { if ($debug) { ADOConnection::outp(" Memcache module PECL extension not found!<br>\n"); } return $false; } $memcache = new Memcache(); if (!@$memcache->pconnect($host, $port)) { if ($debug) { ADOConnection::outp(" Can't connect to memcache server on: {$host}:{$port}<br>\n"); } return $false; } $rs->timeCreated = time(); if (!$memcache->set($key, $rs, $compress, 0)) { if ($debug) { ADOConnection::outp(" Failed to save data at the memcached server!<br>\n"); } return $false; } return $true; }
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For further information, contact Radical Designs at info@radicaldesigns.org *******************************************/ $intro_id = 2; require_once "AMP/BaseDB.php"; //if the frontpage timeout is actually set it will have a different value from the CACHE_TIMEOUT //otherwise no one cares about this case if (($cached_output = AMP_cached_request()) && AMP_SYSTEM_CACHE_TIMEOUT_FRONTPAGE == AMP_SYSTEM_CACHE_TIMEOUT || $cached_output && ($cached_frontpage_stamp = AMP_cache_get(AMP_CACHE_TOKEN_URL_CONTENT . '_TIMESTAMP_FRONTPAGE')) && AMP_SYSTEM_CACHE_TIMEOUT_FRONTPAGE >= time() - $cached_frontpage_stamp) { print $cached_output; exit; } require_once "AMP/BaseTemplate.php"; if ('index.php' != AMP_CONTENT_URL_FRONTPAGE) { ampredirect(AMP_CONTENT_URL_FRONTPAGE); } $currentPage =& AMPContent_Page::instance(); $currentPage->setListType(AMP_CONTENT_LISTTYPE_FRONTPAGE); require_once 'AMP/Content/Class.inc.php'; $currentClass = new ContentClass(AMP_Registry::getDbcon(), AMP_CONTENT_CLASS_FRONTPAGE); $display =& $currentClass->getDisplay(); $currentPage->contentManager->addDisplay($display); AMP_cache_set(AMP_CACHE_TOKEN_URL_CONTENT . '_TIMESTAMP_FRONTPAGE', time()); require_once 'AMP/BaseFooter.php';
function search($folder_path = false, $filename_pattern = '*') { if (!$folder_path) { return false; } if (substr($folder_path, -1) !== DIRECTORY_SEPARATOR) { $folder_path .= DIRECTORY_SEPARATOR; } $complete_path = $folder_path . $filename_pattern; $folder_cache_key = AMP_CACHE_TOKEN_DIR . $complete_path; $class_name = $this->_class_name; $search_total = 0; $result_set = array(); $dir_contents = $this->_search_limit ? false : AMP_cache_get($folder_cache_key); if (!$dir_contents) { $files = $this->sort_glob(glob($this->create_glob_expression(array('path' => $folder_path, 'pattern' => $filename_pattern)), GLOB_BRACE)); foreach ($files as $file_name) { if (!is_file($file_name)) { continue; } $search_total++; if (isset($this->_search_offset) && $search_total < $this->_search_offset) { continue; } if (isset($this->_search_limit) && count($result_set) >= $this->_search_limit) { break; } $result_set[basename($file_name)] =& new $class_name($file_name); } //Cache Folder results for large searches if (count($result_set) > 500 && !$this->_search_limit) { AMP_cache_set($folder_cache_key, $result_set); } } else { $result_set =& $dir_contents; } #$this->sort( $result_set ); return $result_set; }
function _register_fields() { $md = $this->_module_def; $fields = array_map(array(&$this, "_register_fields_filter"), array_keys($md)); $keys = array('label', 'public', 'type', 'required', 'values', 'lookup', 'size', 'enabled'); foreach ($fields as $fname) { if (!$fname) { continue; } if (!$this->admin) { if (!isset($md['enabled_' . $fname])) { continue; } if (!$md['enabled_' . $fname]) { continue; } } $field = array(); foreach ($keys as $key) { $field[$key] = $md[$key . "_" . $fname]; } $field = $this->_register_lookups($field); $this->fields[$fname] = $field; } //Publish Field Hack if ($this->admin && $md['publish']) { $publish_field = array('type' => 'checkbox', 'label' => '<span class=publish_label>PUBLISH</span>', 'required' => false, 'public' => false, 'values' => 0, 'size' => null, 'enabled' => true); $this->fields['publish'] = $publish_field; } //override from custom folder $override_file_name = 'form' . $this->instance . '.xml'; $override_fields = false; $cache_key = AMP_CACHE_TOKEN_XML_DATA . $override_file_name; if (!($override_fields =& AMP_cache_get($cache_key))) { if (file_exists_incpath($override_file_name)) { require 'AMP/System/XMLEngine.inc.php'; $fieldsource =& new AMPSystem_XMLEngine($override_file_name); $override_fields = $fieldsource->readData(); } } if ($override_fields) { $this->fields = array_merge($this->fields, $override_fields); AMP_cache_set($cache_key, $override_fields); } return true; }
function GenerateCode() { // reset code $this->sCode = ''; // loop through and generate the code letter by letter for ($i = 0; $i < $this->iNumChars; $i++) { if (count($this->aCharSet) > 0) { // select random character and add to code string $this->sCode .= $this->aCharSet[array_rand($this->aCharSet)]; } else { // select random character and add to code string $this->sCode .= chr(rand(65, 90)); } } // save code in session variable $captcha_code = $this->bCaseInsensitive ? strtoupper($this->sCode) : $this->sCode; AMP_cache_set(CAPTCHA_SESSION_ID, $captcha_code); AMP_Form_Element_Captcha::create(CAPTCHA_SESSION_ID, $this->sCode); //$_SESSION[CAPTCHA_SESSION_ID] = $captcha_code; }
function _init_fields() { if (!empty($this->_fields)) { return $this->_fields; } $modin = $this->getModin(); if (!$modin) { return false; } $sourceDef = get_class($this) . $modin; //check registry for field defs $reg =& AMP_Registry::instance(); $definedSources =& $reg->getEntry(AMP_REGISTRY_SYSTEM_DATASOURCE_DEFS); if (!$definedSources) { $definedSources = AMP_cache_get(AMP_REGISTRY_SYSTEM_DATASOURCE_DEFS); } if ($definedSources && isset($definedSources[$sourceDef])) { return $definedSources[$sourceDef]; } require_once 'AMP/System/UserData.php'; $moduleSource =& new AMPSystem_UserData($this->dbcon, $modin); if (!$moduleSource->hasData()) { return false; } $md = $moduleSource->getData(); $fields = $this->_allowed_keys; $keys = array('label', 'public', 'type', 'required', 'values', 'lookup', 'size', 'enabled'); foreach ($fields as $fname) { if (!$fname) { continue; } if (!(isset($md['enabled_' . $fname]) && $md['enabled_' . $fname])) { continue; } $field = array(); foreach ($keys as $key) { $field[$key] = $md[$key . "_" . $fname]; } $field = $this->_register_lookups($field); $this->_fields[$fname] = $field; } //Publish Field Hack if ($md['publish']) { $publish_field = array('type' => 'checkbox', 'label' => '<span class=publish_label>PUBLISH</span>', 'required' => false, 'public' => false, 'values' => 0, 'size' => null, 'enabled' => true); $this->_fields['publish'] = $publish_field; } //cache field defs to registry $definedSources[$sourceDef] = $this->_fields; $reg->setEntry(AMP_REGISTRY_SYSTEM_DATASOURCE_DEFS, $definedSources); AMP_cache_set(AMP_REGISTRY_SYSTEM_DATASOURCE_DEFS, $definedSources); return $this->_fields; }
function &instance($type, $instance_var = null, $lookup_baseclass = "AMPSystemLookup", $clear_existing = false) { static $lookup_set = false; static $cache = false; $empty_value = false; if (!$cache) { $cache = AMP_get_cache(); } $req_class = $lookup_baseclass . '_' . ucfirst($type); if (!class_exists($req_class)) { trigger_error(sprintf(AMP_TEXT_ERROR_LOOKUP_NOT_FOUND, $req_class)); return $empty_value; } if (!isset($instance_var)) { if ($clear_existing) { unset($lookup_set[$type]); return $empty_value; } //standard lookup if (!isset($lookup_set[$type])) { $lookup_cache_key = AMPSystem_Lookup::cache_key($type, $instance_var); $cached_lookup = AMP_cache_get($lookup_cache_key); if (!($cached_lookup && (!method_exists($cached_lookup, 'allow_cache') || $cached_lookup->allow_cache()))) { $lookup_set[$type] = new $req_class(); if (!method_exists($lookup_set[$type], 'allow_cache') || $lookup_set[$type]->allow_cache()) { AMP_cache_set($lookup_cache_key, $lookup_set[$type]); } } else { $lookup_set[$type] = $cached_lookup; } } } else { //instanced lookup if (!isset($lookup_set[$type])) { $lookup_set[$type] = array(); } if ($clear_existing) { unset($lookup_set[$type][$instance_var]); return $empty_value; } if (!isset($lookup_set[$type][$instance_var])) { $lookup_cache_key = AMPSystem_Lookup::cache_key($type, $instance_var); $cached_lookup = AMP_cache_get($lookup_cache_key); if (!$cached_lookup) { $lookup_set[$type][$instance_var] = new $req_class($instance_var); AMP_cache_set($lookup_cache_key, $lookup_set[$type][$instance_var]); } else { $lookup_set[$type][$instance_var] = $cached_lookup; } } return $lookup_set[$type][$instance_var]->dataset; } //AMP_cache_set( AMP_CACHE_TOKEN_LOOKUP . 'Master__' . AMP_SYSTEM_USER_ID, $lookup_set ); return $lookup_set[$type]->dataset; }
/* require_once( 'AMP/System/Lookups.inc.php'); $sites = AMP_lookup( 'subsites'); $server_name = $_SERVER['SERVER_NAME']; foreach( $sites as $site_id => $site_url ) { if ( strpos( $site_url, $_SERVER['SERVER_NAME'])) { define( 'AMP_SYSTEM_SETTING_DB_ID', $site_id ); trigger_error( 'found site id ' . $site_id ); } } if ( !defined( 'AMP_SYSTEM_SETTING_DB_ID')) { define( 'AMP_SYSTEM_SETTING_DB_ID', AMP_CONTENT_SECTION_ID_ROOT ); } */ //check cache $system_setup_key = 'SYSTEM_SETUP_' . AMP_SYSTEM_UNIQUE_ID . '_' . AMP_SYSTEM_SETTING_DB_ID; if (!($SystemSetup = AMP_cache_get($system_setup_key))) { $SystemSetup = new AMP_System_Setup(AMP_Registry::getDbcon()); AMP_cache_set($system_setup_key, $SystemSetup); } $SystemSetup->execute(); //default timezone for php 5.3 if (function_exists('date_default_timezone_set')) { date_default_timezone_set('America/Los_Angeles'); } // enable memcache for adodb if memcache is active if (($cache =& AMP_get_cache()) && strtolower(get_class($cache)) == 'amp_system_cache_memcache') { $dbcon =& AMP_Registry::getDbcon(); $dbcon->memcache = true; $dbcon->cacheSecs = AMP_SITE_CACHE_TIMEOUT; }
/** * Returns the output of a display object * * If the optional name parameter is passed, the {@link _displays_executed} flag is set. If this flag is already * set for the specified name, a value of false is returned. * * If a local method is found having the form _doDisplay[Name], that method is performed on the $display object * and the result returned. ( see {@link _doDisplayBuffer} for an example ) * * If no such method is found, the "execute" method of the display object is called and the result returned. * * @param object $display Display object to be executed * @param string $name String key of display object * @since 3.5.3 * @access protected * @return string Output from the display */ function _doDisplay(&$display, $name = null) { if (!isset($name)) { return $display->execute(); } if (isset($this->_displays_executed[$name]) && $this->_displays_executed[$name]) { return false; } $this->_displays_executed[$name] = true; if ($name) { $display_method = '_doDisplay' . ucfirst($name); if (method_exists($this, $display_method)) { return $this->{$display_method}($display); } } //cache the display output for standard displays if (isset($this->_displays_cacheable[$name])) { $output = $display->execute(); AMP_cache_set($this->_displays_cacheable[$name], $output); return $output; } return $display->execute(); }
function cacheComponent(&$component) { if (AMP_DEBUG_MODE_COMPONENT_CACHE_INACTIVE) { return true; } $id = isset($component->id) ? $component->id : null; $cache_key = $this->getCacheKey($component, $id); if (!$cache_key) { return false; } return AMP_cache_set($cache_key, $component); }
$pattern = '/src\s?=\s?\'((?!http)[\w\d\.\/?= -]*)\'/i'; $replace = 'src="'.$url.'/$1"'; $data = preg_replace($pattern, $replace, $data); $pattern = '/background\s?=\s?"((?!http)[\w\d\.\/?= -]*)"/i'; $replace = 'background="'.$url.'/$1"'; $data = preg_replace($pattern, $replace, $data); $pattern = '/action\s?=\s?"((?!http)[\w\d\.\/?= -]*)"/i'; $replace = 'action="'.$url.'/$1"'; $data = preg_replace($pattern, $replace, $data); $pattern = '/,\'\',\'((?!http)[\w\d\.\/?= -]*)\'/i'; $replace = ',\'\',\''.$url.'/$1\''; $data = preg_replace($pattern, $replace, $data); $pattern = array( "\r", "\n" ); $finalPageHtml = str_replace($pattern, '', $data); */ $finalPageHtml = AMP_absolute_urls($nav_output); if ($format == 'js') { $nav_id = $position . mt_rand(1000, 10000); $finalPageHtml = AMP_js_write($finalPageHtml, $nav_id); //$finalPageHtml = 'var '.$nav_id.'= { value: \''. str_replace( "'", "\'", $finalPageHtml ) . "'};\ndocument.write( ".$nav_id.".value );"; } print $finalPageHtml; if (AMP_is_cacheable_url()) { $cache_key = AMP_CACHE_TOKEN_URL_CONTENT . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; $user_id = defined('AMP_SYSTEM_USER_ID') && AMP_SYSTEM_USER_ID ? AMP_SYSTEM_USER_ID : null; AMP_cache_set($cache_key, $finalPageHtml, $user_id); }
function AMP_block_frequent_requesters() { if (!(defined('AMP_BLOCK_FREQUENT_REQUESTERS') && AMP_BLOCK_FREQUENT_REQUESTERS)) { return; } $key = 'REQUESTED_BY_' . $_SERVER['REMOTE_ADDR']; if (!($value = AMP_cache_get($key))) { $value = 0; } ++$value; AMP_cache_set($key, $value); if ($value > 200 && !AMP_Authenticate('admin')) { trigger_error('Blocking further requests from ' . $_SERVER['REMOTE_ADDR']); exit; } }
function us_xml() { header('Content-type: text/xml'); $cache_key = __FILE__ . '-' . __FUNCTION__ . '-map_ID=' . $this->map_ID; $cached_map = AMP_cache_get($cache_key); if ($cached_map) { return $cached_map; } if (!$this->Range) { //$this->build_range(); } if (!$this->points) { $this->build_points(); } if (!$this->Count) { $this->build_count(); } $out = ""; $out .= '<?xml version="1.0" encoding="iso-8859-1"?>'; $out .= '<us_states>'; $out .= '<state id="default_color"><color>' . $this->P['default_color'] . '</color></state>'; $out .= '<state id="background_color"><color>' . $this->P['background_color'] . '</color></state>'; $out .= '<state id="outline_color"><color>' . $this->P['outline_color'] . '</color></state>'; $out .= '<state id="default_point"><color>' . $this->P['default_point_color'] . '</color><size>' . $this->P['default_point_size'] . '</size><src>' . $this->P['default_point_src'] . '</src></state>'; $out .= '<state id="font_size"><data>' . $this->P['font_size'] . '</data></state>'; $out .= '<state id="state_info_icon"><src>' . $this->P['state_info_icon'] . '</src></state>'; $out .= '<state id="line_color"><color>' . $this->P['line_color'] . '</color></state>'; $out .= '<state id="arc_color"><color>' . $this->P['arc_color'] . '</color></state>'; if ($this->Range) { $x = 0; foreach ($this->Range as $r) { $out .= '<state id="range">'; $out .= '<data>' . $r['range'] . '</data>'; $out .= '<color>' . $r['color'] . '</color>'; $out .= '</state>'; $x++; } } if ($this->points) { foreach ($this->points as $p) { $out .= "\n<state id=\"point\">"; $out .= '<name>' . $p['name'] . '</name>'; $out .= '<loc>' . $p['loc'] . '</loc>'; if (isset($this->P['opacity'])) { $out .= '<opacity>' . $this->P['opacity'] . '</opacity>'; } $out .= '<target>' . $this->P['target'] . '</target>'; if ($p['id']) { $out .= '<url>' . $this->P['point_url'] . $p['id'] . '</url>'; } if ($p['hover']) { $out .= '<hover>' . $p['hover'] . '</hover>'; } $out .= '</state>'; } } foreach ($this->Count as $st => $v) { $out .= "\n" . '<state id="' . $st . '">'; $out .= '<name>' . $v['label'] . '</name>'; $out .= '<data>' . $v['data'] . '</data>'; $out .= '<target>' . $this->P['target'] . '</target>'; if (isset($v['hover']) && $v['hover']) { $out .= '<hover>' . $v['hover'] . '</hover>'; } if ($this->P['state_url'] && isset($v['data']) && $v['data'] >= 1) { $out .= '<url>' . $this->P['state_url'] . $st . '</url>'; } $out .= '</state>'; } $out .= '</us_states>'; AMP_cache_set($cache_key, $out); return $out; }