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

/titania/index.php

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