Browse Source

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

merge-requests/1/head
Erase 4 years ago
parent
commit
a814004d8a
2 changed files with 30 additions and 3 deletions
  1. +13
    -2
      flux.php
  2. +17
    -1
      generate.php

+ 13
- 2
flux.php View File

@ -2,23 +2,30 @@
//~ Include RSS Fusion
require_once 'vendor/RSS-Fusion/index.php';
//~ Check if conf file exist
if(!array_key_exists('c', $_GET)
OR !isset($_GET['c'])
OR !file_exists(TL_ROOT . '/../../c/'.$_GET['c'])){
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'){
$_links = $oConf->flux;
//~ Set config
\Config::set('where', $oConf->where);
\Config::set('_starWords', $oConf->_starWords);
\Config::set('_badWords', $oConf->_badWords);
//~ Load feeds
$oFeeds = new FeedReader($_links);
if(!is_null($oFeeds->objParseFeed)){
@ -30,6 +37,7 @@
//~ Delete duplicate item by link
array_push($_c, $item['link']);
//~ Keywords filter
if((count(Config::get('_starWords')) && $item['show'] == 'star')
OR (!count(Config::get('_starWords')) && $item['show'] == 'show')){
array_push($_items, $item);
@ -38,6 +46,7 @@
}
}
//~ Generate RSS
$rssfeed = '<?xml version="1.0" encoding="UTF-8"?>';
$rssfeed .= '<rss version="2.0">';
$rssfeed .= '<channel>';
@ -65,6 +74,8 @@
$rssfeed .= '</channel>';
$rssfeed .= '</rss>';
//~ Return RSS content
header('Content-type: application/xml');
echo $rssfeed;
}

+ 17
- 1
generate.php View File

@ -52,7 +52,8 @@
session_start();
$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
$_d['sucess'] = true;
$_d['message'] = "Voici le lien RSS relatif à votre configuration";
@ -61,6 +62,21 @@
'_' => $_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{
//~ Error
$_d['sucess'] = false;


Loading…
Cancel
Save