Feature Requests #1949622 (Mise en cache + ré-organisation des répertoires)

This commit is contained in:
Leblanc Simon 2008-05-20 20:56:18 +00:00
commit 87ce31754a
14 changed files with 318 additions and 96 deletions

View file

@ -8,7 +8,7 @@ N:Simon Leblanc
P:Simon
E:contact@leblanc-simon.eu
D:2007-12
C:internationalisation, limitation items RSS, bugfixes
C:internationalisation, limitation items RSS, bugfixes, système de cache
N:Guillaume Duhamel
P:Guill

View file

@ -5,6 +5,7 @@ Installation:
* copier les fichiers dans le répertoire souhaité
* éditez le fichier configuration.php
* donnez les droits en écritures pour tous au répertoire "cache/"
* donnez les droits en écritures pour tous aux répertoire "cache/" dans les répertoires contenu dans "template/"
Utilisation:
* Chaque strip est représenté par un fichier SVG et son export en PNG.

View file

@ -1,4 +1,6 @@
SVN :
* ajout d'un système de cache
* correction de bug au niveau des langues
* ajout d'une vue en vignettes
* possibilité d'ajouter des commentaires avec PunBB (http://www.punbb.org)
* légères modifications du template

View file

@ -84,19 +84,39 @@ class configuration
var $shop = 'http://perdu.com';
/**
* HTML template to use
*/
var $template_html = 'template_default.html';
* Use cache feature?
*/
var $use_cache = true;
/**
* cache folder (in the template folder)
*/
var $cache_folder = 'cache';
/**
* HTML template folder
*/
var $template_folder = './template';
/**
* Name of HTML template
*/
var $template_name = 'default';
/**
* Name of RSS template
*/
var $template_rss = 'rss';
/**
* Number of thumbnails per gallery page
*/
var $thumbs_per_page = 5;
/**
* Size of the thumbnails
*/
var $thumb_size = "200px";
/**
* Size of the thumbnails
*/
var $thumb_size = "200px";
}
?>
?>

View file

@ -12,7 +12,7 @@
set_include_path(get_include_path() . PATH_SEPARATOR . getcwd());
require_once 'strip_manager.php';
require_once 'configuration.php';
require_once 'conf/configuration.php';
// hack for passing objects by values instead of reference under PHP5 (but not PHP4)
// damn clone keyword !
@ -37,7 +37,17 @@ class gallery_manager
*/
var $general;
/**
* Base url for asking for strips in gallery
* @var string
*/
var $nav_base_url = "gallery.php?page=";
/**
* Strip manager object
* @var object
*/
var $strip_manager;
/**
* Constructor
@ -46,14 +56,83 @@ class gallery_manager
*/
function gallery_manager() {
//$this->general = new configuration;
$this->strip_manager = new strip_manager();
$sm = new strip_manager();
$this->general = $sm->general;
$this->lang = $sm->lang;
$this->general = $this->strip_manager->general;
$this->lang = $this->strip_manager->lang;
$sm->strips_list_get();
}
/**
* Generate the Gallery output with the template engine.
*
* @access public
*/
function generate() {
if ($this->general->use_cache) {
// use the cache system
include_once 'cache.class.php';
$cache = new STRIPIT_Cache();
// limit the number of strips in Gallery
$limit = $this->general->thumbs_per_page;
if (isset($_GET['limit']) && is_numeric($_GET['limit'])) {
$limit = $_GET['limit'];
if ($limit <= 0) {
$limit = $this->general->thumbs_per_page;
}
}
// the page to view
if( !isset($_GET['page']) || $_GET['page'] == '' || !is_numeric($_GET['page']) ) {
$page = 0;
} else {
$page = $_GET['page'];
if ($page < 0) {
$page = 0;
}
}
$template_folder = $this->general->template_folder.'/'.$this->general->template_name;
$strip_folder = $this->strip_manager->strips_path;
$cache_folder = $this->general->cache_folder;
$language = $this->general->language;
if ($cache->init('gallery-'.$limit.'-'.$page, $template_folder, $strip_folder, $cache_folder, $language)) {
if ($cache->isInCache()) {
// the page is in cache, show cache
$cache->getCache();
} else {
// the cache must be re-generate
ob_start();
$this->_genGallery();
$cache_data = ob_get_contents();
ob_end_clean();
$cache->putInCache($cache_data);
$cache->getCache();
}
} else {
// error in the configuration cache, don't use the cache system
$this->_genGallery();
}
} else {
// don't use the cache system
$this->_genGallery();
}
}
/**
* Generate the HTML template of gallery
*
* @access private
*/
function _genGallery()
{
$this->strip_manager->strips_list_get();
// limit the number of strips in Gallery
$limit = $this->general->thumbs_per_page;
@ -65,7 +144,7 @@ class gallery_manager
}
}
$lastpage = intval(($sm->strips_count - 1) / $limit);
$lastpage = intval(($this->strip_manager->strips_count - 1) / $limit);
if( !isset($_GET['page']) || $_GET['page'] == '' || !is_numeric($_GET['page']) ) {
$element_asked = 0;
@ -84,29 +163,23 @@ class gallery_manager
$start = $element_asked * $limit;
$end = $start + $limit;
if ($end > $sm->strips_count) {
$end = $sm->strips_count;
if ($end > $this->strip_manager->strips_count) {
$end = $this->strip_manager->strips_count;
}
for( $i = $start; $i < $end; $i++ ) {
$sm->strip_info_get( $i );
$this->strip_manager->strip_info_get( $i );
$this->items_list[] = clone($sm); // hack for php4/5 compat
$this->items_list[] = clone($this->strip_manager); // hack for php4/5 compat
}
$this->nav_prev = $this->nav_base_url . ($element_asked - 1) . "&limit=$limit";
$this->nav_next = $this->nav_base_url . ($element_asked + 1) . "&limit=$limit";
$this->nav_last = $this->nav_base_url . $lastpage . "&limit=$limit";
$this->nav_first = $this->nav_base_url . "&limit=$limit";
}
/**
* Generate the Gallery output with the template engine.
*/
function generate() {
$sm = new strip_manager;
$output = new HTML_Template_Flexy($sm->options);
$output->compile('gallery_'.$sm->general->template_html);
$this->nav_prev = $this->nav_base_url . ($element_asked - 1) . "&limit=$limit" . $this->strip_manager->nav_lang_url;
$this->nav_next = $this->nav_base_url . ($element_asked + 1) . "&limit=$limit" . $this->strip_manager->nav_lang_url;
$this->nav_last = $this->nav_base_url . $lastpage . "&limit=$limit" . $this->strip_manager->nav_lang_url;
$this->nav_first = $this->nav_base_url . "&limit=$limit" . $this->strip_manager->nav_lang_url;
$output = new HTML_Template_Flexy($this->strip_manager->options);
$output->compile($this->general->template_folder.'/'.$this->general->template_name.'/gallery_template.html');
$output->outputObject($this,$this->items_list);
}
}
@ -117,4 +190,4 @@ class gallery_manager
$gallerym = new gallery_manager();
$gallerym->generate();
?>
?>

101
rss.php
View file

@ -12,7 +12,7 @@
set_include_path(get_include_path() . PATH_SEPARATOR . getcwd());
require_once 'strip_manager.php';
require_once 'configuration.php';
require_once 'conf/configuration.php';
// hack for passing objects by values instead of reference under PHP5 (but not PHP4)
// damn clone keyword !
@ -36,49 +36,118 @@ class rss_manager
* @var array
*/
var $general;
/**
* Strip manager object
* @var object
*/
var $strip_manager;
/**
* Constructor
*
* Use the {@link strip_manager} to do the stuff, and convert date from the iso8601 to RFC822 format.
*
* @access public
*/
function rss_manager() {
//$this->general = new configuration;
$this->strip_manager = new strip_manager();
$sm = new strip_manager();
$this->general = $sm->general;
$this->lang = $sm->lang;
$this->general = $this->strip_manager->general;
$this->lang = $this->strip_manager->lang;
}
$sm->strips_list_get();
/**
* Init the strip manager
*
* Use the {@link strip_manager} to do the stuff, and convert date from the iso8601 to RFC822 format.
*
* @access private
*/
function _init()
{
$this->strip_manager->strips_list_get();
// limit the number of strip in RSS
$limit = 0;
if (isset($_GET['limit']) && is_numeric($_GET['limit'])) {
// check for have no infinite for
if ($_GET['limit'] > 0 && $_GET['limit'] < $sm->strips_count) {
$limit = $sm->strips_count - $_GET['limit'];
if ($_GET['limit'] > 0 && $_GET['limit'] < $this->strip_manager->strips_count) {
$limit = $this->strip_manager->strips_count - $_GET['limit'];
}
}
for( $i = $sm->strips_count-1; $i >= $limit; $i-- ) { // reverser order
$sm->strip_info_get( $i );
for( $i = $this->strip_manager->strips_count-1; $i >= $limit; $i-- ) { // reverser order
$this->strip_manager->strip_info_get( $i );
// conversion iso8601 -> RFC822
$sm->date = date('r', strtotime($sm->date));
$this->strip_manager->date = date('r', strtotime($this->strip_manager->date));
$this->items_list[] = clone($sm); // hack for php4/5 compat
$this->items_list[] = clone($this->strip_manager); // hack for php4/5 compat
}
}
/**
* Generate the RSS output with the template engine.
*
* @access public
*/
function generate() {
$sm = new strip_manager;
$output = new HTML_Template_Flexy($sm->options);
$output->compile('template.rss');
header('Content-Type: application/rss+xml');
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
if ($this->general->use_cache) {
// use the cache system
include_once 'cache.class.php';
$cache = new STRIPIT_Cache();
$limit = 0;
if (isset($_GET['limit']) && is_numeric($_GET['limit'])) {
$limit = $_GET['limit'];
}
$template_folder = $this->general->template_folder.'/'.$this->general->template_rss;
$strip_folder = $this->strip_manager->strips_path;
$cache_folder = $this->general->cache_folder;
if ($cache->init($limit, $template_folder, $strip_folder, $cache_folder, '', true)) {
if ($cache->isInCache()) {
// the page is in cache, show cache
$cache->getCache();
} else {
// the cache must be re-generate
ob_start();
$this->_genRss();
$cache_data = ob_get_contents();
ob_end_clean();
$cache->putInCache($cache_data);
$cache->getCache();
}
} else {
// error in the configuration cache, don't use the cache system
$this->_genRss();
}
} else {
// don't use the cache system
$this->_genRss();
}
}
/**
* Generate the RSS page
*
* @access private
*/
function _genRss()
{
$this->_init();
$output = new HTML_Template_Flexy($this->strip_manager->options);
$output->compile($this->general->template_folder.'/'.$this->general->template_rss.'/template.rss');
$output->outputObject($this,$this->items_list);
}
}

View file

@ -12,7 +12,7 @@
set_include_path(get_include_path() . PATH_SEPARATOR . getcwd());
require_once 'HTML/Template/Flexy.php';
require_once 'configuration.php';
require_once 'conf/configuration.php';
/**
* Main manager
@ -31,7 +31,7 @@ class strip_manager
* Directory where to find translations files
* @var string
*/
var $lang_path = "./lang";
var $lang_path = "./conf/lang";
/**
* Base url for asking for strips
@ -184,20 +184,24 @@ class strip_manager
* Constructor
*
* Load the {@link configuration}
*
* @access public
*/
function strip_manager() {
$this->general = new configuration;
$this->language();
$this->_language();
}
/**
* Check the asked language and search for translation files
*
* @access private
*/
function language() {
function _language() {
if (isset($_GET[$this->lang_base_key]) && !empty($_GET[$this->lang_base_key])) {
$lang = $_GET[$this->lang_base_key];
$this->nav_lang_url = $this->lang_base_key.$_GET[$this->lang_base_key];
$this->nav_lang_url = '&'.$this->lang_base_key.'='.$_GET[$this->lang_base_key];
} else {
$lang = $this->general->language;
}
@ -205,16 +209,63 @@ class strip_manager
if (file_exists($this->lang_path.'/'.$lang.'.php')) {
require_once $this->lang_path.'/'.$lang.'.php';
$this->lang = new language;
$this->general->language = $lang;
}
}
/**
* Parse the file list and generate the output
*/
* Parse the file list and generate the output
*
* @access public
*/
function generate() {
$this->start();
$this->output();
if ($this->general->use_cache) {
// use the cache system
include_once 'cache.class.php';
$cache = new STRIPIT_Cache();
if( !isset($_GET['strip']) || $_GET['strip'] == '' || !is_numeric($_GET['strip']) ) {
// we must give the last, so we must calculate the last strip :-(
$this->strips_list_get();
$get_strip = $this->strips_count-1;
} else {
$get_strip = $_GET['strip'];
}
if ($get_strip < 0) {
$get_strip = 0;
}
$template_folder = $this->general->template_folder.'/'.$this->general->template_name;
$strip_folder = $this->strips_path;
$cache_folder = $this->general->cache_folder;
$language = $this->general->language;
if ($cache->init($get_strip, $template_folder, $strip_folder, $cache_folder, $language)) {
if ($cache->isInCache()) {
// the page is in cache, show cache
$cache->getCache();
} else {
// the cache must be re-generate
ob_start();
$this->start();
$this->output();
$cache_data = ob_get_contents();
ob_end_clean();
$cache->putInCache($cache_data);
$cache->getCache();
}
} else {
// error in the configuration cache, don't use the cache system
$this->start();
$this->output();
}
} else {
// don't use the cache system
$this->start();
$this->output();
}
}
@ -222,8 +273,12 @@ class strip_manager
* Construct the file list
*
* Add SVG files in the {@link $strips_path} directory and sort them lexically.
* @access public
*/
function strips_list_get() {
// init the array
$this->strips_list = array();
// Open the given directory
$handle = opendir($this->strips_path);
@ -253,6 +308,7 @@ class strip_manager
* Parse meta-data of a given SVG
*
* @param integer index of the file to parse in the {@link $strips_list}
* @access public
*/
function strip_info_get( $element_asked ) {
$this->current_id = $element_asked;
@ -318,6 +374,7 @@ class strip_manager
/**
* Launch {@link strips_list_get}, check the asked strip, construct naviguation menu, launch {@link strip_info_get} on it
* @access public
*/
function start() {
@ -368,12 +425,13 @@ class strip_manager
/**
* Generate the HTML output with the template engine
* @access public
*/
function output() {
$output = new HTML_Template_Flexy($this->options);
$output->compile($this->general->template_html);
$output->compile($this->general->template_folder.'/'.$this->general->template_name.'/template.html');
$output->outputObject($this,$this->elements);
}
}
?>
?>

View file

@ -9,7 +9,7 @@
<meta http-equiv="Content-Type" content="text/HTML; charset=utf-8" />
<meta name=" robot" content="follow, index, all" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="rss.php" />
<link rel="stylesheet" type="text/css" href="style_default.css" />
<link rel="stylesheet" type="text/css" href="{general.template_folder}/{general.template_name}/style.css" />
</head>
@ -34,7 +34,7 @@
<div class="centering">
{foreach:items_list,id,strip}
<div class="shadow">
<a href="{general.url}/{strip.nav_base_url}{strip.current_id}">
<a href="{general.url}/{strip.nav_base_url}{strip.current_id}{strip.nav_lang_url}">
<img class="stripbox"
src="{general.url}/{strip.thumbnail}"
title="{strip.title}"
@ -62,4 +62,4 @@
</body>
</html>
</html>

View file

@ -6,8 +6,8 @@ html {
body {
background-color:#bebfc1;
text-align:center;
margin:0px;
padding:0px;
margin:0px;
padding:0px;
}
a {
@ -30,18 +30,18 @@ a:hover {
}
#footbar {
color:white;
font-size:small;
text-align:center;
background-color:#1f6cd0;
background-image:url("design/gradient2.png");
background-position:bottom left;
background-repeat:repeat-x;
border-top:thin solid black;
border-bottom:thin solid black;
margin-top:1em;
padding-bottom:1em;
clear:left;
color:white;
font-size:small;
text-align:center;
background-color:#1f6cd0;
background-image:url("design/gradient2.png");
background-position:bottom left;
background-repeat:repeat-x;
border-top:thin solid black;
border-bottom:thin solid black;
margin-top:1em;
padding-bottom:1em;
clear:left;
}
#title {
font-size:large;
@ -59,7 +59,7 @@ a:hover {
.stripbox {
border:1px solid black;
background-color:white;
float:left;
float:left;
}
#strip {
@ -194,13 +194,13 @@ a:hover {
#linkbar {
display:inline;
display:inline;
margin-top:2em;
list-style:none;
list-style:none;
}
ul#linkbar li {
display:inline;
display:inline;
}
#main {
@ -208,11 +208,11 @@ ul#linkbar li {
}
#shop_infos {
font-size:medium;
font-weight:bold;
font-size:medium;
font-weight:bold;
}
#forum {
font-size:medium;
font-weight:bold;
}
}

View file

@ -9,7 +9,7 @@
<meta http-equiv="Content-Type" content="text/HTML; charset=utf-8" />
<meta name=" robot" content="follow, index, all" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="rss.php" />
<link rel="stylesheet" type="text/css" href="style_default.css" />
<link rel="stylesheet" type="text/css" href="{general.template_folder}/{general.template_name}/style.css" />
</head>
@ -71,4 +71,4 @@
</body>
</html>
</html>

View file

@ -10,7 +10,7 @@
<meta name=" robot" content="follow, index, all" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="rss.php" />
<link rel="alternate" type="application/rss+xml" title="RSS: 10 items" href="rss.php?limit=10" />
<link rel="stylesheet" type="text/css" href="style_lego.css" />
<link rel="stylesheet" type="text/css" href="{general.template_folder}/{general.template_name}/style.css" />
<link rel="icon" type="image/png" href="favicon.png" />
</head>
@ -58,7 +58,7 @@
<div id="strip_block">
{foreach:items_list,id,strip}
<div class="shadow">
<a href="{general.url}/{strip.nav_base_url}{strip.current_id}">
<a href="{general.url}/{strip.nav_base_url}{strip.current_id}{strip.nav_lang_url}">
<img class="stripbox"
src="{general.url}/{strip.thumbnail}"
title="{strip.title}"
@ -93,4 +93,4 @@
</body>
</html>
</html>

View file

@ -204,5 +204,4 @@ ul#link_bar {
ul#linkbar>li {
display:inline;
margin-left:1em;
}
}

View file

@ -10,7 +10,7 @@
<meta name=" robot" content="follow, index, all" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="rss.php" />
<link rel="alternate" type="application/rss+xml" title="RSS: 10 items" href="rss.php?limit=10" />
<link rel="stylesheet" type="text/css" href="style_lego.css" />
<link rel="stylesheet" type="text/css" href="{general.template_folder}/{general.template_name}/style.css" />
<link rel="icon" type="image/png" href="favicon.png" />
</head>
@ -111,4 +111,4 @@
</body>
</html>
</html>

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:content="http://purl.org/rss/1.0/modules/content/">
@ -47,4 +47,4 @@
{end:}
</channel>
</rss>
</rss>