private function setToolbarTitle() { $subtitle_key = FOFInput::getCmd('option', 'com_overload', $this->input). '_TITLE_'.strtoupper(FOFInput::getCmd('view', '', $this->input)); JToolBarHelper::title( JText::_( FOFInput::getCmd('option', 'com_overload', $this->input)). ' – <small>'.JText::_($subtitle_key).'</small>', 'generic.png'); }
/** * * @staticvar array $instances * @param type $option * @param type $view * @param type $config * @return FOFToolbar */ public static function &getAnInstance($option = null, $config = array()) { static $instances = array(); // Make sure $config is an array if (is_object($config)) { $config = (array) $config; } elseif (!is_array($config)) { $config = array(); } $hash = $option; if (!array_key_exists($hash, $instances)) { if (array_key_exists('input', $config)) { if ($config['input'] instanceof FOFInput) { $input = $config['input']; } else { $input = new FOFInput($config['input']); } } else { $input = new FOFInput(); } $config['option'] = !is_null($option) ? $option : $input->getCmd('option', 'com_foobar'); $input->set('option', $config['option']); $config['input'] = $input; $className = ucfirst(str_replace('com_', '', $config['option'])) . 'Toolbar'; if (!class_exists($className)) { list($isCli, $isAdmin) = FOFDispatcher::isCliAdmin(); if ($isAdmin) { $basePath = JPATH_ADMINISTRATOR; } elseif ($isCli) { $basePath = JPATH_ROOT; } else { $basePath = JPATH_SITE; } $searchPaths = array($basePath . '/components/' . $config['option'], $basePath . '/components/' . $config['option'] . '/toolbars', JPATH_ADMINISTRATOR . '/components/' . $config['option'], JPATH_ADMINISTRATOR . '/components/' . $config['option'] . '/toolbars'); if (array_key_exists('searchpath', $config)) { array_unshift($searchPaths, $config['searchpath']); } JLoader::import('joomla.filesystem.path'); $path = JPath::find($searchPaths, 'toolbar.php'); if ($path) { require_once $path; } } if (!class_exists($className)) { $className = 'FOFToolbar'; } $instance = new $className($config); $instances[$hash] = $instance; } return $instances[$hash]; }
/** * Echoes any HTML to show before the view template * * @param string $view The current view * @param string $task The current task * @param FOFInput $input The input array (request parameters) * @param array $config The view configuration array * * @return void */ public function preRender($view, $task, $input, $config = array()) { $format = $input->getCmd('format', 'html'); if (empty($format)) { $format = 'html'; } if ($format != 'html') { return; } // Render the submenu and toolbar if ($input->getBool('render_toolbar', true)) { $this->renderButtons($view, $task, $input, $config); $this->renderLinkbar($view, $task, $input, $config); } }
/** * Echoes any HTML to show after the view template * * @param string $view The current view * @param string $task The current task * @param FOFInput $input The input array (request parameters) * @param array $config The view configuration array * * @return void */ public function postRender($view, $task, $input, $config = array()) { $format = $input->getCmd('format', 'html'); if (empty($format)) { $format = 'html'; } if ($format != 'html') { return; } // Closing tag only if we're not in CLI if (FOFPlatform::getInstance()->isCli()) { return; } echo "</div>\n"; // Closes akeeba-renderjoomla div }
/** * Gets an instance of a component's toolbar * * @param string $option The name of the component * @param array $config The configuration array for the component * * @return FOFToolbar The toolbar instance for the component */ public static function &getAnInstance($option = null, $config = array()) { static $instances = array(); // Make sure $config is an array if (is_object($config)) { $config = (array) $config; } elseif (!is_array($config)) { $config = array(); } $hash = $option; if (!array_key_exists($hash, $instances)) { if (array_key_exists('input', $config)) { if ($config['input'] instanceof FOFInput) { $input = $config['input']; } else { $input = new FOFInput($config['input']); } } else { $input = new FOFInput(); } $config['option'] = !is_null($option) ? $option : $input->getCmd('option', 'com_foobar'); $input->set('option', $config['option']); $config['input'] = $input; $className = ucfirst(str_replace('com_', '', $config['option'])) . 'Toolbar'; if (!class_exists($className)) { $componentPaths = FOFPlatform::getInstance()->getComponentBaseDirs($config['option']); $searchPaths = array($componentPaths['main'], $componentPaths['main'] . '/toolbars', $componentPaths['alt'], $componentPaths['alt'] . '/toolbars'); if (array_key_exists('searchpath', $config)) { array_unshift($searchPaths, $config['searchpath']); } JLoader::import('joomla.filesystem.path'); $path = JPath::find($searchPaths, 'toolbar.php'); if ($path) { require_once $path; } } if (!class_exists($className)) { $className = 'FOFToolbar'; } $instance = new $className($config); $instances[$hash] = $instance; } return $instances[$hash]; }
/** * Guesses the best candidate for the path to use for a particular form. * * @param string $source The name of the form file to load, without the .xml extension. * @param array $paths The paths to look into. You can declare this to override the default FOF paths. * * @return mixed A string if the path and filename of the form to load is found, false otherwise. * * @since 2.0 */ public function findFormFilename($source, $paths = array()) { // TODO Should we read from internal variables instead of the input? With a temp instance we have no input $option = $this->input->getCmd('option', 'com_foobar'); $view = $this->name; $componentPaths = FOFPlatform::getInstance()->getComponentBaseDirs($option); $file_root = $componentPaths['main']; $alt_file_root = $componentPaths['alt']; $template_root = FOFPlatform::getInstance()->getTemplateOverridePath($option); if (empty($paths)) { // Set up the paths to look into // PLEASE NOTE: If you ever change this, please update Model Unit tests, too, since we have to // copy these default folders (we have to add the protocol for the virtual filesystem) $paths = array($template_root . '/' . $view, $template_root . '/' . FOFInflector::singularize($view), $template_root . '/' . FOFInflector::pluralize($view), $file_root . '/views/' . $view . '/tmpl', $file_root . '/views/' . FOFInflector::singularize($view) . '/tmpl', $file_root . '/views/' . FOFInflector::pluralize($view) . '/tmpl', $alt_file_root . '/views/' . $view . '/tmpl', $alt_file_root . '/views/' . FOFInflector::singularize($view) . '/tmpl', $alt_file_root . '/views/' . FOFInflector::pluralize($view) . '/tmpl', $file_root . '/models/forms', $alt_file_root . '/models/forms'); } $paths = array_unique($paths); // Set up the suffixes to look into $suffixes = array(); $temp_suffixes = FOFPlatform::getInstance()->getTemplateSuffixes(); if (!empty($temp_suffixes)) { foreach ($temp_suffixes as $suffix) { $suffixes[] = $suffix . '.xml'; } } $suffixes[] = '.xml'; // Look for all suffixes in all paths $result = false; $filesystem = FOFPlatform::getInstance()->getIntegrationObject('filesystem'); foreach ($paths as $path) { foreach ($suffixes as $suffix) { $filename = $path . '/' . $source . $suffix; if ($filesystem->fileExists($filename)) { $result = $filename; break; } } if ($result) { break; } } return $result; }
/** * Gets a URL suffix with the Itemid parameter. If it's not the front-end of the site, or if * there is no Itemid set it returns an empty string. * * @return string The &Itemid=123 URL suffix, or an empty string if Itemid is not applicable */ public function getItemidURLSuffix() { if (FOFPlatform::getInstance()->isFrontend() && $this->input->getCmd('Itemid', 0) != 0) { return '&Itemid=' . $this->input->getInt('Itemid', 0); } else { return ''; } }
/** * Gets a temporary instance of a controller object. A temporary instance is * not a Singleton and can be disposed off after use. * * @param string $option The component name, e.g. com_foobar * @param string $view The view name, e.g. cpanel * @param array $config Configuration parameters * * @return \className A disposable class instance */ public static function &getTmpInstance($option = null, $view = null, $config = array()) { // Make sure $config is an array if (is_object($config)) { $config = (array) $config; } elseif (!is_array($config)) { $config = array(); } // Get an input object if (array_key_exists('input', $config)) { $input = $config['input']; } else { $input = null; } if (array_key_exists('input_options', $config)) { $input_options = $config['input_options']; } else { $input_options = array(); } if (!$input instanceof FOFInput) { $input = new FOFInput($input, $input_options); } // Determine the option (component name) and view $config['option'] = !is_null($option) ? $option : $input->getCmd('option', 'com_foobar'); $config['view'] = !is_null($view) ? $view : $input->getCmd('view', 'cpanel'); // Get the class base name, e.g. FoobarController $classBaseName = ucfirst(str_replace('com_', '', $config['option'])) . 'Controller'; // Get the class name suffixes, in the order to be searched for: plural, singular, 'default' $classSuffixes = array(FOFInflector::pluralize($config['view']), FOFInflector::singularize($config['view']), 'default'); // Initialise the base path for performance reasons list($isCli, $isAdmin) = FOFDispatcher::isCliAdmin(); if ($isAdmin) { $basePath = JPATH_ADMINISTRATOR; } elseif ($isCli) { $basePath = JPATH_ROOT; } else { $basePath = JPATH_SITE; } JLoader::import('joomla.filesystem.path'); // Look for the best classname match foreach ($classSuffixes as $suffix) { $className = $classBaseName . ucfirst($suffix); if (class_exists($className)) { // The class is already loaded. We have a match! break; } // The class is not already loaded. Try to find and load it. $searchPaths = array($basePath . '/components/' . $config['option'] . '/controllers', JPATH_ADMINISTRATOR . '/components/' . $config['option'] . '/controllers'); // If we have a searchpath in the configuration please search it first if (array_key_exists('searchpath', $config)) { array_unshift($searchPaths, $config['searchpath']); } else { $configProvider = new FOFConfigProvider(); $searchPath = $configProvider->get($config['option'] . '.views.' . FOFInflector::singularize($config['view']) . '.config.searchpath', null); if ($searchPath) { array_unshift($searchPaths, JPATH_ADMINISTRATOR . '/components/' . $config['option'] . '/' . $searchPath); array_unshift($searchPaths, $basePath . '/components/' . $config['option'] . '/' . $searchPath); } } // Try to find the path to this file. First try to find the // format-specific controller file, e.g. foobar.json.php for // format=json, then the regular one-size-fits-all controller $format = $input->getCmd('format', 'html'); $path = null; if (!empty($format)) { $path = JPath::find($searchPaths, strtolower($suffix) . '.' . strtolower($format) . '.php'); } if (!$path) { $path = JPath::find($searchPaths, strtolower($suffix) . '.php'); } // The path is found. Load the file and make sure the expected class name exists. if ($path) { require_once $path; if (class_exists($className)) { // The class was loaded successfully. We have a match! break; } } } if (!class_exists($className)) { // If no specialised class is found, instantiate the generic FOFController $className = 'FOFController'; } $instance = new $className($config); return $instance; }
/** * Renders a FOFForm for an Edit view and returns the corresponding HTML * * @param FOFForm &$form The form to render * @param FOFModel $model The model providing our data * @param FOFInput $input The input object * * @return string The HTML rendering of the form */ protected function renderFormEdit(FOFForm &$form, FOFModel $model, FOFInput $input) { // Get the key for this model's table $key = $model->getTable()->getKeyName(); $keyValue = $model->getId(); $html = ''; $validate = strtolower($form->getAttribute('validate')); if (in_array($validate, array('true', 'yes', '1', 'on'))) { JHTML::_('behavior.framework', true); JHTML::_('behavior.formvalidation'); $class = ' form-validate'; $this->loadValidationScript($form); } else { $class = ''; } // Check form enctype. Use enctype="multipart/form-data" to upload binary files in your form. $template_form_enctype = $form->getAttribute('enctype'); if (!empty($template_form_enctype)) { $enctype = ' enctype="' . $form->getAttribute('enctype') . '" '; } else { $enctype = ''; } // Check form name. Use name="yourformname" to modify the name of your form. $formname = $form->getAttribute('name'); if (empty($formname)) { $formname = 'adminForm'; } // Check form ID. Use id="yourformname" to modify the id of your form. $formid = $form->getAttribute('name'); if (empty($formid)) { $formid = 'adminForm'; } $html .= '<form action="index.php" method="post" name="' . $formname . '" id="' . $formid . '"' . $enctype . ' class="form-horizontal' . $class . '">' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="option" value="' . $input->getCmd('option') . '" />' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="view" value="' . $input->getCmd('view', 'edit') . '" />' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="task" value="" />' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="' . $key . '" value="' . $keyValue . '" />' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="' . JFactory::getSession()->getFormToken() . '" value="1" />' . PHP_EOL; $html .= $this->renderFormRaw($form, $model, $input, 'edit'); $html .= '</form>'; return $html; }
/** * Renders the toolbar buttons * * @param string $view The active view name * @param string $task The current task * @param FOFInput $input The input object * @param array $config Extra configuration variables for the toolbar * * @return void */ protected function renderButtons($view, $task, $input, $config = array()) { // On command line don't do anything if (FOFPlatform::getInstance()->isCli()) { return; } // Do not render buttons unless we are in the the frontend area and we are asked to do so $toolbar = FOFToolbar::getAnInstance($input->getCmd('option', 'com_foobar'), $config); $renderFrontendButtons = $toolbar->getRenderFrontendButtons(); if (FOFPlatform::getInstance()->isBackend() || !$renderFrontendButtons) { return; } // Load main backend language, in order to display toolbar strings // (JTOOLBAR_BACK, JTOOLBAR_PUBLISH etc etc) FOFPlatform::getInstance()->loadTranslations('joomla'); $title = JFactory::getApplication()->get('JComponentTitle'); $bar = JToolBar::getInstance('toolbar'); // Delete faux links, since if SEF is on, Joomla will follow the link instead of submitting the form $bar_content = str_replace('href="#"', '', $bar->render()); echo '<div id="FOFHeaderHolder">', $bar_content, $title, '<div style="clear:both"></div>', '</div>'; }
/** * Generic check for whether dependencies exist for this object in the db schema * * @param integer $oid The primary key of the record to delete * @param array $joins Any joins to foreign table, used to determine if dependent records exist * * @return boolean True if the record can be deleted */ public function canDelete($oid = null, $joins = null) { $k = $this->_tbl_key; if ($oid) { $this->{$k} = intval($oid); } if (is_array($joins)) { $db = $this->_db; $query = $db->getQuery(true)->select($db->qn('master') . '.' . $db->qn($k))->from($db->qn($this->_tbl) . ' AS ' . $db->qn('master')); $tableNo = 0; foreach ($joins as $table) { $tableNo++; $query->select(array('COUNT(DISTINCT ' . $db->qn('t' . $tableNo) . '.' . $db->qn($table['idfield']) . ') AS ' . $db->qn($table['idalias']))); $query->join('LEFT', $db->qn($table['name']) . ' AS ' . $db->qn('t' . $tableNo) . ' ON ' . $db->qn('t' . $tableNo) . '.' . $db->qn($table['joinfield']) . ' = ' . $db->qn('master') . '.' . $db->qn($k)); } $query->where($db->qn('master') . '.' . $db->qn($k) . ' = ' . $db->q($this->{$k})); $query->group($db->qn('master') . '.' . $db->qn($k)); $this->_db->setQuery((string) $query); if (version_compare(JVERSION, '3.0', 'ge')) { try { $obj = $this->_db->loadObject(); } catch (JDatabaseException $e) { $this->setError($e->getMessage()); } } else { if (!($obj = $this->_db->loadObject())) { $this->setError($this->_db->getErrorMsg()); return false; } } $msg = array(); $i = 0; foreach ($joins as $table) { $k = $table['idalias']; if ($obj->{$k} > 0) { $msg[] = JText::_($table['label']); } $i++; } if (count($msg)) { $option = $this->input->getCmd('option', 'com_foobar'); $comName = str_replace('com_', '', $option); $tview = str_replace('#__' . $comName . '_', '', $this->_tbl); $prefix = $option . '_' . $tview . '_NODELETE_'; foreach ($msg as $key) { $this->setError(JText::_($prefix . $key)); } return false; } else { return true; } } return true; }
/** * Returns current view object * * @param array $config Configuration variables for the model * * @return FOFView The global instance of the view object (singleton) */ public final function getThisView($config = array()) { if (!is_object($this->_viewObject)) { // Make sure $config is an array if (is_object($config)) { $config = (array) $config; } elseif (!is_array($config)) { $config = array(); } $prefix = null; $viewName = null; $viewType = null; if (!empty($this->viewName)) { $parts = FOFInflector::explode($this->viewName); $viewName = ucfirst(array_pop($parts)); $prefix = FOFInflector::implode($parts); } else { $prefix = ucfirst($this->bareComponent) . 'View'; $viewName = ucfirst($this->view); } $document = FOFPlatform::getInstance()->getDocument(); if ($document instanceof JDocument) { $viewType = $document->getType(); } else { $viewType = $this->input->getCmd('format', 'html'); } if ($viewType == 'html' && $this->hasForm) { $viewType = 'form'; } if (!array_key_exists('input', $config) || !$config['input'] instanceof FOFInput) { $config['input'] = $this->input; } $config['input']->set('base_path', $this->basePath); $this->_viewObject = $this->getView($viewName, $viewType, $prefix, $config); } return $this->_viewObject; }
/** * Gets a temporary instance of a Dispatcher * * @param string $option The component name * @param string $view The View name * @param array $config Configuration data * * @return FOFDispatcher */ public static function &getTmpInstance($option = null, $view = null, $config = array()) { if (array_key_exists('input', $config)) { if ($config['input'] instanceof FOFInput) { $input = $config['input']; } else { if (!is_array($config['input'])) { $config['input'] = (array) $config['input']; } $config['input'] = array_merge($_REQUEST, $config['input']); $input = new FOFInput($config['input']); } } else { $input = new FOFInput(); } $config['option'] = !is_null($option) ? $option : $input->getCmd('option', 'com_foobar'); $config['view'] = !is_null($view) ? $view : $input->getCmd('view', ''); $input->set('option', $config['option']); $input->set('view', $config['view']); $config['input'] = $input; $className = ucfirst(str_replace('com_', '', $config['option'])) . 'Dispatcher'; if (!class_exists($className)) { $componentPaths = FOFPlatform::getInstance()->getComponentBaseDirs($config['option']); $searchPaths = array($componentPaths['main'], $componentPaths['main'] . '/dispatchers', $componentPaths['admin'], $componentPaths['admin'] . '/dispatchers'); if (array_key_exists('searchpath', $config)) { array_unshift($searchPaths, $config['searchpath']); } $filesystem = FOFPlatform::getInstance()->getIntegrationObject('filesystem'); $path = $filesystem->pathFind($searchPaths, 'dispatcher.php'); if ($path) { require_once $path; } } if (!class_exists($className)) { $className = 'FOFDispatcher'; } $instance = new $className($config); return $instance; }
/** * Sets an entire array of search paths for templates or resources. * * @param string $type The type of path to set, typically 'template'. * @param mixed $path The new search path, or an array of search paths. If null or false, resets to the current directory only. * * @return void * */ protected function _setPath($type, $path) { list($isCli, ) = FOFDispatcher::isCliAdmin(); // Clear out the prior search dirs $this->_path[$type] = array(); // Actually add the user-specified directories $this->_addPath($type, $path); // Always add the fallback directories as last resort switch (strtolower($type)) { case 'template': // Set the alternative template search dir if (!$isCli) { $app = JFactory::getApplication(); $component = preg_replace('/[^A-Z0-9_\\.-]/i', '', $this->input->getCmd('option')); $fallback = JPATH_THEMES . '/' . $app->getTemplate() . '/html/' . $component . '/' . $this->getName(); $this->_addPath('template', $fallback); } break; } }
/** * Sets an entire array of search paths for templates or resources. * * @param string $type The type of path to set, typically 'template'. * @param mixed $path The new search path, or an array of search paths. If null or false, resets to the current directory only. * * @return void */ protected function _setPath($type, $path) { // Clear out the prior search dirs $this->_path[$type] = array(); // Actually add the user-specified directories $this->_addPath($type, $path); // Always add the fallback directories as last resort switch (strtolower($type)) { case 'template': // Set the alternative template search dir if (!FOFPlatform::getInstance()->isCli()) { $fallback = FOFPlatform::getInstance()->getTemplateOverridePath($this->input->getCmd('option', '')) . '/' . $this->getName(); $this->_addPath('template', $fallback); } break; } }
<?php /** * @package AkeebaBackup * @copyright Copyright (c)2009-2013 Nicholas K. Dionysopoulos * @license GNU General Public License version 3, or later * @since 1.3 */ defined('_JEXEC') or die; $data = $this->item->getData(); if (substr($data['configuration'], 0, 12) == '###AES128###') { // Load the server key file if necessary jimport('joomla.filesystem.file'); if (!defined('AKEEBA_SERVERKEY')) { $filename = JPATH_COMPONENT_ADMINISTRATOR . '/akeeba/serverkey.php'; include_once $filename; } $key = AEUtilSecuresettings::getKey(); $data['configuration'] = AEUtilSecuresettings::decryptSettings($data['configuration'], $key); } $defaultName = FOFInput::getCmd('view', 'joomla', $this->input); $filename = FOFInput::getCmd('basename', $defaultName, $this->input); $document = JFactory::getDocument(); $document->setName($filename); echo json_encode($data);
/** * Renders a FOFForm for a Browse view and returns the corresponding HTML * * @param FOFForm $form The form to render * @param FOFModel $model The model providing our data * @param FOFInput $input The input object * * @return string The HTML rendering of the form */ protected function renderFormEdit(FOFForm &$form, FOFModel $model, FOFInput $input) { // Get the key for this model's table $key = $model->getTable()->getKeyName(); $keyValue = $model->getId(); $html = ''; if ($validate = $form->getAttribute('validate')) { JHTML::_('behavior.formvalidation'); $class = ' form-validate'; $this->loadValidationScript($form); } else { $class = ''; } // Check form enctype. Use enctype="multipart/form-data" to upload binary files in your form. $template_form_enctype = $form->getAttribute('enctype'); if (!empty($template_form_enctype)) { $enctype = ' enctype="' . $form->getAttribute('enctype') . '" '; } else { $enctype = ''; } // Check form name. Use name="yourformname" to modify the name of your form. $formname = $form->getAttribute('name'); if (empty($formname)) { $formname = 'adminForm'; } // Check form ID. Use id="yourformname" to modify the id of your form. $formid = $form->getAttribute('name'); if (empty($formname)) { $formid = 'adminForm'; } $html .= '<form action="index.php" method="post" name="' . $formname . '" id="' . $formid . '"' . $enctype . ' class="form-horizontal' . $class . '">' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="option" value="' . $input->getCmd('option') . '" />' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="view" value="' . $input->getCmd('view', 'edit') . '" />' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="task" value="" />' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="' . $key . '" value="' . $keyValue . '" />' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="' . JFactory::getSession()->getFormToken() . '" value="1" />' . PHP_EOL; foreach ($form->getFieldsets() as $fieldset) { $fields = $form->getFieldset($fieldset->name); if (isset($fieldset->class)) { $class = 'class="' . $fieldset->class . '"'; } else { $class = ''; } $html .= "\t" . '<div id="' . $fieldset->name . '" ' . $class . '>' . PHP_EOL; if (isset($fieldset->label) && !empty($fieldset->label)) { $html .= "\t\t" . '<h3>' . JText::_($fieldset->label) . '</h3>' . PHP_EOL; } foreach ($fields as $field) { $title = $field->title; $required = $field->required; $labelClass = $field->labelClass; $description = $field->description; $input = $field->input; if (!is_null($title)) { $html .= "\t\t\t" . '<div class="control-group">' . PHP_EOL; $html .= "\t\t\t\t" . '<label class="control-label ' . $labelClass . '" for="' . $field->id . '">' . PHP_EOL; $html .= "\t\t\t\t" . JText::_($title) . PHP_EOL; if ($required) { $html .= ' *'; } $html .= "\t\t\t\t" . '</label>' . PHP_EOL; $html .= "\t\t\t\t" . '<div class="controls">' . PHP_EOL; $html .= "\t\t\t\t" . $input . PHP_EOL; if (!empty($description)) { $html .= "\t\t\t\t" . '<span class="help-block">'; $html .= JText::_($description) . '</span>' . PHP_EOL; } $html .= "\t\t\t\t" . '</div>' . PHP_EOL; $html .= "\t\t\t" . '</div>' . PHP_EOL; } else { $html .= "\t\t\t\t" . $input . PHP_EOL; } } $html .= "\t" . '</div>' . PHP_EOL; } $html .= '</form>'; return $html; }
/** * Renders a FOFForm for an Edit view and returns the corresponding HTML * * @param FOFForm &$form The form to render * @param FOFModel $model The model providing our data * @param FOFInput $input The input object * * @return string The HTML rendering of the form */ protected function renderFormEdit(FOFForm &$form, FOFModel $model, FOFInput $input) { // Get the key for this model's table $key = $model->getTable()->getKeyName(); $keyValue = $model->getId(); $html = ''; $validate = strtolower($form->getAttribute('validate')); if (in_array($validate, array('true', 'yes', '1', 'on'))) { JHtml::_('behavior.formvalidation'); $class = ' form-validate'; $this->loadValidationScript($form); } else { $class = ''; } // Check form enctype. Use enctype="multipart/form-data" to upload binary files in your form. $template_form_enctype = $form->getAttribute('enctype'); if (!empty($template_form_enctype)) { $enctype = ' enctype="' . $form->getAttribute('enctype') . '" '; } else { $enctype = ''; } // Check form name. Use name="yourformname" to modify the name of your form. $formname = $form->getAttribute('name'); if (empty($formname)) { $formname = 'adminForm'; } // Check form ID. Use id="yourformname" to modify the id of your form. $formid = $form->getAttribute('name'); if (empty($formid)) { $formid = 'adminForm'; } // Check if we have a custom task $customTask = $form->getAttribute('customTask'); if (empty($customTask)) { $customTask = ''; } // Get the form action URL $actionUrl = FOFPlatform::getInstance()->isBackend() ? 'index.php' : JUri::root() . 'index.php'; if (FOFPlatform::getInstance()->isFrontend() && $input->getCmd('Itemid', 0) != 0) { $itemid = $input->getCmd('Itemid', 0); $uri = new JUri($actionUrl); if ($itemid) { $uri->setVar('Itemid', $itemid); } $actionUrl = JRoute::_($uri->toString()); } $html .= '<form action="' . $actionUrl . '" method="post" name="' . $formname . '" id="' . $formid . '"' . $enctype . ' class="form-horizontal' . $class . '">' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="option" value="' . $input->getCmd('option') . '" />' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="view" value="' . $input->getCmd('view', 'edit') . '" />' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="task" value="' . $customTask . '" />' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="' . $key . '" value="' . $keyValue . '" />' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="' . JFactory::getSession()->getFormToken() . '" value="1" />' . PHP_EOL; $html .= $this->renderFormRaw($form, $model, $input, 'edit'); $html .= '</form>'; return $html; }
/** * Autoload Views * * @param string $class_name The name of the class to load * * @return void */ public function autoload_fof_view($class_name) { JLog::add(__METHOD__ . "() autoloading {$class_name}", JLog::DEBUG, 'fof'); static $isCli = null, $isAdmin = null; if (is_null($isCli) && is_null($isAdmin)) { list($isCli, $isAdmin) = FOFDispatcher::isCliAdmin(); } if (strpos($class_name, 'View') === false) { return; } // Change from camel cased into a lowercase array $class_modified = preg_replace('/(\\s)+/', '_', $class_name); $class_modified = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $class_modified)); $parts = explode('_', $class_modified); // We need at least three parts in the name if (count($parts) < 3) { return; } // We need the second part to be "view" if ($parts[1] != 'view') { return; } // Get the information about this class $component_raw = $parts[0]; $component = 'com_' . $parts[0]; $view = $parts[2]; if (count($parts) > 3) { $format = $parts[3]; } else { $input = new FOFInput(); $format = $input->getCmd('format', 'html', 'cmd'); } // Is this an FOF 2.1 or later component? if (!$this->isFOFComponent($component)) { return; } // Get the alternate view and class name (opposite singular/plural name) $alt_view = FOFInflector::isSingular($view) ? FOFInflector::pluralize($view) : FOFInflector::singularize($view); $alt_class = FOFInflector::camelize($component_raw . '_view_' . $alt_view); // Get the proper and alternate paths and file names $componentPaths = FOFPlatform::getInstance()->getComponentBaseDirs($component); $protoFile = "/models/{$view}"; $protoAltFile = "/models/{$alt_view}"; $path = $componentPaths['main']; $altPath = $componentPaths['alt']; $formats = array($format); if ($format != 'html') { $formats[] = 'raw'; } foreach ($formats as $currentFormat) { $file = $protoFile . '.' . $currentFormat . '.php'; $altFile = $protoAltFile . '.' . $currentFormat . '.php'; // Try to find the proper class in the proper path if (!class_exists($class_name) && file_exists($path . $file)) { @(include_once $path . $file); } // Try to find the proper class in the alternate path if (!class_exists($class_name) && file_exists($altPath . $file)) { @(include_once $altPath . $file); } // Try to find the alternate class in the proper path if (!class_exists($alt_class) && file_exists($path . $altFile)) { @(include_once $path . $altFile); } // Try to find the alternate class in the alternate path if (!class_exists($alt_class) && file_exists($altPath . $altFile)) { @(include_once $altPath . $altFile); } } // If the alternate class exists just map the class to the alternate if (!class_exists($class_name) && class_exists($alt_class)) { $this->class_alias($alt_class, $class_name); } elseif (!class_exists($class_name)) { if ($view != 'default') { $defaultClass = FOFInflector::camelize($component_raw . '_view_default'); $this->class_alias($defaultClass, $class_name); } else { if (!file_exists(self::$fofPath . '/view/' . $format . '.php')) { $default_class = 'FOFView'; } else { $default_class = 'FOFView' . ucfirst($format); } $this->class_alias($default_class, $class_name, true); } } }
/** * Gets a temporary instance of a Dispatcher * * @param string $option The component name * @param string $view The View name * @param array $config Configuration data * * @return FOFDispatcher */ public static function &getTmpInstance($option = null, $view = null, $config = array()) { if (array_key_exists('input', $config)) { if ($config['input'] instanceof FOFInput) { $input = $config['input']; } else { if (!is_array($config['input'])) { $config['input'] = (array) $config['input']; } $config['input'] = array_merge($_REQUEST, $config['input']); $input = new FOFInput($config['input']); } } else { $input = new FOFInput(); } $config['option'] = !is_null($option) ? $option : $input->getCmd('option', 'com_foobar'); $config['view'] = !is_null($view) ? $view : $input->getCmd('view', ''); $input->set('option', $config['option']); $input->set('view', $config['view']); $config['input'] = $input; $className = ucfirst(str_replace('com_', '', $config['option'])) . 'Dispatcher'; if (!class_exists($className)) { list($isCli, $isAdmin) = self::isCliAdmin(); if ($isAdmin) { $basePath = JPATH_ADMINISTRATOR; } elseif ($isCli) { $basePath = JPATH_ROOT; } else { $basePath = JPATH_SITE; } $searchPaths = array($basePath . '/components/' . $config['option'], $basePath . '/components/' . $config['option'] . '/dispatchers', JPATH_ADMINISTRATOR . '/components/' . $config['option'], JPATH_ADMINISTRATOR . '/components/' . $config['option'] . '/dispatchers'); if (array_key_exists('searchpath', $config)) { array_unshift($searchPaths, $config['searchpath']); } JLoader::import('joomla.filesystem.path'); $path = JPath::find($searchPaths, 'dispatcher.php'); if ($path) { require_once $path; } } if (!class_exists($className)) { $className = 'FOFDispatcher'; } $instance = new $className($config); return $instance; }