/** * Saves meta data for given template. * * @param string $templateName * @param string $filename * @param string $content */ public function saveMetaData($templateName, $filename, $content) { $writer = new AtomicWriter($filename); $writer->write("<?php exit; /* meta data for template: " . $templateName . " (generated at " . gmdate('r') . ") DO NOT EDIT THIS FILE */ ?>\n"); $writer->write(serialize($content)); $writer->flush(); $writer->close(); }
/** * @see \wcf\system\cache\source\ICacheSource::set() */ public function set($cacheName, $value, $maxLifetime) { $writer = new AtomicWriter($this->getFilename($cacheName)); $writer->write("<?php exit; /* cache: " . $cacheName . " (generated at " . gmdate('r') . ") DO NOT EDIT THIS FILE */ ?>\n"); $writer->write(serialize($value)); $writer->flush(); $writer->close(); // unset current DirectoryUtil object to make sure new cache file // can be deleted in the same request $this->directoryUtil = null; WCF::resetZendOpcache($this->getFilename($cacheName)); }
/** * 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\tlanguageItem, languageItemValue, languageCustomItemValue,\n\t\t\t\tlanguageUseCustomValue, languageCategoryID\n\t\t\tFROM\twcf" . WCF_N . "_language_item\n\t\t\t" . $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; } $filename = WCF_DIR . 'language/' . $this->languageID . '_' . $category->languageCategory . '.php'; $writer = new AtomicWriter($filename); $writer->write("<?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) { $writer->write("\$this->items['" . $languageItem . "'] = '" . str_replace("'", "\\'", $languageItemValue) . "';\n"); // compile dynamic language variables if ($category->languageCategory != 'wcf.global' && strpos($languageItemValue, '{') !== false) { $writer->write("\$this->dynamicItems['" . $languageItem . "'] = '"); $output = LanguageFactory::getInstance()->getScriptingCompiler()->compileString($languageItem, $languageItemValue); $writer->write(str_replace("'", "\\'", $output['template'])); $writer->write("';\n"); } } $writer->flush(); $writer->close(); FileUtil::makeWritable($filename); } }
/** * Rebuilds the option file. */ public static function rebuild() { $writer = new AtomicWriter(WCF_DIR . 'options.inc.php'); // file header $writer->write("<?php\n/**\n* generated at " . gmdate('r') . "\n*/\n"); // get all options $options = Option::getOptions(); foreach ($options as $optionName => $option) { $writer->write("if (!defined('" . $optionName . "')) define('" . $optionName . "', " . ($option->optionType == 'boolean' || $option->optionType == 'integer' ? intval($option->optionValue) : "'" . addcslashes($option->optionValue, "'\\") . "'") . ");\n"); } unset($options); // file footer $writer->write("\n"); $writer->flush(); $writer->close(); FileUtil::makeWritable(WCF_DIR . 'options.inc.php'); WCF::resetZendOpcache(WCF_DIR . 'options.inc.php'); }