action.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. require_once("common.php");
  3. //Execution du code en fonction de l'action
  4. switch ($_['action']){
  5. case 'synchronize':
  6. $feeds = $feedManager->populate('name');
  7. echo '------------------------------------------------------------------'."\n";
  8. echo '-------------- Synchronisation du '.date('d/m/Y').' --------------'."\n";
  9. echo '------------------------------------------------------------------'."\n";
  10. echo count($feeds).' Flux a synchroniser...'."\n";
  11. foreach ($feeds as $feed) {
  12. $feed->parse();
  13. echo date('H:i:s').' - Flux '.$feed->getName().' : OK'."\n";;
  14. }
  15. break;
  16. case 'readAll':
  17. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  18. $feed = (isset($_['feed'])?array('feed'=>$_['feed']):null);
  19. $eventManager->change(array('unread'=>'0'),$feed);
  20. header('location: ./index.php');
  21. break;
  22. case 'updateConfiguration':
  23. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  24. //Ajout des préférences et reglages
  25. $configurationManager->put('root',$_['root']);
  26. //$configurationManager->put('view',$_['view']);
  27. $configurationManager->put('articleView',$_['articleView']);
  28. $configurationManager->put('articlePerPages',$_['articlePerPages']);
  29. $configurationManager->put('articleDisplayLink',$_['articleDisplayLink']);
  30. $configurationManager->put('articleDisplayDate',$_['articleDisplayDate']);
  31. $configurationManager->put('articleDisplayAuthor',$_['articleDisplayAuthor']);
  32. //Création du dossier de base
  33. $folder =$folderManager->load(array('id'=>1));
  34. $folder->setName($_['category']);
  35. $folder->save();
  36. header('location: ./addFeed.php');
  37. break;
  38. case 'exportFeed':
  39. /*********************/
  40. /** Export **/
  41. /*********************/
  42. if(isset($_POST['exportButton'])){
  43. $feeds = $feedManager->populate('name');
  44. $xmlStream = '<?xml version="1.0" encoding="utf-8"?>
  45. <opml version="2.0">
  46. <head>
  47. <title>Leed export</title>
  48. <ownerName>Leed</ownerName>
  49. <ownerEmail>idleman@idleman.fr</ownerEmail>
  50. <dateCreated>'.date('D, d M Y H:i:s').'+0000</dateCreated>
  51. </head>
  52. <body>
  53. <outline text="Leed" title="Leed" icon="">'."\n";
  54. foreach($feeds as $feed){
  55. $xmlStream .= ' <outline xmlUrl="'.$feed->getUrl().'" htmlUrl="'.$feed->getWebsite().'" text="'.$feed->getDescription().'" title="'.$feed->getName().'" description="'.$feed->getDescription().'" />'."\n";
  56. }
  57. $xmlStream .= ' </outline>
  58. </body>
  59. </opml>';
  60. header('Content-Description: File Transfer');
  61. header('Content-Type: application/octet-stream');
  62. header('Content-Disposition: attachment; filename=leed-'.date('d-m-Y').'.opml');
  63. header('Content-Transfer-Encoding: binary');
  64. header('Expires: 0');
  65. header('Cache-Control: must-revalidate');
  66. header('Pragma: public');
  67. header('Content-Length: ' . strlen($xmlStream));
  68. /*
  69. //A decommenter dans le cas ou on a des pb avec ie
  70. if(preg_match('/msie|(microsoft internet explorer)/i', $_SERVER['HTTP_USER_AGENT'])){
  71. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  72. header('Pragma: public');
  73. }else{
  74. header('Pragma: no-cache');
  75. }
  76. */
  77. ob_clean();
  78. flush();
  79. echo $xmlStream;
  80. }
  81. break;
  82. case 'changeFolderState':
  83. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  84. $folderManager->change(array('isopen'=>$_['isopen']),array('id'=>$_['id']));
  85. break;
  86. case 'importFeed':
  87. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  88. if(isset($_POST['importButton'])){
  89. set_time_limit (360);
  90. $xml = simplexml_load_file($_FILES['newImport']['tmp_name']);
  91. $level = $xml->xpath('body//outline');
  92. foreach($level as $item){
  93. $level2 = $item->outline;
  94. foreach($level2 as $item2){
  95. $newFeed = new Feed();
  96. $newFeed->setName($item2[0]['title']);
  97. $folder = $folderManager->load(array('name'=>$item['title']));
  98. $folder = (!$folder?new Folder():$folder);
  99. $folder->setName($item['title']);
  100. $folder->setParent(-1);
  101. $folder->setIsopen(0);
  102. $folder->save();
  103. $newFeed->setFolder($folder->getId());
  104. $newFeed->setUrl($item2[0]['xmlUrl']);
  105. $newFeed->setDescription($item2[0]['description']);
  106. $newFeed->setWebsite($item2[0]['htmlUrl']);
  107. $newFeed->save();
  108. $newFeed->parse();
  109. }
  110. }
  111. header('location: ./addFeed.php');
  112. }
  113. break;
  114. case 'addFeed':
  115. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  116. if(isset($_['newUrl'])){
  117. $newFeed = new Feed();
  118. $newFeed->setUrl($_['newUrl']);
  119. $newFeed->getInfos();
  120. $newFeed->setFolder(1);
  121. $newFeed->save();
  122. $newFeed->parse();
  123. header('location: ./addFeed.php');
  124. }
  125. break;
  126. case 'removeFeed':
  127. /**************************/
  128. /** Supression d'une url **/
  129. /**************************/
  130. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  131. if(isset($_GET['id'])){
  132. $feedManager->delete(array('id'=>$_GET['id']));
  133. header('location: ./addFeed.php');
  134. }
  135. break;
  136. case 'readContent':
  137. $event = $eventManager->load(array('id'=>$_GET['id']));
  138. $event->setUnread(0);
  139. $event->save();
  140. header('location: '.$event->getGuid());
  141. break;
  142. case 'login':
  143. if(isset($_['usr'])){
  144. $user = $userManager->existAuthToken($_['usr']);
  145. if($user==false){
  146. exit("erreur identification : le compte est inexistant");
  147. }else{
  148. $_SESSION['currentUser'] = serialize($user);
  149. header('location: ./action.php?action=addFeed&newUrl='.$_['newUrl']);
  150. }
  151. }else{
  152. $user = $userManager->exist($_['login'],$_['password']);
  153. if($user==false){
  154. exit("erreur identification : le compte est inexistant");
  155. }else{
  156. $_SESSION['currentUser'] = serialize($user);
  157. }
  158. header('location: ./index.php');
  159. }
  160. break;
  161. case 'logout':
  162. $_SESSION = array();
  163. session_unset();
  164. session_destroy();
  165. header('location: ./index.php');
  166. break;
  167. default:
  168. exit('0');
  169. break;
  170. }
  171. ?>