/** * Validate a given package * * @access public * @param string Path to MOD package (.zip) * @return void */ public function validate($package) { global $root_path, $phpEx, $lang; // Clear some data $this->errors = array(); $this->message = ''; $this->zip_file = $package; $this->message .= sprintf($lang['VALIDATING_ZIP'], $this->orig_package_name) . "\n\n"; $this->push_error(self::ERROR_NOTICE, 'GENERAL_NOTICE'); // Add a general notice about possible wrong fails. // First see if the package actually exists if (!file_exists($package)) { $this->push_error(self::ERROR_FAIL, 'PACKAGE_NOT_EXISTS', __FILE__, $package); $this->cleanup(); return; } $this->temp_dir = $root_path . 'store/temp/mpv_' . md5(uniqid(time())) . '/'; mkdir($this->temp_dir, 0777, true); if (defined('MPV_DEBUG') && MPV_DEBUG) { $type = ''; switch ($this->unzip_type) { case self::UNZIP_EXEC: $type = $lang['TYPE_EXEC']; break; case self::UNZIP_PHP: $type = $lang['TYPE_PHP']; break; case self::UNZIP_PHPBB: $type = $lang['TYPE_PHPBB']; break; default: $this->push_error(self::ERROR_FAIL, 'INVALID_ZIP_METHOD', __FILE__, $this->zip_type); $this->cleanup(); return; } $this->push_error(self::ERROR_INFO, 'ZIP_METHOD', __FILE__, $this->unzip_type, $type); } if ($this->unzip_type == self::UNZIP_EXEC) { $basename = basename($package); copy($package, $this->temp_dir . $basename); // Unzip it. exec('cd ' . escapeshellarg($this->temp_dir) . ' && unzip ' . escapeshellarg($basename)); } else { if ($this->unzip_type == self::UNZIP_PHP) { $zip = new ZipArchive(); if ($zip->open($package) === true) { if (!$zip->extractTo($this->temp_dir)) { $zip->close(); $this->push_error(self::ERROR_FAIL, 'UNABLE_EXTRACT_PHP', __FILE__, $package); $this->cleanup(); return; } $zip->close(); } else { $this->push_error(self::ERROR_FAIL, 'UNABLE_OPEN_PHP', __FILE__, $package); $this->cleanup(); return; } } else { if ($this->unzip_type == self::UNZIP_PHPBB) { if (!class_exists('compress_zip')) { include $root_path . 'includes/functions_compress.' . $phpEx; } // Next, try to unzip it $compress = new compress_zip('r', $package); $compress->extract($this->temp_dir); } else { $this->push_error(self::ERROR_FAIL, 'INVALID_ZIP_METHOD', __FILE__, $this->unzip_type); $this->cleanup(); return; } } } $file_exists = 0; $dir_exists = 0; if ($dh = opendir($this->temp_dir)) { while (false !== ($file = readdir($dh))) { if ($file == '.' || $file == '..') { continue; } if (is_dir($this->temp_dir . $file)) { $dir_exists++; $dir = $file; } if (is_file($this->temp_dir . $file) && $file != $package) { $file_exists++; } } closedir($dh); } if (!$file_exists && $dir_exists) { self::$mod_dir = $dir; } foreach (self::dir_files($this->temp_dir, '', true) as $file) { $this->package_files[] = $file; $ext = substr(strrchr($file, '.'), 1); if ($ext == 'xsl') { $this->xsl_files[] = $file; } else { if ($ext == 'xml') { $raw_xml = file_get_contents($this->temp_dir . $file); if (strpos($raw_xml, '<mod xmlns:xsi=') !== false || strpos($raw_xml, '<mod xmlns=') !== false) { $modx_file = $file; $this->error = array(); set_error_handler(array($this, 'internal_error')); $tmp = cortex_xml::load_file($this->temp_dir . $file); restore_error_handler(); if ($this->error || !$tmp) { foreach ($this->error as $error) { $this->push_error(self::ERROR_FAIL, 'MPV_XML_ERROR', $file, $error); } } else { $this->modx_files[$modx_file] = $tmp; } } unset($raw_xml); } } } // Run the tests foreach ($this->test_collections as $collection) { $collection->run(); } // Now get rid of $this->temp_dir $this->cleanup(); }