Ejemplo n.º 1
0
        $old_session_mode = $site_sess->mode;
        $site_sess->mode = 'get';
        // Set $cat_id to 0 to ensure that no category is selected
        $category_dropdown_selfjump = get_category_dropdown(0, 1);
        $site_sess->mode = $old_session_mode;
        save_cache_file($cache_id, $category_dropdown_selfjump);
    }
}
$site_template->register_vars("category_dropdown_selfjump", $category_dropdown_selfjump);
unset($category_dropdown_selfjump);
// -------------------------------------
if (!$cache_enable) {
    $category_dropdown_form = $site_template->parse_template("category_dropdown_form");
} else {
    $cache_id = create_cache_id('data.dropdown_form', array($user_info[$user_table_fields['user_id']], $config['template_dir'], $config['language_dir']));
    if (!($category_dropdown_form = get_cache_file($cache_id))) {
        // Always append session id if cache is enabled
        $old_session_mode = $site_sess->mode;
        $site_sess->mode = 'get';
        $category_dropdown_form = $site_template->parse_template("category_dropdown_form");
        $site_sess->mode = $old_session_mode;
        save_cache_file($cache_id, $category_dropdown_form);
    }
}
$site_template->register_vars("category_dropdown_form", $category_dropdown_form);
unset($category_dropdown_form);
//-----------------------------------------------------
//--- Random Image ------------------------------------
//-----------------------------------------------------
$random_image = defined("SHOW_RANDOM_IMAGE") && SHOW_RANDOM_IMAGE == 0 ? "" : get_random_image();
$site_template->register_vars("random_image", $random_image);
Ejemplo n.º 2
0
/**
 *
 */
function show_cache_file($mime_type)
{
    $cache_file = DIRECTORY_CACHE . '/' . get_cache_file();
    if (file_exists($cache_file)) {
        $gmdate_mod = gmdate("D, d M Y H:i:s", filemtime($cache_file));
        if (!strstr($gmdate_mod, "GMT")) {
            $gmdate_mod .= " GMT";
        }
        if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])) {
            // check for updates
            $if_modified_since = preg_replace("/;.*\$/", "", $_SERVER["HTTP_IF_MODIFIED_SINCE"]);
            if ($if_modified_since == $gmdate_mod) {
                header("HTTP/1.1 304 Not Modified");
                die;
            }
        }
        clearstatcache();
        $fileSize = filesize($cache_file);
        // send headers then display image
        header('Content-Type: ' . $mime_type);
        header('Accept-Ranges: bytes');
        header('Last-Modified: ' . $gmdate_mod);
        header('Content-Length: ' . $fileSize);
        header('Cache-Control: max-age=9999, must-revalidate');
        header('Expires: ' . $gmdate_mod);
        readfile($cache_file);
        die;
    }
}
Ejemplo n.º 3
0
/**
 *
 * @param <type> $mime_type
 * @return <type> 
 */
function show_cache_file($mime_type)
{
    // use browser cache if available to speed up page load
    if (!empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
        if (strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) < strtotime('now')) {
            header('HTTP/1.1 304 Not Modified');
            die;
        }
    }
    $cache_file = get_cache_file($mime_type);
    if (file_exists($cache_file)) {
        // change the modified headers
        $gmdate_expires = gmdate('D, d M Y H:i:s', strtotime('now +10 days')) . ' GMT';
        $gmdate_modified = gmdate('D, d M Y H:i:s') . ' GMT';
        // send content headers then display image
        header('Content-Type: ' . $mime_type);
        header('Accept-Ranges: bytes');
        header('Last-Modified: ' . $gmdate_modified);
        header('Content-Length: ' . filesize($cache_file));
        header('Cache-Control: max-age=' . CACHE_MAX_AGE . ', must-revalidate');
        header('Expires: ' . $gmdate_expires);
        if (!@readfile($cache_file)) {
            $content = file_get_contents($cache_file);
            if ($content != FALSE) {
                echo $content;
            } else {
                display_error('cache file could not be loaded');
            }
        }
        die;
    }
    return FALSE;
}
Ejemplo n.º 4
0
        global $script_url;
        $url = $script_url . '/' . $url;
    }
    return str_replace('./', '', $url);
}
function get_rss_enclosure($file_name, $image_type, $cat_id)
{
    if (!get_file_path($file_name, $image_type, $cat_id, 0, 0)) {
        return array();
    }
    $file = get_file_path($file_name, $image_type, $cat_id, 0, 1);
    $url = get_file_url($file_name, $image_type, $cat_id);
    return array('url' => $url, 'length' => @filesize($file), 'type' => get_mime_content_type($file));
}
$cache_id = create_cache_id('page.rss', array($user_info[$user_table_fields['user_id']], $action, $image_id, $cat_id, $num_items));
if (!$cache_page_rss || !($content = get_cache_file($cache_id))) {
    $old_session_mode = $site_sess->mode;
    $site_sess->mode = 'cookie';
    ob_start();
    $rss_title = format_rss_text($config['site_name']);
    $rss_link = $site_sess->url($script_url);
    $rss_desc = format_rss_text($config['site_name']);
    $rss_lang = "";
    $rss_image = array();
    $rss_ttl = $cache_page_rss ? $cache_lifetime : 0;
    $rss_cat = array();
    $rss_items = array();
    switch ($action) {
        case 'comments':
            if (!$image_id) {
                exit;
Ejemplo n.º 5
0
 function get_cache_expiration($uri_string)
 {
     $cache_path = get_cache_file($uri_string);
     if (!@file_exists($cache_path)) {
         return FALSE;
     }
     if (!($fp = @fopen($cache_path, FOPEN_READ))) {
         return FALSE;
     }
     flock($fp, LOCK_SH);
     $time_str = '';
     while (($char = fgetc($fp)) !== FALSE) {
         if ($char === 'T') {
             break;
         }
         $time_str .= $char;
     }
     flock($fp, LOCK_UN);
     fclose($fp);
     if (ctype_digit($time_str)) {
         return (int) $time_str;
     } else {
         return FALSE;
     }
 }
Ejemplo n.º 6
0
/**
 * 
 */
function show_cache_file($cache_dir) {

	$cache_file = $cache_dir . '/' . get_cache_file();

	if (file_exists($cache_file)) {
    	
		$gmdate_mod = gmdate("D, d M Y H:i:s", filemtime($cache_file));
		
		if(! strstr($gmdate_mod, "GMT")) {
			$gmdate_mod .= " GMT";
		}
		
		if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])) {
		
			// check for updates
			$if_modified_since = preg_replace("/;.*$/", "", $_SERVER["HTTP_IF_MODIFIED_SINCE"]);
			
			if ($if_modified_since == $gmdate_mod) {
				header("HTTP/1.1 304 Not Modified");
				exit;
			}

		}
		
		$fileSize = filesize($cache_file);
		
		// send headers then display image
		header("Content-Type: image/png");
		header("Accept-Ranges: bytes");
		header("Last-Modified: " . $gmdate_mod);
		header("Content-Length: " . $fileSize);
		header("Cache-Control: max-age=9999, must-revalidate");
		header("Expires: " . $gmdate_mod);
		
		readfile($cache_file);
		
		exit;

	}
	
}
Ejemplo n.º 7
0
 *                                                                        *
 *************************************************************************/
$templates_used = 'categories,category_bit,thumbnail_bit';
$main_template = 'categories';
define('GET_CACHES', 1);
define('ROOT_PATH', './');
define('MAIN_SCRIPT', __FILE__);
include ROOT_PATH . 'global.php';
require ROOT_PATH . 'includes/sessions.php';
$user_access = get_permission();
include ROOT_PATH . 'includes/page_header.php';
if (!$cat_id || !isset($cat_cache[$cat_id]) || !check_permission("auth_viewcat", $cat_id)) {
    redirect("index.php");
}
$cache_id = create_cache_id('page.categories', array($user_info[$user_table_fields['user_id']], $cat_id, $page, $perpage, isset($user_info['lightbox_image_ids']) ? substr(md5($user_info['lightbox_image_ids']), 0, 8) : 0, $config['template_dir'], $config['language_dir']));
if (!$cache_page_categories || !($content = get_cache_file($cache_id))) {
    // Always append session id if cache is enabled
    if ($cache_page_categories) {
        $old_session_mode = $site_sess->mode;
        $site_sess->mode = 'get';
    }
    ob_start();
    //-----------------------------------------------------
    //--- SEO variables -----------------------------------
    //-----------------------------------------------------
    $site_template->register_vars(array('prepend_head_title' => $cat_cache[$cat_id]['cat_name'] . " - "));
    //-----------------------------------------------------
    //--- Show Categories ---------------------------------
    //-----------------------------------------------------
    if (!check_permission("auth_upload", $cat_id)) {
        $upload_url = "";
Ejemplo n.º 8
0
/**
 *
 * @param <type> $mime_type 
 */
function show_cache_file($mime_type)
{
    $cache_file = get_cache_file($mime_type);
    if (file_exists($cache_file)) {
        // use browser cache if available to speed up page load
        if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
            if (strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) < strtotime('now')) {
                header('HTTP/1.1 304 Not Modified');
                die;
            }
        }
        clearstatcache();
        $fileSize = filesize($cache_file);
        // change the modified headers
        $gmdate_expires = gmdate("D, d M Y H:i:s", time() + 315360000) . ' GMT';
        $gmdate_modified = gmdate('D, d M Y H:i:s') . ' GMT';
        // send content headers then display image
        header('Content-Type: ' . $mime_type);
        header('Accept-Ranges: bytes');
        header('Last-Modified: ' . $gmdate_modified);
        header('Content-Length: ' . $fileSize);
        header('Cache-Control: max-age=315360000, public');
        header('Expires: ' . $gmdate_expires);
        if (!@readfile($cache_file)) {
            $content = file_get_contents($cache_file);
            if ($content != FALSE) {
                echo $content;
            } else {
                display_error('cache file could not be loaded');
            }
        }
        // we've shown the image so stop processing
        die;
    }
}
Ejemplo n.º 9
0
function has_cache_for($anime_name)
{
    $file = get_cache_file($anime_name);
    return file_exists($file) && filemtime($file) - time() < CACHE_REFRESH_TIME;
}
Ejemplo n.º 10
0
function amr_cache_url($url, $cache = ICAL_EVENTS_CACHE_TTL)
{
    global $amr_lastcache;
    global $amr_globaltz;
    global $amr_options;
    $text = '';
    // if any args are sent then all must be sent - use wp defaults more or less
    // so better to use filters
    add_filter('http_request_timeout', 'amr_set_http_timeout');
    //add_filter( 'http_request_redirection_count', 'amr_' );
    //'httpversion' => apply_filters( 'http_request_version', '1.0' ),  //or 1.1
    /*
    	curl_setopt($c, CURLOPT_RETURNTRANSFER, true);  // just says to return rather than echo
    	curl_setopt($c, CURLOPT_USERAGENT, 'PHP/'.PHP_VERSION);
    	curl_setopt($c, CURLOPT_ENCODING, '');
    	if( strstr( $resource, 'https' ) !== FALSE ) {
    		curl_setopt($c, CURLOPT_SSLVERSION, 3);
    		curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
    		curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 2);
    	}
    	curl_setopt($c, CURLOPT_COOKIESESSION, true);
    	curl_setopt($c, CURLOPT_HEADER, true);
    	if( !ini_get('safe_mode') ){
    		curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
    	}
    */
    //		If (ICAL_EVENTS_DEBUG) echo '<hr />url before decode: '.$url.'<br />';
    $url = html_entity_decode($url);
    //		If (ICAL_EVENTS_DEBUG) echo '<br />url decoded: '.$url.'<hr />';
    $cachedfile = get_cache_file($url);
    if (file_exists($cachedfile)) {
        $c = filemtime($cachedfile);
        if ($c) {
            $amr_lastcache = amr_newDateTime(strftime('%c', $c));
        } else {
            $amr_lastcache = '';
        }
    } else {
        $c = false;
        $amr_lastcache = amr_newDateTime(strftime('%c', 0));
    }
    // must we refresh ?
    if (isset($_REQUEST['nocache']) or isset($_REQUEST['refresh']) or !file_exists($cachedfile) or time() - $c >= $cache * 60 * 60) {
        if (ICAL_EVENTS_DEBUG) {
            echo '<br>Get ical file remotely, it is time to refresh or it is not cached: <br />';
        }
        amrical_mem_debug('We are going to refresh next');
        //$url = urlencode($u);  - do NOT encode - that gives an invalid URL response
        $check = wp_remote_get($url);
        // if use args, must set all - rather use filters and let wp do its thing
        if (is_wp_error($check) or isset($check['response']['code']) and !($check['response']['code'] == 200) or isset($check[0]) and preg_match('#404#', $check[0])) {
            /* is this bit still meaningful or needed ? */
            if (ICAL_EVENTS_DEBUG) {
                echo '<hr /><b>Http request failed </b><br /> Dumping response: ';
                var_dump($check);
            }
            if (is_wp_error($check)) {
                $text = '<br />' . $check->get_error_message() . '</br>';
            } else {
                $text = '';
            }
            $data = false;
        } elseif (!stristr($check['headers']['content-type'], 'text/calendar')) {
            if (amr_check_start_of_file($data = $check['body'])) {
                // well wrong content type, but has the content!! - bad calendar provider
                $data = $check['body'];
                if (current_user_can('manage_options')) {
                    echo '<br />This message is only shown to the administrator, and only when we refresh the file.';
                    echo '<br />The ics url given is issuing an incorrect content type of text/html.' . ' It should be text/calendar. ' . ' Luckily we persevere and check if the content looks like an ics file.' . 'Please inform the provider of the url. ' . 'Their urls may not be recognised by browsers as ics files. <br />';
                }
            } else {
                if (ICAL_EVENTS_DEBUG) {
                    echo '<br />The url given is not returning a calendar file';
                    echo '<br />The response was ';
                    var_dump($check['response']);
                    echo '<br />The content type is ' . $check['headers']['content-type'];
                    echo '<br />The content type of an ics file should be text/calendar. <br />';
                }
                $data = false;
            }
        } else {
            $data = $check['body'];
        }
        // from the http request
        if (!amr_check_start_of_file($data)) {
            $text .= '&nbsp;' . sprintf(__('Error getting calendar file with htpp or curl %s', 'amr-ical-events-list'), $url);
            if (file_exists($cachedfile)) {
                // Try use cached file if it exists
                if (is_object($amr_lastcache)) {
                    $text .= '&nbsp;...' . sprintf(__('Using File last cached at %s', 'amr-ical-events-list'), $amr_lastcache->format('D c'));
                } else {
                    $text .= '&nbsp;...' . __('File last cached time not available', 'amr-ical-events-list');
                }
                echo '<a class="error" href="#" title="' . __('Warning: Events may be out of date. ', 'amr-ical-events-list') . $text . '">!</a>';
                return $cachedfile;
                //return file not data
            } else {
                echo '<a class="error" href="#" title="' . __('No cached ical file for events', 'amr-ical-events-list') . $text . '">!</a>';
                return false;
            }
            return false;
        } else {
            if (ICAL_EVENTS_DEBUG) {
                echo '<br />We have vcalendar in start of file';
            }
        }
        // somebody wanted to pre process ics files that were not well generated?
        // A filter could be added here, but I'm not keen - could add to support load?
        if ($data) {
            /* now save it as a cached file */
            $data = apply_filters('amr-ics-filter', $data, $url);
            if ($dest = fopen($cachedfile, 'w')) {
                if (!fwrite($dest, $data)) {
                    die('Error writing cache file' . $dest);
                }
                fclose($dest);
                $amr_lastcache = amr_newDateTime(date('Y-m-d H:i:s'));
            } else {
                echo '<br />Error opening or creating the cached file <br />' . $cachedfile;
                return false;
            }
        } else {
            echo '<br>Error opening remote file for refresh ' . $url;
            return false;
        }
        if (!isset($amr_lastcache)) {
            $amr_lastcache = amr_newDateTime(date('Y-m-d H:i:s'));
        }
    } else {
    }
    // no need to refresh, use the cached file
    return $cachedfile;
}
Ejemplo n.º 11
0
        $template = "";
    } else {
        $main_template = $template;
    }
} else {
    $template = "";
}
include ROOT_PATH . 'includes/page_header.php';
if (!empty($template)) {
    $clickstream = "<a href=\"" . $site_sess->url(ROOT_PATH . "index.php") . "\">" . $lang['home'] . "</a>" . $config['category_separator'] . str_replace("_", " ", ucfirst($template));
    $site_template->register_vars("clickstream", $clickstream);
    $site_template->print_template($site_template->parse_template($main_template));
    include ROOT_PATH . 'includes/page_footer.php';
}
$cache_id = create_cache_id('page.index', array($user_info[$user_table_fields['user_id']], isset($user_info['lightbox_image_ids']) ? substr(md5($user_info['lightbox_image_ids']), 0, 8) : 0, $config['template_dir'], $config['language_dir']));
if (!$cache_page_index || !($content = get_cache_file($cache_id))) {
    // Always append session id if cache is enabled
    if ($cache_page_index) {
        $old_session_mode = $site_sess->mode;
        $site_sess->mode = 'get';
    }
    ob_start();
    //-----------------------------------------------------
    //--- Show Categories ---------------------------------
    //-----------------------------------------------------
    $categories = get_categories(0);
    if (!$categories) {
        $categories = $lang['no_categories'];
    }
    $site_template->register_vars("categories", $categories);
    unset($categories);