예제 #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;
 }
예제 #2
0
 function install_skin()
 {
     if (!isset($this->post['submit']) && !isset($this->get['newskin']) && !isset($this->get['skindetails']) && !isset($this->get['temp'])) {
         // Build drop down list for the OLD method
         $skin_box = '';
         $dp = opendir('../skins');
         while (($file = readdir($dp)) !== false) {
             $ext = strtolower(substr($file, -4));
             if ($ext == '.mbs') {
                 $skin_box .= "<option value='../skins/{$file}'>" . substr($file, 0, -4) . "</option>\n";
             }
         }
         closedir($dp);
         // Now check for skins using the NEW method
         // build a list of all the xml skin files
         $new_skin_box = '';
         $packages = packageutil::scan_packages();
         foreach ($packages as $package) {
             if ($package['type'] != 'skin') {
                 continue;
             }
             // skip other mods
             $new_skin_box .= "  <li><a href=\"{$this->self}?a=templates&amp;s=load&amp;newskin=";
             if (strtolower(substr($package['file'], -7)) == '.tar.gz') {
                 $new_skin_box .= urlencode(substr($package['file'], 0, -7)) . "\" ";
             } else {
                 $new_skin_box .= urlencode(substr($package['file'], 0, -4)) . "\" ";
             }
             if ($package['desc']) {
                 $new_skin_box .= "title=\"" . htmlspecialchars($package['desc']) . "\"";
             }
             $new_skin_box .= ">";
             $new_skin_box .= "<strong>" . htmlspecialchars($package['title']) . "</strong></a>";
             $new_skin_box .= " " . htmlspecialchars($package['version']);
             $new_skin_box .= " (" . htmlspecialchars($package['author']) . ")";
             $new_skin_box .= "</li>\n";
         }
         return $this->message($this->lang->install_skin, eval($this->template('ADMIN_INSTALL_SKIN')));
     } else {
         if (isset($this->get['skindetails'])) {
             // Display some preview information on the skin
         } else {
             if (isset($this->get['newskin'])) {
                 // Use new method of install
                 $tarTool = new archive_tar();
                 // Open and parse the XML file
                 $xmlInfo = new xmlparser();
                 if (file_exists('../packages/' . $this->get['newskin'] . '.xml')) {
                     $xmlInfo->parse('../packages/' . $this->get['newskin'] . '.xml');
                 } else {
                     if (file_exists('../packages/' . $this->get['newskin'] . '.tar')) {
                         $tarTool->open_file_reader('../packages/' . $this->get['newskin'] . '.tar');
                         $xmlFilename = $tarTool->extract_file('package.txt');
                         $xmlInfo->parseTar($tarTool, $xmlFilename);
                     } else {
                         if (file_exists('../packages/' . $this->get['newskin'] . '.tar.gz') && $tarTool->can_gunzip()) {
                             $tarTool->open_file_reader('../packages/' . $this->get['newskin'] . '.tar.gz');
                             $xmlFilename = $tarTool->extract_file('package.txt');
                             $xmlInfo->parseTar($tarTool, $xmlFilename);
                         } else {
                             return $this->message($this->lang->install_skin, $this->lang->skin_none);
                         }
                     }
                 }
                 // Get the folder name
                 $node = $xmlInfo->GetNodeByPath('QSFMOD/TYPE');
                 $skin_dir = $node['attrs']['FOLDER'];
                 // 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'));
                 // Add the templates
                 packageutil::insert_templates($skin_dir, $this->db, $xmlInfo->GetNodeByPath('QSFMOD/TEMPLATES'));
                 // Extract the files
                 if (file_exists('../packages/' . $this->get['newskin'] . '.tar')) {
                     $tarTool->open_file_reader('../packages/' . $this->get['newskin'] . '.tar');
                 } else {
                     $tarTool->open_file_reader('../packages/' . $this->get['newskin'] . '.tar.gz');
                 }
                 $nodes = $xmlInfo->GetNodeByPath('QSFMOD/FILES');
                 foreach ($nodes['child'] as $node) {
                     if ($node['name'] == 'FILE') {
                         $filename = $node['content'];
                         $data = $tarTool->extract_file($filename);
                         if ($data !== false) {
                             $this->_make_dir('../' . $filename);
                             $fh = fopen('../' . $filename, 'wb');
                             fwrite($fh, $data);
                             fclose($fh);
                         }
                     }
                 }
                 $tarTool->close_file();
                 $this->chmod('../skins/' . $skin_dir, 0777, true);
                 return $this->message($this->lang->install_skin, $this->lang->install_done);
             } else {
                 // Use old method of install
                 if (!isset($this->get['temp']) && !isset($this->get['install'])) {
                     if (!isset($this->post['install'])) {
                         return $this->message($this->lang->install_skin, $this->lang->skin_none);
                     }
                     $dir = md5(microtime());
                     $zip = new qsf_zip();
                     $zip->extract($this->post['install'], "../skins/{$dir}");
                     $this->chmod("../skins/{$dir}", 0777, true);
                     include "../skins/{$dir}/info.php";
                     if (is_dir("../skins/{$skin['dir']}")) {
                         return $this->message($this->lang->install_skin, "{$this->lang->install_exists1} <b>{$skin['name']}</b> {$this->lang->install_exists2}", $this->lang->install_overwrite, "{$this->self}?a=templates&amp;s=load&amp;temp={$dir}");
                     }
                     $this->get['temp'] = $dir;
                 }
                 $dir = $this->get['temp'];
                 include "../skins/{$dir}/info.php";
                 if (is_dir("../skins/{$skin['dir']}")) {
                     $this->remove_dir("../skins/{$skin['dir']}");
                 }
                 rename("../skins/{$dir}", "../skins/{$skin['dir']}");
                 $this->chmod("../skins/{$skin['dir']}", 0777, true);
                 $dir = $skin['dir'];
                 $queries = array();
                 $pre = $this->db->prefix;
                 include "../skins/{$dir}/templates.php";
                 $this->db->query("DELETE FROM %pskins WHERE skin_dir='%s'", $dir);
                 $this->db->query("INSERT INTO %pskins (skin_name, skin_dir) VALUES ('%s', '%s')", $skin['name'], $dir);
                 $this->db->query("DELETE FROM %ptemplates WHERE template_skin='%s'", $dir);
                 $this->execute_queries($queries);
                 return $this->message($this->lang->install_skin, $this->lang->install_done);
             }
         }
     }
 }
예제 #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);
     }
 }