Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

acp_extensions.php

Zuletzt modifiziert: 01.05.2026, 11:25 - Dateigröße: 22.20 KiB


 001  <?php
 002  /**
 003  *
 004  * This file is part of the phpBB Forum Software package.
 005  *
 006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007  * @license GNU General Public License, version 2 (GPL-2.0)
 008  *
 009  * For full copyright and license information, please see
 010  * the docs/CREDITS.txt file.
 011  *
 012  */
 013   
 014  use phpbb\exception\exception_interface;
 015  use phpbb\exception\runtime_exception;
 016  use phpbb\exception\version_check_exception;
 017   
 018  /**
 019  * @ignore
 020  */
 021  if (!defined('IN_PHPBB'))
 022  {
 023      exit;
 024  }
 025   
 026  class acp_extensions
 027  {
 028      var $u_action;
 029      var $tpl_name;
 030      var $page_title;
 031   
 032      private $config;
 033      private $template;
 034      private $user;
 035      private $log;
 036      private $request;
 037      private $phpbb_dispatcher;
 038      private $ext_manager;
 039      private $phpbb_container;
 040      private $php_ini;
 041   
 042      function main($id, $mode)
 043      {
 044          // Start the page
 045          global $config, $user, $template, $request, $phpbb_extension_manager, $phpbb_root_path, $phpbb_log, $phpbb_dispatcher, $phpbb_container;
 046   
 047          $this->config = $config;
 048          $this->template = $template;
 049          $this->user = $user;
 050          $this->request = $request;
 051          $this->log = $phpbb_log;
 052          $this->phpbb_dispatcher = $phpbb_dispatcher;
 053          $this->ext_manager = $phpbb_extension_manager;
 054          $this->phpbb_container = $phpbb_container;
 055          $this->php_ini = $this->phpbb_container->get('php_ini');
 056   
 057          $this->user->add_lang(array('install', 'acp/extensions', 'acp/modules', 'migrator'));
 058   
 059          $this->page_title = 'ACP_EXTENSIONS';
 060   
 061          $action = $this->request->variable('action', 'list');
 062          $ext_name = $this->request->variable('ext_name', '');
 063   
 064          // What is a safe limit of execution time? Half the max execution time should be safe.
 065          $safe_time_limit = ($this->php_ini->getNumeric('max_execution_time') / 2);
 066          $start_time = time();
 067   
 068          // Cancel action
 069          if ($this->request->is_set_post('cancel'))
 070          {
 071              $action = 'list';
 072              $ext_name = '';
 073          }
 074   
 075          if (in_array($action, array('enable', 'disable', 'delete_data')) && !check_link_hash($this->request->variable('hash', ''), $action . '.' . $ext_name))
 076          {
 077              trigger_error('FORM_INVALID', E_USER_WARNING);
 078          }
 079   
 080          /**
 081          * Event to run a specific action on extension
 082          *
 083          * @event core.acp_extensions_run_action_before
 084          * @var    string    action            Action to run; if the event completes execution of the action, should be set to 'none'
 085          * @var    string    u_action        Url we are at
 086          * @var    string    ext_name        Extension name from request
 087          * @var    int        safe_time_limit    Safe limit of execution time
 088          * @var    int        start_time        Start time
 089          * @var    string    tpl_name        Template file to load
 090          * @since 3.1.11-RC1
 091          * @changed 3.2.1-RC1            Renamed to core.acp_extensions_run_action_before, added tpl_name, added action 'none'
 092          */
 093          $u_action = $this->u_action;
 094          $tpl_name = '';
 095          $vars = array('action', 'u_action', 'ext_name', 'safe_time_limit', 'start_time', 'tpl_name');
 096          extract($this->phpbb_dispatcher->trigger_event('core.acp_extensions_run_action_before', compact($vars)));
 097   
 098          // In case they have been updated by the event
 099          $this->u_action = $u_action;
 100          $this->tpl_name = $tpl_name;
 101   
 102          // If they've specified an extension, let's load the metadata manager and validate it.
 103          if ($ext_name)
 104          {
 105              $md_manager = $this->ext_manager->create_extension_metadata_manager($ext_name);
 106   
 107              try
 108              {
 109                  $md_manager->get_metadata('all');
 110              }
 111              catch (exception_interface $e)
 112              {
 113                  $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
 114                  trigger_error($message . adm_back_link($this->u_action), E_USER_WARNING);
 115              }
 116          }
 117   
 118          // What are we doing?
 119          switch ($action)
 120          {
 121              case 'none':
 122                  // Intentionally empty, used by extensions that execute additional actions in the prior event
 123                  break;
 124   
 125              case 'set_config_version_check_force_unstable':
 126                  $force_unstable = $this->request->variable('force_unstable', false);
 127   
 128                  if ($force_unstable)
 129                  {
 130                      $s_hidden_fields = build_hidden_fields(array(
 131                          'force_unstable'    => $force_unstable,
 132                      ));
 133   
 134                      confirm_box(false, $this->user->lang('EXTENSION_FORCE_UNSTABLE_CONFIRM'), $s_hidden_fields);
 135                  }
 136                  else
 137                  {
 138                      $this->config->set('extension_force_unstable', false);
 139                      trigger_error($this->user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
 140                  }
 141                  break;
 142   
 143              case 'list':
 144              default:
 145                  if (confirm_box(true))
 146                  {
 147                      $this->config->set('extension_force_unstable', true);
 148                      trigger_error($this->user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
 149                  }
 150   
 151                  $this->list_enabled_exts();
 152                  $this->list_disabled_exts();
 153                  $this->list_available_exts();
 154   
 155                  $this->tpl_name = 'acp_ext_list';
 156   
 157                  $this->template->assign_vars(array(
 158                      'U_VERSIONCHECK_FORCE'     => $this->u_action . '&amp;action=list&amp;versioncheck_force=1',
 159                      'FORCE_UNSTABLE'        => $this->config['extension_force_unstable'],
 160                      'U_ACTION'                 => $this->u_action,
 161                  ));
 162              break;
 163   
 164              case 'enable_pre':
 165                  try
 166                  {
 167                      $md_manager->validate_enable();
 168                  }
 169                  catch (exception_interface $e)
 170                  {
 171                      $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
 172                      trigger_error($message . adm_back_link($this->u_action), E_USER_WARNING);
 173                  }
 174   
 175                  $extension = $this->ext_manager->get_extension($ext_name);
 176   
 177                  $this->check_is_enableable($extension);
 178   
 179                  if ($this->ext_manager->is_enabled($ext_name))
 180                  {
 181                      redirect($this->u_action);
 182                  }
 183   
 184                  $this->tpl_name = 'acp_ext_enable';
 185   
 186                  $this->template->assign_vars([
 187                      'S_PRE_STEP'        => true,
 188                      'CONFIRM_MESSAGE'    => $this->user->lang('EXTENSION_ENABLE_CONFIRM', $md_manager->get_metadata('display-name')),
 189                      'U_ENABLE'            => $this->u_action . '&amp;action=enable&amp;ext_name=' . urlencode($ext_name) . '&amp;hash=' . generate_link_hash('enable.' . $ext_name),
 190                  ]);
 191              break;
 192   
 193              case 'enable':
 194                  try
 195                  {
 196                      $md_manager->validate_enable();
 197                  }
 198                  catch (exception_interface $e)
 199                  {
 200                      $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
 201                      trigger_error($message . adm_back_link($this->u_action), E_USER_WARNING);
 202                  }
 203   
 204                  $extension = $this->ext_manager->get_extension($ext_name);
 205   
 206                  $this->check_is_enableable($extension);
 207   
 208                  try
 209                  {
 210                      while ($this->ext_manager->enable_step($ext_name))
 211                      {
 212                          // Are we approaching the time limit? If so we want to pause the update and continue after refreshing
 213                          if ((time() - $start_time) >= $safe_time_limit)
 214                          {
 215                              $this->template->assign_var('S_NEXT_STEP', true);
 216   
 217                              meta_refresh(0, $this->u_action . '&amp;action=enable&amp;ext_name=' . urlencode($ext_name) . '&amp;hash=' . generate_link_hash('enable.' . $ext_name));
 218                          }
 219                      }
 220   
 221                      // Update custom style for admin area
 222                      $this->template->set_custom_style(array(
 223                          array(
 224                              'name'         => 'adm',
 225                              'ext_path'     => 'adm/style/',
 226                          ),
 227                      ), array($phpbb_root_path . 'adm/style'));
 228   
 229                      $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_EXT_ENABLE', time(), array($ext_name));
 230                  }
 231                  catch (\phpbb\db\migration\exception $e)
 232                  {
 233                      $this->template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($this->user));
 234                  }
 235   
 236                  $this->tpl_name = 'acp_ext_enable';
 237   
 238                  $this->template->assign_vars([
 239                      'U_RETURN'        => $this->u_action . '&amp;action=list',
 240                  ]);
 241              break;
 242   
 243              case 'disable_pre':
 244                  if (!$this->ext_manager->is_enabled($ext_name))
 245                  {
 246                      redirect($this->u_action);
 247                  }
 248   
 249                  $this->tpl_name = 'acp_ext_disable';
 250   
 251                  $this->template->assign_vars([
 252                      'S_PRE_STEP'        => true,
 253                      'CONFIRM_MESSAGE'    => $this->user->lang('EXTENSION_DISABLE_CONFIRM', $md_manager->get_metadata('display-name')),
 254                      'U_DISABLE'            => $this->u_action . '&amp;action=disable&amp;ext_name=' . urlencode($ext_name) . '&amp;hash=' . generate_link_hash('disable.' . $ext_name),
 255                  ]);
 256              break;
 257   
 258              case 'disable':
 259                  if (!$this->ext_manager->is_enabled($ext_name))
 260                  {
 261                      redirect($this->u_action);
 262                  }
 263   
 264                  while ($this->ext_manager->disable_step($ext_name))
 265                  {
 266                      // Are we approaching the time limit? If so we want to pause the update and continue after refreshing
 267                      if ((time() - $start_time) >= $safe_time_limit)
 268                      {
 269                          $this->template->assign_var('S_NEXT_STEP', true);
 270   
 271                          meta_refresh(0, $this->u_action . '&amp;action=disable&amp;ext_name=' . urlencode($ext_name) . '&amp;hash=' . generate_link_hash('disable.' . $ext_name));
 272                      }
 273                  }
 274                  $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_EXT_DISABLE', time(), array($ext_name));
 275   
 276                  $this->tpl_name = 'acp_ext_disable';
 277   
 278                  $this->template->assign_vars([
 279                      'U_RETURN'    => $this->u_action . '&amp;action=list',
 280                  ]);
 281              break;
 282   
 283              case 'delete_data_pre':
 284                  if ($this->ext_manager->is_enabled($ext_name))
 285                  {
 286                      redirect($this->u_action);
 287                  }
 288   
 289                  $this->tpl_name = 'acp_ext_delete_data';
 290   
 291                  $this->template->assign_vars([
 292                      'S_PRE_STEP'        => true,
 293                      'CONFIRM_MESSAGE'    => $this->user->lang('EXTENSION_DELETE_DATA_CONFIRM', $md_manager->get_metadata('display-name')),
 294                      'U_PURGE'            => $this->u_action . '&amp;action=delete_data&amp;ext_name=' . urlencode($ext_name) . '&amp;hash=' . generate_link_hash('delete_data.' . $ext_name),
 295                  ]);
 296              break;
 297   
 298              case 'delete_data':
 299                  if ($this->ext_manager->is_enabled($ext_name))
 300                  {
 301                      redirect($this->u_action);
 302                  }
 303   
 304                  try
 305                  {
 306                      while ($this->ext_manager->purge_step($ext_name))
 307                      {
 308                          // Are we approaching the time limit? If so we want to pause the update and continue after refreshing
 309                          if ((time() - $start_time) >= $safe_time_limit)
 310                          {
 311                              $this->template->assign_var('S_NEXT_STEP', true);
 312   
 313                              meta_refresh(0, $this->u_action . '&amp;action=delete_data&amp;ext_name=' . urlencode($ext_name) . '&amp;hash=' . generate_link_hash('delete_data.' . $ext_name));
 314                          }
 315                      }
 316                      $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_EXT_PURGE', time(), array($ext_name));
 317                  }
 318                  catch (\phpbb\db\migration\exception $e)
 319                  {
 320                      $this->template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($this->user));
 321                  }
 322   
 323                  $this->tpl_name = 'acp_ext_delete_data';
 324   
 325                  $this->template->assign_vars([
 326                      'U_RETURN'    => $this->u_action . '&amp;action=list',
 327                  ]);
 328              break;
 329   
 330              case 'details':
 331                  // Output it to the template
 332                  $meta = $md_manager->get_metadata('all');
 333                  $this->output_metadata_to_template($meta);
 334   
 335                  if (isset($meta['extra']['version-check']))
 336                  {
 337                      try
 338                      {
 339                          $updates_available = $this->ext_manager->version_check($md_manager, $this->request->variable('versioncheck_force', false), false, $this->config['extension_force_unstable'] ? 'unstable' : null);
 340   
 341                          $this->template->assign_vars(array(
 342                              'S_UP_TO_DATE' => empty($updates_available),
 343                              'UP_TO_DATE_MSG' => $this->user->lang(empty($updates_available) ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $md_manager->get_metadata('display-name')),
 344                          ));
 345   
 346                          $this->template->assign_block_vars('updates_available', $updates_available);
 347                      }
 348                      catch (runtime_exception $e)
 349                      {
 350                          $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
 351   
 352                          $this->template->assign_vars(array(
 353                              'S_VERSIONCHECK_FAIL' => true,
 354                              'VERSIONCHECK_FAIL_REASON' => ($e->getMessage() !== 'VERSIONCHECK_FAIL') ? $message : '',
 355                          ));
 356                      }
 357                      $this->template->assign_var('S_VERSIONCHECK', true);
 358                  }
 359                  else
 360                  {
 361                      $this->template->assign_var('S_VERSIONCHECK', false);
 362                  }
 363   
 364                  $this->template->assign_vars(array(
 365                      'U_BACK'                => $this->u_action . '&amp;action=list',
 366                      'U_VERSIONCHECK_FORCE'    => $this->u_action . '&amp;action=details&amp;versioncheck_force=1&amp;ext_name=' . urlencode($md_manager->get_metadata('name')),
 367                  ));
 368   
 369                  $this->tpl_name = 'acp_ext_details';
 370              break;
 371          }
 372   
 373          /**
 374          * Event to run after a specific action on extension has completed
 375          *
 376          * @event core.acp_extensions_run_action_after
 377          * @var    string    action            Action that has run
 378          * @var    string    u_action        Url we are at
 379          * @var    string    ext_name        Extension name from request
 380          * @var    int        safe_time_limit    Safe limit of execution time
 381          * @var    int        start_time        Start time
 382          * @var    string    tpl_name        Template file to load
 383          * @since 3.1.11-RC1
 384          */
 385          $u_action = $this->u_action;
 386          $tpl_name = $this->tpl_name;
 387          $vars = array('action', 'u_action', 'ext_name', 'safe_time_limit', 'start_time', 'tpl_name');
 388          extract($this->phpbb_dispatcher->trigger_event('core.acp_extensions_run_action_after', compact($vars)));
 389   
 390          // In case they have been updated by the event
 391          $this->u_action = $u_action;
 392          $this->tpl_name = $tpl_name;
 393      }
 394   
 395      /**
 396      * Lists all the enabled extensions and dumps to the template
 397      *
 398      * @return null
 399      */
 400      public function list_enabled_exts()
 401      {
 402          $enabled_extension_meta_data = array();
 403   
 404          foreach ($this->ext_manager->all_enabled() as $name => $location)
 405          {
 406              $md_manager = $this->ext_manager->create_extension_metadata_manager($name);
 407   
 408              try
 409              {
 410                  $meta = $md_manager->get_metadata('all');
 411                  $enabled_extension_meta_data[$name] = array(
 412                      'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'),
 413                      'META_VERSION' => $meta['version'],
 414                  );
 415   
 416                  if (isset($meta['extra']['version-check']))
 417                  {
 418                      try
 419                      {
 420                          $force_update = $this->request->variable('versioncheck_force', false);
 421                          $updates = $this->ext_manager->version_check($md_manager, $force_update, !$force_update);
 422   
 423                          $enabled_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates);
 424                          $enabled_extension_meta_data[$name]['S_VERSIONCHECK'] = true;
 425                          $enabled_extension_meta_data[$name]['U_VERSIONCHECK_FORCE'] = $this->u_action . '&amp;action=details&amp;versioncheck_force=1&amp;ext_name=' . urlencode($md_manager->get_metadata('name'));
 426                      }
 427                      catch (runtime_exception $e)
 428                      {
 429                          // Ignore exceptions due to the version check
 430                      }
 431                  }
 432                  else
 433                  {
 434                      $enabled_extension_meta_data[$name]['S_VERSIONCHECK'] = false;
 435                  }
 436              }
 437              catch (runtime_exception $e)
 438              {
 439                  $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
 440                  $this->template->assign_block_vars('disabled', array(
 441                      'META_DISPLAY_NAME'        => $this->user->lang('EXTENSION_INVALID_LIST', $name, $message),
 442                      'S_VERSIONCHECK'        => false,
 443                  ));
 444              }
 445              catch (\RuntimeException $e)
 446              {
 447                  $enabled_extension_meta_data[$name]['S_VERSIONCHECK'] = false;
 448              }
 449          }
 450   
 451          uasort($enabled_extension_meta_data, array($this, 'sort_extension_meta_data_table'));
 452   
 453          foreach ($enabled_extension_meta_data as $name => $block_vars)
 454          {
 455              $block_vars['NAME'] = $name;
 456              $block_vars['U_DETAILS'] = $this->u_action . '&amp;action=details&amp;ext_name=' . urlencode($name);
 457   
 458              $this->template->assign_block_vars('enabled', $block_vars);
 459   
 460              $this->output_actions('enabled', array(
 461                  'DISABLE'        => $this->u_action . '&amp;action=disable_pre&amp;ext_name=' . urlencode($name),
 462              ));
 463          }
 464      }
 465   
 466      /**
 467      * Lists all the disabled extensions and dumps to the template
 468      *
 469      * @return null
 470      */
 471      public function list_disabled_exts()
 472      {
 473          $disabled_extension_meta_data = array();
 474   
 475          foreach ($this->ext_manager->all_disabled() as $name => $location)
 476          {
 477              $md_manager = $this->ext_manager->create_extension_metadata_manager($name);
 478   
 479              try
 480              {
 481                  $meta = $md_manager->get_metadata('all');
 482                  $disabled_extension_meta_data[$name] = array(
 483                      'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'),
 484                      'META_VERSION' => $meta['version'],
 485                  );
 486   
 487                  if (isset($meta['extra']['version-check']))
 488                  {
 489                      $force_update = $this->request->variable('versioncheck_force', false);
 490                      $updates = $this->ext_manager->version_check($md_manager, $force_update, !$force_update);
 491   
 492                      $disabled_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates);
 493                      $disabled_extension_meta_data[$name]['S_VERSIONCHECK'] = true;
 494                      $disabled_extension_meta_data[$name]['U_VERSIONCHECK_FORCE'] = $this->u_action . '&amp;action=details&amp;versioncheck_force=1&amp;ext_name=' . urlencode($md_manager->get_metadata('name'));
 495                  }
 496                  else
 497                  {
 498                      $disabled_extension_meta_data[$name]['S_VERSIONCHECK'] = false;
 499                  }
 500              }
 501              catch (version_check_exception $e)
 502              {
 503                  $disabled_extension_meta_data[$name]['S_VERSIONCHECK'] = false;
 504              }
 505              catch (runtime_exception $e)
 506              {
 507                  $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
 508                  $this->template->assign_block_vars('disabled', array(
 509                      'META_DISPLAY_NAME'        => $this->user->lang('EXTENSION_INVALID_LIST', $name, $message),
 510                      'S_VERSIONCHECK'        => false,
 511                  ));
 512              }
 513              catch (\RuntimeException $e)
 514              {
 515                  $disabled_extension_meta_data[$name]['S_VERSIONCHECK'] = false;
 516              }
 517          }
 518   
 519          uasort($disabled_extension_meta_data, array($this, 'sort_extension_meta_data_table'));
 520   
 521          foreach ($disabled_extension_meta_data as $name => $block_vars)
 522          {
 523              $block_vars['NAME'] = $name;
 524              $block_vars['U_DETAILS'] = $this->u_action . '&amp;action=details&amp;ext_name=' . urlencode($name);
 525   
 526              $this->template->assign_block_vars('disabled', $block_vars);
 527   
 528              $this->output_actions('disabled', array(
 529                  'ENABLE'        => $this->u_action . '&amp;action=enable_pre&amp;ext_name=' . urlencode($name),
 530                  'DELETE_DATA'    => $this->u_action . '&amp;action=delete_data_pre&amp;ext_name=' . urlencode($name),
 531              ));
 532          }
 533      }
 534   
 535      /**
 536      * Lists all the available extensions and dumps to the template
 537      *
 538      * @return null
 539      */
 540      public function list_available_exts()
 541      {
 542          $uninstalled = array_diff_key($this->ext_manager->all_available(), $this->ext_manager->all_configured());
 543   
 544          $available_extension_meta_data = array();
 545   
 546          foreach ($uninstalled as $name => $location)
 547          {
 548              $md_manager = $this->ext_manager->create_extension_metadata_manager($name);
 549   
 550              try
 551              {
 552                  $meta = $md_manager->get_metadata('all');
 553                  $available_extension_meta_data[$name] = array(
 554                      'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'),
 555                      'META_VERSION' => $meta['version'],
 556                  );
 557   
 558                  if (isset($meta['extra']['version-check']))
 559                  {
 560                      $force_update = $this->request->variable('versioncheck_force', false);
 561                      $updates = $this->ext_manager->version_check($md_manager, $force_update, !$force_update);
 562   
 563                      $available_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates);
 564                      $available_extension_meta_data[$name]['S_VERSIONCHECK'] = true;
 565                      $available_extension_meta_data[$name]['U_VERSIONCHECK_FORCE'] = $this->u_action . '&amp;action=details&amp;versioncheck_force=1&amp;ext_name=' . urlencode($md_manager->get_metadata('name'));
 566                  }
 567                  else
 568                  {
 569                      $available_extension_meta_data[$name]['S_VERSIONCHECK'] = false;
 570                  }
 571              }
 572              catch (version_check_exception $e)
 573              {
 574                  $available_extension_meta_data[$name]['S_VERSIONCHECK'] = false;
 575              }
 576              catch (runtime_exception $e)
 577              {
 578                  $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
 579                  $this->template->assign_block_vars('not_installed', array(
 580                      'META_DISPLAY_NAME'        => $this->user->lang('EXTENSION_INVALID_LIST', $name, $message),
 581                      'S_VERSIONCHECK'        => false,
 582                  ));
 583              }
 584          }
 585   
 586          uasort($available_extension_meta_data, array($this, 'sort_extension_meta_data_table'));
 587   
 588          foreach ($available_extension_meta_data as $name => $block_vars)
 589          {
 590              $block_vars['NAME'] = $name;
 591              $block_vars['U_DETAILS'] = $this->u_action . '&amp;action=details&amp;ext_name=' . urlencode($name);
 592   
 593              $this->template->assign_block_vars('not_installed', $block_vars);
 594   
 595              $this->output_actions('not_installed', array(
 596                  'ENABLE'        => $this->u_action . '&amp;action=enable_pre&amp;ext_name=' . urlencode($name),
 597              ));
 598          }
 599      }
 600   
 601      /**
 602      * Output actions to a block
 603      *
 604      * @param string $block
 605      * @param array $actions
 606      */
 607      private function output_actions($block, $actions)
 608      {
 609          foreach ($actions as $lang => $url)
 610          {
 611              $this->template->assign_block_vars($block . '.actions', [
 612                  'L_ACTION'            => $this->user->lang('EXTENSION_' . $lang),
 613                  'L_ACTION_EXPLAIN'    => (isset($this->user->lang['EXTENSION_' . $lang . '_EXPLAIN'])) ? $this->user->lang('EXTENSION_' . $lang . '_EXPLAIN') : '',
 614                  'U_ACTION'            => $url,
 615              ]);
 616          }
 617      }
 618   
 619      /**
 620      * Sort helper for the table containing the metadata about the extensions.
 621      */
 622      protected function sort_extension_meta_data_table($val1, $val2)
 623      {
 624          return strnatcasecmp($val1['META_DISPLAY_NAME'], $val2['META_DISPLAY_NAME']);
 625      }
 626   
 627      /**
 628      * Outputs extension metadata into the template
 629      *
 630      * @param array $metadata Array with all metadata for the extension
 631      * @return null
 632      */
 633      public function output_metadata_to_template($metadata)
 634      {
 635          $this->template->assign_vars(array(
 636              'META_NAME'            => $metadata['name'],
 637              'META_TYPE'            => $metadata['type'],
 638              'META_DESCRIPTION'    => (isset($metadata['description'])) ? $metadata['description'] : '',
 639              'META_HOMEPAGE'        => (isset($metadata['homepage'])) ? $metadata['homepage'] : '',
 640              'META_VERSION'        => $metadata['version'],
 641              'META_TIME'            => (isset($metadata['time'])) ? $metadata['time'] : '',
 642              'META_LICENSE'        => $metadata['license'],
 643   
 644              'META_REQUIRE_PHP'        => (isset($metadata['require']['php'])) ? $metadata['require']['php'] : '',
 645              'META_REQUIRE_PHP_FAIL'    => (isset($metadata['require']['php'])) ? false : true,
 646   
 647              'META_REQUIRE_PHPBB'        => (isset($metadata['extra']['soft-require']['phpbb/phpbb'])) ? $metadata['extra']['soft-require']['phpbb/phpbb'] : '',
 648              'META_REQUIRE_PHPBB_FAIL'    => (isset($metadata['extra']['soft-require']['phpbb/phpbb'])) ? false : true,
 649   
 650              'META_DISPLAY_NAME'    => (isset($metadata['extra']['display-name'])) ? $metadata['extra']['display-name'] : '',
 651          ));
 652   
 653          foreach ($metadata['authors'] as $author)
 654          {
 655              $this->template->assign_block_vars('meta_authors', array(
 656                  'AUTHOR_NAME'        => $author['name'],
 657                  'AUTHOR_EMAIL'        => (isset($author['email'])) ? $author['email'] : '',
 658                  'AUTHOR_HOMEPAGE'    => (isset($author['homepage'])) ? $author['homepage'] : '',
 659                  'AUTHOR_ROLE'        => (isset($author['role'])) ? $author['role'] : '',
 660              ));
 661          }
 662      }
 663   
 664      /**
 665      * Checks whether the extension can be enabled. Triggers error if not.
 666      * Error message can be set by the extension.
 667      *
 668      * @param \phpbb\extension\extension_interface $extension Extension to check
 669      */
 670      protected function check_is_enableable(\phpbb\extension\extension_interface $extension)
 671      {
 672          $message = $extension->is_enableable();
 673          if ($message !== true)
 674          {
 675              if (empty($message))
 676              {
 677                  $message = $this->user->lang('EXTENSION_NOT_ENABLEABLE');
 678              }
 679              else if (is_array($message))
 680              {
 681                  $message = implode('<br>', $message);
 682              }
 683   
 684              trigger_error($message . adm_back_link($this->u_action), E_USER_WARNING);
 685          }
 686      }
 687  }
 688