You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.1 KiB

5 years ago
  1. <?php
  2. //~ Include RSS Fusion
  3. require_once 'vendor/RSS-Fusion/index.php';
  4. //~ Array for return
  5. $_d = array(
  6. 'sucess' => false,
  7. 'message' => "",
  8. 'data' => array()
  9. );
  10. //~ Check data
  11. if(array_key_exists('flux', $_POST) && !empty($_POST['flux'])){
  12. $_links = array_unique(
  13. array_map('trim',
  14. explode(',', $_POST['flux'])
  15. )
  16. );
  17. //~ Where to look
  18. if(array_key_exists('where', $_POST) && !empty($_POST['where'])){
  19. \Config::set('where', $_POST['where']);
  20. }
  21. //~ Show or hide keywords
  22. if(array_key_exists('filter', $_POST) && !empty($_POST['filter'])){
  23. $mode = "_starWords";
  24. if($_POST['filter'] === 'hide'){
  25. $mode = "_badWords";
  26. }
  27. Config::set($mode, array_unique(
  28. array_map('trim',
  29. explode(',', $_POST['words'])
  30. )
  31. ));
  32. }
  33. $oFeeds = new FeedReader($_links);
  34. if(!is_null($oFeeds->objParseFeed)){
  35. //~ Config is ok ! Storage
  36. $conf_storage = json_encode(array(
  37. 'flux' => $_links,
  38. 'where' => \Config::get('where'),
  39. '_starWords' => \Config::get('_starWords'),
  40. '_badWords' => \Config::get('_badWords')
  41. ));
  42. session_start();
  43. $conf_name = str_replace('.', '', uniqid(rand(), true));
  44. if(file_put_contents(TL_ROOT . '/../../c/'.$conf_name, $conf_storage)){
  45. //~ Generate link to return
  46. $_d['sucess'] = true;
  47. $_d['message'] = "Voici le lien RSS relatif à votre configuration";
  48. $_d['data'] = array(
  49. 'file' => './flux.php?c='.$conf_name,
  50. '_' => $_POST
  51. );
  52. }else{
  53. //~ Error
  54. $_d['sucess'] = false;
  55. $_d['message'] = "Une erreur est survenue lors de l'enregistrement de votre configuration";
  56. }
  57. }else{
  58. $_d['sucess'] = false;
  59. $_d['message'] = "Une erreur est survenue lors du chargement de flux RSS";
  60. }
  61. }else{
  62. //~ No data
  63. $_d['sucess'] = false;
  64. $_d['message'] = "Merci de renseigner au moins une URL de flux RSS";
  65. }
  66. header('Content-type: text/json');
  67. echo json_encode($_d);
  68. exit;