action.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <?php
  2. /*
  3. @nom: action
  4. @auteur: Idleman (idleman@idleman.fr)
  5. @description: Page de gestion des évenements non liés a une vue particulière (appels ajax, requetes sans resultats etc...)
  6. */
  7. if(!ini_get('safe_mode')) @set_time_limit(0);
  8. require_once("common.php");
  9. //Execution du code en fonction de l'action
  10. switch ($_['action']){
  11. case 'synchronize':
  12. if (ob_get_level() == 0) ob_start();
  13. require_once("SimplePie.class.php");
  14. echo '<link rel="stylesheet" href="templates/marigolds/css/style.css"><ul style="font-family:Verdana;">';
  15. echo str_pad('',4096)."\n";ob_flush();flush();
  16. if (isset($_['code']) && $configurationManager->get('synchronisationCode')!=null && $_['code'] == $configurationManager->get('synchronisationCode')){
  17. $synchronisationType = $configurationManager->get('synchronisationType');
  18. $maxEvents = $configurationManager->get('feedMaxEvents');
  19. echo '<h3>Synchronisation du '.date('d/m/Y H:i:s').'</h3>';
  20. echo '<hr/>';
  21. echo str_pad('',4096)."\n";ob_flush();flush();
  22. if($synchronisationType=='graduate'){
  23. $feeds = $feedManager->loadAll(null,'lastupdate','10');
  24. echo 'Type gradué...<br/>';
  25. echo str_pad('',4096)."\n";ob_flush();flush();
  26. }else{
  27. $feeds = $feedManager->populate('name');
  28. echo 'Type complet...<br/>';
  29. echo str_pad('',4096)."\n";ob_flush();flush();
  30. }
  31. echo count($feeds).' Flux à synchroniser...<br/>';
  32. echo str_pad('',4096)."\n";ob_flush();flush();
  33. foreach ($feeds as $feed) {
  34. echo date('H:i:s').' - Flux '.$feed->getName().' ('.$feed->getUrl().') parsage des flux...<br/>';
  35. echo str_pad('',4096)."\n";ob_flush();flush();
  36. $feed->parse();
  37. echo str_pad('',4096)."\n";ob_flush();flush();
  38. echo date('H:i:s').' - Flux '.$feed->getName().' ('.$feed->getUrl().') supression des vieux evenements...<br/>';
  39. echo str_pad('',4096)."\n";ob_flush();flush();
  40. if($maxEvents!=0) $feed->removeOldEvents($maxEvents);
  41. echo date('H:i:s').' - Flux '.$feed->getName().' ('.$feed->getUrl().') terminé<br/>';
  42. echo str_pad('',4096)."\n";ob_flush();flush();
  43. }
  44. echo date('H:i:s').' - Synchronisation terminée ( '.number_format(microtime(true)-$start,3).' secondes )<br/>';
  45. echo str_pad('',4096)."\n";ob_flush();flush();
  46. }else{
  47. echo 'Code de synchronisation incorrect ou non spécifié';
  48. }
  49. ob_end_flush();
  50. break;
  51. case 'readAll':
  52. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  53. $whereClause = array();
  54. $whereClause['unread'] = '1';
  55. if(isset($_['feed']))$whereClause['feed'] = $_['feed'];
  56. $eventManager->change(array('unread'=>'0'),$whereClause);
  57. header('location: ./index.php');
  58. break;
  59. case 'readFolder':
  60. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  61. $feeds = $feedManager->loadAllOnlyColumn('id',array('folder'=>$_['folder']));
  62. foreach($feeds as $feed){
  63. $eventManager->change(array('unread'=>'0'),array('feed'=>$feed->getId()));
  64. }
  65. header('location: ./index.php');
  66. break;
  67. case 'updateConfiguration':
  68. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  69. //Ajout des préférences et réglages
  70. $configurationManager->put('root',(substr($_['root'], strlen($_['root'])-1)=='/'?$_['root']:$_['root'].'/'));
  71. //$configurationManager->put('view',$_['view']);
  72. $configurationManager->put('articleView',$_['articleView']);
  73. $configurationManager->put('articleDisplayContent',$_['articleDisplayContent']);
  74. $configurationManager->put('articleDisplayAnonymous',$_['articleDisplayAnonymous']);
  75. $configurationManager->put('articlePerPages',$_['articlePerPages']);
  76. $configurationManager->put('articleDisplayLink',$_['articleDisplayLink']);
  77. $configurationManager->put('articleDisplayDate',$_['articleDisplayDate']);
  78. $configurationManager->put('articleDisplayAuthor',$_['articleDisplayAuthor']);
  79. $configurationManager->put('plugin_shaarli',(isset($_['plugin_shaarli']) && $_['plugin_shaarli']=='on'?1:0));
  80. $configurationManager->put('plugin_shaarli_link',$_['plugin_shaarli_link']);
  81. $configurationManager->put('synchronisationType',$_['synchronisationType']);
  82. $configurationManager->put('feedMaxEvents',$_['feedMaxEvents']);
  83. $userManager->change(array('login'=>$_['login']),array('id'=>$myUser->getId()));
  84. if(trim($_['password'])!='') $userManager->change(array('password'=>User::encrypt($_['password'])),array('id'=>$myUser->getId()));
  85. header('location: ./settings.php');
  86. break;
  87. case 'purge':
  88. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  89. $eventManager->truncate();
  90. header('location: ./settings.php');
  91. break;
  92. case 'exportFeed':
  93. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  94. /*********************/
  95. /** Export **/
  96. /*********************/
  97. if(isset($_POST['exportButton'])){
  98. $opml = new Opml();
  99. $xmlStream = $opml->export();
  100. header('Content-Description: File Transfer');
  101. header('Content-Type: application/octet-stream');
  102. header('Content-Disposition: attachment; filename=leed-'.date('d-m-Y').'.opml');
  103. header('Content-Transfer-Encoding: binary');
  104. header('Expires: 0');
  105. header('Cache-Control: must-revalidate');
  106. header('Pragma: public');
  107. header('Content-Length: ' . strlen($xmlStream));
  108. /*
  109. //A decommenter dans le cas ou on a des pb avec ie
  110. if(preg_match('/msie|(microsoft internet explorer)/i', $_SERVER['HTTP_USER_AGENT'])){
  111. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  112. header('Pragma: public');
  113. }else{
  114. header('Pragma: no-cache');
  115. }
  116. */
  117. ob_clean();
  118. flush();
  119. echo $xmlStream;
  120. }
  121. break;
  122. case 'importForm':
  123. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  124. echo '<link rel="stylesheet" href="templates/marigolds/css/style.css"><form action="action.php?action=importFeed" method="POST" enctype="multipart/form-data"><h2>Importer les flux au format opml</h2>
  125. <p>Fichier OPML : <input name="newImport" type="file"/> <button name="importButton">Importer</button></p>
  126. <p>Nb : L\'importation peux prendre un certain temps, laissez votre navigateur tourner et allez vous prendre un café :).</p></form>
  127. ';
  128. break;
  129. case 'synchronizeForm':
  130. if(isset($myUser) && $myUser!=false){
  131. echo '<link rel="stylesheet" href="templates/marigolds/css/style.css">
  132. <a class="button" href="action.php?action=synchronize&format=html&code='.$configurationManager->get('synchronisationCode').'">Synchroniser maintenant</a>
  133. <p>Nb : La synchronisation peux prendre un certain temps, laissez votre navigateur tourner et allez vous prendre un café :).</p>
  134. ';
  135. }else{
  136. echo 'Vous devez être connecté pour accéder à cette partie.';
  137. }
  138. break;
  139. case 'changeFolderState':
  140. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  141. $folderManager->change(array('isopen'=>$_['isopen']),array('id'=>$_['id']));
  142. break;
  143. case 'importFeed':
  144. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  145. if(!isset($_POST['importButton'])) break;
  146. $opml = new Opml();
  147. echo "<h3>Importation</h3><p>En cours...</p>\n";
  148. $errorOutput = $opml->import($_FILES['newImport']['tmp_name']);
  149. if (empty($errorOutput)) {
  150. echo "<p style='color:blue'>L'import s'est déroulé sans problème.</p>\n";
  151. } else {
  152. echo "<p style='color:red'>Erreurs à l'importation!</p>\n";
  153. foreach($errorOutput as $line) {
  154. echo "<p>$line</p>\n";
  155. }
  156. }
  157. if (!empty($opml->alreadyKnowns)) {
  158. echo "<h3>Certains flux étaient déjà connus, ils n'ont pas été "
  159. ."réimportés&nbsp;:</h3>\n<ul>\n";
  160. foreach($opml->alreadyKnowns as $alreadyKnown) {
  161. foreach($alreadyKnown as &$elt) $elt = htmlspecialchars($elt);
  162. $maxLength = 80;
  163. $delimiter = '...';
  164. if (strlen($alreadyKnown->description)>$maxLength) {
  165. $alreadyKnown->description =
  166. substr($alreadyKnown->description, 0,
  167. $maxLength-strlen($delimiter)
  168. ).$delimiter;
  169. }
  170. echo "<li><a target='_parent' href='{$alreadyKnown->xmlUrl}'>"
  171. ."{$alreadyKnown->description}</a></li>\n";
  172. }
  173. echo "</ul>\n";
  174. }
  175. $syncCode = $configurationManager->get('synchronisationCode');
  176. assert('!empty($syncCode)');
  177. $syncLink = "action.php?action=synchronize&format=html&code=$syncCode";
  178. echo "<p>";
  179. echo "<a href='$syncLink' style='text-decoration:none;font-size:3em'>"
  180. ."↺</a>";
  181. echo "<a href='$syncLink'>Cliquez ici pour synchroniser vos flux importés.</a>";
  182. echo "<p>\n";
  183. break;
  184. case 'addFeed':
  185. require_once("SimplePie.class.php");
  186. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  187. if(isset($_['newUrl'])){
  188. $newFeed = new Feed();
  189. $newFeed->setUrl($_['newUrl']);
  190. $newFeed->getInfos();
  191. $newFeed->setFolder((isset($_['newUrlCategory'])?$_['newUrlCategory']:1));
  192. $newFeed->save();
  193. $newFeed->parse();
  194. header('location: ./settings.php#defaultFolder');
  195. }
  196. break;
  197. case 'changeFeedFolder':
  198. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  199. if(isset($_['feed'])){
  200. $feedManager->change(array('folder'=>$_['folder']),array('id'=>$_['feed']));
  201. }
  202. header('location: ./settings.php');
  203. break;
  204. case 'removeFeed':
  205. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  206. if(isset($_GET['id'])){
  207. $feedManager->delete(array('id'=>$_['id']));
  208. $eventManager->delete(array('feed'=>$_['id']));
  209. }
  210. header('location: ./settings.php');
  211. break;
  212. case 'addFolder':
  213. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  214. if(isset($_['newFolder'])){
  215. $folder = new Folder();
  216. if($folder->rowCount(array('name'=>$_['newFolder']))==0){
  217. $folder->setParent(-1);
  218. $folder->setIsopen(0);
  219. $folder->setName($_['newFolder']);
  220. $folder->save();
  221. }
  222. }
  223. header('location: ./settings.php');
  224. break;
  225. case 'renameFolder':
  226. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  227. if(isset($_['id'])){
  228. $folderManager->change(array('name'=>$_['name']),array('id'=>$_['id']));
  229. }
  230. break;
  231. case 'renameFeed':
  232. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  233. if(isset($_['id'])){
  234. $feedManager->change(array('name'=>$_['name']),array('id'=>$_['id']));
  235. }
  236. break;
  237. case 'removeFolder':
  238. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  239. if(isset($_['id']) && is_numeric($_['id']) && $_['id']>0){
  240. $eventManager->customExecute('DELETE FROM '.MYSQL_PREFIX.'event WHERE '.MYSQL_PREFIX.'event.feed in (SELECT '.MYSQL_PREFIX.'feed.id FROM '.MYSQL_PREFIX.'feed WHERE '.MYSQL_PREFIX.'feed.folder =\''.intval($_['id']).'\') ;');
  241. $feedManager->delete(array('folder'=>$_['id']));
  242. $folderManager->delete(array('id'=>$_['id']));
  243. }
  244. header('location: ./settings.php');
  245. break;
  246. case 'readContent':
  247. $event = $eventManager->load(array('id'=>$_['id']));
  248. if($myUser!=false) $eventManager->change(array('unread'=>'0'),array('id'=>$_['id']));
  249. break;
  250. case 'unreadContent':
  251. $event = $eventManager->load(array('id'=>$_['id']));
  252. if($myUser!=false) $eventManager->change(array('unread'=>'1'),array('id'=>$_['id']));
  253. break;
  254. case 'addFavorite':
  255. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  256. $eventManager->change(array('favorite'=>'1'),array('id'=>$_['id']));
  257. break;
  258. case 'removeFavorite':
  259. if($myUser==false) exit('Vous devez vous connecter pour cette action.');
  260. $eventManager->change(array('favorite'=>'0'),array('id'=>$_['id']));
  261. break;
  262. case 'login':
  263. if(isset($_['usr'])){
  264. $user = $userManager->existAuthToken($_['usr']);
  265. if($user==false){
  266. exit("erreur identification : le compte est inexistant");
  267. }else{
  268. $_SESSION['currentUser'] = serialize($user);
  269. header('location: ./action.php?action=addFeed&newUrl='.$_['newUrl']);
  270. }
  271. }else{
  272. $user = $userManager->exist($_['login'],$_['password']);
  273. if($user==false){
  274. exit("erreur identification : le compte est inexistant");
  275. }else{
  276. $_SESSION['currentUser'] = serialize($user);
  277. }
  278. header('location: ./index.php');
  279. }
  280. break;
  281. case 'logout':
  282. $_SESSION = array();
  283. session_unset();
  284. session_destroy();
  285. header('location: ./index.php');
  286. break;
  287. default:
  288. exit('0');
  289. break;
  290. }
  291. ?>