GenericMenu.template.php 11 KB

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