public function writeTemplates($fileClass, $styleId) { DevTools_Helper_File::createDirectory(XenForo_Application::getInstance()->getRootDir() . DIRECTORY_SEPARATOR . 'templates'); $templates = $this->getTemplates($styleId); $fileTemplate = new $fileClass(); foreach ($templates as $template) { $template['id'] = $template['template_id']; $filePath = $fileTemplate->getDirectory($template) . DIRECTORY_SEPARATOR . $fileTemplate->getFileName($template); if (!file_exists($filePath)) { $contents = $this->getModelFromCache('XenForo_Model_StyleProperty')->replacePropertiesInTemplateForEditor($template['template'], $styleId, $fileTemplate->getPropertiesInStyle($styleId)); $contents = $this->getModelFromCache('XenForo_Model_Template')->replaceIncludesWithLinkRel($contents); $fileTemplate->printDebugInfo('Writing ' . $fileTemplate->getDataType() . ' "' . $template['title'] . '" to ' . $filePath . '...'); DevTools_Helper_File::write($filePath, $contents); $file = new $fileClass($filePath); $file->touchDb(); $fileTemplate->printDebugInfo(" done\n"); } } foreach ($this->getModelFromCache('XenForo_Model_AddOn')->getAllAddOns() as $addon) { DevTools_Helper_File::createDirectory($fileTemplate->getDirectory($addon)); } }
public static function postDataWriterSave(XenForo_DataWriter $writer, array $extraData = array()) { $self = new self(); $oldPath = false; $oldData = array_merge($writer->getMergedExistingData(), array('id' => $writer->get('phrase_id'))); if ($writer->isUpdate()) { $oldPath = $self->getDirectory($writer->getMergedExistingData()) . self::$s . $self->getFileName($oldData); } $newPath = false; $newData = array_merge($writer->getMergedData(), array('id' => $writer->get('phrase_id'))); if ($writer->isChanged('addon_id') or $writer->isChanged('title')) { $newPath = $self->getDirectory($newData) . self::$s . $self->getFileName($newData); } if (!$oldPath) { $oldPath = $newPath; } if (!DevTools_Helper_File::write($oldPath, $writer->get('phrase_text'), array('id' => $writer->get('phrase_id')))) { throw new XenForo_Exception("Failed to write phrase file to {$oldPath}"); return; } if ($newPath && $oldPath) { rename($oldPath, $newPath); } $self->touchDb(); }
public static function postDataWriterSave(XenForo_DataWriter $writer, array $extraData = array()) { if (!isset($extraData['styleId']) || !isset($extraData['self'])) { return; } $styleId = $extraData['styleId']; $self = $extraData['self']; $oldPath = false; $oldData = array_merge($writer->getMergedExistingData(), array('id' => $writer->get('template_id'))); if ($writer->isUpdate()) { $oldPath = $self->getDirectory($writer->getMergedExistingData()) . self::$s . $self->getFileName($oldData); } $newPath = false; $newData = array_merge($writer->getMergedData(), array('id' => $writer->get('template_id'))); if ($writer->isChanged('addon_id') or $writer->isChanged('title')) { $newPath = $self->getDirectory($writer->getMergedData()) . self::$s . $self->getFileName($newData); } if (!$oldPath) { $oldPath = $newPath; } $contents = XenForo_Model::create('XenForo_Model_StyleProperty')->replacePropertiesInTemplateForEditor($writer->get('template'), $styleId, $self->getPropertiesInStyle($styleId)); $contents = XenForo_Model::create('XenForo_Model_Template')->replaceIncludesWithLinkRel($contents); if (!DevTools_Helper_File::write($oldPath, $contents, array('id' => $writer->get('template_id'), 'dbName' => XenForo_Application::getConfig()->db->dbname))) { throw new XenForo_Exception("Failed to write template file to {$oldPath}"); return; } if ($newPath and $oldPath) { rename($oldPath, $newPath); } $self->touchDb(); }
public function trashFile(array $oldData) { $trashPath = $this->getDirectory($oldData) . self::$s . '.trash' . self::$s . '__' . $oldData['id'] . '.' . $this->getFileName($oldData); if (DevTools_Helper_File::createDirectory(dirname($trashPath))) { DevTools_Helper_File::write($trashPath, $oldData['contents']); $this->printDebugInfo("- backed up to \"{$trashPath}\"\n"); } }