1 <?php
2 3 4 5 6 7
8 defined('FOF_INCLUDED') or die;
9
10 11 12 13 14 15
16 class FOFRenderJoomla extends FOFRenderAbstract
17 {
18 19 20
21 public function __construct()
22 {
23 $this->priority = 50;
24 $this->enabled = true;
25 }
26
27 28 29 30 31 32 33 34 35 36
37 public function preRender($view, $task, $input, $config = array())
38 {
39 $format = $input->getCmd('format', 'html');
40
41 if (empty($format))
42 {
43 $format = 'html';
44 }
45
46 if ($format != 'html')
47 {
48 return;
49 }
50
51 $platform = FOFPlatform::getInstance();
52
53 if ($platform->isCli())
54 {
55 return;
56 }
57
58 if (version_compare(JVERSION, '3.0.0', 'lt'))
59 {
60 JHtml::_('behavior.framework');
61 }
62 else
63 {
64 if (version_compare(JVERSION, '3.3.0', 'ge'))
65 {
66 JHtml::_('behavior.core');
67 }
68 else
69 {
70 JHtml::_('behavior.framework', true);
71 }
72
73 JHtml::_('jquery.framework');
74 }
75
76
77 $version = new JVersion;
78 $versionParts = explode('.', $version->RELEASE);
79 $minorVersion = str_replace('.', '', $version->RELEASE);
80 $majorVersion = array_shift($versionParts);
81
82 if ($platform->isBackend())
83 {
84 $area = $platform->isBackend() ? 'admin' : 'site';
85 $option = $input->getCmd('option', '');
86 $view = $input->getCmd('view', '');
87 $layout = $input->getCmd('layout', '');
88 $task = $input->getCmd('task', '');
89
90 $classes = array(
91 'joomla-version-' . $majorVersion,
92 'joomla-version-' . $minorVersion,
93 $area,
94 $option,
95 'view-' . $view,
96 'layout-' . $layout,
97 'task-' . $task,
98 );
99 }
100 elseif ($platform->isFrontend())
101 {
102
103 $classes = array(
104 'joomla-version-' . $majorVersion,
105 'joomla-version-' . $minorVersion,
106 );
107 }
108
109 echo '<div id="akeeba-renderjoomla" class="' . implode($classes, ' ') . "\">\n";
110
111
112 if ($input->getBool('render_toolbar', true))
113 {
114 $this->renderButtons($view, $task, $input, $config);
115 $this->renderLinkbar($view, $task, $input, $config);
116 }
117 }
118
119 120 121 122 123 124 125 126 127 128
129 public function postRender($view, $task, $input, $config = array())
130 {
131 $format = $input->getCmd('format', 'html');
132
133 if (empty($format))
134 {
135 $format = 'html';
136 }
137
138 if ($format != 'html')
139 {
140 return;
141 }
142
143
144 if (FOFPlatform::getInstance()->isCli())
145 {
146 return;
147 }
148
149 echo "</div>\n";
150 }
151
152 153 154 155 156 157 158 159 160
161 protected function renderFormBrowse(FOFForm &$form, FOFModel $model, FOFInput $input)
162 {
163 JHtml::_('behavior.multiselect');
164
165
166 $headerFields = $form->getHeaderset();
167
168
169 $html = '';
170 $filter_order = $form->getView()->getLists()->order;
171 $filter_order_Dir = $form->getView()->getLists()->order_Dir;
172 $actionUrl = FOFPlatform::getInstance()->isBackend() ? 'index.php' : JUri::root().'index.php';
173
174 if (FOFPlatform::getInstance()->isFrontend() && ($input->getCmd('Itemid', 0) != 0))
175 {
176 $itemid = $input->getCmd('Itemid', 0);
177 $uri = new JUri($actionUrl);
178
179 if ($itemid)
180 {
181 $uri->setVar('Itemid', $itemid);
182 }
183
184 $actionUrl = JRoute::_($uri->toString());
185 }
186
187 $html .= '<form action="'.$actionUrl.'" method="post" name="adminForm" id="adminForm">' . PHP_EOL;
188 $html .= "\t" . '<input type="hidden" name="option" value="' . $input->getCmd('option') . '" />' . PHP_EOL;
189 $html .= "\t" . '<input type="hidden" name="view" value="' . FOFInflector::pluralize($input->getCmd('view')) . '" />' . PHP_EOL;
190 $html .= "\t" . '<input type="hidden" name="task" value="" />' . PHP_EOL;
191 $html .= "\t" . '<input type="hidden" name="layout" value="' . $input->getCmd('layout', '') . '" />' . PHP_EOL;
192 $html .= "\t" . '<input type="hidden" name="boxchecked" value="" />' . PHP_EOL;
193 $html .= "\t" . '<input type="hidden" name="hidemainmenu" value="" />' . PHP_EOL;
194 $html .= "\t" . '<input type="hidden" name="filter_order" value="' . $filter_order . '" />' . PHP_EOL;
195 $html .= "\t" . '<input type="hidden" name="filter_order_Dir" value="' . $filter_order_Dir . '" />' . PHP_EOL;
196
197 $html .= "\t" . '<input type="hidden" name="' . JFactory::getSession()->getFormToken() . '" value="1" />' . PHP_EOL;
198
199
200 $html .= "\t\t" . '<table class="adminlist" id="adminList">' . PHP_EOL;
201
202
203 $show_header = $form->getAttribute('show_header', 1);
204 $show_filters = $form->getAttribute('show_filters', 1);
205 $show_pagination = $form->getAttribute('show_pagination', 1);
206 $norows_placeholder = $form->getAttribute('norows_placeholder', '');
207
208
209 if ($show_header || $show_filters)
210 {
211 $html .= "\t\t\t<thead>" . PHP_EOL;
212 }
213
214
215 if ($show_header || $show_filters)
216 {
217 $header_html = '';
218 $filter_html = '';
219
220 foreach ($headerFields as $header)
221 {
222
223
224 $tmpHeader = $header->header;
225
226 if (empty($tmpHeader))
227 {
228 continue;
229 }
230
231 $tdwidth = $header->tdwidth;
232
233 if (!empty($tdwidth))
234 {
235 $tdwidth = 'width="' . $tdwidth . '"';
236 }
237 else
238 {
239 $tdwidth = '';
240 }
241
242 $header_html .= "\t\t\t\t\t<th $tdwidth>" . PHP_EOL;
243 $header_html .= "\t\t\t\t\t\t" . $tmpHeader;
244 $header_html .= "\t\t\t\t\t</th>" . PHP_EOL;
245
246 $filter = $header->filter;
247 $buttons = $header->buttons;
248 $options = $header->options;
249
250 $filter_html .= "\t\t\t\t\t<td>" . PHP_EOL;
251
252 if (!empty($filter))
253 {
254 $filter_html .= "\t\t\t\t\t\t$filter" . PHP_EOL;
255
256 if (!empty($buttons))
257 {
258 $filter_html .= "\t\t\t\t\t\t<nobr>$buttons</nobr>" . PHP_EOL;
259 }
260 }
261 elseif (!empty($options))
262 {
263 $label = $header->label;
264 $emptyOption = JHtml::_('select.option', '', '- ' . JText::_($label) . ' -');
265 array_unshift($options, $emptyOption);
266 $attribs = array(
267 'onchange' => 'document.adminForm.submit();'
268 );
269 $filter = JHtml::_('select.genericlist', $options, $header->name, $attribs, 'value', 'text', $header->value, false, true);
270 $filter_html .= "\t\t\t\t\t\t$filter" . PHP_EOL;
271 }
272
273 $filter_html .= "\t\t\t\t\t</td>" . PHP_EOL;
274 }
275 }
276
277
278 if ($show_header)
279 {
280 $html .= "\t\t\t\t<tr>" . PHP_EOL;
281 $html .= $header_html;
282 $html .= "\t\t\t\t</tr>" . PHP_EOL;
283 }
284
285
286 if ($show_filters)
287 {
288 $html .= "\t\t\t\t<tr>";
289 $html .= $filter_html;
290 $html .= "\t\t\t\t</tr>";
291 }
292
293
294 if ($show_header || $show_filters)
295 {
296 $html .= "\t\t\t</thead>" . PHP_EOL;
297 }
298
299
300 $html .= "\t\t\t<tbody>" . PHP_EOL;
301 $fields = $form->getFieldset('items');
302 $num_columns = count($fields);
303 $items = $form->getModel()->getItemList();
304
305 if ($count = count($items))
306 {
307 $m = 1;
308
309 foreach ($items as $i => $item)
310 {
311 $table_item = $form->getModel()->getTable();
312 $table_item->reset();
313 $table_item->bind($item);
314
315 $form->bind($item);
316
317 $m = 1 - $m;
318 $class = 'row' . $m;
319
320 $html .= "\t\t\t\t<tr class=\"$class\">" . PHP_EOL;
321
322 $fields = $form->getFieldset('items');
323
324 foreach ($fields as $field)
325 {
326 $field->rowid = $i;
327 $field->item = $table_item;
328 $labelClass = $field->labelClass ? $field->labelClass : $field->labelclass;
329 $class = $labelClass ? 'class ="' . $labelClass . '"' : '';
330 $html .= "\t\t\t\t\t<td $class>" . $field->getRepeatable() . '</td>' . PHP_EOL;
331 }
332
333 $html .= "\t\t\t\t</tr>" . PHP_EOL;
334 }
335 }
336 elseif ($norows_placeholder)
337 {
338 $html .= "\t\t\t\t<tr><td colspan=\"$num_columns\">";
339 $html .= JText::_($norows_placeholder);
340 $html .= "</td></tr>\n";
341 }
342
343 $html .= "\t\t\t</tbody>" . PHP_EOL;
344
345
346
347 if ($show_pagination)
348 {
349 $pagination = $form->getModel()->getPagination();
350 $html .= "\t\t\t<tfoot>" . PHP_EOL;
351 $html .= "\t\t\t\t<tr><td colspan=\"$num_columns\">";
352
353 if (($pagination->total > 0))
354 {
355 $html .= $pagination->getListFooter();
356 }
357
358 $html .= "</td></tr>\n";
359 $html .= "\t\t\t</tfoot>" . PHP_EOL;
360 }
361
362
363 $html .= "\t\t" . '</table>' . PHP_EOL;
364
365
366 $html .= '</form>' . PHP_EOL;
367
368 return $html;
369 }
370
371 372 373 374 375 376 377 378 379
380 protected function renderFormRead(FOFForm &$form, FOFModel $model, FOFInput $input)
381 {
382 $html = $this->renderFormRaw($form, $model, $input, 'read');
383
384 return $html;
385 }
386
387 388 389 390 391 392 393 394 395
396 protected function renderFormEdit(FOFForm &$form, FOFModel $model, FOFInput $input)
397 {
398
399 $key = $model->getTable()->getKeyName();
400 $keyValue = $model->getId();
401
402 JHTML::_('behavior.tooltip');
403
404 $html = '';
405
406 $validate = strtolower($form->getAttribute('validate'));
407 $class = '';
408
409 if (in_array($validate, array('true', 'yes', '1', 'on')))
410 {
411 JHtml::_('behavior.formvalidation');
412 $class = 'form-validate ';
413 $this->loadValidationScript($form);
414 }
415
416
417 $template_form_enctype = $form->getAttribute('enctype');
418
419 if (!empty($template_form_enctype))
420 {
421 $enctype = ' enctype="' . $form->getAttribute('enctype') . '" ';
422 }
423 else
424 {
425 $enctype = '';
426 }
427
428
429 $formname = $form->getAttribute('name');
430
431 if (empty($formname))
432 {
433 $formname = 'adminForm';
434 }
435
436
437 $formid = $form->getAttribute('name');
438
439 if (empty($formid))
440 {
441 $formid = 'adminForm';
442 }
443
444
445 $customTask = $form->getAttribute('customTask');
446
447 if (empty($customTask))
448 {
449 $customTask = '';
450 }
451
452
453 $actionUrl = FOFPlatform::getInstance()->isBackend() ? 'index.php' : JUri::root().'index.php';
454
455 if (FOFPlatform::getInstance()->isFrontend() && ($input->getCmd('Itemid', 0) != 0))
456 {
457 $itemid = $input->getCmd('Itemid', 0);
458 $uri = new JUri($actionUrl);
459
460 if ($itemid)
461 {
462 $uri->setVar('Itemid', $itemid);
463 }
464
465 $actionUrl = JRoute::_($uri->toString());
466 }
467
468 $html .= '<form action="'.$actionUrl.'" method="post" name="' . $formname .
469 '" id="' . $formid . '"' . $enctype . ' class="' . $class .
470 '">' . PHP_EOL;
471 $html .= "\t" . '<input type="hidden" name="option" value="' . $input->getCmd('option') . '" />' . PHP_EOL;
472 $html .= "\t" . '<input type="hidden" name="view" value="' . $input->getCmd('view', 'edit') . '" />' . PHP_EOL;
473 $html .= "\t" . '<input type="hidden" name="task" value="' . $customTask . '" />' . PHP_EOL;
474 $html .= "\t" . '<input type="hidden" name="' . $key . '" value="' . $keyValue . '" />' . PHP_EOL;
475
476 $html .= "\t" . '<input type="hidden" name="' . JFactory::getSession()->getFormToken() . '" value="1" />' . PHP_EOL;
477
478 $html .= $this->renderFormRaw($form, $model, $input, 'edit');
479 $html .= '</form>';
480
481 return $html;
482 }
483
484 485 486 487 488 489 490 491 492 493
494 protected function renderFormRaw(FOFForm &$form, FOFModel $model, FOFInput $input, $formType)
495 {
496 $html = '';
497
498 foreach ($form->getFieldsets() as $fieldset)
499 {
500 $html .= $this->renderFieldset($fieldset, $form, $model, $input, $formType, false);
501 }
502
503 return $html;
504 }
505
506 507 508 509 510 511 512 513 514 515 516 517
518 protected function renderFieldset(stdClass &$fieldset, FOFForm &$form, FOFModel $model, FOFInput $input, $formType, $showHeader = true)
519 {
520 $html = '';
521
522 $fields = $form->getFieldset($fieldset->name);
523
524 if (isset($fieldset->class))
525 {
526 $class = 'class="' . $fieldset->class . '"';
527 }
528 else
529 {
530 $class = '';
531 }
532
533 $element = empty($fields) ? 'div' : 'fieldset';
534 $html .= "\t" . '<' . $element . ' id="' . $fieldset->name . '" ' . $class . '>' . PHP_EOL;
535
536 $isTabbedFieldset = $this->isTabFieldset($fieldset);
537
538 if (isset($fieldset->label) && !empty($fieldset->label) && !$isTabbedFieldset)
539 {
540 $html .= "\t\t" . '<h3>' . JText::_($fieldset->label) . '</h3>' . PHP_EOL;
541 }
542
543 foreach ($fields as $field)
544 {
545 $groupClass = $form->getFieldAttribute($field->fieldname, 'groupclass', '', $field->group);
546
547
548
549 $title = $form->getFieldAttribute($field->fieldname, 'label', '', $field->group);
550 $emptylabel = $form->getFieldAttribute($field->fieldname, 'emptylabel', false, $field->group);
551
552 if (empty($title) && !$emptylabel)
553 {
554 $model->getName();
555 $title = strtoupper($input->get('option') . '_' . $model->getName() . '_' . $field->id . '_LABEL');
556 }
557
558
559 $description = $form->getFieldAttribute($field->fieldname, 'description', '', $field->group);
560
561 562 563 564
565 566 567 568 569 570 571
572
573 if ($formType == 'read')
574 {
575 $inputField = $field->static;
576 }
577 elseif ($formType == 'edit')
578 {
579 $inputField = $field->input;
580 }
581
582 if (empty($title))
583 {
584 $html .= "\t\t\t" . $inputField . PHP_EOL;
585
586 if (!empty($description) && $formType == 'edit')
587 {
588 $html .= "\t\t\t\t" . '<span class="help-block">';
589 $html .= JText::_($description) . '</span>' . PHP_EOL;
590 }
591 }
592 else
593 {
594 $html .= "\t\t\t" . '<div class="fof-row ' . $groupClass . '">' . PHP_EOL;
595 $html .= $this->renderFieldsetLabel($field, $form, $title);
596 $html .= "\t\t\t\t" . $inputField . PHP_EOL;
597
598 if (!empty($description))
599 {
600 $html .= "\t\t\t\t" . '<span class="help-block">';
601 $html .= JText::_($description) . '</span>' . PHP_EOL;
602 }
603
604 $html .= "\t\t\t" . '</div>' . PHP_EOL;
605 }
606 }
607
608 $element = empty($fields) ? 'div' : 'fieldset';
609 $html .= "\t" . '</' . $element . '>' . PHP_EOL;
610
611 return $html;
612 }
613
614 615 616 617 618 619 620 621 622
623 protected function renderFieldsetLabel($field, FOFForm &$form, $title)
624 {
625 $html = '';
626
627 $labelClass = $field->labelClass ? $field->labelClass : $field->labelclass;
628 $required = $field->required;
629
630 if ($required)
631 {
632 $labelClass .= ' required';
633 }
634
635 $tooltip = $form->getFieldAttribute($field->fieldname, 'tooltip', '', $field->group);
636
637 if (!empty($tooltip))
638 {
639 JHtml::_('behavior.tooltip');
640
641 $tooltipText = JText::_($title) . '::' . JText::_($tooltip);
642
643 $labelClass .= ' hasTip';
644
645 $html .= "\t\t\t\t" . '<label id="' . $field->id . '-lbl" class="' . $labelClass . '" for="' . $field->id . '" title="' . $tooltipText . '" rel="tooltip">';
646 }
647 else
648 {
649 $html .= "\t\t\t\t" . '<label class="' . $labelClass . '" for="' . $field->id . '">';
650 }
651
652 $html .= JText::_($title);
653
654 if ($required)
655 {
656 $html .= '<span class="star"> *</span>';
657 }
658
659 $html .= "\t\t\t\t" . '</label>' . PHP_EOL;
660
661 return $html;
662 }
663
664 665 666 667 668 669 670
671 protected function loadValidationScript(FOFForm &$form)
672 {
673 $message = $form->getView()->escape(JText::_('JGLOBAL_VALIDATION_FORM_FAILED'));
674
675 $js = <<<JS
676 Joomla.submitbutton = function(task)
677 {
678 if (task == 'cancel' || document.formvalidator.isValid(document.id('adminForm')))
679 {
680 Joomla.submitform(task, document.getElementById('adminForm'));
681 }
682 else {
683 alert('$message');
684 }
685 };
686 JS;
687
688 $document = FOFPlatform::getInstance()->getDocument();
689
690 if ($document instanceof JDocument)
691 {
692 $document->addScriptDeclaration($js);
693 }
694 }
695
696 697 698 699 700 701 702 703 704 705
706 protected function renderLinkbar($view, $task, $input, $config = array())
707 {
708
709
710 if (FOFPlatform::getInstance()->isCli())
711 {
712 return;
713 }
714
715
716 $toolbar = FOFToolbar::getAnInstance($input->getCmd('option', 'com_foobar'), $config);
717 $renderFrontendSubmenu = $toolbar->getRenderFrontendSubmenu();
718
719 if (!FOFPlatform::getInstance()->isBackend() && !$renderFrontendSubmenu)
720 {
721 return;
722 }
723
724 $this->renderLinkbarItems($toolbar);
725 }
726
727 728 729 730 731 732 733
734 protected function renderLinkbarItems($toolbar)
735 {
736 $links = $toolbar->getLinks();
737
738 if (!empty($links))
739 {
740 foreach ($links as $link)
741 {
742 JSubMenuHelper::addEntry($link['name'], $link['link'], $link['active']);
743 }
744 }
745 }
746
747 748 749 750 751 752 753 754 755 756
757 protected function renderButtons($view, $task, $input, $config = array())
758 {
759
760
761 if (FOFPlatform::getInstance()->isCli())
762 {
763 return;
764 }
765
766
767 $toolbar = FOFToolbar::getAnInstance($input->getCmd('option', 'com_foobar'), $config);
768 $renderFrontendButtons = $toolbar->getRenderFrontendButtons();
769
770 if (FOFPlatform::getInstance()->isBackend() || !$renderFrontendButtons)
771 {
772 return;
773 }
774
775
776
777 FOFPlatform::getInstance()->loadTranslations('joomla');
778
779 $title = JFactory::getApplication()->get('JComponentTitle');
780 $bar = JToolbar::getInstance('toolbar');
781
782
783 $bar_content = str_replace('href="#"', '', $bar->render());
784
785 echo '<div id="FOFHeaderHolder">', $bar_content, $title, '<div style="clear:both"></div>', '</div>';
786 }
787 }
788