<?php if (!defined('VB_ENTRY')) die('Access denied.'); abstract class vB_Xml_Import { use vB_Trait_NoSerialize; const OPTION_OVERWRITE = 1; const OPTION_IGNOREMISSINGROUTES = 2; const OPTION_IGNOREMISSINGPARENTS = 4; const OPTION_ADDWIDGETS = 8; const OPTION_OVERWRITECOLUMN = 16; const OPTION_ADDSPECIFICWIDGETS = 32; const TYPE_ROUTE = 'routes'; const TYPE_CHANNEL = 'channels'; const TYPE_PAGE = 'pages'; const TYPE_PAGETEMPLATE = 'pageTemplates'; const TYPE_WIDGET = 'widgets'; const TYPE_THEME = 'themes'; const TYPE_SCREENLAYOUT = 'screenLayouts'; protected $db; protected $options; protected $parsedXML; protected $productid; protected static $importedElements; protected $overwriteColumn = ''; public function __construct($productid = 'vbulletin', $options = 9) { $this->db = vB::getDbAssertor(); $this->productid = $productid; $this->options = $options; } public function setOptions($options) { $this->options = $options; } public function setOverwriteColumn($column) { $this->overwriteColumn = (string) $column; } protected static function setImportedId($type, $guid, $newid) { self::$importedElements[$type][$guid] = $newid; } public static function getImportedId($type, $guid = NULL) { if ($guid == NULL) { return (isset(self::$importedElements[$type]) ? self::$importedElements[$type] : array()); } else { if (isset(self::$importedElements[$type]) AND isset(self::$importedElements[$type][$guid])) { return self::$importedElements[$type][$guid]; } else { return false; } } } public function importFromFile($filepath, $guid = false) { $this->parsedXML = vB_Xml_Import::parseFile($filepath); $this->import($guid); } public function importFromParsedXML($parsedXML) { $this->parsedXML = $parsedXML; $this->import(); } protected abstract function import(); public static function parseFile($filepath) { $xmlobj = new vB_XML_Parser(false, $filepath); if ($xmlobj->error_no() == 1 OR $xmlobj->error_no() == 2) { throw new Exception("Please ensure that the file $filepath exists"); } if (!$parsed_xml = $xmlobj->parse()) { throw new Exception('xml error '. $xmlobj->error_string() . ', on line ' . $xmlobj->error_line()); } return $parsed_xml; } protected function replacePhrasePlaceholdersInArray(array $array) { $phrases = array(); foreach ($array AS $k => $v) { if (is_string($v) AND substr($v, 0, 7) == 'phrase:') { $phrase = substr($v, 7); $phrases[$phrase] = $phrase; } } if (!empty($phrases)) { $phrases = vB_Api::instanceInternal('phrase')->renderPhrases($phrases); $phrases = $phrases['phrases']; foreach ($array AS $k => $v) { if (is_string($v) AND substr($v, 0, 7) == 'phrase:' AND !empty($phrases[substr($v, 7)])) { $array[$k] = $phrases[substr($v, 7)]; } } } return $array; } protected function saveWidgetTranslableTextFieldsToPhraseSystem(int $widgetinstanceid, array &$adminConfig) : bool { $modified = false; $fields = [ 'title', 'searchTitle', ]; $widgetLib = vB_Library::instance('widget'); foreach ($fields AS $__key) { if (!empty($adminConfig[$__key])) { assert(strpos($adminConfig[$__key], 'phrase:') === false, "Widget $__key should NOT be a phrase key at this point!"); $__prefix = substr($adminConfig[$__key], 0, 7); if ( $__prefix == 'widget_' ) { continue; } $__phraseTitle = $widgetLib->saveWidgetDefaultTranslableText($widgetinstanceid, $__key, $adminConfig[$__key], true); $adminConfig[$__key] = $__phraseTitle; $modified = true; } } return $modified; } } 