private static function loadNamespace($namespace) { // if (self::loadNamespaceFromDB( $namespace )) return; // try the autoload approach // echo '<hr>'; print_r(One_Script_Factory::getSearchPath());die; $ns = new One_Script(); $ns->load('ini:' . $namespace . '.n.html'); if (!$ns->isError()) { self::$nsContentCache[$namespace] = array(); // process nodes and place them in the cache $root = $ns->rootNode; foreach ($root->chain as $node) { if ($node instanceof One_Script_Node_Section) { self::$nsContentCache[$namespace][$node->sectionName] = $node; } } } else { echo $ns->error; } if (One_Script_Config::$ncEnabled) { // echo 'loading'; $store = self::getStore(); if ($store) { $store->loadNamespace($namespace); } } }
/** * 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(); }
/** * Loads a form definition * * @param One_Scheme $scheme * @param $formFile * @return One_Form_Container_Form */ public static function load($filepath, $scheme, $language = NULL, $formName = 'oneForm', $action = '', $method = 'post') { $templater = One_Repository::getTemplater(NULL, false); // ----------------- // TODO: this section of code is absolute horror // $filepath = One::getInstance()->locate('meta'.DIRECTORY_SEPARATOR.'scheme'.DIRECTORY_SEPARATOR.$fileName.'.xml'); // $oldSearchpaths = $templater->getSearchpath(); // $templater->clearSearchpath(); // $pattern = "%ROOT%/views/" // . "{" . ($scheme->getName() != '' ? "%APP%/{$scheme->getName()}," : "") . "%APP%,default}" . DIRECTORY_SEPARATOR // . "{%LANG%" . DIRECTORY_SEPARATOR . ",}"; // // $templater->addSearchPath($pattern); // $templater->setFile('form.xml'); // if ($templater->hasError()) { // return self::createDefaultForm($scheme, $formFile, $language, $formName, $action, $method); //// throw new One_Exception($templater->getError()); // } // $templater->setSearchpath($oldSearchpaths); $script = new One_Script(); $script->load($filepath); $parsedContent = $script->execute(); if ($templater->hasError()) { throw new One_Exception($templater->getError()); } // ----------------- self::$_dom = new DOMDocument('1.0', 'utf-8'); $validFile = self::$_dom->loadXML($parsedContent); if ($validFile !== false) { // load rules if any self::loadConditions(); // load redirects if any $redirects = self::loadRedirects(); // first element in the xml file should be a container of the type 'form' if (strtolower(self::$_dom->firstChild->localName) == 'form') { $formEle = self::$_dom->firstChild; $formName = trim($formEle->getAttribute('id')) != '' ? trim($formEle->getAttribute('id')) : $formName; $action = trim($formEle->getAttribute('action')) != '' ? trim($formEle->getAttribute('action')) : $action; $attributes = array(); $rawAttributes = $formEle->attributes; for ($i = 0; $i < $rawAttributes->length; $i++) { $attribute = $rawAttributes->item($i); $attributes[$attribute->localName] = $attribute->value; } if (isset($attributes['type']) && trim(strtolower($attributes['type'])) == 'search') { self::$_defaultWidget = 'search'; } else { self::$_defaultWidget = 'scalar'; } if (count($redirects) > 0) { $attributes['redirects'] = $redirects; } $form = new One_Form_Container_Form($formName, $action, $method, $attributes); foreach ($formEle->childNodes as $child) { if ($child instanceof DOMElement) { self::_parseToForm($child, $form); } } } else { throw new One_Exception('Form definition "' . $fileName . '" found, but no form defined'); } } else { return self::createDefaultForm($scheme, $formFile, $language, $formName, $action, $method); } // $templater->clearSearchpath(); // $templater->setSearchpath($oldSearchpaths); // print_r($form); return $form; }
/** * 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; }
function &parseTokens($originalTokens, $endToken = false, $midToken = false, $includePath = "") { $c = array(); $endFound = false; $midFound = false; $tokens = $originalTokens; while (count($tokens) and !$endFound) { //print "[" . count($tokens) . ":" . htmlspecialchars($tokens[0][0]) . "]"; list($token, $location, $lineNumber) = array_shift($tokens); if (!empty($token)) { if ($midToken and !strcmp($token, $midToken)) { $midFound = true; //print "<br><b>FOUND MIDTOKEN=$midToken</b>"; $this->chain = $c; // store and start on altChain $c = array(); } else { if ($endToken and !strcmp($token, $endToken)) { $endFound = true; //print "<br><b>FOUND ENDTOKEN=$endToken</b>"; //print count($tokens); } else { //print "<br> <span style=\"color: #3333ff;\">(" . htmlspecialchars($token) . ")</span>"; if ($token[0] == One_Script_Config::NSNODE_OPEN) { //-------------------------------------------------------------------------- // this is a nanoScript tag //-------------------------------------------------------------------------- preg_match("!" . One_Script_Config::NSNODE_OPEN . "\\s*(.*?)\\s*" . One_Script_Config::NSNODE_CLOSE . "!s", $token, $match); // decode the tag $content = empty($match) ? "" : $match[1]; $parts = preg_split("!\\s!", $content, 2); // the tag and the rest if (count($parts) > 1) { list($tag, $tagOptions) = $parts; } else { $tag = $parts[0]; $tagOptions = ""; } //print "<b>TAG=$tag</b>"; $pairedToken = $this->hasEndToken($tag); if ($pairedToken) { //-------------------------------------------------------------------------- // this is a block tag //-------------------------------------------------------�------------------- $n = $this->newNode($tag, $tagOptions, ""); $tokens = $n->parseTokens($tokens, One_Script_Config::NSNODE_OPEN . $pairedToken . One_Script_Config::NSNODE_CLOSE, 0, $includePath); if (!$tokens) { $this->error = $n->error; return 0; } // print "adding BLOCK " . $this->args; $c[] = $n; } else { switch ($tag) { case 'set': list($lvalue, $expr) = explode("=", $tagOptions, 2); $n = $this->newNode("set", trim($expr), trim($lvalue)); $c[] = $n; break; case 'if': $n = $this->newNode("if", $tagOptions, ""); $tokens = $n->parseTokens($tokens, One_Script_Config::NSNODE_OPEN . "endif" . One_Script_Config::NSNODE_CLOSE, One_Script_Config::NSNODE_OPEN . "else" . One_Script_Config::NSNODE_CLOSE, $includePath); if (!$tokens) { $this->error = $n->error; return 0; } $c[] = $n; break; case 'include': // parse the file $sp = new One_Script(); $sp->load($tagOptions, $includePath); // create an include node $n = $this->newNode("include", $tagOptions, ""); $n->chain = $sp->rootNode->chain; $c[] = $n; break; case '=': $n = $this->newNode("evaluate", $tagOptions, ""); $c[] = $n; break; default: //-------------------------------------------------------------------------- // this is an old-style = tag (kept for compatibility) //-------------------------------------------------------------------------- if ($tag[0] == '=') { $comp = preg_split("!\\s!", substr($content, 1), 2); $identifier = $comp[0]; $modifier = ""; if (count($comp) > 1) { $modifier = $comp[1]; } $n = $this->newNode("value", $identifier, $modifier); $c[] = $n; } else { //-------------------------------------------------------------------------- // this is another tag : check for tags to be ignored //-------------------------------------------------------------------------- //PD13MAY10 : run sequence of tag naming handlers // echo '<br>oops, an unhandled tag called ', $tag; $tagHandled = false; foreach (One_Script_Config::$tagHandlers as $handler) { // echo '<br/>running ', $handler->name(); if (!$tagHandled) { $nn = $handler->handle($this, $tag, $tagOptions); if ($nn !== false) { $c[] = $nn; $tagHandled = true; } } // else echo ' (skipping)'; } if (!$tagHandled) { // if (in_array( $tag, One_Script_Config::$ignoreTags)) // { // $n =& $this->newNode( "text", $token, "" ); // //print "adding ignored tag '$tag'"; // $c[] =& $n; // } // else // { // $n =& $this->newNode( $tag, $tagOptions, "" ); //// print "adding $tag"; // $c[] =& $n; // } } } } } } else { //-------------------------------------------------------------------------- // this is a regular text block //-------------------------------------------------------------------------- $n = $this->newNode("generic", $token, ""); $c[] = $n; } } } } } if ($midFound) { $this->altChain = $c; } else { $this->chain = $c; } // store collected tokens in primary chain if ($endToken and !$endFound) { if ($midToken) { $this->error = "One_Script_Error: could not find '{$midToken}' or '{$endToken}'"; } else { $this->error = "One_Script_Error: could not find '{$endToken}'"; } // $this->dump(); return 0; } return $tokens; // send back whatever is left }