[ Index ]

PHP Cross Reference of phpBB-3.3.3-deutsch

title

Body

[close]

/includes/acp/ -> acp_extensions.php (source)

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


Generated: Sun Feb 14 20:08:31 2021 Cross-referenced by PHPXref 0.7.1