Skip to content

Commit

Permalink
add reset cache button ; remove autoblogs cache when a new one is added
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurHoaro committed Sep 18, 2014
1 parent 9449653 commit 39eb5d9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
setlocale(LC_TIME, 'fr_FR.UTF-8', 'fr_FR', 'fr');

if( !defined('DOCS_CACHE_DURATION')) define( 'DOCS_CACHE_DURATION', 1800 );
if( !defined('DOCS_CACHE_FILENAME')) define( 'DOCS_CACHE_FILENAME', 'cache_docs' );
if( !defined('AUTOBLOGS_CACHE_DURATION')) define( 'AUTOBLOGS_CACHE_DURATION', 1800 );
if( !defined('AUTOBLOGS_CACHE_FILENAME')) define( 'AUTOBLOGS_CACHE_FILENAME', 'cache_autoblogs' );

if( !defined('ALLOW_FULL_UPDATE')) define( 'ALLOW_FULL_UPDATE', TRUE );
if( !defined('ALLOW_CHECK_UPDATE')) define( 'ALLOW_CHECK_UPDATE', TRUE );
Expand Down Expand Up @@ -136,6 +138,7 @@ function createAutoblog($type, $sitename, $siteurl, $rssurl) {
throw new Exception('Impossible de créer le répertoire.');

updateXML('new_autoblog_added', 'new', $foldername, $sitename, $siteurl, $rssurl);
unlink(AUTOBLOGS_CACHE_FILENAME);
}

function getArticlesPerPage( $type ) {
Expand Down
18 changes: 16 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,18 @@ function check( $folder )
}
}

/**
* RESET CACHE
**/
if( !empty($_GET['reset_cache']) ) {
if( $_GET['reset_cache'] == 'docs' ) {
unlink(DOCS_CACHE_FILENAME);
}
if( $_GET['reset_cache'] == 'autoblogs' ) {
unlink(AUTOBLOGS_CACHE_FILENAME);
}
}

?>
<!DOCTYPE html>
<html lang="fr" dir="ltr">
Expand Down Expand Up @@ -886,7 +898,7 @@ function check( $folder )
<?php } ?>
</section>
<?php }
$fichierCache = 'cache_docs';
$fichierCache = DOCS_CACHE_FILENAME;
// si la page n'existe pas dans le cache ou si elle a expiré (durée paramétrable)
// on lance la génération de la page et on la stoke dans un fichier
if (@filemtime($fichierCache)<time()-(DOCS_CACHE_DURATION)) {
Expand All @@ -906,6 +918,7 @@ function check( $folder )
}
if(!empty( $docs )) {
echo ' <section id="docs">
<p class="cache_link"><a href="?reset_cache=docs">Regénérer le cache</a></p>
<header>
<h2>Autres documents</h2>
</header>
Expand Down Expand Up @@ -950,7 +963,7 @@ function check( $folder )
</nav>

<?php
$fichierCache = 'cache_autoblogs';
$fichierCache = AUTOBLOGS_CACHE_FILENAME;
// si la page n'existe pas dans le cache ou si elle a expiré (durée paramétrable)
// on lance la génération de la page et on la stoke dans un fichier
if (@filemtime($fichierCache)<time()-(AUTOBLOGS_CACHE_DURATION)) {
Expand Down Expand Up @@ -1002,6 +1015,7 @@ function check( $folder )

echo '
</ul>
<p class="cache_link"><a href="?reset_cache=autoblogs">Regénérer le cache</a></p>
<p>'.count($autoblogs).' autoblogs hébergés</p>';

// on recuperre le contenu du buffer
Expand Down
7 changes: 7 additions & 0 deletions resources/autoblog.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,10 @@ section#autoblogs > ul > li .source a:hover {color:darkred; text-decoration:none
#logo { max-width: 250px; }
input[type="text"]{width:15em;}
}
.cache_link {
float:right;
}
.cache_link a {
font-weight:normal;
color: #CCC;
}

0 comments on commit 39eb5d9

Please sign in to comment.