コード例 #1
0
 /**
  * Extract style package to demo board.
  *
  * @return null
  */
 public function extract_package()
 {
     $this->package->ensure_extracted();
     $package_root = $this->package->find_directory(array('files' => array('required' => 'style.cfg')));
     $style_root = $this->get_style_dir();
     $filesystem = new \Symfony\Component\Filesystem\Filesystem();
     $filesystem->remove($style_root);
     $filesystem->rename($this->package->get_temp_path() . '/' . $package_root, $style_root);
 }
コード例 #2
0
 /**
  * Get composer.json contents from a zip file.
  *
  * @param string $file Path to the zip file
  * @return string Returns the content of the composer.json
  */
 protected function get_composer_json($file)
 {
     $path = $this->package->set_source($file)->set_temp_path($this->ext_config->__get('contrib_temp_path'), true)->extract()->find_directory(array('files' => array('required' => 'composer.json')), 'vendor');
     $composer_json = '';
     if ($path !== null) {
         $composer_json = file_get_contents($this->package->get_temp_path() . '/' . $path . '/composer.json');
     }
     $this->package->cleanup();
     return $composer_json;
 }
コード例 #3
0
ファイル: manager.php プロジェクト: Sajaki/customisation-db
 /**
  * Extract style package to demo board.
  *
  * @return null
  */
 public function extract_package()
 {
     $this->package->ensure_extracted();
     $package_root = $this->package->find_directory(array('files' => array('required' => 'style.cfg')));
     $style_root = $this->get_style_dir();
     $filesystem = new \Symfony\Component\Filesystem\Filesystem();
     $filesystem->remove($style_root);
     // Only copy necessary files
     $finder = new Finder();
     $finder->ignoreVCS(false)->ignoreDotFiles(false)->files()->notName('/\\.(svg|png|jpe?g|gif|html|js|css|cfg)$/i')->in($this->package->get_temp_path());
     $filesystem->remove($finder);
     $filesystem->rename($this->package->get_temp_path() . '/' . $package_root, $style_root);
 }
コード例 #4
0
ファイル: type.php プロジェクト: OfficeForum/customisation-db
 /**
  * Repack extension to add version check info and match
  * correct directory structure to given ext name.
  *
  * @param package $package
  * @param \titania_contribution $contrib
  * @pram \titania_revision $revision
  * @throws \Exception if an error occurred
  */
 protected function repack(package $package, \titania_contribution $contrib, \titania_revision $revision)
 {
     $package->ensure_extracted();
     $ext_base_path = $package->find_directory(array('files' => array('required' => 'composer.json', 'optional' => 'ext.php')), 'vendor');
     if ($ext_base_path === null) {
         throw new \Exception($this->root_not_found_key);
     }
     $composer_file = $package->get_temp_path() . '/' . $ext_base_path . '/composer.json';
     $data = $this->get_composer_data($composer_file);
     if (!is_array($data) || empty($data['name']) || !$this->validate_ext_name($data['name'])) {
         throw new \Exception('INVALID_EXT_NAME');
     }
     $ext_name = $data['name'];
     $data = $this->update_phpbb_requirement($data);
     $data = $this->set_version_check($data, $contrib);
     $data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     file_put_contents($composer_file, $data);
     $package->restore_root($ext_base_path, $ext_name);
     $package->repack($this->clean_package);
     $revision->revision_composer_json = $data;
     $contrib->contrib_package_name = $ext_name;
     $contrib->submit();
 }
コード例 #5
0
 /**
  * Set package location and temp path.
  */
 protected function set_package_paths()
 {
     $this->package->set_temp_path($this->ext_config->__get('contrib_temp_path'), true)->set_source($this->attachment->get_filepath());
 }
コード例 #6
0
ファイル: download.php プロジェクト: Sajaki/customisation-db
 /**
  * Generate Composer package.
  *
  * @param string $composer_package Path to package destination
  */
 protected function generate_composer_package($composer_package)
 {
     $package = new package();
     $package->set_source($this->ext_config->upload_path . $this->file['physical_filename']);
     $package->set_temp_path($this->ext_config->contrib_temp_path, true);
     $ext_base_path = $package->find_directory(array('files' => array('required' => 'composer.json', 'optional' => 'ext.php')), 'vendor');
     $package->restore_root($ext_base_path, $this->id);
     $filesystem = new Filesystem();
     $filesystem->copy($package->get_source(), $this->ext_config->upload_path . $composer_package);
     $package->set_source($package->get_source() . '.composer');
     $package->repack(true);
     $package->cleanup();
 }
コード例 #7
0
ファイル: type.php プロジェクト: Sajaki/customisation-db
 /**
  * @{inheritDoc}
  */
 public function install_demo(\titania_contribution $contrib, \titania_revision $revision)
 {
     $revision->load_phpbb_versions();
     $attachment = $revision->get_attachment();
     $branch = $revision->phpbb_versions[0]['phpbb_version_branch'];
     $package = new package();
     $package->set_source($attachment->get_filepath())->set_temp_path($this->ext_config->__get('contrib_temp_path'), true);
     $demo_url = '';
     if ($this->demo_manager->configure($branch, $contrib, $package)) {
         $result = $this->demo_manager->install();
         if (empty($result['error'])) {
             $demo_url = $this->demo_manager->get_demo_url($branch, $result['id']);
             $contrib->set_demo_url($branch, $demo_url);
             $contrib->submit();
         }
     }
     $package->cleanup();
     return $demo_url;
 }
コード例 #8
0
 /**
  * Run AutoMOD test.
  *
  * @param \phpbb\titania\entity\package $package
  * @param string $phpbb_path Path to phpBB files we run the test on
  * @param string $details Will hold the details of the mod
  * @param string $results Will hold the results for output
  * @param string $bbcode_results Will hold the results for storage
  * @return bool true on success, false on failure
  */
 public function run_automod_test($package, $phpbb_path, &$details, &$results, &$bbcode_results)
 {
     require $this->phpbb_root_path . 'includes/functions_transfer.' . $this->php_ext;
     require $this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext;
     require $this->ext_root_path . 'includes/library/automod/acp_mods.' . $this->php_ext;
     require $this->ext_root_path . 'includes/library/automod/editor.' . $this->php_ext;
     require $this->ext_root_path . 'includes/library/automod/mod_parser.' . $this->php_ext;
     require $this->ext_root_path . 'includes/library/automod/functions_mods.' . $this->php_ext;
     $this->user->add_lang_ext('phpbb/titania', 'automod');
     // Find the main modx file
     $modx_root = $package->find_directory(array('files' => array('required' => 'install*.xml')));
     if ($modx_root === null) {
         $this->user->add_lang_ext('phpbb/titania', 'contributions');
         $this->errors[] = $this->user->lang['COULD_NOT_FIND_ROOT'];
         return false;
     }
     $modx_root = $package->get_temp_path() . '/' . $modx_root . '/';
     $modx_file = false;
     if (file_exists($modx_root . 'install.xml')) {
         $modx_file = $modx_root . 'install.xml';
     } else {
         $finder = new \Symfony\Component\Finder\Finder();
         $finder->name('install*.xml')->depth(0)->in($modx_root);
         if ($finder->count()) {
             foreach ($finder as $file) {
                 $modx_file = $file->getPathname();
                 break;
             }
         }
     }
     if (!$modx_file) {
         $this->user->add_lang_ext('phpbb/titania', 'contributions');
         $this->errors[] = $this->user->lang['COULD_NOT_FIND_ROOT'];
         return false;
     }
     // HAX
     global $phpbb_root_path;
     $phpbb_root_path = $phpbb_path;
     // The real stuff
     $acp_mods = new \acp_mods();
     $acp_mods->mods_dir = $this->ext_config->__get('contrib_temp_path');
     $acp_mods->mod_root = $modx_root;
     $editor = new \editor_direct();
     $details = $acp_mods->mod_details($modx_file, false);
     $actions = $acp_mods->mod_actions($modx_file);
     $installed = $acp_mods->process_edits($editor, $actions, $details, false, true, false);
     // Reverse HAX
     $phpbb_root_path = $this->phpbb_root_path;
     $this->template->set_filenames(array('automod' => 'contributions/automod.html', 'automod_bbcode' => 'contributions/automod_bbcode.html'));
     $this->template->assign_var('S_AUTOMOD_SUCCESS', $installed);
     $results = $this->template->assign_display('automod');
     $bbcode_results = $this->template->assign_display('automod_bbcode');
     return $installed;
 }
コード例 #9
0
 /**
  * Checks the file for the array contents
  * Make sure it has all the keys present in the newest version
  *
  * @param \phpbb\titania\entity\package $package
  * @param string $reference_filepath The path to the files against I want to validate the uploaded package
  * @return array Returns an array of error messages encountered
  */
 public function check_package($package, $reference_filepath)
 {
     $package->ensure_extracted();
     $error = $missing_keys = array();
     // Basically the individual parts of the translation, we check them separately, because they have colliding filenames
     $types = array('language' => 'language/', 'prosilver' => 'styles/prosilver/imageset/en', 'subsilver2' => 'styles/subsilver2/imageset/en');
     // Do the check for all types
     foreach ($types as $type => $path) {
         // Get all the files present in the uploaded package for the currently iterated type
         $uploaded_files = $this->lang_filelist($package->get_temp_path());
         $reference_files = $this->lang_filelist($reference_filepath);
         ksort($uploaded_files);
         ksort($reference_files);
         switch ($type) {
             case 'language':
                 // The uploaded files array has keys prefixed with the upload path of the contribution
                 // Have it stored in the variable so we can work with it
                 $uploaded_files_prefix = explode('/', key($uploaded_files));
                 $iso_code = $uploaded_files_prefix[2];
                 $uploaded_files_prefix = $package->get_temp_path() . '/' . $uploaded_files_prefix[0];
                 // This goes directly to the root of the uploaded language pack, like /upload_path/language/cs/
                 $uploaded_lang_root = $uploaded_files_prefix . '/language/' . $iso_code . '/';
                 // Just perform a basic check if the common file is there
                 if (!is_file($uploaded_lang_root . 'common.php')) {
                     return array($this->user->lang('NO_TRANSLATION'));
                 }
                 // Loop through the reference files
                 foreach ($reference_files as $dir => $files) {
                     // Do not loop through files which are in non-language directories
                     if (strpos($dir, $path) === 0) {
                         // Loop through the files in the language/, language/adm etc. directories
                         foreach ($files as $file) {
                             $exists = true;
                             $uploaded_file_path = str_replace('/en/', '/' . $iso_code . '/', $uploaded_files_prefix . '/' . $dir . $file);
                             $ext = strtolower(substr($file, -3));
                             // Require php and txt files
                             if ($ext == 'php' || $ext == 'txt') {
                                 if (!is_file($uploaded_file_path)) {
                                     $error[] = $this->user->lang('MISSING_FILE', str_replace('/en/', '/' . $iso_code . '/', $dir . $file));
                                     // report a missing file
                                     $exists = false;
                                 }
                             }
                             // If the file is a php file and actually exists, no point in checking keys in a nonexistent one
                             if ($ext == 'php' && $exists) {
                                 $missing_keys[$dir . $file] = $this->check_missing_keys($reference_filepath . '' . $dir . $file, $uploaded_file_path);
                             }
                             // In the last step we have removed the license and index files if there were any. We'll just put a new one instead
                             $this->add_license_files($uploaded_lang_root . '/LICENSE', $reference_filepath);
                             $this->add_htm_files($uploaded_lang_root, $reference_filepath);
                         }
                     }
                 }
                 if (sizeof($missing_keys)) {
                     foreach ($missing_keys as $file => $keys) {
                         if (sizeof($keys)) {
                             $error[] = $this->user->lang('MISSING_KEYS', $file, implode('<br />', $keys));
                         }
                     }
                 }
                 break;
             case 'prosilver':
             case 'subsilver2':
                 // just let them go through atm...
                 break;
         }
     }
     // We are going to check if all files included in the language pack are allowed
     // Before we need some stuff
     // We construct a list of all reference files with complete structure
     foreach ($reference_files as $dir => $files) {
         if (strpos($dir, $types['language']) === 0 || strpos($dir, $types['prosilver']) === 0 || strpos($dir, $types['subsilver2']) === 0) {
             foreach ($files as $file) {
                 $list_reference_files[] = $dir . $file;
             }
         }
     }
     // We construct a list of all uploaded file with complete structure
     foreach ($uploaded_files as $dir => $files) {
         // We need to clean our directory path according the type and replace iso_code package by en
         if (strpos($dir, $types['language']) != 0) {
             $dir_prefix = explode($types['language'], $dir);
         } else {
             if (strpos($dir, $types['prosilver']) != 0) {
                 $dir_prefix = explode($types['prosilver'], $dir);
             } else {
                 if (strpos($dir, $types['subsilver2']) != 0) {
                     $dir_prefix = explode($types['subsilver2'], $dir);
                 }
             }
         }
         $dir_clean = str_replace('/' . $iso_code . '/', '/en/', str_replace($dir_prefix[0], '', $dir));
         foreach ($files as $file) {
             $list_uploaded_files[] = $dir_clean . $file;
         }
     }
     // It's time to check if each file uploaded in the package is allowed
     foreach ($list_uploaded_files as $file) {
         if (!in_array($file, $list_reference_files) && !in_array($file, $this->ignore_files)) {
             $error[] = $this->user->lang('WRONG_FILE', str_replace('/en/', '/' . $iso_code . '/', $file));
             // report a wrong file
         }
     }
     if (!sizeof($error)) {
         $package->repack();
         // we have made changes to the package, so replace the original zip file
     }
     return $error;
 }
コード例 #10
0
ファイル: type.php プロジェクト: Sajaki/customisation-db
 /**
  * AutoMOD Test.
  *
  * @param \titania_contribution $contrib
  * @param \titania_revision $revision
  * @param attachment $attachment
  * @param string $download_package
  * @param package $package
  * @param template $template
  * @return array
  */
 public function automod_test(\titania_contribution $contrib, \titania_revision $revision, attachment $attachment, $download_package, package $package, template $template)
 {
     $package->ensure_extracted();
     $prevalidator = $this->get_prevalidator();
     // Automod testing time
     $details = '';
     $error = $html_results = $bbcode_results = array();
     if (!$revision->phpbb_versions) {
         $revision->load_phpbb_versions();
     }
     foreach ($revision->phpbb_versions as $row) {
         $version_string = $row['phpbb_version_branch'][0] . '.' . $row['phpbb_version_branch'][1] . '.' . $row['phpbb_version_revision'];
         $phpbb_path = $prevalidator->get_helper()->prepare_phpbb_test_directory($version_string);
         if ($phpbb_path === false) {
             $error = array_merge($error, $prevalidator->get_helper()->get_errors());
             continue;
         }
         $template->assign_vars(array('PHPBB_VERSION' => $version_string, 'TEST_ID' => $row['row_id']));
         $html_result = $bbcode_result = '';
         $installed = $prevalidator->run_automod_test($package, $phpbb_path, $details, $html_result, $bbcode_result);
         $html_results[] = $html_result;
         $bbcode_results[] = $bbcode_result;
     }
     if (is_array($details)) {
         $revision->install_time = $details['INSTALLATION_TIME'];
         switch ($details['INSTALLATION_LEVEL']) {
             case 'easy':
                 $revision->install_level = 1;
                 break;
             case 'intermediate':
                 $revision->install_level = 2;
                 break;
             case 'advanced':
                 $revision->install_level = 3;
                 break;
         }
         $revision->submit();
     }
     $html_results = implode('<br /><br />', $html_results);
     $bbcode_results = implode("\n\n", $bbcode_results);
     // Update the queue with the results
     $queue = $revision->get_queue();
     $queue->automod_results = $bbcode_results;
     $queue->submit();
     $template->assign_var('AUTOMOD_RESULTS', $html_results);
     return array('error' => $error);
 }
コード例 #11
0
ファイル: tools.php プロジェクト: Sajaki/customisation-db
 /**
  * Load revision package.
  */
 protected function load_package()
 {
     $this->package = new \phpbb\titania\entity\package();
     $this->package->set_source($this->attachment->get_filepath())->set_temp_path($this->ext_config->__get('contrib_temp_path'), true);
 }