Example #1
0
 private function makeDir($dir)
 {
     global $_ARRAYLANG;
     if (array_key_exists($this->_mediaType, $this->mediaTypePaths)) {
         $strPath = $this->mediaTypePaths[$this->_mediaType][0] . $this->_path;
         $strWebPath = $this->mediaTypePaths[$this->_mediaType][1] . $this->_path;
     } else {
         $strPath = ASCMS_CONTENT_IMAGE_PATH . $this->_path;
         $strWebPath = ASCMS_CONTENT_IMAGE_WEB_PATH . $this->_path;
     }
     if (preg_match('#^[0-9a-zA-Z_\\-]+$#', $dir)) {
         \Cx\Core\Csrf\Controller\Csrf::check_code();
         $objFile = new \File();
         if (!$objFile->mkDir($strPath, $strWebPath, $dir)) {
             $this->_pushStatusMessage(sprintf($_ARRAYLANG['TXT_FILEBROWSER_UNABLE_TO_CREATE_FOLDER'], $dir), 'error');
         } else {
             $this->_pushStatusMessage(sprintf($_ARRAYLANG['TXT_FILEBROWSER_DIRECTORY_SUCCESSFULLY_CREATED'], $dir));
         }
     } else {
         if (!empty($dir)) {
             $this->_pushStatusMessage($_ARRAYLANG['TXT_FILEBROWSER_INVALID_CHARACTERS'], 'error');
         }
     }
 }
 /**
  * createXML: parse out the XML
  *
  * @global  ADONewConnection
  * @global  array
  * @return  void
  */
 function createFiles()
 {
     global $objDatabase, $_ARRAYLANG;
     $arrModules = array();
     $arrLanguages = array();
     $arrModulesPath = array();
     $arrModuleVariables = array();
     $arrErrorFiles = array();
     $objFile = new File();
     $strHeader = "/**\n* Contrexx CMS\n* generated date " . date('r', time()) . "\n**/\n\n";
     // generate the arrays $arrModulesPath and $arrModules
     $query = "SELECT id, name, is_core FROM " . DBPREFIX . "modules";
     $objResult = $objDatabase->Execute($query);
     if ($objResult !== false) {
         while (!$objResult->EOF) {
             if (strlen($objResult->fields['name']) > 0) {
                 switch ($objResult->fields['name']) {
                     case 'core':
                         $arrModulesPath[$objResult->fields['name']]['sys'] = ASCMS_DOCUMENT_ROOT;
                         $arrModulesPath[$objResult->fields['name']]['web'] = ASCMS_PATH_OFFSET;
                         break;
                     case 'Media1':
                         $arrModulesPath['Media']['sys'] = ASCMS_CORE_MODULE_PATH . '/Media';
                         $arrModulesPath['Media']['web'] = ASCMS_CORE_MODULE_WEB_PATH . '/Media';
                         $objResult->fields['name'] = 'Media';
                         break;
                     case 'Media2':
                     case 'Media3':
                         $objResult->fields['name'] = "";
                         break;
                     default:
                         $arrModulesPath[$objResult->fields['name']]['sys'] = ($objResult->fields['is_core'] == 1 ? ASCMS_CORE_MODULE_PATH : ASCMS_MODULE_PATH) . '/' . $objResult->fields['name'];
                         $arrModulesPath[$objResult->fields['name']]['web'] = ($objResult->fields['is_core'] == 1 ? ASCMS_CORE_MODULE_WEB_PATH : ASCMS_MODULE_WEB_PATH) . '/' . $objResult->fields['name'];
                 }
                 if (!empty($objResult->fields['name'])) {
                     $arrModulesPath[$objResult->fields['name']]['sys'] .= '/lang/';
                     $arrModulesPath[$objResult->fields['name']]['web'] .= '/lang/';
                 }
             }
             $arrModules[$objResult->fields['id']] = array('id' => $objResult->fields['id'], 'name' => $objResult->fields['name']);
             $objResult->MoveNext();
         }
     }
     // get language array
     $query = "SELECT id, lang FROM " . DBPREFIX . "languages";
     $objResult = $objDatabase->Execute($query);
     if ($objResult !== false) {
         while (!$objResult->EOF) {
             $arrLanguages[$objResult->fields['id']] = array('id' => $objResult->fields['id'], 'lang' => $objResult->fields['lang']);
             $objResult->MoveNext();
         }
     }
     // get language variables
     $query = "SELECT vn.name, vn.module_id, vn.backend, vn.frontend, vc.content, vc.lang_id\n                    FROM " . DBPREFIX . "language_variable_names AS vn,\n                         " . DBPREFIX . "language_variable_content AS vc\n                   WHERE vn.id=vc.varid";
     // generate array $arrModuleVariables including the variables
     $objResult = $objDatabase->Execute($query);
     if ($objResult !== false) {
         while (!$objResult->EOF) {
             if ($objResult->fields['module_id'] == 0) {
                 $moduleId = 1;
             } else {
                 $moduleId = $objResult->fields['module_id'];
             }
             if ($objResult->fields['backend'] == 1) {
                 $arrModuleVariables[$moduleId][$objResult->fields['lang_id']]['backend'][$objResult->fields['name']] = $objResult->fields['content'];
             }
             if ($objResult->fields['frontend'] == 1) {
                 $arrModuleVariables[$moduleId][$objResult->fields['lang_id']]['frontend'][$objResult->fields['name']] = $objResult->fields['content'];
             }
             $objResult->MoveNext();
         }
     }
     // generate array $arrOutput with the data to write into files
     foreach ($arrModuleVariables as $moduleId => $arrLanguageVariables) {
         foreach ($arrLanguageVariables as $langId => $arrModeVariables) {
             $filePath = $arrModulesPath[$arrModules[$moduleId]['name']]['sys'] . $arrLanguages[$langId]['lang'] . '/';
             $webFilePath = $arrModulesPath[$arrModules[$moduleId]['name']]['web'] . $arrLanguages[$langId]['lang'] . '/';
             if (!file_exists($filePath)) {
                 $objFile->mkDir($arrModulesPath[$arrModules[$moduleId]['name']]['sys'], $arrModulesPath[$arrModules[$moduleId]['name']]['web'], $arrLanguages[$langId]['lang'] . '/');
             }
             foreach ($arrModeVariables as $strMode => $arrVariables) {
                 $fileName = $strMode . ".php";
                 $arrOutput[$filePath . $fileName]['filename'] = $fileName;
                 $arrOutput[$filePath . $fileName]['path'] = $filePath;
                 $arrOutput[$filePath . $fileName]['webpath'] = $webFilePath;
                 foreach ($arrVariables as $strName => $strContent) {
                     //$strContent = stripslashes(stripslashes($strContent));
                     //$strContent = str_replace("\"", "\\\"", $strContent);
                     //$strContent = addslashes($strContent);
                     if (isset($arrOutput[$filePath . $fileName]['content'])) {
                         $arrOutput[$filePath . $fileName]['content'] .= "\$" . "_ARRAYLANG['" . $strName . "'] = \"" . $strContent . "\";\n";
                     } else {
                         $arrOutput[$filePath . $fileName]['content'] = "\$" . "_ARRAYLANG['" . $strName . "'] = \"" . $strContent . "\";\n";
                     }
                 }
             }
         }
     }
     unset($arrModuleVariables);
     // write variables to files
     foreach ($arrOutput as $file => $strOutput) {
         $objFile->setChmod($strOutput['path'], $strOutput['webpath'], '');
         $objFile->setChmod($strOutput['path'], $strOutput['webpath'], $strOutput['filename']);
         $fileHandle = fopen($file, "w");
         if ($fileHandle) {
             @fwrite($fileHandle, "<?php\n" . $strHeader . $strOutput['content'] . "?>\n");
             @fclose($fileHandle);
         } else {
             array_push($arrErrorFiles, $file);
         }
     }
     unset($arrOutput);
     if (count($arrErrorFiles) > 0) {
         foreach ($arrErrorFiles as $file) {
             $this->strErrMessage .= "<br />" . $_ARRAYLANG['TXT_COULD_NOT_WRITE_TO_FILE'] . " (" . $file . ")";
         }
     } else {
         $this->strOkMessage .= "<br />" . $_ARRAYLANG['TXT_SUCCESSFULLY_EXPORTED_TO_FILES'];
     }
 }
Example #3
0
 /**
  * Create directory
  *
  * @global     array    $_ARRAYLANG
  * @param      string   $dir_name
  */
 function _createDirectory($dir_name)
 {
     global $_ARRAYLANG;
     if (empty($dir_name)) {
         if (!isset($_GET['highlightFiles'])) {
             $this->_strErrorMessage = $_ARRAYLANG['TXT_MEDIA_EMPTY_DIR_NAME'];
         }
         return;
     } else {
         $dir_name = contrexx_stripslashes($dir_name);
     }
     if (!$this->uploadAccessGranted()) {
         $this->_strErrorMessage = $_ARRAYLANG['TXT_MEDIA_DIRCREATION_NOT_ALLOWED'];
         return;
     }
     $obj_file = new \File();
     $dir_name = \Cx\Lib\FileSystem\FileSystem::replaceCharacters($dir_name);
     $creationStatus = $obj_file->mkDir($this->path, $this->webPath, $dir_name);
     if ($creationStatus != "error") {
         $this->highlightName[] = $dir_name;
         $this->_strOkMessage = $_ARRAYLANG['TXT_MEDIA_MSG_NEW_DIR'];
     } else {
         $this->_strErrorMessage = $_ARRAYLANG['TXT_MEDIA_MSG_ERROR_NEW_DIR'];
     }
 }