public static function searchFile($filename, $path, $mode = 'nano') { // try the file as specified $path = $path . $filename; // print "<br>(trying specified $path)"; if ($hash = One_Script_Cache::get($path)) { return array(true, $hash, $path); } if (file_exists($path)) { return self::loadFileContents($path, $mode); } // not found, walk the search sequence -- DEPRECATED /* $sequence = self::$nsLoadPath; if ($sequence) foreach ($sequence as $pathTemplate) { $place = One_Locator::locateUsing($path,$pathTemplate); if ($hash = One_Script_Cache::inCache( $place )) return array( true, $hash, $place ); return self::loadFileContents( $place, $mode ); } */ $place = One_Locator::locateUsing($path, self::currentSearchPattern()); if ($place !== null) { if ($hash = One_Script_Cache::inCache($place)) { return array(true, $hash, $place); } return self::loadFileContents($place, $mode); } self::$error = "One_Script_Factory error : could not locate '{$filename}' in '{$path}'"; return false; }
public function getFlowFile($fileName) { // search for appropriate flow definition xml file $pattern = "%ROOT%/meta/flows/"; $filepath = One_Locator::locateUsing($fileName . '.xml', $pattern); return $filepath; // // // $paths = array(); // $paths[] = One::getInstance()->getCustomPath().'/meta/flows/'.One::getInstance()->getApplication().'/'; // $paths[] = One::getInstance()->getCustomPath().'/meta/flows/'; // $paths[] = One::getInstance()->getPath().'/meta/flows/'; // // $validFile = false; // foreach($paths as $path) // { // $filePath = $path.$fileName.'.xml'; // if(file_exists($filePath)) { // $validFile = true; // break; // } // } // // return ((!$validFile) ? false : $filePath); }
/** * Loads a scheme along with its attributes, behaviors, relations, tasks, store and other information about the * scheme * * @param $schemeName * @return One_Scheme */ public static function load($schemeName) { $scheme = new One_Scheme($schemeName); $schemePath = One_Locator::locate('meta' . DIRECTORY_SEPARATOR . 'scheme' . DIRECTORY_SEPARATOR . $schemeName . '.xml'); if ($schemePath === null) { throw new One_Exception("The scheme {$schemeName} could not be located."); } $dom = new DOMDocument('1.0', 'utf-8'); if (!$dom->load($schemePath)) { throw new One_Exception("The scheme {$schemeName} could not be loaded."); } $xpath = new DOMXPath($dom); $nodelist = $xpath->query('/scheme'); if ($nodelist->length > 0) { $meta = $nodelist->item(0); } else { throw new One_Exception("The definition for scheme {$schemeName} is invalid."); } self::setAttributes($scheme, $xpath, $meta); self::setRelationships($scheme, $xpath, $meta); self::setBehaviors($scheme, $xpath, $meta); self::setRules($scheme, $xpath, $meta); self::setConnection($scheme, $xpath, $meta); self::setInformation($scheme, $xpath, $meta); self::setRoutings($scheme, $xpath, $meta); return $scheme; }
/** * Loads a relation by it's name * * @param string $relationName * @return One_Relation * @static */ public static function load($relationName) { $relation = new One_Relation($relationName); $roles = array(); if (preg_match('/^subscheme%([^%]+)%(.+)/', $relationName, $relMatch) > 0) { $rS = new One_Relation_Role($relMatch[1], $relMatch[1], array('cardinality' => 'one')); $rSu = new One_Relation_Role($relMatch[2], $relMatch[1] . '%' . $relMatch[2], array('cardinality', 'subscheme')); $roles[$relMatch[1]] = $rS; $roles[$relMatch[2]] = $rSu; } else { $relationpath = One_Locator::locate('meta' . DIRECTORY_SEPARATOR . 'relation' . DIRECTORY_SEPARATOR . $relationName . '.xml'); if ($relationpath === null) { throw new One_Exception('Could not load the relation "' . $relationName . '"'); } $dom = new DOMDocument('1.0', 'utf-8'); if ($dom->load($relationpath)) { $relAttributes = array(); $relationSpec = $dom->getElementsByTagName('relation'); if ($relationSpec->length > 0) { $relEle = $relationSpec->item(0); $attributes = $relEle->attributes; for ($i = 0; $i < $attributes->length; $i++) { $attr = $attributes->item($i); $relAttributes[$attr->name] = $attr->value; } } $relation->setMeta($relAttributes); $xpath = new DOMXPath($dom); // create the attribute set for this scheme $roleSpecs = $xpath->query('/relation/roles/role'); for ($i = 0; $i < $roleSpecs->length; $i++) { unset($r); $roleOptions = array(); $roleSpec = $roleSpecs->item($i); $attributes = $roleSpec->attributes; for ($j = 0; $j < $attributes->length; $j++) { $attr = $attributes->item($j); switch ($attr->name) { case 'name': $name = $attr->value; break; case 'scheme': $scheme = $attr->value; break; default: $roleOptions[$attr->name] = $attr->value; break; } } $r = new One_Relation_Role($name, $scheme, $roleOptions); $roles[$r->name] = $r; } } } $relation->setRoles($roles); return $relation; }
/** * Look for the specified file using the locator. If it exists, autoload it and return true, otherwise return false * * @param string $filename * @return boolean */ public static function tryLoading($filename) { $path = One_Locator::locate($filename); if ($path === null) { return false; } require_once $path; return true; }
/** * Loads a store instantiation * * @param string $connectionName * @return One_Store_Connection */ public static function load($connectionName) { // read the scheme's metafile $connectionpath = One_Locator::locate('meta' . DIRECTORY_SEPARATOR . 'connection' . DIRECTORY_SEPARATOR . $connectionName . '.xml'); if ($connectionpath === null) { throw new One_Exception('Could not find the one|content store-connection called <strong>' . $connectionName . '</strong>.'); } // read the scheme's metafile $dom = new DOMDocument('1.0', 'utf-8'); if ($dom->load($connectionpath)) { // Check if the connection tag was defined $connectionSpecs = $dom->getElementsByTagName('connection'); if ($connectionSpecs->length == 0) { throw new One_Exception('one|content store-connection called <strong>' . $connectionName . '</strong> was not properly defined'); } $connectionSpec = $connectionSpecs->item(0); $xpath = new DOMXPath($dom); // Get the connection type $type = self::getType($xpath); //Create the One_Store_Connection $className = 'One_Store_Connection_' . ucfirst(strtolower($type)); if (!class_exists($className)) { throw new One_Exception('A connection of type "' . $type . '" does not exist'); } $connection = new $className($connectionName); // get and set the store $store = self::getStore($xpath); $connection->setStore($store); // get and set the encoding for the connection $encoding = self::getEncoding($xpath); $connection->setEncoding($encoding); $meta = array(); if ($connectionSpec->hasChildNodes()) { $child = $connectionSpec->firstChild; do { if ($child->nodeType == XML_ELEMENT_NODE) { unset($childName); unset($attributes); $childName = $child->nodeName; $meta[$childName] = array(); $attributes = $child->attributes; if (count($attributes) > 0) { for ($i = 0; $i < $attributes->length; $i++) { $attribute = $attributes->item($i); $meta[$childName][$attribute->name] = $attribute->value; } } } $child = $child->nextSibling; } while (!is_null($child)); } $connection->setMeta($meta); return $connection; } else { throw new One_Exception('one|content store-connection called <strong>' . $connectionName . '</strong> was not properly defined'); } }
/** * Load extenders. This is neat stuff. Basically, each extension folder (under ONE_LIB_PATH or ONE_CUSTOM_PATH) * can contain an extension.php file. These files can define a local One_Extension subclass and inject it into the * One_Config::get('extensions') list. Extensions are loaded on initialize and other events. Well, they could be * and will be in the future. Now it's only for initialization. */ public static function loadExtensions() { // call plugin extenders. These define a class for a plugin that is added to the extenders list $extenders = One_Locator::locateAllUsing('extension.php', self::get('locator.root')); if (count($extenders)) { foreach ($extenders as $extenderPath) { require_once $extenderPath; } } }
public static function isPackage($pkName) { $path = One_Locator::locate('script' . DIRECTORY_SEPARATOR . 'package' . DIRECTORY_SEPARATOR . $pkName . '.php'); // echo '<br><b>', $pkName, '</b> is ', ($path === null ? 'NOT' : ' '), ' a package'; //*** temporary if ($path) { return true; } $path = One_Locator::locate('script' . DIRECTORY_SEPARATOR . 'package' . DIRECTORY_SEPARATOR . $pkName . '_tbd.php'); return $path !== null; }
/** * Get all available containers and widgets * * @return array */ public static function getAvailable() { if (is_null(self::$availableCW)) { $containers = array(); $places = One_Locator::locateAllUsing('*.php', '%ROOT%/form/container/'); $ignore = array('abstract', 'index', 'factory'); foreach ($places as $container) { $container = preg_replace('/_tbd.php$/', '.php', $container); //TODO: replace tmp fix if (preg_match('|([^/]*).php$|', $container, $match)) { if (in_array($match[1], $ignore) || strpos($match[1], '.') !== false) { unset($containers[$container]); } else { $containers[$container] = strtolower($match[1]); } } else { unset($containers[$container]); } } sort($containers); $widgets = array(); $places = One_Locator::locateAllUsing('*.php', '%ROOT%/form/widget/{joomla,multi,scalar,select,search}/'); foreach ($places as $widget) { $widget = preg_replace('/_tbd.php$/', '.php', $widget); //TODO: replace tmp fix if (preg_match('|([^/]*)/([^/]*).php$|', $widget, $match)) { if (!in_array($match[2], $ignore)) { $widgets[] = $match[1] . '-' . strtolower($match[2]); } } } $widgets[] = 'defaultactions'; $widgets[] = 'button'; $widgets[] = 'file'; $widgets[] = 'submit'; $widgets[] = 'label'; $widgets[] = 'button'; $widgets[] = 'nscript'; $widgets[] = 'inline'; //TODO: adding a widget here should not be necessary !! sort($widgets); self::$availableCW = array('containers' => $containers, 'widgets' => $widgets); } return self::$availableCW; }
public static function addBlockToken($token, $endToken) { self::$nodeBlockTokens[$token] = $endToken; } public static function addIgnoreTag($tag) { self::$ignoreTags[] = $tag; } public static function addHandler($handler) { array_unshift(self::$tagHandlers, $handler); } public static function setNanoContentBase($server, $database, $user, $pass) { self::$ncServer = $server; self::$ncDatabase = $database; self::$ncUser = $user; self::$ncPass = $pass; self::$ncEnabled = 1; } } One_Script_Config::addHandler(new One_Script_Tag_Handler_Catchall()); One_Script_Config::addHandler(new One_Script_Tag_Handler_Ignore()); One_Script_Config::$ncEnabled = 0; // load custom config if there is any $additionalConfigPaths = One_Locator::locate('script/config_add.php'); if (is_array($additionalConfigPaths)) { foreach ($additionalConfigPaths as $additionalConfig) { include_once $additionalConfig; } }
/** * Return an array with available filter names * * @meta * @return array */ public static function getFilterNames($schemeName = NULL) { $pattern = One_Config::get('locator.root') . 'filter/' . ($schemeName !== null ? '{scheme/,}' : ''); $places = One_Locator::locateAllUsing('*.xml', $pattern); $filters = array(); foreach ($places as $place) { preg_match("|([a-zA-Z0-9_\\-]*)\\.xml\$|", $place, $matches); $filters[] = $matches[1]; } sort($filters); return $filters; }
/** * 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; }