PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/Themes/default/GenericMenu.template.php

https://github.com/smf-portal/SMF2.1
PHP | 359 lines | 245 code | 63 blank | 51 comment | 43 complexity | 0df590fb449cb4e281aba18a2810fd00 MD5 | raw file
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines
  7. * @copyright 2012 Simple Machines
  8. * @license http://www.simplemachines.org/about/smf/license.php BSD
  9. *
  10. * @version 2.1 Alpha 1
  11. */
  12. // This contains the html for the side bar of the admin center, which is used for all admin pages.
  13. function template_generic_menu_sidebar_above()
  14. {
  15. global $context, $settings, $options, $scripturl, $txt, $modSettings;
  16. // This is the main table - we need it so we can keep the content to the right of it.
  17. echo '
  18. <div id="main_container">
  19. <div id="left_admsection">';
  20. // What one are we rendering?
  21. $context['cur_menu_id'] = isset($context['cur_menu_id']) ? $context['cur_menu_id'] + 1 : 1;
  22. $menu_context = &$context['menu_data_' . $context['cur_menu_id']];
  23. // For every section that appears on the sidebar...
  24. $firstSection = true;
  25. foreach ($menu_context['sections'] as $section)
  26. {
  27. // Show the section header - and pump up the line spacing for readability.
  28. echo '
  29. <div class="adm_section">
  30. <div class="cat_bar">
  31. <h4 class="catbg">
  32. ', $section['title'], '
  33. </h4>
  34. </div>
  35. <ul class="dropmenu left_admmenu">';
  36. // For every area of this section show a link to that area (bold if it's currently selected.)
  37. foreach ($section['areas'] as $i => $area)
  38. {
  39. // Not supposed to be printed?
  40. if (empty($area['label']))
  41. continue;
  42. echo '
  43. <li ', !empty($area['subsections']) ?'class="subsections"':'', ' ', ($i == $menu_context['current_area']) ?'id="menu_current_area"':'', '>';
  44. // Is this the current area, or just some area?
  45. if ($i == $menu_context['current_area'])
  46. {
  47. echo '
  48. <strong><a href="', isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $i, $menu_context['extra_parameters'], '">', $area['label'], '</a></strong>';
  49. if (empty($context['tabs']))
  50. $context['tabs'] = isset($area['subsections']) ? $area['subsections'] : array();
  51. }
  52. else
  53. echo '
  54. <a href="', isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $i, $menu_context['extra_parameters'], '">', $area['label'], '</a>';
  55. // Is there any subsections?
  56. if (!empty($area['subsections']))
  57. {
  58. echo '
  59. <ul>';
  60. foreach ($area['subsections'] as $sa => $sub)
  61. {
  62. if (!empty($sub['disabled']))
  63. continue;
  64. $url = isset($sub['url']) ? $sub['url'] : (isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $i) . ';sa=' . $sa;
  65. echo '
  66. <li>
  67. <a ', !empty($sub['selected']) ? 'class="chosen" ' : '', 'href="', $url, $menu_context['extra_parameters'], '">', $sub['label'], '</a>
  68. </li>';
  69. }
  70. echo '
  71. </ul>';
  72. }
  73. echo '
  74. </li>';
  75. }
  76. echo '
  77. </ul>
  78. </div>';
  79. $firstSection = false;
  80. }
  81. // This is where the actual "main content" area for the admin section starts.
  82. echo '
  83. </div>
  84. <div id="main_admsection">';
  85. // If there are any "tabs" setup, this is the place to shown them.
  86. if (!empty($context['tabs']) && empty($context['force_disable_tabs']))
  87. template_generic_menu_tabs($menu_context);
  88. }
  89. // Part of the sidebar layer - closes off the main bit.
  90. function template_generic_menu_sidebar_below()
  91. {
  92. global $context, $settings, $options;
  93. echo '
  94. </div>
  95. </div>';
  96. }
  97. // This contains the html for the side bar of the admin center, which is used for all admin pages.
  98. function template_generic_menu_dropdown_above()
  99. {
  100. global $context, $settings, $options, $scripturl, $txt, $modSettings;
  101. // Which menu are we rendering?
  102. $context['cur_menu_id'] = isset($context['cur_menu_id']) ? $context['cur_menu_id'] + 1 : 1;
  103. $menu_context = &$context['menu_data_' . $context['cur_menu_id']];
  104. echo '
  105. <div id="admin_menu">';
  106. echo '
  107. <ul class="dropmenu" id="dropdown_menu_', $context['cur_menu_id'], '">';
  108. // Main areas first.
  109. foreach ($menu_context['sections'] as $section)
  110. {
  111. echo '
  112. <li ', !empty($section['areas']) ? 'class="subsections"' : '', '><a class="', !empty($section['selected']) ? 'active ' : '', '" href="', $section['url'], $menu_context['extra_parameters'], '">', $section['title'] , '</a>
  113. <ul>';
  114. // For every area of this section show a link to that area (bold if it's currently selected.)
  115. // @todo Code for additional_items class was deprecated and has been removed. Suggest following up in Sources if required.
  116. foreach ($section['areas'] as $i => $area)
  117. {
  118. // Not supposed to be printed?
  119. if (empty($area['label']))
  120. continue;
  121. echo '
  122. <li', !empty($area['subsections']) ? ' class="subsections"' : '', '>';
  123. echo '
  124. <a ', !empty($area['selected']) ? 'class="chosen" ' : '', 'href="', (isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $i), $menu_context['extra_parameters'], '">', $area['icon'], $area['label'], '</a>';
  125. // Is this the current area, or just some area?
  126. if (!empty($area['selected']) && empty($context['tabs']))
  127. $context['tabs'] = isset($area['subsections']) ? $area['subsections'] : array();
  128. // Are there any subsections?
  129. if (!empty($area['subsections']))
  130. {
  131. echo '
  132. <ul>';
  133. foreach ($area['subsections'] as $sa => $sub)
  134. {
  135. if (!empty($sub['disabled']))
  136. continue;
  137. $url = isset($sub['url']) ? $sub['url'] : (isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $i) . ';sa=' . $sa;
  138. echo '
  139. <li ', !empty($area['subsections']) ? ' class="subsections"' : '', '>
  140. <a ', !empty($sub['selected']) ? 'class="chosen" ' : '', ' href="', $url, $menu_context['extra_parameters'], '">', $sub['label'], '</a>
  141. </li>';
  142. }
  143. echo '
  144. </ul>';
  145. }
  146. echo '
  147. </li>';
  148. }
  149. echo '
  150. </ul>
  151. </li>';
  152. }
  153. echo '
  154. </ul>
  155. </div>';
  156. // This is the main table - we need it so we can keep the content to the right of it.
  157. echo '
  158. <div id="admin_content">';
  159. // It's possible that some pages have their own tabs they wanna force...
  160. if (!empty($context['tabs']))
  161. template_generic_menu_tabs($menu_context);
  162. }
  163. // Part of the admin layer - used with admin_above to close the table started in it.
  164. function template_generic_menu_dropdown_below()
  165. {
  166. global $context, $settings, $options;
  167. echo '
  168. </div>';
  169. }
  170. // Some code for showing a tabbed view.
  171. function template_generic_menu_tabs(&$menu_context)
  172. {
  173. global $context, $settings, $options, $scripturl, $txt, $modSettings;
  174. // Handy shortcut.
  175. $tab_context = &$menu_context['tab_data'];
  176. echo '
  177. <div class="cat_bar">
  178. <h3 class="catbg">';
  179. // Exactly how many tabs do we have?
  180. foreach ($context['tabs'] as $id => $tab)
  181. {
  182. // Can this not be accessed?
  183. if (!empty($tab['disabled']))
  184. {
  185. $tab_context['tabs'][$id]['disabled'] = true;
  186. continue;
  187. }
  188. // Did this not even exist - or do we not have a label?
  189. if (!isset($tab_context['tabs'][$id]))
  190. $tab_context['tabs'][$id] = array('label' => $tab['label']);
  191. elseif (!isset($tab_context['tabs'][$id]['label']))
  192. $tab_context['tabs'][$id]['label'] = $tab['label'];
  193. // Has a custom URL defined in the main admin structure?
  194. if (isset($tab['url']) && !isset($tab_context['tabs'][$id]['url']))
  195. $tab_context['tabs'][$id]['url'] = $tab['url'];
  196. // Any additional paramaters for the url?
  197. if (isset($tab['add_params']) && !isset($tab_context['tabs'][$id]['add_params']))
  198. $tab_context['tabs'][$id]['add_params'] = $tab['add_params'];
  199. // Has it been deemed selected?
  200. if (!empty($tab['is_selected']))
  201. $tab_context['tabs'][$id]['is_selected'] = true;
  202. // Does it have its own help?
  203. if (!empty($tab['help']))
  204. $tab_context['tabs'][$id]['help'] = $tab['help'];
  205. // Is this the last one?
  206. if (!empty($tab['is_last']) && !isset($tab_context['override_last']))
  207. $tab_context['tabs'][$id]['is_last'] = true;
  208. }
  209. // Find the selected tab
  210. foreach ($tab_context['tabs'] as $sa => $tab)
  211. {
  212. if (!empty($tab['is_selected']) || (isset($menu_context['current_subsection']) && $menu_context['current_subsection'] == $sa))
  213. {
  214. $selected_tab = $tab;
  215. $tab_context['tabs'][$sa]['is_selected'] = true;
  216. }
  217. }
  218. // Show an icon and/or a help item?
  219. if (!empty($selected_tab['icon']) || !empty($tab_context['icon']) || !empty($selected_tab['help']) || !empty($tab_context['help']))
  220. {
  221. if (!empty($selected_tab['icon']) || !empty($tab_context['icon']))
  222. echo '<img src="', $settings['images_url'], '/icons/', !empty($selected_tab['icon']) ? $selected_tab['icon'] : $tab_context['icon'], '" alt="" class="icon" />';
  223. if (!empty($selected_tab['help']) || !empty($tab_context['help']))
  224. echo '<a href="', $scripturl, '?action=helpadmin;help=', !empty($selected_tab['help']) ? $selected_tab['help'] : $tab_context['help'], '" onclick="return reqOverlayDiv(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics_hd.png" alt="', $txt['help'], '" class="icon" /></a>';
  225. echo $tab_context['title'];
  226. }
  227. else
  228. {
  229. echo '
  230. ', $tab_context['title'];
  231. }
  232. echo '
  233. </h3>
  234. </div>';
  235. // Shall we use the tabs?
  236. if (!empty($settings['use_tabs']))
  237. {
  238. echo '
  239. <p class="description">
  240. ', !empty($selected_tab['description']) ? $selected_tab['description'] : $tab_context['description'], '
  241. </p>';
  242. // The admin tabs.
  243. echo '
  244. <div id="adm_submenus">
  245. <ul class="dropmenu">';
  246. // Print out all the items in this tab.
  247. foreach ($tab_context['tabs'] as $sa => $tab)
  248. {
  249. if (!empty($tab['disabled']))
  250. continue;
  251. if (!empty($tab['is_selected']))
  252. {
  253. echo '
  254. <li>
  255. <a class="active" href="', isset($tab['url']) ? $tab['url'] : $menu_context['base_url'] . ';area=' . $menu_context['current_area'] . ';sa=' . $sa, $menu_context['extra_parameters'], isset($tab['add_params']) ? $tab['add_params'] : '', '">', $tab['label'], '</a>
  256. </li>';
  257. }
  258. else
  259. echo '
  260. <li>
  261. <a href="', isset($tab['url']) ? $tab['url'] : $menu_context['base_url'] . ';area=' . $menu_context['current_area'] . ';sa=' . $sa, $menu_context['extra_parameters'], isset($tab['add_params']) ? $tab['add_params'] : '', '">', $tab['label'], '</a>
  262. </li>';
  263. }
  264. // the end of tabs
  265. echo '
  266. </ul>
  267. </div>
  268. <br class="clear" />';
  269. }
  270. // ...if not use the old style
  271. else
  272. {
  273. echo '
  274. <p class="tabs">';
  275. // Print out all the items in this tab.
  276. foreach ($tab_context['tabs'] as $sa => $tab)
  277. {
  278. if (!empty($tab['disabled']))
  279. continue;
  280. if (!empty($tab['is_selected']))
  281. {
  282. echo '
  283. <img src="', $settings['images_url'], '/selected.png" alt="*" /> <strong><a href="', isset($tab['url']) ? $tab['url'] : $menu_context['base_url'] . ';area=' . $menu_context['current_area'] . ';sa=' . $sa, $menu_context['extra_parameters'], '">', $tab['label'], '</a></strong>';
  284. }
  285. else
  286. echo '
  287. <a href="', isset($tab['url']) ? $tab['url'] : $menu_context['base_url'] . ';area=' . $menu_context['current_area'] . ';sa=' . $sa, $menu_context['extra_parameters'], '">', $tab['label'], '</a>';
  288. if (empty($tab['is_last']))
  289. echo ' | ';
  290. }
  291. echo '
  292. </p>
  293. <p class="description">', isset($selected_tab['description']) ? $selected_tab['description'] : $tab_context['description'], '</p>';
  294. }
  295. }
  296. ?>