1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927
<?php
namespace hji\membership\controllers;
use \hji\membership\Membership;
use \hji\membership\models\WpCatalog;
class Downloads
{
private $catalog = false;
static $plugins_settings_key = 'hj_plugins_options';
static $themes_settings_key = 'hj_themes_options';
private $plugins = false;
private $themes = false;
function __construct()
{
$this->menuSlug = Membership::$slug . '-downloads';
if (is_admin())
{
add_action('admin_menu', array($this, 'add_menu'));
add_action('admin_init', array($this, 'register_plugins_page'));
add_action('admin_init', array($this, 'register_themes_page'));
add_filter('install_plugins_tabs', array($this, 'install_plugins_tab'));
add_action('install_plugins_pre_hj_plugins', array($this, 'init_hj_plugins_list_table'));
add_action('install_plugins_hj_plugins', array($this, 'display_hj_plugins'));
add_filter('themes_api_result', array($this, 'substitute_theme_api_results'), 12, 3);
add_filter('plugins_api_result', array($this, 'substitute_plugin_api_results'), 12, 3);
add_filter('themes_api', array($this, 'themes_api_before_request'), 12, 3);
add_filter('plugins_api', array($this, 'plugins_api_before_request'), 12, 3);
add_filter('theme_install_actions', array($this, 'theme_install_actions'), 12, 2);
add_filter('plugin_install_action_links', array($this, 'plugin_install_action_links'), 12, 2);
add_filter('install_theme_complete_actions', array($this, 'install_theme_complete_actions'), 12, 4);
add_filter('install_plugin_complete_actions', array($this, 'install_plugin_complete_actions'), 12, 3);
add_filter( 'http_request_host_is_external', array($this, 'allow_wp_catalog_host'), 10, 3 );
}
}
function allow_wp_catalog_host($allow, $host, $url)
{
$staging = parse_url(WpCatalog::STAGING_HOST);
$production = parse_url(WpCatalog::PROD_HOST);
if ($host == $staging['host'] || $host == $production['host'])
{
$allow = true;
}
return $allow;
}
public function add_menu()
{
add_submenu_page(Membership::$slug,
Membership::NAME . ' | Product Library',
'Product Library',
'manage_options',
$this->menuSlug,
array($this, 'add_submenu_page_handler'));
}
public function add_submenu_page_handler()
{
$tab = isset($_GET['tab']) ? $_GET['tab'] : self::$plugins_settings_key;
$_GET['tab'] = $tab;
echo '<div class="wrap">';
if ($this->getPluginsCatalog() || $this->getThemesCatalog())
{
$this->plugin_options_tabs();
}
do_settings_sections($tab);
echo '</div>';
}
function getCatalog()
{
if (!$this->catalog)
{
$this->catalog = WpCatalog::browse();
}
return $this->catalog;
}
function getThemesCatalog()
{
$catalog = $this->getCatalog();
if (!isset($catalog['themes']) || empty($catalog['themes']))
{
return;
}
return $catalog['themes'];
}
function getPluginsCatalog()
{
$catalog = $this->getCatalog();
if (!isset($catalog['plugins']) || empty($catalog['plugins']))
{
return;
}
return $catalog['plugins'];
}
function install_themes_tab($tabs)
{
if (!$this->getThemesCatalog())
{
return $tabs;
}
$newTab = array();
if (isset($_GET['page']) && ($_GET['page'] == $this->menuSlug))
{
$newTab['hj_themes_options'] = __('Home Junction Themes');
}
else
{
$newTab['hj_themes'] = __('Home Junction Themes');
}
return $tabs + $newTab;
}
function install_plugins_tab($tabs)
{
if (!$this->getPluginsCatalog())
{
return $tabs;
}
$newTab = array();
if (isset($_GET['page']) && ($_GET['page'] == $this->menuSlug))
{
$newTab['hj_plugins_options'] = __('Home Junction Plugins');
}
else
{
$newTab['hj_plugins'] = __('Home Junction Plugins');
}
return $tabs + $newTab;
}
function plugin_options_tabs()
{
$current_tab = isset($_GET['tab']) ? $_GET['tab'] : self::$plugins_settings_key;
echo '<div class="hji-membership-icon32 icon32"><br></div>';
echo '<h1>Product Library</h1>';
echo '<h2 class="nav-tab-wrapper">';
foreach ($this->plugin_settings_tabs as $tab_key => $tab_caption)
{
$active = $current_tab == $tab_key ? 'nav-tab-active' : '';
echo '<a class="nav-tab ' . $active . '" href="?page=' . $this->menuSlug . '&tab=' . $tab_key . '">' . $tab_caption . '</a>';
}
echo '</h2>';
}
function register_plugins_page()
{
if ($this->getPluginsCatalog())
{
$this->plugin_settings_tabs[self::$plugins_settings_key] = 'Plugins';
register_setting(self::$plugins_settings_key, self::$plugins_settings_key, array($this, 'validate_settings'));
}
add_settings_section('plugins_page', 'Home Junction Plugins', array($this, 'plugins_page'), self::$plugins_settings_key);
}
function register_themes_page()
{
if (!$this->getThemesCatalog())
{
return;
}
$this->plugin_settings_tabs[self::$themes_settings_key] = 'Themes';
register_setting(self::$themes_settings_key, self::$themes_settings_key, array($this, 'validate_settings'));
add_settings_section('themes_page', 'Home Junction Themes', array($this, 'themes_page'), self::$themes_settings_key);
}
public function validate_settings()
{
}
public function themes_page()
{
$tab = 'hj_themes';
$paged = true;
require(Membership::$dir . '/classes/views/theme-install.phtml');
}
public function plugins_page()
{
if (!$this->getPluginsCatalog())
{
if (!Membership::getInstance()->isLicensed())
{
echo '<p>Please make sure your Membership license key is correct and authorized by Home Junction.</p>';
}
else
{
echo '<p>There are no products available for this License. Please contact customer support for details by email ' . Membership::SUPPORT_EMAIL . ' or call ' . Membership::SUPPORT_PHONE . '.</p>';
}
return;
}
wp_enqueue_script('plugin-install');
add_thickbox();
$this->init_hj_plugins_list_table();
$this->display_hj_plugins();
}
public function get_plugins()
{
if (!$plugins = $this->getPluginsCatalog())
{
return;
}
$object_array = array();
foreach ($plugins as $plugin)
{
$ct = new \stdClass;
$ct->name = $plugin['name'];
$ct->slug = @$plugin['slug'];
$ct->version = $plugin['version'];
$ct->author = (isset($plugin['author'])) ? $plugin['author'] : 'Home Junction';
$ct->author_profile = '';
$ct->requires = (isset($plugin['requires'])) ? $plugin['requires'] : '3.6';
$ct->tested = (isset($plugin['tested'])) ? $plugin['tested'] : '3.6';
$ct->rating = (isset($plugin['rating'])) ? $plugin['rating'] : 0;
$ct->num_ratings = (isset($plugin['num_ratings'])) ? $plugin['num_ratings'] : 0;
$ct->homepage = 'http://homejunction.com';
$ct->description = @$plugin['sections']['description'];
$ct->short_description = (isset($plugin['short_description'])) ? $plugin['short_description'] : @$plugin['sections']['description'];
$ct->download_link = $plugin['download_url'];
$ct->sections = @$plugin['sections'];
$ct->icons['default'] = (@$plugin['icons']['default']) ? $plugin['icons']['default'] : Membership::$url . '/resources/images/hji-plugin-thumb.png';
$ct->last_updated = (isset($plugin['last_updated'])) ? date('Y-m-d', $plugin['last_updated']) : null;
$ct->downloaded = null;
$ct->active_installs = null;
$object_array[] = $ct;
}
return $object_array;
}
public function get_themes()
{
$theme_screenshot = Membership::$url . '/resources/images/screenshot.png';
$theme_description = 'Home Junction real estate theme for WordPress.';
if (!$themes = $this->getThemesCatalog())
{
return;
}
$object_array = array();
foreach ($themes as $theme)
{
$ct = new \stdClass;
$ct->isHJITheme = true;
$ct->name = $theme['name'];
$ct->slug = @$theme['slug'];
$ct->version = $theme['version'];
$ct->author = (isset($theme['author'])) ? $theme['author'] : 'Home Junction Inc';
$ct->preview_url = (@$theme['preview_url']) ? $theme['preview_url'] : 'http://ridx3.hjstaging.com/';
$ct->screenshot_url = (isset($theme['screenshot'])) ? $theme['screenshot'] : $theme_screenshot;
$ct->homepage = 'http://homejunction.com';
$ct->description = @$theme['description'];
$ct->download_link = $theme['download_url'];
$ct->rating = 0;
$ct->num_ratings = 0;
$ct->last_updated = (isset($plugin['last_updated'])) ? date('Y-m-d', $plugin['last_updated']) : null;
$object_array[] = $ct;
}
return $object_array;
}
function get_theme($slug)
{
$themes = $this->get_themes();
foreach ($themes as $theme)
{
if ($slug == $theme->slug)
{
return $theme;
}
}
return NULL;
}
function get_plugin($slug)
{
$plugins = $this->get_plugins();
foreach ($plugins as $plugin)
{
if ($slug == $plugin->slug)
{
return $plugin;
}
}
return NULL;
}
function display_hj_themes()
{
$this->hj_themes_list_table->display();
}
function display_hj_plugins()
{
$this->hj_plugins_list_table->display();
}
function themes_api_before_request($x, $action, $args)
{
if ($action == 'theme_information')
{
if ($themes = $this->get_themes())
{
foreach ($themes as $theme)
{
if ($theme->slug == $args->slug)
{
$args->isHJTheme = true;
return $args;
}
}
}
}
return false;
}
function plugins_api_before_request($x, $action, $args)
{
if ((isset($_GET['tab']) && ('hj_plugins' == $_GET['tab'] || 'hj_plugins_options' == $_GET['tab']))
|| isset($_GET['isHJPlugin']))
{
$args->isHJPlugin = true;
return $args;
}
return false;
}
function substitute_theme_api_results($res, $action, $args)
{
if (($action == 'query_themes'
&& isset($_REQUEST['request']['browse'])
&& $_REQUEST['request']['browse'] == 'hj_themes') ||
@$args->isHJTheme == true)
{
if (isset($args->slug))
{
return $this->get_theme($args->slug);
}
$result = new \stdClass();
if (!isset($_REQUEST['request']['page']) ||
$_REQUEST['request']['page'] == 1)
{
$result->themes = $this->get_themes();
}
else
{
$result->themes = array();
}
$result->info = array
(
'page' => 1,
'pages' => 1,
'results' => count($result->themes)
);
return $result;
}
return $res;
}
function substitute_plugin_api_results($res, $action, $args)
{
if (is_object($args) && property_exists($args, 'isHJPlugin') && ($args->isHJPlugin == 'hj_plugins'))
{
if (isset($args->slug))
{
return $this->get_plugin($args->slug);
}
$result = new \stdClass();
$result->plugins = $this->get_plugins();
$result->info = array
(
'results' => count($result->plugins)
);
return $result;
}
return $res;
}
function theme_install_actions($actions, $themes)
{
if (($_GET['tab'] != 'hj_themes') && ($_GET['tab'] != 'hj_themes_options'))
{
return $actions;
}
foreach ($actions as $i => $html_link)
{
if (stristr($html_link, 'theme-information') && !stristr($html_link, 'isHJTheme'))
{
$actions[$i] = str_replace('theme-information', 'theme-information&isHJTheme=1', $html_link);
}
}
foreach ($actions as $i => $html_link)
{
if (stristr($html_link, 'install-theme') && !stristr($html_link, 'isHJTheme'))
{
$actions[$i] = str_replace('install-theme', 'install-theme&isHJTheme=1', $html_link);
}
}
return $actions;
}
function plugin_install_action_links($action_links, $plugin)
{
if (!isset($_GET['tab']) ||
(isset($_GET['tab']) && ($_GET['tab'] != 'hj_plugins') && ($_GET['tab'] != 'hj_plugins_options')))
{
return $action_links;
}
foreach ($action_links as $i => $html_link)
{
if (stristr($html_link, 'plugin-information') && !stristr($html_link, 'isHJPlugin'))
{
$action_links[$i] = str_replace('plugin-information', 'plugin-information&isHJPlugin=1', $html_link);
}
}
foreach ($action_links as $i => $html_link)
{
if (stristr($html_link, 'install-plugin') && !stristr($html_link, 'isHJPlugin'))
{
$action_links[$i] = str_replace('install-plugin', 'install-plugin&isHJPlugin=1', $html_link);
}
}
return $action_links;
}
function install_theme_complete_actions($install_actions, $api, $stylesheet, $theme_info)
{
if (isset($install_actions['themes_page']) && isset($_GET['isHJTheme']))
{
$install_actions['themes_page'] = '<a href="' . admin_url('admin.php?page=hji-membership-downloads&tab=hj_themes_options') .
'" target="_parent">Return to Home Junction Themes</a>';
}
return $install_actions;
}
function install_plugin_complete_actions($install_actions, $api, $plugin_file)
{
if (isset($install_actions['plugins_page']) && isset($_GET['isHJPlugin']))
{
$install_actions['plugins_page'] = '<a href="' . admin_url('admin.php?page=hji-membership-downloads') .
'" target="_parent">Return to Home Junction Plugins</a>';
}
return $install_actions;
}
function init_hj_themes_list_table()
{
_get_list_table('WP_Theme_Install_List_Table');
__inject_theme_table();
$this->hj_themes_list_table = new Theme_Install_List_Table(array('themes', 'theme-install'));
$this->pagenum = $this->hj_themes_list_table->get_pagenum();
$this->hj_themes_list_table->prepare_items();
}
function init_hj_plugins_list_table()
{
_get_list_table('WP_Plugin_Install_List_Table');
__inject_plugin_table();
$screen = get_current_screen();
$this->hj_plugins_list_table = new Plugin_Install_List_Table($screen->id);
$this->pagenum = $this->hj_plugins_list_table->get_pagenum();
$this->hj_plugins_list_table->prepare_items();
}
}
function __inject_theme_table()
{
class Theme_Install_List_Table extends \WP_Theme_Install_List_Table
{
function prepare_items()
{
global $tabs, $tab, $paged, $type, $theme_field_defaults;
wp_reset_vars(array('tab'));
$search_terms = array();
$search_string = '';
if (! empty($_REQUEST['s'])){
$search_string = strtolower(wp_unslash($_REQUEST['s']));
$search_terms = array_unique(array_filter(array_map('trim', explode(',', $search_string))));
}
if (! empty($_REQUEST['features']))
$this->features = $_REQUEST['features'];
$paged = $this->get_pagenum();
$per_page = 36;
$tabs = array();
$tabs['dashboard'] = __('Search');
if ('search' == $tab)
$tabs['search'] = __('Search Results');
$tabs['upload'] = __('Upload');
$tabs['featured'] = _x('Featured','Theme Installer');
$tabs['new'] = _x('Newest','Theme Installer');
$tabs['updated'] = _x('Recently Updated','Theme Installer');
$nonmenu_tabs = array('theme-information');
$tabs = apply_filters('install_themes_tabs', $tabs);
$nonmenu_tabs = apply_filters('install_themes_nonmenu_tabs', $nonmenu_tabs);
if (empty($tab) || (! isset($tabs[ $tab ]) && ! in_array($tab, (array) $nonmenu_tabs)))
$tab = key($tabs);
$args = array('page' => $paged, 'per_page' => $per_page, 'fields' => $theme_field_defaults);
switch ($tab)
{
case 'search':
$type = isset($_REQUEST['type']) ? wp_unslash($_REQUEST['type']) : 'term';
switch ($type)
{
case 'tag':
$args['tag'] = array_map('sanitize_key', $search_terms);
break;
case 'term':
$args['search'] = $search_string;
break;
case 'author':
$args['author'] = $search_string;
break;
}
if (! empty($this->features))
{
$args['tag'] = $this->features;
$_REQUEST['s'] = implode(',', $this->features);
$_REQUEST['type'] = 'tag';
}
add_action('install_themes_table_header', 'install_theme_search_form', 10, 0);
break;
case 'hj_themes':
case 'hj_themes_options':
case 'featured':
case 'new':
case 'updated':
$args['browse'] = $tab;
break;
default:
$args = false;
}
if (! $args)
return;
$api = themes_api('query_themes', $args);
if (is_wp_error($api))
wp_die($api->get_error_message() . '</p> <p><a href="#" onclick="document.location.reload(); return false;">' . __('Try again') . '</a>');
$this->items = $api->themes;
$this->set_pagination_args(array(
'total_items' => $api->info['results'],
'per_page' => $per_page,
'infinite_scroll' => true,
));
}
function single_row($theme)
{
global $themes_allowedtags;
if (empty($theme))
{
return;
}
$name = wp_kses($theme->name, $themes_allowedtags);
$author = wp_kses($theme->author, $themes_allowedtags);
$preview_title = sprintf(__('Preview “%s”'), $name);
$preview_url = add_query_arg(array(
'tab' => 'theme-information',
'theme' => $theme->slug,
));
$actions = array();
$install_url = add_query_arg(array(
'action' => 'install-theme',
'theme' => $theme->slug,
), self_admin_url('update.php'));
$update_url = add_query_arg(array(
'action' => 'upgrade-theme',
'theme' => $theme->slug,
), self_admin_url('update.php'));
$status = $this->_get_theme_status($theme);
switch ($status)
{
default:
case 'install':
$actions[] = '<a class="install-now" href="' . esc_url(wp_nonce_url($install_url, 'install-theme_' . $theme->slug)) . '" title="' . esc_attr(sprintf(__('Install %s'), $name)) . '">' . __('Install Now') . '</a>';
break;
case 'update_available':
$actions[] = '<a class="install-now" href="' . esc_url(wp_nonce_url($update_url, 'upgrade-theme_' . $theme->slug)) . '" title="' . esc_attr(sprintf(__('Update to version %s'), $theme->version)) . '">' . __('Update') . '</a>';
break;
case 'newer_installed':
case 'latest_installed':
$actions[] = '<span class="install-now" title="' . esc_attr__('This theme is already installed and is up to date') . '">' . _x('Installed', 'theme') . '</span>';
break;
}
$actions[] = '<a class="install-theme-preview" href="' . esc_url($preview_url) . '" title="' . esc_attr(sprintf(__('Preview %s'), $name)) . '">' . __('Preview') . '</a>';
$actions = apply_filters('theme_install_actions', $actions, $theme);
?>
<a class="screenshot install-theme-preview" href="<?php echo esc_url($preview_url); ?>" title="<?php echo esc_attr($preview_title); ?>">
<img src='<?php echo esc_url($theme->screenshot_url); ?>' width='150' />
</a>
<h3><?php echo $name; ?></h3>
<div class="theme-author"><?php printf(__('By %s'), $author); ?></div>
<div class="action-links">
<ul>
<?php foreach ($actions as $action): ?>
<li><?php echo $action; ?></li>
<?php endforeach; ?>
<li class="hide-if-no-js"><a href="#" class="theme-detail"><?php _e('Details') ?></a></li>
</ul>
</div>
<?php
$this->install_theme_info($theme);
}
private function _get_theme_status($theme)
{
$status = 'install';
$installed_theme = wp_get_theme($theme->slug);
if ($installed_theme->exists())
{
if (version_compare($installed_theme->get('Version'), $theme->version, '='))
$status = 'latest_installed';
elseif (version_compare($installed_theme->get('Version'), $theme->version, '>'))
$status = 'newer_installed';
else
$status = 'update_available';
}
return $status;
}
}
}
function __inject_plugin_table()
{
class Plugin_Install_List_Table extends \WP_Plugin_Install_List_Table
{
function prepare_items()
{
if(isset($_GET['tab']) && $_GET['tab'] == 'hj_plugins_options')
include(ABSPATH . 'wp-admin/includes/plugin-install.php');
global $tabs, $tab, $paged, $type, $term;
wp_reset_vars(array('tab'));
$paged = $this->get_pagenum();
$per_page = 30;
$tabs = array();
$tabs['dashboard'] = __('Search');
if ('search' == $tab)
$tabs['search'] = __('Search Results');
$tabs['upload'] = __('Upload');
$tabs['featured'] = _x('Featured', 'Plugin Installer');
$tabs['popular'] = _x('Popular', 'Plugin Installer');
$tabs['new'] = _x('Newest', 'Plugin Installer');
$tabs['favorites'] = _x('Favorites', 'Plugin Installer');
$nonmenu_tabs = array('plugin-information');
$tabs = apply_filters('install_plugins_tabs', $tabs);
$nonmenu_tabs = apply_filters('install_plugins_nonmenu_tabs', $nonmenu_tabs);
if (empty($tab) || (!isset($tabs[ $tab ]) && !in_array($tab, (array) $nonmenu_tabs)))
$tab = key($tabs);
$args = array('page' => $paged, 'per_page' => $per_page);
switch ($tab)
{
case 'search':
$type = isset($_REQUEST['type']) ? wp_unslash($_REQUEST['type']) : 'term';
$term = isset($_REQUEST['s']) ? wp_unslash($_REQUEST['s']) : '';
switch ($type)
{
case 'tag':
$args['tag'] = sanitize_title_with_dashes($term);
break;
case 'term':
$args['search'] = $term;
break;
case 'author':
$args['author'] = $term;
break;
}
add_action('install_plugins_table_header', 'install_search_form', 10, 0);
break;
case 'hj_plugins':
case 'hj_plugins_options':
case 'featured':
case 'popular':
case 'new':
$args['browse'] = $tab;
break;
case 'favorites':
$user = isset($_GET['user']) ? wp_unslash($_GET['user']) : get_user_option('wporg_favorites');
update_user_meta(get_current_user_id(), 'wporg_favorites', $user);
if ($user)
$args['user'] = $user;
else
$args = false;
add_action('install_plugins_favorites', 'install_plugins_favorites_form', 9, 0);
break;
default:
$args = false;
}
if (!$args)
return;
$api = plugins_api('query_plugins', $args);
if (is_wp_error($api))
wp_die($api->get_error_message() . '</p> <p class="hide-if-no-js"><a href="#" onclick="document.location.reload(); return false;">' . __('Try again') . '</a>');
$this->items = $api->plugins;
$this->set_pagination_args(array(
'total_items' => $api->info['results'],
'per_page' => $per_page,
));
}
function get_column_info()
{
return array(
array(
'name' => 'Name',
'version' => 'Version',
'rating' => 'Rating',
'description' => 'Description'
),
array(),
array()
);
}
}
}