/Sources/Project.php

https://github.com/SMF-Arcade/SMF-Project-Tools · PHP · 195 lines · 136 code · 34 blank · 25 comment · 30 complexity · 7c5136191c7443471c852fea448d8891 MD5 · raw file

  1. <?php
  2. /**
  3. * Main handler for Project Tools
  4. *
  5. * @package core
  6. * @version 0.5.1
  7. * @license http://download.smfproject.net/license.php New-BSD
  8. * @since 0.1
  9. */
  10. if (!defined('SMF'))
  11. die('Hacking attempt...');
  12. /**
  13. * Main Project Tools functions, handles calling correct module and action
  14. */
  15. function Projects($standalone = false)
  16. {
  17. global $context, $smcFunc, $sourcedir, $user_info, $txt, $project, $issue;
  18. loadProjectToolsPage();
  19. // Check that user can access Project Tools
  20. isAllowedTo('project_access');
  21. if (isset($context['project_error']))
  22. fatal_lang_error($context['project_error'], false);
  23. // Admin made mistake on manual edits? (for safety reasons!!)
  24. if (isset($context['project_error']))
  25. fatal_lang_error($context['project_error'], false);
  26. // Add "Projects" to Linktree
  27. $context['linktree'][] = array(
  28. 'name' => $txt['linktree_projects'],
  29. 'url' => project_get_url(),
  30. );
  31. // Project was not selected
  32. if (empty($project))
  33. {
  34. $subActions = array(
  35. 'list' => array('ProjectList.php', 'ProjectList'),
  36. );
  37. $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'list';
  38. require_once($sourcedir . '/' . $subActions[$_REQUEST['sa']][0]);
  39. call_user_func($subActions[$_REQUEST['sa']][1]);
  40. return;
  41. }
  42. // Array for fixing old < 0.5 urls
  43. $saToArea = array(
  44. 'main' => 'main',
  45. 'subscribe' => array('main', 'subscribe'),
  46. // issues
  47. 'issues' => 'issues',
  48. 'viewIssue' => array('issues', 'view'),
  49. 'tags' => array('issues', 'tags'),
  50. 'update' => array('issues', 'update'),
  51. 'upload' => array('issues', 'upload'),
  52. 'move' => array('issues', 'move'),
  53. 'reply' => array('issues', 'reply'),
  54. 'reply2' => array('issues', 'reply2'),
  55. 'edit' => array('issues', 'edit'),
  56. 'edit2' => array('issues', 'edit2'),
  57. 'removeComment' => array('issues', 'removeComment'),
  58. 'reportIssue' => array('issues', 'report'),
  59. 'reportIssue2' => array('issues', 'report2'),
  60. );
  61. if (empty($_REQUEST['area']) && !empty($_REQUEST['sa']) && isset($saToArea[$_REQUEST['sa']]))
  62. {
  63. if (is_array($saToArea[$_REQUEST['sa']]))
  64. list ($_REQUEST['area'], $_REQUEST['sa']) = $saToArea[$_REQUEST['sa']];
  65. else
  66. {
  67. $_REQUEST['area'] = $saToArea[$_REQUEST['sa']];
  68. unset($_REQUEST['sa']);
  69. }
  70. }
  71. if ((!isset($_REQUEST['area']) || !isset($_REQUEST['sa'])) && !empty($issue))
  72. {
  73. $_REQUEST['area'] = 'issues';
  74. if (!isset($_REQUEST['sa']))
  75. $_REQUEST['sa'] = 'view';
  76. }
  77. // Areas are sets of subactions (registered by modules)
  78. $subAreas = array();
  79. // Tabs
  80. $context['project_tabs'] = array(
  81. 'title' => $context['project']['name'],
  82. 'description' => $context['project']['description'],
  83. 'tabs' => array(
  84. 'main' => array(
  85. 'href' => project_get_url(array('project' => $project)),
  86. 'title' => $txt['project'],
  87. 'is_selected' => false,
  88. 'hide_linktree' => true,
  89. 'order' => 'first',
  90. ),
  91. ),
  92. );
  93. // Let Modules register subAreas
  94. if (!empty($context['active_project_modules']))
  95. {
  96. foreach ($context['active_project_modules'] as $id => $module)
  97. {
  98. if (method_exists($module, 'RegisterProjectArea'))
  99. {
  100. $area = $module->RegisterProjectArea();
  101. $subAreas[$area['area']] = array(
  102. 'area' => $area['area'],
  103. 'module' => $id,
  104. 'tab' => !empty($area['tab']) ? $area['tab'] : $area['area'],
  105. );
  106. }
  107. if (method_exists($module, 'RegisterProjectTabs'))
  108. $module->RegisterProjectTabs($context['project_tabs']['tabs']);
  109. }
  110. }
  111. // Remove tabs which user has no permission to see
  112. foreach ($context['project_tabs']['tabs'] as $id => $tab)
  113. {
  114. if (!empty($tab['permission']) && !allowedTo($tab['permission']))
  115. unset($context['project_tabs']['tabs'][$id]);
  116. elseif (!empty($tab['project_permission']) && !projectAllowedTo($tab['project_permission']))
  117. unset($context['project_tabs']['tabs'][$id]);
  118. }
  119. // Sort tabs to correct order
  120. uksort($context['project_tabs']['tabs'], 'projectTabSort');
  121. if (empty($_REQUEST['area']) || !isset($subAreas[$_REQUEST['area']]))
  122. $_REQUEST['area'] = 'main';
  123. if (empty($_REQUEST['sa']))
  124. $_REQUEST['sa'] = 'main';
  125. $current_area = &$subAreas[$_REQUEST['area']];
  126. $context['current_project_module'] = &$context['active_project_modules'][$current_area['module']];
  127. if (isset($context['project_tabs']['tabs'][$current_area['tab']]))
  128. $context['project_tabs']['tabs'][$current_area['tab']]['is_selected'] = true;
  129. else
  130. $context['project_tabs']['tabs']['main']['is_selected'] = true;
  131. // Can access this area?
  132. if (isset($current_area['permission']))
  133. isAllowedTo($current_area['permission']);
  134. if (isset($current_area['project_permission']))
  135. projectIsAllowedTo($current_area['project_permission']);
  136. // Call Initialize View function
  137. if (isset($context['current_project_module']) && method_exists($context['current_project_module'], 'beforeSubaction'))
  138. $context['current_project_module']->beforeSubaction($_REQUEST['sa']);
  139. // Linktree
  140. $context['linktree'][] = array(
  141. 'name' => strip_tags($context['project']['name']),
  142. 'url' => project_get_url(array('project' => $project)),
  143. );
  144. if (empty($context['project_tabs']['tabs'][$current_area['tab']]['hide_linktree']))
  145. $context['linktree'][] = array(
  146. 'name' => $context['project_tabs']['tabs'][$current_area['tab']]['title'],
  147. 'url' => $context['project_tabs']['tabs'][$current_area['tab']]['href'],
  148. );
  149. if (isset($context['current_project_module']->subTabs[$_REQUEST['sa']]))
  150. {
  151. $context['current_project_module']->subTabs[$_REQUEST['sa']]['is_selected'] = true;
  152. if (empty($context['current_project_module']->subTabs[$_REQUEST['sa']]['hide_linktree']))
  153. $context['linktree'][] = array(
  154. 'name' => $context['current_project_module']->subTabs[$_REQUEST['sa']]['title'],
  155. 'url' => $context['current_project_module']->subTabs[$_REQUEST['sa']]['href'],
  156. );
  157. $context['project_sub_tabs'] = $context['current_project_module']->subTabs;
  158. }
  159. $context['current_project_module']->main($_REQUEST['sa']);
  160. }
  161. ?>