1 <?php
2 3 4 5 6 7
8
9 defined('FOF_INCLUDED') or die;
10
11 12 13 14 15 16 17
18 class FOFToolbar
19 {
20
21 protected $config = array();
22
23
24 protected $input = array();
25
26
27 public $perms = array();
28
29
30 protected $linkbar = array();
31
32
33 protected = false;
34
35
36 protected $renderFrontendButtons = false;
37
38 39 40 41 42 43 44 45
46 public static function &getAnInstance($option = null, $config = array())
47 {
48 static $instances = array();
49
50
51 if (is_object($config))
52 {
53 $config = (array) $config;
54 }
55 elseif (!is_array($config))
56 {
57 $config = array();
58 }
59
60 $hash = $option;
61
62 if (!array_key_exists($hash, $instances))
63 {
64 if (array_key_exists('input', $config))
65 {
66 if ($config['input'] instanceof FOFInput)
67 {
68 $input = $config['input'];
69 }
70 else
71 {
72 $input = new FOFInput($config['input']);
73 }
74 }
75 else
76 {
77 $input = new FOFInput;
78 }
79
80 $config['option'] = !is_null($option) ? $option : $input->getCmd('option', 'com_foobar');
81 $input->set('option', $config['option']);
82 $config['input'] = $input;
83
84 $className = ucfirst(str_replace('com_', '', $config['option'])) . 'Toolbar';
85
86 if (!class_exists($className))
87 {
88 $componentPaths = FOFPlatform::getInstance()->getComponentBaseDirs($config['option']);
89
90 $searchPaths = array(
91 $componentPaths['main'],
92 $componentPaths['main'] . '/toolbars',
93 $componentPaths['alt'],
94 $componentPaths['alt'] . '/toolbars'
95 );
96
97 if (array_key_exists('searchpath', $config))
98 {
99 array_unshift($searchPaths, $config['searchpath']);
100 }
101
102 $filesystem = FOFPlatform::getInstance()->getIntegrationObject('filesystem');
103
104 $path = $filesystem->pathFind(
105 $searchPaths, 'toolbar.php'
106 );
107
108 if ($path)
109 {
110 require_once $path;
111 }
112 }
113
114 if (!class_exists($className))
115 {
116 $className = 'FOFToolbar';
117 }
118
119 $instance = new $className($config);
120
121 $instances[$hash] = $instance;
122 }
123
124 return $instances[$hash];
125 }
126
127 128 129 130 131
132 public function __construct($config = array())
133 {
134
135 if (is_object($config))
136 {
137 $config = (array) $config;
138 }
139 elseif (!is_array($config))
140 {
141 $config = array();
142 }
143
144
145 $this->config = $config;
146
147
148 if (array_key_exists('input', $config))
149 {
150 $this->input = $config['input'];
151 }
152 else
153 {
154 $this->input = new FOFInput;
155 }
156
157
158 $this->component = $this->input->getCmd('option', 'com_foobar');
159
160
161
162 if (array_key_exists('option', $config))
163 {
164 $this->component = $config['option'];
165 }
166
167 $this->input->set('option', $this->component);
168
169
170 $platform = FOFPlatform::getInstance();
171 $perms = (object) array(
172 'manage' => $platform->authorise('core.manage', $this->input->getCmd('option', 'com_foobar')),
173 'create' => $platform->authorise('core.create', $this->input->getCmd('option', 'com_foobar')),
174 'edit' => $platform->authorise('core.edit', $this->input->getCmd('option', 'com_foobar')),
175 'editstate' => $platform->authorise('core.edit.state', $this->input->getCmd('option', 'com_foobar')),
176 'delete' => $platform->authorise('core.delete', $this->input->getCmd('option', 'com_foobar')),
177 );
178
179
180 if (array_key_exists('renderFrontendButtons', $config))
181 {
182 $this->renderFrontendButtons = $config['renderFrontendButtons'];
183 }
184
185 if (array_key_exists('renderFrontendSubmenu', $config))
186 {
187 $this->renderFrontendSubmenu = $config['renderFrontendSubmenu'];
188 }
189
190
191 if (!FOFPlatform::getInstance()->isBackend())
192 {
193
194 if(!class_exists('JToolbarHelper'))
195 {
196 $platformDirs = FOFPlatform::getInstance()->getPlatformBaseDirs();
197 require_once $platformDirs['root'] . '/administrator/includes/toolbar.php';
198 }
199
200
201 if ($this->renderFrontendButtons)
202 {
203
204 FOFPlatform::getInstance()->loadTranslations('');
205
206
207 if(!FOFPlatform::getInstance()->isCli())
208 {
209
210 if (version_compare(JVERSION, '3.0', 'ge'))
211 {
212 JHtml::_('jquery.framework');
213
214 if (version_compare(JVERSION, '3.3.0', 'ge'))
215 {
216 JHtml::_('behavior.core');
217 }
218 else
219 {
220 JHtml::_('behavior.framework', true);
221 }
222 }
223 else
224 {
225 JHtml::_('behavior.framework');
226 }
227 }
228 }
229 }
230
231
232 $this->perms = $perms;
233 }
234
235 236 237 238 239 240 241 242 243
244 public function renderToolbar($view = null, $task = null, $input = null)
245 {
246 if (!empty($input))
247 {
248 $saveInput = $this->input;
249 $this->input = $input;
250 }
251
252
253 if ($this->input->getCmd('tmpl', '') == 'component')
254 {
255 $render_toolbar = false;
256 }
257 else
258 {
259 $render_toolbar = true;
260 }
261
262
263
264 $render_toolbar = $this->input->getBool('render_toolbar', $render_toolbar);
265
266 if (!$render_toolbar)
267 {
268 return;
269 }
270
271
272
273 if (empty($view))
274 {
275 $view = $this->input->getCmd('view', 'cpanel');
276 }
277
278 if (empty($task))
279 {
280 $task = $this->input->getCmd('task', 'default');
281 }
282
283 $this->view = $view;
284 $this->task = $task;
285 $view = FOFInflector::pluralize($view);
286 $component = $this->input->get('option', 'com_foobar', 'cmd');
287
288 $configProvider = new FOFConfigProvider;
289 $toolbar = $configProvider->get(
290 $component . '.views.' . $view . '.toolbar.' . $task
291 );
292
293
294 if (!empty($toolbar))
295 {
296 return $this->renderFromConfig($toolbar);
297 }
298
299
300 $methodName = 'on' . ucfirst($view) . ucfirst($task);
301
302 if (method_exists($this, $methodName))
303 {
304 return $this->$methodName();
305 }
306
307
308 $methodName = 'on' . ucfirst($view);
309
310 if (method_exists($this, $methodName))
311 {
312 return $this->$methodName();
313 }
314
315
316 $methodName = 'on' . ucfirst($task);
317
318 if (method_exists($this, $methodName))
319 {
320 return $this->$methodName();
321 }
322
323 if (!empty($input))
324 {
325 $this->input = $saveInput;
326 }
327 }
328
329 330 331 332 333
334 public function onCpanelsBrowse()
335 {
336 if (FOFPlatform::getInstance()->isBackend() || $this->renderFrontendSubmenu)
337 {
338 $this->renderSubmenu();
339 }
340
341 if (!FOFPlatform::getInstance()->isBackend() && !$this->renderFrontendButtons)
342 {
343 return;
344 }
345
346 $option = $this->input->getCmd('option', 'com_foobar');
347
348 JToolbarHelper::title(JText::_(strtoupper($option)), str_replace('com_', '', $option));
349 JToolbarHelper::preferences($option, 550, 875);
350 }
351
352 353 354 355 356
357 public function onBrowse()
358 {
359
360 if (FOFPlatform::getInstance()->isBackend() || $this->renderFrontendSubmenu)
361 {
362 $this->renderSubmenu();
363 }
364
365 if (!FOFPlatform::getInstance()->isBackend() && !$this->renderFrontendButtons)
366 {
367 return;
368 }
369
370
371 $option = $this->input->getCmd('option', 'com_foobar');
372 $subtitle_key = strtoupper($option . '_TITLE_' . $this->input->getCmd('view', 'cpanel'));
373 JToolbarHelper::title(JText::_(strtoupper($option)) . ': ' . JText::_($subtitle_key), str_replace('com_', '', $option));
374
375
376 if ($this->perms->create)
377 {
378 if (version_compare(JVERSION, '3.0', 'ge'))
379 {
380 JToolbarHelper::addNew();
381 }
382 else
383 {
384 JToolbarHelper::addNewX();
385 }
386 }
387
388 if ($this->perms->edit)
389 {
390 if (version_compare(JVERSION, '3.0', 'ge'))
391 {
392 JToolbarHelper::editList();
393 }
394 else
395 {
396 JToolbarHelper::editListX();
397 }
398 }
399
400 if ($this->perms->create || $this->perms->edit)
401 {
402 JToolbarHelper::divider();
403 }
404
405 if ($this->perms->editstate)
406 {
407 JToolbarHelper::publishList();
408 JToolbarHelper::unpublishList();
409 JToolbarHelper::divider();
410 }
411
412 if ($this->perms->delete)
413 {
414 $msg = JText::_($this->input->getCmd('option', 'com_foobar') . '_CONFIRM_DELETE');
415 JToolbarHelper::deleteList(strtoupper($msg));
416 }
417 }
418
419 420 421 422 423
424 public function onRead()
425 {
426
427 if (FOFPlatform::getInstance()->isBackend() || $this->renderFrontendSubmenu)
428 {
429 $this->renderSubmenu();
430 }
431
432 if (!FOFPlatform::getInstance()->isBackend() && !$this->renderFrontendButtons)
433 {
434 return;
435 }
436
437 $option = $this->input->getCmd('option', 'com_foobar');
438 $componentName = str_replace('com_', '', $option);
439
440
441 $subtitle_key = strtoupper($option . '_TITLE_' . $this->input->getCmd('view', 'cpanel') . '_READ');
442 JToolbarHelper::title(JText::_(strtoupper($option)) . ': ' . JText::_($subtitle_key), $componentName);
443
444
445 JToolbarHelper::back();
446 }
447
448 449 450 451 452
453 public function onAdd()
454 {
455
456 if (!FOFPlatform::getInstance()->isBackend() && !$this->renderFrontendButtons)
457 {
458 return;
459 }
460
461 $option = $this->input->getCmd('option', 'com_foobar');
462 $componentName = str_replace('com_', '', $option);
463
464
465 $subtitle_key = strtoupper($option . '_TITLE_' . FOFInflector::pluralize($this->input->getCmd('view', 'cpanel'))) . '_EDIT';
466 JToolbarHelper::title(JText::_(strtoupper($option)) . ': ' . JText::_($subtitle_key), $componentName);
467
468
469 if ($this->perms->edit || $this->perms->editown)
470 {
471
472
473 JToolbarHelper::apply();
474 }
475
476 JToolbarHelper::save();
477
478 if ($this->perms->create)
479 {
480 JToolbarHelper::custom('savenew', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AND_NEW', false);
481 }
482
483 JToolbarHelper::cancel();
484 }
485
486 487 488 489 490
491 public function onEdit()
492 {
493
494 if (!FOFPlatform::getInstance()->isBackend() && !$this->renderFrontendButtons)
495 {
496 return;
497 }
498
499 $this->onAdd();
500 }
501
502 503 504 505 506
507 public function clearLinks()
508 {
509 $this->linkbar = array();
510 }
511
512 513 514 515 516
517 public function &getLinks()
518 {
519 return $this->linkbar;
520 }
521
522 523 524 525 526 527 528 529 530 531 532
533 public function appendLink($name, $link = null, $active = false, $icon = null, $parent = '')
534 {
535 $linkDefinition = array(
536 'name' => $name,
537 'link' => $link,
538 'active' => $active,
539 'icon' => $icon
540 );
541
542 if (empty($parent))
543 {
544 if(array_key_exists($name, $this->linkbar))
545 {
546 $this->linkbar[$name] = array_merge($this->linkbar[$name], $linkDefinition);
547
548
549 if(array_key_exists('items', $this->linkbar[$name]))
550 {
551 array_unshift($this->linkbar[$name]['items'], $linkDefinition);
552 }
553 }
554 else
555 {
556 $this->linkbar[$name] = $linkDefinition;
557 }
558 }
559 else
560 {
561 if (!array_key_exists($parent, $this->linkbar))
562 {
563 $parentElement = $linkDefinition;
564 $parentElement['name'] = $parent;
565 $parentElement['link'] = null;
566 $this->linkbar[$parent] = $parentElement;
567 $parentElement['items'] = array();
568 }
569 else
570 {
571 $parentElement = $this->linkbar[$parent];
572
573 if (!array_key_exists('dropdown', $parentElement) && !empty($parentElement['link']))
574 {
575 $newSubElement = $parentElement;
576 $parentElement['items'] = array($newSubElement);
577 }
578 }
579
580 $parentElement['items'][] = $linkDefinition;
581 $parentElement['dropdown'] = true;
582
583 if($active)
584 {
585 $parentElement['active'] = true;
586 }
587
588 $this->linkbar[$parent] = $parentElement;
589 }
590 }
591
592 593 594 595 596 597 598 599 600 601
602 public function prefixLink($name, $link = null, $active = false, $icon = null)
603 {
604 $linkDefinition = array(
605 'name' => $name,
606 'link' => $link,
607 'active' => $active,
608 'icon' => $icon
609 );
610 array_unshift($this->linkbar, $linkDefinition);
611 }
612
613 614 615 616 617
618 public function ()
619 {
620 $views = $this->getMyViews();
621
622 if (empty($views))
623 {
624 return;
625 }
626
627 $activeView = $this->input->getCmd('view', 'cpanel');
628
629 foreach ($views as $view)
630 {
631
632 $key = strtoupper($this->component) . '_TITLE_' . strtoupper($view);
633
634
635 if (strtoupper(JText::_($key)) == $key)
636 {
637 $altview = FOFInflector::isPlural($view) ? FOFInflector::singularize($view) : FOFInflector::pluralize($view);
638 $key2 = strtoupper($this->component) . '_TITLE_' . strtoupper($altview);
639
640
641 if (strtoupper(JText::_($key2)) == $key2)
642 {
643
644 $name = ucfirst($view);
645 }
646 else
647 {
648 $name = JText::_($key2);
649 }
650 }
651 else
652 {
653 $name = JText::_($key);
654 }
655
656 $link = 'index.php?option=' . $this->component . '&view=' . $view;
657
658 $active = $view == $activeView;
659
660 $this->appendLink($name, $link, $active);
661 }
662 }
663
664 665 666 667 668
669 protected function getMyViews()
670 {
671 $views = array();
672 $t_views = array();
673 $using_meta = false;
674
675 $componentPaths = FOFPlatform::getInstance()->getComponentBaseDirs($this->component);
676 $searchPath = $componentPaths['main'] . '/views';
677 $filesystem = FOFPlatform::getInstance()->getIntegrationObject('filesystem');
678
679 $allFolders = $filesystem->folderFolders($searchPath);
680
681 if (!empty($allFolders))
682 {
683 foreach ($allFolders as $folder)
684 {
685 $view = $folder;
686
687
688 if (in_array(FOFInflector::pluralize($view), $t_views))
689 {
690 continue;
691 }
692
693
694 $files = $filesystem->folderFiles($searchPath . '/' . $view, '^skip\.xml$');
695
696 if (!empty($files))
697 {
698 continue;
699 }
700
701
702 $meta = $filesystem->folderFiles($searchPath . '/' . $view, '^metadata\.xml$');
703
704
705 if (!$meta)
706 {
707 $plural = FOFInflector::pluralize($view);
708
709 if (in_array($plural, $allFolders))
710 {
711 $view = $plural;
712 $meta = $filesystem->folderFiles($searchPath . '/' . $view, '^metadata\.xml$');
713 }
714 }
715
716 if (!empty($meta))
717 {
718 $using_meta = true;
719 $xml = simplexml_load_file($searchPath . '/' . $view . '/' . $meta[0]);
720 $order = (int) $xml->foflib->ordering;
721 }
722 else
723 {
724
725
726 if (!isset($to_order))
727 {
728 $to_order = array();
729 }
730
731 $order = count($to_order);
732 }
733
734 $view = FOFInflector::pluralize($view);
735
736 $t_view = new stdClass;
737 $t_view->ordering = $order;
738 $t_view->view = $view;
739
740 $to_order[] = $t_view;
741 $t_views[] = $view;
742 }
743 }
744
745 FOFUtilsArray::sortObjects($to_order, 'ordering');
746 $views = FOFUtilsArray::getColumn($to_order, 'view');
747
748
749 if (!$using_meta)
750 {
751 $cpanel = array_search('cpanels', $views);
752
753 if ($cpanel !== false)
754 {
755 unset($views[$cpanel]);
756 array_unshift($views, 'cpanels');
757 }
758 }
759
760 return $views;
761 }
762
763 764 765 766 767
768 public function getRenderFrontendButtons()
769 {
770 return $this->renderFrontendButtons;
771 }
772
773 774 775 776 777
778 public function ()
779 {
780 return $this->renderFrontendSubmenu;
781 }
782
783 784 785 786 787 788 789
790 private function renderFromConfig(array $toolbar)
791 {
792 if (FOFPlatform::getInstance()->isBackend() || $this->renderFrontendSubmenu)
793 {
794 $this->renderSubmenu();
795 }
796
797 if (!FOFPlatform::getInstance()->isBackend() && !$this->renderFrontendButtons)
798 {
799 return;
800 }
801
802
803 foreach ($toolbar as $elementType => $elementAttributes)
804 {
805 $value = isset($elementAttributes['value']) ? $elementAttributes['value'] : null;
806 $this->renderToolbarElement($elementType, $value, $elementAttributes);
807 }
808
809 return;
810 }
811
812 813 814 815 816 817 818 819 820 821 822 823
824 private function renderToolbarElement($type, $value = null, array $attributes = array())
825 {
826 switch ($type)
827 {
828 case 'title':
829 $icon = isset($attributes['icon']) ? $attributes['icon'] : 'generic.png';
830 JToolbarHelper::title($value, $icon);
831 break;
832
833 case 'divider':
834 JToolbarHelper::divider();
835 break;
836
837 case 'custom':
838 $task = isset($attributes['task']) ? $attributes['task'] : '';
839 $icon = isset($attributes['icon']) ? $attributes['icon'] : '';
840 $iconOver = isset($attributes['icon_over']) ? $attributes['icon_over'] : '';
841 $alt = isset($attributes['alt']) ? $attributes['alt'] : '';
842 $listSelect = isset($attributes['list_select']) ?
843 FOFStringUtils::toBool($attributes['list_select']) : true;
844
845 JToolbarHelper::custom($task, $icon, $iconOver, $alt, $listSelect);
846 break;
847
848 case 'preview':
849 $url = isset($attributes['url']) ? $attributes['url'] : '';
850 $update_editors = isset($attributes['update_editors']) ?
851 FOFStringUtils::toBool($attributes['update_editors']) : false;
852
853 JToolbarHelper::preview($url, $update_editors);
854 break;
855
856 case 'help':
857 if (!isset($attributes['help']))
858 {
859 throw new InvalidArgumentException(
860 'The help attribute is missing in the help button type.'
861 );
862 }
863
864 $ref = $attributes['help'];
865 $com = isset($attributes['com']) ? FOFStringUtils::toBool($attributes['com']) : false;
866 $override = isset($attributes['override']) ? $attributes['override'] : null;
867 $component = isset($attributes['component']) ? $attributes['component'] : null;
868
869 JToolbarHelper::help($ref, $com, $override, $component);
870 break;
871
872 case 'back':
873 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_BACK';
874 $href = isset($attributes['href']) ? $attributes['href'] : 'javascript:history.back();';
875
876 JToolbarHelper::back($alt, $href);
877 break;
878
879 case 'media_manager':
880 $directory = isset($attributes['directory']) ? $attributes['directory'] : '';
881 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_UPLOAD';
882
883 JToolbarHelper::media_manager($directory, $alt);
884 break;
885
886 case 'assign':
887 $task = isset($attributes['task']) ? $attributes['task'] : 'assign';
888 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_ASSIGN';
889
890 JToolbarHelper::assign($task, $alt);
891 break;
892
893 case 'new':
894 if ($this->perms->create)
895 {
896 $task = isset($attributes['task']) ? $attributes['task'] : 'add';
897 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_NEW';
898 $check = isset($attributes['check']) ?
899 FOFStringUtils::toBool($attributes['check']) : false;
900
901 JToolbarHelper::addNew($task, $alt, $check);
902 }
903
904 break;
905
906 case 'publish':
907 if ($this->perms->editstate)
908 {
909 $task = isset($attributes['task']) ? $attributes['task'] : 'publish';
910 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_PUBLISH';
911 $check = isset($attributes['check']) ?
912 FOFStringUtils::toBool($attributes['check']) : false;
913
914 JToolbarHelper::publish($task, $alt, $check);
915 }
916
917 break;
918
919 case 'publishList':
920 if ($this->perms->editstate)
921 {
922 $task = isset($attributes['task']) ? $attributes['task'] : 'publish';
923 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_PUBLISH';
924
925 JToolbarHelper::publishList($task, $alt);
926 }
927
928 break;
929
930 case 'unpublish':
931 if ($this->perms->editstate)
932 {
933 $task = isset($attributes['task']) ? $attributes['task'] : 'unpublish';
934 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_UNPUBLISH';
935 $check = isset($attributes['check']) ?
936 FOFStringUtils::toBool($attributes['check']) : false;
937
938 JToolbarHelper::unpublish($task, $alt, $check);
939 }
940
941 break;
942
943 case 'unpublishList':
944 if ($this->perms->editstate)
945 {
946 $task = isset($attributes['task']) ? $attributes['task'] : 'unpublish';
947 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_UNPUBLISH';
948
949 JToolbarHelper::unpublishList($task, $alt);
950 }
951
952 break;
953
954 case 'archiveList':
955 if ($this->perms->editstate)
956 {
957 $task = isset($attributes['task']) ? $attributes['task'] : 'archive';
958 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_ARCHIVE';
959
960 JToolbarHelper::archiveList($task, $alt);
961 }
962
963 break;
964
965 case 'unarchiveList':
966 if ($this->perms->editstate)
967 {
968 $task = isset($attributes['task']) ? $attributes['task'] : 'unarchive';
969 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_UNARCHIVE';
970
971 JToolbarHelper::unarchiveList($task, $alt);
972 }
973
974 break;
975
976 case 'editList':
977 if ($this->perms->edit)
978 {
979 $task = isset($attributes['task']) ? $attributes['task'] : 'edit';
980 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_EDIT';
981
982 JToolbarHelper::editList($task, $alt);
983 }
984
985 break;
986
987 case 'editHtml':
988 $task = isset($attributes['task']) ? $attributes['task'] : 'edit_source';
989 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_EDIT_HTML';
990
991 JToolbarHelper::editHtml($task, $alt);
992 break;
993
994 case 'editCss':
995 $task = isset($attributes['task']) ? $attributes['task'] : 'edit_css';
996 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_EDIT_CSS';
997
998 JToolbarHelper::editCss($task, $alt);
999 break;
1000
1001 case 'deleteList':
1002 if ($this->perms->delete)
1003 {
1004 $msg = isset($attributes['msg']) ? $attributes['msg'] : '';
1005 $task = isset($attributes['task']) ? $attributes['task'] : 'remove';
1006 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_DELETE';
1007
1008 JToolbarHelper::deleteList($msg, $task, $alt);
1009 }
1010
1011 break;
1012
1013 case 'trash':
1014 if ($this->perms->editstate)
1015 {
1016 $task = isset($attributes['task']) ? $attributes['task'] : 'remove';
1017 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_TRASH';
1018 $check = isset($attributes['check']) ?
1019 FOFStringUtils::toBool($attributes['check']) : true;
1020
1021 JToolbarHelper::trash($task, $alt, $check);
1022 }
1023
1024 break;
1025
1026 case 'apply':
1027 $task = isset($attributes['task']) ? $attributes['task'] : 'apply';
1028 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_APPLY';
1029
1030 JToolbarHelper::apply($task, $alt);
1031 break;
1032
1033 case 'save':
1034 $task = isset($attributes['task']) ? $attributes['task'] : 'save';
1035 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_SAVE';
1036
1037 JToolbarHelper::save($task, $alt);
1038 break;
1039
1040 case 'save2new':
1041 $task = isset($attributes['task']) ? $attributes['task'] : 'save2new';
1042 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_SAVE_AND_NEW';
1043
1044 JToolbarHelper::save2new($task, $alt);
1045 break;
1046
1047 case 'save2copy':
1048 $task = isset($attributes['task']) ? $attributes['task'] : 'save2copy';
1049 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_SAVE_AS_COPY';
1050 JToolbarHelper::save2copy($task, $alt);
1051 break;
1052
1053 case 'checkin':
1054 $task = isset($attributes['task']) ? $attributes['task'] : 'checkin';
1055 $alt = isset($attributes['alt']) ? $attributes['alt'] :'JTOOLBAR_CHECKIN';
1056 $check = isset($attributes['check']) ?
1057 FOFStringUtils::toBool($attributes['check']) : true;
1058
1059 JToolbarHelper::checkin($task, $alt, $check);
1060 break;
1061
1062 case 'cancel':
1063 $task = isset($attributes['task']) ? $attributes['task'] : 'cancel';
1064 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_CANCEL';
1065
1066 JToolbarHelper::cancel($task, $alt);
1067 break;
1068
1069 case 'preferences':
1070 if (!isset($attributes['component']))
1071 {
1072 throw new InvalidArgumentException(
1073 'The component attribute is missing in the preferences button type.'
1074 );
1075 }
1076
1077 $component = $attributes['component'];
1078 $height = isset($attributes['height']) ? $attributes['height'] : '550';
1079 $width = isset($attributes['width']) ? $attributes['width'] : '875';
1080 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JToolbar_Options';
1081 $path = isset($attributes['path']) ? $attributes['path'] : '';
1082
1083 JToolbarHelper::preferences($component, $height, $width, $alt, $path);
1084 break;
1085
1086 default:
1087 throw new InvalidArgumentException(sprintf('Unknown button type %s', $type));
1088 }
1089 }
1090 }
1091