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); } } } }
public function _connect() { if (isset($this->_profile['storage_dir']) && $this->_profile['storage_dir'] != '') { $this->_storage_dir = jFile::parseJelixPath($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']); } }
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 = 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; }
/** * retrieve all modules specifications */ protected function getModulesPath($modulesPath, $defaultAccess) { $list = preg_split('/ *, */', $modulesPath); array_unshift($list, JELIX_LIB_PATH . 'core-modules/'); $modulesPathList = array(); foreach ($list as $k => $path) { if (trim($path) == '') { continue; } $p = jFile::parseJelixPath($path); if (!file_exists($p)) { throw new Exception('The path, ' . $path . ' given in the jelix config, doesn\'t exists !', E_USER_ERROR); } if (substr($p, -1) != '/') { $p .= '/'; } $this->moduleRepositories[$p] = array(); if ($handle = opendir($p)) { while (false !== ($f = readdir($handle))) { if ($f[0] != '.' && is_dir($p . $f)) { $m = new migrateModule(); $m->path = $p . $f . '/'; $m->name = $f; $m->access = $f == 'jelix' ? 2 : $defaultAccess; $m->repository = $p; $modulesPathList[$f] = $m; $this->moduleRepositories[$p][$f] = $m; } } closedir($handle); } } return $modulesPathList; }
protected function _execute(InputInterface $input, OutputInterface $output) { $module = $input->getArgument('module'); $initialVersion = $input->getOption('ver'); if (!$initialVersion) { $initialVersion = '0.1pre'; } // note: since module name are used for name of generated name, // only this characters are allowed if ($module == null || preg_match('/([^a-zA-Z_0-9])/', $module)) { throw new \Exception("'" . $module . "' is not a valid name for a module"); } // check if the module already exist or not $path = ''; try { $path = $this->getModulePath($module); } catch (\Exception $e) { } if ($path != '') { throw new \Exception("module '" . $module . "' already exists"); } // verify the given repository $repository = $input->getArgument('repository'); if (substr($repository, -1) != '/') { $repository .= '/'; } $repositoryPath = \jFile::parseJelixPath($repository); if (!$input->getOption('noregistration')) { $this->registerModulesDir($repository, $repositoryPath); } $path = $repositoryPath . $module . '/'; $this->createDir($path); App::setConfig(null); $noSubDir = $input->getOption('nosubdir'); $addInstallZone = $input->getOption('addinstallzone'); $isdefault = $input->getOption('defaultmodule'); if ($input->getOption('admin')) { $noSubDir = false; $addInstallZone = false; } $param = array(); $param['module'] = $module; $param['version'] = $initialVersion; $this->createFile($path . 'jelix-module.json', 'module/jelix-module.json.tpl', $param); // create all sub directories of a module if (!$noSubDir) { $this->createDir($path . 'classes/'); $this->createDir($path . 'zones/'); $this->createDir($path . 'controllers/'); $this->createDir($path . 'templates/'); $this->createDir($path . 'classes/'); $this->createDir($path . 'daos/'); $this->createDir($path . 'forms/'); $this->createDir($path . 'locales/'); $this->createDir($path . 'locales/en_US/'); $this->createDir($path . 'locales/fr_FR/'); $this->createDir($path . 'install/'); if ($this->verbose()) { $output->writeln("Sub directories have been created in the new module {$module}."); } $this->createFile($path . 'install/install.php', 'module/install.tpl', $param); $this->createFile($path . 'urls.xml', 'module/urls.xml.tpl', array()); } $iniDefault = new \Jelix\IniFile\IniModifier(App::mainConfigFile()); $urlsFile = App::appConfigPath($iniDefault->getValue('significantFile', 'urlengine')); $xmlMap = new \Jelix\Routing\UrlMapping\XmlMapModifier($urlsFile, true); // activate the module in the application if ($isdefault) { if ($this->allEntryPoint) { $xmlEp = $xmlMap->getDefaultEntryPoint($type); } else { $xmlEp = $xmlMap->getEntryPoint($this->entryPointId); } if ($xmlEp) { $xmlEp->addUrlAction('/', $module, 'default:index', null, null, array('default' => true)); $xmlEp->addUrlModule('', $module); if ($this->verbose()) { $output->writeln("The new module {$module} becomes the default module"); } } else { if ($this->verbose()) { $output->writeln("No default entry point found: the new module cannot be the default module"); } } } $xmlMap->save(); $iniDefault->setValue($module . '.access', $this->allEntryPoint ? 2 : 1, 'modules'); $iniDefault->save(); $list = $this->getEntryPointsList(); $install = new \Jelix\IniFile\IniModifier(App::configPath('installer.ini.php')); // install the module for all needed entry points foreach ($list as $entryPoint) { $configFile = App::appConfigPath($entryPoint['config']); $epconfig = new \Jelix\IniFile\IniModifier($configFile); if ($this->allEntryPoint) { $access = 2; } else { $access = $entryPoint['file'] == $this->entryPointName ? 2 : 0; } $epconfig->setValue($module . '.access', $access, 'modules'); $epconfig->save(); if ($this->allEntryPoint || $entryPoint['file'] == $this->entryPointName) { $install->setValue($module . '.installed', 1, $entryPoint['id']); $install->setValue($module . '.version', $initialVersion, $entryPoint['id']); } if ($this->verbose()) { $output->writeln("The module is initialized for the entry point " . $entryPoint['file']); } } $install->save(); App::declareModule($path); // create a default controller if (!$input->getOption('nocontroller')) { $arguments = array('module' => $module, 'controller' => 'default', 'method' => 'index'); if ($input->getOption('entry-point')) { $arguments['--entry-point'] = $input->getOption('entry-point'); } if ($input->getOption('cmdline')) { $arguments['--cmdline'] = true; } if ($addInstallZone) { $arguments['--addinstallzone'] = true; } if ($output->isVerbose()) { $arguments['-v'] = true; } $this->executeSubCommand('module:create-ctrl', $arguments, $output); } if ($input->getOption('admin')) { $this->createFile($path . 'classes/admin' . $module . '.listener.php', 'module/admin.listener.php.tpl', $param, "Listener"); $this->createFile($path . 'events.xml', 'module/events.xml.tpl', $param); file_put_contents($path . 'locales/en_US/interface.UTF-8.properties', 'menu.item=' . $module); file_put_contents($path . 'locales/fr_FR/interface.UTF-8.properties', 'menu.item=' . $module); } }
protected function updateModulePath($ini, $currentModulesPath, $repository, $repositoryPath) { $listRepos = preg_split('/ *, */', $currentModulesPath); $repositoryFound = false; foreach ($listRepos as $path) { if (trim($path) == '') { continue; } $p = jFile::parseJelixPath($path); if (substr($p, -1) != '/') { $p .= '/'; } if ($p == $repositoryPath) { $repositoryFound = true; break; } } // the repository doesn't exist in the configuration // let's add it into the configuration if (!$repositoryFound) { $ini->setValue('modulesPath', $currentModulesPath . ',' . $repository); $ini->save(); $this->createDir($repositoryPath); } }
protected function check_sqlite3($params) { $db = $params['database']; if ($db[0] == '/') { $path = $db; } else { if (preg_match('/^(app|lib|var)\\:/', $db)) { $path = jFile::parseJelixPath($db); } else { $path = jApp::varPath('db/sqlite3/' . $db); } } try { $sqlite = new SQLite3($path, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE); $sqlite->close(); } catch (Exception $e) { throw new Exception($this->locales['error.no.connection']); } return true; }
/** * Analyse plugin paths * @param object $config the config container */ protected static function _loadPluginsPathList($config) { $list = preg_split('/ *, */', $config->pluginsPath); array_unshift($list, JELIX_LIB_PATH . 'plugins/'); foreach ($list as $k => $path) { if (trim($path) == '') { continue; } if (preg_match('@^module:([^/]+)(/.*)?$@', $path, $m)) { $mod = $m[1]; if (isset($config->_modulesPathList[$mod])) { $p = $config->_modulesPathList[$mod]; if (isset($m[2]) && strlen($m[2]) > 1) { $p .= $m[2]; } else { $p .= '/plugins/'; } } else { trigger_error('Error in main configuration on pluginsPath -- Path given in pluginsPath for the module ' . $mod . ' is ignored, since this module is unknown or deactivated', E_USER_NOTICE); continue; } } else { $p = jFile::parseJelixPath($path); } if (!file_exists($p)) { trigger_error('Error in main configuration on pluginsPath -- The path, ' . $path . ' given in the jelix config, doesn\'t exists !', E_USER_ERROR); exit; } if (substr($p, -1) != '/') { $p .= '/'; } if ($handle = opendir($p)) { while (false !== ($f = readdir($handle))) { if ($f[0] != '.' && is_dir($p . $f)) { if ($subdir = opendir($p . $f)) { if ($k != 0 && $config->compilation['checkCacheFiletime']) { $config->_allBasePath[] = $p . $f . '/'; } while (false !== ($subf = readdir($subdir))) { if ($subf[0] != '.' && is_dir($p . $f . '/' . $subf)) { if ($f == 'tpl') { $prop = '_tplpluginsPathList_' . $subf; if (!isset($config->{$prop})) { $config->{$prop} = array(); } array_unshift($config->{$prop}, $p . $f . '/' . $subf . '/'); } else { $prop = '_pluginsPathList_' . $f; $config->{$prop}[$subf] = $p . $f . '/' . $subf . '/'; } } } closedir($subdir); } } } closedir($handle); } } }
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; }
public function run() { $this->loadAppConfig(); $entrypoint = $this->getParam('entrypoint'); if (($p = strpos($entrypoint, '.php')) !== false) { $entrypoint = substr($entrypoint, 0, $p); } $ep = $this->getEntryPointInfo($entrypoint); if ($ep == null) { try { $cmd = JelixScript::getCommand('createentrypoint', $this->config); $cmd->initOptParam(array(), array('name' => $entrypoint)); $cmd->run(); $this->appInfos = null; $ep = $this->getEntryPointInfo($entrypoint); } catch (Exception $e) { throw new Exception("The entrypoint has not been created because of this error: " . $e->getMessage() . ". No other files have been created.\n"); } } $installConfig = new \Jelix\IniFile\IniModifier(App::configPath('installer.ini.php')); $inifile = new \Jelix\IniFile\MultiIniModifier(App::mainConfigFile(), App::configPath($ep['config'])); $params = array(); $this->createFile(App::appPath('responses/adminHtmlResponse.class.php'), 'responses/adminHtmlResponse.class.php.tpl', $params, "Response for admin interface"); $this->createFile(App::appPath('responses/adminLoginHtmlResponse.class.php'), 'responses/adminLoginHtmlResponse.class.php.tpl', $params, "Response for login page"); $inifile->setValue('html', 'adminHtmlResponse', 'responses'); $inifile->setValue('htmlauth', 'adminLoginHtmlResponse', 'responses'); $inifile->setValue('startModule', 'master_admin'); $inifile->setValue('startAction', 'default:index'); $repositoryPath = jFile::parseJelixPath('lib:jelix-admin-modules'); $this->registerModulesDir('lib:jelix-admin-modules', $repositoryPath); $installConfig->setValue('jacl.installed', '0', $entrypoint); $inifile->setValue('jacl.access', '0', 'modules'); $installConfig->setValue('jacldb.installed', '0', $entrypoint); $inifile->setValue('jacldb.access', '0', 'modules'); $urlconf = $inifile->getValue($entrypoint, 'simple_urlengine_entrypoints', null, true); if ($urlconf === null || $urlconf == '') { // in defaultconfig $inifile->setValue($entrypoint, 'jacl2db_admin~*@classic, jauthdb_admin~*@classic, master_admin~*@classic, jpref_admin~*@classic', 'simple_urlengine_entrypoints', null, true); // in the config of the entry point $inifile->setValue($entrypoint, 'jacl2db~*@classic, jauth~*@classic, jacl2db_admin~*@classic, jauthdb_admin~*@classic, master_admin~*@classic, jpref_admin~*@classic', 'simple_urlengine_entrypoints'); } else { $urlconf2 = $inifile->getValue($entrypoint, 'simple_urlengine_entrypoints'); if (strpos($urlconf, 'jacl2db_admin~*@classic') === false) { $urlconf .= ',jacl2db_admin~*@classic'; } if (strpos($urlconf, 'jauthdb_admin~*@classic') === false) { $urlconf .= ',jauthdb_admin~*@classic'; } if (strpos($urlconf, 'master_admin~*@classic') === false) { $urlconf .= ',master_admin~*@classic'; } if (strpos($urlconf2, 'jacl2db_admin~*@classic') === false) { $urlconf2 .= ',jacl2db_admin~*@classic'; } if (strpos($urlconf2, 'jauthdb_admin~*@classic') === false) { $urlconf2 .= ',jauthdb_admin~*@classic'; } if (strpos($urlconf2, 'master_admin~*@classic') === false) { $urlconf2 .= ',master_admin~*@classic'; } if (strpos($urlconf2, 'jacl2db~*@classic') === false) { $urlconf2 .= ',jacl2db~*@classic'; } if (strpos($urlconf2, 'jauth~*@classic') === false) { $urlconf2 .= ',jauth~*@classic'; } if (strpos($urlconf2, 'jpref_admin~*@classic') === false) { $urlconf2 .= ',jpref_admin~*@classic'; } $inifile->setValue($entrypoint, $urlconf, 'simple_urlengine_entrypoints', null, true); $inifile->setValue($entrypoint, $urlconf2, 'simple_urlengine_entrypoints'); } if (null == $inifile->getValue($entrypoint, 'basic_significant_urlengine_entrypoints', null, true)) { $inifile->setValue($entrypoint, '1', 'basic_significant_urlengine_entrypoints', null, true); } $inifile->save(); $verbose = $this->verbose(); $reporter = new \Jelix\Installer\Reporter\Console($verbose ? 'notice' : 'warning'); $installer = new \Jelix\Installer\Installer($reporter); $installer->installModules(array('master_admin'), $entrypoint . '.php'); $authini = new \Jelix\IniFile\IniModifier(App::configPath($entrypoint . '/auth.coord.ini.php')); $authini->setValue('after_login', 'master_admin~default:index'); $authini->setValue('timeout', '30'); $authini->save(); $profile = $this->getOption('-profile'); if (!$this->getOption('-noauthdb')) { if ($profile != '') { $authini->setValue('profile', $profile, 'Db'); } $authini->save(); $installer->setModuleParameters('jauthdb', array('defaultuser' => true)); $installer->installModules(array('jauthdb', 'jauthdb_admin'), $entrypoint . '.php'); } else { $installConfig->setValue('jauthdb_admin.installed', '0', $entrypoint); $installConfig->save(); $inifile->setValue('jauthdb_admin.access', '0', 'modules'); $inifile->save(); } if (!$this->getOption('-noacl2db')) { if ($profile != '') { $dbini = new \Jelix\IniFile\IniModifier(App::configPath('profiles.ini.php')); $dbini->setValue('jacl2_profile', $profile, 'jdb'); $dbini->save(); } $installer = new \Jelix\Installer\Installer($reporter); $installer->setModuleParameters('jacl2db', array('defaultuser' => true)); $installer->installModules(array('jacl2db', 'jacl2db_admin'), $entrypoint . '.php'); } else { $installConfig->setValue('jacl2db_admin.installed', '0', $entrypoint); $installConfig->save(); $inifile->setValue('jacl2db_admin.access', '0', 'modules'); $inifile->save(); } $installer->installModules(array('jpref_admin'), $entrypoint . '.php'); }
/** * callback method for jprofiles. Internal use. */ public static function _getClient($profile) { $wsdl = null; $client = 'SoapClient'; if (isset($profile['wsdl'])) { $wsdl = $profile['wsdl']; if ($wsdl == '') { $wsdl = null; } else { if (!preg_match("!^https?\\://!", $wsdl)) { $wsdl = jFile::parseJelixPath($wsdl); } } unset($profile['wsdl']); } if (isset($profile['trace'])) { $profile['trace'] = intval($profile['trace']); // SoapClient recognize only true integer if ($profile['trace']) { $client = 'SoapClientDebug'; } } if (isset($profile['exceptions'])) { $profile['exceptions'] = intval($profile['exceptions']); // SoapClient recognize only true integer } if (isset($profile['connection_timeout'])) { $profile['connection_timeout'] = intval($profile['connection_timeout']); // SoapClient recognize only true integer } // deal with classmap $classMap = array(); if (isset($profile['classmap_file']) && ($f = trim($profile['classmap_file'])) != '') { if (!isset(self::$classmap[$f])) { if (!file_exists(jApp::configPath($f))) { trigger_error("jSoapClient: classmap file " . $f . " does not exists.", E_USER_WARNING); self::$classmap[$f] = array(); } else { self::$classmap[$f] = parse_ini_file(jApp::configPath($f), true); } } if (isset(self::$classmap[$f]['__common__'])) { $classMap = array_merge($classMap, self::$classmap[$f]['__common__']); } if (isset(self::$classmap[$f][$profile['_name']])) { $classMap = array_merge($classMap, self::$classmap[$f][$profile['_name']]); } unset($profile['classmap_file']); } if (isset($profile['classmap']) && is_string($profile['classmap']) && $profile['classmap'] != '') { $map = (array) json_decode(str_replace("'", '"', $profile['classmap'])); $classMap = array_merge($classMap, $map); unset($profile['classmap']); } if (count($classMap)) { $profile['classmap'] = $classMap; } //$context = stream_context_create( array('http' => array('max_redirects' => 3))); //$profile['stream_context'] = $context; unset($profile['_name']); return new $client($wsdl, $profile); }
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'] != '') { $cache_dir = jFile::parseJelixPath($params['cache_dir']); if (is_dir($cache_dir) && is_writable($cache_dir)) { $this->_cache_dir = rtrim(realpath($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']); } else { $this->_directory_umask = jApp::config()->chmodDir; } 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']); } else { $this->_cache_file_umask = jApp::config()->chmodFile; } }
protected function _connect() { if (isset($this->_profile['file']) && $this->_profile['file'] != '') { $this->_file = jFile::parseJelixPath($this->_profile['file']); } else { throw new Exception('No file in the configuration of the dba driver for jKVDB'); } $mode = "cl"; if (isset($this->_profile['handler']) && $this->_profile['handler'] != '') { $handler = $this->_profile['handler']; } else { throw new Exception('No handler in the configuration of the dba driver for jKVDB'); } if (isset($this->_profile['persistant']) && $this->_profile['persistant']) { $conn = dba_popen($this->_file, $mode, $handler); } else { $conn = dba_open($this->_file, $mode, $handler); } if ($conn === false) { return null; } return $conn; }
/** * since urls.xml declare all entrypoints, current entry point does not have * access to all modules, so doesn't know all their paths. * this method retrieve all module paths declared in the configuration * of an entry point or the global configuration * @param string $configFile the config file name */ protected function retrieveModulePaths($configFile) { $conf = parse_ini_file($configFile); if (!array_key_exists('modulesPath', $conf)) { return; } $list = preg_split('/ *, */', $conf['modulesPath']); array_unshift($list, JELIX_LIB_PATH . 'core-modules/'); foreach ($list as $k => $path) { if (trim($path) == '') { continue; } $p = jFile::parseJelixPath($path); if (!file_exists($p)) { continue; } if (substr($p, -1) != '/') { $p .= '/'; } if (isset($this->modulesRepositories[$p])) { continue; } $this->modulesRepositories[$p] = true; if ($handle = opendir($p)) { while (false !== ($f = readdir($handle))) { if ($f[0] != '.' && is_dir($p . $f)) { $this->modulesPath[$f] = $p . $f . '/'; } } closedir($handle); } } }
public function run() { $this->loadAppConfig(); $module = $this->getParam('module'); $initialVersion = $this->getOption('-ver'); if ($initialVersion === false) { $initialVersion = '0.1pre'; } // note: since module name are used for name of generated name, // only this characters are allowed if ($module == null || preg_match('/([^a-zA-Z_0-9])/', $module)) { throw new Exception("'" . $module . "' is not a valid name for a module"); } // check if the module already exist or not $path = ''; try { $path = $this->getModulePath($module); } catch (Exception $e) { } if ($path != '') { throw new Exception("module '" . $module . "' already exists"); } // verify the given repository $repository = $this->getParam('repository', 'app:modules/'); if (substr($repository, -1) != '/') { $repository .= '/'; } $repositoryPath = jFile::parseJelixPath($repository); if (!$this->getOption('-noregistration')) { $this->registerModulesDir($repository, $repositoryPath); } $path = $repositoryPath . $module . '/'; $this->createDir($path); App::setConfig(null); if ($this->getOption('-admin')) { $this->removeOption('-nosubdir'); $this->removeOption('-addinstallzone'); } $param = array(); $param['module'] = $module; $param['version'] = $initialVersion; $this->createFile($path . 'jelix-module.json', 'module/jelix-module.json.tpl', $param); // create all sub directories of a module if (!$this->getOption('-nosubdir')) { $this->createDir($path . 'classes/'); $this->createDir($path . 'zones/'); $this->createDir($path . 'controllers/'); $this->createDir($path . 'templates/'); $this->createDir($path . 'classes/'); $this->createDir($path . 'daos/'); $this->createDir($path . 'forms/'); $this->createDir($path . 'locales/'); $this->createDir($path . 'locales/en_US/'); $this->createDir($path . 'locales/fr_FR/'); $this->createDir($path . 'install/'); if ($this->verbose()) { echo "Sub directories have been created in the new module {$module}.\n"; } $this->createFile($path . 'install/install.php', 'module/install.tpl', $param); $this->createFile($path . 'urls.xml', 'module/urls.xml.tpl', array()); } $isdefault = $this->getOption('-defaultmodule'); $iniDefault = new \Jelix\IniFile\IniModifier(App::mainConfigFile()); // activate the module in the application if ($isdefault) { $iniDefault->setValue('startModule', $module); $iniDefault->setValue('startAction', 'default:index'); if ($this->verbose()) { echo "The new module {$module} becomes the default module\n"; } } $iniDefault->setValue($module . '.access', $this->allEntryPoint ? 2 : 1, 'modules'); $iniDefault->save(); $list = $this->getEntryPointsList(); $install = new \Jelix\IniFile\IniModifier(App::configPath('installer.ini.php')); // install the module for all needed entry points foreach ($list as $entryPoint) { $configFile = App::configPath($entryPoint['config']); $epconfig = new \Jelix\IniFile\IniModifier($configFile); if ($this->allEntryPoint) { $access = 2; } else { $access = $entryPoint['file'] == $this->entryPointName ? 2 : 0; } $epconfig->setValue($module . '.access', $access, 'modules'); $epconfig->save(); if ($this->allEntryPoint || $entryPoint['file'] == $this->entryPointName) { $install->setValue($module . '.installed', 1, $entryPoint['id']); $install->setValue($module . '.version', $initialVersion, $entryPoint['id']); } if ($isdefault) { // we set the module as default module for one or all entry points. // we set the startModule option for all entry points except // if an entry point is indicated on the command line if ($this->allEntryPoint || $entryPoint['file'] == $this->entryPointName) { if ($epconfig->getValue('startModule') != '') { $epconfig->setValue('startModule', $module); $epconfig->setValue('startAction', 'default:index'); $epconfig->save(); } } } if ($this->verbose()) { echo "The module is initialized for the entry point " . $entryPoint['file'] . ".\n"; } } $install->save(); // create a default controller if (!$this->getOption('-nocontroller')) { $agcommand = JelixScript::getCommand('createctrl', $this->config); $options = $this->getCommonActiveOption(); if ($this->getOption('-cmdline')) { $options['-cmdline'] = true; } if ($this->getOption('-addinstallzone')) { $options['-addinstallzone'] = true; } $agcommand->initOptParam($options, array('module' => $module, 'name' => 'default', 'method' => 'index')); $agcommand->run(); } if ($this->getOption('-admin')) { $this->createFile($path . 'classes/admin' . $module . '.listener.php', 'module/admin.listener.php.tpl', $param, "Listener"); $this->createFile($path . 'events.xml', 'module/events.xml.tpl', $param); file_put_contents($path . 'locales/en_US/interface.UTF-8.properties', 'menu.item=' . $module); file_put_contents($path . 'locales/fr_FR/interface.UTF-8.properties', 'menu.item=' . $module); } }
/** * 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] . "'"); } } }
protected function _parseSqlitePath($path) { if (preg_match('/^(app|lib|var|temp|www)\\:/', $db, $m)) { return jFile::parseJelixPath($db); } else { if (preg_match('!^[a-z]\\:(\\\\|/)[a-z]!i', $db) || $db[0] == '/') { if (file_exists($db) || file_exists(dirname($db))) { return $db; } else { throw new Exception('jDbPDOConnection, sqlite: unknown database path scheme'); } } else { return jApp::varPath('db/sqlite/' . $db); } } }
/** * compute path from the configuration or from * the given array. These paths will be used to read images and to save them * into a cache directory. * @return array. keys are * src_url, src_path, cache_path, cache_url */ public static function computeUrlFilePath($config = null) { // paths & uri $basePath = jApp::urlBasePath(); if (!$config) { $config =& jApp::config()->imagemodifier; } // compute URL and file path of the source image if ($config['src_url'] && $config['src_path']) { $srcUri = $config['src_url']; if ($srcUri[0] != '/' && strpos($srcUri, 'http:') !== 0) { $srcUri = $basePath . $srcUri; } $srcPath = jFile::parseJelixPath($config['src_path']); } else { $srcUri = jApp::coord()->request->getServerURI() . $basePath; $srcPath = jApp::wwwPath(); } if ($config['cache_path'] && $config['cache_url']) { $cacheUri = $config['cache_url']; if ($cacheUri[0] != '/' && strpos($cacheUri, 'http:') !== 0) { $cacheUri = $basePath . $cacheUri; } $cachePath = jFile::parseJelixPath($config['cache_path']); } else { $cachePath = jApp::wwwPath('cache/images/'); $cacheUri = jApp::coord()->request->getServerURI() . $basePath . 'cache/images/'; } return array($srcPath, $srcUri, $cachePath, $cacheUri); }
protected function _execute(InputInterface $input, OutputInterface $output) { $entrypoint = $input->getArgument('entrypoint'); if (($p = strpos($entrypoint, '.php')) !== false) { $entrypoint = substr($entrypoint, 0, $p); } $ep = $this->getEntryPointInfo($entrypoint); if ($ep == null) { try { $options = array('entrypoint' => $entrypoint); $this->executeSubCommand('app:createentrypoint', $options, $output); $this->appInfos = null; $ep = $this->getEntryPointInfo($entrypoint); } catch (\Exception $e) { throw new \Exception("The entrypoint has not been created because of this error: " . $e->getMessage() . ". No other files have been created.\n"); } } $installConfig = new \Jelix\IniFile\IniModifier(App::configPath('installer.ini.php')); $inifile = new \Jelix\IniFile\MultiIniModifier(App::mainConfigFile(), App::appConfigPath($ep['config'])); $params = array(); $this->createFile(App::appPath('app/responses/adminHtmlResponse.class.php'), 'app/responses/adminHtmlResponse.class.php.tpl', $params, "Response for admin interface"); $this->createFile(App::appPath('app/responses/adminLoginHtmlResponse.class.php'), 'app/responses/adminLoginHtmlResponse.class.php.tpl', $params, "Response for login page"); $inifile->setValue('html', 'adminHtmlResponse', 'responses'); $inifile->setValue('htmlauth', 'adminLoginHtmlResponse', 'responses'); $repositoryPath = \jFile::parseJelixPath('lib:jelix-admin-modules'); $this->registerModulesDir('lib:jelix-admin-modules', $repositoryPath); $installConfig->setValue('jacl.installed', '0', $entrypoint); $inifile->setValue('jacl.access', '0', 'modules'); $installConfig->setValue('jacldb.installed', '0', $entrypoint); $inifile->setValue('jacldb.access', '0', 'modules'); $inifile->save(); $urlsFile = jApp::appConfigPath($inifile->getValue('significantFile', 'urlengine')); $xmlMap = new \Jelix\Routing\UrlMapping\XmlMapModifier($urlsFile, true); $xmlEp = $xmlMap->getEntryPoint($entrypoint); $xmlEp->addUrlAction('/', 'master_admin', 'default:index', null, null, array('default' => true)); $xmlEp->addUrlModule('', 'master_admin'); $xmlEp->addUrlInclude('/admin/acl', 'jacl2db_admin', 'urls.xml'); $xmlEp->addUrlInclude('/admin/auth', 'jauthdb_admin', 'urls.xml'); $xmlEp->addUrlInclude('/admin/pref', 'jpref_admin', 'urls.xml'); $xmlEp->addUrlInclude('/auth', 'jauth', 'urls.xml'); $xmlMap->save(); $reporter = new \Jelix\Installer\Reporter\Console($output->isVerbose() ? 'notice' : 'warning'); $installer = new \Jelix\Installer\Installer($reporter); $installer->installModules(array('jauth', 'master_admin'), $entrypoint . '.php'); $authini = new \Jelix\IniFile\IniModifier(App::configPath($entrypoint . '/auth.coord.ini.php')); $authini->setValue('after_login', 'master_admin~default:index'); $authini->setValue('timeout', '30'); $authini->save(); $profile = $input->getOption('profile'); if (!$input->getOption('noauthdb')) { if ($profile != '') { $authini->setValue('profile', $profile, 'Db'); } $authini->save(); $installer->setModuleParameters('jauthdb', array('defaultuser' => true)); $installer->installModules(array('jauthdb', 'jauthdb_admin'), $entrypoint . '.php'); } else { $installConfig->setValue('jauthdb_admin.installed', '0', $entrypoint); $installConfig->save(); $inifile->setValue('jauthdb_admin.access', '0', 'modules'); $inifile->save(); } if (!$input->getOption('noacl2db')) { if ($profile != '') { $dbini = new \Jelix\IniFile\IniModifier(App::configPath('profiles.ini.php')); $dbini->setValue('jacl2_profile', $profile, 'jdb'); $dbini->save(); } $installer = new \Jelix\Installer\Installer($reporter); $installer->setModuleParameters('jacl2db', array('defaultuser' => true)); $installer->installModules(array('jacl2db', 'jacl2db_admin'), $entrypoint . '.php'); } else { $installConfig->setValue('jacl2db_admin.installed', '0', $entrypoint); $installConfig->save(); $inifile->setValue('jacl2db_admin.access', '0', 'modules'); $inifile->save(); } $installer->installModules(array('jpref_admin'), $entrypoint . '.php'); }