function execute(&$data, &$parent) { // print_r($this->data); list($iniFile, $section) = preg_split("!\\s!", trim($this->data, 2)); if (!$iniFile) { return "Error: no INI filename specified"; } $iniFile = $iniFile . '.ini'; $path = One_Script_Factory::resolveFilePath($iniFile); if ($path === false) { return "One_Script_Factory: could not locate {$iniFile}"; } $entries = parse_ini_file($path, $section); // if section evals to false, no sections will be returned, but a flat array is returned if ($section) { if (!isset($entries[$section])) { return "Error: no section '{$section}' in {$iniFile}"; } $entries = $entries[$section]; } if ($entries) { foreach ($entries as $k => $v) { $parent->addSection($k, $v); } } }
/** * 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(); }
/** * 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('code'); $ns = new One_Script(); 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); $s = $ns->executeString($src); $dom->add($s); $dom->add($this->value); One_Script_Factory::restoreSearchPath(); }
/** * Parse the template or if $section is set and the section exists, parse the specified section * @param string $section */ public function parse($section = NULL) { $oldSearchpath = One_Script_Factory::getSearchPath(); One_Script_Factory::clearSearchpath(); One_Script_Factory::setSearchPath($this->getSearchPath()); if ($this->useFile()) { $this->nScript->load($this->getFile()); $this->nScript->select($section); if (!$this->nScript->isError()) { $output = $this->nScript->execute($this->getData()); } } else { $this->nScript->select($section); $output = $this->nScript->executeString($this->getContent(), $this->getData()); } One_Script_Factory::clearSearchpath(); One_Script_Factory::setSearchPath($oldSearchpath); One_Script_Content_Factory::$nsContentCache = array(); if ($this->nScript->isError()) { throw new One_Exception($this->nScript->error); } return trim($output); }
/** * Parse the template or if $section is set and the section exists, parse the specified section * * @param string $section */ public function render($section = null) { $oldSearchpath = One_Script_Factory::getSearchPath(); One_Script_Factory::setSearchPath($this->getSearchPath()); if ($this->useFile()) { $this->script->load($this->getFile()); if ($section !== null) { $this->script->select($section); } if (!$this->script->isError()) { $output = $this->script->execute($this->getData()); } } else { $this->script->select($section); $output = $this->script->executeString($this->getContent(), $this->getData()); } One_Script_Factory::setSearchPath($oldSearchpath); One_Script_Content_Factory::clearContentCache(); // *** why is this here ? WTF ! if ($this->script->isError()) { throw new One_Exception_Script($this->script->error); } return trim($output); }
/** * 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; }
static function restoreSearchPath() { self::$nsLoadPath = self::$nsSavedLoadPath; }
public function load($filename, $path = "") { $result = One_Script_Factory::load($filename, $path); if ($result === false) { $this->error = One_Script_Factory::$error; return false; } $this->parse($result, $filename, $path); }
public function getFlattened($path, $section) { list($dummy, $s, $dummy) = One_Script_Factory::loadFileContents($path, 'ini'); $pattern1 = "/\\{section " . $section . "\\}/"; $pattern2 = "/\\{endsection\\}/"; list($dummy, $rest) = preg_split($pattern1, $s, 2); list($sectionContent, $rest) = preg_split($pattern2, $rest, 2); return $sectionContent; }