/**
  * Writes the component.yml file with the data defined in component data array
  * 
  * @param \Cx\Core\View\Model\Entity\Theme $theme the theme object
  */
 public function saveComponentData(\Cx\Core\View\Model\Entity\Theme $theme)
 {
     global $_ARRAYLANG;
     if (!file_exists(\Env::get('cx')->getWebsiteThemesPath() . '/' . $theme->getFoldername())) {
         if (!\Cx\Lib\FileSystem\FileSystem::make_folder(\Env::get('cx')->getWebsiteThemesPath() . '/' . $theme->getFoldername())) {
             \Message::add($theme->getFoldername() . " : " . $_ARRAYLANG['TXT_THEME_UNABLE_TO_CREATE']);
         }
     }
     $filePath = \Env::get('cx')->getWebsiteThemesPath() . '/' . $theme->getFoldername() . '/component.yml';
     try {
         $file = new \Cx\Lib\FileSystem\File($filePath);
         $file->touch();
         $yaml = new \Symfony\Component\Yaml\Yaml();
         $file->write($yaml->dump(array('DlcInfo' => $theme->getComponentData())));
     } catch (\Exception $e) {
         \DBG::log($e->getMessage());
         throw new $e();
     }
 }
function activateDebugging()
{
    $File = new \Cx\Lib\FileSystem\File(ASCMS_DOCUMENT_ROOT . '/update/dbg.log');
    if ($File->getAccessMode() == \Cx\Lib\FileSystem\File::FTP_ACCESS) {
        throw new \Exception('Cannot write log via FTP (file needs to be loaded into memory which leads to memory overflow)');
    }
    // temporariy disable FTP support to prevent the FileSystem
    // from creating the dbg.log file through FTP
    $ftpConfig = \Env::get('ftpConfig');
    if ($ftpConfig['is_activated']) {
        \DBG::msg('Update: Intentionally deactivate FTP support as we do not support to write the update log (dbg.log) through FTP due to potential memory overflows.');
        $hackedFtpConfig = $ftpConfig;
        $hackedFtpConfig['is_activated'] = false;
        \Env::set('ftpConfig', $hackedFtpConfig);
    }
    $File->touch();
    // reset FTP
    if ($ftpConfig['is_activated']) {
        \Env::set('ftpConfig', $ftpConfig);
    }
    if ($File->makeWritable()) {
        \DBG::activate(DBG_LOG_FILE | DBG_PHP | DBG_DB);
        return true;
    }
    return false;
}
Beispiel #3
0
 /**
  * Saves the new image wherever you want
  * @todo    In case the PHP script has no write access to the location set by $this->newImageFile,
  *          the image shall be sent to the output buffer and then be put into the new file
  *          location using the FileSystemFile object.
  * @access  public
  * @param   string    $file             The path for the image file to be written.
  * @param   booelan   $forceOverwrite   Force overwriting existing files if true.
  * @return  boolean                     True on success, false otherwise.
  */
 public function saveNewImage($file, $forceOverwrite = false)
 {
     // TODO: Add some sort of diagnostics (Message) here and elsewhere in this class
     if (!$this->imageCheck) {
         return false;
     }
     if (empty($this->newImage)) {
         return false;
     }
     if (file_exists($file)) {
         if (!$forceOverwrite) {
             return false;
         }
         \Cx\Lib\FileSystem\FileSystem::makeWritable($file);
     } else {
         try {
             $objFile = new \Cx\Lib\FileSystem\File($file);
             $objFile->touch();
         } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
             \DBG::msg($e->getMessage());
         }
     }
     // TODO: Unfortunately, the functions imagegif(), imagejpeg() and imagepng() can't use the Contrexx FileSystem wrapper,
     //       therefore we need to set the global write access image files.
     //       This issue might be solved by using the output-buffer and write the image manually afterwards.
     //
     //       IMPORTANT: In case something went wrong (see bug #1441) and the path $strPathNew.$strFileNew refers to a directory
     //       we must abort the operation here, otherwise we would remove the execution flag on a directory, which would
     //       cause to remove any browsing access to the directory.
     if (is_dir($file)) {
         return false;
     }
     \Cx\Lib\FileSystem\FileSystem::chmod($file, 0666);
     //\Cx\Lib\FileSystem\FileSystem::CHMOD_FILE);
     $this->newImageFile = $file;
     if ($this->newImageType == self::IMG_TYPE_PNG) {
         $this->setTransparency();
     }
     switch ($this->newImageType) {
         case self::IMG_TYPE_GIF:
             $function = 'imagegif';
             if (!function_exists($function)) {
                 $function = 'imagejpeg';
             }
             break;
         case self::IMG_TYPE_JPEG:
             $function = 'imagejpeg';
             break;
         case self::IMG_TYPE_PNG:
             // make a jpeg thumbnail, too
             $function = 'imagepng';
             break;
         default:
             return false;
     }
     // Only adjust quality, if it is set.
     if ($this->newImageQuality != '') {
         $function($this->newImage, $this->newImageFile, $this->getQuality());
     } else {
         $function($this->newImage, $this->newImageFile);
     }
     return true;
 }
Beispiel #4
0
 /**
  *
  * @param Cx\Core_Modules\Listing\Model\ExportInterface $exportInterface
  * @param type $filename 
  * @throws \Cx\Lib\FileSystem\FileSystemException
  */
 public function exportToFile(\Cx\Core_Modules\Listing\Model\Entity\Exportable $exportInterface, $filename)
 {
     try {
         $objFile = new \Cx\Lib\FileSystem\File($filename);
         $objFile->touch();
         $objFile->write($this->export($exportInterface));
     } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
         \DBG::msg($e->getMessage());
         throw new DataSetException("Failed to export data to file {$filename}!");
     }
 }
Beispiel #5
0
 public static function touch($path)
 {
     try {
         $objFile = new \Cx\Lib\FileSystem\File($path);
         $objFile->touch();
         return true;
     } catch (FileSystemException $e) {
         \DBG::msg($e->getMessage());
     }
     return false;
 }
Beispiel #6
0
 function createConfigFile()
 {
     global $configFile, $_ARRLANG;
     $statusMsg = "";
     $configFileContent = $this->_getConfigFileTemplate($statusMsg);
     if (!empty($statusMsg)) {
         return $statusMsg;
     }
     $configFilePath = $_SESSION['installer']['config']['documentRoot'] . $_SESSION['installer']['config']['offsetPath'] . $configFile;
     try {
         $objFile = new \Cx\Lib\FileSystem\File($configFilePath);
         $objFile->touch();
         $objFile->write($configFileContent);
         return true;
     } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
         \DBG::msg($e->getMessage());
     }
     return sprintf($_ARRLANG['TXT_CANNOT_CREATE_FILE'] . "<br />", $configFilePath);
 }
 private function testLoad($path, $name)
 {
     if (!file_exists($path) || !$this->checkClassExistsInFile($name, $path)) {
         return false;
     }
     $path = substr($path, strlen($this->cx->getCodeBaseDocumentRootPath()));
     if (!$this->loadClass($path, $name)) {
         return false;
     }
     try {
         $objFile = new \Cx\Lib\FileSystem\File($this->userClassCacheFile);
         if (!file_exists($this->userClassCacheFile)) {
             $objFile->touch();
         }
         $cacheArr = unserialize(file_get_contents($this->classLoader->getFilePath($this->userClassCacheFile)));
         $cacheArr[$name] = $path;
         $objFile->write(serialize($cacheArr));
     } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
         \DBG::msg($e->getMessage());
     }
     return true;
 }
 /**
  * Store the website details into the YML file
  * 
  * @param string $folderPath
  * @param string $filePath
  * @param array  $ymlContent
  * 
  * @return null
  */
 public function storeUpdateWebsiteDetailsToYml($folderPath, $filePath, $ymlContent)
 {
     if (empty($folderPath) || empty($filePath)) {
         return;
     }
     try {
         if (!file_exists($folderPath)) {
             \Cx\Lib\FileSystem\FileSystem::make_folder($folderPath);
         }
         $file = new \Cx\Lib\FileSystem\File($filePath);
         $file->touch();
         $yaml = new \Symfony\Component\Yaml\Yaml();
         $file->write($yaml->dump(array('PendingCodeBaseChanges' => $ymlContent)));
     } catch (\Exception $e) {
         \DBG::log($e->getMessage());
     }
 }
Beispiel #9
0
 /**
  * Exports a DataSet to a file using an export interface
  *
  * @param Cx\Core_Modules\Listing\Model\Entity\Exportable $exportInterface
  * @param string $filename
  * @param boolean $useCache
  * @throws \Cx\Lib\FileSystem\FileSystemException
  */
 public function exportToFile(\Cx\Core_Modules\Listing\Model\Entity\Exportable $exportInterface, $filename, $useCache = true)
 {
     try {
         $objFile = new \Cx\Lib\FileSystem\File($filename);
         $objFile->touch();
         $export = $this->export($exportInterface);
         $objFile->write($export);
         // delete old key from cache, to reload it on the next import
         if ($useCache) {
             $cache = \Cx\Core\Core\Controller\Cx::instanciate()->getComponent('Cache');
             if (!$cache) {
                 throw new DataSetException('Cache component not available at this stage!');
             }
             $cache->delete($filename);
         }
     } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
         \DBG::msg($e->getMessage());
         throw new DataSetException("Failed to export data to file {$filename}!");
     }
 }
Beispiel #10
0
 /**
  * Should be called whenever there's a problem with the settings
  *
  * Tries to fix or recreate the settings.
  * @return  boolean             False, always.
  * 
  */
 function errorHandler()
 {
     try {
         $file = new \Cx\Lib\FileSystem\File(\Env::get('cx')->getWebsiteConfigPath() . '/' . $this->section . '.yml');
         $file->touch();
         return false;
     } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
         \DBG::msg($e->getMessage());
     }
 }
 /**
  * Write the meta information of the component to the file
  * 
  * @param \Cx\Lib\FileSystem\File $file Path to meta file
  */
 private function writeMetaDataToFile($file)
 {
     $publisher = '';
     $query = '
         SELECT
             `distributor`
         FROM
             `' . DBPREFIX . 'modules`
         WHERE
             `name` = "' . $this->componentName . '"
         LIMIT 1
     ';
     $result = $this->db->query($query);
     if (!$result->EOF) {
         $publisher = $result->fields['distributor'];
     }
     $content = array('DlcInfo' => array('name' => $this->componentName, 'type' => $this->componentType, 'publisher' => $publisher, 'dependencies' => null, 'versions' => null, 'rating' => 0, 'downloads' => 0, 'price' => 0.0, 'pricePer' => 0, 'additionalFiles' => array()));
     try {
         $file = new \Cx\Lib\FileSystem\File($file);
         $file->touch();
         $file->write(\Symfony\Component\Yaml\Yaml::dump($content, 3));
     } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
         \DBG::msg($e->getMessage());
     }
 }
 /**
  * Write sitemap-file
  *
  * @global     object
  * @global     array
  * @param   array An array containing the language ID's of which languages should be included in the sitemap.
  * @param   string  The two letter language code of the selected language used as the virtual language path
  */
 protected function writeXML()
 {
     $filename = \FWLanguage::getLanguageCodeById($this->lang) ? sprintf(self::$strFileNameWithLang, \FWLanguage::getLanguageCodeById($this->lang)) : self::$strFileName;
     $xml = $this->render();
     try {
         $filePath = \Env::get('cx')->getWebsiteDocumentRootPath();
         $objFile = new \Cx\Lib\FileSystem\File($filePath . self::$strFilePath . '/' . $filename);
         $objFile->touch();
         $objFile->write($xml);
     } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
         \DBG::log($e->getMessage());
         return false;
     }
     return true;
 }
 /**
  * Checks if file exists, if not - creates new one with metadata
  * 
  * @param string $filename
  * @param array $unique_keys
  * @param string $identifier
  * @return boolean
  * @throws \Cx\Core\Setting\Controller\SettingException
  */
 protected function prepareFile($filename, $unique_keys = array(), $identifier)
 {
     if ($this->fileExistsAndNotEmpty($filename)) {
         return true;
     }
     \DBG::log('Creating new file');
     try {
         $file = new \Cx\Lib\FileSystem\File($filename);
         $file->touch();
         $data = trim($file->getData());
         if (empty($data)) {
             $inidata = "meta:\n" . "   auto_increment: 1\n";
             if (!empty($identifier)) {
                 $inidata .= "   identifier: {$identifier}\n";
             }
             if (!empty($unique_keys)) {
                 $inidata .= "   unique_keys:\n";
                 foreach ($unique_keys as $key) {
                     $inidata .= "        - {$key}";
                 }
             }
             $file->write($inidata);
         }
     } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
         \DBG::log('EX ' . $e->getMessage());
         throw new \Cx\Core\Setting\Controller\YamlRepositoryException($e->getMessage());
     }
 }
Beispiel #14
0
 /**
  * Create default theme files
  * 
  * \Cx\Core\View\Model\Entity\Theme $theme
  */
 private function createDefaultFiles(\Cx\Core\View\Model\Entity\Theme $theme)
 {
     global $_ARRAYLANG;
     foreach ($this->directories as $dir) {
         if (!\Cx\Lib\FileSystem\FileSystem::make_folder($this->path . $theme->getFoldername() . '/' . $dir)) {
             \Message::add(sprintf($_ARRAYLANG['TXT_UNABLE_TO_CREATE_FILE'], contrexx_raw2xhtml($theme->getFoldername() . '/' . $dir)), \Message::CLASS_ERROR);
             return false;
         }
     }
     //copy "not available" preview.gif as default preview image
     $previewImage = $this->path . $theme->getFoldername() . \Cx\Core\View\Model\Entity\Theme::THEME_PREVIEW_FILE;
     if (!file_exists($previewImage)) {
         try {
             $objFile = new \Cx\Lib\FileSystem\File(\Env::get('cx')->getCodeBaseDocumentRootPath() . \Cx\Core\View\Model\Entity\Theme::THEME_DEFAULT_PREVIEW_FILE);
             $objFile->copy($previewImage);
         } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
             \DBG::msg($e->getMessage());
             \Message::add(sprintf($_ARRAYLANG['TXT_UNABLE_TO_CREATE_FILE'], contrexx_raw2xhtml($theme->getFoldername() . \Cx\Core\View\Model\Entity\Theme::THEME_PREVIEW_FILE)), \Message::CLASS_ERROR);
             return false;
         }
     }
     foreach ($this->filenames as $file) {
         // skip component.yml, will be created later
         if ($file == 'component.yml') {
             continue;
         }
         $filePath = $this->path . $theme->getFoldername() . '/' . $file;
         if (!file_exists($filePath)) {
             try {
                 $objFile = new \Cx\Lib\FileSystem\File($filePath);
                 $objFile->touch();
             } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
                 \DBG::msg($e->getMessage());
                 \Message::add(sprintf($_ARRAYLANG['TXT_UNABLE_TO_CREATE_FILE'], contrexx_raw2xhtml($theme->getFoldername() . '/' . $file)), \Message::CLASS_ERROR);
                 return false;
             }
         }
     }
     // write component.yml file
     // this line will create a default component.yml file
     try {
         $this->themeRepository->loadComponentData($theme);
         $this->themeRepository->convertThemeToComponent($theme);
     } catch (\Exception $e) {
         \DBG::msg($e->getMessage());
         \Message::add($_ARRAYLANG['TXT_UNABLE_TO_CONVERT_THEME_TO_COMPONENT'], \Message::CLASS_ERROR);
     }
     return true;
 }
 /**
  * Create an Image
  * @param     string        $strPathOld: The old path of the image
  * @param     string        $strPathNew: The new path for the created image
  * @param     string        $strFileOld: The name of the old file
  * @param     string        $strFileNew: The name of the new file
  * @param     integer        $intNewWidth: Width of the new image
  * @param     integer        $intNewHeight: Height of the new image
  * @param     integer        $intQuality: Quality of the new image
  */
 function createImages_JPG_GIF_PNG($strPathOld, $strPathNew, $strFileOld, $strFileNew, $intNewWidth, $intNewHeight, $intQuality)
 {
     global $_ARRAYLANG;
     //TODO: sometimes, strings are passed... this is a workaround
     $intNewWidth = intval($intNewWidth);
     $intNewHeight = intval($intNewHeight);
     //copy image
     $intSize = getimagesize($strPathOld . $strFileOld);
     //ermittelt die Gr��e des Bildes
     $intWidth = $intSize[0];
     //die Breite des Bildes
     $intHeight = $intSize[1];
     //die H�he des Bildes
     $strType = $intSize[2];
     //type des Bildes
     if (file_exists($strPathNew . $strFileNew)) {
         \Cx\Lib\FileSystem\FileSystem::makeWritable($strPathNew . $strFileNew);
     } else {
         try {
             $objFile = new \Cx\Lib\FileSystem\File($strPathNew . $strFileNew);
             $objFile->touch();
             $objFile->makeWritable();
         } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
             \DBG::msg($e->getMessage());
         }
     }
     // TODO: Unfortunately, the functions imagegif(), imagejpeg() and imagepng() can't use the Cloudrexx FileSystem wrapper,
     //       therefore we need to set the global write access image files.
     //       This issue might be solved by using the output-buffer and write the image manually afterwards.
     //
     //       IMPORTANT: In case something went wrong (see bug #1441) and the path $strPathNew.$strFileNew refers to a directory
     //       we must abort the operation here, otherwise we would remove the execution flag on a directory, which would
     //       cause to remove any browsing access to the directory.
     if (is_dir($strPathNew . $strFileNew)) {
         return false;
     }
     \Cx\Lib\FileSystem\FileSystem::chmod($strPathNew . $strFileNew, 0666);
     //\Cx\Lib\FileSystem\FileSystem::CHMOD_FILE);
     //fix cases of zeroes
     if ($intNewWidth == 0) {
         if ($intNewHeight == 0) {
             $intNewHeight = $this->arrSettings['standard_height_abs'];
         }
         if ($intNewHeight == 0) {
             //set a standard value if the settings default to 0
             $intNewHeight = 100;
         }
         $intNewWidth = round($intWidth * $intNewHeight / $intHeight, 0);
     } else {
         if ($intNewHeight == 0) {
             $intNewHeight = round($intHeight * $intNewWidth / $intWidth, 0);
         }
     }
     $objSystem = new \FWSystem();
     if ($objSystem === false) {
         return false;
     }
     if (is_array($intSize)) {
         $memoryLimit = $objSystem->getBytesOfLiteralSizeFormat(@ini_get('memory_limit'));
         // a $memoryLimit of zero means that there is no limit. so let's try it and hope that the host system has enough memory
         if (!empty($memoryLimit)) {
             $potentialRequiredMemory = $intSize[0] * $intSize[1] * ($intSize['bits'] / 8) * $intSize['channels'] * 1.8 * 2;
             if (function_exists('memory_get_usage')) {
                 $potentialRequiredMemory += memory_get_usage();
             } else {
                 // add a default of 10 MBytes
                 $potentialRequiredMemory += 10 * pow(1024, 2);
             }
             if ($potentialRequiredMemory > $memoryLimit) {
                 // try to set a higher memory_limit
                 @ini_set('memory_limit', $potentialRequiredMemory);
                 $curr_limit = $objSystem->getBytesOfLiteralSizeFormat(@ini_get('memory_limit'));
                 if ($curr_limit < $potentialRequiredMemory) {
                     return false;
                 }
             }
         }
     } else {
         return false;
     }
     switch ($strType) {
         case 1:
             //GIF
             if ($this->boolGifEnabled) {
                 $handleImage1 = ImageCreateFromGif($strPathOld . $strFileOld);
                 $handleImage2 = @ImageCreateTrueColor($intNewWidth, $intNewHeight);
                 ImageCopyResampled($handleImage2, $handleImage1, 0, 0, 0, 0, $intNewWidth, $intNewHeight, $intWidth, $intHeight);
                 ImageGif($handleImage2, $strPathNew . $strFileNew);
                 ImageDestroy($handleImage1);
                 ImageDestroy($handleImage2);
             } else {
                 $this->strErrMessage = $_ARRAYLANG['TXT_GALLERY_NO_GIF_SUPPORT'];
             }
             break;
         case 2:
             //JPG
             if ($this->boolJpgEnabled) {
                 $handleImage1 = ImageCreateFromJpeg($strPathOld . $strFileOld);
                 $handleImage2 = ImageCreateTrueColor($intNewWidth, $intNewHeight);
                 ImageCopyResampled($handleImage2, $handleImage1, 0, 0, 0, 0, $intNewWidth, $intNewHeight, $intWidth, $intHeight);
                 ImageJpeg($handleImage2, $strPathNew . $strFileNew, $intQuality);
                 ImageDestroy($handleImage1);
                 ImageDestroy($handleImage2);
             } else {
                 $this->strErrMessage = $_ARRAYLANG['TXT_GALLERY_NO_JPG_SUPPORT'];
             }
             break;
         case 3:
             //PNG
             if ($this->boolPngEnabled) {
                 $handleImage1 = ImageCreateFromPNG($strPathOld . $strFileOld);
                 $handleImage2 = @ImageCreateTrueColor($intNewWidth, $intNewHeight);
                 ImageAlphaBlending($handleImage2, false);
                 ImageSaveAlpha($handleImage2, true);
                 ImageCopyResampled($handleImage2, $handleImage1, 0, 0, 0, 0, $intNewWidth, $intNewHeight, $intWidth, $intHeight);
                 ImagePNG($handleImage2, $strPathNew . $strFileNew);
                 ImageDestroy($handleImage1);
                 ImageDestroy($handleImage2);
             } else {
                 $this->strErrMessage = $_ARRAYLANG['TXT_GALLERY_NO_PNG_SUPPORT'];
             }
             break;
     }
     return true;
 }