/** * Create an instance of a class based on a class identifier * * @param mixed Identifier or Identifier object - lib.koowa.[.path].name * @param object An optional KConfig object with configuration options * @return object|false Return object on success, returns FALSE on failure */ public function instantiate($identifier, KConfig $config) { $classname = false; if ($identifier->type == 'lib' && $identifier->package == 'koowa') { $classname = 'K' . KInflector::implode($identifier->path) . ucfirst($identifier->name); $filepath = KLoader::path($identifier); if (!class_exists($classname)) { // use default class instead $classname = 'K' . KInflector::implode($identifier->path) . 'Default'; if (!class_exists($classname)) { throw new KFactoryAdapterException("Class [{$classname}] not found in file [" . basename($filepath) . "]"); } } } return $classname; }
public function loadIdentifier($template, $data = array(), $process = true) { //Identify the template $identifier = KFactory::identify($template); // Find the template $file = KLoader::path($identifier); if ($file === false) { throw new KTemplateException('Template "'.$identifier->name.'" not found'); } // Load the file $this->loadFile($file, $data, $process); return $this; }
/** * Renders a form using an xml path * * @param array $config * @return void */ public function getParameters($config = array()) { $config = new KConfig($config); $config->append(array('data' => array(), 'element_paths' => array(dirname(__FILE__) . '/forms'))); $content = file_exists($config->path) ? file_get_contents($config->path) : ''; $paths = array(); //replace all the addpath="{KServiceIdentifier}" with real path if (preg_match_all('/addpath="([^"]+)"/', $content, $paths)) { $replaces = array(); foreach ($paths[1] as $path) { if (strpos($path, '.')) { $replaces[] = str_replace(JPATH_ROOT . '/', '', dirname(KLoader::path($path . '.dummy'))); } else { $replaces[] = $path; } } $content = str_replace($paths[1], $replaces, $content); } $xml =& JFactory::getXMLParser('Simple'); $parameter = new JParameter(''); $data = KConfig::unbox($config->data); if ($data instanceof JParameter) { $data = $data->toArray(); } if (is_array($data)) { $parameter->loadArray($data); } else { $parameter->loadINI($data); } $parameter->template_data = $config->template_data; foreach ($config->element_paths as $path) { $parameter->addElementPath($path); } if ($xml->loadString($content)) { if ($params =& $xml->document->params) { foreach ($params as $param) { $parameter->setXML($param); } } } return $parameter; }
public function setStorage($path) { if (!is_file($path)) { if (strpos($path, DS) === false ) { $identifier = $this->_identifier->name.'://'.$this->_identifier->application.'/'.$this->_identifier->package.'.'.$path.'.'.$this->_storage_name; $path = KLoader::path($identifier); } else $path = $path.DS.$this->_storage_name.'.'.$this->_identifier->name; } if (is_file($path)) { $this->_storage_path = $path; return $this->_storage_path; } else throw new ComLearnDatabaseTableException('Path: '.$path.' is not a valid storage path'); }
/** * Get an instance of a class based on a class identifier * * @param string The identifier string * @param array An optional associative array of configuration settings. * @throws KFactoryException * @return object Return object on success, throws exception on failure */ protected static function _instantiate($identifier, array $config = array()) { $context = self::$_chain->getContext(); $config = new KConfig($config); $context->config = $config; $result = self::$_chain->run($identifier, $context); //If we get a string returned we assume it's a classname if (is_string($result)) { //Set the classname $identifier->classname = $result; //Set the filepath $identifier->filepath = KLoader::path($identifier); //If the object is indentifiable push the identifier in through the constructor if (array_key_exists('KObjectIdentifiable', class_implements($identifier->classname))) { $config->identifier = $identifier; } // If the class has an instantiate method call it if (is_callable(array($identifier->classname, 'instantiate'), false)) { $result = call_user_func(array($identifier->classname, 'instantiate'), $config); } else { $result = new $identifier->classname($config); } } if (!is_object($result)) { throw new KFactoryException('Cannot create object from identifier : ' . $identifier); } return $result; }
* @category Ninjaboard * @copyright Copyright (C) 2007 - 2011 NinjaForge. All rights reserved. * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> * @link http://ninjaforge.com */ /** * If koowa is unavailable * Abort the dispatcher */ if (!defined('KOOWA')) { return; } /** * If Ninjaboard is unavailable * Abort the dispatcher */ if (!KLoader::path('site::com.ninjaboard.dispatcher')) { return; } //Initialize the dispatcher just so models are mapped, and everything else Ninjaboard needs to run KLoader::load('site::com.ninjaboard.dispatcher'); ComNinjaboardDispatcher::register(); /** * Renders latest posts with the same look and feel like the regular component list * * @category Ninjaboard * @copyright Copyright (C) 2007 - 2011 NinjaForge. All rights reserved. * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> * @link http://ninjaforge.com */ echo KFactory::tmp('site::mod.ninjaboard_posts.html', array('params' => $params, 'module' => $module, 'attribs' => $attribs))->display();
* @copyright Copyright (C) 2007 - 2011 NinjaForge. All rights reserved. * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> * @link http://ninjaforge.com */ /** * If koowa is unavailable * Abort the dispatcher */ if (!defined('KOOWA')) { return; } /** * If Ninjaboard is unavailable * Abort the dispatcher */ if (!KLoader::path('site::com.ninjaboard.dispatcher') || !method_exists('ComNinjaboardDispatcher', 'register')) { echo JText::_('Ninjaboard 1.1 or later required.'); return; } //User needs to be logged in if (KFactory::get('lib.joomla.user')->guest) { return; } //Initialize the dispatcher just so models are mapped, and everything else Ninjaboard needs to run ComNinjaboardDispatcher::register(); /** * Renders latest posts with the same look and feel like the regular component list * * @category Ninjaboard * @copyright Copyright (C) 2007 - 2011 NinjaForge. All rights reserved. * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
/** * Load a template by identifier -- first look in the templates folder for an override * * This functions accepts both template local template file names or identifiers * - application::com.component.view.[.path].name * * @param string The template identifier * @param array An associative array of data to be extracted in local template scope * @return KTemplateAbstract */ public function loadIdentifier($identifier, $data = array()) { try { $identifier = new KIdentifier($identifier); $file = $identifier->name; $path = dirname(KLoader::path($identifier)) . '/tmpl'; } catch (KIdentifierException $e) { $file = $identifier; $path = dirname($this->getView()->getIdentifier()->filepath) . '/tmpl'; } // load the path $this->loadPath($path . '/' . $file . '.php', $data); return $this; }