Exemple #1
0
 /**
  * Write all settings into the config-file
  *
  */
 function _createSettingsFile()
 {
     global $_ARRLANG;
     $objDb = $this->_getDbObject($statusMsg);
     if ($objDb === false) {
         return $statusMsg;
     } else {
         $strSettingsFile = $_SESSION['installer']['config']['documentRoot'] . $_SESSION['installer']['config']['offsetPath'] . '/config/settings.php';
         if (!\Cx\Lib\FileSystem\FileSystem::touch($strSettingsFile) || !\Cx\Lib\FileSystem\FileSystem::makeWritable($strSettingsFile)) {
             return sprintf($_ARRLANG['TXT_SETTINGS_ERROR_WRITABLE'], $strSettingsFile);
         }
         //Header & Footer
         $strHeader = "<?php\n";
         $strHeader .= "/**\n";
         $strHeader .= "* This file is generated by the \"settings\"-menu in your CMS.\n";
         $strHeader .= "* Do not try to edit it manually!\n";
         $strHeader .= "*/\n\n";
         $strFooter = "\n";
         //Get module-names
         $objResult = $objDb->Execute("SELECT id, name FROM `" . $_SESSION['installer']['config']['dbTablePrefix'] . "modules`");
         if ($objResult->RecordCount() > 0) {
             while (!$objResult->EOF) {
                 $arrModules[$objResult->fields['id']] = $objResult->fields['name'];
                 $objResult->MoveNext();
             }
         }
         //Get values
         $objResult = $objDb->Execute("SELECT setname, setmodule, setvalue FROM `" . $_SESSION['installer']['config']['dbTablePrefix'] . "settings` ORDER BY    setmodule ASC, setname ASC");
         $intMaxLen = 0;
         if ($objResult->RecordCount() > 0) {
             while (!$objResult->EOF) {
                 $intMaxLen = strlen($objResult->fields['setname']) > $intMaxLen ? strlen($objResult->fields['setname']) : $intMaxLen;
                 $arrValues[$objResult->fields['setmodule']][$objResult->fields['setname']] = $objResult->fields['setvalue'];
                 $objResult->MoveNext();
             }
         }
         $intMaxLen += strlen('$_CONFIG[\'\']') + 1;
         //needed for formatted output
         //Write values
         $data = $strHeader;
         $strBody = '';
         foreach ($arrValues as $intModule => $arrInner) {
             $strBody .= "/**\n";
             $strBody .= "* -------------------------------------------------------------------------\n";
             $strBody .= "* " . ucfirst(isset($arrModules[$intModule]) ? $arrModules[$intModule] : '') . "\n";
             $strBody .= "* -------------------------------------------------------------------------\n";
             $strBody .= "*/\n";
             foreach ($arrInner as $strName => $strValue) {
                 $strBody .= sprintf("%-" . $intMaxLen . "s", '$_CONFIG[\'' . $strName . '\']');
                 $strBody .= "= ";
                 $strBody .= (is_numeric($strValue) ? $strValue : '"' . str_replace('"', '\\"', $strValue) . '"') . ";\n";
             }
             $strBody .= "\n";
         }
         $data .= $strBody;
         $data .= $strFooter;
         try {
             $objFile = new \Cx\Lib\FileSystem\File($strSettingsFile);
             $objFile->write($data);
             return true;
         } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
             DBG::msg($e->getMessage());
         }
         return false;
     }
 }
 /**
  * Prepare file access
  *
  * Creates the file specified by $path if it doesn't exist
  * and removes the write-protection mode on the file if there's one.
  *
  * @param string $path
  * @return boolean  Returns TRUE if the specified file exists and has no write-protection on it at the end. Returns FALSE if something fails.
  */
 private function prepareFileAccess($path)
 {
     $file = $this->document_root . $path;
     return (file_exists($file) || \Cx\Lib\FileSystem\FileSystem::touch($file)) && \Cx\Lib\FileSystem\FileSystem::makeWritable($file);
 }
 /**
  * create new file or folder
  * 
  * @param array $params supplied arguments from JsonData-request
  * @return string
  */
 public function newWithin($params)
 {
     global $_ARRAYLANG, $objInit;
     $_ARRAYLANG = $objInit->loadLanguageData('ViewManager');
     if (empty($params['post']['theme']) || empty($params['post']['name'])) {
         return array('status' => 'error', 'message' => $_ARRAYLANG['TXT_THEME_OPERATION_FAILED_FOR_EMPTY_NAME']);
     }
     if ($params['post']['isFolder'] && preg_match('/^\\./', trim($params['post']['name']))) {
         // folder name should not start with dot(.)
         return array('status' => 'error', 'reload' => false, 'message' => sprintf($_ARRAYLANG['TXT_THEME_FOLDER_NAME_NOT_ALLOWED'], contrexx_input2xhtml($params['post']['name'])));
     }
     $matches = null;
     preg_match('@{([0-9A-Za-z._-]+)(:([_a-zA-Z][A-Za-z_0-9]*))?}@sm', $params['post']['name'], $matches);
     if (!empty($matches)) {
         return array('status' => 'error', 'reload' => false, 'message' => sprintf($_ARRAYLANG['TXT_THEME_NAME_NOT_ALLOWED'], contrexx_input2xhtml($params['post']['newName'])));
     }
     // Cannot rename the virtual directory
     $virtualDirs = array('/' . \Cx\Core\Core\Model\Entity\SystemComponent::TYPE_CORE_MODULE, '/' . \Cx\Core\Core\Model\Entity\SystemComponent::TYPE_MODULE, '/' . \Cx\Core\Core\Model\Entity\SystemComponent::TYPE_CORE);
     $currentThemeFolderDirPath = \Env::get('cx')->getWebsiteThemesPath() . '/' . $params['post']['theme'] . '/';
     // Create the theme folder, if it does not exist
     if (!\Cx\Lib\FileSystem\FileSystem::exists($currentThemeFolderDirPath)) {
         if (!\Cx\Lib\FileSystem\FileSystem::make_folder($currentThemeFolderDirPath)) {
             return array('status' => 'error', 'reload' => false, 'message' => $_ARRAYLANG['TXT_THEME_NEWFILE_FAILED']);
         }
     }
     $newFileName = \Cx\Lib\FileSystem\FileSystem::replaceCharacters($params['post']['name']);
     if (!\FWValidator::is_file_ending_harmless($newFileName)) {
         return array('status' => 'error', 'reload' => false, 'message' => sprintf($_ARRAYLANG['TXT_THEME_FILE_EXTENSION_NOT_ALLOWED'], contrexx_input2xhtml($newFileName)));
     }
     if (in_array('/' . $newFileName, $virtualDirs)) {
         return array('status' => 'error', 'reload' => false, 'message' => $_ARRAYLANG['TXT_THEME_OPERATION_FAILED_FOR_VIRTUAL_FOLDER']);
     }
     if (!\Cx\Lib\FileSystem\FileSystem::exists($currentThemeFolderDirPath . $newFileName)) {
         if ($params['post']['isFolder']) {
             $status = \Cx\Lib\FileSystem\FileSystem::make_folder($currentThemeFolderDirPath . $newFileName);
             $succesMessage = sprintf($_ARRAYLANG['TXT_THEME_FOLDER_CREATE_SUCCESS'], contrexx_input2xhtml($newFileName));
         } else {
             $status = \Cx\Lib\FileSystem\FileSystem::touch($currentThemeFolderDirPath . $newFileName);
             $succesMessage = sprintf($_ARRAYLANG['TXT_THEME_FILE_CREATE_SUCCESS'], contrexx_input2xhtml($newFileName));
         }
         if (!$status) {
             return array('status' => 'error', 'message' => $_ARRAYLANG['TXT_THEME_NEWFILE_FAILED']);
         }
         return array('status' => 'success', 'reload' => true, 'message' => $succesMessage, 'path' => '/' . $newFileName);
     }
     return array('status' => 'error', 'message' => sprintf($_ARRAYLANG['TXT_THEME_OPERATION_FAILED_FOR_FILE_ALREADY_EXITS'], contrexx_input2xhtml($newFileName)));
 }