コード例 #1
0
ファイル: toolbar.php プロジェクト: ppantilla/bbninja
 /**
  * Gets an instance of a component's toolbar
  *
  * @param   string  $option  The name of the component
  * @param   array   $config  The configuration array for the component
  *
  * @return  F0FToolbar  The toolbar instance for the component
  */
 public static function &getAnInstance($option = null, $config = array())
 {
     static $instances = array();
     // Make sure $config is an array
     if (is_object($config)) {
         $config = (array) $config;
     } elseif (!is_array($config)) {
         $config = array();
     }
     $hash = $option;
     if (!array_key_exists($hash, $instances)) {
         if (array_key_exists('input', $config)) {
             if ($config['input'] instanceof F0FInput) {
                 $input = $config['input'];
             } else {
                 $input = new F0FInput($config['input']);
             }
         } else {
             $input = new F0FInput();
         }
         $config['option'] = !is_null($option) ? $option : $input->getCmd('option', 'com_foobar');
         $input->set('option', $config['option']);
         $config['input'] = $input;
         $className = ucfirst(str_replace('com_', '', $config['option'])) . 'Toolbar';
         if (!class_exists($className)) {
             $componentPaths = F0FPlatform::getInstance()->getComponentBaseDirs($config['option']);
             $searchPaths = array($componentPaths['main'], $componentPaths['main'] . '/toolbars', $componentPaths['alt'], $componentPaths['alt'] . '/toolbars');
             if (array_key_exists('searchpath', $config)) {
                 array_unshift($searchPaths, $config['searchpath']);
             }
             $filesystem = F0FPlatform::getInstance()->getIntegrationObject('filesystem');
             $path = $filesystem->pathFind($searchPaths, 'toolbar.php');
             if ($path) {
                 require_once $path;
             }
         }
         if (!class_exists($className)) {
             $className = 'F0FToolbar';
         }
         $instance = new $className($config);
         $instances[$hash] = $instance;
     }
     return $instances[$hash];
 }
コード例 #2
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;
 }
コード例 #3
0
ファイル: model.php プロジェクト: 01J/topm
 /**
  * Public class constructor
  *
  * @param array $config The configuration 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();
     }
     // Load the configuration provider
     $this->configProvider = new F0FConfigProvider();
     // Load the behavior dispatcher
     $this->modelDispatcher = new F0FModelDispatcherBehavior();
     // Set the $name/$_name variable
     $component = $this->input->getCmd('option', 'com_foobar');
     if (array_key_exists('option', $config)) {
         $component = $config['option'];
     }
     // Set the $name variable
     $this->input->set('option', $component);
     $component = $this->input->getCmd('option', 'com_foobar');
     if (array_key_exists('option', $config)) {
         $component = $config['option'];
     }
     $this->input->set('option', $component);
     $bareComponent = str_replace('com_', '', strtolower($component));
     // Get the view name
     $className = get_class($this);
     if ($className == 'F0FModel') {
         if (array_key_exists('view', $config)) {
             $view = $config['view'];
         }
         if (empty($view)) {
             $view = $this->input->getCmd('view', 'cpanel');
         }
     } else {
         if (array_key_exists('view', $config)) {
             $view = $config['view'];
         }
         if (empty($view)) {
             $eliminatePart = ucfirst($bareComponent) . 'Model';
             $view = strtolower(str_replace($eliminatePart, '', $className));
         }
     }
     if (array_key_exists('name', $config)) {
         $name = $config['name'];
     } else {
         $name = $view;
     }
     $this->name = $name;
     $this->option = $component;
     // Set the model state
     if (array_key_exists('state', $config)) {
         $this->state = $config['state'];
     } else {
         $this->state = new F0FUtilsObject();
     }
     // Set the model dbo
     if (array_key_exists('dbo', $config)) {
         $this->_db = $config['dbo'];
     } else {
         $this->_db = F0FPlatform::getInstance()->getDbo();
     }
     // Set the default view search path
     if (array_key_exists('table_path', $config)) {
         $this->addTablePath($config['table_path']);
     } else {
         $componentPaths = F0FPlatform::getInstance()->getComponentBaseDirs($this->option);
         $path = $componentPaths['admin'] . '/tables';
         $altPath = $this->configProvider->get($this->option . '.views.' . F0FInflector::singularize($this->name) . '.config.table_path', null);
         if ($altPath) {
             $path = $componentPaths['main'] . '/' . $altPath;
         }
         $this->addTablePath($path);
     }
     // Assign the correct table
     if (array_key_exists('table', $config)) {
         $this->table = $config['table'];
     } else {
         $table = $this->configProvider->get($this->option . '.views.' . F0FInflector::singularize($this->name) . '.config.table', F0FInflector::singularize($view));
         $this->table = $table;
     }
     // Set the internal state marker - used to ignore setting state from the request
     if (!empty($config['ignore_request']) || !is_null($this->configProvider->get($this->option . '.views.' . F0FInflector::singularize($this->name) . '.config.ignore_request', null))) {
         $this->__state_set = true;
     }
     // Get and store the pagination request variables
     $defaultSaveState = array_key_exists('savestate', $config) ? $config['savestate'] : -999;
     $this->populateSavestate($defaultSaveState);
     if (F0FPlatform::getInstance()->isCli()) {
         $limit = 20;
         $limitstart = 0;
     } else {
         $app = JFactory::getApplication();
         if (method_exists($app, 'getCfg')) {
             $default_limit = $app->getCfg('list_limit');
         } else {
             $default_limit = 20;
         }
         $limit = $this->getUserStateFromRequest($component . '.' . $view . '.limit', 'limit', $default_limit, 'int', $this->_savestate);
         $limitstart = $this->getUserStateFromRequest($component . '.' . $view . '.limitstart', 'limitstart', 0, 'int', $this->_savestate);
     }
     $this->setState('limit', $limit);
     $this->setState('limitstart', $limitstart);
     // Get the ID or list of IDs from the request or the configuration
     if (array_key_exists('cid', $config)) {
         $cid = $config['cid'];
     } elseif ($cid = $this->configProvider->get($this->option . '.views.' . F0FInflector::singularize($this->name) . '.config.cid', null)) {
         $cid = explode(',', $cid);
     } else {
         $cid = $this->input->get('cid', array(), 'array');
     }
     if (array_key_exists('id', $config)) {
         $id = $config['id'];
     } elseif ($id = $this->configProvider->get($this->option . '.views.' . F0FInflector::singularize($this->name) . '.config.id', null)) {
         $id = explode(',', $id);
         $id = array_shift($id);
     } else {
         $id = $this->input->getInt('id', 0);
     }
     if (is_array($cid) && !empty($cid)) {
         $this->setIds($cid);
     } else {
         $this->setId($id);
     }
     // Populate the event names from the $config array
     $configKey = $this->option . '.views.' . F0FInflector::singularize($view) . '.config.';
     // Assign after delete event handler
     if (isset($config['event_after_delete'])) {
         $this->event_after_delete = $config['event_after_delete'];
     } else {
         $this->event_after_delete = $this->configProvider->get($configKey . 'event_after_delete', $this->event_after_delete);
     }
     // Assign after save event handler
     if (isset($config['event_after_save'])) {
         $this->event_after_save = $config['event_after_save'];
     } else {
         $this->event_after_save = $this->configProvider->get($configKey . 'event_after_save', $this->event_after_save);
     }
     // Assign before delete event handler
     if (isset($config['event_before_delete'])) {
         $this->event_before_delete = $config['event_before_delete'];
     } else {
         $this->event_before_delete = $this->configProvider->get($configKey . 'event_before_delete', $this->event_before_delete);
     }
     // Assign before save event handler
     if (isset($config['event_before_save'])) {
         $this->event_before_save = $config['event_before_save'];
     } else {
         $this->event_before_save = $this->configProvider->get($configKey . 'event_before_save', $this->event_before_save);
     }
     // Assign state change event handler
     if (isset($config['event_change_state'])) {
         $this->event_change_state = $config['event_change_state'];
     } else {
         $this->event_change_state = $this->configProvider->get($configKey . 'event_change_state', $this->event_change_state);
     }
     // Assign cache clean event handler
     if (isset($config['event_clean_cache'])) {
         $this->event_clean_cache = $config['event_clean_cache'];
     } else {
         $this->event_clean_cache = $this->configProvider->get($configKey . 'event_clean_cache', $this->event_clean_cache);
     }
     // Apply model behaviors
     if (isset($config['behaviors'])) {
         $behaviors = (array) $config['behaviors'];
     } elseif ($behaviors = $this->configProvider->get($configKey . 'behaviors', null)) {
         $behaviors = explode(',', $behaviors);
     } else {
         $behaviors = $this->default_behaviors;
     }
     if (is_array($behaviors) && count($behaviors)) {
         foreach ($behaviors as $behavior) {
             $this->addBehavior($behavior);
         }
     }
 }
コード例 #4
0
 /**
  * Gets a temporary instance of a Dispatcher
  *
  * @param   string  $option  The component name
  * @param   string  $view    The View name
  * @param   array   $config  Configuration data
  *
  * @return F0FDispatcher
  */
 public static function &getTmpInstance($option = null, $view = null, $config = array())
 {
     if (array_key_exists('input', $config)) {
         if ($config['input'] instanceof F0FInput) {
             $input = $config['input'];
         } else {
             if (!is_array($config['input'])) {
                 $config['input'] = (array) $config['input'];
             }
             $config['input'] = array_merge($_REQUEST, $config['input']);
             $input = new F0FInput($config['input']);
         }
     } else {
         $input = new F0FInput();
     }
     $config['option'] = !is_null($option) ? $option : $input->getCmd('option', 'com_foobar');
     $config['view'] = !is_null($view) ? $view : $input->getCmd('view', '');
     $input->set('option', $config['option']);
     $input->set('view', $config['view']);
     $config['input'] = $input;
     $className = ucfirst(str_replace('com_', '', $config['option'])) . 'Dispatcher';
     if (!class_exists($className)) {
         $componentPaths = F0FPlatform::getInstance()->getComponentBaseDirs($config['option']);
         $searchPaths = array($componentPaths['main'], $componentPaths['main'] . '/dispatchers', $componentPaths['admin'], $componentPaths['admin'] . '/dispatchers');
         if (array_key_exists('searchpath', $config)) {
             array_unshift($searchPaths, $config['searchpath']);
         }
         $filesystem = F0FPlatform::getInstance()->getIntegrationObject('filesystem');
         $path = $filesystem->pathFind($searchPaths, 'dispatcher.php');
         if ($path) {
             require_once $path;
         }
     }
     if (!class_exists($className)) {
         $className = 'F0FDispatcher';
     }
     $instance = new $className($config);
     return $instance;
 }
コード例 #5
0
ファイル: table.php プロジェクト: lyrasoft/lyrasoft.github.io
 /**
  * Class Constructor.
  *
  * @param   string           $table   Name of the database table to model.
  * @param   string           $key     Name of the primary key field in the table.
  * @param   F0FDatabaseDriver  &$db     Database driver
  * @param   array            $config  The configuration parameters array
  */
 public function __construct($table, $key, &$db, $config = array())
 {
     $this->_tbl = $table;
     $this->_tbl_key = $key;
     $this->_db = $db;
     // Make sure the use F0F cache information is in the config
     if (!array_key_exists('use_table_cache', $config)) {
         $config['use_table_cache'] = F0FPlatform::getInstance()->isGlobalF0FCacheEnabled();
     }
     $this->config = $config;
     // Load the configuration provider
     $this->configProvider = new F0FConfigProvider();
     // Load the behavior dispatcher
     $this->tableDispatcher = new F0FTableDispatcherBehavior();
     // Initialise the table properties.
     if ($fields = $this->getTableFields()) {
         // Do I have anything joined?
         $j_fields = $this->getQueryJoinFields();
         if ($j_fields) {
             $fields = array_merge($fields, $j_fields);
         }
         $this->setKnownFields(array_keys($fields), true);
         $this->reset();
     } else {
         $this->_tableExists = false;
     }
     // 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();
     }
     // Set the $name/$_name variable
     $component = $this->input->getCmd('option', 'com_foobar');
     if (array_key_exists('option', $config)) {
         $component = $config['option'];
     }
     $this->input->set('option', $component);
     // Apply table behaviors
     $type = explode("_", $this->_tbl);
     $type = $type[count($type) - 1];
     $this->_configProviderKey = $component . '.tables.' . F0FInflector::singularize($type);
     $configKey = $this->_configProviderKey . '.behaviors';
     if (isset($config['behaviors'])) {
         $behaviors = (array) $config['behaviors'];
     } elseif ($behaviors = $this->configProvider->get($configKey, null)) {
         $behaviors = explode(',', $behaviors);
     } else {
         $behaviors = $this->default_behaviors;
     }
     if (is_array($behaviors) && count($behaviors)) {
         foreach ($behaviors as $behavior) {
             $this->addBehavior($behavior);
         }
     }
     // If we are tracking assets, make sure an access field exists and initially set the default.
     $asset_id_field = $this->getColumnAlias('asset_id');
     $access_field = $this->getColumnAlias('access');
     if (in_array($asset_id_field, $this->getKnownFields())) {
         JLoader::import('joomla.access.rules');
         $this->_trackAssets = true;
     }
     // If the access property exists, set the default.
     if (in_array($access_field, $this->getKnownFields())) {
         $this->{$access_field} = (int) F0FPlatform::getInstance()->getConfig()->get('access');
     }
     $this->config = $config;
 }