Example #1
0
 /**
  * Looks through all XML docs in packages folder and pulls basic list data for them
  *
  * @author Geoffrey Dunn <*****@*****.**>
  * @since 1.3.0
  * @return array Structured array of packages info
  **/
 function scan_packages($folder = '../packages/')
 {
     if (substr($folder, -1) != '/') {
         $folder .= '/';
     }
     $packages = array();
     $tarTool = new archive_tar();
     $xmlInfo = new xmlparser();
     $dp = opendir($folder);
     while (($file = readdir($dp)) !== false) {
         if (strtolower(substr($file, -4)) == '.tar' || strtolower(substr($file, -7)) == '.tar.gz' && $tarTool->can_gunzip()) {
             if ($tarTool->open_file_reader($folder . $file)) {
                 // Okay. Look at packages.txt to find our xml file
                 $xmlFilename = $tarTool->extract_file('package.txt');
                 if ($xmlFilename === false) {
                     continue;
                 }
                 $xmlInfo->parseTar($tarTool, $xmlFilename);
             } else {
                 continue;
             }
         } else {
             if (strtolower(substr($file, -4)) == '.xml') {
                 $xmlInfo->parse($folder . $file);
             } else {
                 continue;
                 // skip file
             }
         }
         $node = $xmlInfo->GetNodeByPath('QSFMOD/TYPE');
         $package_type = $node['content'];
         $node = $xmlInfo->GetNodeByPath('QSFMOD/TITLE');
         $package_title = $node['content'];
         $node = $xmlInfo->GetNodeByPath('QSFMOD/DESCRIPTION');
         if (isset($node['content']) && $node['content']) {
             $package_desc = $node['content'];
         } else {
             $package_desc = '';
         }
         $node = $xmlInfo->GetNodeByPath('QSFMOD/VERSION');
         $package_version = $node['content'];
         $node = $xmlInfo->GetNodeByPath('QSFMOD/AUTHORNAME');
         $package_author = $node['content'];
         $packages[] = array('file' => $file, 'type' => $package_type, 'title' => $package_title, 'desc' => $package_desc, 'version' => $package_version, 'author' => $package_author);
         $xmlInfo->reset();
     }
     closedir($dp);
     return $packages;
 }
Example #2
0
 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&amp;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);
     }
 }
Example #3
0
 /**
  * Restore a backup
  *
  * @author Jason Warner <*****@*****.**>
  * @since 1.0.2
  * @return string HTML
  **/
 function restore_backup()
 {
     if (!isset($this->get['restore'])) {
         $tarTool = new archive_tar();
         $xmlInfo = new xmlparser();
         $new_backup_box = '';
         $packages = packageutil::scan_packages();
         foreach ($packages as $package) {
             if ($package['type'] != 'backup') {
                 continue;
             }
             // skip other mods
             $new_backup_box .= "  <li><a href=\"{$this->self}?a=backup&amp;s=restore&amp;restore=";
             if (strtolower(substr($package['file'], -7)) == '.tar.gz') {
                 $new_backup_box .= urlencode(substr($package['file'], 0, -7)) . "\" ";
             } else {
                 $new_backup_box .= urlencode(substr($package['file'], 0, -4)) . "\" ";
             }
             if ($package['desc']) {
                 $new_backup_box .= "title=\"" . htmlspecialchars($package['desc']) . "\"";
             }
             $new_backup_box .= ">";
             $new_backup_box .= "<strong>" . htmlspecialchars($package['title']) . "</strong></a>";
             $new_backup_box .= " " . htmlspecialchars($package['version']);
             $new_backup_box .= " (" . htmlspecialchars($package['author']) . ")";
             $new_backup_box .= "</li>\n";
         }
         if ($new_backup_box) {
             return $this->message($this->lang->backup_restore, "\n\t\t\t\t<div>\n\t\t\t\t\t{$this->lang->backup_found}:<br /><br />\n\t\t\t\t\t{$new_backup_box}\n\t\t\t\t\t\n\t\t\t\t\t<b>{$this->lang->backup_warning}</b>\n\t\t\t\t</div>");
         } else {
             return $this->message($this->lang->backup_restore, $this->lang->backup_none);
         }
     } else {
         $tarTool = new archive_tar();
         // Open and parse the XML file
         $xmlInfo = new xmlparser();
         if (file_exists('../packages/' . $this->get['restore'] . '.xml')) {
             $xmlInfo->parse('../packages/' . $this->get['restore'] . '.xml');
         } else {
             if (file_exists('../packages/' . $this->get['restore'] . '.tar')) {
                 $tarTool->open_file_reader('../packages/' . $this->get['restore'] . '.tar');
                 $xmlFilename = $tarTool->extract_file('package.txt');
                 $xmlInfo->parseTar($tarTool, $xmlFilename);
             } else {
                 if (file_exists('../packages/' . $this->get['restore'] . '.tar.gz') && $tarTool->can_gunzip()) {
                     $tarTool->open_file_reader('../packages/' . $this->get['restore'] . '.tar.gz');
                     $xmlFilename = $tarTool->extract_file('package.txt');
                     $xmlInfo->parseTar($tarTool, $xmlFilename);
                 } else {
                     return $this->message($this->lang->backup_restore, $this->lang->backup_invalid);
                 }
             }
         }
         // Run the uninstall queries
         packageutil::run_queries($this->db, $xmlInfo->GetNodeByPath('QSFMOD/UNINSTALL'));
         // Run the install queries
         packageutil::run_queries($this->db, $xmlInfo->GetNodeByPath('QSFMOD/INSTALL'));
         // Done!
         return $this->message($this->lang->backup_restore, $this->lang->backup_restore_done);
     }
 }