/** * Exports all rules as XML * * @param \DataContainer $dc */ public function export(\DataContainer $dc) { if (($ruleCollection = RuleModel::findBy('pid', $dc->id, array('order' => 'sorting'))) === null) { return; } $this->doc = new \DOMDocument('1.1', 'UTF-8'); $rules = $this->doc->createElement('rules'); foreach ($ruleCollection as $rule) { $rules->appendChild($this->createRuleElement($rule)); } $this->doc->appendChild($rules); $file = new \File('system/tmp/' . md5(uniqid(mt_rand(), true)), true); $file->write($this->doc->saveXML()); $file->close(); $file->sendToBrowser('css_class_replacer_ruleset.xml'); $file->delete(); }
/** * Import a rule set * * @param string * @param int */ private function importRuleSet($file, $themeId) { $file = new \File($file, true); $doc = new \DOMDocument('1.1', 'UTF-8'); $doc->loadXML($file->getContent()); $rules = $doc->getElementsByTagName('rule'); $sortIndex = 0; $lastRule = RuleModel::findBy('pid', $themeId, array('order' => 'sorting DESC', 'limit' => 1)); if ($lastRule) { $sortIndex = $lastRule->sorting + 128; } foreach ($rules as $rule) { $set = array('pid' => $themeId, 'sorting' => $sortIndex, 'type' => $rule->getElementsByTagName('type')->item(0)->nodeValue, 'selector' => $rule->getElementsByTagName('selector')->item(0)->nodeValue, 'enable_replace' => $rule->getElementsByTagName('enable_replace')->item(0)->nodeValue === 'true' ? '1' : '', 'replace_directives' => $rule->getElementsByTagName('replace_directives')->item(0)->nodeValue, 'enable_add' => $rule->getElementsByTagName('enable_add')->item(0)->nodeValue === 'true' ? '1' : '', 'add_directives' => $rule->getElementsByTagName('add_directives')->item(0)->nodeValue, 'published' => $rule->getElementsByTagName('published')->item(0)->nodeValue === 'true' ? '1' : ''); $sortIndex += 128; \Database::getInstance()->prepare('INSERT INTO tl_css_class_replacer %s')->set($set)->execute(); } }