/** * Public constructor. Instantiates a FOFViewCsv object. * * @param array $config The configuration data array */ public function __construct($config = array()) { // Make sure $config is an array if (is_object($config)) { $config = (array) $config; } elseif (!is_array($config)) { $config = array(); } parent::__construct($config); if (array_key_exists('csv_header', $config)) { $this->csvHeader = $config['csv_header']; } else { $this->csvHeader = $this->input->getBool('csv_header', true); } if (array_key_exists('csv_filename', $config)) { $this->csvFilename = $config['csv_filename']; } else { $this->csvFilename = $this->input->getString('csv_filename', ''); } if (empty($this->csvFilename)) { $view = $this->input->getCmd('view', 'cpanel'); $view = FOFInflector::pluralize($view); $this->csvFilename = strtolower($view); } if (array_key_exists('csv_fields', $config)) { $this->csvFields = $config['csv_fields']; } }
/** * Method to get the field options. * * @return array The field option objects. */ protected function getOptions() { $options = array(); // Initialize some field attributes. $key = $this->element['key_field'] ? (string) $this->element['key_field'] : 'value'; $value = $this->element['value_field'] ? (string) $this->element['value_field'] : (string) $this->element['name']; $applyAccess = $this->element['apply_access'] ? (string) $this->element['apply_access'] : 'false'; $modelName = (string) $this->element['model']; $nonePlaceholder = (string) $this->element['none']; $translate = empty($this->element['translate']) ? 'true' : (string) $this->element['translate']; $translate = in_array(strtolower($translate), array('true', 'yes', '1', 'on')) ? true : false; if (!empty($nonePlaceholder)) { $options[] = JHtml::_('select.option', JText::_($nonePlaceholder), null); } // Process field atrtibutes $applyAccess = strtolower($applyAccess); $applyAccess = in_array($applyAccess, array('yes', 'on', 'true', '1')); // Explode model name into model name and prefix $parts = FOFInflector::explode($modelName); $mName = ucfirst(array_pop($parts)); $mPrefix = FOFInflector::implode($parts); // Get the model object $config = array('savestate' => 0); $model = FOFModel::getTmpInstance($mName, $mPrefix, $config); if ($applyAccess) { $model->applyAccessFiltering(); } // Process state variables foreach ($this->element->children() as $stateoption) { // Only add <option /> elements. if ($stateoption->getName() != 'state') { continue; } $stateKey = (string) $stateoption['key']; $stateValue = (string) $stateoption; $model->setState($stateKey, $stateValue); } // Set the query and get the result list. $items = $model->getItemList(true); // Build the field options. if (!empty($items)) { foreach ($items as $item) { if ($translate == true) { $options[] = JHtml::_('select.option', $item->{$key}, JText::_($item->{$value})); } else { $options[] = JHtml::_('select.option', $item->{$key}, $item->{$value}); } } } // Merge any additional options in the XML definition. $options = array_merge(parent::getOptions(), $options); return $options; }
public function dispatch() { // Look for controllers in the plugins folder $option = $this->input->get('option', 'com_foobar', 'cmd'); $view = $this->input->get('view', $this->defaultView, 'cmd'); $c = FOFInflector::singularize($view); $alt_path = JPATH_SITE . '/components/' . $option . '/plugins/controllers/' . $c . '.php'; JLoader::import('joomla.filesystem.file'); if (JFile::exists($alt_path)) { // The requested controller exists and there you load it... require_once $alt_path; } $this->input->set('view', $this->view); parent::dispatch(); }
/** * 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 renderFormBrowse(FOFForm &$form, FOFModel $model, FOFInput $input) { JHtml::_('behavior.multiselect'); // Getting all header row elements $headerFields = $form->getHeaderset(); // Start the form $html = ''; $filter_order = $form->getView()->getLists()->order; $filter_order_Dir = $form->getView()->getLists()->order_Dir; $html .= '<form action="index.php" method="post" name="adminForm" id="adminForm">' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="option" value="' . $input->getCmd('option') . '" />' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="view" value="' . FOFInflector::pluralize($input->getCmd('view')) . '" />' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="task" value="" />' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="boxchecked" value="" />' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="hidemainmenu" value="" />' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="filter_order" value="' . $filter_order . '" />' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="filter_order_Dir" value="' . $filter_order_Dir . '" />' . PHP_EOL; if (FOFPlatform::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; // Start the table output $html .= "\t\t" . '<table class="adminlist" id="adminList">' . PHP_EOL; // Get form parameters $show_header = $form->getAttribute('show_header', 1); $show_filters = $form->getAttribute('show_filters', 1); $show_pagination = $form->getAttribute('show_pagination', 1); $norows_placeholder = $form->getAttribute('norows_placeholder', ''); // Open the table header region if required if ($show_header || $show_filters) { $html .= "\t\t\t<thead>" . PHP_EOL; } // Pre-render the header and filter rows if ($show_header || $show_filters) { $header_html = ''; $filter_html = ''; foreach ($headerFields as $header) { // Make sure we have a header field. Under Joomla! 2.5 we cannot // render filter-only fields. $tmpHeader = $header->header; if (empty($tmpHeader)) { continue; } $tdwidth = $header->tdwidth; if (!empty($tdwidth)) { $tdwidth = 'width="' . $tdwidth . '"'; } else { $tdwidth = ''; } $header_html .= "\t\t\t\t\t<th {$tdwidth}>" . PHP_EOL; $header_html .= "\t\t\t\t\t\t" . $tmpHeader; $header_html .= "\t\t\t\t\t</th>" . PHP_EOL; $filter = $header->filter; $buttons = $header->buttons; $options = $header->options; $filter_html .= "\t\t\t\t\t<td>" . PHP_EOL; if (!empty($filter)) { $filter_html .= "\t\t\t\t\t\t{$filter}" . PHP_EOL; if (!empty($buttons)) { $filter_html .= "\t\t\t\t\t\t<nobr>{$buttons}</nobr>" . PHP_EOL; } } elseif (!empty($options)) { $label = $header->label; $emptyOption = JHtml::_('select.option', '', '- ' . JText::_($label) . ' -'); array_unshift($options, $emptyOption); $attribs = array('onchange' => 'document.adminForm.submit();'); $filter = JHtml::_('select.genericlist', $options, $header->name, $attribs, 'value', 'text', $header->value, false, true); $filter_html .= "\t\t\t\t\t\t{$filter}" . PHP_EOL; } $filter_html .= "\t\t\t\t\t</td>" . PHP_EOL; } } // Render header if enabled if ($show_header) { $html .= "\t\t\t\t<tr>" . PHP_EOL; $html .= $header_html; $html .= "\t\t\t\t</tr>" . PHP_EOL; } // Render filter row if enabled if ($show_filters) { $html .= "\t\t\t\t<tr>"; $html .= $filter_html; $html .= "\t\t\t\t</tr>"; } // Close the table header region if required if ($show_header || $show_filters) { $html .= "\t\t\t</thead>" . PHP_EOL; } // Loop through rows and fields, or show placeholder for no rows $html .= "\t\t\t<tbody>" . PHP_EOL; $fields = $form->getFieldset('items'); $num_columns = count($fields); $items = $form->getModel()->getItemList(); if ($count = count($items)) { $m = 1; foreach ($items as $i => $item) { $table_item = $form->getModel()->getTable(); $table_item->reset(); $table_item->bind($item); $form->bind($item); $m = 1 - $m; $class = 'row' . $m; $html .= "\t\t\t\t<tr class=\"{$class}\">" . PHP_EOL; $fields = $form->getFieldset('items'); foreach ($fields as $field) { $field->rowid = $i; $field->item = $table_item; $labelClass = $field->labelClass ? $field->labelClass : $field->labelclass; // Joomla! 2.5/3.x use different case for the same name $class = $labelClass ? 'class ="' . $labelClass . '"' : ''; $html .= "\t\t\t\t\t<td {$class}>" . $field->getRepeatable() . '</td>' . PHP_EOL; } $html .= "\t\t\t\t</tr>" . PHP_EOL; } } elseif ($norows_placeholder) { $html .= "\t\t\t\t<tr><td colspan=\"{$num_columns}\">"; $html .= JText::_($norows_placeholder); $html .= "</td></tr>\n"; } $html .= "\t\t\t</tbody>" . PHP_EOL; // Render the pagination bar, if enabled if ($show_pagination) { $pagination = $form->getModel()->getPagination(); $html .= "\t\t\t<tfoot>" . PHP_EOL; $html .= "\t\t\t\t<tr><td colspan=\"{$num_columns}\">"; if ($pagination->total > 0) { $html .= $pagination->getListFooter(); } $html .= "</td></tr>\n"; $html .= "\t\t\t</tfoot>" . PHP_EOL; } // End the table output $html .= "\t\t" . '</table>' . PHP_EOL; // End the form $html .= '</form>' . PHP_EOL; return $html; }
/** * Tries to guess the controller task to execute based on the view name and * the HTTP request method. * * @param string $view The name of the view * * @return string The best guess of the task to execute */ protected function getTask($view) { // Get a default task based on plural/singular view $request_task = $this->input->getCmd('task', null); $task = FOFInflector::isPlural($view) ? 'browse' : 'edit'; // Get a potential ID, we might need it later $id = $this->input->get('id', null, 'int'); if ($id == 0) { $ids = $this->input->get('ids', array(), 'array'); if (!empty($ids)) { $id = array_shift($ids); } } // Check the request method if (!isset($_SERVER['REQUEST_METHOD'])) { $_SERVER['REQUEST_METHOD'] = 'GET'; } $requestMethod = strtoupper($_SERVER['REQUEST_METHOD']); switch ($requestMethod) { case 'POST': case 'PUT': if (!is_null($id)) { $task = 'save'; } break; case 'DELETE': if ($id != 0) { $task = 'delete'; } break; case 'GET': default: // If it's an edit without an ID or ID=0, it's really an add if ($task == 'edit' && $id == 0) { $task = 'add'; } elseif ($task == 'edit' && FOFPlatform::getInstance()->isFrontend()) { $task = 'read'; } break; } return $task; }
/** * Method to get the field label. * * @return string The field label. * * @since 2.0 */ protected function getLabel() { // Get the label text from the XML element, defaulting to the element name. $title = $this->element['label'] ? (string) $this->element['label'] : ''; if (empty($title)) { $view = $this->form->getView(); $params = $view->getViewOptionAndName(); $title = $params['option'] . '_' . FOFInflector::pluralize($params['view']) . '_FIELD_' . (string) $this->element['name']; $title = strtoupper($title); $result = JText::_($title); if ($result === $title) { $title = ucfirst((string) $this->element['name']); } } return $title; }
/** * Return a list of the view template paths for this component. * * @param string $component The name of the component. For Joomla! this * is something like "com_example" * @param string $view The name of the view you're looking a * template for * @param string $layout The layout name to load, e.g. 'default' * @param string $tpl The sub-template name to load (null by default) * @param boolean $strict If true, only the specified layout will be searched for. * Otherwise we'll fall back to the 'default' layout if the * specified layout is not found. * * @see FOFPlatformInterface::getViewTemplateDirs() * * @return array */ public function getViewTemplatePaths($component, $view, $layout = 'default', $tpl = null, $strict = false) { $isAdmin = $this->isBackend(); $basePath = $isAdmin ? 'admin:' : 'site:'; $basePath .= $component . '/'; $altBasePath = $basePath; $basePath .= $view . '/'; $altBasePath .= (FOFInflector::isSingular($view) ? FOFInflector::pluralize($view) : FOFInflector::singularize($view)) . '/'; if ($strict) { $paths = array($basePath . $layout . ($tpl ? "_{$tpl}" : ''), $altBasePath . $layout . ($tpl ? "_{$tpl}" : '')); } else { $paths = array($basePath . $layout . ($tpl ? "_{$tpl}" : ''), $basePath . $layout, $basePath . 'default' . ($tpl ? "_{$tpl}" : ''), $basePath . 'default', $altBasePath . $layout . ($tpl ? "_{$tpl}" : ''), $altBasePath . $layout, $altBasePath . 'default' . ($tpl ? "_{$tpl}" : ''), $altBasePath . 'default'); $paths = array_unique($paths); } return $paths; }
public function dispatch() { if (!class_exists('AkeebaControllerDefault')) { require_once JPATH_ADMINISTRATOR . '/components/com_akeeba/controllers/default.php'; } // Merge the language overrides $paths = array(JPATH_ROOT, JPATH_ADMINISTRATOR); $jlang = JFactory::getLanguage(); $jlang->load($this->component, $paths[0], 'en-GB', true); $jlang->load($this->component, $paths[0], null, true); $jlang->load($this->component, $paths[1], 'en-GB', true); $jlang->load($this->component, $paths[1], null, true); $jlang->load($this->component . '.override', $paths[0], 'en-GB', true); $jlang->load($this->component . '.override', $paths[0], null, true); $jlang->load($this->component . '.override', $paths[1], 'en-GB', true); $jlang->load($this->component . '.override', $paths[1], null, true); FOFInflector::addWord('alice', 'alices'); // Timezone fix; avoids errors printed out by PHP 5.3.3+ (thanks Yannick!) if (function_exists('date_default_timezone_get') && function_exists('date_default_timezone_set')) { if (function_exists('error_reporting')) { $oldLevel = error_reporting(0); } $serverTimezone = @date_default_timezone_get(); if (empty($serverTimezone) || !is_string($serverTimezone)) { $serverTimezone = 'UTC'; } if (function_exists('error_reporting')) { error_reporting($oldLevel); } @date_default_timezone_set($serverTimezone); } // Necessary defines for Akeeba Engine if (!defined('AKEEBAENGINE')) { define('AKEEBAENGINE', 1); // Required for accessing Akeeba Engine's factory class define('AKEEBAROOT', dirname(__FILE__) . '/akeeba'); define('ALICEROOT', dirname(__FILE__) . '/alice'); } // Setup Akeeba's ACLs, honoring laxed permissions in component's parameters, if set // Access check, Joomla! 1.6 style. $user = JFactory::getUser(); if (!$user->authorise('core.manage', 'com_akeeba')) { return JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR')); } // Make sure we have a profile set throughout the component's lifetime $session = JFactory::getSession(); $profile_id = $session->get('profile', null, 'akeeba'); if (is_null($profile_id)) { // No profile is set in the session; use default profile $session->set('profile', 1, 'akeeba'); } // Load the factory require_once JPATH_COMPONENT_ADMINISTRATOR . '/akeeba/factory.php'; @(include_once JPATH_COMPONENT_ADMINISTRATOR . '/alice/factory.php'); // Load the Akeeba Backup configuration and check user access permission $aeconfig = AEFactory::getConfiguration(); AEPlatform::getInstance()->load_configuration(); unset($aeconfig); // Preload helpers require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/includes.php'; require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/escape.php'; // Load the utils helper library AEPlatform::getInstance()->load_version_defines(); // Create a versioning tag for our static files $staticFilesVersioningTag = md5(AKEEBA_VERSION . AKEEBA_DATE); define('AKEEBAMEDIATAG', $staticFilesVersioningTag); // If JSON functions don't exist, load our compatibility layer if (!function_exists('json_encode') || !function_exists('json_decode')) { require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/jsonlib.php'; } // Look for controllers in the plugins folder $option = $this->input->get('option', 'com_foobar', 'cmd'); $view = $this->input->get('view', $this->defaultView, 'cmd'); $c = FOFInflector::singularize($view); $alt_path = JPATH_ADMINISTRATOR . '/components/' . $option . '/plugins/controllers/' . $c . '.php'; JLoader::import('joomla.filesystem.file'); if (JFile::exists($alt_path)) { // The requested controller exists and there you load it... require_once $alt_path; } $this->input->set('view', $this->view); parent::dispatch(); }
function save() { $app = JFactory::getApplication(); $field_id = $app->input->getInt('j2store_customfield_id'); $formData = $app->input->get('data', array(), 'ARRAY'); //initialise a object $field = new JObject(); $field->field_id = $field_id; $field->j2store_customfield_id = $field_id; foreach ($formData['field'] as $column => $value) { j2storeSelectableHelper::secureField($column); if ($column == 'field_default') { continue; } else { if (is_array($value)) { $value = implode(',', $value); } $field->{$column} = strip_tags($value); } } $fields = array(&$field); if (isset($field->field_namekey)) { $namekey = $field->field_namekey; } $field->field_namekey = 'field_default'; if ($this->_checkOneInput($fields, $formData['field'], $data, '', $oldData)) { if (isset($formData['field']['field_default']) && is_array($formData['field']['field_default'])) { $defaultValue = ''; foreach ($formData['field']['field_default'] as $value) { if (empty($defaultValue)) { $defaultValue .= $value; } else { $defaultValue .= "," . $value; } } $field->field_default = strip_tags($defaultValue); } else { $field->field_default = @strip_tags($formData['field']['field_default']); } } unset($field->field_namekey); if (isset($namekey)) { $field->field_namekey = $namekey; } $fieldOptions = $app->input->get('field_options', array(), 'array'); foreach ($fieldOptions as $column => $value) { if (is_array($value)) { foreach ($value as $id => $val) { j2storeSelectableHelper::secureField($val); $fieldOptions[$column][$id] = strip_tags($val); } } else { $fieldOptions[$column] = strip_tags($value); } } if ($field->field_type == "customtext") { $fieldOptions['customtext'] = $app->input->getHtml('fieldcustomtext', ''); if (empty($field->field_id)) { $field->field_namekey = 'customtext_' . date('z_G_i_s'); } else { $oldField = $this->get($field->field_id); if ($oldField->field_core) { $field->field_type = $oldField->field_type; } } } $field->field_options = serialize($fieldOptions); $fieldValues = $app->input->get('field_values', array(), 'array'); if (!empty($fieldValues)) { $field->field_value = array(); foreach ($fieldValues['title'] as $i => $title) { if (strlen($title) < 1 and strlen($fieldValues['value'][$i]) < 1) { continue; } $value = strlen($fieldValues['value'][$i]) < 1 ? $title : $fieldValues['value'][$i]; $disabled = strlen($fieldValues['disabled'][$i]) < 1 ? '0' : $fieldValues['disabled'][$i]; $field->field_value[] = strip_tags($title) . '::' . strip_tags($value) . '::' . strip_tags($disabled); } $field->field_value = implode("\n", $field->field_value); } if (empty($field->field_id) && $field->field_type != 'customtext') { if (empty($field->field_namekey)) { $field->field_namekey = $field->field_name; } $field->field_namekey = preg_replace('#[^a-z0-9_]#i', '', strtolower($field->field_namekey)); if (empty($field->field_namekey)) { $this->errors[] = 'Please specify a namekey'; return false; } if ($field->field_namekey > 50) { $this->errors[] = 'Please specify a shorter column name'; return false; } if (in_array(strtoupper($field->field_namekey), array('ACCESSIBLE', 'ADD', 'ALL', 'ALTER', 'ANALYZE', 'AND', 'AS', 'ASC', 'ASENSITIVE', 'BEFORE', 'BETWEEN', 'BIGINT', 'BINARY', 'BLOB', 'BOTH', 'BY', 'CALL', 'CASCADE', 'CASE', 'CHANGE', 'CHAR', 'CHARACTER', 'CHECK', 'COLLATE', 'COLUMN', 'CONDITION', 'CONSTRAINT', 'CONTINUE', 'CONVERT', 'CREATE', 'CROSS', 'CURRENT_DATE', 'CURRENT_TIME', 'CURRENT_TIMESTAMP', 'CURRENT_USER', 'CURSOR', 'DATABASE', 'DATABASES', 'DAY_HOUR', 'DAY_MICROSECOND', 'DAY_MINUTE', 'DAY_SECOND', 'DEC', 'DECIMAL', 'DECLARE', 'DEFAULT', 'DELAYED', 'DELETE', 'DESC', 'DESCRIBE', 'DETERMINISTIC', 'DISTINCT', 'DISTINCTROW', 'DIV', 'DOUBLE', 'DROP', 'DUAL', 'EACH', 'ELSE', 'ELSEIF', 'ENCLOSED', 'ESCAPED', 'EXISTS', 'EXIT', 'EXPLAIN', 'FALSE', 'FETCH', 'FLOAT', 'FLOAT4', 'FLOAT8', 'FOR', 'FORCE', 'FOREIGN', 'FROM', 'FULLTEXT', 'GRANT', 'GROUP', 'HAVING', 'HIGH_PRIORITY', 'HOUR_MICROSECOND', 'HOUR_MINUTE', 'HOUR_SECOND', 'IF', 'IGNORE', 'IN', 'INDEX', 'INFILE', 'INNER', 'INOUT', 'INSENSITIVE', 'INSERT', 'INT', 'INT1', 'INT2', 'INT3', 'INT4', 'INT8', 'INTEGER', 'INTERVAL', 'INTO', 'IS', 'ITERATE', 'JOIN', 'KEY', 'KEYS', 'KILL', 'LEADING', 'LEAVE', 'LEFT', 'LIKE', 'LIMIT', 'LINEAR', 'LINES', 'LOAD', 'LOCALTIME', 'LOCALTIMESTAMP', 'LOCK', 'LONG', 'LONGBLOB', 'LONGTEXT', 'LOOP', 'LOW_PRIORITY', 'MASTER_SSL_VERIFY_SERVER_CERT', 'MATCH', 'MAXVALUE', 'MEDIUMBLOB', 'MEDIUMINT', 'MEDIUMTEXT', 'MIDDLEINT', 'MINUTE_MICROSECOND', 'MINUTE_SECOND', 'MOD', 'MODIFIES', 'NATURAL', 'NOT', 'NO_WRITE_TO_BINLOG', 'NULL', 'NUMERIC', 'ON', 'OPTIMIZE', 'OPTION', 'OPTIONALLY', 'OR', 'ORDER', 'OUT', 'OUTER', 'OUTFILE', 'PRECISION', 'PRIMARY', 'PROCEDURE', 'PURGE', 'RANGE', 'READ', 'READS', 'READ_WRITE', 'REAL', 'REFERENCES', 'REGEXP', 'RELEASE', 'RENAME', 'REPEAT', 'REPLACE', 'REQUIRE', 'RESIGNAL', 'RESTRICT', 'RETURN', 'REVOKE', 'RIGHT', 'RLIKE', 'SCHEMA', 'SCHEMAS', 'SECOND_MICROSECOND', 'SELECT', 'SENSITIVE', 'SEPARATOR', 'SET', 'SHOW', 'SIGNAL', 'SMALLINT', 'SPATIAL', 'SPECIFIC', 'SQL', 'SQLEXCEPTION', 'SQLSTATE', 'SQLWARNING', 'SQL_BIG_RESULT', 'SQL_CALC_FOUND_ROWS', 'SQL_SMALL_RESULT', 'SSL', 'STARTING', 'STRAIGHT_JOIN', 'TABLE', 'TERMINATED', 'THEN', 'TINYBLOB', 'TINYINT', 'TINYTEXT', 'TO', 'TRAILING', 'TRIGGER', 'TRUE', 'UNDO', 'UNION', 'UNIQUE', 'UNLOCK', 'UNSIGNED', 'UPDATE', 'USAGE', 'USE', 'USING', 'UTC_DATE', 'UTC_TIME', 'UTC_TIMESTAMP', 'VALUES', 'VARBINARY', 'VARCHAR', 'VARCHARACTER', 'VARYING', 'WHEN', 'WHERE', 'WHILE', 'WITH', 'WRITE', 'XOR', 'YEAR_MONTH', 'ZEROFILL', 'GENERAL', 'IGNORE_SERVER_IDS', 'MASTER_HEARTBEAT_PERIOD', 'MAXVALUE', 'RESIGNAL', 'SIGNAL', 'SLOW', 'ALIAS', 'OPTIONS', 'RELATED', 'IMAGES', 'FILES', 'CATEGORIES', 'PRICES', 'VARIANTS', 'CHARACTERISTICS'))) { $this->errors[] = 'The column name "' . $field->field_namekey . '" is reserved. Please use another one.'; return false; } $tables = array($field->field_table); foreach ($tables as $table_name) { if ($table_name == 'address') { $table_name = FOFInflector::pluralize($table_name); } $columns = $this->database->getTableColumns($this->fieldTable($table_name)); if (isset($columns[$field->field_namekey])) { $this->errors[] = 'The field "' . $field->field_namekey . '" already exists in the table "' . $table_name . '"'; return false; } } foreach ($tables as $table_name) { if ($table_name == 'address') { $table_name = FOFInflector::pluralize($table_name); } $query = 'ALTER TABLE ' . $this->fieldTable($table_name) . ' ADD `' . $field->field_namekey . '` TEXT NULL'; $this->database->setQuery($query); $this->database->query(); } } $this->fielddata = $field; return true; }
protected function onBeforeReset() { if ($this->_trigger_events) { $name = FOFInflector::pluralize($this->getKeyName()); $dispatcher = JDispatcher::getInstance(); $result = $dispatcher->trigger('onBeforeReset' . ucfirst($name), array(&$this)); if (in_array(false, $result, true)) { return false; } else { return true; } } return true; }
/** * 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 renderFormBrowse(FOFForm &$form, FOFModel $model, FOFInput $input) { $html = ''; JHtml::_('behavior.multiselect'); // Joomla! 3.0+ support if (FOFPlatform::getInstance()->checkVersion(JVERSION, '3.0', 'ge')) { JHtml::_('bootstrap.tooltip'); JHtml::_('dropdown.init'); JHtml::_('formbehavior.chosen', 'select'); $view = $form->getView(); $order = $view->escape($view->getLists()->order); $html .= <<<ENDJS <script type="text/javascript"> \tJoomla.orderTable = function() { \t\ttable = document.getElementById("sortTable"); \t\tdirection = document.getElementById("directionTable"); \t\torder = table.options[table.selectedIndex].value; \t\tif (order != '{$order}') \t\t{ \t\t\tdirn = 'asc'; \t\t} \t\telse { \t\t\tdirn = direction.options[direction.selectedIndex].value; \t\t} \t\tJoomla.tableOrdering(order, dirn); \t} </script> ENDJS; } // Getting all header row elements $headerFields = $form->getHeaderset(); // Get form parameters $show_header = $form->getAttribute('show_header', 1); $show_filters = $form->getAttribute('show_filters', 1); $show_pagination = $form->getAttribute('show_pagination', 1); $norows_placeholder = $form->getAttribute('norows_placeholder', ''); // Joomla! 3.0 sidebar support if (FOFPlatform::getInstance()->checkVersion(JVERSION, '3.0', 'gt')) { if ($show_filters) { JHtmlSidebar::setAction("index.php?option=" . $input->getCmd('option') . "&view=" . FOFInflector::pluralize($input->getCmd('view'))); } // Reorder the fields with ordering first $tmpFields = array(); $i = 1; foreach ($headerFields as $tmpField) { if ($tmpField instanceof FOFFormHeaderOrdering) { $tmpFields[0] = $tmpField; } else { $tmpFields[$i] = $tmpField; } $i++; } $headerFields = $tmpFields; ksort($headerFields, SORT_NUMERIC); } // Pre-render the header and filter rows $header_html = ''; $filter_html = ''; $sortFields = array(); if ($show_header || $show_filters) { foreach ($headerFields as $headerField) { $header = $headerField->header; $filter = $headerField->filter; $buttons = $headerField->buttons; $options = $headerField->options; $sortable = $headerField->sortable; $tdwidth = $headerField->tdwidth; // Under Joomla! < 3.0 we can't have filter-only fields if (FOFPlatform::getInstance()->checkVersion(JVERSION, '3.0', 'lt') && empty($header)) { continue; } // If it's a sortable field, add to the list of sortable fields if ($sortable) { $sortFields[$headerField->name] = JText::_($headerField->label); } // Get the table data width, if set if (!empty($tdwidth)) { $tdwidth = 'width="' . $tdwidth . '"'; } else { $tdwidth = ''; } if (!empty($header)) { $header_html .= "\t\t\t\t\t<th {$tdwidth}>" . PHP_EOL; $header_html .= "\t\t\t\t\t\t" . $header; $header_html .= "\t\t\t\t\t</th>" . PHP_EOL; } if (FOFPlatform::getInstance()->checkVersion(JVERSION, '3.0', 'ge')) { // Joomla! 3.0 or later if (!empty($filter)) { $filter_html .= '<div class="filter-search btn-group pull-left">' . "\n"; $filter_html .= "\t" . '<label for="title" class="element-invisible">'; $filter_html .= JText::_($headerField->label); $filter_html .= "</label>\n"; $filter_html .= "\t{$filter}\n"; $filter_html .= "</div>\n"; if (!empty($buttons)) { $filter_html .= '<div class="btn-group pull-left hidden-phone">' . "\n"; $filter_html .= "\t{$buttons}\n"; $filter_html .= '</div>' . "\n"; } } elseif (!empty($options)) { $label = $headerField->label; JHtmlSidebar::addFilter('- ' . JText::_($label) . ' -', (string) $headerField->name, JHtml::_('select.options', $options, 'value', 'text', $model->getState($headerField->name, ''), true)); } } else { // Joomla! 2.5 $filter_html .= "\t\t\t\t\t<td>" . PHP_EOL; if (!empty($filter)) { $filter_html .= "\t\t\t\t\t\t{$filter}" . PHP_EOL; if (!empty($buttons)) { $filter_html .= '<div class="btn-group pull-left hidden-phone">' . PHP_EOL; $filter_html .= "\t\t\t\t\t\t{$buttons}" . PHP_EOL; $filter_html .= '</div>' . PHP_EOL; } } elseif (!empty($options)) { $label = $headerField->label; $emptyOption = JHtml::_('select.option', '', '- ' . JText::_($label) . ' -'); array_unshift($options, $emptyOption); $attribs = array('onchange' => 'document.adminForm.submit();'); $filter = JHtml::_('select.genericlist', $options, $headerField->name, $attribs, 'value', 'text', $headerField->value, false, true); $filter_html .= "\t\t\t\t\t\t{$filter}" . PHP_EOL; } $filter_html .= "\t\t\t\t\t</td>" . PHP_EOL; } } } // Start the form $filter_order = $form->getView()->getLists()->order; $filter_order_Dir = $form->getView()->getLists()->order_Dir; $html .= '<form action="index.php" method="post" name="adminForm" id="adminForm">' . PHP_EOL; if (FOFPlatform::getInstance()->checkVersion(JVERSION, '3.0', 'ge')) { // Joomla! 3.0+ // Get and output the sidebar, if present $sidebar = JHtmlSidebar::render(); if ($show_filters && !empty($sidebar)) { $html .= '<div id="j-sidebar-container" class="span2">' . "\n"; $html .= "\t{$sidebar}\n"; $html .= "</div>\n"; $html .= '<div id="j-main-container" class="span10">' . "\n"; } else { $html .= '<div id="j-main-container">' . "\n"; } // Render header search fields, if the header is enabled if ($show_header) { $html .= "\t" . '<div id="filter-bar" class="btn-toolbar">' . "\n"; $html .= "{$filter_html}\n"; if ($show_pagination) { // Render the pagination rows per page selection box, if the pagination is enabled $html .= "\t" . '<div class="btn-group pull-right hidden-phone">' . "\n"; $html .= "\t\t" . '<label for="limit" class="element-invisible">' . JText::_('JFIELD_PLG_SEARCH_SEARCHLIMIT_DESC') . '</label>' . "\n"; $html .= "\t\t" . $model->getPagination()->getLimitBox() . "\n"; $html .= "\t" . '</div>' . "\n"; } if (!empty($sortFields)) { // Display the field sort order $asc_sel = $view->getLists()->order_Dir == 'asc' ? 'selected="selected"' : ''; $desc_sel = $view->getLists()->order_Dir == 'desc' ? 'selected="selected"' : ''; $html .= "\t" . '<div class="btn-group pull-right hidden-phone">' . "\n"; $html .= "\t\t" . '<label for="directionTable" class="element-invisible">' . JText::_('JFIELD_ORDERING_DESC') . '</label>' . "\n"; $html .= "\t\t" . '<select name="directionTable" id="directionTable" class="input-medium" onchange="Joomla.orderTable()">' . "\n"; $html .= "\t\t\t" . '<option value="">' . JText::_('JFIELD_ORDERING_DESC') . '</option>' . "\n"; $html .= "\t\t\t" . '<option value="asc" ' . $asc_sel . '>' . JText::_('JGLOBAL_ORDER_ASCENDING') . '</option>' . "\n"; $html .= "\t\t\t" . '<option value="desc" ' . $desc_sel . '>' . JText::_('JGLOBAL_ORDER_DESCENDING') . '</option>' . "\n"; $html .= "\t\t" . '</select>' . "\n"; $html .= "\t" . '</div>' . "\n\n"; // Display the sort fields $html .= "\t" . '<div class="btn-group pull-right">' . "\n"; $html .= "\t\t" . '<label for="sortTable" class="element-invisible">' . JText::_('JGLOBAL_SORT_BY') . '</label>' . "\n"; $html .= "\t\t" . '<select name="sortTable" id="sortTable" class="input-medium" onchange="Joomla.orderTable()">' . "\n"; $html .= "\t\t\t" . '<option value="">' . JText::_('JGLOBAL_SORT_BY') . '</option>' . "\n"; $html .= "\t\t\t" . JHtml::_('select.options', $sortFields, 'value', 'text', $view->getLists()->order) . "\n"; $html .= "\t\t" . '</select>' . "\n"; $html .= "\t" . '</div>' . "\n"; } $html .= "\t</div>\n\n"; $html .= "\t" . '<div class="clearfix"> </div>' . "\n\n"; } } // Start the table output $html .= "\t\t" . '<table class="table table-striped" id="itemsList">' . PHP_EOL; // Open the table header region if required if ($show_header || $show_filters && FOFPlatform::getInstance()->checkVersion(JVERSION, '3.0', 'lt')) { $html .= "\t\t\t<thead>" . PHP_EOL; } // Render the header row, if enabled if ($show_header) { $html .= "\t\t\t\t<tr>" . PHP_EOL; $html .= $header_html; $html .= "\t\t\t\t</tr>" . PHP_EOL; } // Render filter row if enabled if ($show_filters && FOFPlatform::getInstance()->checkVersion(JVERSION, '3.0', 'lt')) { $html .= "\t\t\t\t<tr>"; $html .= $filter_html; $html .= "\t\t\t\t</tr>"; } // Close the table header region if required if ($show_header || $show_filters && FOFPlatform::getInstance()->checkVersion(JVERSION, '3.0', 'lt')) { $html .= "\t\t\t</thead>" . PHP_EOL; } // Loop through rows and fields, or show placeholder for no rows $html .= "\t\t\t<tbody>" . PHP_EOL; $fields = $form->getFieldset('items'); $num_columns = count($fields); $items = $model->getItemList(); if ($count = count($items)) { $m = 1; foreach ($items as $i => $item) { $table_item = $model->getTable(); $table_item->reset(); $table_item->bind($item); $form->bind($item); $m = 1 - $m; $class = 'row' . $m; $html .= "\t\t\t\t<tr class=\"{$class}\">" . PHP_EOL; $fields = $form->getFieldset('items'); // Reorder the fields to have ordering first if (FOFPlatform::getInstance()->checkVersion(JVERSION, '3.0', 'gt')) { $tmpFields = array(); $j = 1; foreach ($fields as $tmpField) { if ($tmpField instanceof FOFFormFieldOrdering) { $tmpFields[0] = $tmpField; } else { $tmpFields[$j] = $tmpField; } $j++; } $fields = $tmpFields; ksort($fields, SORT_NUMERIC); } foreach ($fields as $field) { $field->rowid = $i; $field->item = $table_item; $class = $field->labelClass ? 'class ="' . $field->labelClass . '"' : ''; $html .= "\t\t\t\t\t<td {$class}>" . $field->getRepeatable() . '</td>' . PHP_EOL; } $html .= "\t\t\t\t</tr>" . PHP_EOL; } } elseif ($norows_placeholder) { $html .= "\t\t\t\t<tr><td colspan=\"{$num_columns}\">"; $html .= JText::_($norows_placeholder); $html .= "</td></tr>\n"; } $html .= "\t\t\t</tbody>" . PHP_EOL; // Render the pagination bar, if enabled, on J! 2.5 if ($show_pagination && FOFPlatform::getInstance()->checkVersion(JVERSION, '3.0', 'lt')) { $pagination = $model->getPagination(); $html .= "\t\t\t<tfoot>" . PHP_EOL; $html .= "\t\t\t\t<tr><td colspan=\"{$num_columns}\">"; if ($pagination->total > 0) { $html .= $pagination->getListFooter(); } $html .= "</td></tr>\n"; $html .= "\t\t\t</tfoot>" . PHP_EOL; } // End the table output $html .= "\t\t" . '</table>' . PHP_EOL; // Render the pagination bar, if enabled, on J! 3.0+ if ($show_pagination && FOFPlatform::getInstance()->checkVersion(JVERSION, '3.0', 'ge')) { $html .= $model->getPagination()->getListFooter(); } // Close the wrapper element div on Joomla! 3.0+ if (FOFPlatform::getInstance()->checkVersion(JVERSION, '3.0', 'ge')) { $html .= "</div>\n"; } $html .= "\t" . '<input type="hidden" name="option" value="' . $input->getCmd('option') . '" />' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="view" value="' . FOFInflector::pluralize($input->getCmd('view')) . '" />' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="task" value="' . $input->getCmd('task', 'browse') . '" />' . PHP_EOL; // The id field is required in Joomla! 3 front-end to prevent the pagination limit box from screwing it up. Huh!! if (FOFPlatform::getInstance()->checkVersion(JVERSION, '3.0', 'ge') && FOFPlatform::getInstance()->isFrontend()) { $html .= "\t" . '<input type="hidden" name="id" value="' . $input->getCmd('id', '') . '" />' . PHP_EOL; } $html .= "\t" . '<input type="hidden" name="boxchecked" value="" />' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="hidemainmenu" value="" />' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="filter_order" value="' . $filter_order . '" />' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="filter_order_Dir" value="' . $filter_order_Dir . '" />' . PHP_EOL; $html .= "\t" . '<input type="hidden" name="' . JFactory::getSession()->getFormToken() . '" value="1" />' . PHP_EOL; // End the form $html .= '</form>' . PHP_EOL; return $html; }
/** * Finds a suitable renderer * * @return FOFRenderAbstract */ protected function findRenderer() { $filesystem = FOFPlatform::getInstance()->getIntegrationObject('filesystem'); // Try loading the stock renderers shipped with FOF if (empty(self::$renderers) || !class_exists('FOFRenderJoomla', false)) { $path = dirname(__FILE__) . '/../render/'; $renderFiles = $filesystem->folderFiles($path, '.php'); if (!empty($renderFiles)) { foreach ($renderFiles as $filename) { if ($filename == 'abstract.php') { continue; } @(include_once $path . '/' . $filename); $camel = FOFInflector::camelize($filename); $className = 'FOFRender' . ucfirst(FOFInflector::getPart($camel, 0)); $o = new $className(); self::registerRenderer($o); } } } // Try to detect the most suitable renderer $o = null; $priority = 0; if (!empty(self::$renderers)) { foreach (self::$renderers as $r) { $info = $r->getInformation(); if (!$info->enabled) { continue; } if ($info->priority > $priority) { $priority = $info->priority; $o = $r; } } } // Return the current renderer return $o; }
/** * Database iterator constructor. * * @param mixed $cursor The database cursor. * @param string $column An option column to use as the iterator key. * @param string $class The table class of the returned objects. * @param array $config Configuration parameters to push to the table class * * @throws InvalidArgumentException */ public function __construct($cursor, $column = null, $class, $config = array()) { // Figure out the type and prefix of the class by the class name $parts = FOFInflector::explode($class); $this->_tableObject = FOFTable::getInstance($parts[2], ucfirst($parts[0]) . ucfirst($parts[1])); $this->cursor = $cursor; $this->class = 'stdClass'; $this->_column = $column; $this->_fetched = 0; $this->next(); }
/** * 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; }
/** * 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()) { $option = $this->input->getCmd('option', 'com_foobar'); $view = $this->input->getCmd('view', 'cpanels'); $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 $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'); } // 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 JLoader::import('joomla.filesystem.file'); $result = false; foreach ($paths as $path) { foreach ($suffixes as $suffix) { $filename = $path . '/' . $source . $suffix; if (JFile::exists($filename)) { $result = $filename; break; } } if ($result) { break; } } return $result; }
/** * ACL check before changing the publish status of a record; override to customise * * @return boolean True to allow the method to run */ protected function onBeforeUnpublish() { $privilege = $this->configProvider->get($this->component . '.views.' . FOFInflector::singularize($this->view) . '.acl.unpublish', 'core.edit.state'); return $this->checkACL($privilege); }
/** * Get the content type for ucm * * @return string The content type alias */ public function getContentType() { $component = $this->input->get('option'); $view = FOFInflector::singularize($this->input->get('view')); $alias = $component . '.' . $view; return $alias; }
/** * Get the content type for ucm * * @return string The content type alias */ public function getContentType() { if ($this->contentType) { return $this->contentType; } /** * When tags was first introduced contentType variable didn't exist - so we guess one * This will fail if content history behvaiour is enabled. This code is deprecated * and will be removed in FOF 3.0 in favour of the content type class variable */ $component = $this->input->get('option'); $view = FOFInflector::singularize($this->input->get('view')); $alias = $component . '.' . $view; return $alias; }
public static function getPluralization($name, $form = 'singular') { static $cache = array(); if (!empty($cache[$name . '.' . $form])) { return $cache[$name . '.' . $form]; } //Pluralization if (JFile::exists(JPATH_LIBRARIES . '/fof/include.php')) { if (!defined('FOF_INCLUDED')) { require_once JPATH_LIBRARIES . '/fof/include.php'; } } else { if (JFile::exists(JPATH_LIBRARIES . '/fof/inflector/inflector.php')) { require_once JPATH_LIBRARIES . '/fof/inflector/inflector.php'; } else { require_once JPATH_COMPONENT . '/helpers/fofinflector.php'; } } $plural = null; //$inflector = new FOFInflector(); //see if name is singular, if so get a plural if (FOFInflector::isSingular($name)) { $plural = FOFInflector::pluralize($name); } //if still no plural check if name is plural if (empty($plural)) { if (FOFInflector::isPlural($name)) { //if its a plural switch them $plural = $name; //and get a singular $name = FOFInflector::singularize($name); } } //if still no plural just make one anyway if (empty($plural)) { $plural = $name . 's'; } $cache[$name . '.plural'] = $plural; $cache[$name . '.singular'] = $name; return $cache[$name . '.' . $form]; }
/** * Automatically detects all views of the component * * @return array A list of all views, in the order to be displayed in the toolbar submenu */ protected function getMyViews() { $views = array(); $t_views = array(); $using_meta = false; $componentPaths = FOFPlatform::getInstance()->getComponentBaseDirs($this->component); $searchPath = $componentPaths['main'] . '/views'; JLoader::import('joomla.filesystem.folder'); JLoader::import('joomla.utilities.arrayhelper'); $allFolders = JFolder::folders($searchPath); if (!empty($allFolders)) { foreach ($allFolders as $folder) { $view = $folder; // View already added if (in_array(FOFInflector::pluralize($view), $t_views)) { continue; } // Do we have a 'skip.xml' file in there? $files = JFolder::files($searchPath . '/' . $view, '^skip\\.xml$'); if (!empty($files)) { continue; } // Do we have extra information about this view? (ie. ordering) $meta = JFolder::files($searchPath . '/' . $view, '^metadata\\.xml$'); // Not found, do we have it inside the plural one? if (!$meta) { $plural = FOFInflector::pluralize($view); if (in_array($plural, $allFolders)) { $view = $plural; $meta = JFolder::files($searchPath . '/' . $view, '^metadata\\.xml$'); } } if (!empty($meta)) { $using_meta = true; $xml = simplexml_load_file($searchPath . '/' . $view . '/' . $meta[0]); $order = (int) $xml->foflib->ordering; } else { // Next place. It's ok since the index are 0-based and count is 1-based if (!isset($to_order)) { $to_order = array(); } $order = count($to_order); } $view = FOFInflector::pluralize($view); $t_view = new stdClass(); $t_view->ordering = $order; $t_view->view = $view; $to_order[] = $t_view; $t_views[] = $view; } } JArrayHelper::sortObjects($to_order, 'ordering'); $views = JArrayHelper::getColumn($to_order, 'view'); // If not using the metadata file, let's put the cpanel view on top if (!$using_meta) { $cpanel = array_search('cpanels', $views); if ($cpanel !== false) { unset($views[$cpanel]); array_unshift($views, 'cpanels'); } } return $views; }
/** * 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 * * @return string The path and filename of the form to load * * @since 2.0 */ public function findFormFilename($source) { // Get some useful variables list($isCli, $isAdmin) = FOFDispatcher::isCliAdmin(); $option = $this->input->getCmd('option', 'com_foobar'); $view = $this->input->getCmd('view', 'cpanels'); if (!$isCli) { $template = JFactory::getApplication()->getTemplate(); } else { $template = 'cli'; } $file_root = $isAdmin ? JPATH_ADMINISTRATOR : JPATH_SITE; $file_root .= '/components/' . $option; $alt_file_root = $isAdmin ? JPATH_SITE : JPATH_ADMINISTRATOR; $alt_file_root .= '/components/' . $option; $template_root = $isAdmin ? JPATH_ADMINISTRATOR : JPATH_SITE; $template_root .= '/templates/' . $template . '/html/' . $option; // Set up the paths to look into $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'); // Set up the suffixes to look into $jversion = new JVersion(); $versionParts = explode('.', $jversion->RELEASE); $majorVersion = array_shift($versionParts); $suffixes = array('.j' . str_replace('.', '', $jversion->getHelpVersion()) . '.xml', '.j' . $majorVersion . '.xml', '.xml'); unset($jversion, $versionParts, $majorVersion); // Look for all suffixes in all paths JLoader::import('joomla.filesystem.file'); $result = false; foreach ($paths as $path) { foreach ($suffixes as $suffix) { $filename = $path . '/' . $source . $suffix; if (JFile::exists($filename)) { $result = $filename; break; } } if ($result) { break; } } return $result; }
/** * Database iterator constructor. * * @param mixed $cursor The database cursor. * @param string $column An option column to use as the iterator key. * @param string $class The table class of the returned objects. * @param array $config Configuration parameters to push to the table class * * @throws InvalidArgumentException */ public function __construct($cursor, $column = null, $class, $config = array()) { // Figure out the type and prefix of the class by the class name $parts = FOFInflector::explode($class); if (count($parts) != 3) { throw new InvalidArgumentException('Invalid table name, expected a pattern like ComponentTableFoobar got ' . $class); } $this->_tableObject = FOFTable::getInstance($parts[2], ucfirst($parts[0]) . ucfirst($parts[1]))->getClone(); $this->cursor = $cursor; $this->class = 'stdClass'; $this->_column = $column; $this->_fetched = 0; $this->next(); }
/** * Method to get the field options. * * @return array The field option objects. */ protected function getOptions() { $options = array(); $this->value = array(); $value_field = $this->element['value_field'] ? (string) $this->element['value_field'] : 'title'; $input = new FOFInput(); $component = ucfirst(str_replace('com_', '', $input->getString('option'))); $view = ucfirst($input->getString('view')); $relation = FOFInflector::pluralize((string) $this->element['name']); $model = FOFModel::getTmpInstance(ucfirst($relation), $component . 'Model'); $table = $model->getTable(); $key = $table->getKeyName(); $value = $table->getColumnAlias($value_field); foreach ($model->getItemList(true) as $option) { $options[] = JHtml::_('select.option', $option->{$key}, $option->{$value}); } if ($id = FOFModel::getAnInstance($view)->getId()) { $table = FOFTable::getInstance($view, $component . 'Table'); $table->load($id); $relations = $table->getRelations()->getMultiple($relation); foreach ($relations as $item) { $this->value[] = $item->getId(); } } return $options; }
/** * Autoload Helpers * * @param string $class_name The name of the class to load * * @return void */ public function autoload_fof_helper($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, 'Helper') === 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 three parts in the name if (count($parts) != 3) { return; } // We need the second part to be "model" if ($parts[1] != 'helper') { return; } // Get the information about this class $component_raw = $parts[0]; $component = 'com_' . $parts[0]; $view = $parts[2]; // 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 . '_helper_' . $alt_view); // Get the proper and alternate paths and file names $componentPaths = FOFPlatform::getInstance()->getComponentBaseDirs($component); $file = "/helpers/{$view}.php"; $altFile = "/helpers/{$alt_view}.php"; $path = $componentPaths['main']; $altPath = $componentPaths['alt']; // Try to find the proper class in the proper path if (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); } }
/** * Normalises the format of a relation name * * @param string $itemName The raw relation name * @param boolean $pluralise Should I pluralise the name? If not, I will singularise it * * @return string The normalised relation key name */ protected function normaliseItemName($itemName, $pluralise = false) { // Explode the item name $itemNameParts = explode('_', $itemName); // If we have multiple parts the first part is considered to be the component name if (count($itemNameParts) > 1) { $prefix = array_shift($itemNameParts); } else { $prefix = null; } // If we still have multiple parts we need to pluralise/singularise the last part and join everything in // CamelCase format if (count($itemNameParts) > 1) { $name = array_pop($itemNameParts); $name = $pluralise ? FOFInflector::pluralize($name) : FOFInflector::singularize($name); $itemNameParts[] = $name; $itemName = FOFInflector::implode($itemNameParts); } else { $name = array_pop($itemNameParts); $itemName = $pluralise ? FOFInflector::pluralize($name) : FOFInflector::singularize($name); } if (!empty($prefix)) { $itemName = $prefix . '_' . $itemName; } return $itemName; }