function refresh_rss($feeds) { $all_flux = array(); $guid_in_db = rss_list_guid(); $count_new = 0; $total_feed = count($feeds); $new_feeds = get_new_feeds($feeds); if (!$new_feeds) { return 0; } foreach ($new_feeds as $url => $feed) { if ($feed === FALSE) { continue; } else { $items = $feed['items']; // if we are here, there are new posts in the feed (md5 test on rss file is positive). Now test on each post. // only keep new post that are not in DB (in $guid_in_db) OR that are newer than the last post ever retreived. foreach ($items as $key => $item) { if (in_array($item['bt_id'], $guid_in_db) or $item['bt_date'] <= $feeds[$url]['time']) { unset($items[$key]); } // si le post est plus récent que le dernier post reçu de ce flux, // enregistre la date du post avec le flux // on n’enregistre pas la date de dernière vérification, car la date peut être à un mauvais fuseau. if ($item['bt_date'] > $GLOBALS['liste_flux'][$feeds[$url]['link']]['time']) { $GLOBALS['liste_flux'][$feeds[$url]['link']]['time'] = $item['bt_date']; } } if (!empty($items)) { $all_flux = array_merge($all_flux, $items); } } } // if list of new elements is !empty, save new elements if (!empty($all_flux)) { $count_new = count($all_flux); $ret = bdd_rss($all_flux, 'enregistrer-nouveau'); if ($ret !== TRUE) { echo $ret; } } // save last success time file_put_contents($GLOBALS['fichier_liste_fluxrss'], '<?php /* ' . chunk_split(base64_encode(serialize($GLOBALS['liste_flux']))) . ' */'); return $count_new; }
echo 'Success'; echo new_token(); } catch (Exception $e) { die('Error : Rss RM old entries AJAX: ' . $e->getMessage()); } } // add new RSS link to serialized-DB if (isset($_POST['add-feed'])) { $erreurs = valider_form_rss(); if (!empty($erreurs)) { echo erreurs($erreurs); die; } $new_feed = trim($_POST['add-feed']); $new_feed_folder = htmlspecialchars(trim($_POST['add-feed-folder'])); $feed_array = get_new_feeds(array($new_feed => array()), ''); if (!($feed_array[$new_feed]['infos']['type'] == 'ATOM' or $feed_array[$new_feed]['infos']['type'] == 'RSS')) { die('Error: Invalid ressource (not an RSS/ATOM feed)'); } // adding to serialized-db $GLOBALS['liste_flux'][$new_feed] = array('link' => $new_feed, 'title' => ucfirst($feed_array[$new_feed]['infos']['title']), 'favicon' => 'style/rss-feed-icon.png', 'checksum' => '42', 'time' => '1', 'folder' => $new_feed_folder); // sort list with title $GLOBALS['liste_flux'] = array_reverse(tri_selon_sous_cle($GLOBALS['liste_flux'], 'title')); // save to file file_put_contents($GLOBALS['fichier_liste_fluxrss'], '<?php /* ' . chunk_split(base64_encode(serialize($GLOBALS['liste_flux']))) . ' */'); // Update DB refresh_rss(array($new_feed => $GLOBALS['liste_flux'][$new_feed])); echo 'Success'; echo new_token(); } // mark some element(s) as read