[ Index ] |
PHP Cross Reference of MyBB |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.6 4 * Copyright 2010 MyBB Group, All Rights Reserved 5 * 6 * Website: http://mybb.com 7 * License: http://mybb.com/about/license 8 * 9 * $Id$ 10 */ 11 12 // Disallow direct access to this file for security reasons 13 if(!defined("IN_MYBB")) 14 { 15 die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined."); 16 } 17 18 $page->add_breadcrumb_item($lang->plugins, "index.php?module=config-plugins"); 19 20 $plugins->run_hooks("admin_config_plugins_begin"); 21 22 if($mybb->input['action'] == "browse") 23 { 24 $page->add_breadcrumb_item($lang->browse_plugins); 25 26 $page->output_header($lang->browse_plugins); 27 28 $sub_tabs['plugins'] = array( 29 'title' => $lang->plugins, 30 'link' => "index.php?module=config-plugins", 31 'description' => $lang->plugins_desc 32 ); 33 $sub_tabs['update_plugins'] = array( 34 'title' => $lang->plugin_updates, 35 'link' => "index.php?module=config-plugins&action=check", 36 'description' => $lang->plugin_updates_desc 37 ); 38 39 $sub_tabs['browse_plugins'] = array( 40 'title' => $lang->browse_plugins, 41 'link' => "index.php?module=config-plugins&action=browse", 42 'description' => $lang->browse_plugins_desc 43 ); 44 45 $page->output_nav_tabs($sub_tabs, 'browse_plugins'); 46 47 // Process search requests 48 require_once MYBB_ROOT."inc/class_xml.php"; 49 50 $keywords = ""; 51 if($mybb->input['keywords']) 52 { 53 $keywords = "&keywords=".urlencode($mybb->input['keywords']); 54 } 55 56 if($mybb->input['page']) 57 { 58 $url_page = "&page=".intval($mybb->input['page']); 59 } 60 else 61 { 62 $mybb->input['page'] = 1; 63 $url_page = ""; 64 } 65 66 // Gets the major version code. i.e. 1410 -> 1400 or 121 -> 1200 67 if($mybb->version_code >= 1000) 68 { 69 $major_version_code = round($mybb->version_code/100, 0)*100; 70 } 71 else 72 { 73 $major_version_code = round($mybb->version_code/10, 0)*100; 74 } 75 76 $contents = fetch_remote_file("http://mods.mybb.com/xmlbrowse.php?type=mod&version={$major_version_code}{$keywords}{$url_page}", $post_data); 77 78 if(!$contents) 79 { 80 $page->output_inline_error($lang->error_communication_problem); 81 $page->output_footer(); 82 exit; 83 } 84 85 $table = new Table; 86 $table->construct_header($lang->plugin); 87 $table->construct_header($lang->latest_version, array("class" => "align_center", 'width' => 125)); 88 $table->construct_header($lang->controls, array("class" => "align_center", 'width' => 125)); 89 90 $parser = new XMLParser($contents); 91 $tree = $parser->get_tree(); 92 93 if(!is_array($tree) || !isset($tree['results'])) 94 { 95 $page->output_inline_error($lang->error_communication_problem); 96 $page->output_footer(); 97 exit; 98 } 99 100 if(!empty($tree['results']['result'])) 101 { 102 if(array_key_exists("tag", $tree['results']['result'])) 103 { 104 $only_plugin = $tree['results']['result']; 105 unset($tree['results']['result']); 106 $tree['results']['result'][0] = $only_plugin; 107 } 108 109 foreach($tree['results']['result'] as $result) 110 { 111 $table->construct_cell("<strong>{$result['name']['value']}</strong><br /><small>{$result['description']['value']}</small><br /><i><small>{$lang->created_by} {$result['author']['value']}</small></i>"); 112 $table->construct_cell($result['version']['value'], array("class" => "align_center")); 113 $table->construct_cell("<strong><a href=\"http://mods.mybb.com/view/{$result['download_url']['value']}\" target=\"_blank\">{$lang->download}</a></strong>", array("class" => "align_center")); 114 $table->construct_row(); 115 } 116 } 117 118 if($table->num_rows() == 0) 119 { 120 $table->construct_cell($lang->error_no_results_found, array("colspan" => 3)); 121 $table->construct_row(); 122 } 123 124 $search = new Form("index.php?module=config-plugins&action=browse", 'post', 'search_form'); 125 echo "<div style=\"padding-bottom: 3px; margin-top: -9px; text-align: right;\">"; 126 if($mybb->input['keywords']) 127 { 128 $default_class = ''; 129 $value = htmlspecialchars_uni($mybb->input['keywords']); 130 } 131 else 132 { 133 $default_class = "search_default"; 134 $value = $lang->search_for_plugins; 135 } 136 echo $search->generate_text_box('keywords', $value, array('id' => 'search_keywords', 'class' => "{$default_class} field150 field_small"))."\n"; 137 echo "<input type=\"submit\" class=\"search_button\" value=\"{$lang->search}\" />\n"; 138 echo "<script type='text/javascript'> 139 var form = document.getElementById('search_form'); 140 form.onsubmit = function() { 141 var search = document.getElementById('search_keywords'); 142 if(search.value == '' || search.value == '{$lang->search_for_plugins}') 143 { 144 search.focus(); 145 return false; 146 } 147 } 148 149 var search = document.getElementById('search_keywords'); 150 search.onfocus = function() 151 { 152 if(this.value == '{$lang->search_for_plugins}') 153 { 154 $(this).removeClassName('search_default'); 155 this.value = ''; 156 } 157 } 158 search.onblur = function() 159 { 160 if(this.value == '') 161 { 162 $(this).addClassName('search_default'); 163 this.value = '{$lang->search_for_plugins}'; 164 } 165 } 166 // fix the styling used if we have a different default value 167 if(search.value != '{$lang->search_for_plugins}') 168 { 169 $(search).removeClassName('search_default'); 170 } 171 </script>\n"; 172 echo "</div>\n"; 173 echo $search->end(); 174 175 // Recommended plugins = Default; Otherwise search results & pagination 176 if($mybb->request_method == "post") 177 { 178 $table->output("<span style=\"float: right;\"><small><a href=\"http://mods.mybb.com/mods\" target=\"_blank\">{$lang->browse_all_plugins}</a></small></span>".$lang->sprintf($lang->browse_results_for_mybb, $mybb->version)); 179 } 180 else 181 { 182 $table->output("<span style=\"float: right;\"><small><a href=\"http://mods.mybb.com/mods\" target=\"_blank\">{$lang->browse_all_plugins}</a></small></span>".$lang->sprintf($lang->recommended_plugins_for_mybb, $mybb->version)); 183 } 184 185 echo "<br />".draw_admin_pagination($mybb->input['page'], 15, $tree['results']['attributes']['total'], "index.php?module=config-plugins&action=browse{$keywords}&page={page}"); 186 187 $page->output_footer(); 188 } 189 190 if($mybb->input['action'] == "check") 191 { 192 $plugins_list = get_plugins_list(); 193 194 $plugins->run_hooks("admin_config_plugins_check"); 195 196 $info = array(); 197 198 if($plugins_list) 199 { 200 $active_hooks = $plugins->hooks; 201 foreach($plugins_list as $plugin_file) 202 { 203 require_once MYBB_ROOT."inc/plugins/".$plugin_file; 204 $codename = str_replace(".php", "", $plugin_file); 205 $infofunc = $codename."_info"; 206 if(!function_exists($infofunc)) 207 { 208 continue; 209 } 210 $plugininfo = $infofunc(); 211 $plugininfo['guid'] = trim($plugininfo['guid']); 212 213 if($plugininfo['guid'] != "") 214 { 215 $info[] = $plugininfo['guid']; 216 $names[$plugininfo['guid']] = array('name' => $plugininfo['name'], 'version' => $plugininfo['version']); 217 } 218 } 219 $plugins->hooks = $active_hooks; 220 } 221 222 if(empty($info)) 223 { 224 flash_message($lang->error_vcheck_no_supported_plugins, 'error'); 225 admin_redirect("index.php?module=config-plugins"); 226 } 227 228 $url = "http://mods.mybb.com/version_check.php?"; 229 foreach($info as $guid) 230 { 231 $url .= "info[]=".urlencode($guid)."&"; 232 } 233 $url = substr($url, 0, -1); 234 235 require_once MYBB_ROOT."inc/class_xml.php"; 236 $contents = fetch_remote_file($url); 237 238 if(!$contents) 239 { 240 flash_message($lang->error_vcheck_communications_problem, 'error'); 241 admin_redirect("index.php?module=config-plugins"); 242 } 243 244 $parser = new XMLParser($contents); 245 $tree = $parser->get_tree(); 246 247 if(!is_array($tree) || !isset($tree['plugins'])) 248 { 249 $page->output_inline_error($lang->error_communication_problem); 250 $page->output_footer(); 251 exit; 252 } 253 254 if(array_key_exists('error', $tree['plugins'])) 255 { 256 switch($tree['plugins'][0]['error']) 257 { 258 case "1": 259 $error_msg = $lang->error_no_input; 260 break; 261 case "2": 262 $error_msg = $lang->error_no_pids; 263 break; 264 default: 265 $error_msg = ""; 266 } 267 268 flash_message($lang->error_communication_problem.$error_msg, 'error'); 269 admin_redirect("index.php?module=config-plugins"); 270 } 271 272 $table = new Table; 273 $table->construct_header($lang->plugin); 274 $table->construct_header($lang->your_version, array("class" => "align_center", 'width' => 125)); 275 $table->construct_header($lang->latest_version, array("class" => "align_center", 'width' => 125)); 276 $table->construct_header($lang->controls, array("class" => "align_center", 'width' => 125)); 277 278 if(!is_array($tree['plugins']['plugin'])) 279 { 280 flash_message($lang->success_plugins_up_to_date, 'success'); 281 admin_redirect("index.php?module=config-plugins"); 282 } 283 284 if(array_key_exists("tag", $tree['plugins']['plugin'])) 285 { 286 $only_plugin = $tree['plugins']['plugin']; 287 unset($tree['plugins']['plugin']); 288 $tree['plugins']['plugin'][0] = $only_plugin; 289 } 290 291 foreach($tree['plugins']['plugin'] as $plugin) 292 { 293 if(version_compare($names[$plugin['attributes']['guid']]['version'], $plugin['version']['value'], "<")) 294 { 295 $table->construct_cell("<strong>{$names[$plugin['attributes']['guid']]['name']}</strong>"); 296 $table->construct_cell("{$names[$plugin['attributes']['guid']]['version']}", array("class" => "align_center")); 297 $table->construct_cell("<strong><span style=\"color: #C00\">{$plugin['version']['value']}</span></strong>", array("class" => "align_center")); 298 $table->construct_cell("<strong><a href=\"http://mods.mybb.com/view/{$plugin['download_url']['value']}\" target=\"_blank\">{$lang->download}</a></strong>", array("class" => "align_center")); 299 $table->construct_row(); 300 } 301 } 302 303 if($table->num_rows() == 0) 304 { 305 flash_message($lang->success_plugins_up_to_date, 'success'); 306 admin_redirect("index.php?module=config-plugins"); 307 } 308 309 $page->add_breadcrumb_item($lang->plugin_updates); 310 311 $page->output_header($lang->plugin_updates); 312 313 $sub_tabs['plugins'] = array( 314 'title' => $lang->plugins, 315 'link' => "index.php?module=config-plugins", 316 ); 317 318 $sub_tabs['update_plugins'] = array( 319 'title' => $lang->plugin_updates, 320 'link' => "index.php?module=config-plugins&action=check", 321 'description' => $lang->plugin_updates_desc 322 ); 323 324 $sub_tabs['browse_plugins'] = array( 325 'title' => $lang->browse_plugins, 326 'link' => "index.php?module=config-plugins&action=browse", 327 'description' => $lang->browse_plugins_desc 328 ); 329 330 $page->output_nav_tabs($sub_tabs, 'update_plugins'); 331 332 $table->output($lang->plugin_updates); 333 334 $page->output_footer(); 335 } 336 337 // Activates or deactivates a specific plugin 338 if($mybb->input['action'] == "activate" || $mybb->input['action'] == "deactivate") 339 { 340 if(!verify_post_check($mybb->input['my_post_key'])) 341 { 342 flash_message($lang->invalid_post_verify_key2, 'error'); 343 admin_redirect("index.php?module=config-plugins"); 344 } 345 346 if($mybb->input['action'] == "activate") 347 { 348 $plugins->run_hooks("admin_config_plugins_activate"); 349 } 350 else 351 { 352 $plugins->run_hooks("admin_config_plugins_deactivate"); 353 } 354 355 $codename = $mybb->input['plugin']; 356 $codename = str_replace(array(".", "/", "\\"), "", $codename); 357 $file = basename($codename.".php"); 358 359 // Check if the file exists and throw an error if it doesn't 360 if(!file_exists(MYBB_ROOT."inc/plugins/$file")) 361 { 362 flash_message($lang->error_invalid_plugin, 'error'); 363 admin_redirect("index.php?module=config-plugins"); 364 } 365 366 $plugins_cache = $cache->read("plugins"); 367 $active_plugins = $plugins_cache['active']; 368 369 require_once MYBB_ROOT."inc/plugins/$file"; 370 371 $installed_func = "{$codename}_is_installed"; 372 $installed = true; 373 if(function_exists($installed_func) && $installed_func() != true) 374 { 375 $installed = false; 376 } 377 378 $install_uninstall = false; 379 380 if($mybb->input['action'] == "activate") 381 { 382 $message = $lang->success_plugin_activated; 383 384 // Plugin is compatible with this version? 385 if($plugins->is_compatible($codename) == false) 386 { 387 flash_message($lang->sprintf($lang->plugin_incompatible, $mybb->version_code), 'error'); 388 admin_redirect("index.php?module=config-plugins"); 389 } 390 391 // If not installed and there is a custom installation function 392 if($installed == false && function_exists("{$codename}_install")) 393 { 394 call_user_func("{$codename}_install"); 395 $message = $lang->success_plugin_installed; 396 $install_uninstall = true; 397 } 398 399 if(function_exists("{$codename}_activate")) 400 { 401 call_user_func("{$codename}_activate"); 402 } 403 404 $active_plugins[$codename] = $codename; 405 $executed[] = 'activate'; 406 } 407 else if($mybb->input['action'] == "deactivate") 408 { 409 $message = $lang->success_plugin_deactivated; 410 411 if(function_exists("{$codename}_deactivate")) 412 { 413 call_user_func("{$codename}_deactivate"); 414 } 415 416 if($mybb->input['uninstall'] == 1 && function_exists("{$codename}_uninstall")) 417 { 418 call_user_func("{$codename}_uninstall"); 419 $message = $lang->success_plugin_uninstalled; 420 $install_uninstall = true; 421 } 422 423 unset($active_plugins[$codename]); 424 } 425 426 // Update plugin cache 427 $plugins_cache['active'] = $active_plugins; 428 $cache->update("plugins", $plugins_cache); 429 430 // Log admin action 431 log_admin_action($codename, $install_uninstall); 432 433 if($mybb->input['action'] == "activate") 434 { 435 $plugins->run_hooks("admin_config_plugins_activate_commit"); 436 } 437 else 438 { 439 $plugins->run_hooks("admin_config_plugins_deactivate_commit"); 440 } 441 442 flash_message($message, 'success'); 443 admin_redirect("index.php?module=config-plugins"); 444 } 445 446 if(!$mybb->input['action']) 447 { 448 $page->output_header($lang->plugins); 449 450 $sub_tabs['plugins'] = array( 451 'title' => $lang->plugins, 452 'link' => "index.php?module=config-plugins", 453 'description' => $lang->plugins_desc 454 ); 455 $sub_tabs['update_plugins'] = array( 456 'title' => $lang->plugin_updates, 457 'link' => "index.php?module=config-plugins&action=check", 458 'description' => $lang->plugin_updates_desc 459 ); 460 461 $sub_tabs['browse_plugins'] = array( 462 'title' => $lang->browse_plugins, 463 'link' => "index.php?module=config-plugins&action=browse", 464 'description' => $lang->browse_plugins_desc 465 ); 466 467 $page->output_nav_tabs($sub_tabs, 'plugins'); 468 469 $plugins_cache = $cache->read("plugins"); 470 $active_plugins = $plugins_cache['active']; 471 472 $plugins_list = get_plugins_list(); 473 474 $plugins->run_hooks("admin_config_plugins_plugin_list"); 475 476 $table = new Table; 477 $table->construct_header($lang->plugin); 478 $table->construct_header($lang->controls, array("colspan" => 2, "class" => "align_center", "width" => 300)); 479 480 if(!empty($plugins_list)) 481 { 482 foreach($plugins_list as $plugin_file) 483 { 484 require_once MYBB_ROOT."inc/plugins/".$plugin_file; 485 $codename = str_replace(".php", "", $plugin_file); 486 $infofunc = $codename."_info"; 487 if(!function_exists($infofunc)) 488 { 489 continue; 490 } 491 492 $plugininfo = $infofunc(); 493 if($plugininfo['website']) 494 { 495 $plugininfo['name'] = "<a href=\"".$plugininfo['website']."\">".$plugininfo['name']."</a>"; 496 } 497 498 if($plugininfo['authorsite']) 499 { 500 $plugininfo['author'] = "<a href=\"".$plugininfo['authorsite']."\">".$plugininfo['author']."</a>"; 501 } 502 503 if($plugins->is_compatible($codename) == false) 504 { 505 $compatibility_warning = "<span style=\"color: red;\">".$lang->sprintf($lang->plugin_incompatible, $mybb->version)."</span>"; 506 } 507 else 508 { 509 $compatibility_warning = ""; 510 } 511 512 $installed_func = "{$codename}_is_installed"; 513 $install_func = "{$codename}_install"; 514 $uninstall_func = "{$codename}_uninstall"; 515 516 $installed = true; 517 $install_button = false; 518 $uninstall_button = false; 519 520 if(function_exists($installed_func) && $installed_func() != true) 521 { 522 $installed = false; 523 } 524 525 if(function_exists($install_func)) 526 { 527 $install_button = true; 528 } 529 530 if(function_exists($uninstall_func)) 531 { 532 $uninstall_button = true; 533 } 534 535 $table->construct_cell("<strong>{$plugininfo['name']}</strong> ({$plugininfo['version']})<br /><small>{$plugininfo['description']}</small><br /><i><small>{$lang->created_by} {$plugininfo['author']}</small></i>"); 536 537 // Plugin is not installed at all 538 if($installed == false) 539 { 540 if($compatibility_warning) 541 { 542 $table->construct_cell("{$compatibility_warning}", array("class" => "align_center", "colspan" => 2)); 543 } 544 else 545 { 546 $table->construct_cell("<a href=\"index.php?module=config-plugins&action=activate&plugin={$codename}&my_post_key={$mybb->post_code}\">{$lang->install_and_activate}</a>", array("class" => "align_center", "colspan" => 2)); 547 } 548 } 549 // Plugin is activated and installed 550 else if($active_plugins[$codename]) 551 { 552 $table->construct_cell("<a href=\"index.php?module=config-plugins&action=deactivate&plugin={$codename}&my_post_key={$mybb->post_code}\">{$lang->deactivate}</a>", array("class" => "align_center", "width" => 150)); 553 if($uninstall_button) 554 { 555 $table->construct_cell("<a href=\"index.php?module=config-plugins&action=deactivate&uninstall=1&plugin={$codename}&my_post_key={$mybb->post_code}\">{$lang->uninstall}</a>", array("class" => "align_center", "width" => 150)); 556 } 557 else 558 { 559 $table->construct_cell(" ", array("class" => "align_center", "width" => 150)); 560 } 561 } 562 // Plugin is installed but not active 563 else if($installed == true) 564 { 565 $table->construct_cell("<a href=\"index.php?module=config-plugins&action=activate&plugin={$codename}&my_post_key={$mybb->post_code}\">{$lang->activate}</a>", array("class" => "align_center", "width" => 150)); 566 if($uninstall_button) 567 { 568 $table->construct_cell("<a href=\"index.php?module=config-plugins&action=deactivate&uninstall=1&plugin={$codename}&my_post_key={$mybb->post_code}\">{$lang->uninstall}</a>", array("class" => "align_center", "width" => 150)); 569 } 570 else 571 { 572 $table->construct_cell(" ", array("class" => "align_center", "width" => 150)); 573 } 574 } 575 $table->construct_row(); 576 } 577 } 578 579 if($table->num_rows() == 0) 580 { 581 $table->construct_cell($lang->no_plugins, array('colspan' => 3)); 582 $table->construct_row(); 583 } 584 $table->output($lang->plugins); 585 586 $page->output_footer(); 587 } 588 589 function get_plugins_list() 590 { 591 // Get a list of the plugin files which exist in the plugins directory 592 $dir = @opendir(MYBB_ROOT."inc/plugins/"); 593 if($dir) 594 { 595 while($file = readdir($dir)) 596 { 597 $ext = get_extension($file); 598 if($ext == "php") 599 { 600 $plugins_list[] = $file; 601 } 602 } 603 @sort($plugins_list); 604 } 605 @closedir($dir); 606 607 return $plugins_list; 608 } 609 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Oct 8 19:19:50 2013 | Cross-referenced by PHPXref 0.7.1 |