/** * compile the given class id. */ public function compile($selector) { jDaoCompiler::$daoId = $selector->toString(); jDaoCompiler::$daoPath = $selector->getPath(); jDaoCompiler::$dbType = $selector->driver; // chargement du fichier XML $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)); global $gJConfig; if (!isset($gJConfig->_pluginsPathList_db[$selector->driver]) || !file_exists($gJConfig->_pluginsPathList_db[$selector->driver])) { throw new jException('jelix~db.error.driver.notfound', $selector->driver); } require_once $gJConfig->_pluginsPathList_db[$selector->driver] . $selector->driver . '.daobuilder.php'; $class = $selector->driver . 'DaoBuilder'; $generator = new $class($selector->getDaoClass(), $selector->getDaoRecordClass(), $parser); // génération des classes PHP correspondant à la définition de la DAO $compiled = '<?php ' . $generator->buildClasses() . "\n?>"; jFile::write($selector->getCompiledFilePath(), $compiled); return true; }
public function compile($selector) { global $gJCoord; global $gJConfig; $sel = clone $selector; $this->sourceFile = $selector->getPath(); // chargement du fichier XML $doc = new DOMDocument(); if (!$doc->load($this->sourceFile)) { throw new jException('jelix~formserr.invalid.xml.file', array($this->sourceFile)); } if ($doc->documentElement->namespaceURI == JELIX_NAMESPACE_BASE . 'forms/1.0') { require_once JELIX_LIB_PATH . 'forms/jFormsCompiler_jf_1_0.class.php'; $compiler = new jFormsCompiler_jf_1_0($this->sourceFile); } elseif ($doc->documentElement->namespaceURI == JELIX_NAMESPACE_BASE . 'forms/1.1') { if ($doc->documentElement->localName != 'form') { throw new jException('jelix~formserr.bad.root.tag', array($doc->documentElement->localName, $this->sourceFile)); } require_once JELIX_LIB_PATH . 'forms/jFormsCompiler_jf_1_1.class.php'; $compiler = new jFormsCompiler_jf_1_1($this->sourceFile); } else { throw new jException('jelix~formserr.namespace.wrong', array($this->sourceFile)); } $source = array(); $source[] = '<?php '; $source[] = 'class ' . $selector->getClass() . ' extends jFormsBase {'; $source[] = ' public function __construct($sel, &$container, $reset = false){'; $source[] = ' parent::__construct($sel, $container, $reset);'; $compiler->compile($doc, $source); $source[] = " }\n} ?>"; jFile::write($selector->getCompiledFilePath(), implode("\n", $source)); return true; }
public function compile($selector) { $sel = clone $selector; $this->sourceFile = $selector->getPath(); // load XML file $doc = new DOMDocument(); if (!$doc->load($this->sourceFile)) { throw new jException('jelix~formserr.invalid.xml.file', array($this->sourceFile)); } if ($doc->documentElement->namespaceURI == JELIX_NAMESPACE_BASE . 'forms/1.0') { require_once JELIX_LIB_PATH . 'forms/jFormsCompiler_jf_1_0.class.php'; $compiler = new jFormsCompiler_jf_1_0($this->sourceFile); } elseif ($doc->documentElement->namespaceURI == JELIX_NAMESPACE_BASE . 'forms/1.1') { if ($doc->documentElement->localName != 'form') { throw new jException('jelix~formserr.bad.root.tag', array($doc->documentElement->localName, $this->sourceFile)); } require_once JELIX_LIB_PATH . 'forms/jFormsCompiler_jf_1_1.class.php'; $compiler = new jFormsCompiler_jf_1_1($this->sourceFile); } else { throw new jException('jelix~formserr.namespace.wrong', array($this->sourceFile)); } $source = array(); $source[] = "<?php \nif (jApp::config()->compilation['checkCacheFiletime'] &&\n"; $source[] .= "filemtime('" . $this->sourceFile . '\') > ' . filemtime($this->sourceFile) . "){ return false;\n}else{\n"; $source[] = 'class ' . $selector->getClass() . ' extends jFormsBase {'; $source[] = ' public function __construct($sel, &$container, $reset = false){'; $source[] = ' parent::__construct($sel, $container, $reset);'; $compiler->compile($doc, $source); $source[] = " }\n}\n return true;}"; jFile::write($selector->getCompiledFilePath(), implode("\n", $source)); return true; }
/** * 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 compileString($templatecontent, $cachefile, $userModifiers, $userFunctions, $md5) { $this->_modifier = array_merge($this->_modifier, $userModifiers); $this->_userFunctions = $userFunctions; $result = $this->compileContent($templatecontent); $header = "<?php \n"; foreach ($this->_pluginPath as $path => $ok) { $header .= ' require_once(\'' . $path . "');\n"; } $header .= 'function template_meta_' . $md5 . '($t){'; $header .= "\n" . $this->_metaBody . "\n}\n"; $header .= 'function template_' . $md5 . '($t){' . "\n?>"; $result = $header . $result . "<?php \n}\n?>"; jFile::write($cachefile, $result); return true; }
function output() { if ($this->_outputOnlyHeaders) { $this->sendHttpHeaders(); return true; } $this->_commonProcess(); if (count($this->_commands) <= 0) { $this->addDefaultCommands(); } $data = join("\n", $this->_commands) . ' \\begin{document} \\title{' . $this->title . '} \\author{'; foreach ($this->authors as $a) { $data .= $a . '\\\\' . "\n"; } $data .= '} \\date{' . $this->date . '} '; $data .= $this->body->fetch($this->bodyTpl); $data .= ' \\end{document}'; $fbase = 'cache-' . md5($data); $texFile = $this->cachePath . $fbase . '.tex'; $pdfFile = $this->cachePath . $fbase . '.pdf'; if (!file_exists($pdfFile)) { jFile::write($texFile, $data); $output = array(); $retVal = 1; exec($this->pdflatexPath . ' --interaction batchmode --output-directory ' . $this->cachePath . ' ' . $texFile, $output, $retval); if ($retVal != 0) { $outputStr = implode('<br />', $output); throw new jException('jelix~errors.ltx2pdf.exec', array($this->pdflatexPath, $outputStr)); } } $this->_httpHeaders['Content-Type'] = 'application/pdf'; $this->_httpHeaders['Content-length'] = @filesize($pdfFile); $this->_httpHeaders['Content-Disposition'] = 'attachment; filename=' . $this->outputFileName; $this->sendHttpHeaders(); readfile($pdfFile); return true; }
/** * compile the given class id. * @param jSelectorDao $selector */ public function compile($selector) { $daoPath = $selector->getPath(); // load the XML file $doc = new DOMDocument(); 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)); } $tools = jApp::loadPlugin($selector->driver, 'db', '.dbtools.php', $selector->driver . 'DbTools'); if (is_null($tools)) { throw new jException('jelix~db.error.driver.notfound', $selector->driver); } $parser = new jDaoParser($selector); $parser->parse(simplexml_import_dom($doc), $tools); $class = $selector->dbType . 'DaoBuilder'; if (!jApp::includePlugin($selector->dbType, 'daobuilder', '.daobuilder.php', $class)) { throw new jException('jelix~dao.error.builder.notfound', $selector->dbType); } $generator = new $class($selector, $tools, $parser); // generation of PHP classes corresponding to the DAO definition $compiled = '<?php '; $compiled .= "\nif (jApp::config()->compilation['checkCacheFiletime']&&(\n"; $compiled .= "\n filemtime('" . $daoPath . '\') > ' . filemtime($daoPath); $importedDao = $parser->getImportedDao(); if ($importedDao) { foreach ($importedDao as $selimpdao) { $path = $selimpdao->getPath(); $compiled .= "\n|| filemtime('" . $path . '\') > ' . filemtime($path); } } $compiled .= ")){ return false;\n}\nelse {\n"; $compiled .= $generator->buildClasses() . "\n return true; }"; jFile::write($selector->getCompiledFilePath(), $compiled); return true; }
public function endCompile($cachefile) { $content = '<?php $GLOBALS["JELIX_EVENTS"] = ' . var_export($this->eventList, true) . ";\n?>"; jFile::write($cachefile, $content); }
protected function copyMail($header, $body) { $dir = rtrim($this->filePath, '/') . '/copy-' . date('Ymd') . '/'; if (isset(jApp::coord()->request)) { $ip = jApp::coord()->request->getIP(); } else { $ip = "no-ip"; } $filename = $dir . 'mail-' . $ip . '-' . date('Ymd-His') . '-' . uniqid(mt_rand(), true); jFile::write($filename, $header . $body); }
/** * Update the WSDL cache file */ private function _updateWSDL() { static $updated = FALSE; if ($updated) { return; } $mustCompile = jApp::config()->compilation['force'] || !file_exists($this->_cachePath); if (jApp::config()->compilation['checkCacheFiletime'] && !$mustCompile) { if (filemtime($this->_ctrlpath) > filemtime($this->_cachePath)) { $mustCompile = true; } } if ($mustCompile) { jFile::write($this->_cachePath, $this->_compile()); } $updated = TRUE; }
/** * */ public function compile($aSelector) { $sourceFile = $aSelector->getPath(); $cachefile = $aSelector->getCompiledFilePath(); $xml = simplexml_load_file($sourceFile); if (!$xml) { return false; } /* <urls> <classicentrypoint name="index" default="true"> <url pathinfo="/test/:mois/:annee" module="" action=""> <param name="mois" escape="true" regexp="\d{4}"/> <param name="annee" escape="false" /> <static name="bla" value="cequejeveux" /> </url> <url handler="" module="" action="" /> </classicentrypoint> </urls> The compiler generates two files. It generates a php file for each entrypoint. A file contains a $PARSE_URL array: $PARSE_URL = array($isDefault, $infoparser, $infoparser, ... ) where: $isDefault: true if it is the default entry point. In this case and where the url parser doesn't find a corresponding action, it will ignore else it will generate an error $infoparser = array('module','action', 'regexp_pathinfo', 'handler selector', array('secondaries','actions'), false // needs https or not ) or $infoparser = array('module','action','regexp_pathinfo', array('year','month'), // list of dynamic value included in the url, // alphabetical ascendant order array(true, false), // list of boolean which indicates for each // dynamic value, if it is an escaped value or not array('bla'=>'whatIWant' ), // list of static values array('secondaries','actions'), false // need https or not ) It generates an other file common to all entry point. It contains an array which contains informations to create urls $CREATE_URL = array( 'news~show@classic' => // the action selector array(0,'entrypoint', https true/false, 'handler selector') or array(1,'entrypoint', https true/false, array('year','month',), // list of dynamic values included in the url array(0, 1..), // list of integer which indicates for each // dynamic value: 0: urlencode, 1:urlencode except '/', 2:escape, 4: lang, 8: locale "/news/%1/%2/", // the url array('bla'=>'whatIWant' ) // list of static values ) or When there are several urls to the same action, it is an array of this kind of the previous array: array(4, array(1,...), array(1,...)...) or array(2,'entrypoint', https true/false), // for the patterns "@request" or array(3,'entrypoint', https true/false), // for the patterns "module~@request" */ $this->createUrlInfos = array(); $this->createUrlContent = "<?php \nif (jApp::config()->compilation['checkCacheFiletime'] &&( \n"; $this->createUrlContent .= "filemtime('" . $sourceFile . '\') > ' . filemtime($sourceFile); $this->createUrlContentInc = ''; $this->readProjectXml(); $this->retrieveModulePaths(jApp::configPath('defaultconfig.ini.php')); // for an app on a simple http server behind an https proxy, we shouldn't check HTTPS $this->checkHttps = jApp::config()->urlengine['checkHttpsOnParsing']; foreach ($xml->children() as $tagname => $tag) { if (!preg_match("/^(.*)entrypoint\$/", $tagname, $m)) { //TODO : error continue; } $type = $m[1]; if ($type == '') { if (isset($tag['type'])) { $type = (string) $tag['type']; } if ($type == '') { $type = 'classic'; } } $this->defaultUrl = new significantUrlInfoParsing($type, (string) $tag['name'], isset($tag['default']) ? (string) $tag['default'] == 'true' : false, isset($tag['https']) ? (string) $tag['https'] == 'true' : false); if (isset($tag['noentrypoint']) && (string) $tag['noentrypoint'] == 'true') { $this->defaultUrl->entryPointUrl = ''; } $optionalTrailingSlash = isset($tag['optionalTrailingSlash']) && $tag['optionalTrailingSlash'] == 'true'; $this->parseInfos = array($this->defaultUrl->isDefault); //let's read the modulesPath of the entry point $this->retrieveModulePaths($this->getEntryPointConfig($this->defaultUrl->entryPoint)); // if this is the default entry point for the request type, // then we add a rule which will match urls which are not // defined. if ($this->defaultUrl->isDefault) { $this->createUrlInfos['@' . $this->defaultUrl->requestType] = array(2, $this->defaultUrl->entryPoint, $this->defaultUrl->isHttps); } $createUrlInfosDedicatedModules = array(); $parseContent = "<?php \n"; foreach ($tag->children() as $tagname => $url) { $u = clone $this->defaultUrl; $u->module = (string) $url['module']; if (isset($url['https'])) { $u->isHttps = (string) $url['https'] == 'true'; } if (isset($url['noentrypoint']) && (string) $url['noentrypoint'] == 'true') { $u->entryPointUrl = ''; } if (isset($url['include'])) { $this->readInclude($url, $u); continue; } // in the case of a non default entry point, if there is just an // <url module="" />, so all actions of this module will be assigned // to this entry point. if (!$u->isDefault && !isset($url['action']) && !isset($url['handler'])) { $this->parseInfos[] = array($u->module, '', '/.*/', array(), array(), array(), false, $this->checkHttps && $u->isHttps); $createUrlInfosDedicatedModules[$u->getFullSel()] = array(3, $u->entryPointUrl, $u->isHttps, true); continue; } $u->action = (string) $url['action']; if (strpos($u->action, ':') === false) { $u->action = 'default:' . $u->action; } if (isset($url['actionoverride'])) { $u->actionOverride = preg_split("/[\\s,]+/", (string) $url['actionoverride']); foreach ($u->actionOverride as &$each) { if (strpos($each, ':') === false) { $each = 'default:' . $each; } } } // if there is an indicated handler, so, for the given module // (and optional action), we should call the given handler to // parse or create an url if (isset($url['handler'])) { $this->newHandler($u, $url); continue; } // parse dynamic parameters if (isset($url['pathinfo'])) { $path = (string) $url['pathinfo']; $regexppath = $this->extractDynamicParams($url, $path, $u); } else { $regexppath = '.*'; $path = ''; } $tempOptionalTrailingSlash = $optionalTrailingSlash; if (isset($url['optionalTrailingSlash'])) { $tempOptionalTrailingSlash = $url['optionalTrailingSlash'] == 'true'; } if ($tempOptionalTrailingSlash) { if (substr($regexppath, -1) == '/') { $regexppath .= '?'; } else { $regexppath .= '\\/?'; } } // parse static parameters foreach ($url->static as $var) { $t = ""; if (isset($var['type'])) { switch ((string) $var['type']) { case 'lang': $t = '$l'; break; case 'locale': $t = '$L'; break; default: throw new Exception('urls definition: invalid type on a <static> element'); } } $u->statics[(string) $var['name']] = $t . (string) $var['value']; } $this->parseInfos[] = array($u->module, $u->action, '!^' . $regexppath . '$!', $u->params, $u->escapes, $u->statics, $u->actionOverride, $this->checkHttps && $u->isHttps); $this->appendUrlInfo($u, $path, false); if ($u->actionOverride) { foreach ($u->actionOverride as $ao) { $u->action = $ao; $this->appendUrlInfo($u, $path, true); } } } $c = count($createUrlInfosDedicatedModules); foreach ($createUrlInfosDedicatedModules as $k => $inf) { if ($c > 1) { $inf[3] = false; } $this->createUrlInfos[$k] = $inf; } $parseContent .= '$GLOBALS[\'SIGNIFICANT_PARSEURL\'][\'' . rawurlencode($this->defaultUrl->entryPoint) . '\'] = ' . var_export($this->parseInfos, true) . ";\n?>"; jFile::write(jApp::tempPath('compiled/urlsig/' . $aSelector->file . '.' . rawurlencode($this->defaultUrl->entryPoint) . '.entrypoint.php'), $parseContent); } $this->createUrlContent .= ")) { return false; } else {\n"; $this->createUrlContent .= $this->createUrlContentInc; $this->createUrlContent .= '$GLOBALS[\'SIGNIFICANT_CREATEURL\'] =' . var_export($this->createUrlInfos, true) . ";\nreturn true;"; $this->createUrlContent .= "\n}\n"; jFile::write(jApp::tempPath('compiled/urlsig/' . $aSelector->file . '.creationinfos_15.php'), $this->createUrlContent); return true; }
/** * get the zone content * Return the cache content if it is activated and if it's exists, or call _createContent * @return string zone content */ public function getContent() { global $gJConfig; if ($this->_useCache && !$gJConfig->zones['disableCache']) { $f = $this->_getCacheFile(); if (file_exists($f)) { if ($this->_cacheTimeout > 0) { clearstatcache(); if (time() - filemtime($f) > $this->_cacheTimeout) { // timeout : regenerate the cache unlink($f); $this->_cancelCache = false; $content = $this->_createContent(); if (!$this->_cancelCache) { jFile::write($f, $content); } return $content; } } if ($this->_tplname != '') { $this->_tpl = new jTpl(); $this->_tpl->assign($this->_params); $this->_tpl->meta($this->_tplname, $this->_tplOuputType); } $content = file_get_contents($f); } else { $this->_cancelCache = false; $content = $this->_createContent(); if (!$this->_cancelCache) { jFile::write($f, $content); } } } else { $content = $this->_createContent(); } return $content; }
/** * Loads the resources for a given locale/charset. * @param string $locale the locale * @param string $charset the charset */ protected function _loadLocales($locale, $charset) { $this->_loadedCharset[] = $charset; $source = $this->fic->getPath(); $cache = $this->fic->getCompiledFilePath(); // check if we have a compiled version of the ressources if (is_readable($cache)) { $okcompile = true; if (App::config()->compilation['force']) { $okcompile = false; } else { if (App::config()->compilation['checkCacheFiletime']) { if (is_readable($source) && filemtime($source) > filemtime($cache)) { $okcompile = false; } } } if ($okcompile) { include $cache; $this->_strings[$charset] = $_loaded; return; } } $reader = new \jPropertiesFileReader($source, $charset); $reader->parse(); $this->_strings[$charset] = $reader->getProperties(); $content = '<?php $_loaded= ' . var_export($this->_strings[$charset], true) . ' ?>'; \jFile::write($cache, $content); }
/** * output the pdf content * * @return boolean true if the generated content is ok */ function output() { $this->_commonProcess(); if (count($this->_commands) <= 0) { //No commands, likewise we need some... $this->addDefaultCommands(); } $data = join("\n", $this->_commands) . ' \\begin{document} \\title{' . $this->title . '} \\author{'; foreach ($this->authors as $a) { $data .= $a . '\\\\' . "\n"; } $data .= '} \\date{\\today} \\maketitle '; $data .= $this->body->fetch($this->bodyTpl); $data .= ' \\end{document}'; $fbase = 'cache-' . md5($data); $texFile = $this->cachePath . $fbase . '.tex'; $pdfFile = $this->cachePath . $fbase . '.pdf'; if (!file_exists($pdfFile)) { // Naïve cache: we have an md5 on the content of the tex file. If the pdf // corresponding to this content already exists, just serve it. // No managment of cache deletion :o/ jFile::write($texFile, $data); $output = array(); $retVal = 1; exec(' TEXMFOUTPUT=' . $this->cachePath . ' && export TEXMFOUTPUT && TEXINPUTS=:' . $this->cachePath . ' && export TEXINPUTS && ' . $this->pdflatexPath . ' --interaction=batchmode ' . $texFile, $output, $retVal); if ($retVal == 0) { $outputStr = implode('<br />', $output); throw new jException('jelix~errors.ltx2pdf.exec', array($this->pdflatexPath, $outputStr)); } } $this->_httpHeaders['Content-Type'] = 'application/pdf'; $this->_httpHeaders['Content-length'] = @filesize($pdfFile); $this->_httpHeaders['Content-Disposition'] = 'attachment; filename=' . $this->title . '.pdf'; $this->sendHttpHeaders(); readfile($pdfFile); return true; }
protected function _saveCompiledString($cachefile, $result) { jFile::write($cachefile, $result); }
/** * */ public function compile($aSelector) { $sourceFile = $aSelector->getPath(); $cachefile = $aSelector->getCompiledFilePath(); $this->xmlfile = $aSelector->file; $xml = simplexml_load_file($sourceFile); if (!$xml) { return false; } /* <urls> <classicentrypoint name="index" default="true"> <url pathinfo="/test/:mois/:annee" module="" action=""> <param name="mois" escape="true" regexp="\d{4}"/> <param name="annee" escape="false" /> <static name="bla" value="cequejeveux" /> </url> <url handler="" module="" action="" /> </classicentrypoint> </urls> The compiler generates two files. It generates a php file for each entrypoint. A file contains a $PARSE_URL array: $PARSE_URL = array($isDefault, $infoparser, $infoparser, ... ) where: $isDefault: true if it is the default entry point. In this case and where the url parser doesn't find a corresponding action, it will ignore else it will generate an error $infoparser = array('module','action', 'regexp_pathinfo', 'handler selector', array('secondaries','actions'), false // needs https or not ) or $infoparser = array('module','action','regexp_pathinfo', array('year','month'), // list of dynamic value included in the url, // alphabetical ascendant order array(true, false), // list of boolean which indicates for each // dynamic value, if it is an escaped value or not array('bla'=>'whatIWant' ), // list of static values array('secondaries','actions'), false // need https or not ) It generates an other file common to all entry point. It contains an array which contains informations to create urls $CREATE_URL = array( 'news~show@classic' => // the action selector array(0,'entrypoint', https true/false, 'handler selector') or array(1,'entrypoint', https true/false, array('year','month',), // list of dynamic values included in the url array(0, 1..), // list of integer which indicates for each // dynamic value: 0: urlencode, 1:urlencode except '/', 2:escape, 4: lang, 8: locale "/news/%1/%2/", // the url array('bla'=>'whatIWant' ) // list of static values ) or When there are several urls to the same action, it is an array of this kind of the previous array: array(4, array(1,...), array(1,...)...) or array(2,'entrypoint', https true/false), // for the patterns "@request" or array(3,'entrypoint', https true/false, pathinfobase), // for the patterns "module~@request" */ $this->createUrlInfos = array(); $this->createUrlContent = "<?php \nif (\\Jelix\\Core\\App::config()->compilation['checkCacheFiletime'] &&( \n"; $this->createUrlContent .= "filemtime('" . $sourceFile . '\') > ' . filemtime($sourceFile); $this->createUrlContentInc = ''; $this->modulesPath = App::getAllModulesPath(); $this->parseXml($xml); // write cache files containing parsing informations foreach ($this->entrypoints as $epName => $epInfos) { list($urlModel, $parseInfos, $createUrlInfosDedicatedModules) = $epInfos; $parseContent = "<?php \n"; $parseContent .= '$GLOBALS[\'SIGNIFICANT_PARSEURL\'][\'' . rawurlencode($urlModel->entryPoint) . '\'] = ' . var_export($parseInfos, true) . ";\n?>"; \jFile::write(App::tempPath('compiled/urlsig/' . $aSelector->file . '.' . rawurlencode($urlModel->entryPoint) . '.entrypoint.php'), $parseContent); } // write cache file containing url creation informations $this->createUrlContent .= ")) { return false; } else {\n"; $this->createUrlContent .= $this->createUrlContentInc; $this->createUrlContent .= '$GLOBALS[\'SIGNIFICANT_CREATEURL\'] =' . var_export($this->createUrlInfos, true) . ";\nreturn true;"; $this->createUrlContent .= "\n}\n"; \jFile::write(App::tempPath('compiled/urlsig/' . $aSelector->file . '.creationinfos_15.php'), $this->createUrlContent); return true; }
public function compile($selector) { $daoPath = $selector->getPath(); $doc = new DOMDocument(); 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)); } $tools = jApp::loadPlugin($selector->driver, 'db', '.dbtools.php', $selector->driver . 'DbTools'); if (is_null($tools)) { throw new jException('jelix~db.error.driver.notfound', $selector->driver); } $parser = new jDaoParser($selector); $parser->parse(simplexml_import_dom($doc), $tools); require_once jApp::config()->_pluginsPathList_db[$selector->driver] . $selector->driver . '.daobuilder.php'; $class = $selector->driver . 'DaoBuilder'; $generator = new $class($selector, $tools, $parser); $compiled = '<?php ' . $generator->buildClasses() . "\n?>"; jFile::write($selector->getCompiledFilePath(), $compiled); return true; }
public function getContent() { if ($this->_useCache && !jApp::config()->zones['disableCache']) { $f = $this->_getCacheFile(); if (file_exists($f)) { if ($this->_cacheTimeout > 0) { if (version_compare(PHP_VERSION, '5.3.0') >= 0) { clearstatcache(false, $f); } else { clearstatcache(); } if (time() - filemtime($f) > $this->_cacheTimeout) { unlink($f); $this->_cancelCache = false; $content = $this->_createContent(); if (!$this->_cancelCache) { jFile::write($f, $content); } return $content; } } if ($this->_tplname != '') { $this->_tpl = new jTpl(); $this->_tpl->assign($this->_params); $this->_tpl->meta($this->_tplname, $this->_tplOutputType); } $content = file_get_contents($f); } else { $this->_cancelCache = false; $content = $this->_createContent(); if (!$this->_cancelCache) { jFile::write($f, $content); } } } else { $content = $this->_createContent(); } return $content; }
public function compile($aSelector) { $sourceFile = $aSelector->getPath(); $cachefile = $aSelector->getCompiledFilePath(); $xml = simplexml_load_file($sourceFile); if (!$xml) { return false; } $this->createUrlInfos = array(); $this->createUrlContent = "<?php \n"; $this->readProjectXml(); $this->retrieveModulePaths(jApp::configPath('defaultconfig.ini.php')); $this->checkHttps = jApp::config()->urlengine['checkHttpsOnParsing']; foreach ($xml->children() as $tagname => $tag) { if (!preg_match("/^(.*)entrypoint\$/", $tagname, $m)) { continue; } $type = $m[1]; if ($type == '') { if (isset($tag['type'])) { $type = (string) $tag['type']; } if ($type == '') { $type = 'classic'; } } $this->defaultUrl = new significantUrlInfoParsing($type, (string) $tag['name'], isset($tag['default']) ? (string) $tag['default'] == 'true' : false, isset($tag['https']) ? (string) $tag['https'] == 'true' : false); if (isset($tag['noentrypoint']) && (string) $tag['noentrypoint'] == 'true') { $this->defaultUrl->entryPointUrl = ''; } $optionalTrailingSlash = isset($tag['optionalTrailingSlash']) && $tag['optionalTrailingSlash'] == 'true'; $this->parseInfos = array($this->defaultUrl->isDefault); $this->retrieveModulePaths($this->getEntryPointConfig($this->defaultUrl->entryPoint)); if ($this->defaultUrl->isDefault) { $this->createUrlInfos['@' . $this->defaultUrl->requestType] = array(2, $this->defaultUrl->entryPoint, $this->defaultUrl->isHttps); } $createUrlInfosDedicatedModules = array(); $parseContent = "<?php \n"; foreach ($tag->children() as $tagname => $url) { $u = clone $this->defaultUrl; $u->module = (string) $url['module']; if (isset($url['https'])) { $u->isHttps = (string) $url['https'] == 'true'; } if (isset($url['noentrypoint']) && (string) $url['noentrypoint'] == 'true') { $u->entryPointUrl = ''; } if (isset($url['include'])) { $this->readInclude($url, $u); continue; } if (!$u->isDefault && !isset($url['action']) && !isset($url['handler'])) { $this->parseInfos[] = array($u->module, '', '/.*/', array(), array(), array(), false, $this->checkHttps && $u->isHttps); $createUrlInfosDedicatedModules[$u->getFullSel()] = array(3, $u->entryPointUrl, $u->isHttps, true); continue; } $u->action = (string) $url['action']; if (strpos($u->action, ':') === false) { $u->action = 'default:' . $u->action; } if (isset($url['actionoverride'])) { $u->actionOverride = preg_split("/[\\s,]+/", (string) $url['actionoverride']); foreach ($u->actionOverride as &$each) { if (strpos($each, ':') === false) { $each = 'default:' . $each; } } } if (isset($url['handler'])) { $this->newHandler($u, $url); continue; } if (isset($url['pathinfo'])) { $path = (string) $url['pathinfo']; $regexppath = $this->extractDynamicParams($url, $path, $u); } else { $regexppath = '.*'; $path = ''; } $tempOptionalTrailingSlash = $optionalTrailingSlash; if (isset($url['optionalTrailingSlash'])) { $tempOptionalTrailingSlash = $url['optionalTrailingSlash'] == 'true'; } if ($tempOptionalTrailingSlash) { if (substr($regexppath, -1) == '/') { $regexppath .= '?'; } else { $regexppath .= '\\/?'; } } foreach ($url->static as $var) { $t = ""; if (isset($var['type'])) { switch ((string) $var['type']) { case 'lang': $t = '$l'; break; case 'locale': $t = '$L'; break; default: throw new Exception('urls definition: invalid type on a <static> element'); } } $u->statics[(string) $var['name']] = $t . (string) $var['value']; } $this->parseInfos[] = array($u->module, $u->action, '!^' . $regexppath . '$!', $u->params, $u->escapes, $u->statics, $u->actionOverride, $this->checkHttps && $u->isHttps); $this->appendUrlInfo($u, $path, false); if ($u->actionOverride) { foreach ($u->actionOverride as $ao) { $u->action = $ao; $this->appendUrlInfo($u, $path, true); } } } $c = count($createUrlInfosDedicatedModules); foreach ($createUrlInfosDedicatedModules as $k => $inf) { if ($c > 1) { $inf[3] = false; } $this->createUrlInfos[$k] = $inf; } $parseContent .= '$GLOBALS[\'SIGNIFICANT_PARSEURL\'][\'' . rawurlencode($this->defaultUrl->entryPoint) . '\'] = ' . var_export($this->parseInfos, true) . ";\n?>"; jFile::write(jApp::tempPath('compiled/urlsig/' . $aSelector->file . '.' . rawurlencode($this->defaultUrl->entryPoint) . '.entrypoint.php'), $parseContent); } $this->createUrlContent .= '$GLOBALS[\'SIGNIFICANT_CREATEURL\'] =' . var_export($this->createUrlInfos, true) . ";\n?>"; jFile::write(jApp::tempPath('compiled/urlsig/' . $aSelector->file . '.creationinfos.php'), $this->createUrlContent); return true; }
protected function _loadLocales($locale, $charset) { $this->_loadedCharset[] = $charset; $source = $this->fic->getPath(); $cache = $this->fic->getCompiledFilePath(); if (is_readable($cache)) { $okcompile = true; if (jApp::config()->compilation['force']) { $okcompile = false; } else { if (jApp::config()->compilation['checkCacheFiletime']) { if (is_readable($source) && filemtime($source) > filemtime($cache)) { $okcompile = false; } } } if ($okcompile) { include $cache; $this->_strings[$charset] = $_loaded; return; } } $this->_loadResources($source, $charset); if (isset($this->_strings[$charset])) { $content = '<?php $_loaded= ' . var_export($this->_strings[$charset], true) . ' ?>'; jFile::write($cache, $content); } }
/** * get the zone content * Return the cache content if it is activated and if it's exists, or call _createContent * @return string zone content */ public function getContent() { if ($this->_useCache && !jApp::config()->zones['disableCache']) { $cacheFiles = $this->_getCacheFiles(); $f = $cacheFiles['content']; if (file_exists($f)) { if ($this->_cacheTimeout > 0) { clearstatcache(false, $f); if (time() - filemtime($f) > $this->_cacheTimeout) { // timeout : regenerate the cache unlink($f); $this->_cancelCache = false; $response = jApp::coord()->response; $sniffer = new jMethodSniffer($response, '$resp', array('getType', 'getFormatType'), true); jApp::coord()->response = $sniffer; $content = $this->_createContent(); jApp::coord()->response = $response; if (!$this->_cancelCache) { jFile::write($f, $content); jFile::write($cacheFiles['meta'], (string) $sniffer); } return $content; } } //fetch metas from cache : if (file_exists($cacheFiles['meta'])) { if (filesize($cacheFiles['meta']) > 0) { //create an anonymous function and then unset it. if jZone cache is cleared within 2 calls in a single //request, this should still work fine $metaFunct = create_function('$resp', file_get_contents($cacheFiles['meta'])); $metaFunct(jApp::coord()->response); unset($metaFunct); } } else { //the cache does not exist yet for this response type. We have to generate it ! $response = jApp::coord()->response; $sniffer = new jMethodSniffer($response, '$resp', array('getType', 'getFormatType'), true); jApp::coord()->response = $sniffer; $this->_createContent(); jApp::coord()->response = $response; if (!$this->_cancelCache) { jFile::write($cacheFiles['meta'], (string) $sniffer); } } //and now fetch content from cache : $content = file_get_contents($f); } else { $this->_cancelCache = false; $response = jApp::coord()->response; $sniffer = new jMethodSniffer($response, '$resp', array('getType', 'getFormatType'), true); jApp::coord()->response = $sniffer; $content = $this->_createContent(); jApp::coord()->response = $response; if (!$this->_cancelCache) { jFile::write($f, $content); jFile::write($cacheFiles['meta'], (string) $sniffer); } } } else { $content = $this->_createContent(); } return $content; }
public function compile($aSelector) { global $gJCoord; $sourceFile = $aSelector->getPath(); $cachefile = $aSelector->getCompiledFilePath(); // lecture du fichier xml $xml = simplexml_load_file($sourceFile); if (!$xml) { return false; } /* <urls> <classicentrypoint name="index" default="true"> <url pathinfo="/test/:mois/:annee" module="" action=""> <param name="mois" escape="true" regexp="\d{4}"/> <param name="annee" escape="false" /> <static name="bla" value="cequejeveux" /> </url> <url handler="" module="" action="" /> </classicentrypoint> </urls> génère dans un fichier propre à chaque entrypoint : $PARSE_URL = array($isDefault , $infoparser,$infoparser... ) où $isDefault : indique si c'est un point d'entrée par défaut, et donc si le parser ne trouve rien, si il ignore ou fait une erreur $infoparser = array('module','action','selecteur handler') ou $infoparser = array( 'module','action', 'regexp_pathinfo', array('annee','mois'), // tableau des valeurs dynamiques, classées par ordre croissant array(true, false), // tableau des valeurs escapes array('bla'=>'cequejeveux' ) // tableau des valeurs statiques ) génère dans un fichier commun à tous : $CREATE_URL = array( 'news~show@classic' => 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 array('bla'=>'cequejeveux' ) // tableau des valeurs statiques, pour comparer quand il y a plusieurs urls vers la même action ) quand il y a plusieurs urls vers la même action, il y a plutôt un tableau contenant plusieurs tableaux du type précédent array( 4, array(1,...), array(1,...)...) 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" */ $typeparam = array('string' => '([^\\/]+)', 'char' => '([^\\/])', 'letter' => '(\\w)', 'number' => '(\\d+)', 'int' => '(\\d+)', 'integer' => '(\\d+)', 'digit' => '(\\d)', 'date' => '([0-2]\\d{3}\\-(?:0[1-9]|1[0-2])\\-(?:[0-2][1-9]|3[0-1]))', 'year' => '([0-2]\\d{3})', 'month' => '(0[1-9]|1[0-2])', 'day' => '([0-2][1-9]|[1-2]0|3[0-1])'); $createUrlInfos = array(); $createUrlContent = "<?php \n"; $defaultEntrypoints = array(); foreach ($xml->children() as $name => $tag) { if (!preg_match("/^(.*)entrypoint\$/", $name, $m)) { //TODO : erreur continue; } $requestType = $m[1]; $entryPoint = (string) $tag['name']; $isDefault = isset($tag['default']) ? (string) $tag['default'] == 'true' : false; $isHttps = isset($tag['https']) ? (string) $tag['https'] == 'true' : false; $generatedentrypoint = $entryPoint; if (isset($tag['noentrypoint']) && (string) $tag['noentrypoint'] == 'true') { $generatedentrypoint = ''; } $parseInfos = array($isDefault); // si c'est le point d'entrée par défaut pour le type de requet indiqué // alors on indique une regle supplementaire que matcherons // toutes les urls qui ne correspondent pas aux autres rêgles if ($isDefault) { $createUrlInfos['@' . $requestType] = array(2, $entryPoint, $isHttps); } $parseContent = "<?php \n"; foreach ($tag->url as $url) { $module = (string) $url['module']; if (isset($url['https'])) { $urlhttps = (string) $url['https'] == 'true'; } else { $urlhttps = $isHttps; } if (isset($url['noentrypoint']) && (string) $url['noentrypoint'] == 'true') { $urlep = ''; } else { $urlep = $generatedentrypoint; } // dans le cas d'un point d'entrée qui n'est pas celui par défaut pour le type de requete indiqué // si il y a juste un module indiqué alors on sait que toutes les actions // concernant ce module passeront par ce point d'entrée. if (!$isDefault && !isset($url['action']) && !isset($url['handler'])) { $parseInfos[] = array($module, '', '/.*/', array(), array(), array(), false); $createUrlInfos[$module . '~*@' . $requestType] = array(3, $urlep, $urlhttps); continue; } $action = (string) $url['action']; if (strpos($action, ':') === false) { $action = 'default:' . $action; } if (isset($url['actionoverride'])) { $actionOverride = preg_split("/[\\s,]+/", (string) $url['actionoverride']); foreach ($actionOverride as &$each) { if (strpos($each, ':') === false) { $each = 'default:' . $each; } } } else { $actionOverride = false; } // si il y a un handler indiqué, on sait alors que pour le module et action indiqué // il faut passer par cette classe handler pour le parsing et la creation de l'url if (isset($url['handler'])) { $class = (string) $url['handler']; // il faut absolument un nom de module dans le selecteur, car lors de l'analyse de l'url // dans le request, il n'y a pas de module connu dans le context (normal...) $p = strpos($class, '~'); if ($p === false) { $selclass = $module . '~' . $class; } elseif ($p == 0) { $selclass = $module . $class; } else { $selclass = $class; } $s = new jSelectorUrlHandler($selclass); if (!isset($url['action'])) { $action = '*'; } $createUrlContent .= "include_once('" . $s->getPath() . "');\n"; $parseInfos[] = array($module, $action, $selclass, $actionOverride); $createUrlInfos[$module . '~' . $action . '@' . $requestType] = array(0, $urlep, $urlhttps, $selclass); if ($actionOverride) { foreach ($actionOverride as $ao) { $createUrlInfos[$module . '~' . $ao . '@' . $requestType] = array(0, $urlep, $urlhttps, $selclass); } } continue; } $listparam = array(); $escapes = array(); if (isset($url['pathinfo'])) { $path = (string) $url['pathinfo']; $regexppath = $path; if (preg_match_all("/\\:([a-zA-Z_]+)/", $path, $m, PREG_PATTERN_ORDER)) { $listparam = $m[1]; foreach ($url->param as $var) { $nom = (string) $var['name']; $k = array_search($nom, $listparam); if ($k === false) { // TODO error continue; } if (isset($var['escape'])) { $escapes[$k] = (string) $var['escape'] == 'true'; } else { $escapes[$k] = false; } if (isset($var['type'])) { if (isset($typeparam[(string) $var['type']])) { $regexp = $typeparam[(string) $var['type']]; } else { $regexp = '([^\\/]+)'; } } else { if (isset($var['regexp'])) { $regexp = '(' . (string) $var['regexp'] . ')'; } else { $regexp = '([^\\/]+)'; } } $regexppath = str_replace(':' . $nom, $regexp, $regexppath); } foreach ($listparam as $k => $name) { if (isset($escapes[$k])) { continue; } $escapes[$k] = false; $regexppath = str_replace(':' . $name, '([^\\/]+)', $regexppath); } } } else { $regexppath = '.*'; $path = ''; } if (isset($url['optionalTrailingSlash']) && $url['optionalTrailingSlash'] == 'true') { if (substr($regexppath, -1) == '/') { $regexppath .= '?'; } else { $regexppath .= '\\/?'; } } $liststatics = array(); foreach ($url->static as $var) { $liststatics[(string) $var['name']] = (string) $var['value']; } $parseInfos[] = array($module, $action, '!^' . $regexppath . '$!', $listparam, $escapes, $liststatics, $actionOverride); $cuisel = $module . '~' . $action . '@' . $requestType; $arr = array(1, $urlep, $urlhttps, $listparam, $escapes, $path, false, $liststatics); if (isset($createUrlInfos[$cuisel])) { if ($createUrlInfos[$cuisel][0] == 4) { $createUrlInfos[$cuisel][] = $arr; } else { $createUrlInfos[$cuisel] = array(4, $createUrlInfos[$cuisel], $arr); } } else { $createUrlInfos[$cuisel] = $arr; } if ($actionOverride) { foreach ($actionOverride as $ao) { $cuisel = $module . '~' . $ao . '@' . $requestType; $arr = array(1, $urlep, $urlhttps, $listparam, $escapes, $path, true, $liststatics); if (isset($createUrlInfos[$cuisel])) { if ($createUrlInfos[$cuisel][0] == 4) { $createUrlInfos[$cuisel][] = $arr; } else { $createUrlInfos[$cuisel] = array(4, $createUrlInfos[$cuisel], $arr); } } else { $createUrlInfos[$cuisel] = $arr; } } } } $parseContent .= '$GLOBALS[\'SIGNIFICANT_PARSEURL\'][\'' . rawurlencode($entryPoint) . '\'] = ' . var_export($parseInfos, true) . ";\n?>"; jFile::write(JELIX_APP_TEMP_PATH . 'compiled/urlsig/' . $aSelector->file . '.' . rawurlencode($entryPoint) . '.entrypoint.php', $parseContent); } $createUrlContent .= '$GLOBALS[\'SIGNIFICANT_CREATEURL\'] =' . var_export($createUrlInfos, true) . ";\n?>"; jFile::write(JELIX_APP_TEMP_PATH . 'compiled/urlsig/' . $aSelector->file . '.creationinfos.php', $createUrlContent); return true; }
public function endCompile($cachefile) { $content = '<?php return ' . var_export($this->eventList, true) . ";\n?>"; \jFile::write($cachefile, $content); }