/** * Saves the source of this template. * * @param string $source */ public function setSource($source) { $path = $this->getPath(); // create dir $folder = dirname($path); if (!file_exists($folder)) { mkdir($folder, 0777); } // set source $file = new File($path); $file->write($source); $file->close(); @$file->chmod(0777); }
/** * Uncompresses a gzipped file * * @param string $gzipped * @param string $destination * @return boolean result */ public static function uncompressFile($gzipped, $destination) { if (!@is_file($gzipped)) { return false; } $sourceFile = new GZipFile($gzipped, 'rb'); //$filesize = $sourceFile->getFileSize(); $targetFile = new File($destination); while (!$sourceFile->eof()) { $targetFile->write($sourceFile->read(512), 512); } $targetFile->close(); $sourceFile->close(); @$targetFile->chmod(0777); /*if ($filesize != filesize($destination)) { @unlink($destination); return false; }*/ return true; }
/** * @see wcf\system\io\IArchive::extract() */ public function extract($index, $destination) { if (!$this->read) { $this->open(); $this->readContent(); } $header = $this->getFileInfo($index); FileUtil::makePath(dirname($destination)); if ($header['type'] === 'folder') { FileUtil::makePath($destination); return; } // seek to offset $this->file->seek($header['offset']); $targetFile = new File($destination); // read data $n = floor($header['size'] / 512); for ($i = 0; $i < $n; $i++) { $content = $this->file->read(512); $targetFile->write($content, 512); } if ($header['size'] % 512 != 0) { $content = $this->file->read(512); $targetFile->write($content, $header['size'] % 512); } $targetFile->close(); if (FileUtil::isApacheModule() || !@$targetFile->is_writable()) { @$targetFile->chmod(0777); } else { @$targetFile->chmod(0755); } if ($header['mtime']) { @$targetFile->touch($header['mtime']); } // check filesize if (filesize($destination) != $header['size']) { throw new SystemException("Could not untar file '" . $header['filename'] . "' to '" . $destination . "'. Maybe disk quota exceeded in folder '" . dirname($destination) . "'."); } return true; }
/** * Rebuilds the option file. */ public static function rebuild() { $buffer = ''; // file header $buffer .= "<?php\n/**\n* generated at ".gmdate('r')."\n*/\n"; // get all options $options = Option::getOptions(); foreach ($options as $optionName => $option) { $buffer .= "if (!defined('".$optionName."')) define('".$optionName."', ".(($option->optionType == 'boolean' || $option->optionType == 'integer') ? intval($option->optionValue) : "'".addcslashes($option->optionValue, "'\\")."'").");\n"; } unset($options); // file footer $buffer .= "\n"; // open file $file = new File(WCF_DIR.'options.inc.php'); // write buffer $file->write($buffer); // close file $file->close(); @$file->chmod(0777); }
/** * @see wcf\system\io\IArchive::extract() */ public function extract($offset, $destination) { if (!is_int($offset)) { $offset = $this->getIndexByFilename($offset); } try { $file = $this->readFile($offset); } catch (SystemException $e) { return false; } FileUtil::makePath(dirname($destination)); if ($file['header']['type'] === 'folder') { FileUtil::makePath($destination); return; } $targetFile = new File($destination); $targetFile->write($file['content'], strlen($file['content'])); $targetFile->close(); if (FileUtil::isApacheModule() || !@$targetFile->is_writable()) { @$targetFile->chmod(0777); } else { @$targetFile->chmod(0755); } if ($file['header']['mtime']) { @$targetFile->touch($file['header']['mtime']); } // check filesize if (filesize($destination) != $file['header']['size']) { throw new SystemException("Could not unzip file '" . $file['header']['filename'] . "' to '" . $destination . "'. Maybe disk quota exceeded in folder '" . dirname($destination) . "'."); } return true; }
/** * Write the languages files. * * @param array<integer> $languageCategoryIDs */ protected function writeLanguageFiles(array $languageCategoryIDs) { $conditions = new PreparedStatementConditionBuilder(); $conditions->add("languageID = ?", array($this->languageID)); $conditions->add("languageCategoryID IN (?)", array($languageCategoryIDs)); // get language items $sql = "SELECT languageItem, languageItemValue, languageCustomItemValue, languageUseCustomValue, languageCategoryID FROM wcf".WCF_N."_language_item ".$conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); $items = array(); while ($row = $statement->fetchArray()) { $languageCategoryID = $row['languageCategoryID']; if (!isset($items[$languageCategoryID])) { $items[$languageCategoryID] = array(); } $items[$languageCategoryID][$row['languageItem']] = ($row['languageUseCustomValue']) ? $row['languageCustomItemValue'] : $row['languageItemValue']; } foreach ($items as $languageCategoryID => $languageItems) { $category = LanguageFactory::getInstance()->getCategoryByID($languageCategoryID); if ($category === null) { continue; } $content = "<?php\n/**\n* WoltLab Community Framework\n* language: ".$this->languageCode."\n* encoding: UTF-8\n* category: ".$category->languageCategory."\n* generated at ".gmdate("r")."\n* \n* DO NOT EDIT THIS FILE\n*/\n"; foreach ($languageItems as $languageItem => $languageItemValue) { $content .= "\$this->items['".$languageItem."'] = '".str_replace("'", "\'", $languageItemValue)."';\n"; // compile dynamic language variables if ($category->languageCategory != 'wcf.global' && strpos($languageItemValue, '{') !== false) { $output = LanguageFactory::getInstance()->getScriptingCompiler()->compileString($languageItem, $languageItemValue); $content .= "\$this->dynamicItems['".$languageItem."'] = '".str_replace("'", "\'", $output['template'])."';\n"; } } $file = new File(WCF_DIR.'language/'.$this->languageID.'_'.$category->languageCategory.'.php'); @$file->chmod(0777); $file->write($content . '?>'); $file->close(); } }
/** * Rebuilds cached options * * @param string filename * @param integer $packageID */ public static function rebuildFile($filename, $packageID = PACKAGE_ID) { $buffer = ''; // file header $buffer .= "<?php\n/**\n* generated at " . gmdate('r') . "\n*/\n"; // get all options $options = Option::getOptions($packageID); foreach ($options as $optionName => $option) { $buffer .= "if (!defined('" . $optionName . "')) define('" . $optionName . "', " . ($option['optionType'] == 'boolean' || $option['optionType'] == 'integer' ? intval($option['optionValue']) : "'" . addcslashes($option['optionValue'], "'\\") . "'") . ");\n"; } unset($options); // file footer $buffer .= "?>"; // open file $file = new File($filename); // write buffer $file->write($buffer); unset($buffer); // close file $file->close(); @$file->chmod(0777); }
/** * Write the languages files. * * @param array $categoryIDs * @param array $packageIDs */ protected function writeLanguageFiles(array $categoryIDs, array $packageIDs) { // get categories $conditions = new PreparedStatementConditionBuilder(); $conditions->add("languageCategoryID IN (?)", array($categoryIDs)); $sql = "SELECT\t*\n\t\t\tFROM\twcf" . WCF_N . "_language_category\n\t\t\t" . $conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); while ($category = $statement->fetchArray()) { $categoryName = $category['languageCategory']; $categoryID = $category['languageCategoryID']; // loop packages foreach ($packageIDs as $packageID) { $conditions = new PreparedStatementConditionBuilder(); $conditions->add("languageID = ?", array($this->languageID)); $conditions->add("languageCategoryID = ?", array($categoryID)); // get language items if ($packageID === 0) { // update after wcf installation $conditions->add("packageID IS NULL"); $sql = "SELECT \tlanguageItem, languageItemValue, languageCustomItemValue, languageUseCustomValue\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_language_item\n\t\t\t\t\t\t" . $conditions; } else { // update after regular package installation or update or manual import $conditions->add("package_dependency.packageID = ?", array($packageID)); $sql = "SELECT\t\tlanguageItem, languageItemValue, languageCustomItemValue, languageUseCustomValue\n\t\t\t\t\t\tFROM\t\twcf" . WCF_N . "_language_item language_item\n\t\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_package_dependency package_dependency\n\t\t\t\t\t\tON\t\t(package_dependency.dependency = language_item.packageID)\n\t\t\t\t\t\t" . $conditions . "\n\t\t\t\t\t\tORDER BY \tpackage_dependency.priority ASC"; } $statement2 = WCF::getDB()->prepareStatement($sql); $statement2->execute($conditions->getParameters()); $items = array(); while ($row = $statement2->fetchArray()) { if ($row['languageUseCustomValue'] == 1) { $items[$row['languageItem']] = $row['languageCustomItemValue']; } else { $items[$row['languageItem']] = $row['languageItemValue']; } } if (count($items) > 0) { $file = new File(WCF_DIR . 'language/' . $packageID . '_' . $this->languageID . '_' . $categoryName . '.php'); @$file->chmod(0777); $file->write("<?php\n/**\n* WoltLab Community Framework\n* language: " . $this->languageCode . "\n* encoding: UTF-8\n* category: " . $categoryName . "\n* generated at " . gmdate("r") . "\n* \n* DO NOT EDIT THIS FILE\n*/\n"); foreach ($items as $languageItem => $languageItemValue) { $file->write("\$this->items['" . $languageItem . "'] = '" . str_replace("'", "\\'", $languageItemValue) . "';\n"); // compile dynamic language variables if ($categoryName != 'wcf.global' && strpos($languageItemValue, '{') !== false) { $output = LanguageFactory::getInstance()->getScriptingCompiler()->compileString($languageItem, $languageItemValue); $file->write("\$this->dynamicItems['" . $languageItem . "'] = '" . str_replace("'", "\\'", $output['template']) . "';\n"); } } $file->write("?>"); $file->close(); } } } }