예제 #1
0
 /**
  * Public constructor. Instantiates a F0FViewCsv 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 = F0FInflector::pluralize($view);
         $this->csvFilename = strtolower($view);
     }
     if (array_key_exists('csv_fields', $config)) {
         $this->csvFields = $config['csv_fields'];
     }
 }
예제 #2
0
 public function getRepeatable()
 {
     $html = '';
     // Find which is the relation to use
     if ($this->item instanceof F0FTable) {
         // Pluralize the name to match that of the relation
         $relation_name = F0FInflector::pluralize($this->name);
         // Get the relation
         $iterator = $this->item->getRelations()->getMultiple($relation_name);
         $results = array();
         // Decide which class name use in tag markup
         $class = !empty($this->element['class']) ? $this->element['class'] : F0FInflector::singularize($this->name);
         foreach ($iterator as $item) {
             $markup = '<span class="%s">%s</span>';
             // Add link if show_link parameter is set
             if (!empty($this->element['url']) && !empty($this->element['show_link']) && $this->element['show_link']) {
                 // Parse URL
                 $url = $this->getReplacedPlaceholders($this->element['url'], $item);
                 // Set new link markup
                 $markup = '<a class="%s" href="' . JRoute::_($url) . '">%s</a>';
             }
             array_push($results, sprintf($markup, $class, $item->get($item->getColumnAlias('title'))));
         }
         // Join all html segments
         $html .= implode(', ', $results);
     }
     // Parse field parameters
     if (empty($html) && !empty($this->element['empty_replacement'])) {
         $html = JText::_($this->element['empty_replacement']);
     }
     return $html;
 }
예제 #3
0
 private function addSubmenuLink($view, $parent = null)
 {
     static $activeView = null;
     if (empty($activeView)) {
         $activeView = $this->input->getCmd('view', 'cpanel');
     }
     if ($activeView == 'cpanels') {
         $activeView = 'cpanel';
     }
     $key = strtoupper($this->component) . '_TITLE_' . strtoupper($view);
     if (strtoupper(JText::_($key)) == $key) {
         $altview = F0FInflector::isPlural($view) ? F0FInflector::singularize($view) : F0FInflector::pluralize($view);
         $key2 = strtoupper($this->component) . '_TITLE_' . strtoupper($altview);
         if (strtoupper(JText::_($key2)) == $key2) {
             $name = ucfirst($view);
         } else {
             $name = JText::_($key2);
         }
     } else {
         $name = JText::_($key);
     }
     $link = 'index.php?option=' . $this->component . '&view=' . $view;
     $active = $view == $activeView;
     $this->appendLink($name, $link, $active, null, $parent);
 }
예제 #4
0
 /**
  * Checks if the user should be granted access to the current view,
  * based on his Master Password setting.
  *
  * @param string view Optional. The string to check. Leave null to use the current view.
  *
  * @return bool
  */
 public function accessAllowed($view = null)
 {
     if (interface_exists('JModel')) {
         $params = JModelLegacy::getInstance('Storage', 'AdmintoolsModel');
     } else {
         $params = JModel::getInstance('Storage', 'AdmintoolsModel');
     }
     if (empty($view)) {
         $view = $this->input->get('view', 'cpanel');
     }
     $altView = F0FInflector::isPlural($view) ? F0FInflector::singularize($view) : F0FInflector::pluralize($view);
     if (!in_array($view, $this->views) && !in_array($altView, $this->views)) {
         return true;
     }
     $masterHash = $params->getValue('masterpassword', '');
     if (!empty($masterHash)) {
         $masterHash = md5($masterHash);
         // Compare the master pw with the one the user entered
         $session = JFactory::getSession();
         $userHash = $session->get('userpwhash', '', 'admintools');
         if ($userHash != $masterHash) {
             // The login is invalid. If the view is locked I'll have to kick the user out.
             $lockedviews_raw = $params->getValue('lockedviews', '');
             if (!empty($lockedviews_raw)) {
                 $lockedViews = explode(",", $lockedviews_raw);
                 if (in_array($view, $lockedViews) || in_array($altView, $lockedViews)) {
                     return false;
                 }
             }
         }
     }
     return true;
 }
예제 #5
0
 public function noop()
 {
     if ($customURL = $this->input->getString('returnurl', '')) {
         $customURL = base64_decode($customURL);
     }
     $url = !empty($customURL) ? $customURL : 'index.php?option=' . $this->component . '&view=' . F0FInflector::pluralize($this->view);
     $this->setRedirect($url);
 }
예제 #6
0
 public function onBeforeUnpublish()
 {
     $customURL = $this->input->getString('returnurl', '');
     if (!$customURL) {
         $scan_id = $this->input->getCmd('scan_id', 0);
         $url = 'index.php?option=' . $this->component . '&view=' . F0FInflector::pluralize($this->view) . '&scan_id=' . $scan_id;
         $this->input->set('returnurl', base64_encode($url));
     }
     return $this->checkACL('admintools.security');
 }
예제 #7
0
 /**
  * Save fields for many-to-many relations in their pivot tables.
  *
  * @param F0FTable $table Current item table.
  *
  * @return bool True if the object can be saved successfully, false elsewhere.
  * @throws Exception The error message get trying to save fields into the pivot tables.
  */
 public function onAfterStore(&$table)
 {
     // Retrieve the relations configured for this table
     $input = new F0FInput();
     $key = $table->getConfigProviderKey() . '.relations';
     $relations = $table->getConfigProvider()->get($key, array());
     // Abandon the process if not a save task
     if (!in_array($input->getWord('task'), array('apply', 'save', 'savenew'))) {
         return true;
     }
     // For each relation check relative field
     foreach ($relations as $relation) {
         // Only if it is a multiple relation, sure!
         if ($relation['type'] == 'multiple') {
             // Retrive the fully qualified relation data from F0FTableRelations object
             $relation = array_merge(array('itemName' => $relation['itemName']), $table->getRelations()->getRelation($relation['itemName'], $relation['type']));
             // Deduce the name of the field used in the form
             $field_name = F0FInflector::pluralize($relation['itemName']);
             // If field exists we catch its values!
             $field_values = $input->get($field_name, array(), 'array');
             // If the field exists, build the correct pivot couple objects
             $new_couples = array();
             foreach ($field_values as $value) {
                 $new_couples[] = array($relation['ourPivotKey'] => $table->getId(), $relation['theirPivotKey'] => $value);
             }
             // Find existent relations in the pivot table
             $query = $table->getDbo()->getQuery(true)->select($relation['ourPivotKey'] . ', ' . $relation['theirPivotKey'])->from($relation['pivotTable'])->where($relation['ourPivotKey'] . ' = ' . $table->getId());
             $existent_couples = $table->getDbo()->setQuery($query)->loadAssocList();
             // Find new couples and create its
             foreach ($new_couples as $couple) {
                 if (!in_array($couple, $existent_couples)) {
                     $query = $table->getDbo()->getQuery(true)->insert($relation['pivotTable'])->columns($relation['ourPivotKey'] . ', ' . $relation['theirPivotKey'])->values($couple[$relation['ourPivotKey']] . ', ' . $couple[$relation['theirPivotKey']]);
                     // Use database to create the new record
                     if (!$table->getDbo()->setQuery($query)->execute()) {
                         throw new Exception('Can\'t create the relation for the ' . $relation['pivotTable'] . ' table');
                     }
                 }
             }
             // Now find the couples no more present, that will be deleted
             foreach ($existent_couples as $couple) {
                 if (!in_array($couple, $new_couples)) {
                     $query = $table->getDbo()->getQuery(true)->delete($relation['pivotTable'])->where($relation['ourPivotKey'] . ' = ' . $couple[$relation['ourPivotKey']])->where($relation['theirPivotKey'] . ' = ' . $couple[$relation['theirPivotKey']]);
                     // Use database to create the new record
                     if (!$table->getDbo()->setQuery($query)->execute()) {
                         throw new Exception('Can\'t delete the relation for the ' . $relation['pivotTable'] . ' table');
                     }
                 }
             }
         }
     }
     return true;
 }
예제 #8
0
 public function onBeforeDispatch()
 {
     // You can't fix stupid… but you can try working around it
     if (!function_exists('json_encode') || !function_exists('json_decode')) {
         require_once JPATH_ADMINISTRATOR . '/components/' . $this->component . '/helpers/jsonlib.php';
     }
     $result = parent::onBeforeDispatch();
     if ($result) {
         // Merge the language overrides
         $paths = array(JPATH_ADMINISTRATOR, JPATH_ROOT);
         $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);
         // Load Akeeba Strapper
         if (!defined('AKEEBASUBSMEDIATAG')) {
             $staticFilesVersioningTag = md5(AKEEBASUBS_VERSION . AKEEBASUBS_DATE);
             define('AKEEBASUBSMEDIATAG', $staticFilesVersioningTag);
         }
         include_once JPATH_ROOT . '/media/akeeba_strapper/strapper.php';
         AkeebaStrapper::$tag = AKEEBASUBSMEDIATAG;
         AkeebaStrapper::bootstrap();
         AkeebaStrapper::jQueryUI();
         AkeebaStrapper::addCSSfile('media://com_akeebasubs/css/frontend.css', AKEEBASUBS_VERSIONHASH);
         // Load helpers
         require_once JPATH_ADMINISTRATOR . '/components/com_akeebasubs/helpers/cparams.php';
         // Default to the "levels" view
         $view = $this->input->getCmd('view', $this->defaultView);
         if (empty($view) || $view == 'cpanel') {
             $view = 'levels';
         }
         // Set the view, if it's allowed
         $this->input->set('view', $view);
         if (!in_array(F0FInflector::pluralize($view), $this->allowedViews)) {
             $result = false;
         }
         // Handle the submitted form from the tax country module
         $taxCountry = JFactory::getApplication()->input->getCmd('mod_aktaxcountry_country', null);
         if (!is_null($taxCountry)) {
             JFactory::getSession()->set('country', $taxCountry, 'mod_aktaxcountry');
         }
     }
     return $result;
 }
예제 #9
0
 /**
  * Sets the visibility status of a customfields
  *
  * @param int $state 0 = not require, 1 = require
  */
 protected final function setpublic($state = 0)
 {
     $model = $this->getThisModel();
     if (!$model->getId()) {
         $model->setIDsFromRequest();
     }
     $status = $model->visible($state);
     // redirect
     if ($customURL = $this->input->getString('returnurl', '')) {
         $customURL = base64_decode($customURL);
     }
     $url = !empty($customURL) ? $customURL : 'index.php?option=' . $this->component . '&view=' . F0FInflector::pluralize($this->view);
     if (!$status) {
         $this->setRedirect($url, $model->getError(), 'error');
     } else {
         $this->setRedirect($url);
     }
     $this->redirect();
 }
예제 #10
0
 /**
  * import.
  *
  * @return	void
  */
 public function import()
 {
     // CSRF prevention
     if ($this->csrfProtection) {
         $this->_csrfProtection();
     }
     $cid = $this->input->get('cid', array(), 'ARRAY');
     if (empty($cid)) {
         $id = $this->input->getInt('id', 0);
         if ($id) {
             $cid = array($id);
         }
     }
     $helper = FeedLoaderHelper::getInstance();
     $helper->importFeeds($cid);
     // Redirect
     if ($customURL = $this->input->get('returnurl', '', 'string')) {
         $customURL = base64_decode($customURL);
     }
     $url = !empty($customURL) ? $customURL : 'index.php?option=' . $this->component . '&view=' . F0FInflector::pluralize($this->view);
     $this->setRedirect($url);
     ELog::showMessage('COM_AUTOTWEET_VIEW_FEEDS_IMPORT_SUCCESS', JLog::INFO);
 }
예제 #11
0
 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 = F0FInflector::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 = F0FInflector::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;
 }
예제 #12
0
 public function recurringunpublish($cacheable = false)
 {
     $url = 'index.php?option=' . $this->component . '&view=' . F0FInflector::pluralize($this->view);
     $this->setRedirect($url);
     return true;
 }
예제 #13
0
파일: platform.php 프로젝트: 01J/topm
 /**
  * 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 F0FPlatformInterface::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 .= (F0FInflector::isSingular($view) ? F0FInflector::pluralize($view) : F0FInflector::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;
 }
예제 #14
0
 /**
  * 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 = F0FPlatform::getInstance()->getComponentBaseDirs($this->component);
     $searchPath = $componentPaths['main'] . '/views';
     $filesystem = F0FPlatform::getInstance()->getIntegrationObject('filesystem');
     $allFolders = $filesystem->folderFolders($searchPath);
     if (!empty($allFolders)) {
         foreach ($allFolders as $folder) {
             $view = $folder;
             // View already added
             if (in_array(F0FInflector::pluralize($view), $t_views)) {
                 continue;
             }
             // Do we have a 'skip.xml' file in there?
             $files = $filesystem->folderFiles($searchPath . '/' . $view, '^skip\\.xml$');
             if (!empty($files)) {
                 continue;
             }
             // Do we have extra information about this view? (ie. ordering)
             $meta = $filesystem->folderFiles($searchPath . '/' . $view, '^metadata\\.xml$');
             // Not found, do we have it inside the plural one?
             if (!$meta) {
                 $plural = F0FInflector::pluralize($view);
                 if (in_array($plural, $allFolders)) {
                     $view = $plural;
                     $meta = $filesystem->folderFiles($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 = F0FInflector::pluralize($view);
             $t_view = new stdClass();
             $t_view->ordering = $order;
             $t_view->view = $view;
             $to_order[] = $t_view;
             $t_views[] = $view;
         }
     }
     F0FUtilsArray::sortObjects($to_order, 'ordering');
     $views = F0FUtilsArray::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;
 }
예제 #15
0
 /**
  * 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'] . '_' . F0FInflector::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;
 }
예제 #16
0
파일: order.php 프로젝트: afend/RULug
 /**
  * The event which runs before storing (saving) data to the database
  *
  * @param   boolean  $updateNulls  Should nulls be saved as nulls (true) or just skipped over (false)?
  *
  * @return  boolean  True to allow saving
  */
 protected function onBeforeStore($updateNulls)
 {
     // Do we have a "Created" set of fields?
     $created_on = $this->getColumnAlias('created_on');
     $created_by = $this->getColumnAlias('created_by');
     $modified_on = $this->getColumnAlias('modified_on');
     $modified_by = $this->getColumnAlias('modified_by');
     $locked_on = $this->getColumnAlias('locked_on');
     $locked_by = $this->getColumnAlias('locked_by');
     $title = $this->getColumnAlias('title');
     $slug = $this->getColumnAlias('slug');
     $hasCreatedOn = in_array($created_on, $this->getKnownFields());
     $hasCreatedBy = in_array($created_by, $this->getKnownFields());
     if ($hasCreatedOn && $hasCreatedBy) {
         $hasModifiedOn = in_array($modified_on, $this->getKnownFields());
         $hasModifiedBy = in_array($modified_by, $this->getKnownFields());
         $nullDate = $this->_db->getNullDate();
         if ($this->{$created_on} == $nullDate || empty($this->{$created_on})) {
             $uid = F0FPlatform::getInstance()->getUser()->id;
             if ($uid) {
                 $this->{$created_by} = F0FPlatform::getInstance()->getUser()->id;
             }
             $date = F0FPlatform::getInstance()->getDate('now', null, false);
             $this->{$created_on} = $date->toSql();
         } elseif ($hasModifiedOn && $hasModifiedBy) {
             $uid = F0FPlatform::getInstance()->getUser()->id;
             if ($uid) {
                 $this->{$modified_by} = F0FPlatform::getInstance()->getUser()->id;
             }
             $date = F0FPlatform::getInstance()->getDate('now', null, false);
             $this->{$modified_on} = $date->toSql();
         }
     }
     // Do we have a set of title and slug fields?
     $hasTitle = in_array($title, $this->getKnownFields());
     $hasSlug = in_array($slug, $this->getKnownFields());
     if ($hasTitle && $hasSlug) {
         if (empty($this->{$slug})) {
             // Create a slug from the title
             $this->{$slug} = F0FStringUtils::toSlug($this->{$title});
         } else {
             // Filter the slug for invalid characters
             $this->{$slug} = F0FStringUtils::toSlug($this->{$slug});
         }
         // Make sure we don't have a duplicate slug on this table
         $db = $this->getDbo();
         $query = $db->getQuery(true)->select($db->qn($slug))->from($this->_tbl)->where($db->qn($slug) . ' = ' . $db->q($this->{$slug}))->where('NOT ' . $db->qn($this->_tbl_key) . ' = ' . $db->q($this->{$this->_tbl_key}));
         $db->setQuery($query);
         $existingItems = $db->loadAssocList();
         $count = 0;
         $newSlug = $this->{$slug};
         while (!empty($existingItems)) {
             $count++;
             $newSlug = $this->{$slug} . '-' . $count;
             $query = $db->getQuery(true)->select($db->qn($slug))->from($this->_tbl)->where($db->qn($slug) . ' = ' . $db->q($newSlug))->where('NOT ' . $db->qn($this->_tbl_key) . ' = ' . $db->q($this->{$this->_tbl_key}));
             $db->setQuery($query);
             $existingItems = $db->loadAssocList();
         }
         $this->{$slug} = $newSlug;
     }
     // Call the behaviors
     $result = $this->tableDispatcher->trigger('onBeforeStore', array(&$this, $updateNulls));
     if (in_array(false, $result, true)) {
         // Behavior failed, return false
         return false;
     }
     // Execute onBeforeStore<tablename> events in loaded plugins
     if ($this->_trigger_events) {
         $name = F0FInflector::pluralize($this->getKeyName());
         $result = F0FPlatform::getInstance()->runPlugins('onBeforeStore' . ucfirst($name), array(&$this, $updateNulls));
         if (in_array(false, $result, true)) {
             return false;
         } else {
             return true;
         }
     }
     return true;
 }
예제 #17
0
					<button class="btn"
							onclick="return doMassSelect(1);"><?php 
echo JText::_('ATOOLS_LBL_MASTERPW_ALL');
?>
</button>
					<button class="btn"
							onclick="return doMassSelect(0);"><?php 
echo JText::_('ATOOLS_LBL_MASTERPW_NONE');
?>
</button>
				</div>
			</div>
		</div>
		<?php 
foreach ($this->items as $view => $locked) {
    $langKeys = array('ADMINTOOLS_TITLE_' . $view, 'ADMINTOOLS_TITLE_' . F0FInflector::pluralize($view), 'COM_ADMINTOOLS_TITLE_' . $view, 'COM_ADMINTOOLS_TITLE_' . F0FInflector::pluralize($view));
    foreach ($langKeys as $langKey) {
        $label = JText::_($langKey);
        if ($label != $langKey) {
            break;
        }
    }
    ?>
			<?php 
    $fieldname = 'views[' . $view . ']';
    ?>
			<div class="control-group">
				<label for="<?php 
    echo $fieldname;
    ?>
"
예제 #18
0
 /**
  * The even which runs before the object is reset to its default values.
  *
  * @return  boolean  True to allow the reset to complete
  */
 protected function onBeforeReset()
 {
     // Call the behaviors
     $result = $this->tableDispatcher->trigger('onBeforeReset', array(&$this));
     if (in_array(false, $result, true)) {
         // Behavior failed, return false
         return false;
     }
     if ($this->_trigger_events) {
         $name = F0FInflector::pluralize($this->getKeyName());
         $result = F0FPlatform::getInstance()->runPlugins('onBeforeReset' . ucfirst($name), array(&$this));
         if (in_array(false, $result, true)) {
             return false;
         } else {
             return true;
         }
     }
     return true;
 }
예제 #19
0
 public function generate($cachable = false, $urlparams = false)
 {
     // Load the model
     $model = $this->getThisModel();
     if (!$model->getId()) {
         $model->setIDsFromRequest();
     }
     // Make sure we have a valid item
     $item = $model->getItem();
     if (!is_object($item) || empty($item->akeebasubs_subscription_id)) {
         return false;
     }
     // Check that this is an administrator
     if (!$this->checkACL('core.manage')) {
         return false;
     }
     // (Re-)generate the invoice
     $sub = F0FModel::getTmpInstance('Subscriptions', 'AkeebasubsModel')->getItem($item->akeebasubs_subscription_id);
     $status = $model->createInvoice($sub) === true;
     // Post-action redirection
     if ($customURL = $this->input->get('returnurl', '', 'string')) {
         $customURL = base64_decode($customURL);
     }
     $url = !empty($customURL) ? $customURL : 'index.php?option=' . $this->component . '&view=' . F0FInflector::pluralize($this->view);
     if ($status === false) {
         $this->setRedirect($url, JText::_('COM_AKEEBASUBS_INVOICES_MSG_NOTGENERATED'), 'error');
     } else {
         $this->setRedirect($url, JText::_('COM_AKEEBASUBS_INVOICES_MSG_GENERATED'));
     }
 }
예제 #20
0
 /**
  * Public constructor. Instantiates a F0FView 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();
     }
     // Get the input
     if (array_key_exists('input', $config)) {
         if ($config['input'] instanceof F0FInput) {
             $this->input = $config['input'];
         } else {
             $this->input = new F0FInput($config['input']);
         }
     } else {
         $this->input = new F0FInput();
     }
     parent::__construct($config);
     $component = 'com_foobar';
     // Get the component name
     if (array_key_exists('input', $config)) {
         if ($config['input'] instanceof F0FInput) {
             $tmpInput = $config['input'];
         } else {
             $tmpInput = new F0FInput($config['input']);
         }
         $component = $tmpInput->getCmd('option', '');
     } else {
         $tmpInput = $this->input;
     }
     if (array_key_exists('option', $config)) {
         if ($config['option']) {
             $component = $config['option'];
         }
     }
     $config['option'] = $component;
     // Get the view name
     $view = null;
     if (array_key_exists('input', $config)) {
         $view = $tmpInput->getCmd('view', '');
     }
     if (array_key_exists('view', $config)) {
         if ($config['view']) {
             $view = $config['view'];
         }
     }
     $config['view'] = $view;
     // Set the component and the view to the input array
     if (array_key_exists('input', $config)) {
         $tmpInput->set('option', $config['option']);
         $tmpInput->set('view', $config['view']);
     }
     // Set the view name
     if (array_key_exists('name', $config)) {
         $this->_name = $config['name'];
     } else {
         $this->_name = $config['view'];
     }
     $tmpInput->set('view', $this->_name);
     $config['input'] = $tmpInput;
     $config['name'] = $this->_name;
     $config['view'] = $this->_name;
     // Get the component directories
     $componentPaths = F0FPlatform::getInstance()->getComponentBaseDirs($config['option']);
     // Set the charset (used by the variable escaping functions)
     if (array_key_exists('charset', $config)) {
         F0FPlatform::getInstance()->logDeprecated('Setting a custom charset for escaping in F0FView\'s constructor is deprecated. Override F0FView::escape() instead.');
         $this->_charset = $config['charset'];
     }
     // User-defined escaping callback
     if (array_key_exists('escape', $config)) {
         $this->setEscape($config['escape']);
     }
     // Set a base path for use by the view
     if (array_key_exists('base_path', $config)) {
         $this->_basePath = $config['base_path'];
     } else {
         $this->_basePath = $componentPaths['main'];
     }
     // Set the default template search path
     if (array_key_exists('template_path', $config)) {
         // User-defined dirs
         $this->_setPath('template', $config['template_path']);
     } else {
         $altView = F0FInflector::isSingular($this->getName()) ? F0FInflector::pluralize($this->getName()) : F0FInflector::singularize($this->getName());
         $this->_setPath('template', $this->_basePath . '/views/' . $altView . '/tmpl');
         $this->_addPath('template', $this->_basePath . '/views/' . $this->getName() . '/tmpl');
     }
     // Set the default helper search path
     if (array_key_exists('helper_path', $config)) {
         // User-defined dirs
         $this->_setPath('helper', $config['helper_path']);
     } else {
         $this->_setPath('helper', $this->_basePath . '/helpers');
     }
     // Set the layout
     if (array_key_exists('layout', $config)) {
         $this->setLayout($config['layout']);
     } else {
         $this->setLayout('default');
     }
     $this->config = $config;
     if (!F0FPlatform::getInstance()->isCli()) {
         $this->baseurl = F0FPlatform::getInstance()->URIbase(true);
         $fallback = F0FPlatform::getInstance()->getTemplateOverridePath($component) . '/' . $this->getName();
         $this->_addPath('template', $fallback);
     }
 }
예제 #21
0
    /**
     * Renders a F0FForm for a Browse 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 renderFormBrowse(F0FForm &$form, F0FModel $model, F0FInput $input)
    {
        $html = '';
        JHtml::_('behavior.multiselect');
        // Joomla! 3.0+ support
        if (version_compare(JVERSION, '3.0', 'ge')) {
            JHtml::_('bootstrap.tooltip');
            JHtml::_('dropdown.init');
            JHtml::_('formbehavior.chosen', 'select');
            $view = $form->getView();
            $order = $view->escape($view->getLists()->order);
            $html .= <<<HTML
<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>

HTML;
        } else {
            JHtml::_('behavior.tooltip');
        }
        // 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 (version_compare(JVERSION, '3.0', 'gt')) {
            $form_class = '';
            if ($show_filters) {
                JHtmlSidebar::setAction("index.php?option=" . $input->getCmd('option') . "&view=" . F0FInflector::pluralize($input->getCmd('view')));
            }
            // Reorder the fields with ordering first
            $tmpFields = array();
            $i = 1;
            foreach ($headerFields as $tmpField) {
                if ($tmpField instanceof F0FFormHeaderOrdering) {
                    $tmpFields[0] = $tmpField;
                } else {
                    $tmpFields[$i] = $tmpField;
                }
                $i++;
            }
            $headerFields = $tmpFields;
            ksort($headerFields, SORT_NUMERIC);
        } else {
            $form_class = 'class="form-horizontal"';
        }
        // 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 (version_compare(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 (version_compare(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 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" ' . $form_class . '>' . PHP_EOL;
        if (version_compare(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 && version_compare(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 && version_compare(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 && version_compare(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 (version_compare(JVERSION, '3.0', 'gt')) {
                    $tmpFields = array();
                    $j = 1;
                    foreach ($fields as $tmpField) {
                        if ($tmpField instanceof F0FFormFieldOrdering) {
                            $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;
                    $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, on J! 2.5
        if ($show_pagination && version_compare(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 && version_compare(JVERSION, '3.0', 'ge')) {
            $html .= $model->getPagination()->getListFooter();
        }
        // Close the wrapper element div on Joomla! 3.0+
        if (version_compare(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="' . F0FInflector::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 (version_compare(JVERSION, '3.0', 'ge') && F0FPlatform::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;
        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;
        // End the form
        $html .= '</form>' . PHP_EOL;
        return $html;
    }
예제 #22
0
 /**
  * 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 ? F0FInflector::pluralize($name) : F0FInflector::singularize($name);
         $itemNameParts[] = $name;
         $itemName = F0FInflector::implode($itemNameParts);
     } else {
         $name = array_pop($itemNameParts);
         $itemName = $pluralise ? F0FInflector::pluralize($name) : F0FInflector::singularize($name);
     }
     if (!empty($prefix)) {
         $itemName = $prefix . '_' . $itemName;
     }
     return $itemName;
 }
예제 #23
0
 /**
  * Create objects for the options
  *
  * @return  array  The array of option objects
  */
 protected function getOptions()
 {
     // Field options: title translate and show how much related items
     $countAndShowRelated = (string) $this->element['countAndShowRelated'] == 'true';
     $translateTitle = (string) $this->element['translateTitle'] == 'true';
     $table = $this->form->getModel()->getTable();
     // Get relation definitions from fof.xml
     $key = $table->getConfigProviderKey() . '.relations';
     $relations = $table->getConfigProvider()->get($key, array());
     // Get the relation type:
     $relationType = '';
     foreach ($relations as $relation) {
         if ($relation['itemName'] == $this->name) {
             $relationType = $relation['type'];
             break;
         }
     }
     // Get full relation definitions from F0FTableRelation object:
     $relation = $table->getRelations()->getRelation($this->name, $relationType);
     $dbOptions = array();
     // First implementation: multiple relations. Not using others yet
     if ($relation['type'] == 'multiple') {
         // Guessing the related table name from the given tableclassname followed the naming-conventions:
         list($option, $tableWord, $optItemSingular) = explode('_', F0FInflector::underscore($relation['tableClass']));
         $optionsTableName = '#__' . $option . '_' . F0FInflector::pluralize($optItemSingular);
         // Get the options table object
         $optionsTableObject = F0FTable::getAnInstance($relation['tableClass'], null);
         // Get the Items
         $db = JFactory::getDbo();
         $q = $db->getQuery(true)->select('o.*')->from($db->qn($optionsTableName) . ' as o');
         // Should we count and show related items?
         if ($countAndShowRelated) {
             $q->select('count(' . $db->qn('p.' . $relation['ourPivotKey']) . ') as total');
             $q->leftJoin($db->qn($relation['pivotTable']) . ' as p on ' . $db->qn('o.' . $relation['remoteKey']) . ' = ' . $db->qn('p.' . $relation['theirPivotKey']));
             $q->group($db->qn('o.' . $relation['remoteKey']));
         }
         // todo Language-filtering?
         $dbOptions = $db->setQuery($q)->loadObjectList($relation['remoteKey']);
     }
     $options = array();
     // Get the field $options on top
     foreach ($this->element->children() as $option) {
         // Only add <option /> elements.
         if ($option->getName() != 'option') {
             continue;
         }
         // Create a new option object based on the <option /> element.
         $options[] = JHtml::_('select.option', (string) $option['value'], JText::alt(trim((string) $option), preg_replace('/[^a-zA-Z0-9_\\-]/', '_', $this->fieldname)), 'value', 'text', (string) $option['disabled'] == 'true');
     }
     // Loop through the data and prime the $options array
     // Get title column alias:
     $titleField = $optionsTableObject->getColumnAlias('title');
     $keyField = $relation['remoteKey'];
     $enabledField = $optionsTableObject->getColumnAlias('enabled');
     foreach ($dbOptions as $dbOption) {
         $key = $dbOption->{$keyField};
         $value = $dbOption->{$titleField};
         $disabled = !$dbOption->{$enabledField} ? true : false;
         if ($translateTitle) {
             $value = JText::_($value);
         }
         if ($countAndShowRelated) {
             $value = $value . ' (' . $dbOption->total . ')';
         }
         $options[] = JHtml::_('select.option', $key, $value, 'value', 'text', $disabled);
     }
     return $options;
 }
예제 #24
0
 /**
  * The main code of the Dispatcher. It spawns the necessary controller and
  * runs it.
  *
  * @throws Exception
  *
  * @return  void|Exception
  */
 public function dispatch()
 {
     $platform = F0FPlatform::getInstance();
     if (!$platform->authorizeAdmin($this->input->getCmd('option', 'com_foobar'))) {
         return $platform->raiseError(403, JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'));
     }
     $this->transparentAuthentication();
     // Merge English and local translations
     $platform->loadTranslations($this->component);
     $canDispatch = true;
     if ($platform->isCli()) {
         $canDispatch = $canDispatch && $this->onBeforeDispatchCLI();
     }
     $canDispatch = $canDispatch && $this->onBeforeDispatch();
     if (!$canDispatch) {
         // We can set header only if we're not in CLI
         if (!$platform->isCli()) {
             $platform->setHeader('Status', '403 Forbidden', true);
         }
         return $platform->raiseError(403, JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'));
     }
     // Get and execute the controller
     $option = $this->input->getCmd('option', 'com_foobar');
     $view = $this->input->getCmd('view', $this->defaultView);
     $task = $this->input->getCmd('task', null);
     if (empty($task)) {
         $task = $this->getTask($view);
     }
     // Pluralise/sungularise the view name for typical tasks
     if (in_array($task, array('edit', 'add', 'read'))) {
         $view = F0FInflector::singularize($view);
     } elseif (in_array($task, array('browse'))) {
         $view = F0FInflector::pluralize($view);
     }
     $this->input->set('view', $view);
     $this->input->set('task', $task);
     $config = $this->config;
     $config['input'] = $this->input;
     $controller = F0FController::getTmpInstance($option, $view, $config);
     $status = $controller->execute($task);
     if (!$this->onAfterDispatch()) {
         // We can set header only if we're not in CLI
         if (!$platform->isCli()) {
             $platform->setHeader('Status', '403 Forbidden', true);
         }
         return $platform->raiseError(403, JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'));
     }
     $format = $this->input->get('format', 'html', 'cmd');
     $format = empty($format) ? 'html' : $format;
     if ($controller->hasRedirect()) {
         $controller->redirect();
     }
 }
예제 #25
0
파일: model.php 프로젝트: 01J/topm
 /**
  * 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;
 }
예제 #26
0
 /**
  * addSubmenuLink
  *
  * @param   object  $view    Param
  * @param   object  $parent  Param
  *
  * @return  void
  */
 private function addSubmenuLink($view, $parent = null)
 {
     static $activeView = null;
     if (empty($activeView)) {
         $activeView = $this->input->getCmd('view', 'cpanel');
     }
     if ($activeView == 'cpanels') {
         $activeView = 'cpanel';
     }
     $icon_key = strtoupper($this->component) . '_ICON_' . strtoupper($view);
     $icon = JText::_($icon_key);
     $key = strtoupper($this->component) . '_TITLE_' . strtoupper($view);
     if (strtoupper(JText::_($key)) == $key) {
         $altview = F0FInflector::isPlural($view) ? F0FInflector::singularize($view) : F0FInflector::pluralize($view);
         $key2 = strtoupper($this->component) . '_TITLE_' . strtoupper($altview);
         if (strtoupper(JText::_($key2)) == $key2) {
             $name = ucfirst($view);
         } else {
             $name = JText::_($key2);
         }
     } else {
         $name = JText::_($key);
     }
     if ($view == 'usermanual') {
         $link = 'http://documentation.extly.com/';
     } elseif ($view == 'options') {
         $component = urlencode($this->component);
         $uri = (string) JUri::getInstance();
         $return = urlencode(base64_encode($uri));
         $link = 'index.php?option=com_config&amp;view=component&amp;component=' . $component . '&amp;path=&amp;return=' . $return;
     } else {
         $link = 'index.php?option=' . $this->component . '&view=' . $view;
     }
     $active = $view == $activeView;
     $this->appendLink($icon . ' ' . $name, $link, $active, null, $parent);
 }
예제 #27
0
파일: joomla.php 프로젝트: kidaa30/lojinha
 /**
  * Renders a F0FForm for a Browse 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 renderFormBrowse(F0FForm &$form, F0FModel $model, F0FInput $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;
     $actionUrl = F0FPlatform::getInstance()->isBackend() ? 'index.php' : JUri::root() . 'index.php';
     if (F0FPlatform::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="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="' . F0FInflector::pluralize($input->getCmd('view')) . '" />' . PHP_EOL;
     $html .= "\t" . '<input type="hidden" name="task" value="" />' . PHP_EOL;
     $html .= "\t" . '<input type="hidden" name="layout" value="' . $input->getCmd('layout', '') . '" />' . 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;
     // 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;
 }
예제 #28
0
 /**
  * Autoload Helpers
  *
  * @param   string  $class_name  The name of the class to load
  *
  * @return  void
  */
 public function autoload_fof_helper($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, '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 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 . '_helper_' . $alt_view);
     // Get the proper and alternate paths and file names
     $componentPaths = F0FPlatform::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);
     }
 }
예제 #29
0
 /**
  * Creates a View object instance and returns it
  *
  * @param   string  $name    The name of the view, e.g. Items
  * @param   string  $prefix  The prefix of the view, e.g. FoobarView
  * @param   string  $type    The type of the view, usually one of Html, Raw, Json or Csv
  * @param   array   $config  The configuration variables to use for creating the view
  *
  * @return  F0FView
  */
 protected function createView($name, $prefix = '', $type = '', $config = array())
 {
     // Make sure $config is an array
     if (is_object($config)) {
         $config = (array) $config;
     } elseif (!is_array($config)) {
         $config = array();
     }
     $result = null;
     // Clean the view name
     $viewName = preg_replace('/[^A-Z0-9_]/i', '', $name);
     $classPrefix = preg_replace('/[^A-Z0-9_]/i', '', $prefix);
     $viewType = preg_replace('/[^A-Z0-9_]/i', '', $type);
     if (!isset($config['input'])) {
         $config['input'] = $this->input;
     }
     if ($config['input'] instanceof F0FInput) {
         $tmpInput = $config['input'];
     } else {
         $tmpInput = new F0FInput($config['input']);
     }
     // Guess the component name and view
     if (!empty($prefix)) {
         preg_match('/(.*)View$/', $prefix, $m);
         $component = 'com_' . strtolower($m[1]);
     } else {
         $component = '';
     }
     if (empty($component) && array_key_exists('input', $config)) {
         $component = $tmpInput->get('option', $component, 'cmd');
     }
     if (array_key_exists('option', $config)) {
         if ($config['option']) {
             $component = $config['option'];
         }
     }
     $config['option'] = $component;
     $view = strtolower($viewName);
     if (empty($view) && array_key_exists('input', $config)) {
         $view = $tmpInput->get('view', $view, 'cmd');
     }
     if (array_key_exists('view', $config)) {
         if ($config['view']) {
             $view = $config['view'];
         }
     }
     $config['view'] = $view;
     if (array_key_exists('input', $config)) {
         $tmpInput->set('option', $config['option']);
         $tmpInput->set('view', $config['view']);
         $config['input'] = $tmpInput;
     }
     // Get the component directories
     $componentPaths = F0FPlatform::getInstance()->getComponentBaseDirs($config['option']);
     // Get the base paths where the view class files are expected to live
     $basePaths = array($componentPaths['main'], $componentPaths['alt']);
     $basePaths = array_merge($this->paths['view']);
     // Get the alternate (singular/plural) view name
     $altViewName = F0FInflector::isPlural($viewName) ? F0FInflector::singularize($viewName) : F0FInflector::pluralize($viewName);
     $suffixes = array($viewName, $altViewName, 'default');
     $filesystem = F0FPlatform::getInstance()->getIntegrationObject('filesystem');
     foreach ($suffixes as $suffix) {
         // Build the view class name
         $viewClass = $classPrefix . ucfirst($suffix);
         if (class_exists($viewClass)) {
             // The class is already loaded
             break;
         }
         // The class is not loaded. Let's load it!
         $viewPath = $this->createFileName('view', array('name' => $suffix, 'type' => $viewType));
         $path = $filesystem->pathFind($basePaths, $viewPath);
         if ($path) {
             require_once $path;
         }
         if (class_exists($viewClass)) {
             // The class was loaded successfully
             break;
         }
     }
     if (!class_exists($viewClass)) {
         $viewClass = 'F0FView' . ucfirst($type);
     }
     $templateOverridePath = F0FPlatform::getInstance()->getTemplateOverridePath($config['option']);
     // Setup View configuration options
     if (!array_key_exists('template_path', $config)) {
         $config['template_path'][] = $componentPaths['main'] . '/views/' . F0FInflector::pluralize($config['view']) . '/tmpl';
         if ($templateOverridePath) {
             $config['template_path'][] = $templateOverridePath . '/' . F0FInflector::pluralize($config['view']);
         }
         $config['template_path'][] = $componentPaths['main'] . '/views/' . F0FInflector::singularize($config['view']) . '/tmpl';
         if ($templateOverridePath) {
             $config['template_path'][] = $templateOverridePath . '/' . F0FInflector::singularize($config['view']);
         }
         $config['template_path'][] = $componentPaths['main'] . '/views/' . $config['view'] . '/tmpl';
         if ($templateOverridePath) {
             $config['template_path'][] = $templateOverridePath . '/' . $config['view'];
         }
     }
     $extraTemplatePath = $this->configProvider->get($config['option'] . '.views.' . $config['view'] . '.config.template_path', null);
     if ($extraTemplatePath) {
         array_unshift($config['template_path'], $componentPaths['main'] . '/' . $extraTemplatePath);
     }
     if (!array_key_exists('helper_path', $config)) {
         $config['helper_path'] = array($componentPaths['main'] . '/helpers', $componentPaths['admin'] . '/helpers');
     }
     $extraHelperPath = $this->configProvider->get($config['option'] . '.views.' . $config['view'] . '.config.helper_path', null);
     if ($extraHelperPath) {
         $config['helper_path'][] = $componentPaths['main'] . '/' . $extraHelperPath;
     }
     // Set up the page title
     $setFrontendPageTitle = $this->configProvider->get($config['option'] . '.views.' . $config['view'] . '.config.setFrontendPageTitle', null);
     if ($setFrontendPageTitle) {
         $setFrontendPageTitle = strtolower($setFrontendPageTitle);
         $config['setFrontendPageTitle'][] = in_array($setFrontendPageTitle, array('1', 'yes', 'true', 'on'));
     }
     $defaultPageTitle = $this->configProvider->get($config['option'] . '.views.' . $config['view'] . '.config.defaultPageTitle', null);
     if ($defaultPageTitle) {
         $config['defaultPageTitle'][] = in_array($defaultPageTitle, array('1', 'yes', 'true', 'on'));
     }
     // Set the use_hypermedia flag in $config if it's not already set
     if (!isset($config['use_hypermedia'])) {
         $config['use_hypermedia'] = $this->configProvider->get($config['option'] . '.views.' . $config['view'] . '.config.use_hypermedia', false);
     }
     // Set also the linkbar_style
     if (!isset($config['linkbar_style'])) {
         $style = $this->configProvider->get($config['option'] . '.views.' . $config['view'] . '.config.linkbar_style', false);
         if ($style) {
             $config['linkbar_style'] = $style;
         }
     }
     /**
      * Some administrative templates force format=utf (yeah, I know, what the heck, right?) when a format
      * URL parameter does not exist in the URL. Of course there is no such thing as F0FViewUtf (why the heck would
      * it be, there is no such thing as a format=utf in Joomla! for crying out loud) which causes a Fatal Error. So
      * we have to detect that and force $type='html'...
      */
     if (!class_exists($viewClass) && $type != 'html') {
         $type = 'html';
         $result = $this->createView($name, $prefix, $type, $config);
     } else {
         $result = new $viewClass($config);
     }
     return $result;
 }
예제 #30
0
파일: relation.php 프로젝트: esorone/efcpw
 /**
  * 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 F0FInput();
     $component = ucfirst(str_replace('com_', '', $input->getString('option')));
     $view = ucfirst($input->getString('view'));
     $relation = F0FInflector::pluralize((string) $this->element['name']);
     $model = F0FModel::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 = F0FModel::getAnInstance($view)->getId()) {
         $table = F0FTable::getInstance($view, $component . 'Table');
         $table->load($id);
         $relations = $table->getRelations()->getMultiple($relation);
         foreach ($relations as $item) {
             $this->value[] = $item->getId();
         }
     }
     return $options;
 }