function export_skin() { if (!isset($this->post['skin'])) { $skin_box = $this->htmlwidgets->select_skins($this->skin); return $this->message($this->lang->export_skin, "\n\t\t\t{$this->lang->export_select}:<br /><br />\n\t\t\t<form action='{$this->self}?a=templates&s=export' method='post'><div>\n\t\t\t\t<select name='skin'>\n\t\t\t\t\t{$skin_box}\n\t\t\t\t</select>\n\t\t\t\t<input type='submit' value='{$this->lang->export_skin}' /></div>\n\t\t\t</form>"); } else { // Dump the skin data into an XML file $skin = $this->db->fetch("SELECT * FROM %pskins WHERE skin_dir='%s'", $this->post['skin']); $fullSkinName = $skin['skin_dir'] . "-" . $this->version; if (file_exists("../packages/skin_{$fullSkinName}.xml")) { unlink("../packages/skin_{$fullSkinName}.xml"); } $xmlFile = fopen("../packages/skin_{$fullSkinName}.xml", 'w'); if ($xmlFile === false) { return $this->message($this->lang->export_skin, "Error: Could not open file packages/skin_{$fullSkinName}.xml for writing"); } fwrite($xmlFile, "<?xml version='1.0' encoding='utf-8'?>\n"); fwrite($xmlFile, "<qsfmod>\n"); fwrite($xmlFile, " <title>Skin: " . htmlspecialchars($skin['skin_name']) . "</title>\n"); // Skin types need to specify a folder fwrite($xmlFile, " <type folder=\"" . htmlspecialchars($skin['skin_dir']) . "\">skin</type>\n"); fwrite($xmlFile, " <version>{$this->version}</version>\n"); fwrite($xmlFile, " <description></description>\n"); fwrite($xmlFile, " <authorname>Skin Exporter</authorname>\n"); fwrite($xmlFile, " <files>\n"); fwrite($xmlFile, " <file>packages/skin_{$fullSkinName}.xml</file>\n"); $files = $this->recursive_dir("../skins/{$skin['skin_dir']}", "skins/{$skin['skin_dir']}"); foreach ($files as $file) { fwrite($xmlFile, " <file>" . htmlspecialchars($file) . "</file>\n"); } fwrite($xmlFile, " </files>\n"); fwrite($xmlFile, " <templates>\n"); $query = $this->db->query("SELECT * FROM %ptemplates WHERE template_skin = '%s'", $skin['skin_dir']); while ($row = $this->db->nqfetch($query)) { fwrite($xmlFile, " <template><set>{$row['template_set']}</set><name>{$row['template_name']}</name>\n"); fwrite($xmlFile, " <displayname>" . htmlspecialchars($row['template_displayname']) . "</displayname>\n"); fwrite($xmlFile, " <description>" . htmlspecialchars($row['template_description']) . "</description>\n"); fwrite($xmlFile, " <html><![CDATA[\n"); fwrite($xmlFile, utf8_encode(trim($row['template_html'])) . "\n"); fwrite($xmlFile, " ]]></html>\n"); fwrite($xmlFile, " </template>\n"); } fwrite($xmlFile, " </templates>\n"); fwrite($xmlFile, " <install>\n"); fwrite($xmlFile, " <query>\n"); fwrite($xmlFile, " <sql>INSERT INTO %pskins (skin_name, skin_dir) VALUES ('%s', '%s')</sql>\n"); fwrite($xmlFile, " <data>" . htmlspecialchars($skin['skin_name']) . "</data>\n"); fwrite($xmlFile, " <data>" . htmlspecialchars($skin['skin_dir']) . "</data>\n"); fwrite($xmlFile, " </query>\n"); fwrite($xmlFile, " </install>\n"); fwrite($xmlFile, " <uninstall>\n"); fwrite($xmlFile, " <query>\n"); fwrite($xmlFile, " <sql>DELETE FROM %pskins WHERE skin_dir ='%s'</sql>\n"); fwrite($xmlFile, " <data>" . htmlspecialchars($skin['skin_dir']) . "</data>\n"); fwrite($xmlFile, " </query>\n"); fwrite($xmlFile, " <query>\n"); fwrite($xmlFile, " <sql>DELETE FROM %ptemplates WHERE template_skin ='%s'</sql>\n"); fwrite($xmlFile, " <data>" . htmlspecialchars($skin['skin_dir']) . "</data>\n"); fwrite($xmlFile, " </query>\n"); fwrite($xmlFile, " </uninstall>\n"); fwrite($xmlFile, "</qsfmod>\n"); fclose($xmlFile); $tarTool = new archive_tar(); $tarTool->open_file_writer("../packages/skin_{$fullSkinName}", true); // Always wise to make these first for speed $tarTool->add_as_file("packages/skin_{$fullSkinName}.xml", 'package.txt'); $tarTool->add_file("../packages/skin_{$fullSkinName}.xml", "packages/skin_{$fullSkinName}.xml"); // Now throw in everything else $tarTool->add_dir("../skins/{$skin['skin_dir']}", "skins/{$skin['skin_dir']}"); $filename = $tarTool->close_file(); @unlink("../packages/skin_{$fullSkinName}.xml"); $this->chmod($filename, 0777); return $this->message($this->lang->export_skin, $this->lang->export_done, basename($filename), $filename); } }
/** * Generate a backup * * @author Jason Warner <*****@*****.**> * @since 1.0.2 * @return string HTML **/ function create_backup() { if (!isset($this->get['option'])) { return $this->message($this->lang->backup_options, "<ul>\n\t\t\t\t<li><a href=\"{$this->self}?a=backup&s=create&option=download\">{$this->lang->backup_download}</a></li>\n\t\t\t\t<li><a href=\"{$this->self}?a=backup&s=create&option=file\">{$this->lang->backup_createfile}</a></li>\n\t\t\t\t</ul>"); } else { if ($this->get['option'] == 'download') { $this->nohtml = true; $fullBackupName = "backup_" . $this->version . "-" . date('y-m-d-H-i-s'); header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"{$fullBackupName}.xml\""); echo "<?xml version='1.0' encoding='utf-8'?>\n"; echo "<qsfmod>\n"; echo " <title>Backup: " . $this->version . " - " . date('y-m-d-H-i-s') . "</title>\n"; echo " <type>backup</type>\n"; echo " <version>{$this->version}-" . date('y-m-d-H-i-s') . "</version>\n"; echo " <description></description>\n"; echo " <authorname>Backup Tool</authorname>\n"; echo " <files>\n"; echo " <file>packages/{$fullBackupName}.xml</file>\n"; echo " </files>\n"; echo " <templates>\n"; echo " </templates>\n"; echo " <install>\n"; $this->create_dump($this->tables); echo " </install>\n"; echo " <uninstall>\n"; $this->create_truncate($this->tables); echo " </uninstall>\n"; echo "</qsfmod>\n"; } else { if ($this->get['option'] == 'file') { $fullBackupName = "backup_" . $this->version . "-" . date('y-m-d-H-i-s'); if (file_exists("../packages/{$fullBackupName}.xml")) { die("../packages/{$fullBackupName}.xml already exists!"); } $xmlFile = fopen("../packages/{$fullBackupName}.xml", 'w'); if ($xmlFile === false) { return $this->message($this->lang->backup_create, "Error: Could not open file ../packages/{$fullBackupName}.xml for writing"); } fwrite($xmlFile, "<?xml version='1.0' encoding='utf-8'?>\n"); fwrite($xmlFile, "<qsfmod>\n"); fwrite($xmlFile, " <title>Backup: " . $this->version . " - " . date('y-m-d-H-i-s') . "</title>\n"); fwrite($xmlFile, " <type>backup</type>\n"); fwrite($xmlFile, " <version>{$this->version}-" . date('y-m-d-H-i-s') . "</version>\n"); fwrite($xmlFile, " <description></description>\n"); fwrite($xmlFile, " <authorname>Backup Tool</authorname>\n"); fwrite($xmlFile, " <files>\n"); fwrite($xmlFile, " <file>packages/{$fullBackupName}.xml</file>\n"); fwrite($xmlFile, " </files>\n"); fwrite($xmlFile, " <templates>\n"); fwrite($xmlFile, " </templates>\n"); fwrite($xmlFile, " <install>\n"); $this->create_dump($this->tables, $xmlFile); fwrite($xmlFile, " </install>\n"); fwrite($xmlFile, " <uninstall>\n"); $this->create_truncate($this->tables, $xmlFile); fwrite($xmlFile, " </uninstall>\n"); fwrite($xmlFile, "</qsfmod>\n"); fclose($xmlFile); $tarTool = new archive_tar(); $tarTool->open_file_writer("../packages/{$fullBackupName}", true); $tarTool->add_as_file("packages/{$fullBackupName}.xml", 'package.txt'); $tarTool->add_file("../packages/{$fullBackupName}.xml", "packages/{$fullBackupName}.xml"); $filename = $tarTool->close_file(); @unlink("../packages/{$fullBackupName}.xml"); $this->chmod($filename, 0777); return $this->message($this->lang->backup_create, $this->lang->backup_done, $filename, "../packages/{$filename}"); } } } }