Source for file joomla.php

Documentation is available at joomla.php

  1. <?php
  2. /**
  3.  * @package     FrameworkOnFramework
  4.  * @subpackage  render
  5.  * @copyright   Copyright (C) 2010 - 2012 Akeeba Ltd. All rights reserved.
  6.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  7.  */
  8. defined('_JEXEC'or die;
  9.  
  10. /**
  11.  * Default Joomla! 1.5, 1.7, 2.5 view renderer class
  12.  *
  13.  * @package  FrameworkOnFramework
  14.  * @since    2.0
  15.  */
  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     = 50;
  23.         $this->enabled     = true;
  24.     }
  25.  
  26.     /**
  27.      * Echoes any HTML to show before the view template
  28.      *
  29.      * @param   string    $view    The current view
  30.      * @param   string    $task    The current task
  31.      * @param   FOFInput  $input   The input array (request parameters)
  32.      * @param   array     $config  The view configuration array
  33.      *
  34.      * @return  void 
  35.      */
  36.     public function preRender($view$task$input$config array())
  37.     {
  38.         $format     $input->getCmd('format''html');
  39.  
  40.         if (empty($format))
  41.         {
  42.             $format     'html';
  43.         }
  44.  
  45.         if ($format != 'html')
  46.         {
  47.             return;
  48.         }
  49.  
  50.         if (!FOFPlatform::getInstance()->isCli())
  51.         {
  52.             // Wrap output in a Joomla-versioned div
  53.             $version new JVersion;
  54.             $version str_replace('.'''$version->RELEASE);
  55.             echo "<div class=\"joomla-version-$version\">\n";
  56.         }
  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.     /**
  67.      * Echoes any HTML to show after the view template
  68.      *
  69.      * @param   string    $view    The current view
  70.      * @param   string    $task    The current task
  71.      * @param   FOFInput  $input   The input array (request parameters)
  72.      * @param   array     $config  The view configuration array
  73.      *
  74.      * @return  void 
  75.      */
  76.     public function postRender($view$task$input$config array())
  77.     {
  78.         $format     $input->getCmd('format''html');
  79.  
  80.         if (empty($format))
  81.         {
  82.             $format     'html';
  83.         }
  84.  
  85.         if ($format != 'html')
  86.         {
  87.             return;
  88.         }
  89.  
  90.         // Closing tag only if we're not in CLI
  91.         if (FOFPlatform::getInstance()->isCli())
  92.         {
  93.             return;
  94.         }
  95.  
  96.         echo "</div>\n";
  97.     }
  98.  
  99.     /**
  100.      * Renders a FOFForm for a Browse view and returns the corresponding HTML
  101.      *
  102.      * @param   FOFForm   &$form  The form to render
  103.      * @param   FOFModel  $model  The model providing our data
  104.      * @param   FOFInput  $input  The input object
  105.      *
  106.      * @return  string    The HTML rendering of the form
  107.      */
  108.     protected function renderFormBrowse(FOFForm &$formFOFModel $modelFOFInput $input)
  109.     {
  110.         JHtml::_('behavior.multiselect');
  111.  
  112.         // Getting all header row elements
  113.         $headerFields $form->getHeaderset();
  114.  
  115.         // Start the form
  116.         $html                 '';
  117.         $filter_order         $form->getView()->getLists()->order;
  118.         $filter_order_Dir     $form->getView()->getLists()->order_Dir;
  119.  
  120.         $html .= '<form action="index.php" method="post" name="adminForm" id="adminForm">' PHP_EOL;
  121.         $html .= "\t" '<input type="hidden" name="option" value="' $input->getCmd('option''" />' PHP_EOL;
  122.         $html .= "\t" '<input type="hidden" name="view" value="' FOFInflector::pluralize($input->getCmd('view')) '" />' PHP_EOL;
  123.         $html .= "\t" '<input type="hidden" name="task" value="" />' PHP_EOL;
  124.         $html .= "\t" '<input type="hidden" name="boxchecked" value="" />' PHP_EOL;
  125.         $html .= "\t" '<input type="hidden" name="hidemainmenu" value="" />' PHP_EOL;
  126.         $html .= "\t" '<input type="hidden" name="filter_order" value="' $filter_order '" />' PHP_EOL;
  127.         $html .= "\t" '<input type="hidden" name="filter_order_Dir" value="' $filter_order_Dir '" />' PHP_EOL;
  128.         $html .= "\t" '<input type="hidden" name="' JFactory::getSession()->getFormToken('" value="1" />' PHP_EOL;
  129.  
  130.         // Start the table output
  131.         $html .= "\t\t" '<table class="adminlist" id="adminList">' PHP_EOL;
  132.  
  133.         // Get form parameters
  134.         $show_header         $form->getAttribute('show_header'1);
  135.         $show_filters         $form->getAttribute('show_filters'1);
  136.         $show_pagination     $form->getAttribute('show_pagination'1);
  137.         $norows_placeholder     $form->getAttribute('norows_placeholder''');
  138.  
  139.         // Open the table header region if required
  140.         if ($show_header || $show_filters)
  141.         {
  142.             $html .= "\t\t\t<thead>" PHP_EOL;
  143.         }
  144.  
  145.         // Pre-render the header and filter rows
  146.         if ($show_header || $show_filters)
  147.         {
  148.             $header_html '';
  149.             $filter_html '';
  150.  
  151.             foreach ($headerFields as $header)
  152.             {
  153.                 // Make sure we have a header field. Under Joomla! 2.5 we cannot
  154.                 // render filter-only fields.
  155.                 $tmpHeader $header->header;
  156.  
  157.                 if (empty($tmpHeader))
  158.                 {
  159.                     continue;
  160.                 }
  161.  
  162.                 $tdwidth $header->tdwidth;
  163.  
  164.                 if (!empty($tdwidth))
  165.                 {
  166.                     $tdwidth 'width="' $tdwidth '"';
  167.                 }
  168.                 else
  169.                 {
  170.                     $tdwidth '';
  171.                 }
  172.  
  173.                 $header_html .= "\t\t\t\t\t<th $tdwidth>PHP_EOL;
  174.                 $header_html .= "\t\t\t\t\t\t" $tmpHeader;
  175.                 $header_html .= "\t\t\t\t\t</th>" PHP_EOL;
  176.  
  177.                 $filter     $header->filter;
  178.                 $buttons $header->buttons;
  179.                 $options $header->options;
  180.  
  181.                 $filter_html .= "\t\t\t\t\t<td>" PHP_EOL;
  182.  
  183.                 if (!empty($filter))
  184.                 {
  185.                     $filter_html .= "\t\t\t\t\t\t$filterPHP_EOL;
  186.  
  187.                     if (!empty($buttons))
  188.                     {
  189.                         $filter_html .= "\t\t\t\t\t\t<nobr>$buttons</nobr>PHP_EOL;
  190.                     }
  191.                 }
  192.                 elseif (!empty($options))
  193.                 {
  194.                     $label         $header->label;
  195.                     $emptyOption JHtml::_('select.option''''- ' JText::_($label' -');
  196.                     array_unshift($options$emptyOption);
  197.                     $attribs     array(
  198.                         'onchange' => 'document.adminForm.submit();'
  199.                     );
  200.                     $filter         JHtml::_('select.genericlist'$options$header->name$attribs'value''text'$header->valuefalsetrue);
  201.                     $filter_html .= "\t\t\t\t\t\t$filterPHP_EOL;
  202.                 }
  203.  
  204.                 $filter_html .= "\t\t\t\t\t</td>" PHP_EOL;
  205.             }
  206.         }
  207.  
  208.         // Render header if enabled
  209.         if ($show_header)
  210.         {
  211.             $html .= "\t\t\t\t<tr>" PHP_EOL;
  212.             $html .= $header_html;
  213.             $html .= "\t\t\t\t</tr>" PHP_EOL;
  214.         }
  215.  
  216.         // Render filter row if enabled
  217.         if ($show_filters)
  218.         {
  219.             $html .= "\t\t\t\t<tr>";
  220.             $html .= $filter_html;
  221.             $html .= "\t\t\t\t</tr>";
  222.         }
  223.  
  224.         // Close the table header region if required
  225.         if ($show_header || $show_filters)
  226.         {
  227.             $html .= "\t\t\t</thead>" PHP_EOL;
  228.         }
  229.  
  230.         // Loop through rows and fields, or show placeholder for no rows
  231.         $html .= "\t\t\t<tbody>" PHP_EOL;
  232.         $fields         $form->getFieldset('items');
  233.         $num_columns count($fields);
  234.         $items         $form->getModel()->getItemList();
  235.  
  236.         if ($count count($items))
  237.         {
  238.             $m 1;
  239.  
  240.             foreach ($items as $i => $item)
  241.             {
  242.                 $table_item $form->getModel()->getTable();
  243.                 $table_item->reset();
  244.                 $table_item->bind($item);
  245.  
  246.                 $form->bind($item);
  247.  
  248.                 $m         $m;
  249.                 $class     'row' $m;
  250.  
  251.                 $html .= "\t\t\t\t<tr class=\"$class\">PHP_EOL;
  252.  
  253.                 $fields $form->getFieldset('items');
  254.  
  255.                 foreach ($fields as $field)
  256.                 {
  257.                     $field->rowid     $i;
  258.                     $field->item     $table_item;
  259.                     $class             $field->labelClass 'class ="' $field->labelClass '"' '';
  260.                     $html .= "\t\t\t\t\t<td $class>$field->getRepeatable('</td>' PHP_EOL;
  261.                 }
  262.  
  263.                 $html .= "\t\t\t\t</tr>" PHP_EOL;
  264.             }
  265.         }
  266.         elseif ($norows_placeholder)
  267.         {
  268.             $html .= "\t\t\t\t<tr><td colspan=\"$num_columns\">";
  269.             $html .= JText::_($norows_placeholder);
  270.             $html .= "</td></tr>\n";
  271.         }
  272.  
  273.         $html .= "\t\t\t</tbody>" PHP_EOL;
  274.  
  275.         // Render the pagination bar, if enabled
  276.  
  277.         if ($show_pagination)
  278.         {
  279.             $pagination $form->getModel()->getPagination();
  280.             $html .= "\t\t\t<tfoot>" PHP_EOL;
  281.             $html .= "\t\t\t\t<tr><td colspan=\"$num_columns\">";
  282.  
  283.             if (($pagination->total 0))
  284.             {
  285.                 $html .= $pagination->getListFooter();
  286.             }
  287.  
  288.             $html .= "</td></tr>\n";
  289.             $html .= "\t\t\t</tfoot>" PHP_EOL;
  290.         }
  291.  
  292.         // End the table output
  293.         $html .= "\t\t" '</table>' PHP_EOL;
  294.  
  295.         // End the form
  296.         $html .= '</form>' PHP_EOL;
  297.  
  298.         return $html;
  299.     }
  300.  
  301.     /**
  302.      * Renders a FOFForm for a Read view and returns the corresponding HTML
  303.      *
  304.      * @param   FOFForm   &$form  The form to render
  305.      * @param   FOFModel  $model  The model providing our data
  306.      * @param   FOFInput  $input  The input object
  307.      *
  308.      * @return  string    The HTML rendering of the form
  309.      */
  310.     protected function renderFormRead(FOFForm &$formFOFModel $modelFOFInput $input)
  311.     {
  312.         $html $this->renderFormRaw($form$model$input'read');
  313.  
  314.         return $html;
  315.     }
  316.  
  317.     /**
  318.      * Renders a FOFForm for an Edit view and returns the corresponding HTML
  319.      *
  320.      * @param   FOFForm   &$form  The form to render
  321.      * @param   FOFModel  $model  The model providing our data
  322.      * @param   FOFInput  $input  The input object
  323.      *
  324.      * @return  string    The HTML rendering of the form
  325.      */
  326.     protected function renderFormEdit(FOFForm &$formFOFModel $modelFOFInput $input)
  327.     {
  328.         // Get the key for this model's table
  329.         $key         $model->getTable()->getKeyName();
  330.         $keyValue     $model->getId();
  331.  
  332.         JHTML::_('behavior.tooltip');
  333.  
  334.         $html '';
  335.  
  336.         $validate     strtolower($form->getAttribute('validate'));
  337.         $class         '';
  338.  
  339.         if (in_array($validatearray('true''yes''1''on')))
  340.         {
  341.             JHTML::_('behavior.framework'true);
  342.             JHTML::_('behavior.formvalidation');
  343.             $class 'form-validate ';
  344.             $this->loadValidationScript($form);
  345.         }
  346.  
  347.         // Check form enctype. Use enctype="multipart/form-data" to upload binary files in your form.
  348.         $template_form_enctype $form->getAttribute('enctype');
  349.  
  350.         if (!empty($template_form_enctype))
  351.         {
  352.             $enctype ' enctype="' $form->getAttribute('enctype''" ';
  353.         }
  354.         else
  355.         {
  356.             $enctype '';
  357.         }
  358.  
  359.         // Check form name. Use name="yourformname" to modify the name of your form.
  360.         $formname $form->getAttribute('name');
  361.  
  362.         if (empty($formname))
  363.         {
  364.             $formname 'adminForm';
  365.         }
  366.  
  367.         // Check form ID. Use id="yourformname" to modify the id of your form.
  368.         $formid $form->getAttribute('name');
  369.  
  370.         if (empty($formid))
  371.         {
  372.             $formid 'adminForm';
  373.         }
  374.  
  375.         $html .= '<form action="index.php" method="post" name="' $formname .
  376.             '" id="' $formid '"' $enctype ' class="' $class .
  377.             '">' PHP_EOL;
  378.         $html .= "\t" '<input type="hidden" name="option" value="' $input->getCmd('option''" />' PHP_EOL;
  379.         $html .= "\t" '<input type="hidden" name="view" value="' $input->getCmd('view''edit''" />' PHP_EOL;
  380.         $html .= "\t" '<input type="hidden" name="task" value="" />' PHP_EOL;
  381.  
  382.         $html .= "\t" '<input type="hidden" name="' $key '" value="' $keyValue '" />' PHP_EOL;
  383.         $html .= "\t" '<input type="hidden" name="' JFactory::getSession()->getFormToken('" value="1" />' PHP_EOL;
  384.  
  385.         $html .= $this->renderFormRaw($form$model$input'edit');
  386.         $html .= '</form>';
  387.  
  388.         return $html;
  389.     }
  390.  
  391.     /**
  392.      * Renders a raw FOFForm and returns the corresponding HTML
  393.      *
  394.      * @param   FOFForm   &$form     The form to render
  395.      * @param   FOFModel  $model     The model providing our data
  396.      * @param   FOFInput  $input     The input object
  397.      * @param   string    $formType  The form type e.g. 'edit' or 'read'
  398.      *
  399.      * @return  string    The HTML rendering of the form
  400.      */
  401.     protected function renderFormRaw(FOFForm &$formFOFModel $modelFOFInput $input$formType)
  402.     {
  403.         $html '';
  404.  
  405.         foreach ($form->getFieldsets(as $fieldset)
  406.         {
  407.             $fields $form->getFieldset($fieldset->name);
  408.  
  409.             if (isset($fieldset->class))
  410.             {
  411.                 $class 'class="' $fieldset->class '"';
  412.             }
  413.             else
  414.             {
  415.                 $class '';
  416.             }
  417.  
  418.             $element empty($fields'div' 'fieldset';
  419.             $html .= "\t" '<' $element ' id="' $fieldset->name '" ' $class '>' PHP_EOL;
  420.  
  421.             if (isset($fieldset->label&& !empty($fieldset->label))
  422.             {
  423.                 $html .= "\t\t" '<h3>' JText::_($fieldset->label'</h3>' PHP_EOL;
  424.             }
  425.  
  426.             foreach ($fields as $field)
  427.             {
  428.                 $label     $field->label;
  429.  
  430.                 $html .= "<div class=\"fof-row\">";
  431.  
  432.                 if (!is_null($label))
  433.                 {
  434.                     $html .= "\t\t\t" $label PHP_EOL;
  435.                 }
  436.  
  437.                 if ($formType == 'read')
  438.                 {
  439.                     $html .= "\t\t\t" $field->static PHP_EOL;
  440.                 }
  441.                 elseif ($formType == 'edit')
  442.                 {
  443.                     $html .= "\t\t\t" $field->input PHP_EOL;
  444.                 }
  445.  
  446.                 $html .= "</div>";
  447.             }
  448.  
  449.             $element empty($fields'div' 'fieldset';
  450.             $html .= "\t" '</' $element '>' PHP_EOL;
  451.         }
  452.  
  453.         return $html;
  454.     }
  455.  
  456.     /**
  457.      * Loads the validation script for an edit form
  458.      *
  459.      * @param   FOFForm  &$form  The form we are rendering
  460.      *
  461.      * @return  void 
  462.      */
  463.     protected function loadValidationScript(FOFForm &$form)
  464.     {
  465.         $message $form->getView()->escape(JText::_('JGLOBAL_VALIDATION_FORM_FAILED'));
  466.  
  467.         $js = <<<ENDJAVASCRIPT
  468.         Joomla.submitbutton = function(task)
  469.         {
  470.             if (task == 'cancel' || document.formvalidator.isValid(document.id('adminForm')))
  471.             {
  472.                 Joomla.submitform(task, document.getElementById('adminForm'));
  473.             }
  474.             else {
  475.                 alert('$message');
  476.             }
  477.         }
  478. ENDJAVASCRIPT;
  479.  
  480.         $document FOFPlatform::getInstance()->getDocument();
  481.  
  482.         if ($document instanceof JDocument)
  483.         {
  484.             $document->addScriptDeclaration($js);
  485.         }
  486.     }
  487.  
  488.     /**
  489.      * Renders the submenu (link bar)
  490.      *
  491.      * @param   string    $view    The active view name
  492.      * @param   string    $task    The current task
  493.      * @param   FOFInput  $input   The input object
  494.      * @param   array     $config  Extra configuration variables for the toolbar
  495.      *
  496.      * @return  void 
  497.      */
  498.     protected function renderLinkbar($view$task$input$config array())
  499.     {
  500.         // On command line don't do anything
  501.  
  502.         if (FOFPlatform::getInstance()->isCli())
  503.         {
  504.             return;
  505.         }
  506.  
  507.         // Do not render a submenu unless we are in the the admin area
  508.         $toolbar                 FOFToolbar::getAnInstance($input->getCmd('option''com_foobar')$config);
  509.         $renderFrontendSubmenu     $toolbar->getRenderFrontendSubmenu();
  510.  
  511.         if (!FOFPlatform::getInstance()->isBackend(&& !$renderFrontendSubmenu)
  512.         {
  513.             return;
  514.         }
  515.  
  516.         $this->renderLinkbarItems($toolbar);
  517.     }
  518.  
  519.     /**
  520.      * do the rendering job for the linkbar
  521.      *
  522.      * @param   FOFToolbar  $toolbar  A toolbar object
  523.      *
  524.      * @return  void 
  525.      */
  526.     protected function renderLinkbarItems($toolbar)
  527.     {
  528.         $links $toolbar->getLinks();
  529.  
  530.         if (!empty($links))
  531.         {
  532.             foreach ($links as $link)
  533.             {
  534.                 JSubMenuHelper::addEntry($link['name']$link['link']$link['active']);
  535.             }
  536.         }
  537.     }
  538.  
  539.     /**
  540.      * Renders the toolbar buttons
  541.      *
  542.      * @param   string    $view    The active view name
  543.      * @param   string    $task    The current task
  544.      * @param   FOFInput  $input   The input object
  545.      * @param   array     $config  Extra configuration variables for the toolbar
  546.      *
  547.      * @return  void 
  548.      */
  549.     protected function renderButtons($view$task$input$config array())
  550.     {
  551.         // On command line don't do anything
  552.  
  553.         if (FOFPlatform::getInstance()->isCli())
  554.         {
  555.             return;
  556.         }
  557.  
  558.         // Do not render buttons unless we are in the the frontend area and we are asked to do so
  559.         $toolbar                 FOFToolbar::getAnInstance($input->getCmd('option''com_foobar')$config);
  560.         $renderFrontendButtons     $toolbar->getRenderFrontendButtons();
  561.  
  562.         if (FOFPlatform::getInstance()->isBackend(|| !$renderFrontendButtons)
  563.         {
  564.             return;
  565.         }
  566.  
  567.         // Load main backend language, in order to display toolbar strings
  568.         // (JTOOLBAR_BACK, JTOOLBAR_PUBLISH etc etc)
  569.         FOFPlatform::getInstance()->loadTranslations('joomla');
  570.  
  571.         $title     JFactory::getApplication()->get('JComponentTitle');
  572.         $bar     JToolBar::getInstance('toolbar');
  573.  
  574.         // Delete faux links, since if SEF is on, Joomla will follow the link instead of submitting the form
  575.         $bar_content str_replace('href="#"'''$bar->render());
  576.  
  577.         echo '<div id="FOFHeaderHolder">'$bar_content$title'<div style="clear:both"></div>''</div>';
  578.     }
  579. }

Documentation generated on Tue, 19 Nov 2013 15:06:12 +0100 by phpDocumentor 1.4.3