overview.inc.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * Insipid
  4. * Personal web-bookmark-system
  5. *
  6. * Copyright 2016-2019 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. $_requestMode = false;
  29. if(isset($_GET['m']) && !empty($_GET['m'])) {
  30. $_requestMode = trim($_GET['m']);
  31. $_requestMode = Summoner::validate($_requestMode,'nospace') ? $_requestMode : "all";
  32. }
  33. $_id = false;
  34. if(isset($_GET['id']) && !empty($_GET['id'])) {
  35. $_id = trim($_GET['id']);
  36. $_id = Summoner::validate($_id,'digit') ? $_id : false;
  37. }
  38. $_curPage = 1;
  39. if(isset($_GET['page']) && !empty($_GET['page'])) {
  40. $_curPage = trim($_GET['page']);
  41. $_curPage = Summoner::validate($_curPage,'digit') ? $_curPage : 1;
  42. }
  43. $linkCollection = array();
  44. $subHeadline = false;
  45. $tagCollection = array();
  46. $categoryCollection = array();
  47. $pagination = array('pages' => 0);
  48. $displayEditButton = false;
  49. $isAwm = false;
  50. if(Summoner::simpleAuthCheck() === true) {
  51. $displayEditButton = true;
  52. }
  53. switch($_requestMode) {
  54. case 'tag':
  55. if(!empty($_id)) {
  56. $tagObj = new Tag($DB);
  57. $tagObj->initbyid($_id);
  58. $tagname = $tagObj->getData('name');
  59. $subHeadline = $tagname.' <i class="ion-md-pricetag"></i>';
  60. $linkCollection = $Management->linksByTag($_id,false,RESULTS_PER_PAGE, (RESULTS_PER_PAGE * ($_curPage-1)));
  61. }
  62. else {
  63. # show all the tags we have
  64. $tagCollection = $Management->tags(false, true);
  65. $subHeadline = 'All the tags <i class="ion-md-pricetags"></i>';
  66. }
  67. break;
  68. case 'category':
  69. if(!empty($_id)) {
  70. $catObj = new Category($DB);
  71. $catObj->initbyid($_id);
  72. $catname = $catObj->getData('name');
  73. $subHeadline = $catname.' <i class="ion-md-filing"></i>';
  74. $linkCollection = $Management->linksByCategory($_id,false,RESULTS_PER_PAGE, (RESULTS_PER_PAGE * ($_curPage-1)));
  75. }
  76. else {
  77. # show all the categories we have
  78. $categoryCollection = $Management->categories(false, true);
  79. $subHeadline = 'All the categories <i class="ion-md-filing"></i>';
  80. }
  81. break;
  82. case 'awm':
  83. Summoner::simpleAuth();
  84. $isAwm = true;
  85. $subHeadline = 'Awaiting moderation';
  86. $Management->setShowAwm(true);
  87. $linkCollection = $Management->links(RESULTS_PER_PAGE, (RESULTS_PER_PAGE * ($_curPage-1)));
  88. break;
  89. case 'all':
  90. default:
  91. # show all
  92. $linkCollection = $Management->links(RESULTS_PER_PAGE, (RESULTS_PER_PAGE * ($_curPage-1)));
  93. }
  94. if(!empty($linkCollection['amount'])) {
  95. $pagination['pages'] = ceil($linkCollection['amount'] / RESULTS_PER_PAGE);
  96. $pagination['curPage'] = $_curPage;
  97. $pagination['linkadd'] = '&m='.$_requestMode;
  98. if(!empty($_id)) {
  99. $pagination['linkadd'] .= '&id='.$_id;
  100. }
  101. }
  102. if($pagination['pages'] > 11) {
  103. # first pages
  104. $pagination['visibleRange'] = range(1,3);
  105. # last pages
  106. foreach(range($pagination['pages']-2, $pagination['pages']) as $e) {
  107. array_push($pagination['visibleRange'], $e);
  108. }
  109. # pages before and after current page
  110. $cRange = range($pagination['curPage']-1, $pagination['curPage']+1);
  111. foreach($cRange as $e) {
  112. array_push($pagination['visibleRange'], $e);
  113. }
  114. $pagination['currentRangeStart'] = array_shift($cRange);
  115. $pagination['currentRangeEnd'] = array_pop($cRange);
  116. }
  117. else {
  118. $pagination['visibleRange'] = range(1,$pagination['pages']);
  119. }