PageRenderTime 68ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/fof/render/strapper.php

https://github.com/J2MTecnologia/joomla-3.x
PHP | 1129 lines | 753 code | 187 blank | 189 comment | 116 complexity | 2546d432e9eec0796d131bda95546578 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause
  1. <?php
  2. /**
  3. * @package FrameworkOnFramework
  4. * @subpackage render
  5. * @copyright Copyright (C) 2010 - 2014 Akeeba Ltd. All rights reserved.
  6. * @license GNU General Public License version 2 or later; see LICENSE.txt
  7. */
  8. defined('FOF_INCLUDED') or die;
  9. /**
  10. * Akeeba Strapper view renderer class.
  11. *
  12. * @package FrameworkOnFramework
  13. * @since 2.0
  14. */
  15. class FOFRenderStrapper extends FOFRenderAbstract
  16. {
  17. /**
  18. * Public constructor. Determines the priority of this class and if it should be enabled
  19. */
  20. public function __construct()
  21. {
  22. $this->priority = 60;
  23. $this->enabled = class_exists('AkeebaStrapper');
  24. }
  25. /**
  26. * Echoes any HTML to show before the view template
  27. *
  28. * @param string $view The current view
  29. * @param string $task The current task
  30. * @param FOFInput $input The input array (request parameters)
  31. * @param array $config The view configuration array
  32. *
  33. * @return void
  34. */
  35. public function preRender($view, $task, $input, $config = array())
  36. {
  37. $format = $input->getCmd('format', 'html');
  38. if (empty($format))
  39. {
  40. $format = 'html';
  41. }
  42. if ($format != 'html')
  43. {
  44. return;
  45. }
  46. if (!FOFPlatform::getInstance()->isCli())
  47. {
  48. // Wrap output in a Joomla-versioned div
  49. $version = new JVersion;
  50. $versionParts = explode('.', $version->RELEASE);
  51. $minorVersion = str_replace('.', '', $version->RELEASE);
  52. $majorVersion = array_shift($versionParts);
  53. echo "<div class=\"joomla-version-$majorVersion joomla-version-$minorVersion\">\n";
  54. // Wrap output in an akeeba-bootstrap class div
  55. echo "<div class=\"akeeba-bootstrap\">\n";
  56. echo "<div class=\"row-fluid\">\n";
  57. }
  58. // Render submenu and toolbar (only if asked to)
  59. if ($input->getBool('render_toolbar', true))
  60. {
  61. $this->renderButtons($view, $task, $input, $config);
  62. $this->renderLinkbar($view, $task, $input, $config);
  63. }
  64. }
  65. /**
  66. * Echoes any HTML to show after the view template
  67. *
  68. * @param string $view The current view
  69. * @param string $task The current task
  70. * @param FOFInput $input The input array (request parameters)
  71. * @param array $config The view configuration array
  72. *
  73. * @return void
  74. */
  75. public function postRender($view, $task, $input, $config = array())
  76. {
  77. $format = $input->getCmd('format', 'html');
  78. if ($format != 'html' || FOFPlatform::getInstance()->isCli())
  79. {
  80. return;
  81. }
  82. if (!FOFPlatform::getInstance()->isCli() && version_compare(JVERSION, '3.0', 'ge'))
  83. {
  84. $sidebarEntries = JHtmlSidebar::getEntries();
  85. if (!empty($sidebarEntries))
  86. {
  87. echo '</div>';
  88. }
  89. }
  90. echo "</div>\n"; // Closes row-fluid div
  91. echo "</div>\n"; // Closes akeeba-bootstrap div
  92. echo "</div>\n"; // Closes joomla-version div
  93. }
  94. /**
  95. * Loads the validation script for an edit form
  96. *
  97. * @param FOFForm &$form The form we are rendering
  98. *
  99. * @return void
  100. */
  101. protected function loadValidationScript(FOFForm &$form)
  102. {
  103. $message = $form->getView()->escape(JText::_('JGLOBAL_VALIDATION_FORM_FAILED'));
  104. $js = <<<ENDJAVASCRIPT
  105. Joomla.submitbutton = function(task)
  106. {
  107. if (task == 'cancel' || document.formvalidator.isValid(document.id('adminForm')))
  108. {
  109. Joomla.submitform(task, document.getElementById('adminForm'));
  110. }
  111. else {
  112. alert('$message');
  113. }
  114. };
  115. ENDJAVASCRIPT;
  116. $document = FOFPlatform::getInstance()->getDocument();
  117. if ($document instanceof JDocument)
  118. {
  119. $document->addScriptDeclaration($js);
  120. }
  121. }
  122. /**
  123. * Renders the submenu (link bar)
  124. *
  125. * @param string $view The active view name
  126. * @param string $task The current task
  127. * @param FOFInput $input The input object
  128. * @param array $config Extra configuration variables for the toolbar
  129. *
  130. * @return void
  131. */
  132. protected function renderLinkbar($view, $task, $input, $config = array())
  133. {
  134. $style = 'classic';
  135. if (array_key_exists('linkbar_style', $config))
  136. {
  137. $style = $config['linkbar_style'];
  138. }
  139. if (!version_compare(JVERSION, '3.0', 'ge'))
  140. {
  141. $style = 'classic';
  142. }
  143. switch ($style)
  144. {
  145. case 'joomla':
  146. $this->renderLinkbar_joomla($view, $task, $input);
  147. break;
  148. case 'classic':
  149. default:
  150. $this->renderLinkbar_classic($view, $task, $input);
  151. break;
  152. }
  153. }
  154. /**
  155. * Renders the submenu (link bar) in FOF's classic style, using a Bootstrapped
  156. * tab bar.
  157. *
  158. * @param string $view The active view name
  159. * @param string $task The current task
  160. * @param FOFInput $input The input object
  161. * @param array $config Extra configuration variables for the toolbar
  162. *
  163. * @return void
  164. */
  165. protected function renderLinkbar_classic($view, $task, $input, $config = array())
  166. {
  167. if (FOFPlatform::getInstance()->isCli())
  168. {
  169. return;
  170. }
  171. // Do not render a submenu unless we are in the the admin area
  172. $toolbar = FOFToolbar::getAnInstance($input->getCmd('option', 'com_foobar'), $config);
  173. $renderFrontendSubmenu = $toolbar->getRenderFrontendSubmenu();
  174. if (!FOFPlatform::getInstance()->isBackend() && !$renderFrontendSubmenu)
  175. {
  176. return;
  177. }
  178. $links = $toolbar->getLinks();
  179. if (!empty($links))
  180. {
  181. echo "<ul class=\"nav nav-tabs\">\n";
  182. foreach ($links as $link)
  183. {
  184. $dropdown = false;
  185. if (array_key_exists('dropdown', $link))
  186. {
  187. $dropdown = $link['dropdown'];
  188. }
  189. if ($dropdown)
  190. {
  191. echo "<li";
  192. $class = 'dropdown';
  193. if ($link['active'])
  194. {
  195. $class .= ' active';
  196. }
  197. echo ' class="' . $class . '">';
  198. echo '<a class="dropdown-toggle" data-toggle="dropdown" href="#">';
  199. if ($link['icon'])
  200. {
  201. echo "<i class=\"icon icon-" . $link['icon'] . "\"></i>";
  202. }
  203. echo $link['name'];
  204. echo '<b class="caret"></b>';
  205. echo '</a>';
  206. echo "\n<ul class=\"dropdown-menu\">";
  207. foreach ($link['items'] as $item)
  208. {
  209. echo "<li";
  210. if ($item['active'])
  211. {
  212. echo ' class="active"';
  213. }
  214. echo ">";
  215. if ($item['icon'])
  216. {
  217. echo "<i class=\"icon icon-" . $item['icon'] . "\"></i>";
  218. }
  219. if ($item['link'])
  220. {
  221. echo "<a href=\"" . $item['link'] . "\">" . $item['name'] . "</a>";
  222. }
  223. else
  224. {
  225. echo $item['name'];
  226. }
  227. echo "</li>";
  228. }
  229. echo "</ul>\n";
  230. }
  231. else
  232. {
  233. echo "<li";
  234. if ($link['active'])
  235. {
  236. echo ' class="active"';
  237. }
  238. echo ">";
  239. if ($link['icon'])
  240. {
  241. echo "<i class=\"icon icon-" . $link['icon'] . "\"></i>";
  242. }
  243. if ($link['link'])
  244. {
  245. echo "<a href=\"" . $link['link'] . "\">" . $link['name'] . "</a>";
  246. }
  247. else
  248. {
  249. echo $link['name'];
  250. }
  251. }
  252. echo "</li>\n";
  253. }
  254. echo "</ul>\n";
  255. }
  256. }
  257. /**
  258. * Renders the submenu (link bar) using Joomla!'s style. On Joomla! 2.5 this
  259. * is a list of bar separated links, on Joomla! 3 it's a sidebar at the
  260. * left-hand side of the page.
  261. *
  262. * @param string $view The active view name
  263. * @param string $task The current task
  264. * @param FOFInput $input The input object
  265. * @param array $config Extra configuration variables for the toolbar
  266. *
  267. * @return void
  268. */
  269. protected function renderLinkbar_joomla($view, $task, $input, $config = array())
  270. {
  271. // On command line don't do anything
  272. if (FOFPlatform::getInstance()->isCli())
  273. {
  274. return;
  275. }
  276. // Do not render a submenu unless we are in the the admin area
  277. $toolbar = FOFToolbar::getAnInstance($input->getCmd('option', 'com_foobar'), $config);
  278. $renderFrontendSubmenu = $toolbar->getRenderFrontendSubmenu();
  279. if (!FOFPlatform::getInstance()->isBackend() && !$renderFrontendSubmenu)
  280. {
  281. return;
  282. }
  283. $this->renderLinkbarItems($toolbar);
  284. }
  285. /**
  286. * do the rendering job for the linkbar
  287. *
  288. * @param FOFToolbar $toolbar A toolbar object
  289. *
  290. * @return void
  291. */
  292. protected function renderLinkbarItems($toolbar)
  293. {
  294. $links = $toolbar->getLinks();
  295. if (!empty($links))
  296. {
  297. foreach ($links as $link)
  298. {
  299. JHtmlSidebar::addEntry($link['name'], $link['link'], $link['active']);
  300. $dropdown = false;
  301. if (array_key_exists('dropdown', $link))
  302. {
  303. $dropdown = $link['dropdown'];
  304. }
  305. if ($dropdown)
  306. {
  307. foreach ($link['items'] as $item)
  308. {
  309. JHtmlSidebar::addEntry('– ' . $item['name'], $item['link'], $item['active']);
  310. }
  311. }
  312. }
  313. }
  314. }
  315. /**
  316. * Renders the toolbar buttons
  317. *
  318. * @param string $view The active view name
  319. * @param string $task The current task
  320. * @param FOFInput $input The input object
  321. * @param array $config Extra configuration variables for the toolbar
  322. *
  323. * @return void
  324. */
  325. protected function renderButtons($view, $task, $input, $config = array())
  326. {
  327. if (FOFPlatform::getInstance()->isCli())
  328. {
  329. return;
  330. }
  331. // Do not render buttons unless we are in the the frontend area and we are asked to do so
  332. $toolbar = FOFToolbar::getAnInstance($input->getCmd('option', 'com_foobar'), $config);
  333. $renderFrontendButtons = $toolbar->getRenderFrontendButtons();
  334. // Load main backend language, in order to display toolbar strings
  335. // (JTOOLBAR_BACK, JTOOLBAR_PUBLISH etc etc)
  336. FOFPlatform::getInstance()->loadTranslations('joomla');
  337. if (FOFPlatform::getInstance()->isBackend() || !$renderFrontendButtons)
  338. {
  339. return;
  340. }
  341. $bar = JToolBar::getInstance('toolbar');
  342. $items = $bar->getItems();
  343. $substitutions = array(
  344. 'icon-32-new' => 'icon-plus',
  345. 'icon-32-publish' => 'icon-eye-open',
  346. 'icon-32-unpublish' => 'icon-eye-close',
  347. 'icon-32-delete' => 'icon-trash',
  348. 'icon-32-edit' => 'icon-edit',
  349. 'icon-32-copy' => 'icon-th-large',
  350. 'icon-32-cancel' => 'icon-remove',
  351. 'icon-32-back' => 'icon-circle-arrow-left',
  352. 'icon-32-apply' => 'icon-ok',
  353. 'icon-32-save' => 'icon-hdd',
  354. 'icon-32-save-new' => 'icon-repeat',
  355. );
  356. if(isset(JFactory::getApplication()->JComponentTitle))
  357. {
  358. $title = JFactory::getApplication()->JComponentTitle;
  359. }
  360. else
  361. {
  362. $title = '';
  363. }
  364. $html = array();
  365. $actions = array();
  366. // For BC we have to use the same id we're using inside other renderers (FOFHeaderHolder)
  367. //$html[] = '<div class="well" id="' . $bar->getName() . '">';
  368. $html[] = '<div class="well" id="FOFHeaderHolder">';
  369. $html[] = '<div class="titleHolder">'.$title.'</div>';
  370. $html[] = '<div class="buttonsHolder">';
  371. foreach ($items as $node)
  372. {
  373. $type = $node[0];
  374. $button = $bar->loadButtonType($type);
  375. if ($button !== false)
  376. {
  377. if (method_exists($button, 'fetchId'))
  378. {
  379. $id = call_user_func_array(array(&$button, 'fetchId'), $node);
  380. }
  381. else
  382. {
  383. $id = null;
  384. }
  385. $action = call_user_func_array(array(&$button, 'fetchButton'), $node);
  386. $action = str_replace('class="toolbar"', 'class="toolbar btn"', $action);
  387. $action = str_replace('<span ', '<i ', $action);
  388. $action = str_replace('</span>', '</i>', $action);
  389. $action = str_replace(array_keys($substitutions), array_values($substitutions), $action);
  390. $actions[] = $action;
  391. }
  392. }
  393. $html = array_merge($html, $actions);
  394. $html[] = '</div>';
  395. $html[] = '</div>';
  396. echo implode("\n", $html);
  397. }
  398. /**
  399. * Renders a FOFForm for a Browse view and returns the corresponding HTML
  400. *
  401. * @param FOFForm &$form The form to render
  402. * @param FOFModel $model The model providing our data
  403. * @param FOFInput $input The input object
  404. *
  405. * @return string The HTML rendering of the form
  406. */
  407. protected function renderFormBrowse(FOFForm &$form, FOFModel $model, FOFInput $input)
  408. {
  409. $html = '';
  410. JHtml::_('behavior.multiselect');
  411. // Joomla! 3.0+ support
  412. if (version_compare(JVERSION, '3.0', 'ge'))
  413. {
  414. JHtml::_('bootstrap.tooltip');
  415. JHtml::_('dropdown.init');
  416. JHtml::_('formbehavior.chosen', 'select');
  417. $view = $form->getView();
  418. $order = $view->escape($view->getLists()->order);
  419. $html .= <<<JS
  420. <script type="text/javascript">
  421. Joomla.orderTable = function() {
  422. table = document.getElementById("sortTable");
  423. direction = document.getElementById("directionTable");
  424. order = table.options[table.selectedIndex].value;
  425. if (order != '$order')
  426. {
  427. dirn = 'asc';
  428. }
  429. else {
  430. dirn = direction.options[direction.selectedIndex].value;
  431. }
  432. Joomla.tableOrdering(order, dirn);
  433. }
  434. </script>
  435. JS;
  436. }
  437. // Getting all header row elements
  438. $headerFields = $form->getHeaderset();
  439. // Get form parameters
  440. $show_header = $form->getAttribute('show_header', 1);
  441. $show_filters = $form->getAttribute('show_filters', 1);
  442. $show_pagination = $form->getAttribute('show_pagination', 1);
  443. $norows_placeholder = $form->getAttribute('norows_placeholder', '');
  444. // Joomla! 3.0 sidebar support
  445. if (version_compare(JVERSION, '3.0', 'gt'))
  446. {
  447. $form_class = '';
  448. if ($show_filters)
  449. {
  450. JHtmlSidebar::setAction("index.php?option=" .
  451. $input->getCmd('option') . "&view=" .
  452. FOFInflector::pluralize($input->getCmd('view'))
  453. );
  454. }
  455. // Reorder the fields with ordering first
  456. $tmpFields = array();
  457. $i = 1;
  458. foreach ($headerFields as $tmpField)
  459. {
  460. if ($tmpField instanceof FOFFormHeaderOrdering)
  461. {
  462. $tmpFields[0] = $tmpField;
  463. }
  464. else
  465. {
  466. $tmpFields[$i] = $tmpField;
  467. }
  468. $i++;
  469. }
  470. $headerFields = $tmpFields;
  471. ksort($headerFields, SORT_NUMERIC);
  472. }
  473. else
  474. {
  475. $form_class = 'class="form-horizontal"';
  476. }
  477. // Pre-render the header and filter rows
  478. $header_html = '';
  479. $filter_html = '';
  480. $sortFields = array();
  481. if ($show_header || $show_filters)
  482. {
  483. foreach ($headerFields as $headerField)
  484. {
  485. $header = $headerField->header;
  486. $filter = $headerField->filter;
  487. $buttons = $headerField->buttons;
  488. $options = $headerField->options;
  489. $sortable = $headerField->sortable;
  490. $tdwidth = $headerField->tdwidth;
  491. // Under Joomla! < 3.0 we can't have filter-only fields
  492. if (version_compare(JVERSION, '3.0', 'lt') && empty($header))
  493. {
  494. continue;
  495. }
  496. // If it's a sortable field, add to the list of sortable fields
  497. if ($sortable)
  498. {
  499. $sortFields[$headerField->name] = JText::_($headerField->label);
  500. }
  501. // Get the table data width, if set
  502. if (!empty($tdwidth))
  503. {
  504. $tdwidth = 'width="' . $tdwidth . '"';
  505. }
  506. else
  507. {
  508. $tdwidth = '';
  509. }
  510. if (!empty($header))
  511. {
  512. $header_html .= "\t\t\t\t\t<th $tdwidth>" . PHP_EOL;
  513. $header_html .= "\t\t\t\t\t\t" . $header;
  514. $header_html .= "\t\t\t\t\t</th>" . PHP_EOL;
  515. }
  516. if (version_compare(JVERSION, '3.0', 'ge'))
  517. {
  518. // Joomla! 3.0 or later
  519. if (!empty($filter))
  520. {
  521. $filter_html .= '<div class="filter-search btn-group pull-left">' . "\n";
  522. $filter_html .= "\t" . '<label for="title" class="element-invisible">';
  523. $filter_html .= JText::_($headerField->label);
  524. $filter_html .= "</label>\n";
  525. $filter_html .= "\t$filter\n";
  526. $filter_html .= "</div>\n";
  527. if (!empty($buttons))
  528. {
  529. $filter_html .= '<div class="btn-group pull-left hidden-phone">' . "\n";
  530. $filter_html .= "\t$buttons\n";
  531. $filter_html .= '</div>' . "\n";
  532. }
  533. }
  534. elseif (!empty($options))
  535. {
  536. $label = $headerField->label;
  537. JHtmlSidebar::addFilter(
  538. '- ' . JText::_($label) . ' -', (string) $headerField->name,
  539. JHtml::_(
  540. 'select.options',
  541. $options,
  542. 'value',
  543. 'text',
  544. $model->getState($headerField->name, ''), true
  545. )
  546. );
  547. }
  548. }
  549. else
  550. {
  551. // Joomla! 2.5
  552. $filter_html .= "\t\t\t\t\t<td>" . PHP_EOL;
  553. if (!empty($filter))
  554. {
  555. $filter_html .= "\t\t\t\t\t\t$filter" . PHP_EOL;
  556. if (!empty($buttons))
  557. {
  558. $filter_html .= '<div class="btn-group hidden-phone">' . PHP_EOL;
  559. $filter_html .= "\t\t\t\t\t\t$buttons" . PHP_EOL;
  560. $filter_html .= '</div>' . PHP_EOL;
  561. }
  562. }
  563. elseif (!empty($options))
  564. {
  565. $label = $headerField->label;
  566. $emptyOption = JHtml::_('select.option', '', '- ' . JText::_($label) . ' -');
  567. array_unshift($options, $emptyOption);
  568. $attribs = array(
  569. 'onchange' => 'document.adminForm.submit();'
  570. );
  571. $filter = JHtml::_('select.genericlist', $options, $headerField->name, $attribs, 'value', 'text', $headerField->value, false, true);
  572. $filter_html .= "\t\t\t\t\t\t$filter" . PHP_EOL;
  573. }
  574. $filter_html .= "\t\t\t\t\t</td>" . PHP_EOL;
  575. }
  576. }
  577. }
  578. // Start the form
  579. $filter_order = $form->getView()->getLists()->order;
  580. $filter_order_Dir = $form->getView()->getLists()->order_Dir;
  581. $html .= '<form action="index.php" method="post" name="adminForm" id="adminForm" ' . $form_class . '>' . PHP_EOL;
  582. if (version_compare(JVERSION, '3.0', 'ge'))
  583. {
  584. // Joomla! 3.0+
  585. // Get and output the sidebar, if present
  586. $sidebar = JHtmlSidebar::render();
  587. if ($show_filters && !empty($sidebar))
  588. {
  589. $html .= '<div id="j-sidebar-container" class="span2">' . "\n";
  590. $html .= "\t$sidebar\n";
  591. $html .= "</div>\n";
  592. $html .= '<div id="j-main-container" class="span10">' . "\n";
  593. }
  594. else
  595. {
  596. $html .= '<div id="j-main-container">' . "\n";
  597. }
  598. // Render header search fields, if the header is enabled
  599. if ($show_header)
  600. {
  601. $html .= "\t" . '<div id="filter-bar" class="btn-toolbar">' . "\n";
  602. $html .= "$filter_html\n";
  603. if ($show_pagination)
  604. {
  605. // Render the pagination rows per page selection box, if the pagination is enabled
  606. $html .= "\t" . '<div class="btn-group pull-right hidden-phone">' . "\n";
  607. $html .= "\t\t" . '<label for="limit" class="element-invisible">' . JText::_('JFIELD_PLG_SEARCH_SEARCHLIMIT_DESC') . '</label>' . "\n";
  608. $html .= "\t\t" . $model->getPagination()->getLimitBox() . "\n";
  609. $html .= "\t" . '</div>' . "\n";
  610. }
  611. if (!empty($sortFields))
  612. {
  613. // Display the field sort order
  614. $asc_sel = ($view->getLists()->order_Dir == 'asc') ? 'selected="selected"' : '';
  615. $desc_sel = ($view->getLists()->order_Dir == 'desc') ? 'selected="selected"' : '';
  616. $html .= "\t" . '<div class="btn-group pull-right hidden-phone">' . "\n";
  617. $html .= "\t\t" . '<label for="directionTable" class="element-invisible">' . JText::_('JFIELD_ORDERING_DESC') . '</label>' . "\n";
  618. $html .= "\t\t" . '<select name="directionTable" id="directionTable" class="input-medium" onchange="Joomla.orderTable()">' . "\n";
  619. $html .= "\t\t\t" . '<option value="">' . JText::_('JFIELD_ORDERING_DESC') . '</option>' . "\n";
  620. $html .= "\t\t\t" . '<option value="asc" ' . $asc_sel . '>' . JText::_('JGLOBAL_ORDER_ASCENDING') . '</option>' . "\n";
  621. $html .= "\t\t\t" . '<option value="desc" ' . $desc_sel . '>' . JText::_('JGLOBAL_ORDER_DESCENDING') . '</option>' . "\n";
  622. $html .= "\t\t" . '</select>' . "\n";
  623. $html .= "\t" . '</div>' . "\n\n";
  624. // Display the sort fields
  625. $html .= "\t" . '<div class="btn-group pull-right">' . "\n";
  626. $html .= "\t\t" . '<label for="sortTable" class="element-invisible">' . JText::_('JGLOBAL_SORT_BY') . '</label>' . "\n";
  627. $html .= "\t\t" . '<select name="sortTable" id="sortTable" class="input-medium" onchange="Joomla.orderTable()">' . "\n";
  628. $html .= "\t\t\t" . '<option value="">' . JText::_('JGLOBAL_SORT_BY') . '</option>' . "\n";
  629. $html .= "\t\t\t" . JHtml::_('select.options', $sortFields, 'value', 'text', $view->getLists()->order) . "\n";
  630. $html .= "\t\t" . '</select>' . "\n";
  631. $html .= "\t" . '</div>' . "\n";
  632. }
  633. $html .= "\t</div>\n\n";
  634. $html .= "\t" . '<div class="clearfix"> </div>' . "\n\n";
  635. }
  636. }
  637. // Start the table output
  638. $html .= "\t\t" . '<table class="table table-striped" id="itemsList">' . PHP_EOL;
  639. // Open the table header region if required
  640. if ($show_header || ($show_filters && version_compare(JVERSION, '3.0', 'lt')))
  641. {
  642. $html .= "\t\t\t<thead>" . PHP_EOL;
  643. }
  644. // Render the header row, if enabled
  645. if ($show_header)
  646. {
  647. $html .= "\t\t\t\t<tr>" . PHP_EOL;
  648. $html .= $header_html;
  649. $html .= "\t\t\t\t</tr>" . PHP_EOL;
  650. }
  651. // Render filter row if enabled
  652. if ($show_filters && version_compare(JVERSION, '3.0', 'lt'))
  653. {
  654. $html .= "\t\t\t\t<tr>";
  655. $html .= $filter_html;
  656. $html .= "\t\t\t\t</tr>";
  657. }
  658. // Close the table header region if required
  659. if ($show_header || ($show_filters && version_compare(JVERSION, '3.0', 'lt')))
  660. {
  661. $html .= "\t\t\t</thead>" . PHP_EOL;
  662. }
  663. // Loop through rows and fields, or show placeholder for no rows
  664. $html .= "\t\t\t<tbody>" . PHP_EOL;
  665. $fields = $form->getFieldset('items');
  666. $num_columns = count($fields);
  667. $items = $model->getItemList();
  668. if ($count = count($items))
  669. {
  670. $m = 1;
  671. foreach ($items as $i => $item)
  672. {
  673. $table_item = $model->getTable();
  674. $table_item->reset();
  675. $table_item->bind($item);
  676. $form->bind($item);
  677. $m = 1 - $m;
  678. $class = 'row' . $m;
  679. $html .= "\t\t\t\t<tr class=\"$class\">" . PHP_EOL;
  680. $fields = $form->getFieldset('items');
  681. // Reorder the fields to have ordering first
  682. if (version_compare(JVERSION, '3.0', 'gt'))
  683. {
  684. $tmpFields = array();
  685. $j = 1;
  686. foreach ($fields as $tmpField)
  687. {
  688. if ($tmpField instanceof FOFFormFieldOrdering)
  689. {
  690. $tmpFields[0] = $tmpField;
  691. }
  692. else
  693. {
  694. $tmpFields[$j] = $tmpField;
  695. }
  696. $j++;
  697. }
  698. $fields = $tmpFields;
  699. ksort($fields, SORT_NUMERIC);
  700. }
  701. foreach ($fields as $field)
  702. {
  703. $field->rowid = $i;
  704. $field->item = $table_item;
  705. $labelClass = $field->labelClass ? $field->labelClass : $field->labelclass; // Joomla! 2.5/3.x use different case for the same name
  706. $class = $labelClass ? 'class ="' . $labelClass . '"' : '';
  707. $html .= "\t\t\t\t\t<td $class>" . $field->getRepeatable() . '</td>' . PHP_EOL;
  708. }
  709. $html .= "\t\t\t\t</tr>" . PHP_EOL;
  710. }
  711. }
  712. elseif ($norows_placeholder)
  713. {
  714. $html .= "\t\t\t\t<tr><td colspan=\"$num_columns\">";
  715. $html .= JText::_($norows_placeholder);
  716. $html .= "</td></tr>\n";
  717. }
  718. $html .= "\t\t\t</tbody>" . PHP_EOL;
  719. // Render the pagination bar, if enabled, on J! 2.5
  720. if ($show_pagination && version_compare(JVERSION, '3.0', 'lt'))
  721. {
  722. $pagination = $model->getPagination();
  723. $html .= "\t\t\t<tfoot>" . PHP_EOL;
  724. $html .= "\t\t\t\t<tr><td colspan=\"$num_columns\">";
  725. if (($pagination->total > 0))
  726. {
  727. $html .= $pagination->getListFooter();
  728. }
  729. $html .= "</td></tr>\n";
  730. $html .= "\t\t\t</tfoot>" . PHP_EOL;
  731. }
  732. // End the table output
  733. $html .= "\t\t" . '</table>' . PHP_EOL;
  734. // Render the pagination bar, if enabled, on J! 3.0+
  735. if ($show_pagination && version_compare(JVERSION, '3.0', 'ge'))
  736. {
  737. $html .= $model->getPagination()->getListFooter();
  738. }
  739. // Close the wrapper element div on Joomla! 3.0+
  740. if (version_compare(JVERSION, '3.0', 'ge'))
  741. {
  742. $html .= "</div>\n";
  743. }
  744. $html .= "\t" . '<input type="hidden" name="option" value="' . $input->getCmd('option') . '" />' . PHP_EOL;
  745. $html .= "\t" . '<input type="hidden" name="view" value="' . FOFInflector::pluralize($input->getCmd('view')) . '" />' . PHP_EOL;
  746. $html .= "\t" . '<input type="hidden" name="task" value="' . $input->getCmd('task', 'browse') . '" />' . PHP_EOL;
  747. // The id field is required in Joomla! 3 front-end to prevent the pagination limit box from screwing it up. Huh!!
  748. if (version_compare(JVERSION, '3.0', 'ge') && FOFPlatform::getInstance()->isFrontend())
  749. {
  750. $html .= "\t" . '<input type="hidden" name="id" value="' . $input->getCmd('id', '') . '" />' . PHP_EOL;
  751. }
  752. $html .= "\t" . '<input type="hidden" name="boxchecked" value="" />' . PHP_EOL;
  753. $html .= "\t" . '<input type="hidden" name="hidemainmenu" value="" />' . PHP_EOL;
  754. $html .= "\t" . '<input type="hidden" name="filter_order" value="' . $filter_order . '" />' . PHP_EOL;
  755. $html .= "\t" . '<input type="hidden" name="filter_order_Dir" value="' . $filter_order_Dir . '" />' . PHP_EOL;
  756. if (FOFPlatform::getInstance()->isFrontend() && ($input->getCmd('Itemid', 0) != 0))
  757. {
  758. $html .= "\t" . '<input type="hidden" name="Itemid" value="' . $input->getCmd('Itemid', 0) . '" />' . PHP_EOL;
  759. }
  760. $html .= "\t" . '<input type="hidden" name="' . JFactory::getSession()->getFormToken() . '" value="1" />' . PHP_EOL;
  761. // End the form
  762. $html .= '</form>' . PHP_EOL;
  763. return $html;
  764. }
  765. /**
  766. * Renders a FOFForm for a Read view and returns the corresponding HTML
  767. *
  768. * @param FOFForm &$form The form to render
  769. * @param FOFModel $model The model providing our data
  770. * @param FOFInput $input The input object
  771. *
  772. * @return string The HTML rendering of the form
  773. */
  774. protected function renderFormRead(FOFForm &$form, FOFModel $model, FOFInput $input)
  775. {
  776. $html = $this->renderFormRaw($form, $model, $input, 'read');
  777. return $html;
  778. }
  779. /**
  780. * Renders a FOFForm for an Edit view and returns the corresponding HTML
  781. *
  782. * @param FOFForm &$form The form to render
  783. * @param FOFModel $model The model providing our data
  784. * @param FOFInput $input The input object
  785. *
  786. * @return string The HTML rendering of the form
  787. */
  788. protected function renderFormEdit(FOFForm &$form, FOFModel $model, FOFInput $input)
  789. {
  790. // Get the key for this model's table
  791. $key = $model->getTable()->getKeyName();
  792. $keyValue = $model->getId();
  793. $html = '';
  794. $validate = strtolower($form->getAttribute('validate'));
  795. if (in_array($validate, array('true', 'yes', '1', 'on')))
  796. {
  797. JHTML::_('behavior.framework', true);
  798. JHTML::_('behavior.formvalidation');
  799. $class = ' form-validate';
  800. $this->loadValidationScript($form);
  801. }
  802. else
  803. {
  804. $class = '';
  805. }
  806. // Check form enctype. Use enctype="multipart/form-data" to upload binary files in your form.
  807. $template_form_enctype = $form->getAttribute('enctype');
  808. if (!empty($template_form_enctype))
  809. {
  810. $enctype = ' enctype="' . $form->getAttribute('enctype') . '" ';
  811. }
  812. else
  813. {
  814. $enctype = '';
  815. }
  816. // Check form name. Use name="yourformname" to modify the name of your form.
  817. $formname = $form->getAttribute('name');
  818. if (empty($formname))
  819. {
  820. $formname = 'adminForm';
  821. }
  822. // Check form ID. Use id="yourformname" to modify the id of your form.
  823. $formid = $form->getAttribute('name');
  824. if (empty($formid))
  825. {
  826. $formid = 'adminForm';
  827. }
  828. $html .= '<form action="index.php" method="post" name="' . $formname .
  829. '" id="' . $formid . '"' . $enctype . ' class="form-horizontal' .
  830. $class . '">' . PHP_EOL;
  831. $html .= "\t" . '<input type="hidden" name="option" value="' . $input->getCmd('option') . '" />' . PHP_EOL;
  832. $html .= "\t" . '<input type="hidden" name="view" value="' . $input->getCmd('view', 'edit') . '" />' . PHP_EOL;
  833. $html .= "\t" . '<input type="hidden" name="task" value="" />' . PHP_EOL;
  834. $html .= "\t" . '<input type="hidden" name="' . $key . '" value="' . $keyValue . '" />' . PHP_EOL;
  835. if (FOFPlatform::getInstance()->isFrontend() && ($input->getCmd('Itemid', 0) != 0))
  836. {
  837. $html .= "\t" . '<input type="hidden" name="Itemid" value="' . $input->getCmd('Itemid', 0) . '" />' . PHP_EOL;
  838. }
  839. $html .= "\t" . '<input type="hidden" name="' . JFactory::getSession()->getFormToken() . '" value="1" />' . PHP_EOL;
  840. $html .= $this->renderFormRaw($form, $model, $input, 'edit');
  841. $html .= '</form>';
  842. return $html;
  843. }
  844. /**
  845. * Renders a raw FOFForm and returns the corresponding HTML
  846. *
  847. * @param FOFForm &$form The form to render
  848. * @param FOFModel $model The model providing our data
  849. * @param FOFInput $input The input object
  850. * @param string $formType The form type e.g. 'edit' or 'read'
  851. *
  852. * @return string The HTML rendering of the form
  853. */
  854. protected function renderFormRaw(FOFForm &$form, FOFModel $model, FOFInput $input, $formType)
  855. {
  856. $html = '';
  857. foreach ($form->getFieldsets() as $fieldset)
  858. {
  859. $fields = $form->getFieldset($fieldset->name);
  860. if (isset($fieldset->class))
  861. {
  862. $class = 'class="' . $fieldset->class . '"';
  863. }
  864. else
  865. {
  866. $class = '';
  867. }
  868. $html .= "\t" . '<div id="' . $fieldset->name . '" ' . $class . '>' . PHP_EOL;
  869. if (isset($fieldset->label) && !empty($fieldset->label))
  870. {
  871. $html .= "\t\t" . '<h3>' . JText::_($fieldset->label) . '</h3>' . PHP_EOL;
  872. }
  873. foreach ($fields as $field)
  874. {
  875. $required = $field->required;
  876. $labelClass = $field->labelClass;
  877. $groupClass = $form->getFieldAttribute($field->fieldname, 'groupclass', '', $field->group);
  878. // Auto-generate label and description if needed
  879. // Field label
  880. $title = $form->getFieldAttribute($field->fieldname, 'label', '', $field->group);
  881. $emptylabel = $form->getFieldAttribute($field->fieldname, 'emptylabel', false, $field->group);
  882. if (empty($title) && !$emptylabel)
  883. {
  884. $model->getName();
  885. $title = strtoupper($input->get('option') . '_' . $model->getName() . '_' . $field->id . '_LABEL');
  886. }
  887. // Field description
  888. $description = $form->getFieldAttribute($field->fieldname, 'description', '', $field->group);
  889. /**
  890. * The following code is backwards incompatible. Most forms don't require a description in their form
  891. * fields. Having to use emptydescription="1" on each one of them is an overkill. Removed.
  892. */
  893. /*
  894. $emptydescription = $form->getFieldAttribute($field->fieldname, 'emptydescription', false, $field->group);
  895. if (empty($description) && !$emptydescription)
  896. {
  897. $description = strtoupper($input->get('option') . '_' . $model->getName() . '_' . $field->id . '_DESC');
  898. }
  899. */
  900. if ($formType == 'read')
  901. {
  902. $inputField = $field->static;
  903. }
  904. elseif ($formType == 'edit')
  905. {
  906. $inputField = $field->input;
  907. }
  908. if (empty($title))
  909. {
  910. $html .= "\t\t\t" . $inputField . PHP_EOL;
  911. if (!empty($description) && $formType == 'edit')
  912. {
  913. $html .= "\t\t\t\t" . '<span class="help-block">';
  914. $html .= JText::_($description) . '</span>' . PHP_EOL;
  915. }
  916. }
  917. else
  918. {
  919. $html .= "\t\t\t" . '<div class="control-group ' . $groupClass . '">' . PHP_EOL;
  920. $html .= "\t\t\t\t" . '<label class="control-label ' . $labelClass . '" for="' . $field->id . '">' . PHP_EOL;
  921. $html .= "\t\t\t\t" . JText::_($title) . PHP_EOL;
  922. if ($required)
  923. {
  924. $html .= ' *';
  925. }
  926. $html .= "\t\t\t\t" . '</label>' . PHP_EOL;
  927. $html .= "\t\t\t\t" . '<div class="controls">' . PHP_EOL;
  928. $html .= "\t\t\t\t" . $inputField . PHP_EOL;
  929. if (!empty($description))
  930. {
  931. $html .= "\t\t\t\t" . '<span class="help-block">';
  932. $html .= JText::_($description) . '</span>' . PHP_EOL;
  933. }
  934. $html .= "\t\t\t\t" . '</div>' . PHP_EOL;
  935. $html .= "\t\t\t" . '</div>' . PHP_EOL;
  936. }
  937. }
  938. $html .= "\t" . '</div>' . PHP_EOL;
  939. }
  940. return $html;
  941. }
  942. }