/** * Launch the compilation of a template * * Store the result (a php content) into a cache file given by the selector. * @param jSelectorTpl $selector the template selector * @return boolean true if ok */ public function compile($selector) { $this->_sourceFile = $selector->getPath(); $cachefile = $selector->getCompiledFilePath(); $this->outputType = $selector->outputType; $this->trusted = $selector->trusted; $this->_modifier = array_merge($this->_modifier, $selector->userModifiers); $this->_userFunctions = $selector->userFunctions; jContext::push($selector->module); if (!file_exists($this->_sourceFile)) { $this->doError0('errors.tpl.not.found'); } $result = $this->compileContent(file_get_contents($this->_sourceFile)); $header = "<?php \n"; foreach ($this->_pluginPath as $path => $ok) { $header .= ' require_once(\'' . $path . "');\n"; } $header .= 'function template_meta_' . md5($selector->module . '_' . $selector->resource . '_' . $this->outputType . ($this->trusted ? '_t' : '')) . '($t){'; $header .= "\n" . $this->_metaBody . "\n}\n"; $header .= 'function template_' . md5($selector->module . '_' . $selector->resource . '_' . $this->outputType . ($this->trusted ? '_t' : '')) . '($t){' . "\n?>"; $result = $header . $result . "<?php \n}\n?>"; jFile::write($cachefile, $result); jContext::pop(); return true; }
public function compile($selector) { $this->_sourceFile = $selector->getPath(); $this->outputType = $selector->outputType; $this->trusted = $selector->trusted; $md5 = md5($selector->module . '_' . $selector->resource . '_' . $this->outputType . ($this->trusted ? '_t' : '')); jContext::push($selector->module); if (!file_exists($this->_sourceFile)) { $this->doError0('errors.tpl.not.found'); } $this->compileString(file_get_contents($this->_sourceFile), $selector->getCompiledFilePath(), $selector->userModifiers, $selector->userFunctions, $md5); jContext::pop(); return true; }
public function run() { $this->loadAppConfig(); #if ENABLE_OPTIMIZED_SOURCE require JELIX_LIB_PATH . 'dao/jDaoCompiler.class.php'; // jDaoParser is in jDaoCompiler file #endif $path = $this->getModulePath($this->_parameters['module']); $filename = $path . 'forms/'; $this->createDir($filename); $filename .= strtolower($this->_parameters['form']) . '.form.xml'; if ($this->getOption('-createlocales')) { $locale_content = ''; $locale_base = $this->_parameters['module'] . '~' . strtolower($this->_parameters['form']) . '.form.'; $locale_filename_fr = $path . 'locales/fr_FR/'; $this->createDir($locale_filename_fr); $locale_filename_fr .= strtolower($this->_parameters['form']) . '.UTF-8.properties'; $locale_filename_en = $path . 'locales/en_EN/'; $this->createDir($locale_filename_en); $locale_filename_en .= strtolower($this->_parameters['form']) . '.UTF-8.properties'; $submit = "\n\n<submit ref=\"_submit\">\n\t<label locale='" . $locale_base . "ok' />\n</submit>"; } else { $submit = "\n\n<submit ref=\"_submit\">\n\t<label>ok</label>\n</submit>"; } $dao = $this->getParam('dao'); if ($dao === null) { if ($this->getOption('-createlocales')) { $locale_content = "form.ok=OK\n"; $this->createFile($locale_filename_fr, 'locales.tpl', array('content' => $locale_content)); $this->createFile($locale_filename_en, 'locales.tpl', array('content' => $locale_content)); } $this->createFile($filename, 'module/form.xml.tpl', array('content' => '<!-- add control declaration here -->' . $submit)); return; } global $gJConfig; $gJConfig->startModule = $this->_parameters['module']; jContext::push($this->_parameters['module']); $tools = jDb::getConnection()->tools(); // we're going to parse the dao $selector = new jSelectorDao($dao, ''); $doc = new DOMDocument(); $daoPath = $selector->getPath(); if (!$doc->load($daoPath)) { throw new jException('jelix~daoxml.file.unknown', $daoPath); } if ($doc->documentElement->namespaceURI != JELIX_NAMESPACE_BASE . 'dao/1.0') { throw new jException('jelix~daoxml.namespace.wrong', array($daoPath, $doc->namespaceURI)); } $parser = new jDaoParser($selector); $parser->parse(simplexml_import_dom($doc), $tools); // now we generate the form file $properties = $parser->GetProperties(); $table = $parser->GetPrimaryTable(); $content = ''; foreach ($properties as $name => $property) { if (!$property->ofPrimaryTable) { continue; } if ($property->isPK && $property->autoIncrement) { continue; } $attr = ''; if ($property->required) { $attr .= ' required="true"'; } if ($property->defaultValue !== null) { $attr .= ' defaultvalue="' . htmlspecialchars($property->defaultValue) . '"'; } if ($property->maxlength !== null) { $attr .= ' maxlength="' . $property->maxlength . '"'; } if ($property->minlength !== null) { $attr .= ' minlength="' . $property->minlength . '"'; } $datatype = ''; $tag = 'input'; switch ($property->unifiedType) { case 'integer': case 'numeric': $datatype = 'integer'; break; case 'datetime': $datatype = 'datetime'; break; case 'time': $datatype = 'time'; break; case 'date': $datatype = 'date'; break; case 'double': case 'float': $datatype = 'decimal'; break; case 'text': case 'blob': $tag = 'textarea'; break; case 'boolean': $tag = 'checkbox'; break; } if ($datatype != '') { $attr .= ' type="' . $datatype . '"'; } if ($this->getOption('-createlocales')) { $locale_content .= 'form.' . $name . '=' . ucwords(str_replace('_', ' ', $name)) . "\n"; $content .= "\n\n<{$tag} ref=\"{$name}\"{$attr}>\n\t<label locale='" . $locale_base . $name . "' />\n</{$tag}>"; } else { $content .= "\n\n<{$tag} ref=\"{$name}\"{$attr}>\n\t<label>" . ucwords(str_replace('_', ' ', $name)) . "</label>\n</{$tag}>"; } } if ($this->getOption('-createlocales')) { $locale_content .= "form.ok=OK\n"; $this->createFile($locale_filename_fr, 'module/locales.tpl', array('content' => $locale_content)); $this->createFile($locale_filename_en, 'module/locales.tpl', array('content' => $locale_content)); } $this->createFile($filename, 'module/form.xml.tpl', array('content' => $content . $submit)); }
public function run() { jxs_init_jelix_env(); $path = $this->getModulePath($this->_parameters['module']); $filename = $path . 'forms/'; $this->createDir($filename); $filename .= strtolower($this->_parameters['form']) . '.form.xml'; $submit = "\n\n<submit ref=\"_submit\">\n\t<label>ok</label>\n</submit>"; if (($dao = $this->getParam('dao')) === null) { $this->createFile($filename, 'form.xml.tpl', array('content' => '<!-- add control declaration here -->' . $submit)); return; } global $gJConfig; $gJConfig->startModule = $this->_parameters['module']; jContext::push($this->_parameters['module']); // we're going to parse the dao $selector = new jSelectorDao($dao, '', false); jDaoCompiler::$daoId = $selector->toString(); jDaoCompiler::$daoPath = $selector->getPath(); jDaoCompiler::$dbType = $selector->driver; $doc = new DOMDocument(); if (!$doc->load(jDaoCompiler::$daoPath)) { throw new jException('jelix~daoxml.file.unknow', jDaoCompiler::$daoPath); } if ($doc->documentElement->namespaceURI != JELIX_NAMESPACE_BASE . 'dao/1.0') { throw new jException('jelix~daoxml.namespace.wrong', array(jDaoCompiler::$daoPath, $doc->namespaceURI)); } $parser = new jDaoParser(); $parser->parse(simplexml_import_dom($doc)); // know we generate the form file $properties = $parser->GetProperties(); $table = $parser->GetPrimaryTable(); $content = ''; foreach ($properties as $name => $property) { if (!$property->ofPrimaryTable) { continue; } if ($property->isPK && ($property->datatype == 'autoincrement' || $property->datatype == 'bigautoincrement')) { continue; } $attr = ''; if ($property->required) { $attr .= ' required="true"'; } if ($property->defaultValue !== null) { $attr .= ' defaultvalue="' . htmlspecialchars($property->defaultValue) . '"'; } if ($property->maxlength !== null) { $attr .= ' maxlength="' . $property->maxlength . '"'; } if ($property->minlength !== null) { $attr .= ' minlength="' . $property->minlength . '"'; } //if(false) // $attr.=' defaultvalue=""'; $datatype = ''; $tag = 'input'; switch ($property->datatype) { case 'autoincrement': case 'bigautoincrement': case 'int': case 'integer': case 'numeric': $datatype = 'integer'; break; case 'datetime': $datatype = 'datetime'; break; case 'time': $datatype = 'time'; break; case 'date': $datatype = 'date'; break; case 'double': case 'float': $datatype = 'decimal'; break; case 'text': $tag = 'textarea'; break; case 'boolean': $tag = 'checkbox'; break; } if ($datatype != '') { $attr .= ' type="' . $datatype . '"'; } $content .= "\n\n<{$tag} ref=\"{$name}\"{$attr}>\n\t<label>{$name}</label>\n</{$tag}>"; } $this->createFile($filename, 'form.xml.tpl', array('content' => $content . $submit)); }
/** * instancy a zone object, and call one of its methods * @param string $name zone selector * @param string $method method name * @param array $params arguments for the method * @return mixed the result returned by the method */ private static function _callZone($name, $method, &$params) { $sel = new jSelectorZone($name); jContext::push($sel->module); $fileName = $sel->getPath(); require_once $fileName; $className = $sel->resource . 'Zone'; $zone = new $className($params); $toReturn = $zone->{$method}(); jContext::pop(); return $toReturn; }
/** * main method : launch the execution of the action. * * This method should be called in a entry point. * @param jRequest $request the request object */ public function process($request) { global $gJConfig; $this->request = $request; // let's log messages appeared during init foreach ($this->initErrorMessages as $msg) { jLog::log($msg, $msg->getCategory()); } $this->request->init(); jSession::start(); $this->moduleName = $request->getParam('module'); $this->actionName = $request->getParam('action'); if (empty($this->moduleName)) { $this->moduleName = $gJConfig->startModule; } if (empty($this->actionName)) { if ($this->moduleName == $gJConfig->startModule) { $this->actionName = $gJConfig->startAction; } else { $this->actionName = 'default:index'; } } jContext::push($this->moduleName); try { $this->action = new jSelectorActFast($this->request->type, $this->moduleName, $this->actionName); if ($gJConfig->modules[$this->moduleName . '.access'] < 2) { throw new jException('jelix~errors.module.untrusted', $this->moduleName); } $ctrl = $this->getController($this->action); } catch (jException $e) { if ($gJConfig->urlengine['notfoundAct'] == '') { throw $e; } try { $this->action = new jSelectorAct($gJConfig->urlengine['notfoundAct']); $ctrl = $this->getController($this->action); } catch (jException $e2) { throw $e; } } if (count($this->plugins)) { $pluginparams = array(); if (isset($ctrl->pluginParams['*'])) { $pluginparams = $ctrl->pluginParams['*']; } if (isset($ctrl->pluginParams[$this->action->method])) { $pluginparams = array_merge($pluginparams, $ctrl->pluginParams[$this->action->method]); } foreach ($this->plugins as $name => $obj) { $result = $this->plugins[$name]->beforeAction($pluginparams); if ($result) { $this->action = $result; jContext::pop(); jContext::push($result->module); $this->moduleName = $result->module; $this->actionName = $result->resource; $ctrl = $this->getController($this->action); break; } } } $this->response = $ctrl->{$this->action->method}(); if ($this->response == null) { throw new jException('jelix~errors.response.missing', $this->action->toString()); } foreach ($this->plugins as $name => $obj) { $this->plugins[$name]->beforeOutput(); } $this->response->output(); foreach ($this->plugins as $name => $obj) { $this->plugins[$name]->afterProcess(); } jContext::pop(); jSession::end(); }
function single() { $rep = $this->_prepareResponse(); $module = $this->param('mod'); $testname = $this->param('test'); if (isset($this->testsList[$module])) { $reporter = jClasses::create("junittests~jtextrespreporter"); jClasses::inc('junittests~junittestcase'); jClasses::inc('junittests~junittestcasedb'); $reporter->setResponse($rep); foreach ($this->testsList[$module] as $test) { if ($test[1] == $testname) { $group = new GroupTest('"' . $module . '" module , ' . $test[2]); $group->addTestFile($GLOBALS['gJConfig']->_modulesPathList[$module] . 'tests/' . $test[0]); jContext::push($module); $result = $group->run($reporter); if (!$result) { $rep->setExitCode(jResponseCmdline::EXIT_CODE_ERROR); } jContext::pop(); break; } } } else { $rep->addContent("\n" . 'no tests for "' . $module . '" module.' . "\n"); } return $this->_finishResponse($rep); }
protected function setUp() { parent::setUp(); jContext::push($this->module); }
function single() { if (!isset($GLOBALS['gJConfig']->enableTests) || !$GLOBALS['gJConfig']->enableTests) { // security $rep = $this->getResponse('html', true); $rep->title = 'Error'; $rep->setHttpStatus('404', 'Not found'); $rep->addContent('<p>404 Not Found</p>'); return $rep; } $rep = $this->_prepareResponse(); $module = $this->param('mod'); $testname = $this->param('test'); if (isset($this->testsList[$module])) { $reporter = jClasses::create("junittests~jhtmlrespreporter"); jClasses::inc('junittests~junittestcase'); jClasses::inc('junittests~junittestcasedb'); $reporter->setResponse($rep); foreach ($this->testsList[$module] as $test) { if ($test[1] == $testname) { $group = new TestSuite('"' . $module . '" module , ' . $test[2]); $group->addFile($GLOBALS['gJConfig']->_modulesPathList[$module] . 'tests/' . $test[0]); jContext::push($module); $group->run($reporter); jContext::pop(); break; } } } else { $rep->body->assign('MAIN', '<p>no tests for "' . $module . '" module.</p>'); } return $this->_finishResponse($rep); }
function single() { $rep = $this->_prepareResponse(); $module = $this->param('mod'); $testname = $this->param('test'); $category = $this->category ? ' ' . $this->category : ''; if (isset($this->testsList[$module])) { $reporter = jClasses::create($this->responseType); jClasses::inc('junittests~junittestcase'); jClasses::inc('junittests~junittestcasedb'); $reporter->setResponse($rep); foreach ($this->testsList[$module] as $test) { if ($test[1] == $testname) { $group = new TestSuite('"' . $module . '" module , ' . $test[2]); $group->addFile(jApp::config()->_modulesPathList[$module] . 'tests/' . $test[0]); jContext::push($module); $result = $group->run($reporter); if (!$result) { $rep->setExitCode(jResponseCmdline::EXIT_CODE_ERROR); } jContext::pop(); break; } } } else { $this->output("\n" . 'no' . $category . ' tests for "' . $module . '" module.' . "\n"); } return $this->_finishResponse($rep); }