/www/watchlist.php

https://github.com/omigeot-ccpo/SemanticScuttle-SSO · PHP · 128 lines · 79 code · 18 blank · 31 comment · 20 complexity · eba97dc4eabc0bac0d599b3c04f27f6c MD5 · raw file

  1. <?php
  2. /***************************************************************************
  3. Copyright (C) 2004 - 2006 Scuttle project
  4. http://sourceforge.net/projects/scuttle/
  5. http://scuttle.org/
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. ***************************************************************************/
  18. require_once 'www-header.php';
  19. /* Service creation: only useful services are created */
  20. $bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark');
  21. $cacheservice =SemanticScuttle_Service_Factory::get('Cache');
  22. /* Managing all possible inputs */
  23. isset($_GET['page']) ? define('GET_PAGE', $_GET['page']): define('GET_PAGE', 0);
  24. isset($_GET['sort']) ? define('GET_SORT', $_GET['sort']): define('GET_SORT', '');
  25. /* Managing current logged user */
  26. $currentUser = $userservice->getCurrentObjectUser();
  27. /* Managing path info */
  28. @list($url, $user, $page) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : NULL;
  29. if ($usecache) {
  30. // Generate hash for caching on
  31. if ($userservice->isLoggedOn()) {
  32. if ($currentUser->getUsername() != $user) {
  33. $cachehash = md5($_SERVER['REQUEST_URI'] . $currentUser->getUsername());
  34. // Cache for 5 minutes
  35. $cacheservice->Start($cachehash);
  36. }
  37. } else {
  38. // Cache for 30 minutes
  39. $cachehash = md5($_SERVER['REQUEST_URI']);
  40. $cacheservice->Start($cachehash, 1800);
  41. }
  42. }
  43. if ($user) {
  44. if (is_int($user)) {
  45. $userid = intval($user);
  46. } else {
  47. $userinfo = $userservice->getObjectUserByUsername($user);
  48. if ($userinfo == NULL ) {
  49. // Throw a 404 error
  50. $tplVars['error'] = sprintf(T_('User with username %s was not found'), $user);
  51. $templateservice->loadTemplate('error.404.tpl', $tplVars);
  52. exit();
  53. } else {
  54. $userid =& $userinfo->getId();
  55. }
  56. }
  57. }
  58. // Header variables
  59. $tplVars['loadjs'] = true;
  60. if ($user) {
  61. $tplVars['user'] = $user;
  62. $tplVars['userid'] = $userid;
  63. $tplVars['userinfo'] =& $userinfo;
  64. // Pagination
  65. $perpage = getPerPageCount($currentUser);
  66. if (intval(GET_PAGE) > 1) {
  67. $page = intval(GET_PAGE);
  68. $start = ($page - 1) * $perpage;
  69. } else {
  70. $page = 0;
  71. $start = 0;
  72. }
  73. // Set template vars
  74. $tplVars['currenttag'] = '';
  75. $tplVars['page'] = $page;
  76. $tplVars['start'] = $start;
  77. $tplVars['bookmarkCount'] = $start + 1;
  78. $bookmarks =& $bookmarkservice->getBookmarks($start, $perpage, $userid, NULL, NULL, getSortOrder(), true);
  79. $tplVars['sidebar_blocks'] = array('watchlist');
  80. $tplVars['watched'] = true;
  81. $tplVars['total'] = $bookmarks['total'];
  82. $tplVars['bookmarks'] =& $bookmarks['bookmarks'];
  83. $tplVars['cat_url'] = createURL('tags', '%2$s');
  84. $tplVars['nav_url'] = createURL('watchlist', '%s/%s%s');
  85. if ($userservice->isLoggedOn() && $user == $currentUser->getUsername()) {
  86. $title = T_('My Watchlist');
  87. } else {
  88. $title = T_('Watchlist') .': '. $user;
  89. }
  90. $tplVars['pagetitle'] = $title;
  91. $tplVars['subtitle'] = $title;
  92. $tplVars['range'] = 'watchlist';
  93. $tplVars['pageName'] = PAGE_WATCHLIST;
  94. $tplVars['rsschannels'] = array(
  95. array(filter($sitename .': '. $title), createURL('rss', 'watchlist/'. filter($user, 'url')))
  96. );
  97. $templateservice->loadTemplate('bookmarks.tpl', $tplVars);
  98. } else {
  99. $tplVars['error'] = T_('Username was not specified');
  100. $templateservice->loadTemplate('error.404.tpl', $tplVars);
  101. exit();
  102. }
  103. if ($usecache) {
  104. // Cache output if existing copy has expired
  105. $cacheservice->End($hash);
  106. }
  107. ?>