Пример #1
0
 function &getCachedComponent($component_type, $id = null, $passthru_value = null)
 {
     if (AMP_DEBUG_MODE_COMPONENT_CACHE_INACTIVE || isset($this->_cache_allowed[$component_type]) && !$this->_cache_allowed[$component_type]) {
         return $this->getComponent($component_type, $passthru_value);
     }
     $empty_value = false;
     $cache =& AMP_get_cache();
     $cache_key = $this->getCacheKey($component_type, $id);
     if (!$cache_key) {
         return $empty_value;
     }
     $component_class = $this->getComponentClass($component_type);
     if (!$component_class) {
         return $empty_value;
     }
     if (!class_exists($component_class) && isset($this->paths[$component_type])) {
         require_once $this->paths[$component_type];
     }
     if ($component = AMP_cache_get($cache_key)) {
         return $component;
     }
     $component = $this->getComponent($component_type, $passthru_value);
     if (!$component) {
         return $empty_value;
     }
     $result = AMP_cache_set($cache_key, $component);
     //$cache->add( $component, $cache_key );
     return $component;
 }
Пример #2
0
 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;
 }
Пример #3
0
 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);
 }
Пример #4
0
 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;
 }
Пример #5
0
function &getmemcache($key, &$err, $timeout = 0, $host, $port)
{
    $false = false;
    $err = false;
    $AMP_key = AMP_CACHE_TOKEN_ADODB . $key;
    if ($cache_value = AMP_cache_get($AMP_key)) {
        return $cache_value;
    } else {
        return $false;
    }
    /***
     * ADODB standard library memcache code
     * not used by AMP
     **/
    if (!function_exists('memcache_pconnect')) {
        $err = 'Memcache module PECL extension not found!';
        return $false;
    }
    $memcache = new Memcache();
    if (!@$memcache->pconnect($host, $port)) {
        $err = 'Can\'t connect to memcache server on: ' . $host . ':' . $port;
        return $false;
    }
    $rs = $memcache->get($key);
    if (!$rs) {
        $err = 'Item with such key doesn\'t exists on the memcached server.';
        return $false;
    }
    $tdiff = intval($rs->timeCreated + $timeout - time());
    if ($tdiff <= 2) {
        switch ($tdiff) {
            case 2:
                if ((rand() & 15) == 0) {
                    $err = "Timeout 2";
                    return $false;
                }
                break;
            case 1:
                if ((rand() & 3) == 0) {
                    $err = "Timeout 1";
                    return $false;
                }
                break;
            default:
                $err = "Timeout 0";
                return $false;
        }
    }
    return $rs;
}
Пример #6
0
 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);
     }
 }
Пример #7
0
 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;
 }
Пример #8
0
    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';
Пример #9
0
 function _commit_cached($action)
 {
     if (array_search($action, $this->_actions_cacheable) === FALSE) {
         return false;
     }
     $cache_key = sprintf(AMP_CACHE_TOKEN_ACTION_OUTPUT, $action) . $_SERVER['REQUEST_URI'];
     $user_id = defined('AMP_SYSTEM_USER_ID') ? AMP_SYSTEM_USER_ID : null;
     $cached_output = AMP_cache_get($cache_key, $user_id);
     if (!$cached_output) {
         return false;
     }
     require_once 'AMP/Content/Buffer.php';
     $buffer =& new AMP_Content_Buffer();
     $buffer->add($cached_output);
     $this->_display->add($buffer, $action);
     $this->_results[$action] = true;
     $this->_action_committed = $action;
     return true;
 }
Пример #10
0
 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;
 }
Пример #11
0
 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;
 }
Пример #12
0
 function AudioPhpCaptcha($sFlitePath = CAPTCHA_FLITE_PATH, $sAudioPath = CAPTCHA_AUDIO_PATH)
 {
     $this->SetFlitePath($sFlitePath);
     $this->SetAudioPath($sAudioPath);
     // retrieve code if already set by previous instance of visual PhpCaptcha
     if ($cached_code = AMP_cache_get(CAPTCHA_SESSION_ID)) {
         $this->sCode = $cached_code;
     }
 }
Пример #13
0
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;
    }
}
Пример #14
0
/*
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;
}
Пример #15
0
 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;
 }
Пример #16
0
 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;
 }