/** * Echoes any HTML to show after the view template * * @param string $view The current view * @param string $task The current task * @param F0FInput $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 (F0FPlatform::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 F0FToolbar 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 F0FInput) { $input = $config['input']; } else { $input = new F0FInput($config['input']); } } else { $input = new F0FInput(); } $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 = F0FPlatform::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']); } $filesystem = F0FPlatform::getInstance()->getIntegrationObject('filesystem'); $path = $filesystem->pathFind($searchPaths, 'toolbar.php'); if ($path) { require_once $path; } } if (!class_exists($className)) { $className = 'F0FToolbar'; } $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 F0F 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 = F0FPlatform::getInstance()->getComponentBaseDirs($option); $file_root = $componentPaths['main']; $alt_file_root = $componentPaths['alt']; $template_root = F0FPlatform::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 . '/' . F0FInflector::singularize($view), $template_root . '/' . F0FInflector::pluralize($view), $file_root . '/views/' . $view . '/tmpl', $file_root . '/views/' . F0FInflector::singularize($view) . '/tmpl', $file_root . '/views/' . F0FInflector::pluralize($view) . '/tmpl', $alt_file_root . '/views/' . $view . '/tmpl', $alt_file_root . '/views/' . F0FInflector::singularize($view) . '/tmpl', $alt_file_root . '/views/' . F0FInflector::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 = F0FPlatform::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 = F0FPlatform::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 (F0FPlatform::getInstance()->isFrontend() && $this->input->getCmd('Itemid', 0) != 0) { return '&Itemid=' . $this->input->getInt('Itemid', 0); } else { return ''; } }
/** * Renders the toolbar buttons * * @param string $view The active view name * @param string $task The current task * @param F0FInput $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 (F0FPlatform::getInstance()->isCli()) { return; } // Do not render buttons unless we are in the the frontend area and we are asked to do so $toolbar = F0FToolbar::getAnInstance($input->getCmd('option', 'com_foobar'), $config); $renderFrontendButtons = $toolbar->getRenderFrontendButtons(); if (F0FPlatform::getInstance()->isBackend() || !$renderFrontendButtons) { return; } // Load main backend language, in order to display toolbar strings // (JTOOLBAR_BACK, JTOOLBAR_PUBLISH etc etc) F0FPlatform::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="F0FHeaderHolder">', $bar_content, $title, '<div style="clear:both"></div>', '</div>'; }
/** * Renders a F0FForm for an Edit view and returns the corresponding HTML * * @param F0FForm &$form The form to render * @param F0FModel $model The model providing our data * @param F0FInput $input The input object * * @return string The HTML rendering of the form */ protected function renderFormEdit(F0FForm &$form, F0FModel $model, F0FInput $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; if (F0FPlatform::getInstance()->isFrontend() && $input->getCmd('Itemid', 0) != 0) { $html .= "\t" . '<input type="hidden" name="Itemid" value="' . $input->getCmd('Itemid', 0) . '" />' . 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; }
/** * 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 F0FDispatcher */ public static function &getTmpInstance($option = null, $view = null, $config = array()) { if (array_key_exists('input', $config)) { if ($config['input'] instanceof F0FInput) { $input = $config['input']; } else { if (!is_array($config['input'])) { $config['input'] = (array) $config['input']; } $config['input'] = array_merge($_REQUEST, $config['input']); $input = new F0FInput($config['input']); } } else { $input = new F0FInput(); } $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 = F0FPlatform::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 = F0FPlatform::getInstance()->getIntegrationObject('filesystem'); $path = $filesystem->pathFind($searchPaths, 'dispatcher.php'); if ($path) { require_once $path; } } if (!class_exists($className)) { $className = 'F0FDispatcher'; } $instance = new $className($config); return $instance; }
/** * Autoload Views * * @param string $class_name The name of the class to load * * @return void */ public function autoload_fof_view($class_name) { F0FPlatform::getInstance()->logDebug(__METHOD__ . "() autoloading {$class_name}"); static $isCli = null, $isAdmin = null; if (is_null($isCli) && is_null($isAdmin)) { list($isCli, $isAdmin) = F0FDispatcher::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 F0FInput(); $format = $input->getCmd('format', 'html', 'cmd'); } // Is this an F0F 2.1 or later component? if (!$this->isF0FComponent($component)) { return; } // Get the alternate view and class name (opposite singular/plural name) $alt_view = F0FInflector::isSingular($view) ? F0FInflector::pluralize($view) : F0FInflector::singularize($view); $alt_class = F0FInflector::camelize($component_raw . '_view_' . $alt_view); // Get the proper and alternate paths and file names $componentPaths = F0FPlatform::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 = F0FInflector::camelize($component_raw . '_view_default'); $this->class_alias($defaultClass, $class_name); } else { if (!file_exists(self::$fofPath . '/view/' . $format . '.php')) { $default_class = 'F0FView'; } else { $default_class = 'F0FView' . ucfirst($format); } $this->class_alias($default_class, $class_name, true); } } }
/** * 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 (Exception $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; }
/** * Method to create a clickable icon to change the state of an item * * @param mixed $value Either the scalar value or an object (for backward compatibility, deprecated) * @param integer $i The index * @param bool $withLink Param * * @return string */ public static function processedWithIcons($value, $i, $withLink = null) { if (is_object($value)) { $value = $value->published; } $img = $value ? self::REQ_ICON_YES : self::REQ_ICON_NO; if ($withLink === null) { $platform = F0FPlatform::getInstance(); $input = new F0FInput(); $withLink = $platform->authorise('core.edit.state', $input->getCmd('option', 'com_foobar')); } if (!$withLink) { return $img; } $task = $value ? 'unpublish' : 'publish'; $alt = $value ? JText::_('JPUBLISHED') : JText::_('JUNPUBLISHED'); $action = $value ? JText::_('JLIB_HTML_UNPUBLISH_ITEM') : JText::_('JLIB_HTML_PUBLISH_ITEM'); $href = '<a href="#" onclick="return listItemTask(\'cb' . $i . '\',\'' . $task . '\')" title="' . $action . '">' . $img . '</a>'; return $href; }
/** * imageControl. * * @param string $selected Value * @param string $name The name for the field * @param string $label Label * @param string $desc Description * @param array $idTag Additional HTML attributes for the <select> tag * @param string $class Class * @param bool $preview Param * * @return string HTML */ public static function imageControl($selected, $name, $label, $desc, $idTag = null, $class = null, $preview = false) { static $inserted = false; JHTML::_('behavior.modal'); if (!$idTag) { $idTag = self::generateIdTag(); } if (empty($class)) { $class = 'span4'; } $class = ' class="' . $class . '"'; $control[] = '<div class="input-append">'; /* Input-prepend $control[] = '<div class="media-preview add-on"><span title="' . JText::_($label) . '" class="hasTipPreview"><i class="xticon xticon-file-image-o"></i></span></div>'; */ $control[] = '<input type="text" name="' . $name . '" id="' . $idTag . '" value="' . $selected . '" maxlength="512"' . $class . '/>'; $input = new F0FInput(); $manage = F0FPlatform::getInstance()->authorise('core.manage', $input->getCmd('option', 'com_foobar')); if ($manage) { $control[] = '<a class="btn modal" rel="{handler: \'iframe\', size: {x: 800, y: 500}}" href="index.php?option=com_media&view=images&tmpl=component&asset=com_autotweet&author=' . JFactory::getUser()->id . '&fieldid=' . $idTag . '" title="' . JText::_('JSELECT') . '">' . JText::_('JSELECT') . '</a>'; } $control[] = '<a onclick="jInsertFieldValue(\'\', \'' . $idTag . '\'); return false;" href="#" title="" class="btn hasTooltip" data-original-title="' . JText::_('JCLEAR') . '"><i class="xticon xticon-remove"></i></a>'; $control[] = '<a onclick="jRefreshPreview(\'\', \'' . $idTag . '\'); return false;" href="#" title="" class="btn hasTooltip" data-original-title="' . JText::_('JLIB_FORM_MEDIA_PREVIEW_TIP_TITLE') . '"><i class="xticon xticon-eye"></i></a>'; $control[] = '</div>'; $control[] = '<br/><br/>'; $img_preview = null; if ($preview && !empty($selected)) { $img_preview = '<img src="' . $selected . '" class="img-polaroid span7">'; } $control[] = '<div id="' . $idTag . '-image">' . $img_preview . '</div>'; $control = implode('', $control); if (!$inserted) { $inserted = true; $document = JFactory::getDocument(); $document->addScriptDeclaration("\n\t// Extly's imageControl\n\twindow.jInsertFieldValue = function(value, id) {\n\t\t\tjQuery('#' + id).val(value);\n\t};\n\twindow.jRefreshPreview = function(value, id) {\n\t\t\tvar img_preview = jQuery('#' + id).val();\n\t\t\tvar url_root = '" . JUri::root() . "';\n\t\t\tvar id_image = '#' + id + '-image';\n\n\t\t\tif (img_preview.length == 0) {\n\t\t\t\tjQuery(id_image).html('');\n\n\t\t\t\treturn true;\n\t\t\t};\n\n\t\t\tif (!img_preview.match(/http(s?):\\/\\//)) {\n\t\t\t\timg_preview = url_root + img_preview;\n\t\t\t};\n\n\t\t\tjQuery(id_image).html('<img src=\"' + img_preview + '\" class=\"img-polaroid span7\">');\n\t};\n\t"); } return self::genericControl($label, $desc, $name, $control); }
/** * 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 (!F0FPlatform::getInstance()->isCli()) { $fallback = F0FPlatform::getInstance()->getTemplateOverridePath($this->input->getCmd('option', '')) . '/' . $this->getName(); $this->_addPath('template', $fallback); } break; } }
/** * Renders the toolbar buttons * * @param string $view The active view name * @param string $task The current task * @param F0FInput $input The input object * @param array $config Extra configuration variables for the toolbar * * @return void */ protected function renderButtons($view, $task, $input, $config = array()) { if (F0FPlatform::getInstance()->isCli()) { return; } // Do not render buttons unless we are in the the frontend area and we are asked to do so $toolbar = F0FToolbar::getAnInstance($input->getCmd('option', 'com_foobar'), $config); $renderFrontendButtons = $toolbar->getRenderFrontendButtons(); // Load main backend language, in order to display toolbar strings // (JTOOLBAR_BACK, JTOOLBAR_PUBLISH etc etc) F0FPlatform::getInstance()->loadTranslations('joomla'); if (F0FPlatform::getInstance()->isBackend() || !$renderFrontendButtons) { return; } $bar = JToolBar::getInstance('toolbar'); $items = $bar->getItems(); $substitutions = array('icon-32-new' => 'xticon xticon-plus', 'icon-32-publish' => 'xticon xticon-check-sign', 'icon-32-unpublish' => 'xticon xticon-times-circle', 'icon-32-delete' => 'xticon xticon-times', 'icon-32-edit' => 'xticon xticon-edit', 'icon-32-copy' => 'xticon xticon-copy', 'icon-32-cancel' => 'xticon xticon-times-circle', 'icon-32-back' => 'xticon xticon-times-circle', 'icon-32-apply' => 'xticon xticon-save', 'icon-32-save' => 'xticon xticon-edit', 'icon-32-save-new' => 'xticon xticon-plus', 'icon-32-process' => 'xticon xticon-cog'); $html = array(); $actions = array(); $html[] = '<div class="extly"><div id="F0FHeaderHolder" class="row-fluid"><div class="span12">'; $html[] = '<div class="buttonsHolder btn-toolbar pull-right">'; foreach ($items as $node) { $type = $node[0]; $button = $bar->loadButtonType($type); if ($button !== false) { if (method_exists($button, 'fetchId')) { $id = call_user_func_array(array(&$button, 'fetchId'), $node); } else { $id = null; } $action = call_user_func_array(array(&$button, 'fetchButton'), $node); $action = str_replace('class="toolbar"', 'class="toolbar btn"', $action); $action = str_replace('<span ', '<i ', $action); $action = str_replace('</span>', '</i>', $action); $action = str_replace(array_keys($substitutions), array_values($substitutions), $action); $actions[] = $action; } } $html = array_merge($html, $actions); $html[] = '</div>'; $html[] = '</div></div></div>'; echo implode("\n", $html); }
/** * published. * * @param string $selected The key that is selected * @param string $name The name for the field * @param array $attribs Additional HTML attributes for the <select> tag * @param string $yes Param * @param string $no Param * @param string $idTag Additional HTML attributes for the <select> tag * * @return string HTML */ public static function published($selected = null, $name = 'enabled', $attribs = array(), $yes = 'JPUBLISHED', $no = 'JUNPUBLISHED', $idTag = null) { $platform = F0FPlatform::getInstance(); $input = new F0FInput(); $editstate = $platform->authorise('core.edit.state', $input->getCmd('option', 'com_foobar')); if ($editstate) { if ($selected === null) { $selected = 1; } return self::booleanList($selected, $name, $attribs, $yes, $no, $idTag); } else { if ($selected) { $value = 1; $tag = JText::_($yes); } else { $value = 0; $tag = JText::_($no); } $control = EHtml::readonlyText($tag, $name . '-readonly'); $control .= '<input type="hidden" value="' . $value . '" name="' . $name . '" id="' . $idTag . '">'; return $control; } }