action.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <?php
  2. set_time_limit(0);
  3. require_once("common.php");
  4. //Execution du code en fonction de l'action
  5. switch ($_['action']){
  6. case 'synchronize':
  7. $synchronisationType = $configurationManager->get('synchronisationType');
  8. $maxEvents = $configurationManager->get('feedMaxEvents');
  9. if(isset($_['format'])) echo '<textarea style="width:100%;height: 500px;overflow:auto;">';
  10. echo '------------------------------------------------------------------'."\n";
  11. echo '-------------- Synchronisation du '.date('d/m/Y H:i:s').' --------------'."\n";
  12. echo '------------------------------------------------------------------'."\n";
  13. if($synchronisationType=='graduate'){
  14. $feeds = $feedManager->loadAll(null,'lastupdate','10');
  15. echo 'Synchronisation graduée...'."\n";
  16. }else{
  17. $feeds = $feedManager->populate('name');
  18. echo 'Synchronisation complete...'."\n";
  19. }
  20. echo count($feeds).' Flux a synchroniser...'."\n";
  21. foreach ($feeds as $feed) {
  22. echo date('H:i:s').' - Flux '.$feed->getName().' ('.$feed->getUrl().') parsage des flux...'."\n";
  23. $feed->parse();
  24. echo date('H:i:s').' - Flux '.$feed->getName().' ('.$feed->getUrl().') supression des vieux evenements...'."\n";
  25. if($maxEvents!=0) $feed->removeOldEvents($maxEvents);
  26. echo date('H:i:s').' - Flux '.$feed->getName().' ('.$feed->getUrl().') termin&eacute;'."\n";
  27. }
  28. echo date('H:i:s').' - Synchronisation terminée'."\n";
  29. if(isset($_['format'])) echo '</textarea>';
  30. break;
  31. case 'readAll':
  32. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  33. $feed = (isset($_['feed'])?array('feed'=>$_['feed']):null);
  34. $eventManager->change(array('unread'=>'0'),$feed);
  35. header('location: ./index.php');
  36. break;
  37. case 'readFolder':
  38. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  39. $feeds = $feedManager->loadAllOnlyColumn('id',array('folder'=>$_['folder']));
  40. foreach($feeds as $feed){
  41. $eventManager->change(array('unread'=>'0'),array('feed'=>$feed->getId()));
  42. }
  43. header('location: ./index.php');
  44. break;
  45. case 'updateConfiguration':
  46. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  47. //Ajout des préférences et reglages
  48. $configurationManager->put('root',$_['root']);
  49. //$configurationManager->put('view',$_['view']);
  50. $configurationManager->put('articleView',$_['articleView']);
  51. $configurationManager->add('articleDisplayContent',$_['articleDisplayContent']);
  52. $configurationManager->add('articleDisplayAnonymous',$_['articleDisplayAnonymous']);
  53. $configurationManager->put('articlePerPages',$_['articlePerPages']);
  54. $configurationManager->put('articleDisplayLink',$_['articleDisplayLink']);
  55. $configurationManager->put('articleDisplayDate',$_['articleDisplayDate']);
  56. $configurationManager->put('articleDisplayAuthor',$_['articleDisplayAuthor']);
  57. $configurationManager->put('plugin_shaarli',(isset($_['plugin_shaarli']) && $_['plugin_shaarli']=='on'?1:0));
  58. $configurationManager->put('plugin_shaarli_link',$_['plugin_shaarli_link']);
  59. $configurationManager->put('synchronisationType',$_['synchronisationType']);
  60. $configurationManager->add('feedMaxEvents',$_['feedMaxEvents']);
  61. header('location: ./addFeed.php');
  62. break;
  63. case 'exportFeed':
  64. /*********************/
  65. /** Export **/
  66. /*********************/
  67. if(isset($_POST['exportButton'])){
  68. $feeds = $feedManager->populate('name');
  69. $folders = $folderManager->loadAll(array('parent'=>-1),'name');
  70. $xmlStream = '<?xml version="1.0" encoding="utf-8"?>
  71. <opml version="2.0">
  72. <head>
  73. <title>Leed export</title>
  74. <ownerName>Leed</ownerName>
  75. <ownerEmail>idleman@idleman.fr</ownerEmail>
  76. <dateCreated>'.date('D, d M Y H:i:s').'+0000</dateCreated>
  77. </head>
  78. <body>';
  79. $xmlStream .= Functions::recursiveExportOutline($folders);
  80. // foreach($folders as $folder){
  81. // $feeds = $folder->getFeeds();
  82. // $xmlStream .='<outline text="'.$folder->getName().'" title="'.$folder->getName().'" icon="">'."\n";
  83. // foreach($feeds as $feed){
  84. // $xmlStream .= ' <outline xmlUrl="'.$feed->getUrl().'" htmlUrl="'.$feed->getWebsite().'" text="'.$feed->getDescription().'" title="'.$feed->getName().'" description="'.$feed->getDescription().'" />'."\n";
  85. // }
  86. // $xmlStream .= ' </outline>';
  87. // }
  88. $xmlStream .= '</body>
  89. </opml>';
  90. header('Content-Description: File Transfer');
  91. header('Content-Type: application/octet-stream');
  92. header('Content-Disposition: attachment; filename=leed-'.date('d-m-Y').'.opml');
  93. header('Content-Transfer-Encoding: binary');
  94. header('Expires: 0');
  95. header('Cache-Control: must-revalidate');
  96. header('Pragma: public');
  97. header('Content-Length: ' . strlen($xmlStream));
  98. /*
  99. //A decommenter dans le cas ou on a des pb avec ie
  100. if(preg_match('/msie|(microsoft internet explorer)/i', $_SERVER['HTTP_USER_AGENT'])){
  101. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  102. header('Pragma: public');
  103. }else{
  104. header('Pragma: no-cache');
  105. }
  106. */
  107. ob_clean();
  108. flush();
  109. echo $xmlStream;
  110. }
  111. break;
  112. case 'importForm':
  113. echo '<link rel="stylesheet" href="css/style.css"><form action="action.php?action=importFeed" method="POST" enctype="multipart/form-data"><h2>Importer les flux au format opml</h2>
  114. <p>Fichier OPML : <input name="newImport" type="file"/> <button name="importButton">Importer</button></p>
  115. <p>Nb : L\'importation peux prendre un certain temps, laissez votre navigateur tourner et allez vous prendre un caf&eacute; :).</p></form>
  116. ';
  117. break;
  118. case 'changeFolderState':
  119. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  120. $folderManager->change(array('isopen'=>$_['isopen']),array('id'=>$_['id']));
  121. break;
  122. case 'importFeed':
  123. if (ob_get_level() == 0) ob_start();
  124. ignore_user_abort(true);
  125. echo '<link rel="stylesheet" href="css/style.css"><ul style="font-family:Verdana;">';
  126. echo str_pad('',4096)."\n";ob_flush();flush();
  127. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  128. if(isset($_POST['importButton'])){
  129. echo '<li>Lecture du fichier OPML...</li>';
  130. echo str_pad('',4096)."\n";ob_flush();flush();
  131. $xml = simplexml_load_file($_FILES['newImport']['tmp_name']);
  132. $report = 'Import de flux depart : '.date('d/m/Y H:i:s')."\n";
  133. echo '<li>Parsage recursif du fichier OPML...</li>';
  134. echo str_pad('',4096)."\n";ob_flush();flush();
  135. $report .= Functions::recursiveImportXmlOutline($xml->body->outline,1);
  136. $report .= 'Import de flux fin : '.date('d/m/Y H:i:s')."\n";
  137. echo '<li>Création des logs d\'imports....</li>';
  138. echo str_pad('',4096)."\n";ob_flush();flush();
  139. file_put_contents('./logs/Import du '.date('d-m-Y').'.log', $report ,FILE_APPEND);
  140. echo '<li>Import des flux terminé.</li>';
  141. echo str_pad('',4096)."\n";ob_flush();flush();
  142. echo '</ul>';
  143. echo str_pad('',4096)."\n";ob_flush();flush();
  144. ob_end_flush();
  145. //header('location: ./addFeed.php');
  146. }
  147. break;
  148. case 'addFeed':
  149. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  150. if(isset($_['newUrl'])){
  151. $newFeed = new Feed();
  152. $newFeed->setUrl($_['newUrl']);
  153. $newFeed->getInfos();
  154. $newFeed->setFolder((isset($_['newUrlCategory'])?$_['newUrlCategory']:1));
  155. $newFeed->save();
  156. $newFeed->parse();
  157. header('location: ./addFeed.php');
  158. }
  159. break;
  160. case 'changeFeedFolder':
  161. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  162. if(isset($_['feed'])){
  163. $feedManager->change(array('folder'=>$_['folder']),array('id'=>$_['feed']));
  164. }
  165. header('location: ./addFeed.php');
  166. break;
  167. case 'removeFeed':
  168. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  169. if(isset($_GET['id'])){
  170. $feedManager->delete(array('id'=>$_['id']));
  171. $eventManager->delete(array('feed'=>$_['id']));
  172. }
  173. header('location: ./addFeed.php');
  174. break;
  175. case 'addFolder':
  176. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  177. if(isset($_['newFolder'])){
  178. $folder = new Folder();
  179. if($folder->rowCount(array('name'=>$_['newFolder']))==0){
  180. $folder->setParent(-1);
  181. $folder->setIsopen(0);
  182. $folder->setName($_['newFolder']);
  183. $folder->save();
  184. }
  185. }
  186. header('location: ./addFeed.php');
  187. break;
  188. case 'renameFolder':
  189. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  190. if(isset($_['id'])){
  191. $folderManager->change(array('name'=>$_['name']),array('id'=>$_['id']));
  192. }
  193. break;
  194. case 'removeFolder':
  195. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  196. if(isset($_['id'])){
  197. $eventManager->customExecute('DELETE FROM event WHERE event.feed in (SELECT feed.id FROM feed WHERE feed.folder ='.$_['id'].') ;');
  198. $feedManager->delete(array('folder'=>$_['id']));
  199. $folderManager->delete(array('id'=>$_['id']));
  200. }
  201. header('location: ./addFeed.php');
  202. break;
  203. case 'readContent':
  204. $event = $eventManager->load(array('id'=>$_['id']));
  205. if($myUser!=false) $eventManager->change(array('unread'=>'0'),array('id'=>$_['id']));
  206. break;
  207. case 'unreadContent':
  208. $event = $eventManager->load(array('id'=>$_['id']));
  209. if($myUser!=false) $eventManager->change(array('unread'=>'1'),array('id'=>$_['id']));
  210. break;
  211. case 'addFavorite':
  212. $eventManager->change(array('favorite'=>'1'),array('id'=>$_['id']));
  213. break;
  214. case 'removeFavorite':
  215. $eventManager->change(array('favorite'=>'0'),array('id'=>$_['id']));
  216. break;
  217. case 'login':
  218. if(isset($_['usr'])){
  219. $user = $userManager->existAuthToken($_['usr']);
  220. if($user==false){
  221. exit("erreur identification : le compte est inexistant");
  222. }else{
  223. $_SESSION['currentUser'] = serialize($user);
  224. header('location: ./action.php?action=addFeed&newUrl='.$_['newUrl']);
  225. }
  226. }else{
  227. $user = $userManager->exist($_['login'],$_['password']);
  228. if($user==false){
  229. exit("erreur identification : le compte est inexistant");
  230. }else{
  231. $_SESSION['currentUser'] = serialize($user);
  232. }
  233. header('location: ./index.php');
  234. }
  235. break;
  236. case 'logout':
  237. $_SESSION = array();
  238. session_unset();
  239. session_destroy();
  240. header('location: ./index.php');
  241. break;
  242. default:
  243. exit('0');
  244. break;
  245. }
  246. ?>