PageRenderTime 39ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/includes/toolbar.php

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