[ Index ]

PHP Cross Reference of phpBB-3.2.11-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()
  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->template->assign_vars(array(
 155                      'U_VERSIONCHECK_FORCE'     => $this->u_action . '&amp;action=list&amp;versioncheck_force=1',
 156                      'FORCE_UNSTABLE'        => $this->config['extension_force_unstable'],
 157                      'U_ACTION'                 => $this->u_action,
 158                  ));
 159  
 160                  $this->tpl_name = 'acp_ext_list';
 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                  if (!$extension->is_enableable())
 176                  {
 177                      trigger_error($this->user->lang['EXTENSION_NOT_ENABLEABLE'] . adm_back_link($this->u_action), E_USER_WARNING);
 178                  }
 179  
 180                  if ($this->ext_manager->is_enabled($ext_name))
 181                  {
 182                      redirect($this->u_action);
 183                  }
 184  
 185                  $this->tpl_name = 'acp_ext_enable';
 186  
 187                  $this->template->assign_vars(array(
 188                      'PRE'                => true,
 189                      'L_CONFIRM_MESSAGE'    => $this->user->lang('EXTENSION_ENABLE_CONFIRM', $md_manager->get_metadata('display-name')),
 190                      'U_ENABLE'            => $this->u_action . '&amp;action=enable&amp;ext_name=' . urlencode($ext_name) . '&amp;hash=' . generate_link_hash('enable.' . $ext_name),
 191                  ));
 192              break;
 193  
 194              case 'enable':
 195                  try
 196                  {
 197                      $md_manager->validate_enable();
 198                  }
 199                  catch (exception_interface $e)
 200                  {
 201                      $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
 202                      trigger_error($message . adm_back_link($this->u_action), E_USER_WARNING);
 203                  }
 204  
 205                  $extension = $this->ext_manager->get_extension($ext_name);
 206                  if (!$extension->is_enableable())
 207                  {
 208                      trigger_error($this->user->lang['EXTENSION_NOT_ENABLEABLE'] . adm_back_link($this->u_action), E_USER_WARNING);
 209                  }
 210  
 211                  try
 212                  {
 213                      while ($this->ext_manager->enable_step($ext_name))
 214                      {
 215                          // Are we approaching the time limit? If so we want to pause the update and continue after refreshing
 216                          if ((time() - $start_time) >= $safe_time_limit)
 217                          {
 218                              $this->template->assign_var('S_NEXT_STEP', true);
 219  
 220                              meta_refresh(0, $this->u_action . '&amp;action=enable&amp;ext_name=' . urlencode($ext_name) . '&amp;hash=' . generate_link_hash('enable.' . $ext_name));
 221                          }
 222                      }
 223  
 224                      // Update custom style for admin area
 225                      $this->template->set_custom_style(array(
 226                          array(
 227                              'name'         => 'adm',
 228                              'ext_path'     => 'adm/style/',
 229                          ),
 230                      ), array($phpbb_root_path . 'adm/style'));
 231  
 232                      $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_EXT_ENABLE', time(), array($ext_name));
 233                  }
 234                  catch (\phpbb\db\migration\exception $e)
 235                  {
 236                      $this->template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($this->user));
 237                  }
 238  
 239                  $this->tpl_name = 'acp_ext_enable';
 240  
 241                  $this->template->assign_vars(array(
 242                      'U_RETURN'        => $this->u_action . '&amp;action=list',
 243                  ));
 244              break;
 245  
 246              case 'disable_pre':
 247                  if (!$this->ext_manager->is_enabled($ext_name))
 248                  {
 249                      redirect($this->u_action);
 250                  }
 251  
 252                  $this->tpl_name = 'acp_ext_disable';
 253  
 254                  $this->template->assign_vars(array(
 255                      'PRE'                => true,
 256                      'L_CONFIRM_MESSAGE'    => $this->user->lang('EXTENSION_DISABLE_CONFIRM', $md_manager->get_metadata('display-name')),
 257                      'U_DISABLE'            => $this->u_action . '&amp;action=disable&amp;ext_name=' . urlencode($ext_name) . '&amp;hash=' . generate_link_hash('disable.' . $ext_name),
 258                  ));
 259              break;
 260  
 261              case 'disable':
 262                  if (!$this->ext_manager->is_enabled($ext_name))
 263                  {
 264                      redirect($this->u_action);
 265                  }
 266  
 267                  while ($this->ext_manager->disable_step($ext_name))
 268                  {
 269                      // Are we approaching the time limit? If so we want to pause the update and continue after refreshing
 270                      if ((time() - $start_time) >= $safe_time_limit)
 271                      {
 272                          $this->template->assign_var('S_NEXT_STEP', true);
 273  
 274                          meta_refresh(0, $this->u_action . '&amp;action=disable&amp;ext_name=' . urlencode($ext_name) . '&amp;hash=' . generate_link_hash('disable.' . $ext_name));
 275                      }
 276                  }
 277                  $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_EXT_DISABLE', time(), array($ext_name));
 278  
 279                  $this->tpl_name = 'acp_ext_disable';
 280  
 281                  $this->template->assign_vars(array(
 282                      'U_RETURN'    => $this->u_action . '&amp;action=list',
 283                  ));
 284              break;
 285  
 286              case 'delete_data_pre':
 287                  if ($this->ext_manager->is_enabled($ext_name))
 288                  {
 289                      redirect($this->u_action);
 290                  }
 291                  $this->tpl_name = 'acp_ext_delete_data';
 292  
 293                  $this->template->assign_vars(array(
 294                      'PRE'                => true,
 295                      'L_CONFIRM_MESSAGE'    => $this->user->lang('EXTENSION_DELETE_DATA_CONFIRM', $md_manager->get_metadata('display-name')),
 296                      'U_PURGE'            => $this->u_action . '&amp;action=delete_data&amp;ext_name=' . urlencode($ext_name) . '&amp;hash=' . generate_link_hash('delete_data.' . $ext_name),
 297                  ));
 298              break;
 299  
 300              case 'delete_data':
 301                  if ($this->ext_manager->is_enabled($ext_name))
 302                  {
 303                      redirect($this->u_action);
 304                  }
 305  
 306                  try
 307                  {
 308                      while ($this->ext_manager->purge_step($ext_name))
 309                      {
 310                          // Are we approaching the time limit? If so we want to pause the update and continue after refreshing
 311                          if ((time() - $start_time) >= $safe_time_limit)
 312                          {
 313                              $this->template->assign_var('S_NEXT_STEP', true);
 314  
 315                              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));
 316                          }
 317                      }
 318                      $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_EXT_PURGE', time(), array($ext_name));
 319                  }
 320                  catch (\phpbb\db\migration\exception $e)
 321                  {
 322                      $this->template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($this->user));
 323                  }
 324  
 325                  $this->tpl_name = 'acp_ext_delete_data';
 326  
 327                  $this->template->assign_vars(array(
 328                      'U_RETURN'    => $this->u_action . '&amp;action=list',
 329                  ));
 330              break;
 331  
 332              case 'details':
 333                  // Output it to the template
 334                  $meta = $md_manager->get_metadata('all');
 335                  $this->output_metadata_to_template($meta);
 336  
 337                  if (isset($meta['extra']['version-check']))
 338                  {
 339                      try
 340                      {
 341                          $updates_available = $this->ext_manager->version_check($md_manager, $this->request->variable('versioncheck_force', false), false, $this->config['extension_force_unstable'] ? 'unstable' : null);
 342  
 343                          $this->template->assign_vars(array(
 344                              'S_UP_TO_DATE' => empty($updates_available),
 345                              'UP_TO_DATE_MSG' => $this->user->lang(empty($updates_available) ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $md_manager->get_metadata('display-name')),
 346                          ));
 347  
 348                          $this->template->assign_block_vars('updates_available', $updates_available);
 349                      }
 350                      catch (exception_interface $e)
 351                      {
 352                          $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
 353  
 354                          $this->template->assign_vars(array(
 355                              'S_VERSIONCHECK_FAIL' => true,
 356                              'VERSIONCHECK_FAIL_REASON' => ($e->getMessage() !== 'VERSIONCHECK_FAIL') ? $message : '',
 357                          ));
 358                      }
 359                      $this->template->assign_var('S_VERSIONCHECK', true);
 360                  }
 361                  else
 362                  {
 363                      $this->template->assign_var('S_VERSIONCHECK', false);
 364                  }
 365  
 366                  $this->template->assign_vars(array(
 367                      'U_BACK'                => $this->u_action . '&amp;action=list',
 368                      'U_VERSIONCHECK_FORCE'    => $this->u_action . '&amp;action=details&amp;versioncheck_force=1&amp;ext_name=' . urlencode($md_manager->get_metadata('name')),
 369                  ));
 370  
 371                  $this->tpl_name = 'acp_ext_details';
 372              break;
 373          }
 374  
 375          /**
 376          * Event to run after a specific action on extension has completed
 377          *
 378          * @event core.acp_extensions_run_action_after
 379          * @var    string    action            Action that has run
 380          * @var    string    u_action        Url we are at
 381          * @var    string    ext_name        Extension name from request
 382          * @var    int        safe_time_limit    Safe limit of execution time
 383          * @var    int        start_time        Start time
 384          * @var    string    tpl_name        Template file to load
 385          * @since 3.1.11-RC1
 386          */
 387          $u_action = $this->u_action;
 388          $tpl_name = $this->tpl_name;
 389          $vars = array('action', 'u_action', 'ext_name', 'safe_time_limit', 'start_time', 'tpl_name');
 390          extract($this->phpbb_dispatcher->trigger_event('core.acp_extensions_run_action_after', compact($vars)));
 391  
 392          // In case they have been updated by the event
 393          $this->u_action = $u_action;
 394          $this->tpl_name = $tpl_name;
 395      }
 396  
 397      /**
 398      * Lists all the enabled extensions and dumps to the template
 399      *
 400      * @return null
 401      */
 402  	public function list_enabled_exts()
 403      {
 404          $enabled_extension_meta_data = array();
 405  
 406          foreach ($this->ext_manager->all_enabled() as $name => $location)
 407          {
 408              $md_manager = $this->ext_manager->create_extension_metadata_manager($name);
 409  
 410              try
 411              {
 412                  $meta = $md_manager->get_metadata('all');
 413                  $enabled_extension_meta_data[$name] = array(
 414                      'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'),
 415                      'META_VERSION' => $meta['version'],
 416                  );
 417  
 418                  if (isset($meta['extra']['version-check']))
 419                  {
 420                      try
 421                      {
 422                          $force_update = $this->request->variable('versioncheck_force', false);
 423                          $updates = $this->ext_manager->version_check($md_manager, $force_update, !$force_update);
 424  
 425                          $enabled_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates);
 426                          $enabled_extension_meta_data[$name]['S_VERSIONCHECK'] = true;
 427                          $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'));
 428                      }
 429                      catch (exception_interface $e)
 430                      {
 431                          // Ignore exceptions due to the version check
 432                      }
 433                  }
 434                  else
 435                  {
 436                      $enabled_extension_meta_data[$name]['S_VERSIONCHECK'] = false;
 437                  }
 438              }
 439              catch (exception_interface $e)
 440              {
 441                  $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
 442                  $this->template->assign_block_vars('disabled', array(
 443                      'META_DISPLAY_NAME'        => $this->user->lang('EXTENSION_INVALID_LIST', $name, $message),
 444                      'S_VERSIONCHECK'        => false,
 445                  ));
 446              }
 447              catch (\RuntimeException $e)
 448              {
 449                  $enabled_extension_meta_data[$name]['S_VERSIONCHECK'] = false;
 450              }
 451          }
 452  
 453          uasort($enabled_extension_meta_data, array($this, 'sort_extension_meta_data_table'));
 454  
 455          foreach ($enabled_extension_meta_data as $name => $block_vars)
 456          {
 457              $block_vars['NAME'] = $name;
 458              $block_vars['U_DETAILS'] = $this->u_action . '&amp;action=details&amp;ext_name=' . urlencode($name);
 459  
 460              $this->template->assign_block_vars('enabled', $block_vars);
 461  
 462              $this->output_actions('enabled', array(
 463                  'DISABLE'        => $this->u_action . '&amp;action=disable_pre&amp;ext_name=' . urlencode($name),
 464              ));
 465          }
 466      }
 467  
 468      /**
 469      * Lists all the disabled extensions and dumps to the template
 470      *
 471      * @return null
 472      */
 473  	public function list_disabled_exts()
 474      {
 475          $disabled_extension_meta_data = array();
 476  
 477          foreach ($this->ext_manager->all_disabled() as $name => $location)
 478          {
 479              $md_manager = $this->ext_manager->create_extension_metadata_manager($name);
 480  
 481              try
 482              {
 483                  $meta = $md_manager->get_metadata('all');
 484                  $disabled_extension_meta_data[$name] = array(
 485                      'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'),
 486                      'META_VERSION' => $meta['version'],
 487                  );
 488  
 489                  if (isset($meta['extra']['version-check']))
 490                  {
 491                      $force_update = $this->request->variable('versioncheck_force', false);
 492                      $updates = $this->ext_manager->version_check($md_manager, $force_update, !$force_update);
 493  
 494                      $disabled_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates);
 495                      $disabled_extension_meta_data[$name]['S_VERSIONCHECK'] = true;
 496                      $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'));
 497                  }
 498                  else
 499                  {
 500                      $disabled_extension_meta_data[$name]['S_VERSIONCHECK'] = false;
 501                  }
 502              }
 503              catch (version_check_exception $e)
 504              {
 505                  $disabled_extension_meta_data[$name]['S_VERSIONCHECK'] = false;
 506              }
 507              catch (exception_interface $e)
 508              {
 509                  $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
 510                  $this->template->assign_block_vars('disabled', array(
 511                      'META_DISPLAY_NAME'        => $this->user->lang('EXTENSION_INVALID_LIST', $name, $message),
 512                      'S_VERSIONCHECK'        => false,
 513                  ));
 514              }
 515              catch (\RuntimeException $e)
 516              {
 517                  $disabled_extension_meta_data[$name]['S_VERSIONCHECK'] = false;
 518              }
 519          }
 520  
 521          uasort($disabled_extension_meta_data, array($this, 'sort_extension_meta_data_table'));
 522  
 523          foreach ($disabled_extension_meta_data as $name => $block_vars)
 524          {
 525              $block_vars['NAME'] = $name;
 526              $block_vars['U_DETAILS'] = $this->u_action . '&amp;action=details&amp;ext_name=' . urlencode($name);
 527  
 528              $this->template->assign_block_vars('disabled', $block_vars);
 529  
 530              $this->output_actions('disabled', array(
 531                  'ENABLE'        => $this->u_action . '&amp;action=enable_pre&amp;ext_name=' . urlencode($name),
 532                  'DELETE_DATA'    => $this->u_action . '&amp;action=delete_data_pre&amp;ext_name=' . urlencode($name),
 533              ));
 534          }
 535      }
 536  
 537      /**
 538      * Lists all the available extensions and dumps to the template
 539      *
 540      * @return null
 541      */
 542  	public function list_available_exts()
 543      {
 544          $uninstalled = array_diff_key($this->ext_manager->all_available(), $this->ext_manager->all_configured());
 545  
 546          $available_extension_meta_data = array();
 547  
 548          foreach ($uninstalled as $name => $location)
 549          {
 550              $md_manager = $this->ext_manager->create_extension_metadata_manager($name);
 551  
 552              try
 553              {
 554                  $meta = $md_manager->get_metadata('all');
 555                  $available_extension_meta_data[$name] = array(
 556                      'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'),
 557                      'META_VERSION' => $meta['version'],
 558                  );
 559  
 560                  if (isset($meta['extra']['version-check']))
 561                  {
 562                      $force_update = $this->request->variable('versioncheck_force', false);
 563                      $updates = $this->ext_manager->version_check($md_manager, $force_update, !$force_update);
 564  
 565                      $available_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates);
 566                      $available_extension_meta_data[$name]['S_VERSIONCHECK'] = true;
 567                      $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'));
 568                  }
 569                  else
 570                  {
 571                      $available_extension_meta_data[$name]['S_VERSIONCHECK'] = false;
 572                  }
 573              }
 574              catch (version_check_exception $e)
 575              {
 576                  $available_extension_meta_data[$name]['S_VERSIONCHECK'] = false;
 577              }
 578              catch (exception_interface $e)
 579              {
 580                  $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters()));
 581                  $this->template->assign_block_vars('disabled', array(
 582                      'META_DISPLAY_NAME'        => $this->user->lang('EXTENSION_INVALID_LIST', $name, $message),
 583                      'S_VERSIONCHECK'        => false,
 584                  ));
 585              }
 586          }
 587  
 588          uasort($available_extension_meta_data, array($this, 'sort_extension_meta_data_table'));
 589  
 590          foreach ($available_extension_meta_data as $name => $block_vars)
 591          {
 592              $block_vars['NAME'] = $name;
 593              $block_vars['U_DETAILS'] = $this->u_action . '&amp;action=details&amp;ext_name=' . urlencode($name);
 594  
 595              $this->template->assign_block_vars('disabled', $block_vars);
 596  
 597              $this->output_actions('disabled', array(
 598                  'ENABLE'        => $this->u_action . '&amp;action=enable_pre&amp;ext_name=' . urlencode($name),
 599              ));
 600          }
 601      }
 602  
 603      /**
 604      * Output actions to a block
 605      *
 606      * @param string $block
 607      * @param array $actions
 608      */
 609  	private function output_actions($block, $actions)
 610      {
 611          foreach ($actions as $lang => $url)
 612          {
 613              $this->template->assign_block_vars($block . '.actions', array(
 614                  'L_ACTION'            => $this->user->lang('EXTENSION_' . $lang),
 615                  'L_ACTION_EXPLAIN'    => (isset($this->user->lang['EXTENSION_' . $lang . '_EXPLAIN'])) ? $this->user->lang('EXTENSION_' . $lang . '_EXPLAIN') : '',
 616                  'U_ACTION'            => $url,
 617              ));
 618          }
 619      }
 620  
 621      /**
 622      * Sort helper for the table containing the metadata about the extensions.
 623      */
 624  	protected function sort_extension_meta_data_table($val1, $val2)
 625      {
 626          return strnatcasecmp($val1['META_DISPLAY_NAME'], $val2['META_DISPLAY_NAME']);
 627      }
 628  
 629      /**
 630      * Outputs extension metadata into the template
 631      *
 632      * @param array $metadata Array with all metadata for the extension
 633      * @return null
 634      */
 635  	public function output_metadata_to_template($metadata)
 636      {
 637          $this->template->assign_vars(array(
 638              'META_NAME'            => $metadata['name'],
 639              'META_TYPE'            => $metadata['type'],
 640              'META_DESCRIPTION'    => (isset($metadata['description'])) ? $metadata['description'] : '',
 641              'META_HOMEPAGE'        => (isset($metadata['homepage'])) ? $metadata['homepage'] : '',
 642              'META_VERSION'        => $metadata['version'],
 643              'META_TIME'            => (isset($metadata['time'])) ? $metadata['time'] : '',
 644              'META_LICENSE'        => $metadata['license'],
 645  
 646              'META_REQUIRE_PHP'        => (isset($metadata['require']['php'])) ? $metadata['require']['php'] : '',
 647              'META_REQUIRE_PHP_FAIL'    => (isset($metadata['require']['php'])) ? false : true,
 648  
 649              'META_REQUIRE_PHPBB'        => (isset($metadata['extra']['soft-require']['phpbb/phpbb'])) ? $metadata['extra']['soft-require']['phpbb/phpbb'] : '',
 650              'META_REQUIRE_PHPBB_FAIL'    => (isset($metadata['extra']['soft-require']['phpbb/phpbb'])) ? false : true,
 651  
 652              'META_DISPLAY_NAME'    => (isset($metadata['extra']['display-name'])) ? $metadata['extra']['display-name'] : '',
 653          ));
 654  
 655          foreach ($metadata['authors'] as $author)
 656          {
 657              $this->template->assign_block_vars('meta_authors', array(
 658                  'AUTHOR_NAME'        => $author['name'],
 659                  'AUTHOR_EMAIL'        => (isset($author['email'])) ? $author['email'] : '',
 660                  'AUTHOR_HOMEPAGE'    => (isset($author['homepage'])) ? $author['homepage'] : '',
 661                  'AUTHOR_ROLE'        => (isset($author['role'])) ? $author['role'] : '',
 662              ));
 663          }
 664      }
 665  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1