예제 #1
0
 /**
  * The function that gets extension metadata manager for Upload Extensions.
  */
 public static function get_manager()
 {
     objects::$md_manager = new \phpbb\extension\metadata_manager(objects::$upload_ext_name, objects::$config, objects::$phpbb_extension_manager, objects::$template, objects::$user, objects::$phpbb_root_path);
     try {
         $metadata = objects::$md_manager->get_metadata('all');
     } catch (\phpbb\extension\exception $e) {
         files::catch_errors($e);
     }
     $upload_extensions_download = false;
     try {
         $updates_available = extensions::version_check(objects::$md_manager, objects::$request->variable('versioncheck_force', false));
         objects::$template->assign_vars(array('UPLOAD_EXT_NEW_UPDATE' => !empty($updates_available), 'S_UPLOAD_UP_TO_DATE' => empty($updates_available), 'S_UPLOAD_VERSIONCHECK' => true, 'UPLOAD_UP_TO_DATE_MSG' => objects::$user->lang(empty($updates_available) ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', objects::$md_manager->get_metadata('display-name'))));
         foreach ($updates_available as $branch => $version_data) {
             objects::$template->assign_block_vars('upload_updates_available', $version_data);
             $upload_extensions_download = $version_data['download'];
         }
     } catch (\RuntimeException $e) {
         objects::$template->assign_vars(array('S_UPLOAD_VERSIONCHECK_STATUS' => $e->getCode(), 'UPLOAD_VERSIONCHECK_FAIL_REASON' => $e->getMessage() !== objects::$user->lang('VERSIONCHECK_FAIL') ? $e->getMessage() : ''));
     }
     objects::$self_update = $upload_extensions_download;
 }
예제 #2
0
 /**
  * Gets missing language directories for an extension from a specified zip file.
  * @param string $ext_name The name of the extension.
  * @param string $zip_file The name of zip file.
  * @return null|bool
  */
 public static function restore_languages($ext_name, $zip_file)
 {
     $ext_tmp = objects::$phpbb_root_path . 'ext/' . objects::$upload_ext_name . '/tmp/' . (int) objects::$user->data['user_id'];
     // Ensure that we don't have any previous files in the working directory.
     if (is_dir($ext_tmp)) {
         if (!files::catch_errors(files::rrmdir($ext_tmp))) {
             files::catch_errors(objects::$user->lang['ERROR_DIRECTORIES_NOT_RESTORED']);
             return false;
         }
     }
     if (!class_exists('\\compress_zip')) {
         include objects::$phpbb_root_path . 'includes/functions_compress.' . objects::$phpEx;
     }
     $zip = new \compress_zip('r', objects::$zip_dir . '/' . $zip_file);
     $zip->extract($ext_tmp . '/');
     $zip->close();
     $composery = files::getComposer($ext_tmp);
     if (!$composery) {
         files::catch_errors(files::rrmdir($ext_tmp));
         files::catch_errors(objects::$user->lang['ERROR_ZIP_NO_COMPOSER']);
         files::catch_errors(objects::$user->lang['ERROR_DIRECTORIES_NOT_RESTORED']);
         return false;
     }
     $source = substr($composery, 0, -14);
     // Check languages missing in the new version.
     $ext_path = objects::$phpbb_root_path . 'ext/' . $ext_name;
     $old_langs = files::get_languages($source . '/language');
     $new_langs = files::get_languages($ext_path . '/language');
     $old_langs = array_diff($old_langs, $new_langs);
     if (sizeof($old_langs)) {
         foreach ($old_langs as $lang) {
             files::catch_errors(files::rcopy($source . '/language/' . $lang, $ext_path . '/language/' . $lang));
         }
         objects::$template->assign_var('EXT_LANGUAGES_RESTORED', true);
     }
     files::catch_errors(files::rrmdir($ext_tmp));
 }
예제 #3
0
 /**
  * The function that uploads the specified language package for the extension.
  *
  * @param string $action    Requested action.
  * @param string $ext_name  The name of the extension.
  * @param string $lang_name The ISO code of the language.
  * @return bool
  */
 public function upload_lang($action, $ext_name, $lang_name)
 {
     global $phpbb_root_path, $phpEx, $user;
     if (empty($ext_name)) {
         files::catch_errors(objects::$user->lang('ERROR_LANGUAGE_NO_EXTENSION'));
         return false;
     }
     if (empty($lang_name)) {
         files::catch_errors(objects::$user->lang('ERROR_LANGUAGE_NOT_DEFINED'));
         return false;
     }
     $file = $this->proceed_upload($action);
     if (!$file) {
         return false;
     }
     $dest_file = $this->get_dest_file($action, $file, objects::$zip_dir);
     if (!$dest_file) {
         return false;
     }
     // We need to use the user ID and the time to escape from problems with simultaneous uploads.
     // We suppose that one user can upload only one extension per session.
     $ext_tmp = $phpbb_root_path . 'ext/' . objects::$upload_ext_name . '/tmp/' . (int) $user->data['user_id'];
     // Ensure that we don't have any previous files in the working directory.
     if (is_dir($ext_tmp)) {
         if (!files::catch_errors(files::rrmdir($ext_tmp))) {
             if ($action != 'upload_local') {
                 $file->remove();
             }
             return false;
         }
     }
     if (!class_exists('\\compress_zip')) {
         include $phpbb_root_path . 'includes/functions_compress.' . $phpEx;
     }
     $zip = new \compress_zip('r', $dest_file);
     $zip->extract($ext_tmp . '/');
     $zip->close();
     if ($action != 'upload_local') {
         $file->remove();
     }
     // The files can be stored inside the $ext_tmp directory or up to two levels lower in the file tree.
     $lang_dir = '';
     // First level (the highest one).
     $files = @scandir($ext_tmp);
     if ($files === false) {
         files::catch_errors(objects::$user->lang('ERROR_LANGUAGE_UNKNOWN_STRUCTURE'));
         return false;
     }
     $files = array_diff($files, array('.', '..'));
     $last_file = array_pop($files);
     // Continue searching if we have a single directory.
     if (!sizeof($files) && !is_null($last_file) && @is_dir($ext_tmp . $lang_dir . '/' . $last_file)) {
         $lang_dir .= '/' . $last_file;
         // Second level.
         $files = @scandir($ext_tmp . $lang_dir);
         if ($files === false) {
             files::catch_errors(objects::$user->lang('ERROR_LANGUAGE_UNKNOWN_STRUCTURE'));
             return false;
         }
         $files = array_diff($files, array('.', '..'));
         // Search for a directory with language ISO code (to escape from problems with unnecessary readme files).
         if (array_search($lang_name, $files) !== false && @is_dir($ext_tmp . $lang_dir . '/' . $lang_name)) {
             $lang_dir .= '/' . $lang_name;
         }
     }
     $source = $ext_tmp . $lang_dir;
     if (!files::catch_errors(files::rcopy($source, $phpbb_root_path . 'ext/' . $ext_name . '/language/' . $lang_name))) {
         files::catch_errors(files::rrmdir($ext_tmp));
         return false;
     }
     if (!files::catch_errors(files::rrmdir($ext_tmp))) {
         return false;
     }
     if (objects::$is_ajax && $ext_name === objects::$upload_ext_name && $lang_name === objects::$user->lang_name) {
         /*
          * Refresh the page if the uploaded language package
          * is currently used by the user of Upload Extensions.
          * Only for Ajax requests.
          */
         $response_object = new \phpbb\json_response();
         $response_object->send(array("LANGUAGE" => urlencode($lang_name), "REFRESH" => true));
     }
     objects::$template->assign_var('EXT_LANGUAGE_UPLOADED', objects::$user->lang('EXT_LANGUAGE_UPLOADED', $lang_name));
     return true;
 }