Example #1
0
 /**
  * set
  *
  * @param string $key	a key (unique name) to identify the cached info
  * @param mixed  $value	the value to cache
  * @param integer $ttl how many seconds will the info be cached
  *
  * @return boolean whether the action was successful or not
  */
 public function set($key, $value, $ttl)
 {
     $r = false;
     if ($fl = @fopen($this->dir . '/.flock', 'w+')) {
         if (flock($fl, LOCK_EX)) {
             // mutex zone
             $md5 = md5($key);
             $subdir = $md5[0] . $md5[1];
             if (!file_exists($this->dir . '/' . $subdir)) {
                 jFile::createDir($this->dir . '/' . $subdir);
             }
             // write data to cache
             $fn = $this->dir . '/' . $subdir . '/' . $md5;
             if ($f = @gzopen($fn . '.tmp', 'w')) {
                 // write temporary file
                 fputs($f, base64_encode(serialize($value)));
                 fclose($f);
                 // change time of the file to the expiry time
                 @touch("{$fn}.tmp", time() + $ttl);
                 // rename the temporary file
                 $r = @rename("{$fn}.tmp", $fn);
             }
             // end of mutex zone
             flock($fl, LOCK_UN);
         }
     }
     return $r;
 }
 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);
         }
     }
 }
Example #3
0
 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);
         }
     }
 }
Example #4
0
 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']);
     }
 }
Example #5
0
 protected function loadProfile()
 {
     try {
         jProfiles::get('jcache', 'jforms', true);
     } catch (Exception $e) {
         // no profile, let's create a default profile
         $cacheDir = jApp::tempPath('jforms');
         jFile::createDir($cacheDir);
         $params = array('enabled' => 1, 'driver' => 'file', 'ttl' => 3600 * 48, 'automatic_cleaning_factor' => 3, 'cache_dir' => $cacheDir, 'directory_level' => 3);
         jProfiles::createVirtualProfile('jcache', 'jforms', $params);
     }
 }
 public static function readAndCache($configFile, $isCli = null, $pseudoScriptName = '')
 {
     if ($isCli === null) {
         $isCli = jServer::isCLI();
     }
     $config = self::read($configFile, false, $isCli, $pseudoScriptName);
     $tempPath = jApp::tempPath();
     jFile::createDir($tempPath);
     if (BYTECODE_CACHE_EXISTS) {
         $filename = $tempPath . str_replace('/', '~', $configFile) . '.conf.php';
         if ($f = @fopen($filename, 'wb')) {
             fwrite($f, '<?php $config = ' . var_export(get_object_vars($config), true) . ";\n?>");
             fclose($f);
         } else {
             throw new Exception('Error while writing configuration cache file -- ' . $filename);
         }
     } else {
         jIniFile::write(get_object_vars($config), $tempPath . str_replace('/', '~', $configFile) . '.resultini.php', ";<?php die('');?>\n");
     }
     return $config;
 }
Example #7
0
 public function set($key, $value, $ttl)
 {
     $r = false;
     if ($fl = @fopen($this->dir . '/.flock', 'w+')) {
         if (flock($fl, LOCK_EX)) {
             $md5 = md5($key);
             $subdir = $md5[0] . $md5[1];
             if (!file_exists($this->dir . '/' . $subdir)) {
                 jFile::createDir($this->dir . '/' . $subdir);
             }
             $fn = $this->dir . '/' . $subdir . '/' . $md5;
             if ($f = @gzopen($fn . '.tmp', 'w')) {
                 fputs($f, base64_encode(serialize($value)));
                 fclose($f);
                 @touch("{$fn}.tmp", time() + $ttl);
                 $r = @rename("{$fn}.tmp", $fn);
             }
             flock($fl, LOCK_UN);
         }
     }
     return $r;
 }
Example #8
0
 public function __construct($params)
 {
     $this->profil_name = $params['_name'];
     if (isset($params['enabled'])) {
         $this->enabled = $params['enabled'] ? true : false;
     }
     if (isset($params['ttl'])) {
         $this->ttl = $params['ttl'];
     }
     $this->_cache_dir = jApp::tempPath('cache/') . $this->profil_name . '/';
     if (isset($params['cache_dir']) && $params['cache_dir'] != '') {
         if (is_dir($params['cache_dir']) && is_writable($params['cache_dir'])) {
             $this->_cache_dir = rtrim(realpath($params['cache_dir']), '\\/') . DIRECTORY_SEPARATOR;
         } else {
             throw new jException('jelix~cache.directory.not.writable', $this->profil_name);
         }
     } else {
         jFile::createDir($this->_cache_dir);
     }
     if (isset($params['file_locking'])) {
         $this->_file_locking = $params['file_locking'] ? true : false;
     }
     if (isset($params['automatic_cleaning_factor'])) {
         $this->automatic_cleaning_factor = $params['automatic_cleaning_factor'];
     }
     if (isset($params['directory_level']) && $params['directory_level'] > 0) {
         $this->_directory_level = $params['directory_level'];
     }
     if (isset($params['directory_umask']) && is_string($params['directory_umask']) && $params['directory_umask'] != '') {
         $this->_directory_umask = octdec($params['directory_umask']);
     }
     if (isset($params['file_name_prefix'])) {
         $this->_file_name_prefix = $params['file_name_prefix'];
     }
     if (isset($params['cache_file_umask']) && is_string($params['cache_file_umask']) && $params['cache_file_umask'] != '') {
         $this->_cache_file_umask = octdec($params['cache_file_umask']);
     }
 }
Example #9
0
 /**
  * Identical to read(), but also stores the result in a temporary file
  * @return object an object which contains configuration values
  */
 public function readAndCache()
 {
     $config = $this->read(false);
     $tempPath = App::tempPath();
     \jFile::createDir($tempPath, $config->chmodDir);
     $filename = $tempPath . str_replace('/', '~', $this->configFileName);
     if (BYTECODE_CACHE_EXISTS) {
         $filename .= '.conf.php';
         if ($f = @fopen($filename, 'wb')) {
             fwrite($f, '<?php $config = ' . var_export(get_object_vars($config), true) . ";\n?>");
             fclose($f);
             chmod($filename, $config->chmodFile);
         } else {
             throw new Exception('Error while writing configuration cache file -- ' . $filename);
         }
     } else {
         IniFileMgr::write(get_object_vars($config), $filename . '.resultini.php', ";<?php die('');?>\n", '', $config->chmodFile);
     }
     return $config;
 }
 public static function createVirtualProfile($repository, $project, $layers, $crs)
 {
     // Set cache configuration
     $cacheName = 'lizmapCache_' . $repository . '_' . $project . '_' . $layers . '_' . $crs;
     if (array_key_exists($cacheName, self::$_profiles)) {
         return $cacheName;
     }
     // Storage type
     $ser = lizmap::getServices();
     $cacheStorageType = $ser->cacheStorageType;
     // Expiration time : take default one
     $cacheExpiration = (int) $ser->cacheExpiration;
     // Cache root directory
     if ($cacheStorageType != 'redis') {
         $cacheRootDirectory = $ser->cacheRootDirectory;
         if (!is_writable($cacheRootDirectory) or !is_dir($cacheRootDirectory)) {
             $cacheRootDirectory = sys_get_temp_dir();
         }
     }
     if ($cacheStorageType == 'file') {
         // CACHE CONTENT INTO FILE SYSTEM
         // Directory where to store the cached files
         $cacheDirectory = $cacheRootDirectory . '/' . $repository . '/' . $project . '/' . $layers . '/' . $crs . '/';
         // Create directory if needed
         jFile::createDir($cacheDirectory);
         // Virtual cache profile parameter
         $cacheParams = array("driver" => "file", "cache_dir" => $cacheDirectory, "file_locking" => True, "directory_level" => "5", "file_name_prefix" => "lizmap_", "ttl" => $cacheExpiration);
         // Create the virtual cache profile
         jProfiles::createVirtualProfile('jcache', $cacheName, $cacheParams);
     } elseif ($cacheStorageType == 'redis') {
         // CACHE CONTENT INTO REDIS
         self::declareRedisProfile($ser, $cacheName, $repository, $project, $layers, $crs);
     } else {
         // CACHE CONTENT INTO SQLITE DATABASE
         // Directory where to store the sqlite database
         $cacheDirectory = $cacheRootDirectory . '/' . $repository . '/' . $project . '/';
         jFile::createDir($cacheDirectory);
         // Create directory if needed
         $cacheDatabase = $cacheDirectory . $layers . '_' . $crs . '.db';
         $cachePdoDsn = 'sqlite:' . $cacheDatabase;
         // Create database and populate with table if needed
         if (!file_exists($cacheDatabase)) {
             copy(jApp::varPath() . "cacheTemplate.db", $cacheDatabase);
         }
         // Virtual jdb profile corresponding to the layer database
         $jdbParams = array("driver" => "pdo", "dsn" => $cachePdoDsn, "user" => "cache", "password" => "cache");
         // Create the virtual jdb profile
         $cacheJdbName = "jdb_" . $cacheName;
         jProfiles::createVirtualProfile('jdb', $cacheJdbName, $jdbParams);
         // Virtual cache profile parameter
         $cacheParams = array("driver" => "db", "dbprofile" => $cacheJdbName, "ttl" => $cacheExpiration, "base64encoding" => true);
         // Create the virtual cache profile
         jProfiles::createVirtualProfile('jcache', $cacheName, $cacheParams);
     }
     self::$_profiles[$cacheName] = true;
     return $cacheName;
 }
Example #11
0
 protected function migrate_1_7_0()
 {
     $this->reporter->message('Start migration to 1.7.0', 'notice');
     $newConfigPath = App::appConfigPath();
     if (!file_exists($newConfigPath)) {
         $this->reporter->message('Create app/config/', 'notice');
         \jFile::createDir($newConfigPath);
     }
     // move mainconfig.php to app/config/
     if (!file_exists($newConfigPath . 'mainconfig.ini.php')) {
         if (!file_exists(App::configPath('mainconfig.ini.php'))) {
             if (!file_exists(App::configPath('defaultconfig.ini.php'))) {
                 throw new \Exception("Migration to Jelix 1.7.0 canceled: where is your mainconfig.ini.php?");
             }
             $this->reporter->message('Move var/config/defaultconfig.ini.php to app/config/mainconfig.ini.php', 'notice');
             rename(App::configPath('defaultconfig.ini.php'), $newConfigPath . 'mainconfig.ini.php');
         } else {
             $this->reporter->message('Move var/config/mainconfig.ini.php to app/config/', 'notice');
             rename(App::configPath('mainconfig.ini.php'), $newConfigPath . 'mainconfig.ini.php');
         }
     }
     // move entrypoint configs to app/config
     $projectxml = simplexml_load_file(App::appPath('project.xml'));
     // read all entry points data
     foreach ($projectxml->entrypoints->entry as $entrypoint) {
         $configFile = (string) $entrypoint['config'];
         $dest = App::appConfigPath($configFile);
         if (!file_exists($dest)) {
             if (!file_exists(App::configPath($configFile))) {
                 $this->reporter->message("Config file var/config/{$configFile} indicated in project.xml, does not exist", 'warning');
                 continue;
             }
             $this->reporter->message("Move var/config/{$configFile} to app/config/", 'notice');
             \jFile::createDir(dirname($dest));
             rename(App::configPath($configFile), $dest);
         }
         $config = parse_ini_file(App::appConfigPath($configFile), true);
         if (isset($config['urlengine']['significantFile'])) {
             $urlFile = $config['urlengine']['significantFile'];
             if (!file_exists(App::appConfigPath($urlFile)) && file_exists(App::configPath($urlFile))) {
                 $this->reporter->message("Move var/config/{$urlFile} to app/config/", 'notice');
                 rename(App::configPath($urlFile), App::appConfigPath($urlFile));
             }
         }
     }
     // move urls.xml to app/config
     $mainconfig = parse_ini_file(App::appConfigPath('mainconfig.ini.php'), true);
     if (isset($mainconfig['urlengine']['significantFile'])) {
         $urlFile = $mainconfig['urlengine']['significantFile'];
     } else {
         $urlFile = 'urls.xml';
     }
     if (!file_exists(App::appConfigPath($urlFile)) && file_exists(App::configPath($urlFile))) {
         $this->reporter->message("Move var/config/{$urlFile} to app/config/", 'notice');
         rename(App::configPath($urlFile), App::appConfigPath($urlFile));
     }
     $this->reporter->message('Migration to 1.7.0 is done', 'notice');
     if (!file_exists(App::appPath('app/responses'))) {
         $this->reporter->message("Move responses/ to app/responses/", 'notice');
         rename(App::appPath('responses'), App::appPath('app/responses'));
     }
 }
Example #12
0
 /**
  * save all uploaded file in the given directory
  * @param string $path path of the directory where to store the file. If it is not given,
  *                     it will be stored under the var/uploads/_modulename~formname_/ directory
  */
 public function saveAllFiles($path = '')
 {
     if ($path == '') {
         $path = JELIX_APP_VAR_PATH . 'uploads/' . $this->sel . '/';
     } else {
         if (substr($path, -1, 1) != '/') {
             $path .= '/';
         }
     }
     if (count($this->uploads)) {
         jFile::createDir($path);
     }
     foreach ($this->uploads as $ref => $ctrl) {
         if (!isset($_FILES[$ref]) || $_FILES[$ref]['error'] != UPLOAD_ERR_OK) {
             continue;
         }
         if ($ctrl->maxsize && $_FILES[$ref]['size'] > $ctrl->maxsize) {
             continue;
         }
         move_uploaded_file($_FILES[$ref]['tmp_name'], $path . $_FILES[$ref]['name']);
     }
 }
 /**
  * @param string $sourcePath
  * @param string $targetPath
  */
 static function copyDirectoryContent($sourcePath, $targetPath)
 {
     jFile::createDir($targetPath);
     $dir = new DirectoryIterator($sourcePath);
     foreach ($dir as $dirContent) {
         if ($dirContent->isFile()) {
             copy($dirContent->getPathName(), $targetPath . substr($dirContent->getPathName(), strlen($dirContent->getPath())));
         } else {
             if (!$dirContent->isDot() && $dirContent->isDir()) {
                 $newTarget = $targetPath . substr($dirContent->getPathName(), strlen($dirContent->getPath()));
                 $this->copyDirectoryContent($dirContent->getPathName(), $newTarget);
             }
         }
     }
 }
Example #14
0
 /**
  * initialize the installation
  *
  * it reads configurations files of all entry points, and prepare object for
  * each module, needed to install/upgrade modules.
  * @param ReporterInterface $reporter  object which is responsible to process messages (display, storage or other..)
  * @param string $lang  the language code for messages
  */
 function __construct(ReporterInterface $reporter, $lang = '')
 {
     $this->reporter = $reporter;
     $this->messages = new Checker\Messages($lang);
     $localConfig = App::configPath('localconfig.ini.php');
     if (!file_exists($localConfig)) {
         $localConfigDist = App::configPath('localconfig.ini.php.dist');
         if (file_exists($localConfigDist)) {
             copy($localConfigDist, $localConfig);
         } else {
             file_put_contents($localConfig, ';<' . '?php die(\'\');?' . '>');
         }
     }
     $this->mainConfig = new \Jelix\IniFile\MultiIniModifier(\Jelix\Core\Config::getDefaultConfigFile(), App::mainConfigFile());
     $this->localConfig = new \Jelix\IniFile\MultiIniModifier($this->mainConfig, $localConfig);
     $this->installerIni = $this->getInstallerIni();
     $urlfile = App::appConfigPath($this->localConfig->getValue('significantFile', 'urlengine'));
     $this->xmlMapFile = new \Jelix\Routing\UrlMapping\XmlMapModifier($urlfile, true);
     $appInfos = new \Jelix\Core\Infos\AppInfos();
     $this->readEntryPointsData($appInfos);
     $this->installerIni->save();
     // be sure temp path is ready
     $chmod = $this->mainConfig->getValue('chmodDir');
     \jFile::createDir(App::tempPath(), intval($chmod, 8));
 }
Example #15
0
 /**
  * copy a file from the install/ directory to an other
  * @param string $relativeSourcePath relative path to the install/ directory of the file to copy
  * @param string $targetPath the full path where to copy the file
  */
 protected final function copyFile($relativeSourcePath, $targetPath, $overwrite = false)
 {
     $targetPath = $this->expandPath($targetPath);
     if (!$overwrite && file_exists($targetPath)) {
         return;
     }
     $dir = dirname($targetPath);
     \jFile::createDir($dir);
     copy($this->path . 'install/' . $relativeSourcePath, $targetPath);
 }
Example #16
0
 /**
 Returns feedParser object from cache if present or write it to cache and
 returns result.
 
 @param	url		<b>string</b>		Feed URL
 @return	<b>feedParser</b>
 */
 protected function withCache($url)
 {
     $url_md5 = md5($url);
     $cached_file = sprintf('%s/%s/%s/%s/%s.php', $this->cache_dir, $this->cache_file_prefix, substr($url_md5, 0, 2), substr($url_md5, 2, 2), $url_md5);
     $may_use_cached = false;
     if (@file_exists($cached_file)) {
         $may_use_cached = true;
         $ts = @filemtime($cached_file);
         if ($ts > strtotime($this->cache_ttl)) {
             # Direct cache
             return unserialize(file_get_contents($cached_file));
         }
         $this->setValidator('IfModifiedSince', $ts);
     }
     if (!$this->getFeed($url)) {
         if ($may_use_cached) {
             # connection failed - fetched from cache
             return unserialize(file_get_contents($cached_file));
         }
         return false;
     }
     switch ($this->getStatus()) {
         case '304':
             @files::touch($cached_file);
             return unserialize(file_get_contents($cached_file));
         case '200':
             if ($feed = new feedParser($this->getContent())) {
                 try {
                     jFile::createDir(dirname($cached_file), true);
                 } catch (Exception $e) {
                     return $feed;
                 }
                 if ($fp = @fopen($cached_file, 'wb')) {
                     fwrite($fp, serialize($feed));
                     fclose($fp);
                     //files::inheritChmod($cached_file);
                 }
                 return $feed;
             }
     }
     return false;
 }
Example #17
0
 /**
  * @param \Jelix\IniFile\MultiIniModifier $mainConfig   the mainconfig.ini.php file combined with defaultconfig.ini.php
  * @param \Jelix\IniFile\MultiIniModifier $localConfig   the localconfig.ini.php file combined with $mainConfig
  * @param string $configFile the path of the configuration file, relative
  *                           to the app/config directory
  * @param string $file the filename of the entry point
  * @param string $type type of the entry point ('classic', 'cli', 'xmlrpc'....)
  */
 function __construct(\Jelix\IniFile\MultiIniModifier $mainConfig, \Jelix\IniFile\MultiIniModifier $localConfig, $configFile, $file, $type)
 {
     $this->type = $type;
     $this->isCliScript = $type == 'cmdline';
     $this->configFile = $configFile;
     $this->scriptName = $this->isCliScript ? $file : '/' . $file;
     $this->file = $file;
     $this->mainConfigIni = $mainConfig;
     $this->localConfigIni = $localConfig;
     $appConfigPath = \Jelix\Core\App::appConfigPath($configFile);
     if (!file_exists($appConfigPath)) {
         \jFile::createDir(dirname($appConfigPath));
         file_put_contents($appConfigPath, ';<' . '?php die(\'\');?' . '>');
     }
     $this->epConfigIni = new \Jelix\IniFile\IniModifier($appConfigPath);
     $varConfigPath = \Jelix\Core\App::configPath($configFile);
     if (!file_exists($varConfigPath)) {
         \jFile::createDir(dirname($varConfigPath));
         file_put_contents($varConfigPath, ';<' . '?php die(\'\');?' . '>');
     }
     $this->localEpConfigIni = new \Jelix\IniFile\IniModifier($varConfigPath);
     $this->fullConfigIni = new \Jelix\IniFile\MultiIniModifier($localConfig, $this->epConfigIni);
     $this->fullConfigIni = new \Jelix\IniFile\MultiIniModifier($this->fullConfigIni, $this->localEpConfigIni);
     $compiler = new \Jelix\Core\Config\Compiler($configFile, $this->scriptName, $this->isCliScript);
     $this->config = $compiler->read(true);
     $this->modulesInfos = $compiler->getModulesInfos();
 }
Example #18
0
 /**
  * transform source image file (given parameters) and cache result
  * @param string $src the url of image (myapp/www/):string.[gif|jpeg|jpg|jpe|xpm|xbm|wbmp|png]
  * @param string image's hashname
  * @param array $params parameters specifying transformations
  **/
 protected static function transformAndCache($src, $cacheName, $params)
 {
     $mimes = array('gif' => 'image/gif', 'png' => 'image/png', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'xpm' => 'image/x-xpixmap', 'xbm' => 'image/x-xbitmap', 'wbmp' => 'image/vnd.wap.wbmp');
     global $gJConfig;
     $srcUri = 'http' . (empty($_SERVER['HTTPS']) ? '' : 's') . '://' . $_SERVER['HTTP_HOST'] . $gJConfig->urlengine['basePath'] . $src;
     $srcFs = JELIX_APP_WWW_PATH . $src;
     $path_parts = pathinfo($srcUri);
     $mimeType = $mimes[strtolower($path_parts['extension'])];
     $quality = !empty($params['quality']) ? $params['quality'] : 100;
     // Creating an image
     switch ($mimeType) {
         case 'image/gif':
             $image = imagecreatefromgif($srcFs);
             break;
         case 'image/jpeg':
             $image = imagecreatefromjpeg($srcFs);
             break;
         case 'image/png':
             $image = imagecreatefrompng($srcFs);
             break;
         case 'image/vnd.wap.wbmp':
             $image = imagecreatefromwbmp($srcFs);
             break;
         case 'image/image/x-xbitmap':
             $image = imagecreatefromxbm($srcFs);
             break;
         case 'image/x-xpixmap':
             $image = imagecreatefromxpm($srcFs);
             break;
         default:
             return;
     }
     if (!empty($params['maxwidth']) && !empty($params['maxheight'])) {
         $origWidth = imagesx($image);
         $origHeight = imagesy($image);
         $constWidth = $params['maxwidth'];
         $constHeight = $params['maxheight'];
         $ratio = imagesx($image) / imagesy($image);
         if ($origWidth < $constWidth && $origHeight < $constHeight) {
             $params['width'] = $origWidth;
             $params['height'] = $origHeight;
         } else {
             $ratioHeight = $constWidth / $ratio;
             $ratioWidth = $constHeight * $ratio;
             if ($ratioWidth > $constWidth) {
                 $constHeight = $ratioHeight;
             } else {
                 if ($ratioHeight > $constHeight) {
                     $constWidth = $ratioWidth;
                 }
             }
             $params['width'] = $constWidth;
             $params['height'] = $constHeight;
         }
     }
     if (!empty($params['width']) || !empty($params['height'])) {
         $ancienimage = $image;
         $resampleheight = imagesy($ancienimage);
         $resamplewidth = imagesx($ancienimage);
         $posx = 0;
         $posy = 0;
         if (empty($params['width'])) {
             $finalheight = $params['height'];
             $finalwidth = $finalheight * imagesx($ancienimage) / imagesy($ancienimage);
         } else {
             if (empty($params['height'])) {
                 $finalwidth = $params['width'];
                 $finalheight = $finalwidth * imagesy($ancienimage) / imagesx($ancienimage);
             } else {
                 $finalwidth = $params['width'];
                 $finalheight = $params['height'];
                 if (!empty($params['omo']) && $params['omo'] == 'true') {
                     if ($params['width'] >= $params['height']) {
                         $resampleheight = $resamplewidth * $params['height'] / $params['width'];
                     } else {
                         $resamplewidth = $resampleheight * $params['width'] / $params['height'];
                     }
                 }
             }
         }
         if (!empty($params['zoom'])) {
             $resampleheight /= 100 / $params['zoom'];
             $resamplewidth /= 100 / $params['zoom'];
         }
         $posx = imagesx($ancienimage) / 2 - $resamplewidth / 2;
         $posy = imagesy($ancienimage) / 2 - $resampleheight / 2;
         if (!empty($params['alignh'])) {
             if ($params['alignh'] == 'left') {
                 $posx = 0;
             } else {
                 if ($params['alignh'] == 'right') {
                     $posx = -($resamplewidth - imagesx($ancienimage));
                 } else {
                     if ($params['alignh'] != 'center') {
                         $posx = -$params['alignh'];
                     }
                 }
             }
         }
         if (!empty($params['alignv'])) {
             if ($params['alignv'] == 'top') {
                 $posy = 0;
             } else {
                 if ($params['alignv'] == 'bottom') {
                     $posy = -($resampleheight - imagesy($ancienimage));
                 } else {
                     if ($params['alignv'] != 'center') {
                         $posy = -$params['alignv'];
                     }
                 }
             }
         }
         $image = imagecreatetruecolor($finalwidth, $finalheight);
         imagesavealpha($image, true);
         $tp = imagecolorallocatealpha($image, 0, 0, 0, 127);
         imagefill($image, 0, 0, $tp);
         imagecopyresampled($image, $ancienimage, 0, 0, $posx, $posy, imagesx($image), imagesy($image), $resamplewidth, $resampleheight);
     }
     // The shadow cast adds to the dimension of the image chooses
     if (!empty($params['shadow'])) {
         $image = self::createShadow($image, $params);
     }
     // Background
     if (!empty($params['background'])) {
         $params['background'] = str_replace('#', '', $params['background']);
         $rgb = array(0, 0, 0);
         for ($x = 0; $x < 3; $x++) {
             $rgb[$x] = hexdec(substr($params['background'], 2 * $x, 2));
         }
         $fond = imagecreatetruecolor(imagesx($image), imagesy($image));
         imagefill($fond, 0, 0, imagecolorallocate($fond, $rgb[0], $rgb[1], $rgb[2]));
         imagecopy($fond, $image, 0, 0, 0, 0, imagesx($image), imagesy($image));
         $image = $fond;
     }
     $cachePath = JELIX_APP_WWW_PATH . 'cache/images/';
     jFile::createDir($cachePath);
     // Register
     switch ($mimeType) {
         case 'image/gif':
             imagegif($image, $cachePath . $cacheName);
             break;
         case 'image/jpeg':
             imagejpeg($image, $cachePath . $cacheName, $quality);
             break;
         default:
             imagepng($image, $cachePath . $cacheName);
     }
     // Destruction
     @imagedestroy($image);
 }
 /**
  * transform source image file (given parameters) and store the result into an other file
  * @param string $srcFs the path to the image to transform. [gif|jpeg|jpg|jpe|xpm|xbm|wbmp|png]
  * @param string $targetPath  the path of the directory to store the resulting image
  * @param string $targetName the filename of the resulting image
  * @param array $params parameters specifying transformations
  */
 public static function transformImage($srcFs, $targetPath, $targetName, $params)
 {
     $path_parts = pathinfo($srcFs);
     $mimeType = self::$mimes[strtolower($path_parts['extension'])];
     $quality = !empty($params['quality']) ? $params['quality'] : 100;
     // Creating an image
     switch ($mimeType) {
         case 'image/gif':
             $image = imagecreatefromgif($srcFs);
             break;
         case 'image/jpeg':
             $image = imagecreatefromjpeg($srcFs);
             break;
         case 'image/png':
             $image = imagecreatefrompng($srcFs);
             break;
         case 'image/vnd.wap.wbmp':
             $image = imagecreatefromwbmp($srcFs);
             break;
         case 'image/image/x-xbitmap':
             $image = imagecreatefromxbm($srcFs);
             break;
         case 'image/x-xpixmap':
             $image = imagecreatefromxpm($srcFs);
             break;
         default:
             return;
     }
     if (!empty($params['maxwidth']) && !empty($params['maxheight'])) {
         $origWidth = imagesx($image);
         $origHeight = imagesy($image);
         $constWidth = $params['maxwidth'];
         $constHeight = $params['maxheight'];
         $ratio = imagesx($image) / imagesy($image);
         if ($origWidth < $constWidth && $origHeight < $constHeight) {
             $params['width'] = $origWidth;
             $params['height'] = $origHeight;
         } else {
             $ratioHeight = $constWidth / $ratio;
             $ratioWidth = $constHeight * $ratio;
             if ($ratioWidth > $constWidth) {
                 $constHeight = $ratioHeight;
             } else {
                 if ($ratioHeight > $constHeight) {
                     $constWidth = $ratioWidth;
                 }
             }
             $params['width'] = $constWidth;
             $params['height'] = $constHeight;
         }
     }
     if (!empty($params['width']) || !empty($params['height'])) {
         $ancienimage = $image;
         $resampleheight = imagesy($ancienimage);
         $resamplewidth = imagesx($ancienimage);
         $posx = 0;
         $posy = 0;
         if (empty($params['width'])) {
             $finalheight = $params['height'];
             $finalwidth = $finalheight * imagesx($ancienimage) / imagesy($ancienimage);
         } else {
             if (empty($params['height'])) {
                 $finalwidth = $params['width'];
                 $finalheight = $finalwidth * imagesy($ancienimage) / imagesx($ancienimage);
             } else {
                 $finalwidth = $params['width'];
                 $finalheight = $params['height'];
                 if (!empty($params['omo']) && $params['omo'] == 'true') {
                     if ($params['width'] >= $params['height']) {
                         $resampleheight = $resamplewidth * $params['height'] / $params['width'];
                     } else {
                         $resamplewidth = $resampleheight * $params['width'] / $params['height'];
                     }
                 }
             }
         }
         if (!empty($params['zoom'])) {
             $resampleheight /= 100 / $params['zoom'];
             $resamplewidth /= 100 / $params['zoom'];
         }
         $posx = imagesx($ancienimage) / 2 - $resamplewidth / 2;
         $posy = imagesy($ancienimage) / 2 - $resampleheight / 2;
         if (!empty($params['alignh'])) {
             if ($params['alignh'] == 'left') {
                 $posx = 0;
             } else {
                 if ($params['alignh'] == 'right') {
                     $posx = -($resamplewidth - imagesx($ancienimage));
                 } else {
                     if ($params['alignh'] != 'center') {
                         $posx = -$params['alignh'];
                     }
                 }
             }
         }
         if (!empty($params['alignv'])) {
             if ($params['alignv'] == 'top') {
                 $posy = 0;
             } else {
                 if ($params['alignv'] == 'bottom') {
                     $posy = -($resampleheight - imagesy($ancienimage));
                 } else {
                     if ($params['alignv'] != 'center') {
                         $posy = -$params['alignv'];
                     }
                 }
             }
         }
         $image = imagecreatetruecolor($finalwidth, $finalheight);
         imagesavealpha($image, true);
         $tp = imagecolorallocatealpha($image, 0, 0, 0, 127);
         imagecopyresampled($image, $ancienimage, 0, 0, $posx, $posy, imagesx($image), imagesy($image), $resamplewidth, $resampleheight);
         imagefill($image, 0, 0, $tp);
         // Because of a strange behavior (ticket #1486), we must fill the background AFTER imagecopyresampled
     }
     // The shadow cast adds to the dimension of the image chooses
     if (!empty($params['shadow'])) {
         $image = self::createShadow($image, $params);
     }
     // Background
     if (!empty($params['background'])) {
         $params['background'] = str_replace('#', '', $params['background']);
         $rgb = array(0, 0, 0);
         for ($x = 0; $x < 3; $x++) {
             $rgb[$x] = hexdec(substr($params['background'], 2 * $x, 2));
         }
         $fond = imagecreatetruecolor(imagesx($image), imagesy($image));
         imagefill($fond, 0, 0, imagecolorallocate($fond, $rgb[0], $rgb[1], $rgb[2]));
         imagecopy($fond, $image, 0, 0, 0, 0, imagesx($image), imagesy($image));
         $image = $fond;
     }
     jFile::createDir($targetPath);
     // Register
     switch ($mimeType) {
         case 'image/gif':
             imagegif($image, $targetPath . $targetName);
             break;
         case 'image/jpeg':
             imagejpeg($image, $targetPath . $targetName, $quality);
             break;
         default:
             imagepng($image, $targetPath . $targetName);
     }
     chmod($targetPath . $targetName, jApp::config()->chmodFile);
     // Destruction
     @imagedestroy($image);
 }
Example #20
0
 /**
  * initialize the installation
  *
  * it reads configurations files of all entry points, and prepare object for
  * each module, needed to install/upgrade modules.
  * @param ReporterInterface $reporter  object which is responsible to process messages (display, storage or other..)
  * @param string $lang  the language code for messages
  */
 function __construct(ReporterInterface $reporter, $lang = '')
 {
     $this->reporter = $reporter;
     $this->messages = new Checker\Messages($lang);
     $this->mainConfig = new \Jelix\IniFile\IniModifier(App::mainConfigFile());
     $localConfig = App::configPath('localconfig.ini.php');
     if (!file_exists($localConfig)) {
         $localConfigDist = App::configPath('localconfig.ini.php.dist');
         if (file_exists($localConfigDist)) {
             copy($localConfigDist, $localConfig);
         } else {
             file_put_contents($localConfig, ';<' . '?php die(\'\');?' . '>');
         }
     }
     $this->localConfig = new \Jelix\IniFile\MultiIniModifier($this->mainConfig, $localConfig);
     $this->installerIni = $this->getInstallerIni();
     $appInfos = new \Jelix\Core\Infos\AppInfos();
     $this->readEntryPointsData($appInfos);
     $this->installerIni->save();
     // be sure temp path is ready
     \jFile::createDir(App::tempPath(), intval($this->mainConfig->getValue('chmodDirValue'), 8));
 }