Exemplo n.º 1
0
 /**
  * Create the package
  * @param  String|Boolean $path     The path to the directory that is used
  *                                  to build the package or false if the
  *                                  $filelist argument is provided
  * @param  String         $mode     The type of package is build can be "stk",
  *                                  "language" or any of the "extra's"
  * @param  compress_zip   $builder  The compress object used for this package
  * @param  Array|Boolean  $filelist If false for the first argument this param
  *                                  contains the filelist
  * @param  String         $transl   Must be set when packing non-englis language
  *                                  files, as these translations will be checked
  * @return void
  */
 private function create_package($path, $mode, $builder, $filelist = false, $transl = '')
 {
     // Get the filelist
     if ($path !== false) {
         $filelist = $this->filelist($path);
     }
     // Get some mode specific data
     $dir_skip = $this->get_dir_ignores($mode);
     $file_skip = $this->get_file_ignores($mode);
     // Run through the filelist
     foreach ($filelist as $dir => $files) {
         // Empty stuff
         if (empty($files)) {
             continue;
         }
         // Skip dirs that this mode don't like
         if (!empty($dir_skip) && preg_match("#^{$dir_skip}#ise", $dir)) {
             continue;
         }
         $dir = !empty($dir) ? rtrim($dir, '/') . '/' : $dir;
         // Do the file magic
         foreach ($files as $file) {
             // If needed skip some files
             if ($file[0] == '.' || !empty($file_skip) && preg_match("#^{$file_skip}\$#ise", $file)) {
                 continue;
             }
             // Add to the package
             $dest = "{$dir}{$file}";
             $orig = "./../{$dir}{$file}";
             if ($mode == 'language') {
                 // When packing language files the path needs a slight adjustment
                 $dest = "{$transl}/{$dir}/{$file}";
                 $orig = "{$path}/{$dir}{$file}";
                 // Validate the language pack
                 if (!empty($transl)) {
                     $this->_validate_language_file($orig, $transl);
                 }
             }
             $builder->add_custom_file($orig, $dest);
         }
     }
 }
 /**
  * Merge MOD and the according language pack together
  *
  * @param bool $test Whether to generate the MOD package or just test the language pack
  */
 public function merge_packs($test = false)
 {
     global $phpbb_root_path, $config;
     /**
      * Unzip both packages
      */
     $mod = new compress_zip('r', $phpbb_root_path . $config['mods_tmp_dir_path'] . 'mods/' . $this->filename . '.zip');
     $mod->extract($phpbb_root_path . $config['mods_tmp_dir_path'] . 'mods/');
     /* ZipArchive is not currently supported on the server - leave this here for possible later use
     		$mod = new ZipArchive();
     		$mod->open($config['mods_tmp_dir_path'] . 'mods/' . $this->filename . '.zip');
     		$mod->extractTo($config['mods_tmp_dir_path'] . 'mods/');*/
     // If no localisation pack exists then we just check the original MOD package to make sure all Hungarian translation files are included
     if (file_exists($phpbb_root_path . $config['mods_tmp_dir_path'] . 'localisations/' . $this->filename . '.zip')) {
         $loc = new compress_zip('r', $phpbb_root_path . $config['mods_tmp_dir_path'] . 'localisations/' . $this->filename . '.zip');
         $loc->extract($phpbb_root_path . $config['mods_tmp_dir_path'] . 'localisations/');
     }
     /**
      * Merge packages
      */
     $errors = array();
     // Introduce variables with short names for frequently used file paths
     $mod_dir = $phpbb_root_path . $config['mods_tmp_dir_path'] . 'mods/' . $this->filename;
     $loc_dir = $phpbb_root_path . $config['mods_tmp_dir_path'] . 'localisations/' . $this->filename;
     // First look at the language files in the mods directory
     if (file_exists($mod_dir . '/root/language/en/') && !file_exists($mod_dir . '/root/language/hu/')) {
         $files = scandir_rec($mod_dir . '/root/language/en/');
         foreach ($files as $file) {
             if (!file_exists($loc_dir . '/root/language/hu/' . $file)) {
                 $errors[] = array('MISSING_LANGUAGE_FILE', 'root/language/hu/' . $file);
             } else {
                 // Check PHP syntax (assume we are on a unix-based system)
                 if (substr(shell_exec('php -l ' . $loc_dir . '/root/language/hu/' . $file), 0, 11) == 'Parse error') {
                     $errors[] = array('SYNTAX_ERROR', 'root/language/hu/' . $file);
                 } else {
                     $dir_name = $mod_dir . '/root/language/hu/' . site_dirname($file);
                     if (!file_exists($dir_name)) {
                         mkdir($dir_name, 0755, true);
                     }
                     rename($loc_dir . '/root/language/hu/' . $file, $mod_dir . '/root/language/hu/' . $file);
                 }
             }
         }
     }
     // Next the styles directory
     if (file_exists($mod_dir . '/root/styles/prosilver/imageset/en/') && !file_exists($mod_dir . '/root/styles/prosilver/imageset/hu/')) {
         // Check whether prosilver images are in place
         $files = scandir_rec($mod_dir . '/root/styles/prosilver/imageset/en/');
         foreach ($files as $file) {
             if (!file_exists($loc_dir . '/root/styles/prosilver/imageset/hu/' . $file)) {
                 $errors[] = array('MISSING_STYLE_IMAGE', '/root/styles/prosilver/imageset/hu/' . $file);
             }
         }
         // Copy all image files
         $files = scandir_rec($loc_dir . '/root/styles/');
         foreach ($files as $file) {
             if (substr($file, -4) == '.gif' && !file_exists($loc_dir . '/root/styles/' . $file)) {
                 $dir_name = $mod_dir . '/root/styles/' . site_dirname($file);
                 if (!file_exists($dir_name)) {
                     mkdir($dir_name, 0755, true);
                 }
                 rename($loc_dir . '/root/styles/' . $file, $mod_dir . '/root/styles/' . $file);
             }
         }
     }
     // Copy the entire contrib directory
     if (file_exists($loc_dir . '/contrib/')) {
         $files = scandir_rec($loc_dir . '/contrib/');
         foreach ($files as $file) {
             if (!file_exists($mod_dir . '/contrib/' . $file)) {
                 $dir_name = $mod_dir . '/contrib/' . site_dirname($file) . '/';
                 if (!file_exists($dir_name)) {
                     mkdir($dir_name, 0755, true);
                 }
                 rename($loc_dir . '/contrib/' . $file, $mod_dir . '/contrib/' . $file);
             }
         }
     }
     // Now the Hungarian MODX file
     if (file_exists($loc_dir . '/languages/hu.xml') && !file_exists($mod_dir . '/languages/hu.xml')) {
         if (!file_exists($mod_dir . '/languages/')) {
             mkdir($mod_dir . '/languages/', 0755);
         }
         rename($loc_dir . '/languages/hu.xml', $mod_dir . '/languages/hu.xml');
     }
     // Style localisations
     if (file_exists($loc_dir . '/templates/')) {
         $files = scandir_rec($loc_dir . '/templates/');
         foreach ($files as $file) {
             if (preg_match('#^([^/]+)\\/hu\\.xml$#is', $file, $match) && !file_exists($mod_dir . '/templates/' . $file)) {
                 mkdir($mod_dir . '/templates/' . $match[1], 0755, true);
                 rename($loc_dir . '/templates/' . $file, $mod_dir . '/templates/' . $file);
             }
         }
     }
     // And finally merge the translation and the original version of install.xml (or alternatively MOD_NAME.xml)
     // @todo implement the merge
     /**
      * "Zip everything back"
      */
     if (!empty($errors)) {
         throw new ModException($errors);
     }
     if ($test) {
         return true;
     }
     // Remove old file?
     if (file_exists($phpbb_root_path . $config['downloads_path'] . '/mods/' . $this->filename . '.zip')) {
         unlink($phpbb_root_path . $config['downloads_path'] . '/mods/' . $this->filename . '.zip');
     }
     /* ZipArchive is not supported on the server - but leave this here for possible later use
     		$final = new DirZipArchive();
     		$final->open('$config['downloads_path'] . '/mods/' . $this->filename . '.zip', ZIPARCHIVE::CREATE);
     		$final->addDir($mod_dir . '/', $this->filename);
     		$final->close();*/
     // Generate final MOD pack
     $final = new compress_zip('w', $phpbb_root_path . $config['downloads_path'] . '/mods/' . $this->filename . '.zip');
     $filelist = scandir_rec($mod_dir . '/');
     foreach ($filelist as $file) {
         // Add file to archive
         $final->add_custom_file($mod_dir . '/' . $file, $this->filename . '/' . $file);
     }
     $final->close();
     $this->data['size'] = filesize($phpbb_root_path . $config['downloads_path'] . '/mods/' . $this->filename . '.zip');
     return true;
 }