public function _connect() { if (isset($this->_profile['storage_dir']) && $this->_profile['storage_dir'] != '') { $this->_storage_dir = str_replace(array('var:', 'temp:'), array(jApp::varPath(), jApp::tempPath()), $this->_profile['storage_dir']); $this->_storage_dir = rtrim($this->_storage_dir, '\\/') . DIRECTORY_SEPARATOR; } else { $this->_storage_dir = jApp::varPath('kvfiles/'); } jFile::createDir($this->_storage_dir); if (isset($this->_profile['file_locking'])) { $this->_file_locking = $this->_profile['file_locking'] ? true : false; } if (isset($this->_profile['automatic_cleaning_factor'])) { $this->automatic_cleaning_factor = $this->_profile['automatic_cleaning_factor']; } if (isset($this->_profile['directory_level']) && $this->_profile['directory_level'] > 0) { $this->_directory_level = $this->_profile['directory_level']; if ($this->_directory_level > 16) { $this->_directory_level = 16; } } if (isset($this->_profile['directory_umask']) && is_string($this->_profile['directory_umask']) && $this->_profile['directory_umask'] != '') { $this->_directory_umask = octdec($this->_profile['directory_umask']); } if (isset($this->_profile['file_umask']) && is_string($this->_profile['file_umask']) && $this->_profile['file_umask'] != '') { $this->file_umask = octdec($this->_profile['file_umask']); } }
function check() { if (isset($_FILES[$this->ref])) { $this->fileInfo = $_FILES[$this->ref]; } else { $this->fileInfo = array('name' => '', 'type' => '', 'size' => 0, 'tmp_name' => '', 'error' => UPLOAD_ERR_NO_FILE); } if ($this->fileInfo['error'] == UPLOAD_ERR_NO_FILE) { if ($this->required) { return $this->container->errors[$this->ref] = jForms::ERRDATA_REQUIRED; } } else { if ($this->fileInfo['error'] != UPLOAD_ERR_OK || !is_uploaded_file($this->fileInfo['tmp_name'])) { return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID; } if ($this->maxsize && $this->fileInfo['size'] > $this->maxsize) { return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID; } if (count($this->mimetype)) { $this->fileInfo['type'] = jFile::getMimeType($this->fileInfo['tmp_name']); if (!in_array($this->fileInfo['type'], $this->mimetype)) { return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID; } } } return null; }
public function run() { $this->loadAppConfig(); $config = jApp::config(); $model_lang = $this->getParam('model_lang', $config->locale); $lang = $this->getParam('lang'); foreach ($config->_modulesPathList as $module => $dir) { $source_dir = $dir . 'locales/' . $model_lang . '/'; if (!file_exists($source_dir)) { continue; } $target_dir = jApp::varPath('overloads/' . $module . '/locales/' . $lang . '/'); jFile::createDir($target_dir); if ($dir_r = opendir($source_dir)) { while (FALSE !== ($fich = readdir($dir_r))) { if ($fich != "." && $fich != ".." && is_file($source_dir . $fich) && strpos($fich, '.' . $config->charset . '.properties') && !file_exists($target_dir . $fich)) { copy($source_dir . $fich, $target_dir . $fich); if ($this->verbose()) { echo "Copy Locales file {$fich} from {$source_dir} to {$target_dir}.\n"; } } } closedir($dir_r); } } }
protected function _execute(InputInterface $input, OutputInterface $output) { $config = App::config(); $model_lang = $input->getArgument('model_lang'); if (!$model_lang) { $model_lang = $config->locale; } $lang = $input->getArgument('lang'); foreach ($config->_modulesPathList as $module => $dir) { $source_dir = $dir . 'locales/' . $model_lang . '/'; if (!file_exists($source_dir)) { continue; } if ($input->getOption('to-overload')) { $target_dir = App::appPath('app/overloads/' . $module . '/locales/' . $lang . '/'); } else { $target_dir = App::appPath('app/locales/' . $lang . '/' . $module . '/locales/'); } \jFile::createDir($target_dir); if ($dir_r = opendir($source_dir)) { while (FALSE !== ($fich = readdir($dir_r))) { if ($fich != "." && $fich != ".." && is_file($source_dir . $fich) && strpos($fich, '.' . $config->charset . '.properties') && !file_exists($target_dir . $fich)) { copy($source_dir . $fich, $target_dir . $fich); if ($this->verbose()) { $output->writeln("Copy Locales file {$fich} from {$source_dir} to {$target_dir}."); } } } closedir($dir_r); } } }
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 run() { try { $tempPath = jApp::tempBasePath(); if ($tempPath == DIRECTORY_SEPARATOR || $tempPath == '' || $tempPath == '/') { echo "Error: bad path in jApp::tempBasePath(), it is equals to '" . $tempPath . "' !!\n"; echo " Jelix cannot clear the content of the temp directory.\n"; echo " Correct the path in your application.init.php or create the corresponding directory\n"; exit(1); } if (!jFile::removeDir($tempPath, false, array('.svn', '.dummy'))) { echo "Some temp files were not removed\n"; } else { if ($this->verbose()) { echo "All temp files have been removed\n"; } } } catch (Exception $e) { if ($this->config->helpLang == 'fr') { echo "Un ou plusieurs répertoires n'ont pas pu être supprimés.\n" . "Message d'erreur : " . $e->getMessage() . "\n"; } else { echo "One or more directories couldn't be deleted.\n" . "Error: " . $e->getMessage() . "\n"; } } }
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; }
function atStart($config) { if ($config->sessions['storage'] == 'files') { $config->sessions['files_path'] = jFile::parseJelixPath($config->sessions['files_path']); } $config->sessions['_class_to_load'] = array(); if ($config->sessions['loadClasses'] != '') { trigger_error("Configuration: loadClasses is deprecated, use instead autoload configuration in jelix-module.json or module.xml files", E_USER_NOTICE); $list = preg_split('/ *, */', $config->sessions['loadClasses']); foreach ($list as $sel) { if (preg_match("/^([a-zA-Z0-9_\\.]+)~([a-zA-Z0-9_\\.\\/]+)\$/", $sel, $m)) { if (!isset($config->_modulesPathList[$m[1]])) { throw new Exception('Error in the configuration file -- in loadClasses parameter, ' . $m[1] . ' is not a valid or activated module'); } if (($p = strrpos($m[2], '/')) !== false) { $className = substr($m[2], $p + 1); $subpath = substr($m[2], 0, $p + 1); } else { $className = $m[2]; $subpath = ''; } $path = $config->_modulesPathList[$m[1]] . 'classes/' . $subpath . $className . '.class.php'; if (!file_exists($path) || strpos($subpath, '..') !== false) { throw new Exception('Error in the configuration file -- in loadClasses parameter, bad class selector: ' . $sel); } $config->sessions['_class_to_load'][] = $path; } else { throw new Exception('Error in the configuration file -- in loadClasses parameter, bad class selector: ' . $sel); } } } }
/** * 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; }
function check() { if (isset($_FILES[$this->ref])) { $this->fileInfo = $_FILES[$this->ref]; } else { $this->fileInfo = array('name' => '', 'type' => '', 'size' => 0, 'tmp_name' => '', 'error' => UPLOAD_ERR_NO_FILE); } if ($this->fileInfo['error'] == UPLOAD_ERR_NO_FILE) { if ($this->required) { return $this->container->errors[$this->ref] = jForms::ERRDATA_REQUIRED; } } else { if ($this->fileInfo['error'] == UPLOAD_ERR_NO_TMP_DIR || $this->fileInfo['error'] == UPLOAD_ERR_CANT_WRITE) { return $this->container->errors[$this->ref] = jForms::ERRDATA_FILE_UPLOAD_ERROR; } if ($this->fileInfo['error'] == UPLOAD_ERR_INI_SIZE || $this->fileInfo['error'] == UPLOAD_ERR_FORM_SIZE || $this->maxsize && $this->fileInfo['size'] > $this->maxsize) { return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID_FILE_SIZE; } if ($this->fileInfo['error'] == UPLOAD_ERR_PARTIAL || !is_uploaded_file($this->fileInfo['tmp_name'])) { return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID; } if (count($this->mimetype)) { $this->fileInfo['type'] = jFile::getMimeType($this->fileInfo['tmp_name']); if ($this->fileInfo['type'] == 'application/octet-stream') { // let's try with the name $this->fileInfo['type'] = jFile::getMimeTypeFromFilename($this->fileInfo['name']); } if (!in_array($this->fileInfo['type'], $this->mimetype)) { return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID_FILE_TYPE; } } } return null; }
/** * set * * @param string $key a key (unique name) to identify the cached info * @param mixed $value the value to cache * @param integer $ttl how many seconds will the info be cached * * @return boolean whether the action was successful or not */ public function set($key, $value, $ttl) { $r = false; if ($fl = @fopen($this->dir . '/.flock', 'w+')) { if (flock($fl, LOCK_EX)) { // mutex zone $md5 = md5($key); $subdir = $md5[0] . $md5[1]; if (!file_exists($this->dir . '/' . $subdir)) { jFile::createDir($this->dir . '/' . $subdir); } // write data to cache $fn = $this->dir . '/' . $subdir . '/' . $md5; if ($f = @gzopen($fn . '.tmp', 'w')) { // write temporary file fputs($f, base64_encode(serialize($value))); fclose($f); // change time of the file to the expiry time @touch("{$fn}.tmp", time() + $ttl); // rename the temporary file $r = @rename("{$fn}.tmp", $fn); } // end of mutex zone flock($fl, LOCK_UN); } } return $r; }
protected function loadProfile() { try { jProfiles::get('jcache', 'jforms', true); } catch (Exception $e) { // no profile, let's create a default profile $cacheDir = jApp::tempPath('jforms'); jFile::createDir($cacheDir); $params = array('enabled' => 1, 'driver' => 'file', 'ttl' => 3600 * 48, 'automatic_cleaning_factor' => 3, 'cache_dir' => $cacheDir, 'directory_level' => 3); jProfiles::createVirtualProfile('jcache', 'jforms', $params); } }
function clear() { $confirm = $this->param('confirm'); if ($confirm == 'Y') { jFile::removeDir(jApp::tempPath(), false); jMessage::add(jLocale::get('jelixcache~jelixcache.cache.clear.done')); } else { jMessage::add(jLocale::get('jelixcache~jelixcache.cache.clear.canceled')); } $rep = $this->getResponse('redirect'); $rep->action = 'jelixcache~default:index'; return $rep; }
/** * Let use one of the available theme */ function useit() { $theme = (string) $this->param('theme'); $mainConfig = new jIniFileModifier(jApp::configPath() . 'defaultconfig.ini.php'); $mainConfig->setValue('theme', strtolower($theme)); $mainConfig->setValue('datepicker', strtolower($theme), 'forms'); $mainConfig->save(); jFile::removeDir(jApp::tempPath(), false); jMessage::add(jLocale::get('theme.selected'), 'information'); $rep = $this->getResponse('redirect'); $rep->action = 'default:index'; return $rep; }
public static function clearTemp() { if (!defined('JELIX_APP_TEMP_PATH')) { echo "Error: JELIX_APP_TEMP_PATH is not defined\n"; exit(1); } if (JELIX_APP_TEMP_PATH == DIRECTORY_SEPARATOR || JELIX_APP_TEMP_PATH == '' || JELIX_APP_TEMP_PATH == '/') { echo "Error: bad path in JELIX_APP_TEMP_PATH, it is equals to '" . JELIX_APP_TEMP_PATH . "' !!\n"; echo " Jelix cannot clear the content of the temp directory.\n"; echo " Correct the path in JELIX_APP_TEMP_PATH or create the directory you\n"; echo " indicated into JELIX_APP_TEMP_PATH.\n"; exit(1); } jFile::removeDir(JELIX_APP_TEMP_PATH, false); }
protected function _connect() { $funcconnect = isset($this->profile['persistent']) && $this->profile['persistent'] ? 'sqlite_popen' : 'sqlite_open'; $db = $this->profile['database']; if (preg_match('/^(app|lib|var)\\:/', $db)) { $path = jFile::parseJelixPath($db); } else { $path = jApp::varPath('db/sqlite/' . $db); } if ($cnx = @$funcconnect($path)) { return $cnx; } else { throw new jException('jelix~db.error.connection', $db); } }
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; }
public function run() { try { jFile::removeDir(JELIX_APP_TEMP_PATH, false); jFile::removeDir(JELIX_APP_REAL_TEMP_PATH, false); if (defined('JELIX_APP_TEMP_CLI_PATH')) { jFile::removeDir(JELIX_APP_TEMP_CLI_PATH, false); } } catch (Exception $e) { if (MESSAGE_LANG == 'fr') { echo "Un ou plusieurs répertoires n'ont pas pu être supprimés.\n" . "Message d'erreur : " . $e->getMessage() . "\n"; } else { echo "One or more directories couldn't be deleted.\n" . "Error: " . $e->getMessage() . "\n"; } } }
public function run() { try { if (!defined('JELIX_APP_TEMP_PATH')) { echo "Error: JELIX_APP_TEMP_PATH is not defined\n"; exit(1); } if (JELIX_APP_TEMP_PATH == DIRECTORY_SEPARATOR || JELIX_APP_TEMP_PATH == '' || JELIX_APP_TEMP_PATH == '/') { echo "Error: bad path in JELIX_APP_TEMP_PATH, it is equals to '" . JELIX_APP_TEMP_PATH . "' !!\n"; echo " Jelix cannot clear the content of the temp directory.\n"; echo " Correct the path in JELIX_APP_TEMP_PATH or create the directory you\n"; echo " indicated into JELIX_APP_TEMP_PATH.\n"; exit(1); } jFile::removeDir(JELIX_APP_TEMP_PATH, false); if (!defined('JELIX_APP_REAL_TEMP_PATH')) { echo "Error: JELIX_APP_REAL_TEMP_PATH is not defined\n"; exit(1); } if (JELIX_APP_REAL_TEMP_PATH == DIRECTORY_SEPARATOR || JELIX_APP_REAL_TEMP_PATH == '' || JELIX_APP_REAL_TEMP_PATH == '/') { echo "Error: bad path in JELIX_APP_REAL_TEMP_PATH, it is equals to '" . JELIX_APP_REAL_TEMP_PATH . "' !!\n"; echo " Jelix cannot clear the content of the temp directory.\n"; echo " Correct the path in JELIX_APP_REAL_TEMP_PATH or create the directory you\n"; echo " indicated into JELIX_APP_REAL_TEMP_PATH.\n"; exit(1); } jFile::removeDir(JELIX_APP_REAL_TEMP_PATH, false); if (defined('JELIX_APP_TEMP_CLI_PATH')) { if (JELIX_APP_TEMP_CLI_PATH == DIRECTORY_SEPARATOR || JELIX_APP_TEMP_CLI_PATH == '' || JELIX_APP_TEMP_CLI_PATH == '/') { echo "Error: bad path in JELIX_APP_TEMP_CLI_PATH, it is equals to '" . JELIX_APP_TEMP_CLI_PATH . "' !!\n"; echo " Jelix cannot clear the content of the temp directory.\n"; echo " Correct the path in JELIX_APP_TEMP_CLI_PATH or create the directory you\n"; echo " indicated into JELIX_APP_TEMP_CLI_PATH.\n"; exit(1); } jFile::removeDir(JELIX_APP_TEMP_CLI_PATH, false); } } catch (Exception $e) { if (MESSAGE_LANG == 'fr') { echo "Un ou plusieurs répertoires n'ont pas pu être supprimés.\n" . "Message d'erreur : " . $e->getMessage() . "\n"; } else { echo "One or more directories couldn't be deleted.\n" . "Error: " . $e->getMessage() . "\n"; } } }
public static function clearTemp($path = '') { if ($path == '') { $path = jApp::tempBasePath(); if ($path == '') { throw new Exception("default temp base path is not defined", 1); } } if ($path == DIRECTORY_SEPARATOR || $path == '' || $path == '/') { throw new Exception('given temp path is invalid', 2); } if (!file_exists($path)) { throw new Exception('given temp path does not exists', 3); } if (!is_writeable($path)) { throw new Exception('given temp path does not exists', 4); } jFile::removeDir($path, false); }
public function getfile() { $module = $this->param('targetmodule'); if (!jApp::isModuleEnabled($module) || jApp::config()->modules[$module . '.access'] < 2) { throw new jException('jelix~errors.module.untrusted', $module); } $rep = $this->getResponse('binary'); $rep->doDownload = false; $dir = jApp::getModulePath($module) . 'www/'; $rep->fileName = realpath($dir . str_replace('..', '', $this->param('file'))); if (!is_file($rep->fileName)) { $rep = $this->getResponse('html', true); $rep->bodyTpl = 'jelix~404.html'; $rep->setHttpStatus('404', 'Not Found'); return $rep; } $rep->mimeType = jFile::getMimeTypeFromFilename($rep->fileName); return $rep; }
public static function readAndCache($configFile, $isCli = null, $pseudoScriptName = '') { if ($isCli === null) { $isCli = jServer::isCLI(); } $config = self::read($configFile, false, $isCli, $pseudoScriptName); $tempPath = jApp::tempPath(); jFile::createDir($tempPath); if (BYTECODE_CACHE_EXISTS) { $filename = $tempPath . str_replace('/', '~', $configFile) . '.conf.php'; if ($f = @fopen($filename, 'wb')) { fwrite($f, '<?php $config = ' . var_export(get_object_vars($config), true) . ";\n?>"); fclose($f); } else { throw new Exception('Error while writing configuration cache file -- ' . $filename); } } else { jIniFile::write(get_object_vars($config), $tempPath . str_replace('/', '~', $configFile) . '.resultini.php', ";<?php die('');?>\n"); } return $config; }
public function set($key, $value, $ttl) { $r = false; if ($fl = @fopen($this->dir . '/.flock', 'w+')) { if (flock($fl, LOCK_EX)) { $md5 = md5($key); $subdir = $md5[0] . $md5[1]; if (!file_exists($this->dir . '/' . $subdir)) { jFile::createDir($this->dir . '/' . $subdir); } $fn = $this->dir . '/' . $subdir . '/' . $md5; if ($f = @gzopen($fn . '.tmp', 'w')) { fputs($f, base64_encode(serialize($value))); fclose($f); @touch("{$fn}.tmp", time() + $ttl); $r = @rename("{$fn}.tmp", $fn); } flock($fl, LOCK_UN); } } return $r; }
/** * 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 __construct($params) { $this->profil_name = $params['_name']; if (isset($params['enabled'])) { $this->enabled = $params['enabled'] ? true : false; } if (isset($params['ttl'])) { $this->ttl = $params['ttl']; } $this->_cache_dir = jApp::tempPath('cache/') . $this->profil_name . '/'; if (isset($params['cache_dir']) && $params['cache_dir'] != '') { if (is_dir($params['cache_dir']) && is_writable($params['cache_dir'])) { $this->_cache_dir = rtrim(realpath($params['cache_dir']), '\\/') . DIRECTORY_SEPARATOR; } else { throw new jException('jelix~cache.directory.not.writable', $this->profil_name); } } else { jFile::createDir($this->_cache_dir); } if (isset($params['file_locking'])) { $this->_file_locking = $params['file_locking'] ? true : false; } if (isset($params['automatic_cleaning_factor'])) { $this->automatic_cleaning_factor = $params['automatic_cleaning_factor']; } if (isset($params['directory_level']) && $params['directory_level'] > 0) { $this->_directory_level = $params['directory_level']; } if (isset($params['directory_umask']) && is_string($params['directory_umask']) && $params['directory_umask'] != '') { $this->_directory_umask = octdec($params['directory_umask']); } if (isset($params['file_name_prefix'])) { $this->_file_name_prefix = $params['file_name_prefix']; } if (isset($params['cache_file_umask']) && is_string($params['cache_file_umask']) && $params['cache_file_umask'] != '') { $this->_cache_file_umask = octdec($params['cache_file_umask']); } }
protected function _connect() { $funcconnect = isset($this->profile['persistent']) && $this->profile['persistent'] ? 'sqlite_popen' : 'sqlite_open'; $db = $this->profile['database']; if (preg_match('/^(app|lib|var)\\:/', $db)) { $path = jFile::parseJelixPath($db); } else { if ($db[0] == '/' || preg_match('!^[a-z]\\:(\\\\|/)[a-z]!i', $db)) { if (file_exists($db) || file_exists(dirname($db))) { $path = $db; } else { throw new Exception('sqlite connector: unknown database path scheme'); } } else { $path = jApp::varPath('db/sqlite/' . $db); } } if ($cnx = @$funcconnect($path)) { return $cnx; } else { throw new jException('jelix~db.error.connection', $db); } }
protected function execute(InputInterface $input, OutputInterface $output) { try { $tempPath = \Jelix\Core\App::tempBasePath(); if ($tempPath == DIRECTORY_SEPARATOR || $tempPath == '' || $tempPath == '/') { $output->writeln("<error>Error: bad path in jApp::tempBasePath(), it is equals to '" . $tempPath . "' !!</error>"); $output->writeln(" Jelix cannot clear the content of the temp directory."); $output->writeln(" Correct the path in your application.init.php or create the corresponding directory"); return 1; } if (!\jFile::removeDir($tempPath, false, array('.svn', '.git', '.dummy'))) { $output->writeln("Some temp files were not removed"); } else { if ($output->isVerbose()) { $output->writeln("All temp files have been removed"); } } } catch (\Exception $e) { $output->writeln("One or more directories couldn't be deleted."); $output->writeln("<error>Error: " . $e->getMessage() . "</error>"); return 2; } }
protected function _connect() { $db = $this->profile['database']; if (preg_match('/^(app|lib|var|temp|www)\\:/', $db)) { $path = jFile::parseJelixPath($db); } else { if ($db[0] == '/' || preg_match('!^[a-z]\\:(\\\\|/)[a-z]!i', $db)) { if (file_exists($db) || file_exists(dirname($db))) { $path = $db; } else { throw new Exception('sqlite3 connector: unknown database path scheme'); } } else { $path = jApp::varPath('db/sqlite3/' . $db); } } $sqlite = new SQLite3($path); // Load extensions if needed if (isset($this->profile['extensions'])) { $list = preg_split('/ *, */', $this->profile['extensions']); foreach ($list as $ext) { try { $sqlite->loadExtension($ext); } catch (Exception $e) { throw new Exception('sqlite3 connector: error while loading sqlite extension ' . $ext); } } } // set timeout if (isset($this->profile['busytimeout'])) { $timeout = intval($this->profile['busytimeout']); if ($timeout) { $sqlite->busyTimeout($timeout); } } return $sqlite; }
/** * returns html formated stack trace * @param array $trace * @return string */ function formatTrace($trace) { $html = '<table>'; foreach ($trace as $k => $t) { if (isset($t['file'])) { $file = $t['file']; $path = jFile::unparseJelixPath($file, '<i>', '</i>'); } else { $file = '[php]'; } $html .= '<tr><td>' . $k . '</td><td>' . (isset($t['class']) ? $t['class'] . $t['type'] : '') . $t['function'] . '()</td>'; $html .= '<td>' . $file . '</td><td>' . (isset($t['line']) ? $t['line'] : '') . '</td></tr>'; } $html .= '</table>'; return $html; }