1 <?php
   2    3    4    5    6    7 
   8 defined('FOF_INCLUDED') or die;
   9 
  10   11   12   13   14   15 
  16 class FOFRenderStrapper extends FOFRenderAbstract
  17 {
  18       19   20 
  21     public function __construct()
  22     {
  23         $this->priority  = 60;
  24         $this->enabled   = class_exists('AkeebaStrapper');
  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                 'j-toggle-main',
 100                 'j-toggle-transition',
 101                 'span12',
 102             );
 103         }
 104         elseif ($platform->isFrontend())
 105         {
 106             
 107             $classes = array(
 108                 'joomla-version-' . $majorVersion,
 109                 'joomla-version-' . $minorVersion,
 110             );
 111         }
 112 
 113         
 114         echo '<div id="akeeba-bootstrap" class="' . implode($classes, ' ') . "\">\n";
 115         echo "<div class=\"akeeba-bootstrap\">\n";
 116         echo "<div class=\"row-fluid\">\n";
 117 
 118         
 119         if ($input->getBool('render_toolbar', true))
 120         {
 121             $this->renderButtons($view, $task, $input, $config);
 122             $this->renderLinkbar($view, $task, $input, $config);
 123         }
 124     }
 125 
 126      127  128  129  130  131  132  133  134  135 
 136     public function postRender($view, $task, $input, $config = array())
 137     {
 138         $format = $input->getCmd('format', 'html');
 139 
 140         if ($format != 'html' || FOFPlatform::getInstance()->isCli())
 141         {
 142             return;
 143         }
 144 
 145         if (!FOFPlatform::getInstance()->isCli() && version_compare(JVERSION, '3.0', 'ge'))
 146         {
 147             $sidebarEntries = JHtmlSidebar::getEntries();
 148 
 149             if (!empty($sidebarEntries))
 150             {
 151                 echo '</div>';
 152             }
 153         }
 154 
 155         echo "</div>\n";    
 156         echo "</div>\n";    
 157         echo "</div>\n";    
 158     }
 159 
 160      161  162  163  164  165  166 
 167     protected function loadValidationScript(FOFForm &$form)
 168     {
 169         $message = $form->getView()->escape(JText::_('JGLOBAL_VALIDATION_FORM_FAILED'));
 170 
 171         $js = <<<JS
 172 Joomla.submitbutton = function(task)
 173 {
 174     if (task == 'cancel' || document.formvalidator.isValid(document.id('adminForm')))
 175     {
 176         Joomla.submitform(task, document.getElementById('adminForm'));
 177     }
 178     else {
 179         alert('$message');
 180     }
 181 };
 182 JS;
 183 
 184         $document = FOFPlatform::getInstance()->getDocument();
 185 
 186         if ($document instanceof JDocument)
 187         {
 188             $document->addScriptDeclaration($js);
 189         }
 190     }
 191 
 192      193  194  195  196  197  198  199  200  201 
 202     protected function renderLinkbar($view, $task, $input, $config = array())
 203     {
 204         $style = 'classic';
 205 
 206         if (array_key_exists('linkbar_style', $config))
 207         {
 208             $style = $config['linkbar_style'];
 209         }
 210 
 211         if (!version_compare(JVERSION, '3.0', 'ge'))
 212         {
 213             $style = 'classic';
 214         }
 215 
 216         switch ($style)
 217         {
 218             case 'joomla':
 219                 $this->renderLinkbar_joomla($view, $task, $input);
 220                 break;
 221 
 222             case 'classic':
 223             default:
 224                 $this->renderLinkbar_classic($view, $task, $input);
 225                 break;
 226         }
 227     }
 228 
 229      230  231  232  233  234  235  236  237  238  239 
 240     protected function renderLinkbar_classic($view, $task, $input, $config = array())
 241     {
 242         if (FOFPlatform::getInstance()->isCli())
 243         {
 244             return;
 245         }
 246 
 247         
 248         $toolbar                 = FOFToolbar::getAnInstance($input->getCmd('option', 'com_foobar'), $config);
 249         $renderFrontendSubmenu   = $toolbar->getRenderFrontendSubmenu();
 250 
 251         if (!FOFPlatform::getInstance()->isBackend() && !$renderFrontendSubmenu)
 252         {
 253             return;
 254         }
 255 
 256         $links = $toolbar->getLinks();
 257 
 258         if (!empty($links))
 259         {
 260             echo "<ul class=\"nav nav-tabs\">\n";
 261 
 262             foreach ($links as $link)
 263             {
 264                 $dropdown = false;
 265 
 266                 if (array_key_exists('dropdown', $link))
 267                 {
 268                     $dropdown = $link['dropdown'];
 269                 }
 270 
 271                 if ($dropdown)
 272                 {
 273                     echo "<li";
 274                     $class = 'dropdown';
 275 
 276                     if ($link['active'])
 277                     {
 278                         $class .= ' active';
 279                     }
 280 
 281                     echo ' class="' . $class . '">';
 282 
 283                     echo '<a class="dropdown-toggle" data-toggle="dropdown" href="#">';
 284 
 285                     if ($link['icon'])
 286                     {
 287                         echo "<i class=\"icon icon-" . $link['icon'] . "\"></i>";
 288                     }
 289 
 290                     echo $link['name'];
 291                     echo '<b class="caret"></b>';
 292                     echo '</a>';
 293 
 294                     echo "\n<ul class=\"dropdown-menu\">";
 295 
 296                     foreach ($link['items'] as $item)
 297                     {
 298                         echo "<li";
 299 
 300                         if ($item['active'])
 301                         {
 302                             echo ' class="active"';
 303                         }
 304 
 305                         echo ">";
 306 
 307                         if ($item['icon'])
 308                         {
 309                             echo "<i class=\"icon icon-" . $item['icon'] . "\"></i>";
 310                         }
 311 
 312                         if ($item['link'])
 313                         {
 314                             echo "<a href=\"" . $item['link'] . "\">" . $item['name'] . "</a>";
 315                         }
 316                         else
 317                         {
 318                             echo $item['name'];
 319                         }
 320 
 321                         echo "</li>";
 322                     }
 323 
 324                     echo "</ul>\n";
 325                 }
 326                 else
 327                 {
 328                     echo "<li";
 329 
 330                     if ($link['active'])
 331                     {
 332                         echo ' class="active"';
 333                     }
 334 
 335                     echo ">";
 336 
 337                     if ($link['icon'])
 338                     {
 339                         echo "<i class=\"icon icon-" . $link['icon'] . "\"></i>";
 340                     }
 341 
 342                     if ($link['link'])
 343                     {
 344                         echo "<a href=\"" . $link['link'] . "\">" . $link['name'] . "</a>";
 345                     }
 346                     else
 347                     {
 348                         echo $link['name'];
 349                     }
 350                 }
 351 
 352                 echo "</li>\n";
 353             }
 354 
 355             echo "</ul>\n";
 356         }
 357     }
 358 
 359      360  361  362  363  364  365  366  367  368  369  370 
 371     protected function renderLinkbar_joomla($view, $task, $input, $config = array())
 372     {
 373         
 374         if (FOFPlatform::getInstance()->isCli())
 375         {
 376             return;
 377         }
 378 
 379         
 380         $toolbar                 = FOFToolbar::getAnInstance($input->getCmd('option', 'com_foobar'), $config);
 381         $renderFrontendSubmenu   = $toolbar->getRenderFrontendSubmenu();
 382 
 383         if (!FOFPlatform::getInstance()->isBackend() && !$renderFrontendSubmenu)
 384         {
 385             return;
 386         }
 387 
 388         $this->renderLinkbarItems($toolbar);
 389     }
 390 
 391      392  393  394  395  396  397 
 398     protected function renderLinkbarItems($toolbar)
 399     {
 400         $links = $toolbar->getLinks();
 401 
 402         if (!empty($links))
 403         {
 404             foreach ($links as $link)
 405             {
 406                 JHtmlSidebar::addEntry($link['name'], $link['link'], $link['active']);
 407 
 408                 $dropdown = false;
 409 
 410                 if (array_key_exists('dropdown', $link))
 411                 {
 412                     $dropdown = $link['dropdown'];
 413                 }
 414 
 415                 if ($dropdown)
 416                 {
 417                     foreach ($link['items'] as $item)
 418                     {
 419                         JHtmlSidebar::addEntry('– ' . $item['name'], $item['link'], $item['active']);
 420                     }
 421                 }
 422             }
 423         }
 424     }
 425 
 426      427  428  429  430  431  432  433  434  435 
 436     protected function renderButtons($view, $task, $input, $config = array())
 437     {
 438         if (FOFPlatform::getInstance()->isCli())
 439         {
 440             return;
 441         }
 442 
 443         
 444         $toolbar                 = FOFToolbar::getAnInstance($input->getCmd('option', 'com_foobar'), $config);
 445         $renderFrontendButtons   = $toolbar->getRenderFrontendButtons();
 446 
 447         
 448         
 449         FOFPlatform::getInstance()->loadTranslations('joomla');
 450 
 451         if (FOFPlatform::getInstance()->isBackend() || !$renderFrontendButtons)
 452         {
 453             return;
 454         }
 455 
 456         $bar     = JToolbar::getInstance('toolbar');
 457         $items   = $bar->getItems();
 458 
 459         $substitutions = array(
 460             'icon-32-new'        => 'icon-plus',
 461             'icon-32-publish'    => 'icon-eye-open',
 462             'icon-32-unpublish'  => 'icon-eye-close',
 463             'icon-32-delete'     => 'icon-trash',
 464             'icon-32-edit'       => 'icon-edit',
 465             'icon-32-copy'       => 'icon-th-large',
 466             'icon-32-cancel'     => 'icon-remove',
 467             'icon-32-back'       => 'icon-circle-arrow-left',
 468             'icon-32-apply'      => 'icon-ok',
 469             'icon-32-save'       => 'icon-hdd',
 470             'icon-32-save-new'   => 'icon-repeat',
 471         );
 472 
 473         if(isset(JFactory::getApplication()->JComponentTitle))
 474         {
 475             $title   = JFactory::getApplication()->JComponentTitle;
 476         }
 477         else
 478         {
 479             $title = '';
 480         }
 481 
 482         $html    = array();
 483         $actions = array();
 484 
 485         
 486         
 487 
 488         $html[]  = '<div class="well" id="FOFHeaderHolder">';
 489         $html[]  =      '<div class="titleHolder">'.$title.'</div>';
 490         $html[]  =      '<div class="buttonsHolder">';
 491 
 492         foreach ($items as $node)
 493         {
 494             $type    = $node[0];
 495             $button  = $bar->loadButtonType($type);
 496 
 497             if ($button !== false)
 498             {
 499                 if (method_exists($button, 'fetchId'))
 500                 {
 501                     $id = call_user_func_array(array(&$button, 'fetchId'), $node);
 502                 }
 503                 else
 504                 {
 505                     $id = null;
 506                 }
 507 
 508                 $action     = call_user_func_array(array(&$button, 'fetchButton'), $node);
 509                 $action     = str_replace('class="toolbar"', 'class="toolbar btn"', $action);
 510                 $action     = str_replace('<span ', '<i ', $action);
 511                 $action     = str_replace('</span>', '</i>', $action);
 512                 $action     = str_replace(array_keys($substitutions), array_values($substitutions), $action);
 513                 $actions[]  = $action;
 514             }
 515         }
 516 
 517         $html   = array_merge($html, $actions);
 518         $html[] = '</div>';
 519         $html[] = '</div>';
 520 
 521         echo implode("\n", $html);
 522     }
 523 
 524      525  526  527  528  529  530  531  532 
 533     protected function renderFormBrowse(FOFForm &$form, FOFModel $model, FOFInput $input)
 534     {
 535         $html = '';
 536 
 537         JHtml::_('behavior.multiselect');
 538 
 539         
 540         if (version_compare(JVERSION, '3.0', 'ge'))
 541         {
 542             JHtml::_('bootstrap.tooltip');
 543             JHtml::_('dropdown.init');
 544             JHtml::_('formbehavior.chosen', 'select');
 545             $view    = $form->getView();
 546             $order   = $view->escape($view->getLists()->order);
 547             $html .= <<<HTML
 548 <script type="text/javascript">
 549     Joomla.orderTable = function() {
 550         table = document.getElementById("sortTable");
 551         direction = document.getElementById("directionTable");
 552         order = table.options[table.selectedIndex].value;
 553         if (order != '$order')
 554         {
 555             dirn = 'asc';
 556         }
 557         else {
 558             dirn = direction.options[direction.selectedIndex].value;
 559         }
 560         Joomla.tableOrdering(order, dirn);
 561     };
 562 </script>
 563 
 564 HTML;
 565         }
 566         else
 567         {
 568             JHtml::_('behavior.tooltip');
 569         }
 570 
 571         
 572         $headerFields = $form->getHeaderset();
 573 
 574         
 575         $show_header         = $form->getAttribute('show_header', 1);
 576         $show_filters        = $form->getAttribute('show_filters', 1);
 577         $show_pagination     = $form->getAttribute('show_pagination', 1);
 578         $norows_placeholder  = $form->getAttribute('norows_placeholder', '');
 579 
 580         
 581 
 582         if (version_compare(JVERSION, '3.0', 'gt'))
 583         {
 584             $form_class = '';
 585 
 586             if ($show_filters)
 587             {
 588                 JHtmlSidebar::setAction("index.php?option=" .
 589                     $input->getCmd('option') . "&view=" .
 590                     FOFInflector::pluralize($input->getCmd('view'))
 591                 );
 592             }
 593 
 594             
 595             $tmpFields = array();
 596             $i = 1;
 597 
 598             foreach ($headerFields as $tmpField)
 599             {
 600                 if ($tmpField instanceof FOFFormHeaderOrdering)
 601                 {
 602                     $tmpFields[0] = $tmpField;
 603                 }
 604 
 605                 else
 606                 {
 607                     $tmpFields[$i] = $tmpField;
 608                 }
 609 
 610                 $i++;
 611             }
 612 
 613             $headerFields = $tmpFields;
 614             ksort($headerFields, SORT_NUMERIC);
 615         }
 616         else
 617         {
 618             $form_class = 'class="form-horizontal"';
 619         }
 620 
 621         
 622         $header_html = '';
 623         $filter_html = '';
 624         $sortFields  = array();
 625 
 626         if ($show_header || $show_filters)
 627         {
 628             foreach ($headerFields as $headerField)
 629             {
 630                 $header      = $headerField->header;
 631                 $filter      = $headerField->filter;
 632                 $buttons     = $headerField->buttons;
 633                 $options     = $headerField->options;
 634                 $sortable    = $headerField->sortable;
 635                 $tdwidth     = $headerField->tdwidth;
 636 
 637                 
 638 
 639                 if (version_compare(JVERSION, '3.0', 'lt') && empty($header))
 640                 {
 641                     continue;
 642                 }
 643 
 644                 
 645 
 646                 if ($sortable)
 647                 {
 648                     $sortFields[$headerField->name] = JText::_($headerField->label);
 649                 }
 650 
 651                 
 652 
 653                 if (!empty($tdwidth))
 654                 {
 655                     $tdwidth = 'width="' . $tdwidth . '"';
 656                 }
 657                 else
 658                 {
 659                     $tdwidth = '';
 660                 }
 661 
 662                 if (!empty($header))
 663                 {
 664                     $header_html .= "\t\t\t\t\t<th $tdwidth>" . PHP_EOL;
 665                     $header_html .= "\t\t\t\t\t\t" . $header;
 666                     $header_html .= "\t\t\t\t\t</th>" . PHP_EOL;
 667                 }
 668 
 669                 if (version_compare(JVERSION, '3.0', 'ge'))
 670                 {
 671                     
 672                     if (!empty($filter))
 673                     {
 674                         $filter_html .= '<div class="filter-search btn-group pull-left">' . "\n";
 675                         $filter_html .= "\t" . '<label for="title" class="element-invisible">';
 676                         $filter_html .= JText::_($headerField->label);
 677                         $filter_html .= "</label>\n";
 678                         $filter_html .= "\t$filter\n";
 679                         $filter_html .= "</div>\n";
 680 
 681                         if (!empty($buttons))
 682                         {
 683                             $filter_html .= '<div class="btn-group pull-left hidden-phone">' . "\n";
 684                             $filter_html .= "\t$buttons\n";
 685                             $filter_html .= '</div>' . "\n";
 686                         }
 687                     }
 688                     elseif (!empty($options))
 689                     {
 690                         $label = $headerField->label;
 691 
 692                         JHtmlSidebar::addFilter(
 693                             '- ' . JText::_($label) . ' -', (string) $headerField->name,
 694                             JHtml::_(
 695                                 'select.options',
 696                                 $options,
 697                                 'value',
 698                                 'text',
 699                                 $model->getState($headerField->name, ''), true
 700                             )
 701                         );
 702                     }
 703                 }
 704                 else
 705                 {
 706                     
 707                     $filter_html .= "\t\t\t\t\t<td>" . PHP_EOL;
 708 
 709                     if (!empty($filter))
 710                     {
 711                         $filter_html .= "\t\t\t\t\t\t$filter" . PHP_EOL;
 712 
 713                         if (!empty($buttons))
 714                         {
 715                             $filter_html .= '<div class="btn-group hidden-phone">' . PHP_EOL;
 716                             $filter_html .= "\t\t\t\t\t\t$buttons" . PHP_EOL;
 717                             $filter_html .= '</div>' . PHP_EOL;
 718                         }
 719                     }
 720                     elseif (!empty($options))
 721                     {
 722                         $label       = $headerField->label;
 723                         $emptyOption = JHtml::_('select.option', '', '- ' . JText::_($label) . ' -');
 724                         array_unshift($options, $emptyOption);
 725                         $attribs     = array(
 726                             'onchange' => 'document.adminForm.submit();'
 727                         );
 728                         $filter      = JHtml::_('select.genericlist', $options, $headerField->name, $attribs, 'value', 'text', $headerField->value, false, true);
 729                         $filter_html .= "\t\t\t\t\t\t$filter" . PHP_EOL;
 730                     }
 731 
 732                     $filter_html .= "\t\t\t\t\t</td>" . PHP_EOL;
 733                 }
 734             }
 735         }
 736 
 737         
 738         $filter_order        = $form->getView()->getLists()->order;
 739         $filter_order_Dir    = $form->getView()->getLists()->order_Dir;
 740         $actionUrl           = FOFPlatform::getInstance()->isBackend() ? 'index.php' : JUri::root().'index.php';
 741 
 742         if (FOFPlatform::getInstance()->isFrontend() && ($input->getCmd('Itemid', 0) != 0))
 743         {
 744             $itemid = $input->getCmd('Itemid', 0);
 745             $uri = new JUri($actionUrl);
 746 
 747             if ($itemid)
 748             {
 749                 $uri->setVar('Itemid', $itemid);
 750             }
 751 
 752             $actionUrl = JRoute::_($uri->toString());
 753         }
 754 
 755         $html .= '<form action="'.$actionUrl.'" method="post" name="adminForm" id="adminForm" ' . $form_class . '>' . PHP_EOL;
 756 
 757         if (version_compare(JVERSION, '3.0', 'ge'))
 758         {
 759             
 760             
 761             $sidebar = JHtmlSidebar::render();
 762 
 763             if ($show_filters && !empty($sidebar))
 764             {
 765                 $html .= '<div id="j-sidebar-container" class="span2">' . "\n";
 766                 $html .= "\t$sidebar\n";
 767                 $html .= "</div>\n";
 768                 $html .= '<div id="j-main-container" class="span10">' . "\n";
 769             }
 770             else
 771             {
 772                 $html .= '<div id="j-main-container">' . "\n";
 773             }
 774 
 775             
 776 
 777             if ($show_header)
 778             {
 779                 $html .= "\t" . '<div id="filter-bar" class="btn-toolbar">' . "\n";
 780                 $html .= "$filter_html\n";
 781 
 782                 if ($show_pagination)
 783                 {
 784                     
 785                     $html .= "\t" . '<div class="btn-group pull-right hidden-phone">' . "\n";
 786                     $html .= "\t\t" . '<label for="limit" class="element-invisible">' . JText::_('JFIELD_PLG_SEARCH_SEARCHLIMIT_DESC') . '</label>' . "\n";
 787                     $html .= "\t\t" . $model->getPagination()->getLimitBox() . "\n";
 788                     $html .= "\t" . '</div>' . "\n";
 789                 }
 790 
 791                 if (!empty($sortFields))
 792                 {
 793                     
 794                     $asc_sel     = ($view->getLists()->order_Dir == 'asc') ? 'selected="selected"' : '';
 795                     $desc_sel    = ($view->getLists()->order_Dir == 'desc') ? 'selected="selected"' : '';
 796                     $html .= "\t" . '<div class="btn-group pull-right hidden-phone">' . "\n";
 797                     $html .= "\t\t" . '<label for="directionTable" class="element-invisible">' . JText::_('JFIELD_ORDERING_DESC') . '</label>' . "\n";
 798                     $html .= "\t\t" . '<select name="directionTable" id="directionTable" class="input-medium" onchange="Joomla.orderTable()">' . "\n";
 799                     $html .= "\t\t\t" . '<option value="">' . JText::_('JFIELD_ORDERING_DESC') . '</option>' . "\n";
 800                     $html .= "\t\t\t" . '<option value="asc" ' . $asc_sel . '>' . JText::_('JGLOBAL_ORDER_ASCENDING') . '</option>' . "\n";
 801                     $html .= "\t\t\t" . '<option value="desc" ' . $desc_sel . '>' . JText::_('JGLOBAL_ORDER_DESCENDING') . '</option>' . "\n";
 802                     $html .= "\t\t" . '</select>' . "\n";
 803                     $html .= "\t" . '</div>' . "\n\n";
 804 
 805                     
 806                     $html .= "\t" . '<div class="btn-group pull-right">' . "\n";
 807                     $html .= "\t\t" . '<label for="sortTable" class="element-invisible">' . JText::_('JGLOBAL_SORT_BY') . '</label>' . "\n";
 808                     $html .= "\t\t" . '<select name="sortTable" id="sortTable" class="input-medium" onchange="Joomla.orderTable()">' . "\n";
 809                     $html .= "\t\t\t" . '<option value="">' . JText::_('JGLOBAL_SORT_BY') . '</option>' . "\n";
 810                     $html .= "\t\t\t" . JHtml::_('select.options', $sortFields, 'value', 'text', $view->getLists()->order) . "\n";
 811                     $html .= "\t\t" . '</select>' . "\n";
 812                     $html .= "\t" . '</div>' . "\n";
 813                 }
 814 
 815                 $html .= "\t</div>\n\n";
 816                 $html .= "\t" . '<div class="clearfix"> </div>' . "\n\n";
 817             }
 818         }
 819 
 820         
 821         $html .= "\t\t" . '<table class="table table-striped" id="itemsList">' . PHP_EOL;
 822 
 823         
 824 
 825         if ($show_header || ($show_filters && version_compare(JVERSION, '3.0', 'lt')))
 826         {
 827             $html .= "\t\t\t<thead>" . PHP_EOL;
 828         }
 829 
 830         
 831 
 832         if ($show_header)
 833         {
 834             $html .= "\t\t\t\t<tr>" . PHP_EOL;
 835             $html .= $header_html;
 836             $html .= "\t\t\t\t</tr>" . PHP_EOL;
 837         }
 838 
 839         
 840 
 841         if ($show_filters && version_compare(JVERSION, '3.0', 'lt'))
 842         {
 843             $html .= "\t\t\t\t<tr>";
 844             $html .= $filter_html;
 845             $html .= "\t\t\t\t</tr>";
 846         }
 847 
 848         
 849 
 850         if ($show_header || ($show_filters && version_compare(JVERSION, '3.0', 'lt')))
 851         {
 852             $html .= "\t\t\t</thead>" . PHP_EOL;
 853         }
 854 
 855         
 856         $html .= "\t\t\t<tbody>" . PHP_EOL;
 857         $fields      = $form->getFieldset('items');
 858         $num_columns = count($fields);
 859         $items       = $model->getItemList();
 860 
 861         if ($count = count($items))
 862         {
 863             $m = 1;
 864 
 865             foreach ($items as $i => $item)
 866             {
 867                 $table_item = $model->getTable();
 868                 $table_item->reset();
 869                 $table_item->bind($item);
 870 
 871                 $form->bind($item);
 872 
 873                 $m       = 1 - $m;
 874                 $class   = 'row' . $m;
 875 
 876                 $html .= "\t\t\t\t<tr class=\"$class\">" . PHP_EOL;
 877 
 878                 $fields = $form->getFieldset('items');
 879 
 880                 
 881                 if (version_compare(JVERSION, '3.0', 'gt'))
 882                 {
 883                     $tmpFields = array();
 884                     $j = 1;
 885 
 886                     foreach ($fields as $tmpField)
 887                     {
 888                         if ($tmpField instanceof FOFFormFieldOrdering)
 889                         {
 890                             $tmpFields[0] = $tmpField;
 891                         }
 892 
 893                         else
 894                         {
 895                             $tmpFields[$j] = $tmpField;
 896                         }
 897 
 898                         $j++;
 899                     }
 900 
 901                     $fields = $tmpFields;
 902                     ksort($fields, SORT_NUMERIC);
 903                 }
 904 
 905                 foreach ($fields as $field)
 906                 {
 907                     $field->rowid    = $i;
 908                     $field->item     = $table_item;
 909                     $labelClass = $field->labelClass ? $field->labelClass : $field->labelclass; 
 910                     $class           = $labelClass ? 'class ="' . $labelClass . '"' : '';
 911                     $html .= "\t\t\t\t\t<td $class>" . $field->getRepeatable() . '</td>' . PHP_EOL;
 912                 }
 913 
 914                 $html .= "\t\t\t\t</tr>" . PHP_EOL;
 915             }
 916         }
 917         elseif ($norows_placeholder)
 918         {
 919             $html .= "\t\t\t\t<tr><td colspan=\"$num_columns\">";
 920             $html .= JText::_($norows_placeholder);
 921             $html .= "</td></tr>\n";
 922         }
 923 
 924         $html .= "\t\t\t</tbody>" . PHP_EOL;
 925 
 926         
 927         if ($show_pagination && version_compare(JVERSION, '3.0', 'lt'))
 928         {
 929             $pagination = $model->getPagination();
 930             $html .= "\t\t\t<tfoot>" . PHP_EOL;
 931             $html .= "\t\t\t\t<tr><td colspan=\"$num_columns\">";
 932 
 933             if (($pagination->total > 0))
 934             {
 935                 $html .= $pagination->getListFooter();
 936             }
 937 
 938             $html .= "</td></tr>\n";
 939             $html .= "\t\t\t</tfoot>" . PHP_EOL;
 940         }
 941 
 942         
 943         $html .= "\t\t" . '</table>' . PHP_EOL;
 944 
 945         
 946 
 947         if ($show_pagination && version_compare(JVERSION, '3.0', 'ge'))
 948         {
 949             $html .= $model->getPagination()->getListFooter();
 950         }
 951 
 952         
 953 
 954         if (version_compare(JVERSION, '3.0', 'ge'))
 955         {
 956             $html .= "</div>\n";
 957         }
 958 
 959         $html .= "\t" . '<input type="hidden" name="option" value="' . $input->getCmd('option') . '" />' . PHP_EOL;
 960         $html .= "\t" . '<input type="hidden" name="view" value="' . FOFInflector::pluralize($input->getCmd('view')) . '" />' . PHP_EOL;
 961         $html .= "\t" . '<input type="hidden" name="task" value="' . $input->getCmd('task', 'browse') . '" />' . PHP_EOL;
 962         $html .= "\t" . '<input type="hidden" name="layout" value="' . $input->getCmd('layout', '') . '" />' . PHP_EOL;
 963 
 964         
 965 
 966         if (version_compare(JVERSION, '3.0', 'ge') && FOFPlatform::getInstance()->isFrontend())
 967         {
 968             $html .= "\t" . '<input type="hidden" name="id" value="' . $input->getCmd('id', '') . '" />' . PHP_EOL;
 969         }
 970 
 971         $html .= "\t" . '<input type="hidden" name="boxchecked" value="" />' . PHP_EOL;
 972         $html .= "\t" . '<input type="hidden" name="hidemainmenu" value="" />' . PHP_EOL;
 973         $html .= "\t" . '<input type="hidden" name="filter_order" value="' . $filter_order . '" />' . PHP_EOL;
 974         $html .= "\t" . '<input type="hidden" name="filter_order_Dir" value="' . $filter_order_Dir . '" />' . PHP_EOL;
 975 
 976         $html .= "\t" . '<input type="hidden" name="' . JFactory::getSession()->getFormToken() . '" value="1" />' . PHP_EOL;
 977 
 978         
 979         $html .= '</form>' . PHP_EOL;
 980 
 981         return $html;
 982     }
 983 
 984      985  986  987  988  989  990  991  992 
 993     protected function renderFormRead(FOFForm &$form, FOFModel $model, FOFInput $input)
 994     {
 995         $html = $this->renderFormRaw($form, $model, $input, 'read');
 996 
 997         return $html;
 998     }
 999 
1000     1001 1002 1003 1004 1005 1006 1007 1008 
1009     protected function renderFormEdit(FOFForm &$form, FOFModel $model, FOFInput $input)
1010     {
1011         
1012         $key         = $model->getTable()->getKeyName();
1013         $keyValue    = $model->getId();
1014 
1015         $html = '';
1016 
1017         $validate    = strtolower($form->getAttribute('validate'));
1018 
1019         if (in_array($validate, array('true', 'yes', '1', 'on')))
1020         {
1021             JHtml::_('behavior.formvalidation');
1022             $class = ' form-validate';
1023             $this->loadValidationScript($form);
1024         }
1025         else
1026         {
1027             $class = '';
1028         }
1029 
1030         
1031         $template_form_enctype = $form->getAttribute('enctype');
1032 
1033         if (!empty($template_form_enctype))
1034         {
1035             $enctype = ' enctype="' . $form->getAttribute('enctype') . '" ';
1036         }
1037         else
1038         {
1039             $enctype = '';
1040         }
1041 
1042         
1043         $formname = $form->getAttribute('name');
1044 
1045         if (empty($formname))
1046         {
1047             $formname = 'adminForm';
1048         }
1049 
1050         
1051         $formid = $form->getAttribute('name');
1052 
1053         if (empty($formid))
1054         {
1055             $formid = 'adminForm';
1056         }
1057 
1058         
1059         $customTask = $form->getAttribute('customTask');
1060 
1061         if (empty($customTask))
1062         {
1063             $customTask = '';
1064         }
1065 
1066         
1067         $actionUrl = FOFPlatform::getInstance()->isBackend() ? 'index.php' : JUri::root().'index.php';
1068 
1069         if (FOFPlatform::getInstance()->isFrontend() && ($input->getCmd('Itemid', 0) != 0))
1070         {
1071             $itemid = $input->getCmd('Itemid', 0);
1072             $uri = new JUri($actionUrl);
1073 
1074             if ($itemid)
1075             {
1076                 $uri->setVar('Itemid', $itemid);
1077             }
1078 
1079             $actionUrl = JRoute::_($uri->toString());
1080         }
1081 
1082         $html .= '<form action="'.$actionUrl.'" method="post" name="' . $formname .
1083             '" id="' . $formid . '"' . $enctype . ' class="form-horizontal' .
1084             $class . '">' . PHP_EOL;
1085         $html .= "\t" . '<input type="hidden" name="option" value="' . $input->getCmd('option') . '" />' . PHP_EOL;
1086         $html .= "\t" . '<input type="hidden" name="view" value="' . $input->getCmd('view', 'edit') . '" />' . PHP_EOL;
1087         $html .= "\t" . '<input type="hidden" name="task" value="' . $customTask . '" />' . PHP_EOL;
1088         $html .= "\t" . '<input type="hidden" name="' . $key . '" value="' . $keyValue . '" />' . PHP_EOL;
1089 
1090         $html .= "\t" . '<input type="hidden" name="' . JFactory::getSession()->getFormToken() . '" value="1" />' . PHP_EOL;
1091 
1092         $html .= $this->renderFormRaw($form, $model, $input, 'edit');
1093         $html .= '</form>';
1094 
1095         return $html;
1096     }
1097 
1098     1099 1100 1101 1102 1103 1104 1105 1106 1107 
1108     protected function renderFormRaw(FOFForm &$form, FOFModel $model, FOFInput $input, $formType)
1109     {
1110         $html = '';
1111         $tabHtml = array();
1112 
1113         
1114         $isTabbed = $form->getAttribute('tabbed', '0');
1115         $isTabbed = in_array($isTabbed, array('true', 'yes', 'on', '1'));
1116 
1117         foreach ($form->getFieldsets() as $fieldset)
1118         {
1119             if ($isTabbed && $this->isTabFieldset($fieldset))
1120             {
1121                 continue;
1122             }
1123             elseif ($isTabbed && isset($fieldset->innertab))
1124             {
1125                 $inTab = $fieldset->innertab;
1126             }
1127             else
1128             {
1129                 $inTab = '__outer';
1130             }
1131 
1132             $tabHtml[$inTab][] = $this->renderFieldset($fieldset, $form, $model, $input, $formType, false);
1133         }
1134 
1135         
1136         if ($isTabbed)
1137         {
1138             $html .= '<ul class="nav nav-tabs">' . PHP_EOL;
1139 
1140             foreach ($form->getFieldsets() as $fieldset)
1141             {
1142                 
1143                 $isTabbedFieldset = $this->isTabFieldset($fieldset);
1144                 if (!$isTabbedFieldset)
1145                 {
1146                     continue;
1147                 }
1148 
1149                 
1150                 if (!isset($fieldset->label) || empty($fieldset->label))
1151                 {
1152                     continue;
1153                 }
1154 
1155                 $label = JText::_($fieldset->label);
1156                 $name = $fieldset->name;
1157                 $liClass = ($isTabbedFieldset == 2) ? 'class="active"' : '';
1158 
1159                 $html .= "<li $liClass><a href=\"#$name\" data-toggle=\"tab\">$label</a></li>" . PHP_EOL;
1160             }
1161 
1162             $html .= '</ul>' . "\n\n<div class=\"tab-content\">" . PHP_EOL;
1163 
1164             foreach ($form->getFieldsets() as $fieldset)
1165             {
1166                 if (!$this->isTabFieldset($fieldset))
1167                 {
1168                     continue;
1169                 }
1170 
1171                 $html .= $this->renderFieldset($fieldset, $form, $model, $input, $formType, false, $tabHtml);
1172             }
1173 
1174             $html .= "</div>\n";
1175         }
1176 
1177         if (isset($tabHtml['__outer']))
1178         {
1179             $html .= implode('', $tabHtml['__outer']);
1180         }
1181 
1182         return $html;
1183     }
1184 
1185     1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 
1197     protected function renderFieldset(stdClass &$fieldset, FOFForm &$form, FOFModel $model, FOFInput $input, $formType, $showHeader = true, &$innerHtml = null)
1198     {
1199         $html = '';
1200 
1201         $fields = $form->getFieldset($fieldset->name);
1202 
1203         if (isset($fieldset->class))
1204         {
1205             $class = 'class="' . $fieldset->class . '"';
1206         }
1207         else
1208         {
1209             $class = '';
1210         }
1211 
1212         if (isset($innerHtml[$fieldset->name]))
1213         {
1214             $innerclass = isset($fieldset->innerclass) ? ' class="' . $fieldset->innerclass . '"' : '';
1215 
1216             $html .= "\t" . '<div id="' . $fieldset->name . '" ' . $class . '>' . PHP_EOL;
1217             $html .= "\t\t" . '<div' . $innerclass . '>' . PHP_EOL;
1218         }
1219         else
1220         {
1221             $html .= "\t" . '<div id="' . $fieldset->name . '" ' . $class . '>' . PHP_EOL;
1222         }
1223 
1224         $isTabbedFieldset = $this->isTabFieldset($fieldset);
1225 
1226         if (isset($fieldset->label) && !empty($fieldset->label) && !$isTabbedFieldset)
1227         {
1228             $html .= "\t\t" . '<h3>' . JText::_($fieldset->label) . '</h3>' . PHP_EOL;
1229         }
1230 
1231         foreach ($fields as $field)
1232         {
1233             $groupClass  = $form->getFieldAttribute($field->fieldname, 'groupclass', '', $field->group);
1234 
1235             
1236             
1237             $title       = $form->getFieldAttribute($field->fieldname, 'label', '', $field->group);
1238             $emptylabel  = $form->getFieldAttribute($field->fieldname, 'emptylabel', false, $field->group);
1239 
1240             if (empty($title) && !$emptylabel)
1241             {
1242                 $model->getName();
1243                 $title = strtoupper($input->get('option') . '_' . $model->getName() . '_' . $field->id . '_LABEL');
1244             }
1245 
1246             
1247             $description = $form->getFieldAttribute($field->fieldname, 'description', '', $field->group);
1248 
1249             1250 1251 1252 
1253             1254 1255 1256 1257 1258 1259 
1260 
1261             if ($formType == 'read')
1262             {
1263                 $inputField = $field->static;
1264             }
1265             elseif ($formType == 'edit')
1266             {
1267                 $inputField = $field->input;
1268             }
1269 
1270             if (empty($title))
1271             {
1272                 $html .= "\t\t\t" . $inputField . PHP_EOL;
1273 
1274                 if (!empty($description) && $formType == 'edit')
1275                 {
1276                     $html .= "\t\t\t\t" . '<span class="help-block">';
1277                     $html .= JText::_($description) . '</span>' . PHP_EOL;
1278                 }
1279             }
1280             else
1281             {
1282                 $html .= "\t\t\t" . '<div class="control-group ' . $groupClass . '">' . PHP_EOL;
1283                 $html .= $this->renderFieldsetLabel($field, $form, $title);
1284                 $html .= "\t\t\t\t" . '<div class="controls">' . PHP_EOL;
1285                 $html .= "\t\t\t\t\t" . $inputField . PHP_EOL;
1286 
1287                 if (!empty($description))
1288                 {
1289                     $html .= "\t\t\t\t" . '<span class="help-block">';
1290                     $html .= JText::_($description) . '</span>' . PHP_EOL;
1291                 }
1292 
1293                 $html .= "\t\t\t\t" . '</div>' . PHP_EOL;
1294                 $html .= "\t\t\t" . '</div>' . PHP_EOL;
1295             }
1296         }
1297 
1298         if (isset($innerHtml[$fieldset->name]))
1299         {
1300             $html .= "\t\t" . '</div>' . PHP_EOL;
1301             $html .= implode('', $innerHtml[$fieldset->name]) . PHP_EOL;
1302             $html .= "\t" . '</div>' . PHP_EOL;
1303         }
1304         else
1305         {
1306             $html .= "\t" . '</div>' . PHP_EOL;
1307         }
1308 
1309         return $html;
1310     }
1311 
1312     1313 1314 1315 1316 1317 1318 1319 1320 
1321     protected function renderFieldsetLabel($field, FOFForm &$form, $title)
1322     {
1323         $html = '';
1324 
1325         $labelClass  = $field->labelClass ? $field->labelClass : $field->labelclass; 
1326         $required    = $field->required;
1327 
1328         $tooltip = $form->getFieldAttribute($field->fieldname, 'tooltip', '', $field->group);
1329 
1330         if (!empty($tooltip))
1331         {
1332             if (version_compare(JVERSION, '3.0', 'ge'))
1333             {
1334                 static $loadedTooltipScript = false;
1335 
1336                 if (!$loadedTooltipScript)
1337                 {
1338                     $js = <<<JS
1339 (function($)
1340 {
1341     $(document).ready(function()
1342     {
1343         $('.fof-tooltip').tooltip({placement: 'top'});
1344     });
1345 })(akeeba.jQuery);
1346 JS;
1347                     $document = FOFPlatform::getInstance()->getDocument();
1348 
1349                     if ($document instanceof JDocument)
1350                     {
1351                         $document->addScriptDeclaration($js);
1352                     }
1353 
1354                     $loadedTooltipScript = true;
1355                 }
1356 
1357                 $tooltipText = '<strong>' . JText::_($title) . '</strong><br />' . JText::_($tooltip);
1358 
1359                 $html .= "\t\t\t\t" . '<label class="control-label fof-tooltip ' . $labelClass . '" for="' . $field->id . '" title="' . $tooltipText . '" data-toggle="fof-tooltip">';
1360             }
1361             else
1362             {
1363                 
1364                 
1365                 JHtml::_('behavior.tooltip');
1366 
1367                 $tooltipText = JText::_($title) . '::' . JText::_($tooltip);
1368 
1369                 $html .= "\t\t\t\t" . '<label class="control-label hasTip ' . $labelClass . '" for="' . $field->id . '" title="' . $tooltipText . '" rel="tooltip">';
1370             }
1371         }
1372         else
1373         {
1374             $html .= "\t\t\t\t" . '<label class="control-label ' . $labelClass . '" for="' . $field->id . '">';
1375         }
1376 
1377         $html .= JText::_($title);
1378 
1379         if ($required)
1380         {
1381             $html .= ' *';
1382         }
1383 
1384         $html .= '</label>' . PHP_EOL;
1385 
1386         return $html;
1387     }
1388 }
1389