| [ Index ] |
PHP Cross Reference of MyBB 1.6.5 |
[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: plugins.php 5404 2011-03-19 01:17:10Z jammerx2 $ 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(!array_key_exists("results", $tree)) 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(array_key_exists('error', $tree['plugins'])) 248 { 249 switch($tree['plugins'][0]['error']) 250 { 251 case "1": 252 $error_msg = $lang->error_no_input; 253 break; 254 case "2": 255 $error_msg = $lang->error_no_pids; 256 break; 257 default: 258 $error_msg = ""; 259 } 260 261 flash_message($lang->error_communication_problem.$error_msg, 'error'); 262 admin_redirect("index.php?module=config-plugins"); 263 } 264 265 $table = new Table; 266 $table->construct_header($lang->plugin); 267 $table->construct_header($lang->your_version, array("class" => "align_center", 'width' => 125)); 268 $table->construct_header($lang->latest_version, array("class" => "align_center", 'width' => 125)); 269 $table->construct_header($lang->controls, array("class" => "align_center", 'width' => 125)); 270 271 if(!is_array($tree['plugins']['plugin'])) 272 { 273 flash_message($lang->success_plugins_up_to_date, 'success'); 274 admin_redirect("index.php?module=config-plugins"); 275 } 276 277 if(array_key_exists("tag", $tree['plugins']['plugin'])) 278 { 279 $only_plugin = $tree['plugins']['plugin']; 280 unset($tree['plugins']['plugin']); 281 $tree['plugins']['plugin'][0] = $only_plugin; 282 } 283 284 foreach($tree['plugins']['plugin'] as $plugin) 285 { 286 if(version_compare($names[$plugin['attributes']['guid']]['version'], $plugin['version']['value'], "<")) 287 { 288 $table->construct_cell("<strong>{$names[$plugin['attributes']['guid']]['name']}</strong>"); 289 $table->construct_cell("{$names[$plugin['attributes']['guid']]['version']}", array("class" => "align_center")); 290 $table->construct_cell("<strong><span style=\"color: #C00\">{$plugin['version']['value']}</span></strong>", array("class" => "align_center")); 291 $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")); 292 $table->construct_row(); 293 } 294 } 295 296 if($table->num_rows() == 0) 297 { 298 flash_message($lang->success_plugins_up_to_date, 'success'); 299 admin_redirect("index.php?module=config-plugins"); 300 } 301 302 $page->add_breadcrumb_item($lang->plugin_updates); 303 304 $page->output_header($lang->plugin_updates); 305 306 $sub_tabs['plugins'] = array( 307 'title' => $lang->plugins, 308 'link' => "index.php?module=config-plugins", 309 ); 310 311 $sub_tabs['update_plugins'] = array( 312 'title' => $lang->plugin_updates, 313 'link' => "index.php?module=config-plugins&action=check", 314 'description' => $lang->plugin_updates_desc 315 ); 316 317 $sub_tabs['browse_plugins'] = array( 318 'title' => $lang->browse_plugins, 319 'link' => "index.php?module=config-plugins&action=browse", 320 'description' => $lang->browse_plugins_desc 321 ); 322 323 $page->output_nav_tabs($sub_tabs, 'update_plugins'); 324 325 $table->output($lang->plugin_updates); 326 327 $page->output_footer(); 328 } 329 330 // Activates or deactivates a specific plugin 331 if($mybb->input['action'] == "activate" || $mybb->input['action'] == "deactivate") 332 { 333 if(!verify_post_check($mybb->input['my_post_key'])) 334 { 335 flash_message($lang->invalid_post_verify_key2, 'error'); 336 admin_redirect("index.php?module=config-plugins"); 337 } 338 339 if($mybb->input['action'] == "activate") 340 { 341 $plugins->run_hooks("admin_config_plugins_activate"); 342 } 343 else 344 { 345 $plugins->run_hooks("admin_config_plugins_deactivate"); 346 } 347 348 $codename = $mybb->input['plugin']; 349 $codename = str_replace(array(".", "/", "\\"), "", $codename); 350 $file = basename($codename.".php"); 351 352 // Check if the file exists and throw an error if it doesn't 353 if(!file_exists(MYBB_ROOT."inc/plugins/$file")) 354 { 355 flash_message($lang->error_invalid_plugin, 'error'); 356 admin_redirect("index.php?module=config-plugins"); 357 } 358 359 $plugins_cache = $cache->read("plugins"); 360 $active_plugins = $plugins_cache['active']; 361 362 require_once MYBB_ROOT."inc/plugins/$file"; 363 364 $installed_func = "{$codename}_is_installed"; 365 $installed = true; 366 if(function_exists($installed_func) && $installed_func() != true) 367 { 368 $installed = false; 369 } 370 371 $install_uninstall = false; 372 373 if($mybb->input['action'] == "activate") 374 { 375 $message = $lang->success_plugin_activated; 376 377 // Plugin is compatible with this version? 378 if($plugins->is_compatible($codename) == false) 379 { 380 flash_message($lang->sprintf($lang->plugin_incompatible, $mybb->version_code), 'error'); 381 admin_redirect("index.php?module=config-plugins"); 382 } 383 384 // If not installed and there is a custom installation function 385 if($installed == false && function_exists("{$codename}_install")) 386 { 387 call_user_func("{$codename}_install"); 388 $message = $lang->success_plugin_installed; 389 $install_uninstall = true; 390 } 391 392 if(function_exists("{$codename}_activate")) 393 { 394 call_user_func("{$codename}_activate"); 395 } 396 397 $active_plugins[$codename] = $codename; 398 $executed[] = 'activate'; 399 } 400 else if($mybb->input['action'] == "deactivate") 401 { 402 $message = $lang->success_plugin_deactivated; 403 404 if(function_exists("{$codename}_deactivate")) 405 { 406 call_user_func("{$codename}_deactivate"); 407 } 408 409 if($mybb->input['uninstall'] == 1 && function_exists("{$codename}_uninstall")) 410 { 411 call_user_func("{$codename}_uninstall"); 412 $message = $lang->success_plugin_uninstalled; 413 $install_uninstall = true; 414 } 415 416 unset($active_plugins[$codename]); 417 } 418 419 // Update plugin cache 420 $plugins_cache['active'] = $active_plugins; 421 $cache->update("plugins", $plugins_cache); 422 423 // Log admin action 424 log_admin_action($codename, $install_uninstall); 425 426 if($mybb->input['action'] == "activate") 427 { 428 $plugins->run_hooks("admin_config_plugins_activate_commit"); 429 } 430 else 431 { 432 $plugins->run_hooks("admin_config_plugins_deactivate_commit"); 433 } 434 435 flash_message($message, 'success'); 436 admin_redirect("index.php?module=config-plugins"); 437 } 438 439 if(!$mybb->input['action']) 440 { 441 $page->output_header($lang->plugins); 442 443 $sub_tabs['plugins'] = array( 444 'title' => $lang->plugins, 445 'link' => "index.php?module=config-plugins", 446 'description' => $lang->plugins_desc 447 ); 448 $sub_tabs['update_plugins'] = array( 449 'title' => $lang->plugin_updates, 450 'link' => "index.php?module=config-plugins&action=check", 451 'description' => $lang->plugin_updates_desc 452 ); 453 454 $sub_tabs['browse_plugins'] = array( 455 'title' => $lang->browse_plugins, 456 'link' => "index.php?module=config-plugins&action=browse", 457 'description' => $lang->browse_plugins_desc 458 ); 459 460 $page->output_nav_tabs($sub_tabs, 'plugins'); 461 462 $plugins_cache = $cache->read("plugins"); 463 $active_plugins = $plugins_cache['active']; 464 465 $plugins_list = get_plugins_list(); 466 467 $plugins->run_hooks("admin_config_plugins_plugin_list"); 468 469 $table = new Table; 470 $table->construct_header($lang->plugin); 471 $table->construct_header($lang->controls, array("colspan" => 2, "class" => "align_center", "width" => 300)); 472 473 if(!empty($plugins_list)) 474 { 475 foreach($plugins_list as $plugin_file) 476 { 477 require_once MYBB_ROOT."inc/plugins/".$plugin_file; 478 $codename = str_replace(".php", "", $plugin_file); 479 $infofunc = $codename."_info"; 480 if(!function_exists($infofunc)) 481 { 482 continue; 483 } 484 485 $plugininfo = $infofunc(); 486 if($plugininfo['website']) 487 { 488 $plugininfo['name'] = "<a href=\"".$plugininfo['website']."\">".$plugininfo['name']."</a>"; 489 } 490 491 if($plugininfo['authorsite']) 492 { 493 $plugininfo['author'] = "<a href=\"".$plugininfo['authorsite']."\">".$plugininfo['author']."</a>"; 494 } 495 496 if($plugins->is_compatible($codename) == false) 497 { 498 $compatibility_warning = "<span style=\"color: red;\">".$lang->sprintf($lang->plugin_incompatible, $mybb->version)."</span>"; 499 } 500 else 501 { 502 $compatibility_warning = ""; 503 } 504 505 $installed_func = "{$codename}_is_installed"; 506 $install_func = "{$codename}_install"; 507 $uninstall_func = "{$codename}_uninstall"; 508 509 $installed = true; 510 $install_button = false; 511 $uninstall_button = false; 512 513 if(function_exists($installed_func) && $installed_func() != true) 514 { 515 $installed = false; 516 } 517 518 if(function_exists($install_func)) 519 { 520 $install_button = true; 521 } 522 523 if(function_exists($uninstall_func)) 524 { 525 $uninstall_button = true; 526 } 527 528 $table->construct_cell("<strong>{$plugininfo['name']}</strong> ({$plugininfo['version']})<br /><small>{$plugininfo['description']}</small><br /><i><small>{$lang->created_by} {$plugininfo['author']}</small></i>"); 529 530 // Plugin is not installed at all 531 if($installed == false) 532 { 533 if($compatibility_warning) 534 { 535 $table->construct_cell("{$compatibility_warning}", array("class" => "align_center", "colspan" => 2)); 536 } 537 else 538 { 539 $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)); 540 } 541 } 542 // Plugin is activated and installed 543 else if($active_plugins[$codename]) 544 { 545 $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)); 546 if($uninstall_button) 547 { 548 $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)); 549 } 550 else 551 { 552 $table->construct_cell(" ", array("class" => "align_center", "width" => 150)); 553 } 554 } 555 // Plugin is installed but not active 556 else if($installed == true) 557 { 558 $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)); 559 if($uninstall_button) 560 { 561 $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)); 562 } 563 else 564 { 565 $table->construct_cell(" ", array("class" => "align_center", "width" => 150)); 566 } 567 } 568 $table->construct_row(); 569 } 570 } 571 572 if($table->num_rows() == 0) 573 { 574 $table->construct_cell($lang->no_plugins, array('colspan' => 3)); 575 $table->construct_row(); 576 } 577 $table->output($lang->plugins); 578 579 $page->output_footer(); 580 } 581 582 function get_plugins_list() 583 { 584 // Get a list of the plugin files which exist in the plugins directory 585 $dir = @opendir(MYBB_ROOT."inc/plugins/"); 586 if($dir) 587 { 588 while($file = readdir($dir)) 589 { 590 $ext = get_extension($file); 591 if($ext == "php") 592 { 593 $plugins_list[] = $file; 594 } 595 } 596 @sort($plugins_list); 597 } 598 @closedir($dir); 599 600 return $plugins_list; 601 } 602 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sun Dec 11 14:16:27 2011 | Cross-referenced by PHPXref 0.7.1 |