function firstRun() { // do the check again, for safety reasons: if ($this->_config['date_lch'] !== null) { $this->_installed = true; return zmgError::throwError('Illegal way of accessing firstRun'); } zmgimport('org.zoomfactory.lib.helpers.zmgFileHelper'); if (zmgFileHelper::exists(ZMG_ABS_PATH . DS . 'etc' . DS . 'app.config.php.bak')) { $this->_installed = true; return zmgError::throwError('Illegal access: component already installed.'); } $messages =& zmgFactory::getMessages(); $html_file = "<html><body bgcolor=\"#FFFFFF\"></body></html>"; //make all the necessary folders writable for ZMG $config_dir = ZMG_ABS_PATH . DS . "etc"; if (!zmgFileHelper::chmodRecursive($config_dir)) { $messages->append('Installation Error!', 'Unable to set directory permissions for: ' . $config_dir); } //make sure the configuration file itself is writable if (!zmgFileHelper::chmodRecursive($config_dir . DS . 'app.config.php')) { $messages->append('Installation Error!', 'Unable to set file permissions for: ' . $config_dir . DS . 'app.config.php'); } $media_dir = zmgEnv::getRootPath() . DS . $this->get('filesystem/mediapath'); if (!is_dir($media_dir)) { if (zmgFileHelper::createDir($media_dir)) { if (!zmgFileHelper::write($media_dir . DS . 'index.html', $html_file)) { $messages->append('Installation Error!', 'Unable to write to file: ' . $media_dir . DS . 'index.html'); } } else { $messages->append('Installation Error!', 'Unable to create directory: ' . $media_dir); } } //backup the original config file that came with the distribution package if (!zmgFileHelper::copy('app.config.php', 'app.config.php.bak', ZMG_ABS_PATH . DS . 'etc')) { $messages->append('Installation Error!', 'Unable to copy file: ' . ZMG_ABS_PATH . DS . 'etc' . DS . 'app.config.php'); } $this->_installed = $this->save(); if ($this->_installed) { $messages->append('Installation Success!', 'Your component is ready to use now.'); } else { $messages->append('Installation Error!', 'Settings could not be saved.'); } return $this->_installed; }
/** * Class constructor. * Prepares files for first run. * Global variables setting. * * @return void */ function zmgLogger($logDir = "log", $logMode = "oneFile") { //set global variables $this->_logDir = $logDir; $this->_logMode = $logMode; $this->_countFile = $this->_logDir . DS . $this->_countFile; zmgimport('org.zoomfactory.lib.helpers.zmgFileHelper'); //verify log folder existence. If it doesn't I create it if (!is_dir($this->_logDir)) { if (!zmgFileHelper::createDir($this->_logDir)) { zmgError::throwError("Could not create log dir"); } } //Counter init if (!zmgFileHelper::exists($this->_countFile)) { //if log counter file does not exist, I create it touch($this->_countFile); //inicializing file in 0 $initNumber = 0; $fp = fopen($this->_countFile, "a"); if (fwrite($fp, $initNumber) === false) { zmgError::throwError("Could not write Counter file"); } fclose($fp); } //read counter $logNumber = intval(trim(file_get_contents($this->_countFile))); $logNumber++; //increment counter //set log number in class var $this->_logNumber = $logNumber; //write incremented counter value $fp = fopen($this->_countFile, "w+"); if (fwrite($fp, $logNumber) === false) { zmgError::throwError("Could not write Counter file"); } fclose($fp); }
function buildDirStructure() { zmgimport('org.zoomfactory.lib.helpers.zmgFileHelper'); $html_file = "<html><body bgcolor=\"#FFFFFF\"></body></html>"; $root = zmgEnv::getRootPath(); $mediapath = $root . DS . zmgFactory::getConfig()->get('filesystem/mediapath'); $dirs = array($mediapath . $this->dir, $mediapath . $this->dir . DS . 'thumbs', $mediapath . $this->dir . DS . 'viewsize'); foreach ($dirs as $dir) { if (zmgFileHelper::createDir($dir, 0777)) { if (!zmgFileHelper::write($dir . DS . 'index.html', $html_file)) { zmgError::throwError(T_('Unable to write to file: ') . $dir . DS . 'index.html'); } } else { zmgError::throwError(T_('Unable to create directory: ') . $dir); } } return true; }
/** * Create a folder -- and all necessary parent folders * * @param string $path A path to create from the base path * @param int $mode Directory permissions to set for folders created * @return boolean True if successful * @since 1.5 */ function createDir($path = '', $mode = 0755) { // Initialize variables //jimport('joomla.client.helper'); //$FTPOptions = JClientHelper::getCredentials('ftp'); static $nested = 0; // Check to make sure the path valid and clean $path = zmgFileHelper::cleanPath($path); // Check if parent dir exists $parent = dirname($path); if (!is_dir($parent)) { // Prevent infinite loops! $nested++; if ($nested > 20 || $parent == $path) { zmgError::throwError(T_('Infinite loop detected')); $nested--; return false; } // Create the parent directory if (zmgFileHelper::createDir($parent, $mode) !== true) { // zmgFileHelper::createDir throws an error $nested--; return false; } // OK, parent directory has been created $nested--; } // Check if dir already exists if (is_dir($path)) { return true; } // Check for safe mode if (zmgFactory::getConfig()->get('plugins/safemode/general/enable') == 1) { $ret = zmgFactory::getEvents()->fire('ondircreate', $path); zmgFileHelper::chmod($path); } else { // We need to get and explode the open_basedir paths $obd = ini_get('open_basedir'); // If open_basedir is set we need to get the open_basedir that the path is in if ($obd != null) { if (ZMG_ISWIN) { $obdSeparator = ";"; } else { $obdSeparator = ":"; } // Create the array of open_basedir paths $obdArray = explode($obdSeparator, $obd); $inOBD = false; // Iterate through open_basedir paths looking for a match foreach ($obdArray as $test) { $test = zmgFileHelper::cleanPath($test); if (strpos($path, $test) === 0) { $obdpath = $test; $inOBD = true; break; } } if ($inOBD == false) { // Return false for zmgFileHelper::createDir because the path to be created is not in open_basedir zmgError::throwError(T_('Path not in open_basedir paths')); return false; } } // First set umask $origmask = @umask(0); // Create the path if (!($ret = @mkdir($path, $mode))) { @umask($origmask); zmgError::throwError(T_('Could not create directory')); return false; } // Reset umask @umask($origmask); } return $ret; }