PageRenderTime 72ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/titania/contributions/index.php

https://github.com/marc1706/customisation-db
PHP | 190 lines | 123 code | 28 blank | 39 comment | 36 complexity | 7ba5e13ef0a5e0202f1608e6244ee205 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package Titania
  5. * @copyright (c) 2008 phpBB Customisation Database Team
  6. * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2
  7. *
  8. */
  9. /**
  10. * @ignore
  11. */
  12. define('IN_TITANIA', true);
  13. if (!defined('TITANIA_ROOT')) define('TITANIA_ROOT', '../');
  14. if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
  15. include(TITANIA_ROOT . 'common.' . PHP_EXT);
  16. // Setup some vars
  17. $page = basename(request_var('page', ''));
  18. // Add common lang
  19. titania::add_lang('contributions');
  20. // Go to the queue discussion for this contribution item (saves us from having to figure out the URL to the topic every time we generate it)
  21. if ($page == 'queue_discussion')
  22. {
  23. load_contrib();
  24. $sql = 'SELECT * FROM ' . TITANIA_TOPICS_TABLE . '
  25. WHERE topic_type = ' . TITANIA_QUEUE_DISCUSSION . '
  26. AND parent_id = ' . titania::$contrib->contrib_id;
  27. $result = phpbb::$db->sql_query($sql);
  28. $row = phpbb::$db->sql_fetchrow($result);
  29. phpbb::$db->sql_freeresult($result);
  30. if ($row)
  31. {
  32. $topic = new titania_topic;
  33. $topic->__set_array($row);
  34. redirect($topic->get_url());
  35. }
  36. trigger_error('NO_QUEUE_DISCUSSION_TOPIC');
  37. }
  38. // And now to load the appropriate page...
  39. switch ($page)
  40. {
  41. case 'faq' :
  42. case 'support' :
  43. case 'manage' :
  44. case 'revision' :
  45. case 'revision_edit' :
  46. case 'demo' :
  47. include(TITANIA_ROOT . 'contributions/' . $page . '.' . PHP_EXT);
  48. break;
  49. case 'report' :
  50. include(TITANIA_ROOT . 'contributions/details.' . PHP_EXT);
  51. break;
  52. default :
  53. include(TITANIA_ROOT . 'contributions/details.' . PHP_EXT);
  54. break;
  55. }
  56. /**
  57. * Load contribution
  58. *
  59. * Call this AFTER you have loaded the main object (like the FAQ item if requested for example)
  60. *
  61. * @param mixed $contrib contrib_id (always send if you have loaded an item for this contrib!)
  62. */
  63. function load_contrib($contrib_id = false)
  64. {
  65. $contrib = (request_var('id', 0)) ? request_var('id', 0) : utf8_normalize_nfc(request_var('c', '', true));
  66. $type = request_var('type', '');
  67. // Load the contribution
  68. titania::$contrib = new titania_contribution();
  69. if (!titania::$contrib->load($contrib))
  70. {
  71. trigger_error('CONTRIB_NOT_FOUND');
  72. }
  73. // Make sure the contrib requested is the same as the contrib loaded
  74. if (($contrib_id !== false && $contrib_id != titania::$contrib->contrib_id) || $type != titania_types::$types[titania::$contrib->contrib_type]->url)
  75. {
  76. // Mismatch, redirect
  77. redirect(titania::$contrib->get_url(basename(request_var('page', 'details'))));
  78. }
  79. // Put the author in titania::$author
  80. titania::$author = titania::$contrib->author;
  81. // Check to see if the currently accessing user is an author
  82. if (titania::$access_level == TITANIA_ACCESS_PUBLIC && phpbb::$user->data['is_registered'] && !phpbb::$user->data['is_bot'])
  83. {
  84. if (titania::$contrib->is_author || titania::$contrib->is_active_coauthor)
  85. {
  86. titania::$access_level = TITANIA_ACCESS_AUTHORS;
  87. }
  88. }
  89. // Count the number of FAQ items to display
  90. $flags = titania_count::get_flags(titania::$access_level);
  91. $faq_count = titania_count::from_db(titania::$contrib->contrib_faq_count, $flags);
  92. /**
  93. * Menu Array
  94. *
  95. * 'filename' => array(
  96. * 'title' => 'nav menu title',
  97. * 'url' => $page_url,
  98. * 'auth' => ($can_see_page) ? true : false, // Not required, always true if missing
  99. * ),
  100. */
  101. $nav_ary = array(
  102. 'details' => array(
  103. 'title' => 'CONTRIB_DETAILS',
  104. 'url' => titania::$contrib->get_url(),
  105. ),
  106. 'faq' => array(
  107. 'title' => 'CONTRIB_FAQ',
  108. 'url' => titania::$contrib->get_url('faq'),
  109. 'auth' => (titania::$access_level != TITANIA_ACCESS_PUBLIC || $faq_count) ? true : false,
  110. 'count' => $faq_count,
  111. ),
  112. 'support' => array(
  113. 'title' => 'CONTRIB_SUPPORT',
  114. 'url' => titania::$contrib->get_url('support'),
  115. 'auth' => (titania::$config->support_in_titania || titania::$access_level < TITANIA_ACCESS_PUBLIC) ? true : false,
  116. ),
  117. 'manage' => array(
  118. 'title' => 'CONTRIB_MANAGE',
  119. 'url' => titania::$contrib->get_url('manage'),
  120. 'auth' => ((((titania::$contrib->is_author || titania::$contrib->is_active_coauthor) && phpbb::$auth->acl_get('u_titania_post_edit_own')) && !in_array(titania::$contrib->contrib_status, array(TITANIA_CONTRIB_CLEANED, TITANIA_CONTRIB_DISABLED))) || phpbb::$auth->acl_get('u_titania_mod_contrib_mod') || titania_types::$types[titania::$contrib->contrib_type]->acl_get('moderate'))
  121. ),
  122. );
  123. // Search for a category with the same name as the contrib type. This is a bit ugly, but there really isn't any better option
  124. $categories_ary = titania::$cache->get_categories();
  125. titania::$contrib->get_categories();
  126. titania::$contrib->integrate_demo = false;
  127. foreach ($categories_ary as $category_id => $category_row)
  128. {
  129. $category_row['category_name'] = (isset(phpbb::$user->lang[$category_row['category_name']])) ? phpbb::$user->lang[$category_row['category_name']] : $category_row['category_name'];
  130. if ($category_row['category_name'] == titania_types::$types[titania::$contrib->contrib_type]->lang || $category_row['category_name'] == titania_types::$types[titania::$contrib->contrib_type]->langs)
  131. {
  132. $category_object = new titania_category;
  133. $category_object->__set_array($categories_ary[$category_id]);
  134. // Generate the main breadcrumbs
  135. titania::generate_breadcrumbs(array(
  136. $category_object->category_name => titania_url::build_url($category_object->get_url()),
  137. ));
  138. }
  139. if (isset(titania::$contrib->categories[$category_id]) && $category_row['category_options'] & TITANIA_CAT_FLAG_DEMO)
  140. {
  141. titania::$contrib->integrate_demo = true;
  142. phpbb::$template->assign_var('S_INTEGRATE_DEMO', true);
  143. }
  144. }
  145. $nav_ary['demo'] = array(
  146. 'title' => 'CONTRIB_DEMO',
  147. 'url' => titania::$contrib->get_url('demo'),
  148. 'auth' => (titania::$contrib->contrib_demo && titania::$contrib->contrib_status == TITANIA_CONTRIB_APPROVED && titania::$contrib->integrate_demo) ? true : false,
  149. );
  150. // Display nav menu
  151. $page = request_var('page', '');
  152. titania::generate_nav($nav_ary, $page, 'details');
  153. titania::generate_breadcrumbs(array(
  154. titania::$contrib->contrib_name => titania::$contrib->get_url(),
  155. ));
  156. if ($page)
  157. {
  158. titania::generate_breadcrumbs(array(
  159. $nav_ary[$page]['title'] => $nav_ary[$page]['url'],
  160. ));
  161. }
  162. }