overview.inc.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. /**
  3. * Insipid
  4. * Personal web-bookmark-system
  5. *
  6. * Copyright 2016-2021 Johannes Keßler
  7. *
  8. * Development starting from 2011: Johannes Keßler
  9. * https://www.bananas-playground.net/projekt/insipid/
  10. *
  11. * creator:
  12. * Luke Reeves <luke@neuro-tech.net>
  13. *
  14. * This program is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation, either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program. If not, see http://www.gnu.org/licenses/gpl-3.0.
  26. *
  27. */
  28. $currentGetParameters['p'] = 'overview';
  29. $_requestMode = false;
  30. if(isset($_GET['m']) && !empty($_GET['m'])) {
  31. $_requestMode = trim($_GET['m']);
  32. $_requestMode = Summoner::validate($_requestMode,'nospace') ? $_requestMode : false;
  33. }
  34. $_id = false;
  35. if(isset($_GET['id']) && !empty($_GET['id'])) {
  36. $_id = trim($_GET['id']);
  37. $_id = Summoner::validate($_id,'digit') ? $_id : false;
  38. }
  39. $_curPage = 1;
  40. if(isset($_GET['page']) && !empty($_GET['page'])) {
  41. $_curPage = trim($_GET['page']);
  42. $_curPage = Summoner::validate($_curPage,'digit') ? $_curPage : 1;
  43. }
  44. $_sort = false;
  45. if(isset($_GET['s']) && !empty($_GET['s'])) {
  46. $_sort = trim($_GET['s']);
  47. $_sort = Summoner::validate($_sort,'nospace') ? $_sort : false;
  48. }
  49. $_sortDirection = false;
  50. if(isset($_GET['sd']) && !empty($_GET['sd'])) {
  51. $_sortDirection = trim($_GET['sd']);
  52. $_sortDirection = Summoner::validate($_sortDirection,'nospace') ? $_sortDirection : false;
  53. }
  54. $linkCollection = array();
  55. $subHeadline = false;
  56. $tagCollection = array();
  57. $categoryCollection = array();
  58. $pagination = array('pages' => 0);
  59. $displayEditButton = false;
  60. $isAwm = false;
  61. $sortLink = array();
  62. if(Summoner::simpleAuthCheck() === true) {
  63. $displayEditButton = true;
  64. }
  65. $sortLink['active'] = 'default';
  66. $sortLink['activeDirection'] = false;
  67. $_LinkColllectionQueryOptions = array(
  68. 'limit' => RESULTS_PER_PAGE,
  69. 'offset' =>(RESULTS_PER_PAGE * ($_curPage-1))
  70. );
  71. if(!empty($_sort) && $_sort === 'title') {
  72. $currentGetParameters['s'] = 'title';
  73. $sortLink['active'] = 'title';
  74. $_LinkColllectionQueryOptions['sort'] = 'title';
  75. }
  76. if(!empty($_sortDirection) && $_sortDirection === 'asc') {
  77. $currentGetParameters['sd'] = 'asc';
  78. $sortLink['activeDirection'] = true;
  79. $_LinkColllectionQueryOptions['sortDirection'] = 'asc';
  80. }
  81. switch($_requestMode) {
  82. case 'tag':
  83. $currentGetParameters['m'] = 'tag';
  84. if(!empty($_id)) {
  85. $tagObj = new Tag($DB);
  86. $tagObj->initbyid($_id);
  87. $tagname = $tagObj->getData('name');
  88. $subHeadline = $tagname.' <i class="ion-md-pricetag"></i>';
  89. $linkCollection = $Management->linksByTag($_id, $_LinkColllectionQueryOptions);
  90. $currentGetParameters['id'] = $_id;
  91. }
  92. else {
  93. # show all the tags we have
  94. $tagCollection = $Management->tags(false, true);
  95. $subHeadline = $T->t('view.tags').' <i class="ion-md-pricetags"></i>';
  96. }
  97. break;
  98. case 'category':
  99. $currentGetParameters['m'] = 'category';
  100. if(!empty($_id)) {
  101. $catObj = new Category($DB);
  102. $catObj->initbyid($_id);
  103. $catname = $catObj->getData('name');
  104. $subHeadline = $catname.' <i class="ion-md-filing"></i>';
  105. $linkCollection = $Management->linksByCategory($_id, $_LinkColllectionQueryOptions);
  106. $currentGetParameters['id'] = $_id;
  107. }
  108. else {
  109. # show all the categories we have
  110. $categoryCollection = $Management->categories(false, true);
  111. $subHeadline = $T->t('view.categories').' <i class="ion-md-filing"></i>';
  112. }
  113. break;
  114. case 'awm':
  115. $currentGetParameters['m'] = 'awm';
  116. Summoner::simpleAuth();
  117. $isAwm = true;
  118. $subHeadline = 'Awaiting moderation';
  119. $Management->setShowAwm(true);
  120. $linkCollection = $Management->links(RESULTS_PER_PAGE, (RESULTS_PER_PAGE * ($_curPage-1)));
  121. break;
  122. case 'all':
  123. default:
  124. # show all
  125. $linkCollection = $Management->links(RESULTS_PER_PAGE, (RESULTS_PER_PAGE * ($_curPage-1)));
  126. }
  127. if(!empty($linkCollection['amount'])) {
  128. $pagination['pages'] = ceil($linkCollection['amount'] / RESULTS_PER_PAGE);
  129. $pagination['curPage'] = $_curPage;
  130. $currentGetParameters['page'] = $_curPage;
  131. }
  132. if($pagination['pages'] > 11) {
  133. # first pages
  134. $pagination['visibleRange'] = range(1,3);
  135. # last pages
  136. foreach(range($pagination['pages']-2, $pagination['pages']) as $e) {
  137. array_push($pagination['visibleRange'], $e);
  138. }
  139. # pages before and after current page
  140. $cRange = range($pagination['curPage']-1, $pagination['curPage']+1);
  141. foreach($cRange as $e) {
  142. array_push($pagination['visibleRange'], $e);
  143. }
  144. $pagination['currentRangeStart'] = array_shift($cRange);
  145. $pagination['currentRangeEnd'] = array_pop($cRange);
  146. }
  147. else {
  148. $pagination['visibleRange'] = range(1,$pagination['pages']);
  149. }
  150. $sortLink['default'] = Summoner::createFromParameterLinkQuery($currentGetParameters,array('s'=>false,'sd'=>false));
  151. $sortLink['name'] = Summoner::createFromParameterLinkQuery($currentGetParameters,array('s'=>'title','sd'=>false));
  152. $sortLink['direction'] = Summoner::createFromParameterLinkQuery($currentGetParameters,array('sd'=>'asc'));