overview.inc.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 = '';
  30. if(isset($_GET['m']) && !empty($_GET['m'])) {
  31. $_requestMode = trim($_GET['m']);
  32. $_requestMode = Summoner::validate($_requestMode,'nospace') ? $_requestMode : '';
  33. }
  34. $_id = '';
  35. if(isset($_GET['id']) && !empty($_GET['id'])) {
  36. $_id = trim($_GET['id']);
  37. $_id = Summoner::validate($_id,'digit') ? $_id : '';
  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 = '';
  45. if(isset($_GET['s']) && !empty($_GET['s'])) {
  46. $_sort = trim($_GET['s']);
  47. $_sort = Summoner::validate($_sort,'nospace') ? $_sort : '';
  48. }
  49. $_sortDirection = '';
  50. if(isset($_GET['sd']) && !empty($_GET['sd'])) {
  51. $_sortDirection = trim($_GET['sd']);
  52. $_sortDirection = Summoner::validate($_sortDirection,'nospace') ? $_sortDirection : '';
  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. $colInfo = array();
  63. if(Summoner::simpleAuthCheck() === true) {
  64. $displayEditButton = true;
  65. }
  66. $sortLink['active'] = 'default';
  67. $sortLink['activeDirection'] = false;
  68. $_LinkColllectionQueryOptions = array(
  69. 'limit' => RESULTS_PER_PAGE,
  70. 'offset' =>(RESULTS_PER_PAGE * ($_curPage-1))
  71. );
  72. if(!empty($_sort) && $_sort === 'title') {
  73. $currentGetParameters['s'] = 'title';
  74. $sortLink['active'] = 'title';
  75. $_LinkColllectionQueryOptions['sort'] = 'title';
  76. }
  77. if(!empty($_sortDirection) && $_sortDirection === 'asc') {
  78. $currentGetParameters['sd'] = 'asc';
  79. $sortLink['activeDirection'] = true;
  80. $_LinkColllectionQueryOptions['sortDirection'] = 'asc';
  81. }
  82. switch($_requestMode) {
  83. case 'tag':
  84. $currentGetParameters['m'] = 'tag';
  85. if(!empty($_id)) {
  86. $tagObj = new Tag($DB);
  87. $tagObj->initbyid($_id);
  88. $tagname = $tagObj->getData('name');
  89. $subHeadline = $tagname.' <i class="ion-md-pricetag"></i>';
  90. $linkCollection = $Management->linksByTag($_id, $_LinkColllectionQueryOptions);
  91. $currentGetParameters['id'] = $_id;
  92. }
  93. else {
  94. # show all the tags we have
  95. $tagCollection = $Management->tags(0, true);
  96. $subHeadline = $T->t('view.tags').' <i class="ion-md-pricetags"></i>';
  97. $colInfo = $Management->linkRelationStats();
  98. }
  99. break;
  100. case 'category':
  101. $currentGetParameters['m'] = 'category';
  102. if(!empty($_id)) {
  103. $catObj = new Category($DB);
  104. $catObj->initbyid($_id);
  105. $catname = $catObj->getData('name');
  106. $subHeadline = $catname.' <i class="ion-md-filing"></i>';
  107. $linkCollection = $Management->linksByCategory($_id, $_LinkColllectionQueryOptions);
  108. $currentGetParameters['id'] = $_id;
  109. }
  110. else {
  111. # show all the categories we have
  112. $categoryCollection = $Management->categories(0, true);
  113. $subHeadline = $T->t('view.categories').' <i class="ion-md-filing"></i>';
  114. $colInfo = $Management->linkRelationStats('category');
  115. }
  116. break;
  117. case 'awm':
  118. $currentGetParameters['m'] = 'awm';
  119. Summoner::simpleAuth();
  120. $isAwm = true;
  121. $subHeadline = 'Awaiting moderation';
  122. $Management->setShowAwm(true);
  123. $linkCollection = $Management->links($_LinkColllectionQueryOptions);
  124. break;
  125. case 'all':
  126. default:
  127. # show all
  128. $linkCollection = $Management->links($_LinkColllectionQueryOptions);
  129. }
  130. if(!empty($linkCollection['amount'])) {
  131. $pagination['pages'] = ceil($linkCollection['amount'] / RESULTS_PER_PAGE);
  132. $pagination['curPage'] = $_curPage;
  133. $currentGetParameters['page'] = $_curPage;
  134. }
  135. if($pagination['pages'] > 11) {
  136. # first pages
  137. $pagination['visibleRange'] = range(1,3);
  138. # last pages
  139. foreach(range($pagination['pages']-2, $pagination['pages']) as $e) {
  140. array_push($pagination['visibleRange'], $e);
  141. }
  142. # pages before and after current page
  143. $cRange = range($pagination['curPage']-1, $pagination['curPage']+1);
  144. foreach($cRange as $e) {
  145. array_push($pagination['visibleRange'], $e);
  146. }
  147. $pagination['currentRangeStart'] = array_shift($cRange);
  148. $pagination['currentRangeEnd'] = array_pop($cRange);
  149. }
  150. else {
  151. $pagination['visibleRange'] = range(1,$pagination['pages']);
  152. }
  153. $sortLink['default'] = Summoner::createFromParameterLinkQuery($currentGetParameters,array('s'=>false,'sd'=>false));
  154. $sortLink['name'] = Summoner::createFromParameterLinkQuery($currentGetParameters,array('s'=>'title','sd'=>false));
  155. $sortLink['direction'] = Summoner::createFromParameterLinkQuery($currentGetParameters,array('sd'=>'asc'));