/** * Clean attachment package. * * @return array Returns array containing any errors encountered. */ protected function clean_package() { $error = array(); if (!$this->contrib->type->restore_root && !$this->contrib->type->clean_package) { return $error; } $root_directory = null; if ($this->contrib->type->restore_root && is_array($this->contrib->type->root_search)) { $search = $this->contrib->type->root_search; $exclude = !empty($search['exclude']) ? $search['exclude'] : null; unset($search['exclude']); $root_directory = $this->package->find_directory($search, $exclude); if ($root_directory === null) { $error[] = $this->user->lang($this->contrib->type->root_not_found_key); } } if (empty($error)) { if ($root_directory !== null) { // Adjust package name to follow naming conventions $new_root_name = $this->contrib->type->fix_package_name($this->contrib, $this->revision, $this->attachment, $root_directory); $this->package->restore_root($root_directory, $new_root_name); } // Replace the uploaded zip package with the new one $this->package->repack($this->contrib->type->clean_package); $this->update_package_stats(); } // Remove our temp files $this->package->cleanup(); return $error; }
/** * 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); }
/** * 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); }
/** * 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(); }
/** * 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(); }
/** * @{inheritDoc} */ public function upload_check(attachment $attachment) { $package = new package(); $package->set_source($attachment->get_filepath())->set_temp_path($this->ext_config->__get('contrib_temp_path'), true)->extract(); $license_location = $package->find_directory(array('files' => array('required' => 'license.txt'))); $package->cleanup(); if ($license_location !== null && substr_count($license_location, '/') < 2) { return array(); } return array($this->user->lang('LICENSE_FILE_MISSING')); }
/** * 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; }