/administrator/includes/toolbar.php

https://bitbucket.org/eternaware/joomus · PHP · 692 lines · 196 code · 70 blank · 426 comment · 1 complexity · 1d320f16e5e12f8ca9506f883fe8bb1c MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Administrator
  4. *
  5. * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  6. * @license GNU General Public License version 2 or later; see LICENSE.txt
  7. */
  8. defined('_JEXEC') or die;
  9. /**
  10. * Utility class for the button bar.
  11. *
  12. * @package Joomla.Administrator
  13. * @since 1.5
  14. */
  15. abstract class JToolbarHelper
  16. {
  17. /**
  18. * Title cell.
  19. * For the title and toolbar to be rendered correctly,
  20. * this title fucntion must be called before the starttable function and the toolbars icons
  21. * this is due to the nature of how the css has been used to postion the title in respect to the toolbar.
  22. *
  23. * @param string $title The title.
  24. * @param string $icon The space-separated names of the image.
  25. *
  26. * @return void
  27. *
  28. * @since 1.5
  29. */
  30. public static function title($title, $icon = 'generic.png')
  31. {
  32. // Strip the extension.
  33. $icons = explode(' ', $icon);
  34. foreach ($icons as &$icon)
  35. {
  36. $icon = 'icon-48-' . preg_replace('#\.[^.]*$#', '', $icon);
  37. }
  38. $html = '<div class="pagetitle ' . htmlspecialchars(implode(' ', $icons)) . '"><h2>' . $title . '</h2></div>';
  39. $app = JFactory::getApplication();
  40. $app->JComponentTitle = $html;
  41. }
  42. /**
  43. * Writes a spacer cell.
  44. *
  45. * @param string $width The width for the cell
  46. *
  47. * @return void
  48. *
  49. * @since 1.5
  50. */
  51. public static function spacer($width = '')
  52. {
  53. $bar = JToolbar::getInstance('toolbar');
  54. // Add a spacer.
  55. $bar->appendButton('Separator', 'spacer', $width);
  56. }
  57. /**
  58. * Writes a divider between menu buttons
  59. *
  60. * @return void
  61. *
  62. * @since 1.5
  63. */
  64. public static function divider()
  65. {
  66. $bar = JToolbar::getInstance('toolbar');
  67. // Add a divider.
  68. $bar->appendButton('Separator', 'divider');
  69. }
  70. /**
  71. * Writes a custom option and task button for the button bar.
  72. *
  73. * @param string $task The task to perform (picked up by the switch($task) blocks.
  74. * @param string $icon The image to display.
  75. * @param string $iconOver The image to display when moused over.
  76. * @param string $alt The alt text for the icon image.
  77. * @param bool $listSelect True if required to check that a standard list item is checked.
  78. *
  79. * @return void
  80. *
  81. * @since 1.5
  82. */
  83. public static function custom($task = '', $icon = '', $iconOver = '', $alt = '', $listSelect = true)
  84. {
  85. $bar = JToolbar::getInstance('toolbar');
  86. // Strip extension.
  87. $icon = preg_replace('#\.[^.]*$#', '', $icon);
  88. // Add a standard button.
  89. $bar->appendButton('Standard', $icon, $alt, $task, $listSelect);
  90. }
  91. /**
  92. * Writes a preview button for a given option (opens a popup window).
  93. *
  94. * @param string $url The name of the popup file (excluding the file extension)
  95. * @param bool $updateEditors
  96. *
  97. * @return void
  98. *
  99. * @since 1.5
  100. */
  101. public static function preview($url = '', $updateEditors = false)
  102. {
  103. $bar = JToolbar::getInstance('toolbar');
  104. // Add a preview button.
  105. $bar->appendButton('Popup', 'preview', 'Preview', $url.'&task=preview');
  106. }
  107. /**
  108. * Writes a preview button for a given option (opens a popup window).
  109. *
  110. * @param string $ref The name of the popup file (excluding the file extension for an xml file).
  111. * @param bool $com Use the help file in the component directory.
  112. * @param string $override Use this URL instead of any other
  113. * @param string $component Name of component to get Help (null for current component)
  114. *
  115. * @return void
  116. *
  117. * @since 1.5
  118. */
  119. public static function help($ref, $com = false, $override = null, $component = null)
  120. {
  121. $bar = JToolbar::getInstance('toolbar');
  122. // Add a help button.
  123. $bar->appendButton('Help', $ref, $com, $override, $component);
  124. }
  125. /**
  126. * Writes a cancel button that will go back to the previous page without doing
  127. * any other operation.
  128. *
  129. * @param string $alt Alternative text.
  130. * @param string $href URL of the href attribute.
  131. *
  132. * @return void
  133. *
  134. * @since 1.5
  135. */
  136. public static function back($alt = 'JTOOLBAR_BACK', $href = 'javascript:history.back();')
  137. {
  138. $bar = JToolbar::getInstance('toolbar');
  139. // Add a back button.
  140. $bar->appendButton('Link', 'back', $alt, $href);
  141. }
  142. /**
  143. * Writes a media_manager button.
  144. *
  145. * @param string $directory The sub-directory to upload the media to.
  146. * @param string $alt An override for the alt text.
  147. *
  148. * @return void
  149. *
  150. * @since 1.5
  151. */
  152. public static function media_manager($directory = '', $alt = 'JTOOLBAR_UPLOAD')
  153. {
  154. $bar = JToolbar::getInstance('toolbar');
  155. // Add an upload button.
  156. $bar->appendButton('Popup', 'upload', $alt, 'index.php?option=com_media&tmpl=component&task=popupUpload&folder=' . $directory, 800, 520);
  157. }
  158. /**
  159. * Writes a common 'default' button for a record.
  160. *
  161. * @param string $task An override for the task.
  162. * @param string $alt An override for the alt text.
  163. *
  164. * @return void
  165. *
  166. * @since 1.5
  167. */
  168. public static function makeDefault($task = 'default', $alt = 'JTOOLBAR_DEFAULT')
  169. {
  170. $bar = JToolbar::getInstance('toolbar');
  171. // Add a default button.
  172. $bar->appendButton('Standard', 'star', $alt, $task, true);
  173. }
  174. /**
  175. * Writes a common 'assign' button for a record.
  176. *
  177. * @param string $task An override for the task.
  178. * @param string $alt An override for the alt text.
  179. *
  180. * @return void
  181. *
  182. * @since 1.5
  183. */
  184. public static function assign($task = 'assign', $alt = 'JTOOLBAR_ASSIGN')
  185. {
  186. $bar = JToolbar::getInstance('toolbar');
  187. // Add an assign button.
  188. $bar->appendButton('Standard', 'assign', $alt, $task, true);
  189. }
  190. /**
  191. * Writes the common 'new' icon for the button bar.
  192. *
  193. * @param string $task An override for the task.
  194. * @param string $alt An override for the alt text.
  195. * @param boolean $check True if required to check that a standard list item is checked.
  196. *
  197. * @return void
  198. *
  199. * @since 1.5
  200. */
  201. public static function addNew($task = 'add', $alt = 'JTOOLBAR_NEW', $check = false)
  202. {
  203. $bar = JToolbar::getInstance('toolbar');
  204. // Add a new button.
  205. $bar->appendButton('Standard', 'new', $alt, $task, $check);
  206. }
  207. /**
  208. * Writes a common 'publish' button.
  209. *
  210. * @param string $task An override for the task.
  211. * @param string $alt An override for the alt text.
  212. * @param boolean $check True if required to check that a standard list item is checked.
  213. *
  214. * @return void
  215. *
  216. * @since 1.5
  217. */
  218. public static function publish($task = 'publish', $alt = 'JTOOLBAR_PUBLISH', $check = false)
  219. {
  220. $bar = JToolbar::getInstance('toolbar');
  221. // Add a publish button.
  222. $bar->appendButton('Standard', 'publish', $alt, $task, $check);
  223. }
  224. /**
  225. * Writes a common 'publish' button for a list of records.
  226. *
  227. * @param string $task An override for the task.
  228. * @param string $alt An override for the alt text.
  229. *
  230. * @return void
  231. *
  232. * @since 1.5
  233. */
  234. public static function publishList($task = 'publish', $alt = 'JTOOLBAR_PUBLISH')
  235. {
  236. $bar = JToolbar::getInstance('toolbar');
  237. // Add a publish button (list).
  238. $bar->appendButton('Standard', 'publish', $alt, $task, true);
  239. }
  240. /**
  241. * Writes a common 'unpublish' button.
  242. *
  243. * @param string $task An override for the task.
  244. * @param string $alt An override for the alt text.
  245. * @param boolean $check True if required to check that a standard list item is checked.
  246. *
  247. * @return void
  248. *
  249. * @since 1.5
  250. */
  251. public static function unpublish($task = 'unpublish', $alt = 'JTOOLBAR_UNPUBLISH', $check = false)
  252. {
  253. $bar = JToolbar::getInstance('toolbar');
  254. // Add an unpublish button
  255. $bar->appendButton('Standard', 'unpublish', $alt, $task, $check);
  256. }
  257. /**
  258. * Writes a common 'unpublish' button for a list of records.
  259. *
  260. * @param string $task An override for the task.
  261. * @param string $alt An override for the alt text.
  262. *
  263. * @return void
  264. *
  265. * @since 1.5
  266. */
  267. public static function unpublishList($task = 'unpublish', $alt = 'JTOOLBAR_UNPUBLISH')
  268. {
  269. $bar = JToolbar::getInstance('toolbar');
  270. // Add an unpublish button (list).
  271. $bar->appendButton('Standard', 'unpublish', $alt, $task, true);
  272. }
  273. /**
  274. * Writes a common 'archive' button for a list of records.
  275. *
  276. * @param string $task An override for the task.
  277. * @param string $alt An override for the alt text.
  278. *
  279. * @return void
  280. *
  281. * @since 1.5
  282. */
  283. public static function archiveList($task = 'archive', $alt = 'JTOOLBAR_ARCHIVE')
  284. {
  285. $bar = JToolbar::getInstance('toolbar');
  286. // Add an archive button.
  287. $bar->appendButton('Standard', 'archive', $alt, $task, true);
  288. }
  289. /**
  290. * Writes an unarchive button for a list of records.
  291. *
  292. * @param string $task An override for the task.
  293. * @param string $alt An override for the alt text.
  294. *
  295. * @return void
  296. *
  297. * @since 1.5
  298. */
  299. public static function unarchiveList($task = 'unarchive', $alt = 'JTOOLBAR_UNARCHIVE')
  300. {
  301. $bar = JToolbar::getInstance('toolbar');
  302. // Add an unarchive button (list).
  303. $bar->appendButton('Standard', 'unarchive', $alt, $task, true);
  304. }
  305. /**
  306. * Writes a common 'edit' button for a list of records.
  307. *
  308. * @param string $task An override for the task.
  309. * @param string $alt An override for the alt text.
  310. *
  311. * @return void
  312. *
  313. * @since 1.5
  314. */
  315. public static function editList($task = 'edit', $alt = 'JTOOLBAR_EDIT')
  316. {
  317. $bar = JToolbar::getInstance('toolbar');
  318. // Add an edit button.
  319. $bar->appendButton('Standard', 'edit', $alt, $task, true);
  320. }
  321. /**
  322. * Writes a common 'edit' button for a template html.
  323. *
  324. * @param string $task An override for the task.
  325. * @param string $alt An override for the alt text.
  326. *
  327. * @return void
  328. *
  329. * @since 1.5
  330. */
  331. public static function editHtml($task = 'edit_source', $alt = 'JTOOLBAR_EDIT_HTML')
  332. {
  333. $bar = JToolbar::getInstance('toolbar');
  334. // Add an edit html button.
  335. $bar->appendButton('Standard', 'edithtml', $alt, $task, true);
  336. }
  337. /**
  338. * Writes a common 'edit' button for a template css.
  339. *
  340. * @param string $task An override for the task.
  341. * @param string $alt An override for the alt text.
  342. *
  343. * @return void
  344. *
  345. * @since 1.5
  346. */
  347. public static function editCss($task = 'edit_css', $alt = 'JTOOLBAR_EDIT_CSS')
  348. {
  349. $bar = JToolbar::getInstance('toolbar');
  350. // Add an edit css button (hide).
  351. $bar->appendButton('Standard', 'editcss', $alt, $task, true);
  352. }
  353. /**
  354. * Writes a common 'delete' button for a list of records.
  355. *
  356. * @param string $msg Postscript for the 'are you sure' message.
  357. * @param string $task An override for the task.
  358. * @param string $alt An override for the alt text.
  359. *
  360. * @return void
  361. *
  362. * @since 1.5
  363. */
  364. public static function deleteList($msg = '', $task = 'remove', $alt = 'JTOOLBAR_DELETE')
  365. {
  366. $bar = JToolbar::getInstance('toolbar');
  367. // Add a delete button.
  368. if ($msg)
  369. {
  370. $bar->appendButton('Confirm', $msg, 'delete', $alt, $task, true);
  371. }
  372. else
  373. {
  374. $bar->appendButton('Standard', 'delete', $alt, $task, true);
  375. }
  376. }
  377. /**
  378. * Write a trash button that will move items to Trash Manager.
  379. *
  380. * @param string $task An override for the task.
  381. * @param string $alt An override for the alt text.
  382. * @param bool $check
  383. *
  384. * @return void
  385. *
  386. * @since 1.5
  387. */
  388. public static function trash($task = 'remove', $alt = 'JTOOLBAR_TRASH', $check = true)
  389. {
  390. $bar = JToolbar::getInstance('toolbar');
  391. // Add a trash button.
  392. $bar->appendButton('Standard', 'trash', $alt, $task, $check, false);
  393. }
  394. /**
  395. * Writes a save button for a given option.
  396. * Apply operation leads to a save action only (does not leave edit mode).
  397. *
  398. * @param string $task An override for the task.
  399. * @param string $alt An override for the alt text.
  400. *
  401. * @return void
  402. *
  403. * @since 1.5
  404. */
  405. public static function apply($task = 'apply', $alt = 'JTOOLBAR_APPLY')
  406. {
  407. $bar = JToolbar::getInstance('toolbar');
  408. // Add an apply button
  409. $bar->appendButton('Standard', 'apply', $alt, $task, false);
  410. }
  411. /**
  412. * Writes a save button for a given option.
  413. * Save operation leads to a save and then close action.
  414. *
  415. * @param string $task An override for the task.
  416. * @param string $alt An override for the alt text.
  417. *
  418. * @return void
  419. *
  420. * @since 1.5
  421. */
  422. public static function save($task = 'save', $alt = 'JTOOLBAR_SAVE')
  423. {
  424. $bar = JToolbar::getInstance('toolbar');
  425. // Add a save button.
  426. $bar->appendButton('Standard', 'save', $alt, $task, false);
  427. }
  428. /**
  429. * Writes a save and create new button for a given option.
  430. * Save and create operation leads to a save and then add action.
  431. *
  432. * @param string $task An override for the task.
  433. * @param string $alt An override for the alt text.
  434. *
  435. * @return void
  436. *
  437. * @since 1.6
  438. */
  439. public static function save2new($task = 'save2new', $alt = 'JTOOLBAR_SAVE_AND_NEW')
  440. {
  441. $bar = JToolbar::getInstance('toolbar');
  442. // Add a save and create new button.
  443. $bar->appendButton('Standard', 'save-new', $alt, $task, false);
  444. }
  445. /**
  446. * Writes a save as copy button for a given option.
  447. * Save as copy operation leads to a save after clearing the key,
  448. * then returns user to edit mode with new key.
  449. *
  450. * @param string $task An override for the task.
  451. * @param string $alt An override for the alt text.
  452. *
  453. * @return void
  454. *
  455. * @since 1.6
  456. */
  457. public static function save2copy($task = 'save2copy', $alt = 'JTOOLBAR_SAVE_AS_COPY')
  458. {
  459. $bar = JToolbar::getInstance('toolbar');
  460. // Add a save and create new button.
  461. $bar->appendButton('Standard', 'save-copy', $alt, $task, false);
  462. }
  463. /**
  464. * Writes a checkin button for a given option.
  465. *
  466. * @param string $task An override for the task.
  467. * @param string $alt An override for the alt text.
  468. * @param boolean $check True if required to check that a standard list item is checked.
  469. *
  470. * @return void
  471. *
  472. * @since 1.7
  473. */
  474. public static function checkin($task = 'checkin', $alt = 'JTOOLBAR_CHECKIN', $check = true)
  475. {
  476. $bar = JToolbar::getInstance('toolbar');
  477. // Add a save and create new button.
  478. $bar->appendButton('Standard', 'checkin', $alt, $task, $check);
  479. }
  480. /**
  481. * Writes a cancel button and invokes a cancel operation (eg a checkin).
  482. *
  483. * @param string $task An override for the task.
  484. * @param string $alt An override for the alt text.
  485. *
  486. * @return void
  487. *
  488. * @since 1.5
  489. */
  490. public static function cancel($task = 'cancel', $alt = 'JTOOLBAR_CANCEL')
  491. {
  492. $bar = JToolbar::getInstance('toolbar');
  493. // Add a cancel button.
  494. $bar->appendButton('Standard', 'cancel', $alt, $task, false);
  495. }
  496. /**
  497. * Writes a configuration button and invokes a cancel operation (eg a checkin).
  498. *
  499. * @param string $component The name of the component, eg, com_content.
  500. * @param int $height The height of the popup. [UNUSED]
  501. * @param int $width The width of the popup. [UNUSED]
  502. * @param string $alt The name of the button.
  503. * @param string $path An alternative path for the configuation xml relative to JPATH_SITE.
  504. *
  505. * @return void
  506. *
  507. * @since 1.5
  508. */
  509. public static function preferences($component, $height = '550', $width = '875', $alt = 'JToolbar_Options', $path = '')
  510. {
  511. $component = urlencode($component);
  512. $path = urlencode($path);
  513. $bar = JToolBar::getInstance('toolbar');
  514. // Add a button linking to config for component.
  515. $bar->appendButton('Link', 'options', $alt, 'index.php?option=com_config&amp;view=component&amp;component=' . $component . '&amp;path=' . $path);
  516. }
  517. }
  518. /**
  519. * Utility class for the submenu.
  520. *
  521. * @package Joomla.Administrator
  522. * @since 1.5
  523. */
  524. abstract class JSubMenuHelper
  525. {
  526. /**
  527. * Menu entries
  528. *
  529. * @var array
  530. * @since 3.0
  531. */
  532. protected static $entries = array();
  533. /**
  534. * Filters
  535. *
  536. * @var array
  537. * @since 3.0
  538. */
  539. protected static $filters = array();
  540. /**
  541. * Value for the action attribute of the form.
  542. *
  543. * @var string
  544. * @since 3.0
  545. */
  546. protected static $action = '';
  547. /**
  548. * Method to add a menu item to submenu.
  549. *
  550. * @param string $name Name of the menu item.
  551. * @param string $link URL of the menu item.
  552. * @param bool $active True if the item is active, false otherwise.
  553. *
  554. * @return void
  555. *
  556. * @since 1.5
  557. */
  558. public static function addEntry($name, $link = '', $active = false)
  559. {
  560. array_push(self::$entries, array($name, $link, $active));
  561. }
  562. /**
  563. * Returns an array of all submenu entries
  564. *
  565. * @return array
  566. *
  567. * @since 3.0
  568. */
  569. public static function getEntries()
  570. {
  571. return self::$entries;
  572. }
  573. /**
  574. * Method to add a filter to the submenu
  575. *
  576. * @param string $label Label for the menu item.
  577. * @param string $name name for the filter. Also used as id.
  578. * @param string $options options for the select field.
  579. * @param bool $noDefault Don't the label as the empty option
  580. *
  581. * @return void
  582. *
  583. * @since 3.0
  584. */
  585. public static function addFilter($label, $name, $options, $noDefault = false)
  586. {
  587. array_push(self::$filters, array('label' => $label, 'name' => $name, 'options' => $options, 'noDefault' => $noDefault));
  588. }
  589. /**
  590. * Returns an array of all filters
  591. *
  592. * @return array
  593. *
  594. * @since 3.0
  595. */
  596. public static function getFilters()
  597. {
  598. return self::$filters;
  599. }
  600. /**
  601. * Set value for the action attribute of the filter form
  602. *
  603. * @return void
  604. *
  605. * @since 3.0
  606. */
  607. public static function setAction($action)
  608. {
  609. self::$action = $action;
  610. }
  611. /**
  612. * Get value for the action attribute of the filter form
  613. *
  614. * @return string
  615. *
  616. * @since 3.0
  617. */
  618. public static function getAction()
  619. {
  620. return self::$action;
  621. }
  622. }