/** * Get an instance of One_Controller_Flow for the proper scheme * * @param One_Scheme $scheme * @param array $redirects * @return One_Controller_Flow */ public static function getInstance(One_Scheme $scheme, array $redirects = array()) { if (!array_key_exists(One_Config::get('app.name'), self::$_flowCache) || !array_key_exists($scheme->getName(), self::$_flowCache[One_Config::get('app.name')])) { self::$_flowCache[One_Config::get('app.name')][$scheme->getName()] = new One_Controller_Flow($scheme, $redirects); } return self::$_flowCache[One_Config::get('app.name')][$scheme->getName()]; }
public function dispatch() { // if ($this->_view == 'rest') { // return $this->dispatchRest(); // } try { $scheme = $this->_scheme; $this->controller = One_Repository::getController($scheme, $this->_options); $content = $this->controller->execute($this->_task, $this->_options); if (is_null($this->controller->getRedirect())) { if ($this->parseContentPlugins && $this->task != 'edit') { // @TODO lookup better way to trigger this today $dummy = new stdClass(); $dummy->text = $content; JPluginHelper::importPlugin('content'); $dispatcher = JDispatcher::getInstance(); $params = JFactory::getApplication()->getParams(); $dispatcher->trigger('onContentPrepare', array('com_one.default', &$dummy, &$params, 0)); $content = $dummy->text; } echo $content; } else { $this->setRedirect($this->controller->getRedirect()); $this->redirect(); } } catch (Exception $e) { if (One_Config::get('debug.exitOnError') === false) { echo $e->getMessage(); } else { throw new Exception($e); } } }
public function onAfterInitialise() { // read folder locations from plugin settings $oneLibFolder = JPATH_SITE . '/libraries/one/lib/'; $oneCustomFolder = JPATH_SITE . '/libraries/one/custom/'; // bootstrap one|content require_once $oneLibFolder . 'core/bootstrap.php'; One_Bootstrap::bootstrap($oneLibFolder, $oneCustomFolder); // one|content for Joomla uses different views for front/backend and per language // which requires a particular setup of the locator pattern used for these $application = 'site'; $app = JFactory::getApplication(); if (strpos($app->getName(), 'admin') !== false) { $application = 'admin'; } One_Config::set('app.name', $application); // pickup language setting $language = JFactory::getLanguage()->getTag(); One_Config::set('app.language', $language); // setup locator tokens $locatorTokens = array('%APP%' => One_Config::get('app.name'), '%LANG%' => One_Config::get('app.language')); One_Config::set('locator.tokens', $locatorTokens); One_Config::set('view.locator', 'One_View_Locator_Joomla'); // set the templater. You have the choice between One_View_Templater_Script and One_View_Templater_Php, // the latter being a standard PHP template hndler // *** TODO: needs to load this from plugin parameters One_Config::set('view.templater', 'One_View_Templater_Script'); // debug behaviour One_Config::set('debug.exitOnError', $this->params->get('exitOnError')); One_Config::set('debug.query', $this->params->get('enableDebug', 0)); // special form subfolder to use One_Config::set('form.chrome', $this->params->get('formChrome', '')); }
/** * Specialize the pattern by replacing certain tokens in the provided pattern. These tokens are set in the * One_Config object when one|content is bootstrapped. The tokens aer provided as an array, to make the use * of the token functionality flexible. * * REPLACE BY * ------- -------- * %ROOT% the root pattern * %APP% the application currently used * %LANG% the current language (is applicable) * * @param $pattern */ public static function localize($pattern) { $localized = str_replace('%ROOT%', One_Config::get('locator.root'), $pattern); $tokens = One_Config::get('locator.tokens'); if (count($tokens)) { foreach ($tokens as $token => $value) { $localized = str_replace($token, $value, $localized); } } return $localized; }
/** * Render the query * * @param One_Query $query * @return string */ public function render(One_Query $query, $overrideFilters = false) { $this->query = $query; $this->scheme = $this->query->getScheme(); // if the person wants to perform a raw query, return the raw query if (!is_null($query->getRaw())) { if (One_Config::get('debug.query')) { echo '<pre>'; var_dump($query->getRaw()); echo '</pre>'; } return $query->getRaw(); } $this->query = $query; $this->scheme = $this->query->getScheme(); $resources = $this->scheme->getResources(); // fetch collection to fetch data from $this->_collection = $resources['collection']; // add possible filters to the query if (!$overrideFilters && isset($resources['filter'])) { $filters = explode(';', $resources['filter']); if (count($filters) > 0) { foreach ($filters as $filterName) { if ($filterName != '') { $filter = One_Repository::getFilter($filterName, $query->getScheme()->getName()); $filter->affect($query); } } } } $findQuery = array('fields' => array(), 'query' => array()); if (count($query->getSelect()) > 0) { $findQuery['fields'] = $this->createSelects($query->getSelect()); } // get where clauses $whereClauses = $query->getWhereClauses(); $where = NULL; if (!is_null($whereClauses)) { $where = $this->whereClauses($whereClauses); } if (!is_null($where)) { $findQuery['query'] = $where; } if (One_Config::get('debug.query')) { echo '<pre>'; var_dump($findQuery); echo '</pre>'; } $findQuery = json_encode($findQuery); return $findQuery; }
public function execute() { try { $app = JFactory::getApplication(); $menu = $app->getMenu(); $menuItem = $menu->getActive(); $alias = $menuItem->route; $controller = new One_Controller_Rest(JFactory::getApplication()->input->getArray()); $controller->run($alias); } catch (Exception $e) { if (One_Config::get('debug.exitOnError') === false) { echo $e->getMessage(); } else { throw new Exception($e); } } }
/** * Render the output of the widget and add it to the DOM * * @param One_Model $model * @param One_Dom $d */ protected function _render($model, One_Dom $dom) { $src = $this->getCfg('src'); if (trim($src) == '') { throw new One_Exception("A field of type 'nscript' should have a 'src'-attribute defining the nanoScript file to parse."); } One_Script_Factory::saveSearchPath(); One_Script_Factory::clearSearchPath(); $useLang = $this->getCfg('language'); if ('' == trim($useLang)) { $useLang = strtolower(One_Config::get('app.language')); } die('deprecated stuff found in ' . __FILE__ . ':' . __LINE); $cps = One_Config::getInstance()->getCustomPaths(); foreach ($cps as $cp) { One_Script_Factory::addSearchPath($cp . '/views/' . One_Config::get('app.name') . '/' . $model->getScheme()->getName() . '/language/' . $useLang . '/'); } foreach ($cps as $cp) { One_Script_Factory::addSearchPath($cp . '/views/' . One_Config::get('app.name') . '/' . $model->getScheme()->getName() . '/'); } $ns = new One_Script(); $ns->load($src); if (!$ns->isError()) { if ($this->getID()) { $ns->set('id', $this->getID()); } if ($this->getName()) { $ns->set('name', $this->getName()); } if ($this->getLabel()) { $ns->set('label', $this->getLabel()); } if ($this->getValue($model)) { $ns->set('value', $this->getValue($model)); } $ns->set('model', $model); $dom->add($ns->execute()); } else { throw new One_Exception($ns->error); } $dom->add($this->value); One_Script_Factory::restoreSearchPath(); }
public function dispatch() { try { $scheme = $this->_scheme; $this->controller = One_Repository::getController($scheme, $this->_options); $content = $this->controller->execute($this->_task, $this->_options); if (is_null($this->controller->getRedirect())) { echo $content; } else { $this->setRedirect($this->controller->getRedirect()); $this->redirect(); } } catch (Exception $e) { if (One_Config::get('debug.exitOnError') === false) { echo $e->getMessage(); } else { throw new Exception($e); } } }
/** * Determine what type of widget the DOMElement is and load it's conditions * * @param One_Form_Container_Abstract $container * @param DOMElement $element * @param string $widgetClass * @return One_Form_Widget_Abstract */ protected static function determineWidget($container, $element, $widgetClass) { $id = $element->hasAttribute('id') ? $element->getAttribute('id') : $element->getAttribute('attribute'); $name = $element->hasAttribute('name') ? $element->getAttribute('name') : $element->getAttribute('attribute'); $label = $element->hasAttribute('label') ? $element->getAttribute('label') : $element->getAttribute('attribute'); $attributes = array(); $rawAttributes = $element->attributes; for ($i = 0; $i < $rawAttributes->length; $i++) { $attribute = $rawAttributes->item($i); $attributes[$attribute->localName] = $attribute->value; } if (false === isset($attributes['language'])) { $attributes['language'] = strtolower(One_Config::get('app.language')); } $widget = new $widgetClass($id, $name, $label, $attributes); if ($element->hasAttribute('optionsFrom') && method_exists($widget, 'setOptions')) { $parts = explode(':', $element->getAttribute('optionsFrom')); if (2 == count($parts)) { $session = One_Repository::getSession(); $sessionCacheName = md5($id . '#' . $name . '#' . $element->getAttribute('optionsFrom')); if (false === $element->hasAttribute('cacheOptions') || $element->hasAttribute('cacheOptions') && false === $session->varExists($sessionCacheName, 'One_Form_Cache')) { $optView = new One_View($parts[0], $parts[1]); try { $rawOptions = trim($optView->show()); $options = json_decode($rawOptions, 1); if (false === is_array($options)) { $options = array(); } $widget->setOptions($options); if ($element->hasAttribute('cacheOptions')) { $session->set($sessionCacheName, $options, 'One_Form_Cache'); } } catch (Exception $e) { // echo $e->getMessage(); // exit; } } else { $options = $session->get($sessionCacheName, 'One_Form_Cache'); $widget->setOptions($options); } } } self::loadConstraints($element, $widget); $container->addWidget($widget); return $widget; }
public function getCurrentLanguage() { return One_Config::get('app.language'); }
static function addObligatedWidgets(One_Form_Container_Form $form, One_Scheme $scheme) { // the form should always have a (hidden) widget with the value of the identityAttribute unless there is no identityAttribute if (!is_null($scheme->getIdentityAttribute()) && !$form->hasWidget($scheme->getIdentityAttribute()->getName())) { $form->addWidget(new One_Form_Widget_Scalar_Hidden($scheme->getIdentityAttribute()->getName(), $scheme->getIdentityAttribute()->getName(), NULL, array('one' => 'one', 'language' => strtolower(One_Config::get('app.language'))))); } if (!$form->hasWidget('task')) { $form->addWidget(new One_Form_Widget_Scalar_Hidden('task', 'task', NULL, array('default' => 'edit', 'one' => 'one', 'language' => strtolower(One_Config::get('app.language'))))); } if (!$form->hasWidget('scheme')) { $form->addWidget(new One_Form_Widget_Scalar_Hidden('scheme', 'scheme', NULL, array('default' => $scheme->getName(), 'one' => 'one', 'language' => strtolower(One_Config::get('app.language'))))); } }
/** * Parse the output of the widget with nanoscript * * @param One_Model $model * @param array $data */ protected function parse($model, $data = array()) { // general Dataset $data['excludeError'] = in_array($this->getCfg('excludeError'), array('true', 'yes', '1', 'exclude', 'excludeError')) ? 1 : 0; // determine if we need to look for the template-file in a subfolder of widget $widgetClass = preg_match('/One_Form_Widget_Default_/', get_class($this)) ? get_parent_class($this) : get_class($this); $current = str_replace('One_Form_Widget_', '', $widgetClass); $parts = preg_split('/_/', strtolower($current)); // array_pop($parts); $wtype = implode(DIRECTORY_SEPARATOR, $parts); $formChrome = One_Config::get('form.chrome', ''); $pattern = "%ROOT%/views/" . "{%APP%,default}/" . "oneform/" . ($formChrome ? "{" . $formChrome . '/,}' : '') . "widget/" . ($wtype ? "{" . $wtype . "/,}" : '') . "{%LANG%/,}"; One_Script_Factory::pushSearchPath($pattern); $script = new One_Script(); // $script->load($this->_type . '.html'); $script->load($wtype . '.html'); if ($script->error) { One_Script_Factory::popSearchPath(); throw new One_Exception('Error loading template for widget ' . $this->_type . ' : ' . $script->error); } $dom = One_Repository::createDom(); $dom->add($script->execute($data)); return $dom; }
/** * Set the One_Script search path according to scheme * * The order to look is * 1) SPACE/views/APP/SCHEME/LANG * 2) SPACE/views/APP/SCHEME/ * 3) SPACE/views/APP/LANG * 4) SPACE/views/APP/ * 3) SPACE/views/default/LANG * 4) SPACE/views/default/ * * @param string $schemeName */ public function setDefaultViewSearchPath() { $locator = One_Config::get('view.locator', 'One_View_Locator'); $viewPattern = $locator::getPatternForScheme($this->schemeName); $this->templater->setSearchPath($viewPattern); }
/** * Render the query * * @param One_Query $query * @return string */ public function render(One_Query $query, $overrideFilters = false) { $this->query = $query; $this->scheme = $this->query->getScheme(); // if the person wants to perform a raw query, return the raw query if (!is_null($query->getRaw())) { if (One_Config::get('debug.query')) { echo '<pre>'; var_dump($query->getRaw()); echo '</pre>'; } return $query->getRaw(); } $this->query = $query; $this->scheme = $this->query->getScheme(); $resources = $this->scheme->getResources(); // fetch main table to fetch data from $this->mainTable = $resources['table']; $this->defineRole('$self$'); // add possible filters to the query if (!$overrideFilters && isset($resources['filter'])) { $filters = explode(';', $resources['filter']); if (count($filters) > 0) { foreach ($filters as $filterName) { if ($filterName != '') { $filter = One_Repository::getFilter($filterName, $query->getScheme()->getName()); $filter->affect($query); } } } } // TR20100531 No longer needs to be run after the rest since joins are now checked while adding // sselects, order, ... $joins = NULL; $qJoins = $query->getJoins(); if (count($qJoins) > 0) { foreach ($qJoins as $join => $type) { $this->defineRole($join); $query->setRoleAlias($join, $this->aliases[$join]); $joins .= $this->createJoin($query->getRole($join), $type); } } $selects = $this->aliases['$self$'] . '.*'; if (count($query->getSelect()) > 0) { $selects = $this->createSelects($query->getSelect()); } // get where clauses $whereClauses = $query->getWhereClauses(); $where = NULL; if (!is_null($whereClauses)) { $where = $this->whereClauses($whereClauses); } // get having clauses $havingClauses = $query->getHavingClauses(); $having = NULL; if (!is_null($havingClauses)) { $having = $this->whereClauses($havingClauses); } // get order $order = $this->createOrder(); //get grouping $group = $this->createGroup(); // get limit $limit = $this->createLimit(); $sql = 'SELECT ' . $selects . ' FROM ' . $this->mainTable . ' ' . $this->aliases['$self$']; if (!is_null($joins)) { $sql .= $joins; } if (!is_null($where)) { $sql .= ' WHERE ' . $where; } if (!is_null($group)) { $sql .= ' GROUP BY ' . $group; } if (!is_null($having)) { $sql .= ' HAVING ' . $having; } if (!is_null($order)) { $sql .= ' ORDER BY ' . $order; } if (!is_null($limit)) { /* Use the following format to replace MySQL LIMIT for PL/SQL : SELECT * FROM ( SELECT rownum rnum, a.* FROM( SELECT fieldA,fieldB FROM table ORDER BY fieldA ) a WHERE rownum <= START + LIMIT ) WHERE rnum >= START ** or ** SELECT rownum rnum, a.* FROM( SELECT fieldA,fieldB FROM table ORDER BY fieldA ) a WHERE rownum <= LIMIT */ $qLimit = $this->query->getLimit(); if (isset($qLimit['start']) && intval($qLimit['start']) > -1) { $start = intval($qLimit['start']); } else { $start = 0; } if (isset($qLimit['limit']) && intval($qLimit['limit']) > 0) { $limit = intval($qLimit['limit']); } else { $limit = 50; } // @TODO: clean this up // create alias for rownum field $rnfield = $this->createAlias(); $subsel = $this->createAlias(); $sql = "SELECT rownum {$rnfield}, {$subsel}.* FROM ( {$sql} ) {$subsel} WHERE rownum <= {$limit}"; if ($start) { $sql = "SELECT * FROM ( {$sql} ) WHERE {$rnfield} > {$start}"; } } if (One_Config::get('debug.query')) { echo '<pre>'; var_dump($sql); echo '</pre>'; } return $sql; }
/** * Render the query * * @param One_Query $query * @return string */ public function render(One_Query $query, $overrideFilters = false) { $this->query = $query; $this->scheme = $this->query->getScheme(); // if the person wants to perform a raw query, return the raw query if (!is_null($query->getRaw())) { if (One_Config::get('debug.query')) { echo '<pre>'; var_dump($query->getRaw()); echo '</pre>'; } return $query->getRaw(); } $this->query = $query; $this->scheme = $this->query->getScheme(); $resources = $this->scheme->getResources(); // fetch main table to fetch data from $this->mainTable = $resources['table']; $this->defineRole('$self$'); // add possible filters to the query if (!$overrideFilters && isset($resources['filter'])) { $filters = explode(';', $resources['filter']); if (count($filters) > 0) { foreach ($filters as $filterName) { if ($filterName != '') { $filter = One_Repository::getFilter($filterName, $query->getScheme()->getName()); $filter->affect($query); } } } } // TR20100531 No longer needs to be run after the rest since joins are now checked while adding // sselects, order, ... $joins = NULL; $qJoins = $query->getJoins(); if (count($qJoins) > 0) { foreach ($qJoins as $join => $type) { $this->defineRole($join); $query->setRoleAlias($join, $this->aliases[$join]); $joins .= $this->createJoin($query->getRole($join), $type); } } // *** TODO: change the '*' to only the relavant fields defined in the scheme $selects = $this->aliases['$self$'] . '.*'; if (count($query->getSelect()) > 0) { $selects = $this->createSelects($query->getSelect()); } // get where clauses $whereClauses = $query->getWhereClauses(); $where = NULL; if (!is_null($whereClauses)) { $where = $this->whereClauses($whereClauses); } // get having clauses $havingClauses = $query->getHavingClauses(); $having = NULL; if (!is_null($havingClauses)) { $having = $this->whereClauses($havingClauses); } // get order $order = $this->createOrder(); //get grouping $group = $this->createGroup(); // get limit $limit = $this->createLimit(); $sql = 'SELECT ' . $selects . ' FROM `' . $this->mainTable . '` ' . $this->aliases['$self$']; if (!is_null($joins)) { $sql .= $joins; } if (!is_null($where)) { $sql .= ' WHERE ' . $where; } if (!is_null($group)) { $sql .= ' GROUP BY ' . $group; } if (!is_null($having)) { $sql .= ' HAVING ' . $having; } if (!is_null($order)) { $sql .= ' ORDER BY ' . $order; } if (!is_null($limit)) { $sql .= ' LIMIT ' . $limit; } if (One_Config::get('debug.query')) { echo '<pre>'; var_dump($sql); echo '</pre>'; } return $sql; }
/** * @return One_Templater */ public static function getTemplater($templaterClass = NULL) { if (is_null($templaterClass)) { $templaterClass = One_Config::get('view.templater', 'One_View_Templater_Script'); } return new $templaterClass(''); }
/** * Gets all the columns that should be shown in the list * * @return array Array of all columns in the form of object with extra data */ private function getColumns() { $session = One_Repository::getSession(); $exists = true; $filename = One_Locator::locateUsing('list.xml', ONE_LOCATOR_ROOTPATTERN . 'views/' . One_Config::get('app.name') . '/' . $this->scheme->getName() . '/'); if ($filename === null) { $exists = false; } if ($exists) { $xml = @simplexml_load_file($filename); } if ($exists && $xml) { // JL06JAN2009 - if no sorting was clicked, check if the default sort column was set // in the xml file $xmlarray_defs = xmlpm($xml, "/view/columns"); $sort = (string) $xmlarray_defs[0]->attributes()->sort; $limit = (string) $xmlarray_defs[0]->attributes()->limit; if ('' != trim($sort)) { preg_match('/^([^\\+\\-]+)(\\+|\\-)?$/i', $sort, $sortMatch); $this->_sortOrder = 'asc'; $this->_sort = $sortMatch[1]; if (isset($sortMatch[2]) && $sortMatch[2] == '-') { $this->_sortOrder = 'desc'; } } if (0 < abs(intval($limit))) { $this->_limit = abs(intval($limit)); } $xmlarray = $xmlarray_defs[0]->column; $this->_columns = array(); foreach ($xmlarray as $xmlpart) { $tmp = new stdClass(); $name = ''; $setFilter = false; $filterType = 'text'; $filterOptions = array(); $operator = 'contains'; foreach ($xmlpart->attributes() as $key => $val) { switch (strtolower($key)) { case 'name': $tmp->name = (string) $val; break; case 'label': $tmp->label = (string) $val; break; case 'filter': if ($val == 1) { $setFilter = true; } break; case 'filtertype': if (in_array(strtolower($val), array('dropdown', 'text', 'daterange'))) { $filterType = strtolower($val); } break; case 'filteroptions': $options = explode(';', $val); foreach ($options as $option) { $parts = explode('=', $option, 2); $filterOptions[$parts[0]] = $parts[1]; } case 'operator': if (in_array((string) $val, $this->_operators)) { $operator = (string) $val; } default: $tmp->{$key} = (string) $val; } } if ($filterType == 'dropdown' && count($filterOptions) == 0 && trim($tmp->name) != '') { preg_match('/([^:]+)((:)(.+))?/', $tmp->name, $matches); if (!is_null($matches[4])) { $link = $this->scheme->getLink($matches[1]); $target = One_Repository::getScheme($link->getTarget()); $tAtt = $matches[4]; $tFac = One_Repository::getFactory($target->getName()); $tQ = $tFac->selectQuery(); $tQ->setSelect(array($tAtt)); $tQ->setOrder(array($matches[4] . '+')); $options = $tQ->execute(false); foreach ($options as $option) { $filterOptions[$option->{$tAtt}] = $option->{$tAtt}; } } } //PD16SEP09: if no name is given, interpret the body of the tag as CDATA containing nanoScript // TR20100408: change this to only set the name as the label if no name is given. if (!isset($tmp->name)) { $tmp->name = $tmp->label; } //filter operator defaults to contains if (!isset($tmp->name)) { $tmp->operator = 'contains'; } // TR20100408: change this to interpret as nanoscript if a value is passed to the tag if (trim((string) $xmlpart) != '') { $tmp->nScript = (string) $xmlpart; } $this->_columns[$tmp->name] = $tmp; if ($setFilter) { if ($filterType != 'daterange') { $value = JRequest::getVar('s' . $tmp->name, NULL); } else { $value = array(JRequest::getVar('s' . $tmp->name . 'Start', NULL), JRequest::getVar('s' . $tmp->name . 'End', NULL)); } if (is_null($value)) { $value = $session->get($tmp->name, $this->scheme->getName() . '--list'); } $session->set($tmp->name, $value, $this->scheme->getName() . '--list'); $this->_filters[$tmp->name] = array('label' => $tmp->label, 'value' => $value, 'type' => $filterType, 'options' => $filterOptions, 'operator' => $operator); } } } if (is_null($this->_columns)) { $columns = $this->scheme->get('attributes'); $this->_columns = array(); foreach ($columns as $name => $column) { $tmp = new stdClass(); $tmp->label = $column->getName(); $tmp->name = $column->getName(); // TR20100317 used to be $column->column() but should not be used anymore $this->_columns[$tmp->name] = $tmp; } } return $this->_columns; }