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']); } }
/** * initialize some member */ function __construct() { $config = jApp::config(); $this->defaultLang = $config->locale; $this->CharSet = $config->charset; $this->Mailer = $config->mailer['mailerType']; if ($config->mailer['mailerType']) { $this->Mailer = $config->mailer['mailerType']; } $this->Hostname = $config->mailer['hostname']; $this->Sendmail = $config->mailer['sendmailPath']; $this->Host = $config->mailer['smtpHost']; $this->Port = $config->mailer['smtpPort']; $this->Helo = $config->mailer['smtpHelo']; $this->SMTPAuth = $config->mailer['smtpAuth']; $this->SMTPSecure = $config->mailer['smtpSecure']; $this->Username = $config->mailer['smtpUsername']; $this->Password = $config->mailer['smtpPassword']; $this->Timeout = $config->mailer['smtpTimeout']; if ($config->mailer['webmasterEmail'] != '') { $this->From = $config->mailer['webmasterEmail']; } $this->FromName = $config->mailer['webmasterName']; $this->filePath = jApp::varPath($config->mailer['filesDir']); $this->copyToFiles = $config->mailer['copyToFiles']; parent::__construct(true); }
public function testFileMail() { //if (file_exists(jApp::varPath().'mails/mail.txt')) // unlink(jApp::varPath().'mails/mail.txt'); $mail = new testJMailer(); $mail->From = '*****@*****.**'; $mail->FromName = 'Super Me'; $mail->Sender = '*****@*****.**'; $mail->Subject = 'Email test'; $mail->Body = 'This is a test mail'; $mail->AddAddress('*****@*****.**'); $mail->AddAddress('*****@*****.**'); $mail->IsFile(); $mail->Send(); $this->assertEqual(jApp::varPath() . 'mails/', $mail->filePath); $this->assertEqual(jApp::varPath() . 'mails/mail.txt', $mail->getStorageFile2()); if ($this->assertTrue(file_exists(jApp::varPath() . 'mails/mail.txt'))) { $content = file_get_contents(jApp::varPath() . 'mails/mail.txt'); $this->assertTrue(strpos($content, 'Return-Path: toto@truc.com') !== false); $this->assertTrue(strpos($content, 'To: titi@machin.local, toto@machin.local') !== false); $this->assertTrue(strpos($content, 'From: Super Me <*****@*****.**>') !== false); $this->assertTrue(strpos($content, 'Subject: Email test') !== false); $this->assertTrue(strpos($content, 'Content-Transfer-Encoding: 8bit') !== false); $this->assertTrue(strpos($content, 'Content-Type: text/plain; charset="UTF-8"') !== false); $this->assertTrue(strpos($content, 'This is a test mail') !== false); } }
protected function _createPath() { if (!isset(jApp::config()->_modulesPathList[$this->module])) { throw new jExceptionSelector('jelix~errors.selector.module.unknown', $this->toString()); } // check if the dao was redefined (overloaded) in var/ $overloadedPath = jApp::varPath('overloads/' . $this->module . '/' . $this->_dirname . $this->resource . $this->_suffix); if (is_readable($overloadedPath)) { $this->_path = $overloadedPath; $this->_where = 'var/'; return; } // check if the dao was redefined (overloaded) in app/ $overloadedPath = jApp::appPath('app/overloads/' . $this->module . '/' . $this->_dirname . $this->resource . $this->_suffix); if (is_readable($overloadedPath)) { $this->_path = $overloadedPath; $this->_where = 'app/'; return; } // else check if the module exists in the current module $this->_path = jApp::config()->_modulesPathList[$this->module] . $this->_dirname . $this->resource . $this->_suffix; if (!is_readable($this->_path)) { throw new jExceptionSelector('jelix~errors.selector.invalid.target', array($this->toString(), "dao")); } $this->_where = 'modules/'; }
protected function _createPath() { if (!isset(jApp::config()->_modulesPathList[$this->module])) { throw new jExceptionSelector('jelix~errors.selector.module.unknown', $this->toString(true)); } // we see if the forms have been redefined in var/ $overloadedPath = jApp::varPath('overloads/' . $this->module . '/' . $this->_dirname . $this->resource . $this->_suffix); if (is_readable($overloadedPath)) { $this->_path = $overloadedPath; $this->_where = 'var/'; return; } // we see if the forms have been redefined in app/ $overloadedPath = jApp::appPath('app/overloads/' . $this->module . '/' . $this->_dirname . $this->resource . $this->_suffix); if (is_readable($overloadedPath)) { $this->_path = $overloadedPath; $this->_where = 'app/'; return; } $this->_path = jApp::config()->_modulesPathList[$this->module] . $this->_dirname . $this->resource . $this->_suffix; if (!is_readable($this->_path)) { throw new jExceptionSelector('jelix~errors.selector.invalid.target', array($this->toString(), $this->type)); } $this->_where = 'modules/'; }
/** * display the RSS of the forum */ public function read_rss() { $ftitle = jUrl::escape($this->param('ftitle'), true); $id_forum = (int) $this->param('id_forum'); if (!jAcl2::check('hfnu.posts.list', 'forum' . $id_forum)) { $rep = $this->getResponse('redirect'); $rep->action = 'default:index'; return $rep; } if ($id_forum == 0) { $rep = $this->getResponse('redirect'); $rep->action = 'default:index'; return $rep; } $forum = jClasses::getService('havefnubb~hfnuforum')->getForum($id_forum); if (jUrl::escape($forum->forum_name, true) != $ftitle) { $rep = $this->getResponse('redirect'); $rep->action = jApp::config()->urlengine['notfoundAct']; return $rep; } jApp::coord()->getPlugin('history')->change('label', htmlentities($forum->forum_name, ENT_COMPAT, 'UTF-8')); $feed_reader = new jFeedReader(); $feed_reader->setCacheDir(jApp::varPath('feeds')); $feed_reader->setTimeout(2); $feed_reader->setUserAgent('HaveFnuBB - http://www.havefnubb.org/'); $feed = $feed_reader->parse($forum->forum_url); $rep = $this->getResponse('html'); $tpl = new jTpl(); $tpl->assign('feed', $feed); $tpl->assign('forum', $forum); $rep->title = $forum->forum_name; $rep->body->assign('MAIN', $tpl->fetch('havefnubb~forum_rss.view')); return $rep; }
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); } } }
function __construct($profile) { $this->profile = $profile; $prof = $profile; $user = ''; $password = ''; $dsn = ''; if (isset($profile['dsn'])) { $this->dbms = substr($profile['dsn'], 0, strpos($profile['dsn'], ':')); $dsn = $profile['dsn']; unset($prof['dsn']); if ($this->dbms == 'sqlite') { $dsn = str_replace(array('app:', 'lib:', 'var:'), array(jApp::appPath(), LIB_PATH, jApp::varPath()), $dsn); } } else { $this->dbms = $profile['driver']; $db = $profile['database']; $dsn = $this->dbms . ':host=' . $profile['host'] . ';dbname=' . $db; if ($this->dbms != 'sqlite') { $dsn = $this->dbms . ':host=' . $profile['host'] . ';dbname=' . $db; } else { if (preg_match('/^(app|lib|var)\\:/', $db, $m)) { $dsn = 'sqlite:' . str_replace(array('app:', 'lib:', 'var:'), array(jApp::appPath(), LIB_PATH, jApp::varPath()), $db); } else { $dsn = 'sqlite:' . jApp::varPath('db/sqlite/' . $db); } } } if (isset($prof['usepdo'])) { unset($prof['usepdo']); } if (isset($prof['user'])) { $user = $prof['user']; unset($prof['user']); } if (isset($prof['password'])) { $password = $profile['password']; unset($prof['password']); } unset($prof['driver']); parent::__construct($dsn, $user, $password, $prof); $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('jDbPDOResultSet')); $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); if ($this->dbms == 'mysql') { $this->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); } if ($this->dbms == 'oci') { $this->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); } if (isset($prof['force_encoding']) && $prof['force_encoding'] == true) { $charset = jApp::config()->charset; if ($this->dbms == 'mysql' && isset($this->_mysqlCharsets[$charset])) { $this->exec("SET NAMES '" . $this->_mysqlCharsets[$charset] . "'"); } elseif ($this->dbms == 'pgsql' && isset($this->_pgsqlCharsets[$charset])) { $this->exec("SET client_encoding to '" . $this->_pgsqlCharsets[$charset] . "'"); } } }
function testContext() { $appPath = jApp::appPath(); $varPath = jApp::varPath(); $logPath = jApp::logPath(); $configPath = jApp::configPath(); $wwwPath = jApp::wwwPath(); $scriptsPath = jApp::scriptsPath(); $tempPath = jApp::tempPath(); // first save jApp::saveContext(); // verify that we still have the current path $this->assertEquals($appPath, jApp::appPath()); $this->assertEquals($varPath, jApp::varPath()); $this->assertEquals($logPath, jApp::logPath()); $this->assertEquals($configPath, jApp::configPath()); $this->assertEquals($wwwPath, jApp::wwwPath()); $this->assertEquals($scriptsPath, jApp::scriptsPath()); $this->assertEquals($tempPath, jApp::tempPath()); // change the path jApp::initPaths('/myapp/'); $this->assertEquals('/myapp/', jApp::appPath()); $this->assertEquals('/myapp/var/', jApp::varPath()); $this->assertEquals('/myapp/var/log/', jApp::logPath()); $this->assertEquals('/myapp/var/config/', jApp::configPath()); $this->assertEquals('/myapp/www/', jApp::wwwPath()); $this->assertEquals('/myapp/scripts/', jApp::scriptsPath()); $this->assertEquals($tempPath, jApp::tempPath()); // second save jApp::saveContext(); jApp::initPaths('/myapp2/'); $this->assertEquals('/myapp2/', jApp::appPath()); $this->assertEquals('/myapp2/var/', jApp::varPath()); $this->assertEquals('/myapp2/var/log/', jApp::logPath()); $this->assertEquals('/myapp2/var/config/', jApp::configPath()); $this->assertEquals('/myapp2/www/', jApp::wwwPath()); $this->assertEquals('/myapp2/scripts/', jApp::scriptsPath()); $this->assertEquals($tempPath, jApp::tempPath()); // pop the second save, we should be with the first saved values jApp::restoreContext(); $this->assertEquals('/myapp/', jApp::appPath()); $this->assertEquals('/myapp/var/', jApp::varPath()); $this->assertEquals('/myapp/var/log/', jApp::logPath()); $this->assertEquals('/myapp/var/config/', jApp::configPath()); $this->assertEquals('/myapp/www/', jApp::wwwPath()); $this->assertEquals('/myapp/scripts/', jApp::scriptsPath()); $this->assertEquals($tempPath, jApp::tempPath()); // pop the first save, we should be with initial paths jApp::restoreContext(); $this->assertEquals($appPath, jApp::appPath()); $this->assertEquals($varPath, jApp::varPath()); $this->assertEquals($logPath, jApp::logPath()); $this->assertEquals($configPath, jApp::configPath()); $this->assertEquals($wwwPath, jApp::wwwPath()); $this->assertEquals($scriptsPath, jApp::scriptsPath()); $this->assertEquals($tempPath, jApp::tempPath()); }
/** * get the info of a given theme * @param string $theme the name of the theme * @return array details of the theme */ static function readManifest($theme) { $themeInfos = array(); $path = jApp::varPath() . '/themes/' . $theme . '/theme.php'; if (file_exists($path)) { include $path; } return $themeInfos; }
/** * initialize the application paths * * Warning: given paths should be ended by a directory separator. * @param string $appPath application directory * @param string $wwwPath www directory * @param string $varPath var directory * @param string $logPath log directory * @param string $configPath config directory * @param string $scriptPath scripts directory */ public static function initPaths($appPath, $wwwPath = null, $varPath = null, $logPath = null, $configPath = null, $scriptPath = null) { self::$appPath = $appPath; self::$wwwPath = is_null($wwwPath) ? $appPath . 'www/' : $wwwPath; self::$varPath = is_null($varPath) ? $appPath . 'var/' : $varPath; self::$logPath = is_null($logPath) ? self::$varPath . 'log/' : $logPath; self::$configPath = is_null($configPath) ? self::$varPath . 'config/' : $configPath; self::$scriptPath = is_null($scriptPath) ? $appPath . 'scripts/' : $scriptPath; self::$_isInit = true; }
protected function _connect() { $db = $this->profile['database']; if (preg_match('/^(app|lib|var)\\:/', $db)) { $path = str_replace(array('app:', 'lib:', 'var:'), array(jApp::appPath(), LIB_PATH, jApp::varPath()), $db); } else { $path = jApp::varPath('db/sqlite3/' . $db); } return new SQLite3($path); }
public function run() { $paths = array(); $paths[] = jApp::tempBasePath(); $paths[] = jApp::logPath(); $paths[] = jApp::varPath('mails'); $paths[] = jApp::varPath('db'); foreach ($paths as $path) { $this->setRights($path); } }
public function __construct() { // read the lizmap configuration file $readConfigPath = parse_ini_file(jApp::varPath() . $this->config, True); $this->data = $readConfigPath; // set generic parameters foreach ($this->properties as $prop) { if (isset($readConfigPath['services'][$prop])) { $this->{$prop} = $readConfigPath['services'][$prop]; } } }
public function getPath() { // add a trailing slash if needed if (!preg_match('#/$#', $this->data['path'])) { $this->data['path'] .= '/'; } // if path is relative, get full path if ($this->data['path'][0] != '/' and $this->data['path'][1] != ':') { return jApp::varPath() . $this->data['path']; } return $this->data['path']; }
public function __construct($key) { // read the lizmap log configuration file $readConfigPath = parse_ini_file(jApp::varPath() . $this->config, True); $section = 'item:' . $key; // Check if this item exists in the ini file if (array_key_exists($section, $readConfigPath)) { // Set each property foreach (self::$properties as $property) { $this->data[$property] = $readConfigPath[$section][$property]; } } $this->key = $key; }
/** * initialize the application paths * * Warning: given paths should be ended by a directory separator. * @param string $appPath application directory * @param string $wwwPath www directory * @param string $varPath var directory * @param string $logPath log directory * @param string $configPath config directory * @param string $scriptPath scripts directory */ public static function initPaths($appPath, $wwwPath = null, $varPath = null, $logPath = null, $configPath = null, $scriptPath = null) { self::$appPath = $appPath; self::$wwwPath = is_null($wwwPath) ? $appPath . 'www/' : $wwwPath; self::$varPath = is_null($varPath) ? $appPath . 'var/' : $varPath; self::$logPath = is_null($logPath) ? self::$varPath . 'log/' : $logPath; self::$configPath = is_null($configPath) ? self::$varPath . 'config/' : $configPath; self::$scriptPath = is_null($scriptPath) ? $appPath . 'scripts/' : $scriptPath; self::$_isInit = true; self::$_coord = null; self::$_config = null; self::$configAutoloader = null; self::$_mainConfigFile = null; }
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); } }
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 = str_replace(array('app:', 'lib:', 'var:'), array(jApp::appPath(), LIB_PATH, jApp::varPath()), $db); } else { $path = jApp::varPath('db/sqlite/' . $db); } if ($cnx = @$funcconnect($path)) { return $cnx; } else { throw new jException('jelix~db.error.connection', $db); } }
/** * action to display the page * @param jTpl $tpl the template container */ function show($tpl) { if (!isset($_SESSION['hfnconf'])) { $_SESSION['hfnconf'] = $this->loadconf(); } $themes = array(); $dir = new DirectoryIterator(jApp::varPath() . 'themes/'); foreach ($dir as $dirContent) { if ($dirContent->isDir() && !$dirContent->isDot()) { $themes[] = $dirContent->getFilename(); } } $tpl->assign('themes', $themes); $tpl->assign($_SESSION['hfnconf']); return true; }
protected function _createPath() { global $gJConfig; if (!isset($gJConfig->_modulesPathList[$this->module])) { throw new jExceptionSelector('jelix~errors.selector.module.unknown', $this->toString()); } $path = $this->module . '/' . $this->resource; $lpath = $this->module . '/' . $gJConfig->locale . '/' . $this->resource; if ($gJConfig->theme != 'default') { // on regarde si il y a un template redéfinie pour le theme courant $this->_where = 'themes/' . $gJConfig->theme . '/' . $lpath; $this->_path = jApp::varPath($this->_where . '.tpl'); if (is_readable($this->_path)) { return; } // on regarde si il y a un template redéfinie pour le theme courant $this->_where = 'themes/' . $gJConfig->theme . '/' . $path; $this->_path = jApp::varPath($this->_where . '.tpl'); if (is_readable($this->_path)) { return; } } // on regarde si il y a un template redéfinie dans le theme par defaut $this->_where = 'themes/default/' . $lpath; $this->_path = jApp::varPath($this->_where . '.tpl'); if (is_readable($this->_path)) { return; } $this->_where = 'themes/default/' . $path; $this->_path = jApp::varPath($this->_where . '.tpl'); if (is_readable($this->_path)) { return; } // et sinon, on regarde si le template existe dans le module en question $this->_path = $gJConfig->_modulesPathList[$this->module] . $this->_dirname . $gJConfig->locale . '/' . $this->resource . '.tpl'; if (is_readable($this->_path)) { $this->_where = 'modules/' . $lpath; return; } $this->_path = $gJConfig->_modulesPathList[$this->module] . $this->_dirname . $this->resource . '.tpl'; if (is_readable($this->_path)) { $this->_where = 'modules/' . $path; return; } throw new jExceptionSelector('jelix~errors.selector.invalid.target', array($this->toString(), "template")); }
protected function _createPath() { if (!isset(jApp::config()->_modulesPathList[$this->module])) { throw new jExceptionSelector('jelix~errors.selector.module.unknown', $this->toString()); } $path = $this->module . '/' . $this->resource; $lpath = $this->module . '/' . jApp::config()->locale . '/' . $this->resource; if (($theme = jApp::config()->theme) != 'default') { // check if there is a redefined template for the current theme $this->_where = 'themes/' . $theme . '/' . $lpath; $this->_path = jApp::varPath($this->_where . '.tpl'); if (is_readable($this->_path)) { return; } // check if there is a redefined template for the current localized theme $this->_where = 'themes/' . $theme . '/' . $path; $this->_path = jApp::varPath($this->_where . '.tpl'); if (is_readable($this->_path)) { return; } } // check if there is a redefined template for the default theme $this->_where = 'themes/default/' . $lpath; $this->_path = jApp::varPath($this->_where . '.tpl'); if (is_readable($this->_path)) { return; } $this->_where = 'themes/default/' . $path; $this->_path = jApp::varPath($this->_where . '.tpl'); if (is_readable($this->_path)) { return; } // else check if the template exists in the current module $this->_path = jApp::config()->_modulesPathList[$this->module] . $this->_dirname . jApp::config()->locale . '/' . $this->resource . '.tpl'; if (is_readable($this->_path)) { $this->_where = 'modules/' . $lpath; return; } $this->_path = jApp::config()->_modulesPathList[$this->module] . $this->_dirname . $this->resource . '.tpl'; if (is_readable($this->_path)) { $this->_where = 'modules/' . $path; return; } throw new jExceptionSelector('jelix~errors.selector.invalid.target', array($this->toString(), "template")); }
protected function _createPath() { global $gJConfig; if (!isset($gJConfig->_modulesPathList[$this->module])) { throw new jExceptionSelector('jelix~errors.selector.module.unknown', $this->toString()); } // on regarde si le dao a été redéfini $overloadedPath = jApp::varPath('overloads/' . $this->module . '/' . $this->_dirname . $this->resource . $this->_suffix); if (is_readable($overloadedPath)) { $this->_path = $overloadedPath; $this->_where = 'overloaded/'; return; } // et sinon, on regarde si le dao existe dans le module en question $this->_path = $gJConfig->_modulesPathList[$this->module] . $this->_dirname . $this->resource . $this->_suffix; if (!is_readable($this->_path)) { throw new jExceptionSelector('jelix~errors.selector.invalid.target', array($this->toString(), "dao")); } $this->_where = 'modules/'; }
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 _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; }
public function getRootRepositories() { $rootRepositories = $this->rootRepositories; if ($rootRepositories != '') { // if path is relative, get full path if ($rootRepositories[0] != '/' and $rootRepositories[1] != ':') { $rootRepositories = realpath(jApp::varPath() . $rootRepositories); } // add a trailing slash if needed if (!preg_match('#/$#', $rootRepositories)) { $rootRepositories .= '/'; } } return $rootRepositories; }
/** * replace a path with Jelix shortcuts parts (var:, temp:, www: app:, lib:) * * @param string $path the system valid path * @param string $beforeShortcut a string to be output before the Jelix shortcut * @param string $afterShortcut a string to be output after the Jelix shortcut * @return string the path with Jelix shortcuts parts */ public static function unparseJelixPath($path, $beforeShortcut = '', $afterShortcut = '') { $shortcutPath = ''; $shortcut = ''; if (strpos($path, LIB_PATH) === 0) { $shortcutPath = LIB_PATH; $shortcut = 'lib:'; } elseif (strpos($path, jApp::tempPath()) === 0) { $shortcutPath = jApp::tempPath(); $shortcut = 'temp:'; } elseif (strpos($path, jApp::wwwPath()) === 0) { $shortcutPath = jApp::wwwPath(); $shortcut = 'www:'; } elseif (strpos($path, jApp::varPath()) === 0) { $shortcutPath = jApp::varPath(); $shortcut = 'var:'; } elseif (strpos($path, jApp::appPath()) === 0) { $shortcutPath = jApp::appPath(); $shortcut = 'app:'; } else { $shortcutPath = dirname(jApp::appPath()); $shortcut = 'app:'; while ($shortcutPath != '.' && $shortcutPath != '') { $shortcut .= '../'; if (strpos($path, $shortcutPath) === 0) { break; } $shortcutPath = dirname($shortcutPath); } if ($shortcutPath == '.') { $shortcutPath = ''; } } if ($shortcutPath != '') { $cut = $shortcutPath[0] == '/' ? 0 : 1; $path = $beforeShortcut . $shortcut . $afterShortcut . substr($path, strlen($path) + $cut); } return $path; }
/** * Save the data for one section. * @return Redirect to the index. */ function saveSection() { $repository = $this->param('repository'); $new = (bool) $this->param('new'); $ok = true; // Get services data $services = lizmap::getServices(); // Repository (first take the default one) $lrep = lizmap::getRepository($repository); // what to do if it's a new one! // Get the form $form = jForms::get('admin~config_section'); // token $token = $this->param('__JFORMS_TOKEN__'); if (!$token) { $ok = false; jMessage::add('missing form token'); } // If the form is not defined, redirection if (!$form) { $ok = false; } // Redirection in case of errors if (!$ok) { $rep = $this->getResponse("redirect"); $rep->action = "admin~config:index"; return $rep; } // Rebuild form fields /*foreach(lizmap::getRepositoryProperties() as $k){ if ( $propertiesOptions[$k]['fieldType'] == 'checkbox' ) { $ctrl = new jFormsControlCheckbox($k); } else { $ctrl = new jFormsControlInput($k); } $ctrl->required = $propertiesOptions[$k]['required']; $ctrl->label = jLocale::get("admin~admin.form.admin_section.repository.".$k.".label"); $datatype = new jDatatypeString(); $ctrl->datatype=$datatype; $form->addControl($ctrl); }*/ lizmap::constructRepositoryForm($lrep, $form); if ($lrep) { $form = $this->populateRepositoryRightsFormControl($form, $lrep->getKey(), false); } // Set form data from request data $form->initFromRequest(); // Check the form $ok = true; if (!$form->check()) { $ok = false; } if (!$new && !$lrep) { $form->setErrorOn('repository', jLocale::get("admin~admin.form.admin_section.message.repository.wrong")); $ok = false; } // Check paths if (in_array('path', lizmap::getRepositoryProperties())) { $npath = $form->getData('path'); if ($npath[0] != '/' and $npath[1] != ':') { $npath = jApp::varPath() . $npath; } if (!file_exists($npath) or !is_dir($npath)) { $form->setErrorOn('path', jLocale::get("admin~admin.form.admin_section.message.path.wrong")); $ok = false; } $rootRepositories = $services->getRootRepositories(); if ($rootRepositories != '') { if ($lrep && substr($lrep->getPath(), 0, strlen($rootRepositories)) !== $rootRepositories) { //Can't update path $form->setData('path', $lrep->getData('path')); } else { if ($lrep && substr($lrep->getPath(), 0, strlen($rootRepositories)) === $rootRepositories && substr(realpath($npath), 0, strlen($rootRepositories)) !== $rootRepositories) { $form->setErrorOn('path', jLocale::get("admin~admin.form.admin_section.message.path.not_authorized")); jLog::log('rootRepositories == ' . $rootRepositories . ', repository ' . $lrep->getKey() . ' path == ' . realpath($npath)); $ok = false; } else { if ($lrep == null && substr(realpath($npath), 0, strlen($rootRepositories)) !== $rootRepositories) { $form->setErrorOn('path', jLocale::get("admin~admin.form.admin_section.message.path.not_authorized")); jLog::log('rootRepositories == ' . $rootRepositories . ', new repository path == ' . realpath($npath)); $ok = false; } } } } } if (!$ok) { // Errors : redirection to the display action $rep = $this->getResponse('redirect'); $rep->action = 'admin~config:editSection'; $rep->params['repository'] = $repository; $rep->params['errors'] = "1"; foreach (jApp::coord()->request->params as $k => $v) { if (preg_match('#^' . $this->lizmapClientPrefix . '#', $k)) { $rep->params[$k] = $v; } } if ($new) { $form->setReadOnly('repository', false); } return $rep; } // Repository data $data = array(); foreach (lizmap::getRepositoryProperties() as $prop) { $data[$prop] = $form->getData($prop); // Check paths if ($prop == 'path') { # add a trailing / if needed if (!preg_match('#/$#', $data[$prop])) { $data[$prop] .= '/'; } } } // Save the data if ($new && !$lrep) { $lrep = lizmap::createRepository($repository, $data); } else { if ($lrep) { $modifySection = $lrep->update($data); } } jMessage::add(jLocale::get("admin~admin.form.admin_section.message.data.saved")); // group rights data $this->saveRepositoryRightsFromRequest($form, $repository); // Redirect to the validation page $rep = $this->getResponse("redirect"); $rep->params['repository'] = $repository; if ($new) { $rep->params['new'] = 1; } $rep->action = "admin~config:validateSection"; return $rep; }
function checkAppPaths() { $ok = true; if (!defined('JELIX_LIB_PATH') || !jApp::isInit()) { throw new Exception($this->messages->get('path.core')); } if (!file_exists(jApp::tempBasePath()) || !is_writable(jApp::tempBasePath())) { $this->error('path.temp'); $ok = false; } if (!file_exists(jApp::logPath()) || !is_writable(jApp::logPath())) { $this->error('path.log'); $ok = false; } if (!file_exists(jApp::varPath())) { $this->error('path.var'); $ok = false; } if (!file_exists(jApp::configPath())) { $this->error('path.config'); $ok = false; } elseif ($this->checkForInstallation) { if (!is_writable(jApp::configPath())) { $this->error('path.config.writable'); $ok = false; } if (file_exists(jApp::configPath('profiles.ini.php')) && !is_writable(jApp::configPath('profiles.ini.php'))) { $this->error('path.profiles.writable'); $ok = false; } if (file_exists(jApp::mainConfigFile()) && !is_writable(jApp::mainConfigFile())) { $this->error('path.mainconfig.writable'); $ok = false; } elseif (file_exists(jApp::configPath('defaultconfig.ini.php')) && !is_writable(jApp::configPath('defaultconfig.ini.php'))) { $this->error('path.mainconfig.writable'); $ok = false; } if (file_exists(jApp::configPath('installer.ini.php')) && !is_writable(jApp::configPath('installer.ini.php'))) { $this->error('path.installer.writable'); $ok = false; } } if (!file_exists(jApp::wwwPath())) { $this->error('path.www'); $ok = false; } foreach ($this->otherPaths as $path) { $realPath = jFile::parseJelixPath($path); if (!file_exists($realPath)) { $this->error('path.custom.not.exists', array($path)); $ok = false; } else { if (!is_writable($realPath)) { $this->error('path.custom.writable', array($path)); $ok = false; } else { $this->ok('path.custom.ok', array($path)); } } } if ($ok) { $this->ok('paths.ok'); } else { throw new Exception($this->messages->get('too.critical.error')); } /*if(!isset($GLOBALS['config_file']) || empty($GLOBALS['config_file']) || !file_exists(jApp::configPath($GLOBALS['config_file']))){ throw new Exception($this->messages->get('config.file')); }*/ return $ok; }
/** * Use a profile to do the connection * @param array $profile the profile data readed from the ini file */ function __construct($profile) { $this->profile = $profile; $prof = $profile; $user = ''; $password = ''; $dsn = ''; if (isset($profile['dsn'])) { $this->dbms = $this->driverName = substr($profile['dsn'], 0, strpos($profile['dsn'], ':')); $dsn = $profile['dsn']; unset($prof['dsn']); if ($this->dbms == 'sqlite') { $dsn = jFile::parseJelixPath($dsn); } } else { $this->dbms = $this->driverName = $profile['driver']; $db = $profile['database']; $dsn = $this->dbms . ':host=' . $profile['host'] . ';dbname=' . $db; if ($this->dbms != 'sqlite') { $dsn = $this->dbms . ':host=' . $profile['host'] . ';dbname=' . $db; } else { if (preg_match('/^(app|lib|var)\\:/', $db, $m)) { $dsn = 'sqlite:' . jFile::parseJelixPath($db); } else { $dsn = 'sqlite:' . jApp::varPath('db/sqlite/' . $db); } } } if (isset($prof['usepdo'])) { unset($prof['usepdo']); } // we check user and password because some db like sqlite doesn't have user/password if (isset($prof['user'])) { $user = $prof['user']; unset($prof['user']); } if (isset($prof['password'])) { $password = $profile['password']; unset($prof['password']); } unset($prof['driver']); parent::__construct($dsn, $user, $password, $prof); $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('jDbPDOResultSet')); $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // we cannot launch two queries at the same time with PDO ! except if // we use mysql with the attribute MYSQL_ATTR_USE_BUFFERED_QUERY // TODO check if PHP 5.3 or higher fixes this issue if ($this->dbms == 'mysql') { $this->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); } // Oracle returns names of columns in upper case by default. so here // we force the case in lower. if ($this->dbms == 'oci') { $this->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); } if (isset($prof['force_encoding']) && $prof['force_encoding'] == true) { $charset = jApp::config()->charset; if ($this->dbms == 'mysql' && isset($this->_mysqlCharsets[$charset])) { $this->exec("SET NAMES '" . $this->_mysqlCharsets[$charset] . "'"); } elseif ($this->dbms == 'pgsql' && isset($this->_pgsqlCharsets[$charset])) { $this->exec("SET client_encoding to '" . $this->_pgsqlCharsets[$charset] . "'"); } } }