PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/titania/index.php

http://github.com/phpbb/customisation-db
PHP | 377 lines | 260 code | 65 blank | 52 comment | 39 complexity | efa882867bd44d92a3f79f2d42c84245 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. require TITANIA_ROOT . 'common.' . PHP_EXT;
  16. $action = request_var('action', '');
  17. switch ($action)
  18. {
  19. case 'login':
  20. phpbb::login_box(titania_url::build_url(''));
  21. break;
  22. case 'logout':
  23. if (phpbb::$user->data['user_id'] != ANONYMOUS)
  24. {
  25. phpbb::$user->session_kill();
  26. phpbb::$user->session_begin();
  27. }
  28. redirect(titania_url::build_url(''));
  29. break;
  30. /**
  31. * Rate something & remove a rating from something
  32. */
  33. case 'rate' :
  34. $type = request_var('type', '');
  35. $id = request_var('id', 0);
  36. $value = request_var('value', -1.0);
  37. switch ($type)
  38. {
  39. case 'author' :
  40. $object = new titania_author();
  41. $object->load($id);
  42. $object->get_rating();
  43. $redirect = $object->get_url();
  44. if (!$object || !$object->author_id)
  45. {
  46. trigger_error('AUTHOR_NOT_FOUND');
  47. }
  48. break;
  49. case 'contrib' :
  50. $object = new titania_contribution();
  51. $object->load($id);
  52. $object->get_rating();
  53. $redirect = $object->get_url();
  54. if (!$object)
  55. {
  56. trigger_error('CONTRIB_NOT_FOUND');
  57. }
  58. break;
  59. default :
  60. trigger_error('BAD_RATING');
  61. break;
  62. }
  63. $result = ($value == -1) ? $object->rating->delete_rating() : $object->rating->add_rating($value);
  64. if ($result)
  65. {
  66. redirect($redirect);
  67. }
  68. else
  69. {
  70. trigger_error('BAD_RATING');
  71. }
  72. break;
  73. /**
  74. * Rerun the MPV or Automod test for the queue
  75. */
  76. case 'mpv' :
  77. case 'automod' :
  78. $revision_id = request_var('revision', 0);
  79. titania::add_lang(array('contributions', 'manage'));
  80. // Get the revision, contribution, attachment, and queue
  81. $revision = new titania_revision(false, $revision_id);
  82. if (!$revision->load())
  83. {
  84. trigger_error('NO_REVISION');
  85. }
  86. $contrib = new titania_contribution();
  87. if (!$contrib->load($revision->contrib_id))
  88. {
  89. trigger_error('CONTRIB_NOT_FOUND');
  90. }
  91. $revision->contrib = $contrib;
  92. if (!titania_types::$types[$contrib->contrib_type]->acl_get('view'))
  93. {
  94. titania::needs_auth();
  95. }
  96. $revision_attachment = new titania_attachment(TITANIA_CONTRIB);
  97. $revision_attachment->attachment_id = $revision->attachment_id;
  98. if (!$revision_attachment->load())
  99. {
  100. trigger_error('ERROR_NO_ATTACHMENT');
  101. }
  102. $queue = $revision->get_queue();
  103. $zip_file = titania::$config->upload_path . '/' . utf8_basename($revision_attachment->attachment_directory) . '/' . utf8_basename($revision_attachment->physical_filename);
  104. $download_package = titania_url::build_url('download', array('id' => $revision_attachment->attachment_id));
  105. if ($action == 'mpv')
  106. {
  107. // Start up the machine
  108. $contrib_tools = new titania_contrib_tools($zip_file);
  109. // Run MPV
  110. $mpv_results = $contrib_tools->mpv($download_package);
  111. if ($mpv_results === false)
  112. {
  113. // Too lazy to write another one...teams only anyways
  114. trigger_error('MPV_TEST_FAILED');
  115. }
  116. else
  117. {
  118. $mpv_results = phpbb::$user->lang['VALIDATION_MPV'] . "\n[quote=&quot;" . phpbb::$user->lang['VALIDATION_MPV'] . '&quot;]' . $mpv_results . "[/quote]\n";
  119. $queue->topic_reply($mpv_results);
  120. }
  121. }
  122. else if ($action == 'automod')
  123. {
  124. $new_dir_name = $contrib->contrib_name_clean . '_' . preg_replace('#[^0-9a-z]#', '_', strtolower($revision->revision_version));
  125. // Start up the machine
  126. $contrib_tools = new titania_contrib_tools($zip_file, $new_dir_name);
  127. // Automod testing time
  128. $details = '';
  129. $html_results = $bbcode_results = array();
  130. $sql = 'SELECT row_id, phpbb_version_branch, phpbb_version_revision FROM ' . TITANIA_REVISIONS_PHPBB_TABLE . '
  131. WHERE revision_id = ' . $revision->revision_id;
  132. $result = phpbb::$db->sql_query($sql);
  133. while ($row = phpbb::$db->sql_fetchrow($result))
  134. {
  135. $version_string = $row['phpbb_version_branch'][0] . '.' . $row['phpbb_version_branch'][1] . '.' .$row['phpbb_version_revision'];
  136. $phpbb_path = $contrib_tools->automod_phpbb_files($version_string);
  137. if ($phpbb_path === false)
  138. {
  139. continue;
  140. }
  141. phpbb::$template->assign_vars(array(
  142. 'PHPBB_VERSION' => $version_string,
  143. 'TEST_ID' => $row['row_id'],
  144. ));
  145. $html_result = $bbcode_result = '';
  146. $contrib_tools->automod($phpbb_path, $details, $html_result, $bbcode_result);
  147. $bbcode_results[] = $bbcode_result;
  148. }
  149. phpbb::$db->sql_freeresult($result);
  150. $bbcode_results = phpbb::$user->lang['VALIDATION_AUTOMOD'] . "\n[quote=&quot;" . phpbb::$user->lang['VALIDATION_AUTOMOD'] . '&quot;]' . implode("\n\n", $bbcode_results) . "[/quote]\n";
  151. // Update the queue with the results
  152. $queue = $revision->get_queue();
  153. $queue->topic_reply($bbcode_results);
  154. $contrib_tools->remove_temp_files();
  155. }
  156. if (sizeof($contrib_tools->error))
  157. {
  158. trigger_error(implode('<br />', $contrib_tools->error));
  159. }
  160. redirect(titania_url::build_url('manage/queue', array('queue' => titania_types::$types[$queue->queue_type]->url, 'q' => $queue->queue_id)));
  161. break;
  162. /**
  163. * Display all support topics
  164. */
  165. case 'support' :
  166. // The type of contribs (mod, style, converter, official_tool, etc.)
  167. $type = request_var('type', 'all');
  168. $type_id = titania_types::type_from_url($type);
  169. $type = (!$type_id) ? 'all' : $type;
  170. if ($type == 'all')
  171. {
  172. // Mark all topics read
  173. if (request_var('mark', '') == 'topics')
  174. {
  175. titania_tracking::track(TITANIA_ALL_SUPPORT, 0);
  176. }
  177. // Mark all topics read
  178. phpbb::$template->assign_var('U_MARK_TOPICS', titania_url::append_url(titania_url::build_url('support/all'), array('mark' => 'topics')));
  179. }
  180. // Generate the main breadcrumbs
  181. titania::generate_breadcrumbs(array(
  182. 'ALL_SUPPORT' => titania_url::build_url('support/' . $type . '/'),
  183. ));
  184. $data = topics_overlord::display_forums_complete('all_support', false, array('contrib_type' => $type_id));
  185. // Links to the support topic lists
  186. foreach (titania_types::$types as $id => $class)
  187. {
  188. phpbb::$template->assign_block_vars('support_types', array(
  189. 'U_SUPPORT' => titania_url::build_url('support/' . $class->url . '/'),
  190. 'TYPE_SUPPORT' => $class->langs,
  191. ));
  192. }
  193. // Canonical URL
  194. $data['sort']->set_url('support/' . $type . '/');
  195. phpbb::$template->assign_var('U_CANONICAL', $data['sort']->build_canonical());
  196. titania::page_header('CUSTOMISATION_DATABASE');
  197. titania::page_footer(true, 'all_support.html');
  198. break;
  199. /**
  200. * Display all contributions
  201. */
  202. case 'contributions' :
  203. // Mark all contribs read
  204. if (request_var('mark', '') == 'contribs')
  205. {
  206. titania_tracking::track(TITANIA_CONTRIB, 0);
  207. }
  208. phpbb::$template->assign_vars(array(
  209. 'U_MARK_TOPICS' => titania_url::append_url(titania_url::$current_page_url, array('mark' => 'contribs')),
  210. 'L_MARK_TOPICS_READ' => phpbb::$user->lang['MARK_CONTRIBS_READ'],
  211. ));
  212. $data = contribs_overlord::display_contribs('all', false);
  213. // Canonical URL
  214. $data['sort']->set_url('contributions');
  215. phpbb::$template->assign_var('U_CANONICAL', $data['sort']->build_canonical());
  216. titania::page_header('CUSTOMISATION_DATABASE');
  217. titania::page_footer(true, 'all_contributions.html');
  218. break;
  219. /**
  220. * Default (display category/contrib list)
  221. */
  222. default :
  223. titania::_include('functions_display', 'titania_display_categories');
  224. // Get the category_id
  225. $category = request_var('c', '');
  226. $category_ary = explode('-', $category);
  227. if ($category_ary)
  228. {
  229. $category_id = array_pop($category_ary);
  230. }
  231. else
  232. {
  233. $category_id = (int) $category;
  234. }
  235. titania_display_categories($category_id);
  236. $categories_ary = false;
  237. if ($category_id != 0)
  238. {
  239. // Breadcrumbs
  240. $category_object = new titania_category;
  241. $categories_ary = titania::$cache->get_categories();
  242. // Parents
  243. foreach (array_reverse(titania::$cache->get_category_parents($category_id)) as $row)
  244. {
  245. $category_object->__set_array($categories_ary[$row['category_id']]);
  246. titania::generate_breadcrumbs(array(
  247. ((isset(phpbb::$user->lang[$categories_ary[$row['category_id']]['category_name']])) ? phpbb::$user->lang[$categories_ary[$row['category_id']]['category_name']] : $categories_ary[$row['category_id']]['category_name']) => titania_url::build_url($category_object->get_url()),
  248. ));
  249. }
  250. // Self
  251. $category_object->__set_array($categories_ary[$category_id]);
  252. titania::generate_breadcrumbs(array(
  253. ((isset(phpbb::$user->lang[$categories_ary[$category_id]['category_name']])) ? phpbb::$user->lang[$categories_ary[$category_id]['category_name']] : $categories_ary[$category_id]['category_name']) => titania_url::build_url($category_object->get_url()),
  254. ));
  255. // Get the child categories we want to select the contributions from
  256. $child_categories = array_keys(titania::$cache->get_category_children($category_id));
  257. phpbb::$template->assign_vars(array(
  258. 'CATEGORY_ID' => $category_id,
  259. 'S_DISPLAY_SEARCHBOX' => true,
  260. 'S_SEARCHBOX_ACTION' => titania_url::build_url('find-contribution'),
  261. ));
  262. $sort = false;
  263. // If there are categories we are listing as well, only show 10 by default
  264. if (sizeof($child_categories))
  265. {
  266. // Setup the sort tool to only display the 10 most recent
  267. $sort = contribs_overlord::build_sort();
  268. $sort->set_defaults(10);
  269. }
  270. // Include the current category in the ones selected
  271. $child_categories[] = $category_id;
  272. $data = contribs_overlord::display_contribs('category', $child_categories, $sort);
  273. // Canonical URL
  274. $data['sort']->set_url($category_object->get_url());
  275. phpbb::$template->assign_var('U_CANONICAL', $data['sort']->build_canonical());
  276. }
  277. else
  278. {
  279. // Mark all contribs read
  280. if (request_var('mark', '') == 'contribs')
  281. {
  282. titania_tracking::track(TITANIA_CONTRIB, 0);
  283. }
  284. phpbb::$template->assign_vars(array(
  285. 'CATEGORY_ID' => 0,
  286. 'U_MARK_FORUMS' => titania_url::append_url(titania_url::$current_page_url, array('mark' => 'contribs')),
  287. 'L_MARK_FORUMS_READ' => phpbb::$user->lang['MARK_CONTRIBS_READ'],
  288. 'S_DISPLAY_SEARCHBOX' => true,
  289. 'S_SEARCHBOX_ACTION' => titania_url::build_url('find-contribution'),
  290. ));
  291. // Setup the sort tool to only display the 10 most recent
  292. $sort = contribs_overlord::build_sort();
  293. $sort->set_defaults(10);
  294. $data = contribs_overlord::display_contribs('all', 0, $sort);
  295. // Canonical URL
  296. $data['sort']->set_url('');
  297. phpbb::$template->assign_var('U_CANONICAL', $data['sort']->build_canonical());
  298. }
  299. phpbb::$template->assign_vars(array(
  300. 'U_CREATE_CONTRIBUTION' => (phpbb::$auth->acl_get('u_titania_contrib_submit')) ? titania_url::build_url('author/' . htmlspecialchars_decode(phpbb::$user->data['username_clean']) . '/create') : '',
  301. 'S_HAS_CONTRIBS' => ($categories_ary && $categories_ary[$category_id]['category_type']) ? true : false,
  302. ));
  303. if ($category_id != 0)
  304. {
  305. $category_name = (isset(phpbb::$user->lang[$category_object->category_name])) ? phpbb::$user->lang[$category_object->category_name] : $category_object->category_name;
  306. titania::page_header($category_name . ' - ' . phpbb::$user->lang['CUSTOMISATION_DATABASE']);
  307. titania::page_footer(true, 'index_body.html');
  308. }
  309. break;
  310. }
  311. titania::page_header('CUSTOMISATION_DATABASE');
  312. titania::page_footer(true, 'index_body.html');