示例#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'])) {
         // 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
         $tarTool = new archive_tar();
         $xmlInfo = new xmlparser();
         $new_skin_box = '';
         $dp = opendir('../packages');
         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('../packages/' . $file)) {
                     // Okay. Look at packages.txt to find our xml file
                     $xmlFilename = $tarTool->extract_file('package.txt');
                     if ($xmlFilename === false) {
                         continue;
                     }
                     $xmlData = $tarTool->extract_file($xmlFilename);
                     $xmlInfo->parseTar($tarTool, $xmlFilename);
                 } else {
                     continue;
                 }
             } else {
                 if (strtolower(substr($file, -4)) == '.xml') {
                     $xmlInfo->parse('../packages/' . $file);
                 } else {
                     $xmlInfo->reset();
                     continue;
                     // skip file
                 }
             }
             $node = $xmlInfo->GetNodeByPath('QSFMOD/TYPE');
             if ($node['content'] != 'skin') {
                 continue;
             }
             // skip other mods
             $new_skin_box .= "  <li><a href=\"{$this->self}?a=templates&amp;s=load&amp;newskin=";
             if (strtolower(substr($file, -7)) == '.tar.gz') {
                 $new_skin_box .= urlencode(substr($file, 0, -7)) . "\" ";
             } else {
                 $new_skin_box .= urlencode(substr($file, 0, -4)) . "\" ";
             }
             $node = $xmlInfo->GetNodeByPath('QSFMOD/DESCRIPTION');
             if (isset($node['content']) && $node['content']) {
                 $new_skin_box .= "title=\"" . htmlspecialchars($node['content']) . "\"";
             }
             $new_skin_box .= ">";
             $node = $xmlInfo->GetNodeByPath('QSFMOD/TITLE');
             $new_skin_box .= "<strong>" . htmlspecialchars($node['content']) . "</strong></a>";
             $node = $xmlInfo->GetNodeByPath('QSFMOD/VERSION');
             $new_skin_box .= " " . htmlspecialchars($node['content']);
             $node = $xmlInfo->GetNodeByPath('QSFMOD/AUTHORNAME');
             $new_skin_box .= " (" . htmlspecialchars($node['content']) . ")";
             $new_skin_box .= "</li>\n";
             $xmlInfo->reset();
         }
         closedir($dp);
         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 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);
             }
         }
     }
 }