function __construct($sel, $locale = null, $charset = null)
 {
     global $gJConfig;
     if ($locale === null) {
         $locale = $gJConfig->locale;
     }
     if ($charset === null) {
         $charset = $gJConfig->charset;
     }
     if (strpos($locale, '_') === false) {
         $locale .= '_' . strtoupper($locale);
     }
     $this->locale = $locale;
     $this->charset = $charset;
     $this->_suffix = '.' . $charset . '.properties';
     $this->_compilerPath = JELIX_LIB_CORE_PATH . 'jLocalesCompiler.class.php';
     if (preg_match("/^(([a-zA-Z0-9_\\.]+)~)?([a-zA-Z0-9_]+)\\.([a-zA-Z0-9_\\.]+)\$/", $sel, $m)) {
         if ($m[1] != '' && $m[2] != '') {
             $this->module = $m[2];
         } else {
             $this->module = jContext::get();
         }
         $this->resource = $m[3];
         $this->fileKey = $m[3];
         $this->messageKey = $m[4];
         $this->_createPath();
         $this->_createCachePath();
     } else {
         throw new jExceptionSelector('jelix~errors.selector.invalid.syntax', array($sel, $this->type));
     }
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
 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;
 }
 function __construct($sel)
 {
     if (preg_match("/^(([a-zA-Z0-9_\\.]+)~)?([a-zA-Z0-9_\\.]+)\$/", $sel, $m)) {
         if ($m[1] != '' && $m[2] != '') {
             $this->module = $m[2];
         } else {
             $this->module = jContext::get();
         }
         $this->resource = $m[3];
         $this->_createPath();
         $this->_createCachePath();
     } else {
         throw new jExceptionSelector('jelix~errors.selector.invalid.syntax', array($sel, $this->type));
     }
 }
 function __construct($sel)
 {
     if (preg_match("/^(([a-zA-Z0-9_\\.]+)~)?([a-zA-Z0-9_\\.\\/]+)\$/", $sel, $m)) {
         if ($m[1] != '' && $m[2] != '') {
             $this->module = $m[2];
         } else {
             $this->module = jContext::get();
         }
         $this->resource = $m[3];
         if (($p = strrpos($m[3], '/')) !== false) {
             $this->className = substr($m[3], $p + 1);
             $this->subpath = substr($m[3], 0, $p + 1);
         } else {
             $this->className = $m[3];
             $this->subpath = '';
         }
         $this->_createPath();
         $this->_createCachePath();
     } else {
         throw new jExceptionSelector('jelix~errors.selector.invalid.syntax', array($sel, $this->type));
     }
 }
 /**
  * @param string $sel  the selector
  * @param boolean $enableRequestPart true if the selector can contain the request part
  */
 function __construct($sel, $enableRequestPart = false)
 {
     global $gJCoord;
     if (preg_match("/^(?:([a-zA-Z0-9_\\.]+|\\#)~)?([a-zA-Z0-9_:]+|\\#)?(?:@([a-zA-Z0-9_]+))?\$/", $sel, $m)) {
         $m = array_pad($m, 4, '');
         if ($m[1] != '') {
             if ($m[1] == '#') {
                 $this->module = $gJCoord->moduleName;
             } else {
                 $this->module = $m[1];
             }
         } else {
             $this->module = jContext::get();
         }
         if ($m[2] == '#') {
             $this->resource = $gJCoord->actionName;
         } else {
             $this->resource = $m[2];
         }
         $r = explode(':', $this->resource);
         if (count($r) == 1) {
             $this->controller = 'default';
             $this->method = $r[0] == '' ? 'index' : $r[0];
         } else {
             $this->controller = $r[0] == '' ? 'default' : $r[0];
             $this->method = $r[1] == '' ? 'index' : $r[1];
         }
         $this->resource = $this->controller . ':' . $this->method;
         if ($m[3] != '' && $enableRequestPart) {
             $this->request = $m[3];
         } else {
             $this->request = $gJCoord->request->type;
         }
         $this->_createPath();
     } else {
         throw new jExceptionSelector('jelix~errors.selector.invalid.syntax', array($sel, $this->type));
     }
 }
Esempio n. 7
0
 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));
 }
Esempio n. 8
0
 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));
 }
Esempio n. 9
0
 /**
  * clear the context
  */
 static function clear()
 {
     self::$context = array();
 }
Esempio n. 10
0
 /**
  * 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();
 }
Esempio n. 11
0
 /**
  * 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;
 }
Esempio n. 12
0
 public function create($urlact)
 {
     if ($this->dataCreateUrl == null) {
         $sel = new jSelectorUrlCfgSig(jApp::config()->urlengine['significantFile']);
         jIncluder::inc($sel);
         $this->dataCreateUrl =& $GLOBALS['SIGNIFICANT_CREATEURL'];
     }
     $url = new jUrl('', $urlact->params, '');
     $module = $url->getParam('module', jContext::get());
     $action = $url->getParam('action');
     $id = $module . '~' . $action . '@' . $urlact->requestType;
     $urlinfo = null;
     if (isset($this->dataCreateUrl[$id])) {
         $urlinfo = $this->dataCreateUrl[$id];
         $url->delParam('module');
         $url->delParam('action');
     } else {
         $id = $module . '~*@' . $urlact->requestType;
         if (isset($this->dataCreateUrl[$id])) {
             $urlinfo = $this->dataCreateUrl[$id];
             if ($urlinfo[0] != 3 || $urlinfo[3] === true) {
                 $url->delParam('module');
             }
         } else {
             $id = '@' . $urlact->requestType;
             if (isset($this->dataCreateUrl[$id])) {
                 $urlinfo = $this->dataCreateUrl[$id];
             } else {
                 throw new Exception("Significant url engine doesn't find corresponding url to this action :" . $module . '~' . $action . '@' . $urlact->requestType);
             }
         }
     }
     if ($urlinfo[0] == 4) {
         $l = count($urlinfo);
         $urlinfofound = null;
         for ($i = 1; $i < $l; $i++) {
             $ok = true;
             foreach ($urlinfo[$i][7] as $n => $v) {
                 $specialStatic = $v[0] == '$';
                 $paramStatic = $url->getParam($n, null);
                 if ($specialStatic) {
                     $typePS = $v[1];
                     $v = substr($v, 2);
                     if ($typePS == 'l') {
                         if ($paramStatic === null) {
                             $paramStatic = jLocale::getCurrentLang();
                         } else {
                             if (preg_match('/^(\\w{2,3})_\\w{2,3}$/', $paramStatic, $m)) {
                                 $paramStatic = $m[1];
                             }
                         }
                     } elseif ($typePS == 'L') {
                         if ($paramStatic === null) {
                             $paramStatic = jApp::config()->locale;
                         } else {
                             if (preg_match('/^\\w{2,3}$/', $paramStatic, $m)) {
                                 $paramStatic = jLocale::langToLocale($paramStatic);
                             }
                         }
                     }
                 }
                 if ($paramStatic != $v) {
                     $ok = false;
                     break;
                 }
             }
             if ($ok) {
                 $urlinfofound = $urlinfo[$i];
                 break;
             }
         }
         if ($urlinfofound !== null) {
             $urlinfo = $urlinfofound;
         } else {
             $urlinfo = $urlinfo[1];
         }
     }
     $url->scriptName = jApp::config()->urlengine['basePath'] . $urlinfo[1];
     if ($urlinfo[2]) {
         $url->scriptName = jApp::coord()->request->getServerURI(true) . $url->scriptName;
     }
     if ($urlinfo[1] && !jApp::config()->urlengine['multiview']) {
         $url->scriptName .= jApp::config()->urlengine['entrypointExtension'];
     }
     if (in_array($urlact->requestType, array('xmlrpc', 'jsonrpc', 'soap'))) {
         $url->clearParam();
         return $url;
     }
     if ($urlinfo[0] == 0) {
         $s = new jSelectorUrlHandler($urlinfo[3]);
         $c = $s->resource . 'UrlsHandler';
         $handler = new $c();
         $handler->create($urlact, $url);
         if ($urlinfo[4] != '') {
             $url->pathInfo = $urlinfo[4] . $url->pathInfo;
         }
     } elseif ($urlinfo[0] == 1) {
         $pi = $urlinfo[5];
         foreach ($urlinfo[3] as $k => $param) {
             $typeParam = $urlinfo[4][$k];
             $value = $url->getParam($param, '');
             if ($typeParam & 2) {
                 $value = jUrl::escape($value, true);
             } else {
                 if ($typeParam & 1) {
                     $value = str_replace('%2F', '/', urlencode($value));
                 } else {
                     if ($typeParam & 4) {
                         if ($value == '') {
                             $value = jLocale::getCurrentLang();
                         } else {
                             if (preg_match('/^(\\w{2,3})_\\w{2,3}$/', $value, $m)) {
                                 $value = $m[1];
                             }
                         }
                     } else {
                         if ($typeParam & 8) {
                             if ($value == '') {
                                 $value = jApp::config()->locale;
                             } else {
                                 if (preg_match('/^\\w{2,3}$/', $value, $m)) {
                                     $value = jLocale::langToLocale($value);
                                 }
                             }
                         } else {
                             $value = urlencode($value);
                         }
                     }
                 }
             }
             $pi = str_replace(':' . $param, $value, $pi);
             $url->delParam($param);
         }
         $url->pathInfo = $pi;
         if ($urlinfo[6]) {
             $url->setParam('action', $action);
         }
         foreach ($urlinfo[7] as $name => $value) {
             $url->delParam($name);
         }
     } elseif ($urlinfo[0] == 3) {
         if ($urlinfo[3]) {
             $url->delParam('module');
         }
     }
     return $url;
 }
Esempio n. 13
0
 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);
 }
Esempio n. 14
0
 protected function tearDown()
 {
     jContext::pop();
 }
Esempio n. 15
0
 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);
 }
Esempio n. 16
0
 /**
  * Create a jurl object with the given action data
  * @param jUrlAction $url  information about the action
  * @return jUrl the url correspondant to the action
  * @author      Laurent Jouanneau
  * @copyright   2005 CopixTeam, 2005-2006 Laurent Jouanneau
  *   very few lines of code are copyrighted by CopixTeam, written by Laurent Jouanneau
  *   and released under GNU Lesser General Public Licence,
  *   in an experimental version of Copix Framework v2.3dev20050901,
  *   http://www.copix.org.
  */
 public function create($urlact)
 {
     if ($this->dataCreateUrl == null) {
         $sel = new jSelectorUrlCfgSig($GLOBALS['gJConfig']->urlengine['significantFile']);
         jIncluder::inc($sel);
         $this->dataCreateUrl =& $GLOBALS['SIGNIFICANT_CREATEURL'];
     }
     $url = new jUrl('', $urlact->params, '');
     $module = $url->getParam('module', jContext::get());
     $action = $url->getParam('action');
     // let's try to retrieve informations corresponding
     // to the given action. this informations will allow us to build
     // the url
     $id = $module . '~' . $action . '@' . $urlact->requestType;
     $urlinfo = null;
     if (isset($this->dataCreateUrl[$id])) {
         $urlinfo = $this->dataCreateUrl[$id];
         $url->delParam('module');
         $url->delParam('action');
     } else {
         $id = $module . '~*@' . $urlact->requestType;
         if (isset($this->dataCreateUrl[$id])) {
             $urlinfo = $this->dataCreateUrl[$id];
             if ($urlinfo[0] != 3 || $urlinfo[3] === true) {
                 $url->delParam('module');
             }
         } else {
             $id = '@' . $urlact->requestType;
             if (isset($this->dataCreateUrl[$id])) {
                 $urlinfo = $this->dataCreateUrl[$id];
             } else {
                 throw new Exception("Significant url engine doesn't find corresponding url to this action :" . $module . '~' . $action . '@' . $urlact->requestType);
             }
         }
     }
     /*
     urlinfo =
       or array(0,'entrypoint', https true/false, 'handler selector', 'basepathinfo')
       or array(1,'entrypoint', https true/false,
               array('year','month',), // list of dynamic values included in the url
               array(true, false..), // list of integers which indicates for each
                                     // dynamic value: 0: urlencode, 1:urlencode except '/', 2:escape
               "/news/%1/%2/", // the url
               true/false, // false : this is a secondary action
               array('bla'=>'whatIWant' ) // list of static values
               )
       or array(2,'entrypoint', https true/false), // for the patterns "@request"
       or array(3,'entrypoint', https true/false), // for the patterns "module~@request"
       or array(4, array(1,...), array(1,...)...)
     */
     if ($urlinfo[0] == 4) {
         // an action is mapped to several urls
         // so it isn't finished. Let's find building information
         // into the array
         $l = count($urlinfo);
         $urlinfofound = null;
         for ($i = 1; $i < $l; $i++) {
             $ok = true;
             // verify that given static parameters of the action correspond
             // to those defined for this url
             foreach ($urlinfo[$i][7] as $n => $v) {
                 if ($url->getParam($n, '') != $v) {
                     $ok = false;
                     break;
                 }
             }
             if ($ok) {
                 // static parameters correspond: we found our informations
                 $urlinfofound = $urlinfo[$i];
                 break;
             }
         }
         if ($urlinfofound !== null) {
             $urlinfo = $urlinfofound;
         } else {
             $urlinfo = $urlinfo[1];
         }
     }
     // at this step, we have informations to build the url
     $url->scriptName = $GLOBALS['gJConfig']->urlengine['basePath'] . $urlinfo[1];
     if ($urlinfo[2]) {
         $url->scriptName = $GLOBALS['gJCoord']->request->getServerURI(true) . $url->scriptName;
     }
     if ($urlinfo[1] && !$GLOBALS['gJConfig']->urlengine['multiview']) {
         $url->scriptName .= $GLOBALS['gJConfig']->urlengine['entrypointExtension'];
     }
     // pour certains types de requete, les paramètres ne sont pas dans l'url
     // donc on les supprime
     // c'est un peu crade de faire ça en dur ici, mais ce serait lourdingue
     // de charger la classe request pour savoir si on peut supprimer ou pas
     if (in_array($urlact->requestType, array('xmlrpc', 'jsonrpc', 'soap'))) {
         $url->clearParam();
         return $url;
     }
     if ($urlinfo[0] == 0) {
         $s = new jSelectorUrlHandler($urlinfo[3]);
         $c = $s->resource . 'UrlsHandler';
         $handler = new $c();
         $handler->create($urlact, $url);
         if ($urlinfo[4] != '') {
             $url->pathInfo = $urlinfo[4] . $url->pathInfo;
         }
     } elseif ($urlinfo[0] == 1) {
         $pi = $urlinfo[5];
         foreach ($urlinfo[3] as $k => $param) {
             switch ($urlinfo[4][$k]) {
                 case 2:
                     $value = jUrl::escape($url->getParam($param, ''), true);
                     break;
                 case 1:
                     $value = str_replace('%2F', '/', urlencode($url->getParam($param, '')));
                     break;
                 default:
                     $value = urlencode($url->getParam($param, ''));
                     break;
             }
             $pi = str_replace(':' . $param, $value, $pi);
             $url->delParam($param);
         }
         $url->pathInfo = $pi;
         if ($urlinfo[6]) {
             $url->setParam('action', $action);
         }
         // removed parameters corresponding to static values
         foreach ($urlinfo[7] as $name => $value) {
             $url->delParam($name);
         }
     } elseif ($urlinfo[0] == 3) {
         if ($urlinfo[3]) {
             $url->delParam('module');
         }
     }
     return $url;
 }
Esempio n. 17
0
 /**
  * Create a jurl object with the given action data
  * @param jUrlAction $url  information about the action
  * @return jUrl the url correspondant to the action
  * @author      Laurent Jouanneau
  * @copyright   2005 CopixTeam, 2005-2006 Laurent Jouanneau
  *   very few lines of code are copyrighted by CopixTeam, written by Laurent Jouanneau
  *   and released under GNU Lesser General Public Licence,
  *   in an experimental version of Copix Framework v2.3dev20050901,
  *   http://www.copix.org.
  */
 public function create($urlact)
 {
     if ($this->dataCreateUrl == null) {
         $sel = new jSelectorUrlCfgSig($GLOBALS['gJConfig']->urlengine['significantFile']);
         jIncluder::inc($sel);
         $this->dataCreateUrl =& $GLOBALS['SIGNIFICANT_CREATEURL'];
     }
     /*
     a) recupere module~action@request -> obtient les infos pour la creation de l'url
     b) récupère un à un les parametres indiqués dans params à partir de jUrl
     c) remplace la valeur récupérée dans le result et supprime le paramètre de l'url
     d) remplace scriptname de jUrl par le resultat
     */
     $url = new jUrl('', $urlact->params, '');
     $module = $url->getParam('module', jContext::get());
     $action = $url->getParam('action');
     $id = $module . '~' . $action . '@' . $urlact->requestType;
     $urlinfo = null;
     if (isset($this->dataCreateUrl[$id])) {
         $urlinfo = $this->dataCreateUrl[$id];
         $url->delParam('module');
         $url->delParam('action');
     } else {
         $id = $module . '~*@' . $urlact->requestType;
         if (isset($this->dataCreateUrl[$id])) {
             $urlinfo = $this->dataCreateUrl[$id];
             $url->delParam('module');
         } else {
             $id = '@' . $urlact->requestType;
             if (isset($this->dataCreateUrl[$id])) {
                 $urlinfo = $this->dataCreateUrl[$id];
             } else {
                 throw new Exception("Significant url engine doesn't find corresponding url to this action :" . $module . '~' . $action . '@' . $urlact->requestType);
             }
         }
     }
     /*
     urlinfo =
         array(0,'entrypoint', https true/false,'selecteur handler')
         ou
         array(1,'entrypoint', https true/false, 
                 array('annee','mois','jour','id','titre'), // liste des paramètres de l'url à prendre en compte
                 array(true, false..), // valeur des escapes
                 "/news/%1/%2/%3/%4-%5", // forme de l'url
                 false, //indique si  c'est une action surchargeante
                 )
         ou
         array(2,'entrypoint', https true/false,); pour les clés du type "@request"
         array(3,'entrypoint', https true/false); pour les clés du type "module~@request"
         array(4, array(1,..), array(1,..)...);
     */
     if ($urlinfo[0] == 4) {
         $l = count($urlinfo);
         $urlinfofound = null;
         for ($i = 1; $i < $l; $i++) {
             $ok = true;
             foreach ($urlinfo[$i][7] as $n => $v) {
                 if ($url->getParam($n, '') != $v) {
                     $ok = false;
                     break;
                 }
             }
             if ($ok) {
                 $urlinfofound = $urlinfo[$i];
                 break;
             }
         }
         if ($urlinfofound !== null) {
             $urlinfo = $urlinfofound;
         } else {
             $urlinfo = $urlinfo[1];
         }
     }
     $url->scriptName = $GLOBALS['gJConfig']->urlengine['basePath'] . $urlinfo[1];
     if ($urlinfo[2]) {
         $url->scriptName = 'https://' . $_SERVER['HTTP_HOST'] . $url->scriptName;
     }
     if ($urlinfo[1] && !$GLOBALS['gJConfig']->urlengine['multiview']) {
         $url->scriptName .= $GLOBALS['gJConfig']->urlengine['entrypointExtension'];
     }
     // pour certains types de requete, les paramètres ne sont pas dans l'url
     // donc on les supprime
     // c'est un peu crade de faire ça en dur ici, mais ce serait lourdingue
     // de charger la classe request pour savoir si on peut supprimer ou pas
     if (in_array($urlact->requestType, array('xmlrpc', 'jsonrpc', 'soap'))) {
         $url->clearParam();
         return $url;
     }
     if ($urlinfo[0] == 0) {
         $s = new jSelectorUrlHandler($urlinfo[3]);
         $c = $s->resource . 'UrlsHandler';
         $handler = new $c();
         $handler->create($urlact, $url);
     } elseif ($urlinfo[0] == 1) {
         $pi = $urlinfo[5];
         foreach ($urlinfo[3] as $k => $param) {
             if ($urlinfo[4][$k]) {
                 $pi = str_replace(':' . $param, jUrl::escape($url->getParam($param, ''), true), $pi);
             } else {
                 $pi = str_replace(':' . $param, $url->getParam($param, ''), $pi);
             }
             $url->delParam($param);
         }
         $url->pathInfo = $pi;
         if ($urlinfo[6]) {
             $url->setParam('action', $action);
         }
         // removed parameters corresponding to static values
         foreach ($urlinfo[7] as $name => $value) {
             $url->delParam($name);
         }
     } elseif ($urlinfo[0] == 3) {
         $url->delParam('module');
     }
     return $url;
 }
Esempio n. 18
0
 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);
 }