index.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /*
  3. @nom: index
  4. @auteur: Idleman (http://blog.idleman.fr)
  5. @description: Page d'accueil et de lecture des flux
  6. */
  7. require_once('header.php');
  8. Plugin::callHook("index_pre_treatment", array(&$_));
  9. //Récuperation de l'action (affichage) demandée
  10. $action = (isset($_['action'])?$_['action']:'');
  11. $tpl->assign('action',$action);
  12. if($isAlwaysDisplayed) {
  13. //Récuperation des dossiers de flux par ordre de nom
  14. $tpl->assign('folders',$folderManager->populate('name'));
  15. //Recuperation de tous les non Lu
  16. $tpl->assign('unread',$feedManager->countUnreadEvents());
  17. //recuperation de tous les flux
  18. $allFeeds = $feedManager->getFeedsPerFolder();
  19. $tpl->assign('allFeeds',$allFeeds);
  20. //recuperation de tous les flux par dossier
  21. $tpl->assign('allFeedsPerFolder',$allFeeds['folderMap']);
  22. //recuperation de tous les event nons lu par dossiers
  23. $tpl->assign('allEvents',$eventManager->getEventCountPerFolder());
  24. //utilisé pour récupérer le statut d'un feed dans le template (en erreur ou ok)
  25. $feedState = new Feed();
  26. $tpl->assign('feedState',$feedState);
  27. }
  28. //afficher ou non le champ OTP
  29. $tpl->assign('otpEnabled', $configurationManager->get('otpEnabled'));
  30. $articleDisplayAuthor = $configurationManager->get('articleDisplayAuthor');
  31. $articleDisplayDate = $configurationManager->get('articleDisplayDate');
  32. $articleDisplayFolderSort = $configurationManager->get('articleDisplayFolderSort');
  33. $articleDisplayHomeSort = $configurationManager->get('articleDisplayHomeSort');
  34. $articleDisplayLink = $configurationManager->get('articleDisplayLink');
  35. $articleDisplayMode = $configurationManager->get('articleDisplayMode');
  36. $articlePerPages = $configurationManager->get('articlePerPages');
  37. $displayOnlyUnreadFeedFolder = $configurationManager->get('displayOnlyUnreadFeedFolder');
  38. if (!isset($displayOnlyUnreadFeedFolder)) $displayOnlyUnreadFeedFolder=false;
  39. ($displayOnlyUnreadFeedFolder=='true')?$displayOnlyUnreadFeedFolder_reverse='false':$displayOnlyUnreadFeedFolder_reverse='true';
  40. $optionFeedIsVerbose = $configurationManager->get('optionFeedIsVerbose');
  41. $page = 0;
  42. $pages = 0;
  43. $tpl->assign('articleDisplayAuthor',$articleDisplayAuthor);
  44. $tpl->assign('articleDisplayDate',$articleDisplayDate);
  45. $tpl->assign('articleDisplayFolderSort',$articleDisplayFolderSort);
  46. $tpl->assign('articleDisplayHomeSort',$articleDisplayHomeSort);
  47. $tpl->assign('articleDisplayLink',$articleDisplayLink);
  48. $tpl->assign('articleDisplayMode',$articleDisplayMode);
  49. $tpl->assign('articlePerPages',$articlePerPages);
  50. $tpl->assign('displayOnlyUnreadFeedFolder',$displayOnlyUnreadFeedFolder);
  51. $tpl->assign('displayOnlyUnreadFeedFolder_reverse',$displayOnlyUnreadFeedFolder_reverse);
  52. $target = '`'.MYSQL_PREFIX.'event`.`title`,`'.MYSQL_PREFIX.'event`.`unread`,`'.MYSQL_PREFIX.'event`.`favorite`,`'.MYSQL_PREFIX.'event`.`feed`,';
  53. if($articleDisplayMode=='summary') $target .= '`'.MYSQL_PREFIX.'event`.`description`,';
  54. if($articleDisplayMode=='content') $target .= '`'.MYSQL_PREFIX.'event`.`content`,';
  55. if($articleDisplayLink) $target .= '`'.MYSQL_PREFIX.'event`.`link`,';
  56. if($articleDisplayDate) $target .= '`'.MYSQL_PREFIX.'event`.`pubdate`,';
  57. if($articleDisplayAuthor) $target .= '`'.MYSQL_PREFIX.'event`.`creator`,';
  58. $target .= '`'.MYSQL_PREFIX.'event`.`id`';
  59. $tpl->assign('target',$target);
  60. $tpl->assign('feeds',[]);
  61. $tpl->assign('order','');
  62. $tpl->assign('unreadEventsForFolder',0);
  63. $pagesArray = array();
  64. switch($action){
  65. /* AFFICHAGE DES EVENEMENTS D'UN FLUX EN PARTICULIER */
  66. case 'selectedFeed':
  67. $currentFeed = $feedManager->getById($_['feed']);
  68. $tpl->assign('currentFeed',$currentFeed);
  69. $numberOfItem = $eventManager->rowCount(array('feed'=>$currentFeed->getId()));
  70. $allowedOrder = array('date'=>'pubdate DESC','older'=>'pubdate','unread'=>'unread DESC,pubdate DESC');
  71. $order = (isset($_['order'])?$allowedOrder[$_['order']]:$allowedOrder['unread']);
  72. $page = (isset($_['page'])?$_['page']:1);
  73. $pages = ceil($numberOfItem/$articlePerPages);
  74. $startArticle = ($page-1)*$articlePerPages;
  75. $events = $currentFeed->getEvents($startArticle,$articlePerPages,$order,$target);
  76. $tpl->assign('order',(isset($_['order'])?$_['order']:''));
  77. break;
  78. /* AFFICHAGE DES EVENEMENTS D'UN DOSSIER EN PARTICULIER */
  79. case 'selectedFolder':
  80. $currentFolder = $folderManager->getById($_['folder']);
  81. $tpl->assign('currentFolder',$currentFolder);
  82. $numberOfItem = $currentFolder->unreadCount();
  83. $page = (isset($_['page'])?$_['page']:1);
  84. $pages = ceil($numberOfItem/$articlePerPages);
  85. $startArticle = ($page-1)*$articlePerPages;
  86. if($articleDisplayFolderSort) {$order = '`'.MYSQL_PREFIX.'event`.`pubdate` desc';} else {$order = '`'.MYSQL_PREFIX.'event`.`pubdate` asc';}
  87. $events = $currentFolder->getEvents($startArticle,$articlePerPages,$order,$target);
  88. break;
  89. /* AFFICHAGE DES EVENEMENTS FAVORIS */
  90. case 'favorites':
  91. $numberOfItem = $eventManager->rowCount(array('favorite'=>1));
  92. $page = (isset($_['page'])?$_['page']:1);
  93. $pages = ceil($numberOfItem/$articlePerPages);
  94. $startArticle = ($page-1)*$articlePerPages;
  95. $events = $eventManager->loadAllOnlyColumn($target,array('favorite'=>1),'pubdate DESC',$startArticle.','.$articlePerPages);
  96. $tpl->assign('numberOfItem',$numberOfItem);
  97. break;
  98. /* AFFICHAGE DES EVENEMENTS NON LUS (COMPORTEMENT PAR DEFAUT) */
  99. case 'unreadEvents':
  100. case 'wrongLogin':
  101. $wrongLogin = true;
  102. default:
  103. $wrongLogin = !empty($wrongLogin);
  104. $tpl->assign('wrongLogin',$wrongLogin);
  105. if(!$isAlwaysDisplayed) {
  106. break;
  107. }
  108. $filter = array('unread'=>1);
  109. if($optionFeedIsVerbose) {
  110. $numberOfItem = $eventManager->rowCount($filter);
  111. } else {
  112. $numberOfItem = $eventManager->getEventCountNotVerboseFeed();
  113. }
  114. $page = (isset($_['page'])?$_['page']:1);
  115. $pages = ($articlePerPages>0?ceil($numberOfItem/$articlePerPages):1);
  116. $startArticle = ($page-1)*$articlePerPages;
  117. if($articleDisplayHomeSort) {$order = 'pubdate desc';} else {$order = 'pubdate asc';}
  118. if($optionFeedIsVerbose) {
  119. $events = $eventManager->loadAllOnlyColumn($target,$filter,$order,$startArticle.','.$articlePerPages);
  120. } else {
  121. $events = $eventManager->getEventsNotVerboseFeed($startArticle,$articlePerPages,$order,$target);
  122. }
  123. $tpl->assign('numberOfItem',$numberOfItem);
  124. break;
  125. }
  126. $tpl->assign('pages',$pages);
  127. $tpl->assign('page',$page);
  128. $paginationScale = $configurationManager->get('paginationScale');
  129. if (empty($paginationScale)) {
  130. $configurationManager->put('paginationScale', 5);
  131. $paginationScale = $configurationManager->get('paginationScale');
  132. }
  133. for($i=($page-$paginationScale<=0?1:$page-$paginationScale);$i<($page+$paginationScale>$pages+1?$pages+1:$page+$paginationScale);$i++){
  134. $pagesArray[]=$i;
  135. }
  136. $tpl->assign('pagesArray',$pagesArray);
  137. $tpl->assign('previousPages',($page-$paginationScale<0?-1:$page-$paginationScale-1));
  138. $tpl->assign('nextPages',($page+$paginationScale>$pages+1?-1:$page+$paginationScale));
  139. Plugin::callHook("index_post_treatment", array(&$events));
  140. $tpl->assign('events',$events);
  141. $tpl->assign('time',$_SERVER['REQUEST_TIME']);
  142. $tpl->assign('hightlighted',0);
  143. $tpl->assign('scroll',false);
  144. $view = 'index';
  145. require_once('footer.php');
  146. ?>