/** * initialize some member */ function __construct($exception = true) { $config = \Jelix\Core\App::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 = \Jelix\Core\App::varPath($config->mailer['filesDir']); $this->copyToFiles = $config->mailer['copyToFiles']; parent::__construct(true); }
/** * @param string $path path to the app directory. If not given * call \Jelix\Core\App to retrieve it. */ function __construct($path = '') { $config = \Jelix\Core\App::config(); if ($config) { $locale = $config->locale; } else { $locale = ''; } if (!$path) { $path = \Jelix\Core\App::appPath(); if (!$path) { throw new \Exception("Jelix Application is not initialized with Jelix\\Core\\App"); } } $this->path = rtrim($path, '/') . '/'; if (file_exists($this->path . 'jelix-app.json')) { $parser = new AppJsonParser($this->path . 'jelix-app.json', $locale); } else { if (file_exists($this->path . 'project.xml')) { $this->isXml = true; $parser = new ProjectXmlParser($this->path . 'project.xml', $locale); } else { return; } } $this->_exists = true; $parser->parse($this); }
/** * @param string $path path to the module directory */ function __construct($path) { $p = rtrim($path, '/'); $this->path = $p . '/'; // by default, the module name is the directory name of the module $this->name = basename($p); $config = \Jelix\Core\App::config(); if ($config) { $locale = $config->locale; } else { $locale = ''; } if (file_exists($this->path . 'jelix-module.json')) { $parser = new ModuleJsonParser($this->path . 'jelix-module.json', $locale); } else { if (file_exists($this->path . 'module.xml')) { $this->isXml = true; $parser = new ModuleXmlParser($this->path . 'module.xml', $locale); } else { return; } } $this->_exists = true; $parser->parse($this); }
public function __construct() { $this->config = \Jelix\Core\App::config()->syslogLogger; $this->catSyslog = array('error' => LOG_ERR, 'warning' => LOG_WARNING, 'notice' => LOG_NOTICE, 'deprecated' => LOG_NOTICE, 'strict' => LOG_NOTICE, 'debug' => LOG_DEBUG); $ident = strtr($this->config['ident'], array('%sapi%' => php_sapi_name(), '%domain%' => \Jelix\Core\App::config()->domainName, '%pid%' => getmypid())); openlog($ident, LOG_ODELAY | LOG_PERROR, $this->config['facility']); }
/** * Loads the resources for a given locale/charset. * @param string $locale the locale * @param string $charset the charset */ protected function _loadLocales($locale, $charset) { $this->_loadedCharset[] = $charset; $source = $this->fic->getPath(); $cache = $this->fic->getCompiledFilePath(); // check if we have a compiled version of the ressources if (is_readable($cache)) { $okcompile = true; if (App::config()->compilation['force']) { $okcompile = false; } else { if (App::config()->compilation['checkCacheFiletime']) { if (is_readable($source) && filemtime($source) > filemtime($cache)) { $okcompile = false; } } } if ($okcompile) { include $cache; $this->_strings[$charset] = $_loaded; return; } } $reader = new \jPropertiesFileReader($source, $charset); $reader->parse(); $this->_strings[$charset] = $reader->getProperties(); $content = '<?php $_loaded= ' . var_export($this->_strings[$charset], true) . ' ?>'; \jFile::write($cache, $content); }
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); } } }
/** * constructor */ function __construct() { if (App::config()->httpVersion != "") { $this->httpVersion = App::config()->httpVersion; $this->forcedHttpVersion = true; } }
public function run() { $this->loadAppConfig(); $config = \Jelix\Core\App::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; } if ($this->getOption('-to-overload')) { $target_dir = \Jelix\Core\App::varPath('overloads/' . $module . '/locales/' . $lang . '/'); } else { $target_dir = \Jelix\Core\App::varPath('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()) { echo "Copy Locales file {$fich} from {$source_dir} to {$target_dir}.\n"; } } } closedir($dir_r); } } }
public function compileItem($sourceFile, $module) { if (is_readable($sourceFile)) { $xml = simplexml_load_file($sourceFile); $config = App::config()->disabledListeners; if (isset($xml->listener)) { foreach ($xml->listener as $listener) { $listenerName = (string) $listener['name']; $selector = $module . '~' . $listenerName; foreach ($listener->event as $eventListened) { $name = (string) $eventListened['name']; if (isset($config[$name])) { if (is_array($config[$name])) { if (in_array($selector, $config[$name])) { continue; } } else { if ($config[$name] == $selector) { continue; } } } // key = event name , value = list of file listener $this->eventList[$name][] = array($module, $listenerName); } } } } return true; }
protected function _createPath() { if (!isset(App::config()->_modulesPathList[$this->module])) { throw new Exception('jelix~errors.selector.module.unknown', $this->toString()); } $this->_path = App::config()->_modulesPathList[$this->module] . $this->_dirname . $this->subpath . $this->className . $this->_suffix; if (!file_exists($this->_path) || strpos($this->subpath, '..') !== false) { // second test for security issues throw new Exception('jelix~errors.selector.invalid.target', array($this->toString(), $this->type)); } }
/** * helper method to retrieve the path of the module. * * @param string $module the name of the module * * @return string the path of the module */ protected function getModulePath($module) { $this->loadAppConfig(); $config = \Jelix\Core\App::config(); if (!isset($config->_modulesPathList[$module])) { if (isset($config->_externalModulesPathList[$module])) { return $config->_externalModulesPathList[$module]; } throw new \Exception($this->getName() . ": The module {$module} doesn't exist"); } return $config->_modulesPathList[$module]; }
/** * @param \Jelix\Routing\ServerResponse $response */ function output($response) { if (!\Jelix\Core\App::router()->request) { return; } $email = \Jelix\Core\App::config()->mailLogger['email']; $headers = str_replace(array('\\r', '\\n'), array("\r", "\n"), \Jelix\Core\App::config()->mailLogger['emailHeaders']); $message = ''; foreach ($this->messages as $msg) { $message .= "\n\n" . $msg->getFormatedMessage(); } error_log(wordwrap($message, 70), 1, $email, $headers); }
/** * @param \Jelix\Logger\MessageInterface $message the message to log */ function logMessage($message) { if (!is_writable(\Jelix\Core\App::logPath())) { return; } $type = $message->getCategory(); $appConf = \Jelix\Core\App::config(); if ($appConf) { $conf =& \Jelix\Core\App::config()->fileLogger; if (!isset($conf[$type])) { return; } $f = $conf[$type]; $f = str_replace('%m%', date("m"), $f); $f = str_replace('%Y%', date("Y"), $f); $f = str_replace('%d%', date("d"), $f); $f = str_replace('%H%', date("H"), $f); } else { $f = 'errors.log'; } $coord = \Jelix\Core\App::router(); if ($coord && $coord->request) { $ip = $coord->request->getIP(); } else { $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1'; } $f = str_replace('%ip%', $ip, $f); try { if (!preg_match("/^([\\w\\.\\/]+)\$/", $f, $m)) { throw new Exception("Invalid file name for file logger name {$f}"); } $file = \Jelix\Core\App::logPath($f); @error_log(date("Y-m-d H:i:s") . "\t" . $ip . "\t{$type}\t" . $message->getFormatedMessage() . "\n", 3, $file); @chmod($file, \Jelix\Core\App::config()->chmodFile); } catch (\Exception $e) { $file = \Jelix\Core\App::logPath('errors.log'); @error_log(date("Y-m-d H:i:s") . "\t" . $ip . "\terror\t" . $e->getMessage() . "\n", 3, $file); @chmod($file, \Jelix\Core\App::config()->chmodFile); } }
protected function _createPath() { if (!isset(App::config()->_modulesPathList[$this->module])) { throw new Exception('jelix~errors.selector.module.unknown', $this->toString(true)); } $this->_path = App::config()->_modulesPathList[$this->module] . $this->_dirname . $this->resource . $this->_suffix; if (!is_readable($this->_path)) { if ($this->type == 'loc') { throw new \Exception('(202) The file of the locale key "' . $this->toString() . '" (charset ' . $this->charset . ', lang ' . $this->locale . ') does not exist'); } elseif ($this->toString() == 'jelix~errors.selector.invalid.target') { throw new \Exception("Jelix Panic ! don't find localization files to show you an other error message !"); } else { throw new Exception('jelix~errors.selector.invalid.target', array($this->toString(), $this->type)); } } }
protected function _createPath() { if (!isset(App::config()->_modulesPathList[$this->module])) { if ($this->module == 'jelix') { throw new Exception('jelix module is not enabled !!'); } throw new \Jelix\Core\Selector\Exception('jelix~errors.selector.module.unknown', $this->toString()); } $locales = array($this->locale); $lang = substr($this->locale, 0, strpos($this->locale, '_')); // FIXME we should drop support of such locales 'en_EN', and supports directory with lang name 'en' // study impact of such changes $generic_locale = $lang . '_' . strtoupper($lang); if ($this->locale !== $generic_locale) { $locales[] = $generic_locale; } foreach ($locales as $locale) { // check if the locale has been overloaded $overloadedPath = App::varPath('overloads/' . $this->module . '/locales/' . $locale . '/' . $this->resource . $this->_suffix); if (is_readable($overloadedPath)) { $this->_path = $overloadedPath; $this->_where = 'overloaded/'; $this->_cacheSuffix = '.' . $locale . '.' . $this->charset . '.php'; return; } // check if the locale is available in the locales directory $localesPath = App::varPath('locales/' . $locale . '/' . $this->module . '/locales/' . $this->resource . $this->_suffix); if (is_readable($localesPath)) { $this->_path = $localesPath; $this->_where = 'locales/'; $this->_cacheSuffix = '.' . $locale . '.' . $this->charset . '.php'; return; } // else check for the original locale file in the module $path = App::config()->_modulesPathList[$this->module] . 'locales/' . $locale . '/' . $this->resource . $this->_suffix; if (is_readable($path)) { $this->_where = 'modules/'; $this->_path = $path; $this->_cacheSuffix = '.' . $locale . '.' . $this->charset . '.php'; return; } } // to avoid infinite loop in a specific lang or charset, we should check if we don't // try to retrieve the same message as the one we use for the exception below, // and if it is this message, it means that the error message doesn't exist // in the specific lang or charset, so we retrieve it in en_EN language and UTF-8 charset if ($this->toString() == 'jelix~errors.selector.invalid.target') { $l = 'en_US'; $c = 'UTF-8'; } else { $l = null; $c = null; } throw new \Jelix\Core\Selector\Exception('jelix~errors.selector.invalid.target', array($this->toString(), "locale"), 1, $l, $c); }
public static function config() { return \Jelix\Core\App::config(); }
/** * extract parameters for the action from the path info. * * @params array $infoparsing we have this array * array( * 0=>'module', * 1=>'action', * 2=>'regexp_pathinfo', * 3=>array('year','month'), // list of dynamic value included in the url, * // alphabetical ascendant order * 4=>array(0, 1..), // list of integer which indicates for each * // dynamic value: 0: urlencode, 1:urlencode except '/', 2:escape, 4: lang, 8: locale * * 5=>array('bla'=>'whatIWant' ), // list of static values * 6=>false or array('secondaries','actions') * 7=>true/false true if https is needed * @params array $matches result of the match with the regexp corresponding to the url * * @return \jUrlAction or null if the handler does not accept the url */ protected function parseGetParams($infoparsing, \jUrl $url, $matches) { list($module, $action, $reg, $dynamicValues, $escapes, $staticValues, $secondariesActions, $needsHttps) = $infoparsing; $params = $url->params; $params['module'] = $module; if ($secondariesActions && isset($params['action'])) { // if the action parameter exists in the current url // and if it is one of secondaries actions, then we keep it // else we take the action indicated in the url mapping if (strpos($params['action'], ':') === false) { $params['action'] = 'default:' . $params['action']; } if (!in_array($params['action'], $secondariesActions) && $action != '') { $params['action'] = $action; } } elseif ($action != '') { if (substr($action, -2) == ':*') { $action = substr($action, 0, -1); // This is an url for a whole controller if (isset($matches[1]) && $matches[1]) { $action .= $matches[1]; } else { $action .= 'index'; } $matches = array(); } // else this is an url for a specific action $params['action'] = $action; } elseif (count($matches) == 2) { // this an url for a whole module if ($matches[1] == '/' || $matches[1] == '') { $params['action'] = 'default:index'; } else { $pathInfoParts = explode('/', $matches[1]); $co = count($pathInfoParts); if ($co == 2) { $params['action'] = $pathInfoParts[1] . ':index'; } else { $params['action'] = $pathInfoParts[1] . ':' . $pathInfoParts[2]; } } $matches = array(); } // let's merge static parameters if ($staticValues) { foreach ($staticValues as $n => $v) { if (!empty($v) && $v[0] == '$') { // special statique value $typeStatic = $v[1]; $v = substr($v, 2); if ($typeStatic == 'l') { App::config()->locale = Locale::langToLocale($v); } elseif ($typeStatic == 'L') { App::config()->locale = $v; } } $params[$n] = $v; } } // now let's read dynamic parameters if (count($matches)) { array_shift($matches); foreach ($dynamicValues as $k => $name) { if (isset($matches[$k])) { if ($escapes[$k] & self::ESCAPE_NON_ASCII) { $params[$name] = \jUrl::unescape($matches[$k]); } else { $params[$name] = $matches[$k]; if ($escapes[$k] & self::ESCAPE_LANG) { $v = $matches[$k]; if (preg_match('/^\\w{2,3}$/', $v, $m)) { App::config()->locale = Locale::langToLocale($v); } else { App::config()->locale = $v; $params[$name] = substr($v, 0, strpos('_')); } } elseif ($escapes[$k] & self::ESCAPE_LOCALE) { $v = $matches[$k]; if (preg_match('/^\\w{2,3}$/', $v, $m)) { App::config()->locale = $params[$name] = Locale::langToLocale($v); } else { App::config()->locale = $v; } } } } } } $urlact = new \jUrlAction($params); $urlact->needsHttps = $needsHttps; return $urlact; }
/** * returns the locale corresponding to a lang. * * The file lang_to_locale give corresponding locale, but you can override these * association into the langToLocale section of the main configuration * @param string $lang a lang code (xx) * @return string the corresponding locale (xx_YY) */ static function langToLocale($lang) { $conf = App::config(); if (isset($conf->langToLocale[$lang])) { return $conf->langToLocale[$lang]; } if (is_null(self::$langToLocale)) { self::$langToLocale = @parse_ini_file(__DIR__ . '/lang_to_locale.ini.php'); } if (isset(self::$langToLocale[$lang])) { return self::$langToLocale[$lang]; } return ''; }
protected function _execute(InputInterface $input, OutputInterface $output) { $module = $input->getArgument('module'); $formName = $input->getArgument('form'); $daoName = $input->getArgument('dao'); require_once JELIX_LIB_PATH . 'dao/jDaoParser.class.php'; $path = $this->getModulePath($module); $formdir = $path . 'forms/'; $this->createDir($formdir); $formfile = strtolower($formName) . '.form.xml'; if ($input->getOption('createlocales')) { $locale_content = ''; $locale_base = $module . '~' . strtolower($formName) . '.form.'; $locale_filename_fr = 'locales/fr_FR/'; $this->createDir($path . $locale_filename_fr); $locale_filename_fr .= strtolower($formName) . '.UTF-8.properties'; $locale_filename_en = 'locales/en_US/'; $this->createDir($path . $locale_filename_en); $locale_filename_en .= strtolower($formName) . '.UTF-8.properties'; $submit = "\n\n<submit ref=\"_submit\">\n\t<label locale='" . $locale_base . "ok' />\n</submit>"; } else { $submit = "\n\n<submit ref=\"_submit\">\n\t<label>ok</label>\n</submit>"; } if ($daoName === null) { if ($input->getOption('createlocales')) { $locale_content = "form.ok=OK\n"; $this->createFile($path . $locale_filename_fr, 'locales.tpl', array('content' => $locale_content), "Locales file"); $this->createFile($path . $locale_filename_en, 'locales.tpl', array('content' => $locale_content), "Locales file"); } $this->createFile($formdir . $formfile, 'module/form.xml.tpl', array('content' => '<!-- add control declaration here -->' . $submit), "Form"); return; } \Jelix\Core\App::config()->startModule = $module; \Jelix\Core\App::pushCurrentModule($module); $tools = \jDb::getConnection()->tools(); // we're going to parse the dao $selector = new \jSelectorDao($daoName, ''); $doc = new \DOMDocument(); $daoPath = $selector->getPath(); if (!$doc->load($daoPath)) { throw new \jException('jelix~daoxml.file.unknown', $daoPath); } if ($doc->documentElement->namespaceURI != JELIX_NAMESPACE_BASE . 'dao/1.0') { throw new \jException('jelix~daoxml.namespace.wrong', array($daoPath, $doc->namespaceURI)); } $parser = new \jDaoParser($selector); $parser->parse(simplexml_import_dom($doc), $tools); // now we generate the form file $properties = $parser->GetProperties(); $table = $parser->GetPrimaryTable(); $content = ''; foreach ($properties as $name => $property) { if (!$property->ofPrimaryTable) { continue; } if ($property->isPK && $property->autoIncrement) { continue; } $attr = ''; if ($property->required) { $attr .= ' required="true"'; } if ($property->defaultValue !== null) { $attr .= ' defaultvalue="' . htmlspecialchars($property->defaultValue) . '"'; } if ($property->maxlength !== null) { $attr .= ' maxlength="' . $property->maxlength . '"'; } if ($property->minlength !== null) { $attr .= ' minlength="' . $property->minlength . '"'; } $datatype = ''; $tag = 'input'; switch ($property->unifiedType) { case 'integer': case 'numeric': $datatype = 'integer'; break; case 'datetime': $datatype = 'datetime'; break; case 'time': $datatype = 'time'; break; case 'date': $datatype = 'date'; break; case 'double': case 'float': $datatype = 'decimal'; break; case 'text': case 'blob': $tag = 'textarea'; break; case 'boolean': $tag = 'checkbox'; break; } if ($datatype != '') { $attr .= ' type="' . $datatype . '"'; } // use database comment to create form's label if ($property->comment != '' && $input->getOption('usecomments')) { if ($input->getOption('createlocales')) { // replace special chars by dot $locale_content .= 'form.' . $name . '=' . htmlspecialchars(utf8_decode($property->comment)) . "\n"; $content .= "\n\n<{$tag} ref=\"{$name}\"{$attr}>\n\t<label locale='" . $locale_base . $name . "' />\n</{$tag}>"; } else { // encoding special chars $content .= "\n\n<{$tag} ref=\"{$name}\"{$attr}>\n\t<label>" . htmlspecialchars($property->comment) . "</label>\n</{$tag}>"; } } else { if ($input->getOption('createlocales')) { $locale_content .= 'form.' . $name . '=' . ucwords(str_replace('_', ' ', $name)) . "\n"; $content .= "\n\n<{$tag} ref=\"{$name}\"{$attr}>\n\t<label locale='" . $locale_base . $name . "' />\n</{$tag}>"; } else { $content .= "\n\n<{$tag} ref=\"{$name}\"{$attr}>\n\t<label>" . ucwords(str_replace('_', ' ', $name)) . "</label>\n</{$tag}>"; } } } if ($input->getOption('createlocales')) { $locale_content .= "form.ok=OK\n"; $this->createFile($path . $locale_filename_fr, 'module/locales.tpl', array('content' => $locale_content), "Locales file"); $this->createFile($path . $locale_filename_en, 'module/locales.tpl', array('content' => $locale_content), "Locales file"); } $this->createFile($formdir . $formfile, 'module/form.xml.tpl', array('content' => $content . $submit), "Form file"); }
/** * return the generic error message (errorMessage in the configuration). * Replaced the %code% pattern in the message by the current error code * @return string */ public function getGenericErrorMessage() { $msg = App::config()->error_handling['errorMessage']; if ($this->errorMessage) { $code = $this->errorMessage->getCode(); } else { $code = ''; } return str_replace('%code%', $code, $msg); }
protected function _createPath() { if (!isset(App::config()->_modulesPathList[$this->module])) { if ($this->module == 'jelix') { throw new Exception('jelix module is not enabled !!'); } throw new \Jelix\Core\Selector\Exception('jelix~errors.selector.module.unknown', $this->toString()); } $this->_cacheSuffix = '.' . $this->locale . '.' . $this->charset . '.php'; // check if the locale has been overloaded in var/ $overloadedPath = App::varPath('overloads/' . $this->module . '/locales/' . $this->locale . '/' . $this->resource . $this->_suffix); if (is_readable($overloadedPath)) { $this->_path = $overloadedPath; $this->_where = 'var/overloaded/'; return; } // check if the locale is available in the locales directory in var/ $localesPath = App::varPath('locales/' . $this->locale . '/' . $this->module . '/locales/' . $this->resource . $this->_suffix); if (is_readable($localesPath)) { $this->_path = $localesPath; $this->_where = 'var/locales/'; return; } // check if the locale has been overloaded in app/ $overloadedPath = App::appPath('app/overloads/' . $this->module . '/locales/' . $this->locale . '/' . $this->resource . $this->_suffix); if (is_readable($overloadedPath)) { $this->_path = $overloadedPath; $this->_where = 'app/overloaded/'; return; } // check if the locale is available in the locales directory in app/ $localesPath = App::appPath('app/locales/' . $this->locale . '/' . $this->module . '/locales/' . $this->resource . $this->_suffix); if (is_readable($localesPath)) { $this->_path = $localesPath; $this->_where = 'app/locales/'; return; } // else check for the original locale file in the module $path = App::config()->_modulesPathList[$this->module] . 'locales/' . $this->locale . '/' . $this->resource . $this->_suffix; if (is_readable($path)) { $this->_where = 'modules/'; $this->_path = $path; return; } // to avoid infinite loop in a specific lang or charset, we should check if we don't // try to retrieve the same message as the one we use for the exception below, // and if it is this message, it means that the error message doesn't exist // in the specific lang or charset, so we retrieve it in en_EN language and UTF-8 charset if ($this->toString() == 'jelix~errors.selector.invalid.target') { $l = 'en_US'; $c = 'UTF-8'; } else { $l = null; $c = null; } throw new \Jelix\Core\Selector\Exception('jelix~errors.selector.invalid.target', array($this->toString(), "locale"), 1, $l, $c); }
protected function cmd_subject_create() { $params = $this->getParam('...'); if (!is_array($params) || count($params) > 4 || count($params) < 2) { throw new Exception("wrong parameter count"); } $cnx = jDb::getConnection('jacl2_profile'); $sql = "SELECT id_aclsbj FROM " . $cnx->prefixTable('jacl2_subject') . " WHERE id_aclsbj=" . $cnx->quote($params[0]); $rs = $cnx->query($sql); if ($rs->fetch()) { throw new Exception("This subject already exists"); } $sql = "INSERT into " . $cnx->prefixTable('jacl2_subject') . " (id_aclsbj, label_key, id_aclsbjgrp) VALUES ("; $sql .= $cnx->quote($params[0]) . ','; $sql .= $cnx->quote($params[1]); if (isset($params[2]) && $params[2] != 'null') { $sql .= ',' . $cnx->quote($params[2]); } else { $sql .= ", NULL"; } $sql .= ')'; $cnx->exec($sql); if ($this->verbose()) { echo "Rights: subject " . $params[0] . " is created."; } if (isset($params[3]) && preg_match("/^([a-zA-Z0-9_\\.]+)~([a-zA-Z0-9_]+)\\.([a-zA-Z0-9_\\.]+)\$/", $params[1], $m)) { $localestring = "\n" . $m[3] . '=' . $params[3]; $path = $this->getModulePath($m[1]); $file = $path . 'locales/' . \Jelix\Core\App::config()->locale . '/' . $m[2] . '.' . \Jelix\Core\App::config()->charset . '.properties'; if (file_exists($file)) { $localestring = file_get_contents($file) . $localestring; } file_put_contents($file, $localestring); if ($this->verbose()) { echo " and locale string " . $m[3] . " is created into " . $file . "\n"; } } else { if ($this->verbose()) { echo "\n"; } } }
/** * return the server port of the application * @return string the ":port" or empty string * @since 1.2.4 */ function getPort($forceHttps = null) { $isHttps = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] && $_SERVER['HTTPS'] != 'off'; if ($forceHttps === null) { $https = $isHttps; } else { $https = $forceHttps; } $forcePort = $https ? App::config()->forceHTTPSPort : App::config()->forceHTTPPort; if ($forcePort === true) { return ''; } else { if ($forcePort) { // a number $port = $forcePort; } else { if ($isHttps != $https || !isset($_SERVER['SERVER_PORT'])) { // the asked protocol is different from the current protocol // we use the standard port for the asked protocol return ''; } else { $port = $_SERVER['SERVER_PORT']; } } } if ($port === NULL || $port == '' || $https && $port == '443' || !$https && $port == '80') { return ''; } return ':' . $port; }
/** * return the list of all listener corresponding to an event * @param string $eventName the event name we wants the listeners for. * @return array of objects */ protected static function loadListenersFor($eventName) { if (!self::$listenersConfig) { self::$compilerData[3] = App::config()->urlengine['urlScriptId'] . '.' . self::$compilerData[3]; self::$listenersConfig = Includer::incAll(self::$compilerData); } $inf =& self::$listenersConfig; self::$hashListened[$eventName] = array(); if (isset($inf[$eventName])) { $modules =& App::config()->_modulesPathList; foreach ($inf[$eventName] as $listener) { list($module, $listenerName) = $listener; if (!isset($modules[$module])) { // some modules could be unused continue; } if (!isset(self::$listenersSingleton[$module][$listenerName])) { require_once $modules[$module] . 'classes/' . $listenerName . '.listener.php'; $className = $listenerName . 'Listener'; self::$listenersSingleton[$module][$listenerName] = new $className(); } self::$hashListened[$eventName][] = self::$listenersSingleton[$module][$listenerName]; } } }
public function run() { $this->loadAppConfig(); $module = $this->_parameters['module']; $path = $this->getModulePath($module); $table = $this->getParam('table'); $ctrlname = $this->getParam('ctrlname', $table); $acl2 = $this->getOption('-acl2'); if (file_exists($path . 'controllers/' . $ctrlname . '.classic.php')) { throw new Exception("controller '" . $ctrlname . "' already exists"); } $agcommand = JelixScript::getCommand('createdao', $this->config); $options = $this->getCommonActiveOption(); $profile = ''; if ($this->getOption('-profile')) { $profile = $this->getOption('-profile'); $options['-profile'] = $profile; } $agcommand->initOptParam($options, array('module' => $module, 'name' => $table, 'table' => $table)); $agcommand->run(); $agcommand = JelixScript::getCommand('createform', $this->config); $options = $this->getCommonActiveOption(); if ($this->getOption('-createlocales')) { $options['-createlocales'] = true; } $agcommand->initOptParam($options, array('module' => $module, 'form' => $table, 'dao' => $table)); $agcommand->run(); $acl2rights = ''; $pluginsParameters = "\n '*' =>array('auth.required'=>true),\n 'index' =>array('jacl2.right'=>'{$module}.{$ctrlname}.view'),\n 'precreate' =>array('jacl2.right'=>'{$module}.{$ctrlname}.create'),\n 'create' =>array('jacl2.right'=>'{$module}.{$ctrlname}.create'),\n 'savecreate' =>array('jacl2.right'=>'{$module}.{$ctrlname}.create'),\n 'preupdate' =>array('jacl2.right'=>'{$module}.{$ctrlname}.update'),\n 'editupdate' =>array('jacl2.right'=>'{$module}.{$ctrlname}.update'),\n 'saveupdate' =>array('jacl2.right'=>'{$module}.{$ctrlname}.update'),\n 'view' =>array('jacl2.right'=>'{$module}.{$ctrlname}.view'),\n 'delete' =>array('jacl2.right'=>'{$module}.{$ctrlname}.delete')"; if ($acl2) { $subjects = array('view' => 'View', 'create' => 'Create', 'update' => 'Update', 'delete' => 'Delete'); $sel = $this->getOption('-acl2locale'); if (!$sel) { $sel = $module . '~acl' . $ctrlname; } foreach ($subjects as $subject => $label) { $subject = $module . "." . $ctrlname . "." . $subject; $labelkey = $sel . '.' . $subject; try { $options = $this->getCommonActiveOption(); $agcommand = JelixScript::getCommand('acl2right', $this->config); $agcommand->initOptParam($options, array('action' => 'subject_create', '...' => array($subject, $labelkey, 'null', $label . ' ' . $ctrlname))); $agcommand->run(); } catch (Exception $e) { } } } else { $pluginsParameters = "/*" . $pluginsParameters . "\n*/"; } $this->createDir($path . 'controllers/'); $params = array('name' => $ctrlname, 'module' => $module, 'table' => $table, 'profile' => $profile, 'acl2rights' => $pluginsParameters); $this->createFile($path . 'controllers/' . $ctrlname . '.classic.php', 'module/controller.daocrud.tpl', $params, "Controller"); if ($this->getOption('-masteradmin')) { if ($acl2) { $params['checkacl2'] = "if(jAcl2::check('{$module}.{$ctrlname}.view'))"; } else { $params['checkacl2'] = ''; } $this->createFile($path . 'classes/' . $ctrlname . 'menu.listener.php', 'module/masteradminmenu.listener.php.tpl', $params, "Listener"); if (file_exists($path . 'events.xml')) { $xml = simplexml_load_file($path . 'events.xml'); $xml->registerXPathNamespace('j', 'http://jelix.org/ns/events/1.0'); $listenerPath = "j:listener[@name='" . $ctrlname . "menu']"; $eventPath = "j:event[@name='masteradminGetMenuContent']"; if (!($event = $xml->xpath("//{$listenerPath}/{$eventPath}"))) { if ($listeners = $xml->xpath("//{$listenerPath}")) { $listener = $listeners[0]; } else { $listener = $xml->addChild('listener'); $listener->addAttribute('name', $ctrlname . 'menu'); } $event = $listener->addChild('event'); $event->addAttribute('name', 'masteradminGetMenuContent'); $result = $xml->asXML($path . 'events.xml'); if ($this->verbose() && $result) { echo "Events.xml in module '" . $this->_parameters['module'] . "' has been updated.\n"; } else { if (!$result) { echo "Warning: events.xml in module '" . $this->_parameters['module'] . "' cannot be updated, check permissions or add the event manually.\n"; } } } else { if ($this->verbose()) { echo "events.xml in module '" . $this->_parameters['module'] . "' is already updated.\n"; } } } else { $this->createFile($path . 'events.xml', 'module/events_crud.xml.tpl', array('classname' => $ctrlname . 'menu')); } } if (\Jelix\Core\App::config()->urlengine['engine'] == 'significant') { if (!file_exists($path . 'urls.xml')) { $this->createFile($path . 'urls.xml', 'module/urls.xml.tpl', array()); if ($this->verbose()) { echo "Notice: you should link the urls.xml of the module " . $this->_parameters['module'] . "', into the urls.xml in var/config.\n"; } } $xml = simplexml_load_file($path . 'urls.xml'); $xml->registerXPathNamespace('j', 'http://jelix.org/ns/suburls/1.0'); // if the url already exists, let's try an other $count = 0; $urlXPath = "//j:url[@pathinfo='/" . $ctrlname . "/']"; while ($url = $xml->xpath("//{$urlXPath}")) { $count++; $urlXPath = "//j:url[@pathinfo='/" . $ctrlname . "-" . $count . "/']"; } if ($count == 0) { $urlPath = "/" . $ctrlname . "/"; } else { $urlPath = "/" . $ctrlname . "-" . $count . "/"; } /* <url pathinfo="/thedata/" action="mycrud:index" /> <url pathinfo="/thedata/view/:id" action="mycrud:view" /> <url pathinfo="/thedata/precreate" action="mycrud:precreate" /> <url pathinfo="/thedata/create" action="mycrud:create" /> <url pathinfo="/thedata/savecreate" action="mycrud:savecreate" /> <url pathinfo="/thedata/preedit/:id" action="mycrud:preupdate" /> <url pathinfo="/thedata/edit/:id" action="mycrud:editupdate" /> <url pathinfo="/thedata/save/:id" action="mycrud:saveupdate" /> <url pathinfo="/thedata/delete/:id" action="mycrud:delete" /> */ $url = $xml->addChild('url'); $url->addAttribute('pathinfo', $urlPath); $url->addAttribute('action', $ctrlname . ':index'); $url = $xml->addChild('url'); $url->addAttribute('pathinfo', $urlPath . "view/:id"); $url->addAttribute('action', $ctrlname . ':view'); $url = $xml->addChild('url'); $url->addAttribute('pathinfo', $urlPath . "precreate"); $url->addAttribute('action', $ctrlname . ':precreate'); $url = $xml->addChild('url'); $url->addAttribute('pathinfo', $urlPath . "create"); $url->addAttribute('action', $ctrlname . ':create'); $url = $xml->addChild('url'); $url->addAttribute('pathinfo', $urlPath . "savecreate"); $url->addAttribute('action', $ctrlname . ':savecreate'); $url = $xml->addChild('url'); $url->addAttribute('pathinfo', $urlPath . "preedit/:id"); $url->addAttribute('action', $ctrlname . ':preupdate'); $url = $xml->addChild('url'); $url->addAttribute('pathinfo', $urlPath . "edit/:id"); $url->addAttribute('action', $ctrlname . ':editupdate'); $url = $xml->addChild('url'); $url->addAttribute('pathinfo', $urlPath . "save/:id"); $url->addAttribute('action', $ctrlname . ':saveupdate'); $url = $xml->addChild('url'); $url->addAttribute('pathinfo', $urlPath . "delete/:id"); $url->addAttribute('action', $ctrlname . ':delete'); $result = $xml->asXML($path . 'urls.xml'); if ($this->verbose() && $result) { echo "urls.xml in module '" . $this->_parameters['module'] . "' has been updated.\n"; } else { if (!$result) { echo "Warning: urls.xml in module '" . $this->_parameters['module'] . "' cannot be updated, check permissions or add the urls manually.\n"; } } } }
/** * indicate if, for the given category, the given logger is activated * @param string $logger the logger name * @param string $category the category * @return boolean true if it is activated */ public static function isPluginActivated($logger, $category) { $confLog =& \Jelix\Core\App::config()->logger; $loggers = preg_split('/[\\s,]+/', $confLog['_all']); if (in_array($logger, $loggers)) { return true; } if (!isset($confLog[$category])) { return false; } $loggers = preg_split('/[\\s,]+/', $confLog[$category]); return in_array($logger, $loggers); }