Commit a814004d authored by Erase's avatar Erase
Browse files

Function for delete old conf file if he's not call every 3 weeks

parent 72e4fd5c
...@@ -2,23 +2,30 @@ ...@@ -2,23 +2,30 @@
//~ Include RSS Fusion //~ Include RSS Fusion
require_once 'vendor/RSS-Fusion/index.php'; require_once 'vendor/RSS-Fusion/index.php';
//~ Check if conf file exist
if(!array_key_exists('c', $_GET) if(!array_key_exists('c', $_GET)
OR !isset($_GET['c']) OR !isset($_GET['c'])
OR !file_exists(TL_ROOT . '/../../c/'.$_GET['c'])){ OR !file_exists(TL_ROOT . '/../../c/'.$_GET['c'])){
exit; exit;
} }
$oConf = json_decode(file_get_contents(TL_ROOT . '/../../c/'.$_GET['c'])); $conf = TL_ROOT . '/../../c/'.$_GET['c'];
//~ Update file date (file is deleted if is not updated every 3 weeks)
touch($conf);
//~ Open conf
$oConf = json_decode(file_get_contents($conf));
if($oConf && gettype($oConf) == 'object'){ if($oConf && gettype($oConf) == 'object'){
$_links = $oConf->flux; $_links = $oConf->flux;
//~ Set config
\Config::set('where', $oConf->where); \Config::set('where', $oConf->where);
\Config::set('_starWords', $oConf->_starWords); \Config::set('_starWords', $oConf->_starWords);
\Config::set('_badWords', $oConf->_badWords); \Config::set('_badWords', $oConf->_badWords);
//~ Load feeds
$oFeeds = new FeedReader($_links); $oFeeds = new FeedReader($_links);
if(!is_null($oFeeds->objParseFeed)){ if(!is_null($oFeeds->objParseFeed)){
...@@ -30,6 +37,7 @@ ...@@ -30,6 +37,7 @@
//~ Delete duplicate item by link //~ Delete duplicate item by link
array_push($_c, $item['link']); array_push($_c, $item['link']);
//~ Keywords filter
if((count(Config::get('_starWords')) && $item['show'] == 'star') if((count(Config::get('_starWords')) && $item['show'] == 'star')
OR (!count(Config::get('_starWords')) && $item['show'] == 'show')){ OR (!count(Config::get('_starWords')) && $item['show'] == 'show')){
array_push($_items, $item); array_push($_items, $item);
...@@ -38,6 +46,7 @@ ...@@ -38,6 +46,7 @@
} }
} }
//~ Generate RSS
$rssfeed = '<?xml version="1.0" encoding="UTF-8"?>'; $rssfeed = '<?xml version="1.0" encoding="UTF-8"?>';
$rssfeed .= '<rss version="2.0">'; $rssfeed .= '<rss version="2.0">';
$rssfeed .= '<channel>'; $rssfeed .= '<channel>';
...@@ -65,6 +74,8 @@ ...@@ -65,6 +74,8 @@
$rssfeed .= '</channel>'; $rssfeed .= '</channel>';
$rssfeed .= '</rss>'; $rssfeed .= '</rss>';
//~ Return RSS content
header('Content-type: application/xml'); header('Content-type: application/xml');
echo $rssfeed; echo $rssfeed;
} }
...@@ -52,7 +52,8 @@ ...@@ -52,7 +52,8 @@
session_start(); session_start();
$conf_name = str_replace('.', '', uniqid(rand(), true)); $conf_name = str_replace('.', '', uniqid(rand(), true));
if(file_put_contents(TL_ROOT . '/../../c/'.$conf_name, $conf_storage)){ $path = TL_ROOT . '/../../c/';
if(file_put_contents($path.$conf_name, $conf_storage)){
//~ Generate link to return //~ Generate link to return
$_d['sucess'] = true; $_d['sucess'] = true;
$_d['message'] = "Voici le lien RSS relatif à votre configuration"; $_d['message'] = "Voici le lien RSS relatif à votre configuration";
...@@ -61,6 +62,21 @@ ...@@ -61,6 +62,21 @@
'_' => $_POST '_' => $_POST
); );
//~ Delete old file conf
if ($handle = opendir($path)){
//~ Loop through the directory
while (false !== ($file = readdir($handle))){
//~ Check the file we're doing is actually a file
if (is_file($path.$file) && $file !== 'index.php' && $file !== '.gitignore'){
//~ Check if the file is older than 3 week old
if (filemtime($path.$file) < (time() - (3 * 7 * 24 * 60 * 60))){ //~ 3 weeks
//~ Do the deletion
unlink($path.$file);
}
}
}
}
}else{ }else{
//~ Error //~ Error
$_d['sucess'] = false; $_d['sucess'] = false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment