[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
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 /** 15 * @ignore 16 */ 17 if (!defined('IN_PHPBB')) 18 { 19 exit; 20 } 21 22 class acp_extensions 23 { 24 var $u_action; 25 var $tpl_name; 26 var $page_title; 27 28 private $config; 29 private $template; 30 private $user; 31 private $cache; 32 private $log; 33 private $request; 34 private $phpbb_dispatcher; 35 private $ext_manager; 36 37 function main() 38 { 39 // Start the page 40 global $config, $user, $template, $request, $phpbb_extension_manager, $phpbb_root_path, $phpEx, $phpbb_log, $cache, $phpbb_dispatcher; 41 42 $this->config = $config; 43 $this->template = $template; 44 $this->user = $user; 45 $this->cache = $cache; 46 $this->request = $request; 47 $this->log = $phpbb_log; 48 $this->phpbb_dispatcher = $phpbb_dispatcher; 49 $this->ext_manager = $phpbb_extension_manager; 50 51 $this->user->add_lang(array('install', 'acp/extensions', 'migrator')); 52 53 $this->page_title = 'ACP_EXTENSIONS'; 54 55 $action = $this->request->variable('action', 'list'); 56 $ext_name = $this->request->variable('ext_name', ''); 57 58 // What is a safe limit of execution time? Half the max execution time should be safe. 59 $safe_time_limit = (ini_get('max_execution_time') / 2); 60 $start_time = time(); 61 62 // Cancel action 63 if ($this->request->is_set_post('cancel')) 64 { 65 $action = 'list'; 66 $ext_name = ''; 67 } 68 69 if (in_array($action, array('enable', 'disable', 'delete_data')) && !check_link_hash($this->request->variable('hash', ''), $action . '.' . $ext_name)) 70 { 71 trigger_error('FORM_INVALID', E_USER_WARNING); 72 } 73 74 /** 75 * Event to run a specific action on extension 76 * 77 * @event core.acp_extensions_run_action_before 78 * @var string action Action to run; if the event completes execution of the action, should be set to 'none' 79 * @var string u_action Url we are at 80 * @var string ext_name Extension name from request 81 * @var int safe_time_limit Safe limit of execution time 82 * @var int start_time Start time 83 * @var string tpl_name Template file to load 84 * @since 3.1.11-RC1 85 * @changed 3.2.1-RC1 Renamed to core.acp_extensions_run_action_before, added tpl_name, added action 'none' 86 */ 87 $u_action = $this->u_action; 88 $tpl_name = ''; 89 $vars = array('action', 'u_action', 'ext_name', 'safe_time_limit', 'start_time', 'tpl_name'); 90 extract($this->phpbb_dispatcher->trigger_event('core.acp_extensions_run_action_before', compact($vars))); 91 92 // In case they have been updated by the event 93 $this->u_action = $u_action; 94 $this->tpl_name = $tpl_name; 95 96 // If they've specified an extension, let's load the metadata manager and validate it. 97 if ($ext_name) 98 { 99 $md_manager = $this->ext_manager->create_extension_metadata_manager($ext_name, $this->template); 100 101 try 102 { 103 $md_manager->get_metadata('all'); 104 } 105 catch (\phpbb\extension\exception $e) 106 { 107 trigger_error($e, E_USER_WARNING); 108 } 109 } 110 111 // What are we doing? 112 switch ($action) 113 { 114 case 'none': 115 // Intentionally empty, used by extensions that execute additional actions in the prior event 116 break; 117 118 case 'set_config_version_check_force_unstable': 119 $force_unstable = $this->request->variable('force_unstable', false); 120 121 if ($force_unstable) 122 { 123 $s_hidden_fields = build_hidden_fields(array( 124 'force_unstable' => $force_unstable, 125 )); 126 127 confirm_box(false, $this->user->lang('EXTENSION_FORCE_UNSTABLE_CONFIRM'), $s_hidden_fields); 128 } 129 else 130 { 131 $this->config->set('extension_force_unstable', false); 132 trigger_error($this->user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action)); 133 } 134 break; 135 136 case 'list': 137 default: 138 if (confirm_box(true)) 139 { 140 $this->config->set('extension_force_unstable', true); 141 trigger_error($this->user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action)); 142 } 143 144 $this->list_enabled_exts(); 145 $this->list_disabled_exts(); 146 $this->list_available_exts(); 147 148 $this->template->assign_vars(array( 149 'U_VERSIONCHECK_FORCE' => $this->u_action . '&action=list&versioncheck_force=1', 150 'FORCE_UNSTABLE' => $this->config['extension_force_unstable'], 151 'U_ACTION' => $this->u_action, 152 )); 153 154 $this->tpl_name = 'acp_ext_list'; 155 break; 156 157 case 'enable_pre': 158 try 159 { 160 $md_manager->validate_enable(); 161 } 162 catch (\phpbb\extension\exception $e) 163 { 164 trigger_error($e . adm_back_link($this->u_action), E_USER_WARNING); 165 } 166 167 $extension = $this->ext_manager->get_extension($ext_name); 168 if (!$extension->is_enableable()) 169 { 170 trigger_error($this->user->lang['EXTENSION_NOT_ENABLEABLE'] . adm_back_link($this->u_action), E_USER_WARNING); 171 } 172 173 if ($this->ext_manager->is_enabled($ext_name)) 174 { 175 redirect($this->u_action); 176 } 177 178 $this->tpl_name = 'acp_ext_enable'; 179 180 $this->template->assign_vars(array( 181 'PRE' => true, 182 'L_CONFIRM_MESSAGE' => $this->user->lang('EXTENSION_ENABLE_CONFIRM', $md_manager->get_metadata('display-name')), 183 'U_ENABLE' => $this->u_action . '&action=enable&ext_name=' . urlencode($ext_name) . '&hash=' . generate_link_hash('enable.' . $ext_name), 184 )); 185 break; 186 187 case 'enable': 188 try 189 { 190 $md_manager->validate_enable(); 191 } 192 catch (\phpbb\extension\exception $e) 193 { 194 trigger_error($e . adm_back_link($this->u_action), E_USER_WARNING); 195 } 196 197 $extension = $this->ext_manager->get_extension($ext_name); 198 if (!$extension->is_enableable()) 199 { 200 trigger_error($this->user->lang['EXTENSION_NOT_ENABLEABLE'] . adm_back_link($this->u_action), E_USER_WARNING); 201 } 202 203 try 204 { 205 while ($this->ext_manager->enable_step($ext_name)) 206 { 207 // Are we approaching the time limit? If so we want to pause the update and continue after refreshing 208 if ((time() - $start_time) >= $safe_time_limit) 209 { 210 $this->template->assign_var('S_NEXT_STEP', true); 211 212 meta_refresh(0, $this->u_action . '&action=enable&ext_name=' . urlencode($ext_name) . '&hash=' . generate_link_hash('enable.' . $ext_name)); 213 } 214 } 215 216 // Update custom style for admin area 217 $this->template->set_custom_style(array( 218 array( 219 'name' => 'adm', 220 'ext_path' => 'adm/style/', 221 ), 222 ), array($phpbb_root_path . 'adm/style')); 223 224 $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_EXT_ENABLE', time(), array($ext_name)); 225 } 226 catch (\phpbb\db\migration\exception $e) 227 { 228 $this->template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($this->user)); 229 } 230 231 $this->tpl_name = 'acp_ext_enable'; 232 233 $this->template->assign_vars(array( 234 'U_RETURN' => $this->u_action . '&action=list', 235 )); 236 break; 237 238 case 'disable_pre': 239 if (!$this->ext_manager->is_enabled($ext_name)) 240 { 241 redirect($this->u_action); 242 } 243 244 $this->tpl_name = 'acp_ext_disable'; 245 246 $this->template->assign_vars(array( 247 'PRE' => true, 248 'L_CONFIRM_MESSAGE' => $this->user->lang('EXTENSION_DISABLE_CONFIRM', $md_manager->get_metadata('display-name')), 249 'U_DISABLE' => $this->u_action . '&action=disable&ext_name=' . urlencode($ext_name) . '&hash=' . generate_link_hash('disable.' . $ext_name), 250 )); 251 break; 252 253 case 'disable': 254 if (!$this->ext_manager->is_enabled($ext_name)) 255 { 256 redirect($this->u_action); 257 } 258 259 while ($this->ext_manager->disable_step($ext_name)) 260 { 261 // Are we approaching the time limit? If so we want to pause the update and continue after refreshing 262 if ((time() - $start_time) >= $safe_time_limit) 263 { 264 $this->template->assign_var('S_NEXT_STEP', true); 265 266 meta_refresh(0, $this->u_action . '&action=disable&ext_name=' . urlencode($ext_name) . '&hash=' . generate_link_hash('disable.' . $ext_name)); 267 } 268 } 269 $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_EXT_DISABLE', time(), array($ext_name)); 270 271 $this->tpl_name = 'acp_ext_disable'; 272 273 $this->template->assign_vars(array( 274 'U_RETURN' => $this->u_action . '&action=list', 275 )); 276 break; 277 278 case 'delete_data_pre': 279 if ($this->ext_manager->is_enabled($ext_name)) 280 { 281 redirect($this->u_action); 282 } 283 $this->tpl_name = 'acp_ext_delete_data'; 284 285 $this->template->assign_vars(array( 286 'PRE' => true, 287 'L_CONFIRM_MESSAGE' => $this->user->lang('EXTENSION_DELETE_DATA_CONFIRM', $md_manager->get_metadata('display-name')), 288 'U_PURGE' => $this->u_action . '&action=delete_data&ext_name=' . urlencode($ext_name) . '&hash=' . generate_link_hash('delete_data.' . $ext_name), 289 )); 290 break; 291 292 case 'delete_data': 293 if ($this->ext_manager->is_enabled($ext_name)) 294 { 295 redirect($this->u_action); 296 } 297 298 try 299 { 300 while ($this->ext_manager->purge_step($ext_name)) 301 { 302 // Are we approaching the time limit? If so we want to pause the update and continue after refreshing 303 if ((time() - $start_time) >= $safe_time_limit) 304 { 305 $this->template->assign_var('S_NEXT_STEP', true); 306 307 meta_refresh(0, $this->u_action . '&action=delete_data&ext_name=' . urlencode($ext_name) . '&hash=' . generate_link_hash('delete_data.' . $ext_name)); 308 } 309 } 310 $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_EXT_PURGE', time(), array($ext_name)); 311 } 312 catch (\phpbb\db\migration\exception $e) 313 { 314 $this->template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($this->user)); 315 } 316 317 $this->tpl_name = 'acp_ext_delete_data'; 318 319 $this->template->assign_vars(array( 320 'U_RETURN' => $this->u_action . '&action=list', 321 )); 322 break; 323 324 case 'details': 325 // Output it to the template 326 $md_manager->output_template_data(); 327 328 try 329 { 330 $updates_available = $this->version_check($md_manager, $this->request->variable('versioncheck_force', false)); 331 332 $this->template->assign_vars(array( 333 'S_UP_TO_DATE' => empty($updates_available), 334 'S_VERSIONCHECK' => true, 335 'UP_TO_DATE_MSG' => $this->user->lang(empty($updates_available) ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $md_manager->get_metadata('display-name')), 336 )); 337 338 $this->template->assign_block_vars('updates_available', $updates_available); 339 } 340 catch (\RuntimeException $e) 341 { 342 $this->template->assign_vars(array( 343 'S_VERSIONCHECK_STATUS' => $e->getCode(), 344 'VERSIONCHECK_FAIL_REASON' => ($e->getMessage() !== $this->user->lang('VERSIONCHECK_FAIL')) ? $e->getMessage() : '', 345 )); 346 } 347 348 $this->template->assign_vars(array( 349 'U_BACK' => $this->u_action . '&action=list', 350 'U_VERSIONCHECK_FORCE' => $this->u_action . '&action=details&versioncheck_force=1&ext_name=' . urlencode($md_manager->get_metadata('name')), 351 )); 352 353 $this->tpl_name = 'acp_ext_details'; 354 break; 355 } 356 357 /** 358 * Event to run after a specific action on extension has completed 359 * 360 * @event core.acp_extensions_run_action_after 361 * @var string action Action that has run 362 * @var string u_action Url we are at 363 * @var string ext_name Extension name from request 364 * @var int safe_time_limit Safe limit of execution time 365 * @var int start_time Start time 366 * @var string tpl_name Template file to load 367 * @since 3.1.11-RC1 368 */ 369 $u_action = $this->u_action; 370 $tpl_name = $this->tpl_name; 371 $vars = array('action', 'u_action', 'ext_name', 'safe_time_limit', 'start_time', 'tpl_name'); 372 extract($this->phpbb_dispatcher->trigger_event('core.acp_extensions_run_action_after', compact($vars))); 373 374 // In case they have been updated by the event 375 $this->u_action = $u_action; 376 $this->tpl_name = $tpl_name; 377 } 378 379 /** 380 * Lists all the enabled extensions and dumps to the template 381 * 382 * @return null 383 */ 384 public function list_enabled_exts() 385 { 386 $enabled_extension_meta_data = array(); 387 388 foreach ($this->ext_manager->all_enabled() as $name => $location) 389 { 390 $md_manager = $this->ext_manager->create_extension_metadata_manager($name, $this->template); 391 392 try 393 { 394 $meta = $md_manager->get_metadata('all'); 395 $enabled_extension_meta_data[$name] = array( 396 'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'), 397 'META_VERSION' => $meta['version'], 398 ); 399 400 $force_update = $this->request->variable('versioncheck_force', false); 401 $updates = $this->version_check($md_manager, $force_update, !$force_update); 402 403 $enabled_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates); 404 $enabled_extension_meta_data[$name]['S_VERSIONCHECK'] = true; 405 $enabled_extension_meta_data[$name]['U_VERSIONCHECK_FORCE'] = $this->u_action . '&action=details&versioncheck_force=1&ext_name=' . urlencode($md_manager->get_metadata('name')); 406 } 407 catch (\phpbb\extension\exception $e) 408 { 409 $this->template->assign_block_vars('disabled', array( 410 'META_DISPLAY_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), 411 'S_VERSIONCHECK' => false, 412 )); 413 } 414 catch (\RuntimeException $e) 415 { 416 $enabled_extension_meta_data[$name]['S_VERSIONCHECK'] = false; 417 } 418 } 419 420 uasort($enabled_extension_meta_data, array($this, 'sort_extension_meta_data_table')); 421 422 foreach ($enabled_extension_meta_data as $name => $block_vars) 423 { 424 $block_vars['NAME'] = $name; 425 $block_vars['U_DETAILS'] = $this->u_action . '&action=details&ext_name=' . urlencode($name); 426 427 $this->template->assign_block_vars('enabled', $block_vars); 428 429 $this->output_actions('enabled', array( 430 'DISABLE' => $this->u_action . '&action=disable_pre&ext_name=' . urlencode($name), 431 )); 432 } 433 } 434 435 /** 436 * Lists all the disabled extensions and dumps to the template 437 * 438 * @return null 439 */ 440 public function list_disabled_exts() 441 { 442 $disabled_extension_meta_data = array(); 443 444 foreach ($this->ext_manager->all_disabled() as $name => $location) 445 { 446 $md_manager = $this->ext_manager->create_extension_metadata_manager($name, $this->template); 447 448 try 449 { 450 $meta = $md_manager->get_metadata('all'); 451 $disabled_extension_meta_data[$name] = array( 452 'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'), 453 'META_VERSION' => $meta['version'], 454 ); 455 456 $force_update = $this->request->variable('versioncheck_force', false); 457 $updates = $this->version_check($md_manager, $force_update, !$force_update); 458 459 $disabled_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates); 460 $disabled_extension_meta_data[$name]['S_VERSIONCHECK'] = true; 461 $disabled_extension_meta_data[$name]['U_VERSIONCHECK_FORCE'] = $this->u_action . '&action=details&versioncheck_force=1&ext_name=' . urlencode($md_manager->get_metadata('name')); 462 } 463 catch (\phpbb\extension\exception $e) 464 { 465 $this->template->assign_block_vars('disabled', array( 466 'META_DISPLAY_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), 467 'S_VERSIONCHECK' => false, 468 )); 469 } 470 catch (\RuntimeException $e) 471 { 472 $disabeld_extension_meta_data[$name]['S_VERSIONCHECK'] = false; 473 } 474 } 475 476 uasort($disabled_extension_meta_data, array($this, 'sort_extension_meta_data_table')); 477 478 foreach ($disabled_extension_meta_data as $name => $block_vars) 479 { 480 $block_vars['NAME'] = $name; 481 $block_vars['U_DETAILS'] = $this->u_action . '&action=details&ext_name=' . urlencode($name); 482 483 $this->template->assign_block_vars('disabled', $block_vars); 484 485 $this->output_actions('disabled', array( 486 'ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . urlencode($name), 487 'DELETE_DATA' => $this->u_action . '&action=delete_data_pre&ext_name=' . urlencode($name), 488 )); 489 } 490 } 491 492 /** 493 * Lists all the available extensions and dumps to the template 494 * 495 * @return null 496 */ 497 public function list_available_exts() 498 { 499 $uninstalled = array_diff_key($this->ext_manager->all_available(), $this->ext_manager->all_configured()); 500 501 $available_extension_meta_data = array(); 502 503 foreach ($uninstalled as $name => $location) 504 { 505 $md_manager = $this->ext_manager->create_extension_metadata_manager($name, $this->template); 506 507 try 508 { 509 $meta = $md_manager->get_metadata('all'); 510 $available_extension_meta_data[$name] = array( 511 'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'), 512 'META_VERSION' => $meta['version'], 513 ); 514 515 $force_update = $this->request->variable('versioncheck_force', false); 516 $updates = $this->version_check($md_manager, $force_update, !$force_update); 517 518 $available_extension_meta_data[$name]['S_UP_TO_DATE'] = empty($updates); 519 $available_extension_meta_data[$name]['S_VERSIONCHECK'] = true; 520 $available_extension_meta_data[$name]['U_VERSIONCHECK_FORCE'] = $this->u_action . '&action=details&versioncheck_force=1&ext_name=' . urlencode($md_manager->get_metadata('name')); 521 } 522 catch (\phpbb\extension\exception $e) 523 { 524 $this->template->assign_block_vars('disabled', array( 525 'META_DISPLAY_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), 526 'S_VERSIONCHECK' => false, 527 )); 528 } 529 catch (\RuntimeException $e) 530 { 531 $available_extension_meta_data[$name]['S_VERSIONCHECK'] = false; 532 } 533 } 534 535 uasort($available_extension_meta_data, array($this, 'sort_extension_meta_data_table')); 536 537 foreach ($available_extension_meta_data as $name => $block_vars) 538 { 539 $block_vars['NAME'] = $name; 540 $block_vars['U_DETAILS'] = $this->u_action . '&action=details&ext_name=' . urlencode($name); 541 542 $this->template->assign_block_vars('disabled', $block_vars); 543 544 $this->output_actions('disabled', array( 545 'ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . urlencode($name), 546 )); 547 } 548 } 549 550 /** 551 * Output actions to a block 552 * 553 * @param string $block 554 * @param array $actions 555 */ 556 private function output_actions($block, $actions) 557 { 558 foreach ($actions as $lang => $url) 559 { 560 $this->template->assign_block_vars($block . '.actions', array( 561 'L_ACTION' => $this->user->lang('EXTENSION_' . $lang), 562 'L_ACTION_EXPLAIN' => (isset($this->user->lang['EXTENSION_' . $lang . '_EXPLAIN'])) ? $this->user->lang('EXTENSION_' . $lang . '_EXPLAIN') : '', 563 'U_ACTION' => $url, 564 )); 565 } 566 } 567 568 /** 569 * Check the version and return the available updates. 570 * 571 * @param \phpbb\extension\metadata_manager $md_manager The metadata manager for the version to check. 572 * @param bool $force_update Ignores cached data. Defaults to false. 573 * @param bool $force_cache Force the use of the cache. Override $force_update. 574 * @return array 575 * @throws RuntimeException 576 */ 577 protected function version_check(\phpbb\extension\metadata_manager $md_manager, $force_update = false, $force_cache = false) 578 { 579 $meta = $md_manager->get_metadata('all'); 580 581 if (!isset($meta['extra']['version-check'])) 582 { 583 throw new \RuntimeException($this->user->lang('NO_VERSIONCHECK'), 1); 584 } 585 586 $version_check = $meta['extra']['version-check']; 587 588 $version_helper = new \phpbb\version_helper($this->cache, $this->config, new \phpbb\file_downloader(), $this->user); 589 $version_helper->set_current_version($meta['version']); 590 $version_helper->set_file_location($version_check['host'], $version_check['directory'], $version_check['filename'], isset($version_check['ssl']) ? $version_check['ssl'] : false); 591 $version_helper->force_stability($this->config['extension_force_unstable'] ? 'unstable' : null); 592 593 return $version_helper->get_ext_update_on_branch($force_update, $force_cache); 594 } 595 596 /** 597 * Sort helper for the table containing the metadata about the extensions. 598 */ 599 protected function sort_extension_meta_data_table($val1, $val2) 600 { 601 return strnatcasecmp($val1['META_DISPLAY_NAME'], $val2['META_DISPLAY_NAME']); 602 } 603 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |