PageRenderTime 26ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/qa-include/qa-page-favorites.php

http://github.com/q2a/question2answer
PHP | 156 lines | 80 code | 42 blank | 34 comment | 7 complexity | 014a65fc5a2f42d25932feb7bafed0af MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /*
  3. Question2Answer (c) Gideon Greenspan
  4. http://www.question2answer.org/
  5. File: qa-include/qa-page-favorites.php
  6. Version: See define()s at top of qa-include/qa-base.php
  7. Description: Controller for page listing user's favorites
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License
  10. as published by the Free Software Foundation; either version 2
  11. of the License, or (at your option) any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. More about this license: http://www.question2answer.org/license.php
  17. */
  18. if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
  19. header('Location: ../');
  20. exit;
  21. }
  22. require_once QA_INCLUDE_DIR.'qa-db-selects.php';
  23. require_once QA_INCLUDE_DIR.'qa-app-format.php';
  24. // Check that we're logged in
  25. $userid=qa_get_logged_in_userid();
  26. if (!isset($userid))
  27. qa_redirect('login');
  28. // Get lists of favorites for this user
  29. @list($questions, $users, $tags, $categories)=qa_db_select_with_pending(
  30. qa_db_user_favorite_qs_selectspec($userid),
  31. QA_FINAL_EXTERNAL_USERS ? null : qa_db_user_favorite_users_selectspec($userid),
  32. qa_db_user_favorite_tags_selectspec($userid),
  33. qa_db_user_favorite_categories_selectspec($userid)
  34. );
  35. $usershtml=qa_userids_handles_html(QA_FINAL_EXTERNAL_USERS ? $questions : array_merge($questions, $users));
  36. // Prepare and return content for theme
  37. $qa_content=qa_content_prepare(true);
  38. $qa_content['title']=qa_lang_html('misc/my_favorites_title');
  39. // Favorite questions
  40. $qa_content['q_list']=array(
  41. 'title' => count($questions) ? qa_lang_html('main/nav_qs') : qa_lang_html('misc/no_favorite_qs'),
  42. 'qs' => array(),
  43. );
  44. if (count($questions)) {
  45. $qa_content['q_list']['form']=array(
  46. 'tags' => 'METHOD="POST" ACTION="'.qa_self_html().'"',
  47. );
  48. $options=qa_post_html_defaults('Q');
  49. foreach ($questions as $question)
  50. $qa_content['q_list']['qs'][]=qa_post_html_fields($question, $userid, qa_cookie_get(), $usershtml, null, $options);
  51. }
  52. // Favorite users
  53. if (!QA_FINAL_EXTERNAL_USERS) {
  54. $qa_content['ranking_users']=array(
  55. 'title' => count($users) ? qa_lang_html('main/nav_users') : qa_lang_html('misc/no_favorite_users'),
  56. 'items' => array(),
  57. 'rows' => ceil(count($users)/qa_opt('columns_users')),
  58. 'type' => 'users'
  59. );
  60. foreach ($users as $user)
  61. $qa_content['ranking_users']['items'][]=array(
  62. 'label' => qa_get_user_avatar_html($user['flags'], $user['email'], $user['handle'],
  63. $user['avatarblobid'], $user['avatarwidth'], $user['avatarheight'], qa_opt('avatar_users_size'), true).' '.$usershtml[$user['userid']],
  64. 'score' => qa_html(number_format($user['points'])),
  65. );
  66. }
  67. // Favorite tags
  68. if (qa_using_tags()) {
  69. $qa_content['ranking_tags']=array(
  70. 'title' => count($tags) ? qa_lang_html('main/nav_tags') : qa_lang_html('misc/no_favorite_tags'),
  71. 'items' => array(),
  72. 'rows' => ceil(count($tags)/qa_opt('columns_tags')),
  73. 'type' => 'tags'
  74. );
  75. foreach ($tags as $tag)
  76. $qa_content['ranking_tags']['items'][]=array(
  77. 'label' => qa_tag_html($tag['word']),
  78. 'count' => number_format($tag['tagcount']),
  79. );
  80. }
  81. // Favorite categories
  82. if (qa_using_categories()) {
  83. $qa_content['nav_list_categories']=array(
  84. 'title' => count($categories) ? qa_lang_html('main/nav_categories') : qa_lang_html('misc/no_favorite_categories'),
  85. 'nav' => array(),
  86. 'type' => 'nav-cat',
  87. );
  88. foreach ($categories as $category)
  89. $qa_content['nav_list_categories']['nav'][$category['categoryid']]=array(
  90. 'label' => qa_html($category['title']),
  91. 'state' => 'open',
  92. 'note' => ' - <A HREF="'.qa_path_html('questions/'.implode('/', array_reverse(explode('/', $category['backpath'])))).'">'.
  93. ( ($category['qcount']==1)
  94. ? qa_lang_html_sub('main/1_question', '1', '1')
  95. : qa_lang_html_sub('main/x_questions', number_format($category['qcount']))
  96. ).'</A>'.
  97. (strlen($category['content']) ? qa_html(' - '.$category['content']) : ''),
  98. );
  99. }
  100. // Sub navigation for account pages and suggestion
  101. $qa_content['suggest_next']=qa_lang_html_sub('misc/suggest_favorites_add', '<SPAN CLASS="qa-favorite-image">&nbsp;</SPAN>');
  102. if (!QA_FINAL_EXTERNAL_USERS)
  103. $qa_content['navigation']['sub']=qa_account_sub_navigation();
  104. return $qa_content;
  105. /*
  106. Omit PHP closing tag to help avoid accidental output
  107. */