Overview

Packages

  • ACF
  • Automation
    • Actions
    • Activation
    • LeadProfile
    • Menus
    • Queries
    • Rules
    • Triggers
  • CTA
    • Activation
    • AJAXListeners
    • Cloning
    • Core
    • Display
    • EditPage
    • Enqueues
    • GPLSettings
    • LeadsProfile
    • Loading
    • Menus
    • Notices
    • PlacementMetabox
    • PostType
    • Templates
    • Tracking
    • Variations
    • YOAST
  • InboundPro
    • Activation
    • AdminAJAX
    • AutoLoading
    • Cron
    • DataInterface
    • FieldMapping
    • Funnels
    • InboundNowAPI
    • Installer
    • LeadStatuses
    • Menus
    • Notifications
    • Ouath
    • Reports
    • Settings
    • Tracking
    • Translations
    • Updates
  • LandingPages
    • Activation
    • DataInterfaces
    • Management
    • Menus
    • NeedsAttention
    • Notices
    • Sidebars
    • Templates
    • Tracking
    • Variations
    • WelcomeScreen
    • Widgets
  • Leads
    • Activation
    • Akismet
    • BranchControl
    • BulkActions
    • Dashboard
    • Management
    • Notifications
    • Settings
    • Tracking
    • UserProfile
    • WPLogin
  • Mailer
    • Activation
    • Admin
    • ClickTracking
    • DataInterface
    • InboundForms
    • Leads
    • Management
    • Notifications
    • Scheduling
    • Sending
    • Settings
    • ShortcodesAndTokens
    • SparkPost
    • Templates
    • Unsubscribes
    • Variations
    • YoastSEO
  • None
  • Shared
    • APIs
    • CPT
    • DatabaseRoutines
    • DebugTricks
    • DoubleOptin
    • EventManagement
    • FieldMapping
    • InboundForms
    • LeadSorage
    • MarketingButton
    • Menus
    • Notifications
    • Shortcodes
    • ShortcodesAndTokens
    • StandAloneLicensing
    • Tracking
    • VisualEditor
  • xDepreciated

Classes

  • CTA_Activation
  • CTA_Activation_Update_Routines
  • CTA_Admin_Notices
  • CTA_Ajax_Listeners
  • CTA_Clone_Post
  • CTA_Conversion_Tracking
  • CTA_Dynamic_Widget
  • CTA_Enqueues
  • CTA_Load_Extensions
  • CTA_Menus
  • CTA_Metaboxes
  • CTA_Metaboxes_Global
  • CTA_Post_Type
  • CTA_Render
  • CTA_Settings
  • CTA_Static_Widget
  • CTA_Template_Manager
  • CTA_Template_Manager_List
  • CTA_Variations
  • CTA_WordPress_Leads
  • CTA_WordPress_SEO
  • Inbound_Ajax
  • Inbound_Akismet
  • Inbound_Analytics
  • Inbound_API
  • Inbound_API_Keys_Generation
  • Inbound_API_Keys_Table
  • Inbound_API_Wrapper
  • Inbound_Asset_Loader
  • Inbound_Automation_Action_Add_Remove_List
  • Inbound_Automation_Action_Add_Remove_Tag
  • Inbound_Automation_Action_Create_Lead
  • Inbound_Automation_Action_Create_User
  • Inbound_Automation_Action_Kill_Tasks
  • Inbound_Automation_Action_Relay_Data
  • Inbound_Automation_Action_Send_Email
  • Inbound_Automation_Action_Wait
  • Inbound_Automation_Activation
  • Inbound_Automation_Activation_Update_Routines
  • Inbound_Automation_Adminbar
  • Inbound_Automation_Lead_Profile
  • Inbound_Automation_Loader
  • Inbound_Automation_Plugin
  • Inbound_Automation_Post_Type
  • Inbound_Automation_Processing
  • Inbound_Automation_Query_Lead
  • Inbound_Automation_Query_User
  • Inbound_Automation_Trigger_inbound_double_optin_confirm
  • Inbound_Automation_Trigger_inbound_store_lead_post
  • Inbound_Automation_Trigger_inbound_track_link
  • Inbound_Automation_Trigger_Publish_Post
  • Inbound_Automation_Trigger_Save_Post_Deactivated
  • Inbound_Automation_Trigger_Set_Object_Terms
  • Inbound_Automation_Trigger_Update_Lead
  • Inbound_Automation_Trigger_User_Register
  • Inbound_Calls_To_Action_Plugin
  • Inbound_Confirm_Double_Optin
  • Inbound_Cron
  • Inbound_CTA_Quick_View
  • Inbound_Customizer
  • Inbound_Debug_Scripts
  • Inbound_Email_Meta
  • Inbound_Email_Preview
  • Inbound_Email_Template_Shortcodes
  • Inbound_Event_Report
  • Inbound_Events
  • Inbound_Events_Report
  • Inbound_Extension_Loads
  • Inbound_Forms
  • Inbound_Funnel_Reporting
  • Inbound_Impressions_Report
  • Inbound_Landing_Pages_Plugin
  • Inbound_Lead_Statuses
  • Inbound_Leads
  • Inbound_Leads_Custom_fields
  • Inbound_Leads_Plugin
  • Inbound_License
  • Inbound_List_Double_Optin
  • Inbound_Load_Shared
  • Inbound_Logging_Automation
  • Inbound_Login
  • Inbound_Mail_Daemon
  • Inbound_Mailer_ACF
  • Inbound_Mailer_Activation
  • Inbound_Mailer_Activation_Update_Routines
  • Inbound_Mailer_Ajax_Listeners
  • Inbound_Mailer_Clone_Post
  • Inbound_Mailer_Common_Settings
  • Inbound_Mailer_Customizer
  • Inbound_Mailer_Direct_Email_Leads
  • Inbound_Mailer_Enqueues
  • Inbound_Mailer_Forms_Integration
  • Inbound_Mailer_Load_Templates
  • Inbound_Mailer_Menus
  • Inbound_Mailer_Metaboxes
  • Inbound_Mailer_Notifications
  • Inbound_Mailer_Plugin
  • Inbound_Mailer_Post_Type
  • Inbound_Mailer_Scheduling
  • Inbound_Mailer_Settings
  • Inbound_Mailer_SparkPost
  • Inbound_Mailer_Stats_Report
  • Inbound_Mailer_Template_Manager
  • Inbound_Mailer_Template_Manager_List
  • Inbound_Mailer_Tokens
  • Inbound_Mailer_Tracking
  • Inbound_Mailer_Unsubscribe
  • Inbound_Mailer_Variations
  • Inbound_Mailer_WordPress_SEO
  • Inbound_Maintenance_Lists
  • Inbound_Marketing_Button
  • Inbound_Menus_Admin
  • Inbound_Menus_Adminbar
  • Inbound_Metaboxes_Automation
  • Inbound_Metaboxes_Leads
  • Inbound_Notifications
  • Inbound_Now_Store
  • Inbound_Options_API
  • Inbound_Pro_Activation
  • Inbound_Pro_Admin_Ajax_Listeners
  • Inbound_Pro_Automatic_Updates
  • Inbound_Pro_Downloads
  • Inbound_Pro_Notifications
  • Inbound_Pro_Oauth_Engine
  • Inbound_Pro_Plugin
  • Inbound_Pro_Settings
  • Inbound_Quick_View
  • Inbound_Reporting_Templates
  • Inbound_Search_And_Comment_Report
  • Inbound_Shared_ACF_BootStrap
  • Inbound_Shortcodes
  • Inbound_Shortcodes_Cookies
  • Inbound_Shortcodes_Fields
  • Inbound_SparkPost
  • Inbound_SparkPost_Stats
  • Inbound_Template_Utils
  • Inbound_Templating_Engine
  • Inbound_Tracking
  • Inbound_Translation_Updater
  • Inbound_Updater
  • Inbound_Upgrade_For_More_Reports
  • Inbound_Upgrade_Routines
  • Inbound_Visitor_Event_Report
  • Inbound_Visitor_Impressions_Report
  • Inbound_Visitors_Report
  • INBOUNDNOW_EXTEND
  • Landing_Pages_ACF
  • Landing_Pages_Activation
  • Landing_Pages_Activation_Update_Routines
  • Landing_Pages_Admin_Menus
  • Landing_Pages_Admin_Notices
  • Landing_Pages_Install
  • Landing_Pages_Load_Extensions
  • Landing_Pages_Meta
  • Landing_Pages_Metaboxes
  • Landing_Pages_Post_Type
  • Landing_Pages_Row_Actions
  • Landing_Pages_Settings
  • Landing_Pages_Sidebars
  • Landing_Pages_Split_Testing_Stats
  • Landing_Pages_Template_Management
  • Landing_Pages_Template_Switcher
  • Landing_Pages_Templates_List_Table
  • Landing_Pages_Variations
  • LandingPages_Welcome
  • Leads_Activation
  • Leads_Activation_Update_Routines
  • Leads_Admin_Notices
  • Leads_Batch_Processor
  • Leads_Branching
  • Leads_Dashboard
  • Leads_Field_Map
  • Leads_Manager
  • Leads_Post_Type
  • Leads_Settings
  • Leads_Tracking
  • Leads_User_Profile
  • LeadStorage
  • LP_EXTENSION_LICENSENING
  • LP_EXTENSION_UPDATER
  • LP_Variation_Rotation
  • LP_Widget_Conversion_Area

Functions

  • cta_check_active
  • cta_example_template_function
  • cta_load_dynamic_widget
  • CTA_Load_Extensions
  • cta_load_static_widget
  • CTA_Render
  • inbound_add_conversion_to_lead
  • inbound_automation_check_active
  • inbound_automation_load_definitions
  • inbound_automation_metaboxes
  • inbound_automation_processing
  • inbound_color
  • inbound_color_scheme
  • inbound_confirm_email_service_provider
  • inbound_email_kill_ie8
  • inbound_email_load_templates
  • inbound_form_add_lead_list
  • inbound_form_auto_publish
  • inbound_form_delete_transient
  • inbound_form_get_data
  • inbound_form_save
  • inbound_forms_change_columns
  • inbound_forms_cpt
  • inbound_forms_custom_columns
  • inbound_forms_default_content
  • inbound_get_form_names
  • inbound_get_parent_directory
  • inbound_Hex_2_RGB
  • inbound_inbound_email_example_template_function
  • inbound_load_lead_manager
  • inbound_load_token_engine
  • inbound_mailer_acf_integration
  • Inbound_Mailer_Common_Settings
  • Inbound_Mailer_Load_Templates
  • inbound_qtrans_disable
  • inbound_record_log
  • inbound_register_form_role_capabilities
  • inbound_shortcode_alert
  • inbound_shortcode_callout
  • inbound_shortcode_columns
  • inbound_shortcode_content_box
  • inbound_shortcode_divider
  • inbound_shortcode_empty_paragraph_fix
  • inbound_shortcode_four_fifth_columns
  • inbound_shortcode_full_columns
  • inbound_shortcode_gmap
  • inbound_shortcode_icon
  • inbound_shortcode_intro
  • inbound_shortcode_landing_pages
  • inbound_shortcode_leadp
  • inbound_shortcode_list_icons
  • inbound_shortcode_one_fifth_columns
  • inbound_shortcode_one_fourth_columns
  • inbound_shortcode_one_half_columns
  • inbound_shortcode_one_third_columns
  • inbound_shortcode_portfolio
  • inbound_shortcode_pricing
  • inbound_shortcode_profile
  • inbound_shortcode_social_links
  • inbound_shortcode_tabs
  • inbound_shortcode_teaser
  • inbound_shortcode_testimonial
  • inbound_shortcode_three_fifth_columns
  • inbound_shortcode_three_fourth_columns
  • inbound_shortcode_two_fifth_columns
  • inbound_shortcode_two_third_columns
  • inbound_shortcode_video
  • inbound_store_lead
  • inbound_template_brightness
  • inbound_template_color
  • Inbound_Templating_Engine
  • inbound_travis_check
  • inboundnow_add_master_license
  • json_encode_fallback
  • landingpage_fix_known_wp_title_isses
  • landingpages_is_active
  • load_CTA_Settings
  • load_CTA_Template_Manager
  • load_Inbound_API_Keys_Generation
  • load_Inbound_Lead_Statuses
  • load_Inbound_Leads_Custom_fields
  • load_inbound_mail_daemon
  • load_Inbound_Mailer_Settings
  • load_Inbound_Mailer_Template_Manager
  • load_Inbound_Pro_Downloads
  • lp_ab_testing_get_current_variation_id
  • lp_add_option
  • lp_body_class
  • lp_check_active
  • lp_content_area
  • lp_conversion_area
  • lp_discover_important_wrappers
  • lp_footer
  • lp_generate_drowndown
  • lp_get_parent_directory
  • lp_get_value
  • lp_global_config
  • lp_head
  • lp_in_admin_header
  • lp_init
  • lp_list_feature
  • lp_load_widgets
  • lp_main_headline
  • lp_manage_templates
  • lp_move_template_files
  • lp_rebuild_attributes
  • lp_templates_upload
  • mailer_check_active
  • wp_cta_check_active
  • wp_cta_kill_ie8
  • wp_cta_load_calls_to_action
  • wp_leads_get_page_final_id
  • wpl_url_to_postid
  • wpleads_add_lead_to_list
  • wpleads_check_active
  • wpleads_get_lead_lists_as_array
  • Overview
  • Package
  • Class
  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: 928: 929: 930: 931: 932: 933: 934: 935: 936: 937: 938: 939: 940: 941: 942: 943: 944: 945: 946: 947: 948: 949: 950: 951: 952: 953: 954: 955: 956: 957: 958: 959: 960: 961: 962: 963: 964: 965: 966: 967: 968: 969: 970: 971: 
<?php

/**
 *
 * Class for managing external package retrieveal, installation, and deletion. (Extensions & Templates)
 * @package     InboundPro
 * @subpackage  Installer
 */


class Inbound_Pro_Downloads {

    static $management_mode; /* UI mode toggle */
    static $items; /* dataset of remotly available items based on page being loaded */
    static $downloads; /* improved dataset of loaded downloads */
    static $download; /* focus dataset being processed */
    static $headline; /* UI headline */
    static $customer; /* sets customer status */
    static $access_level; /* sets customer status */

    /**
     *  Initializes class
     */
    public function __construct() {
        self::add_hooks();
    }

    /**
     *  Loads hooks and filters
     */
    public static function add_hooks() {
        /* Listen for management REQUEST calls  */
        add_action( 'admin_init' , array( __CLASS__ , 'run_management_actions' ) );

        /* enqueue js and css */
        add_action( 'admin_enqueue_scripts' , array( __CLASS__ , 'enqueue_scripts' ) );

        /* load inline js & css */
        add_action( 'admin_footer' , array( __CLASS__ , 'load_inline_js_css' ) );

        add_action( 'inbound-pro/check-for-updates' , array( __CLASS__ , 'cron_check_for_updates' ) );

        /* add open_base_dir check */
        add_action('admin_notices', array( __CLASS__ , 'check_open_base_dir' ) );

    }


    /**
     *  Load CSS & JS
     */
    public static function enqueue_scripts() {
        $screen = get_current_screen();

        /* Load assets for upload page */
        if ( ( isset($screen) && ( $screen->base != 'inbound-pro_page_inbound-manage-templates' && $screen->base != 'inbound-pro_page_inbound-manage-extensions' ) ) ){
            return;
        }

        wp_enqueue_script('jquery');
        wp_enqueue_script('underscore');

        wp_enqueue_script('shuffle', INBOUND_PRO_URLPATH . 'assets/libraries/Shuffle/jquery.shuffle.modernizr.min.js' , array( 'jquery') );

        wp_enqueue_script('bootstrap', INBOUNDNOW_SHARED_URLPATH . 'assets/includes/BootStrap/js/bootstrap.min.js');
        wp_enqueue_style('bootstrap', INBOUNDNOW_SHARED_URLPATH . 'assets/includes/BootStrap/css/bootstrap.min.css');
        wp_enqueue_style('manage-downloads', INBOUND_PRO_URLPATH . 'assets/css/admin/manage-downloads.css');
        wp_enqueue_style('fontawesome', INBOUNDNOW_SHARED_URLPATH . 'assets/fonts/fontawesome/css/font-awesome.min.css');

        /* load cusotm js */
        wp_enqueue_script('manage-downloads', INBOUND_PRO_URLPATH . 'assets/js/admin/manage-downloads.js' );

        /* localize script */
        $memory = Inbound_Options_API::get_option( 'inbound-pro' , 'memory' , array() );
        $meta_filter = ( isset( $memory[ 'meta_filter'] ) ) ? $memory[ 'meta_filter'] : 'uninstalled' ;

        /* get pro templates dataset */
        self::build_main_dataset();

        wp_localize_script( 'manage-downloads', 'downloads' , array( 'meta_filter' => $meta_filter , 'plugin_url_path' => INBOUND_PRO_URLPATH , 'dataset' => self::$downloads , 'current_page' => $_GET['page'] ) );
    }


    /**
     *  Listens for POSTED actions
     */
    public static function run_management_actions() {

        if (!isset($_REQUEST['action']) || !current_user_can('activate_plugins') ) {
            return;
        }

        switch ($_REQUEST['action']):
            case 'install':
                self::run_installation();
                break;
            case 'upgrade':

                break;
            case 'uninstall':
                self::run_uninstallation();
                break;
        endswitch;

    }


    /**
     *  Runs upload commands
     */
    public static function run_installation() {
        global $download_name;

        if ( ! current_user_can('delete_plugins') ) {
            wp_die( __('You do not have sufficient permissions to delete plugins for this site.') );
        }

        /* preapre variables */
        $filename = ( isset($filename) && $filename ) ? $filename : $_REQUEST['filename'];
        $download_type = ( isset($download_type) && $download_type ) ? $download_type : $_REQUEST['filename'];

        /* get downloads dataset */
        self::build_main_dataset();

        /* get download array from */
        self::$download = self::$downloads[ $_REQUEST['download_name'] ];

        /* get zip URL from api server */
        self::$download['download_location'] = Inbound_API_Wrapper::get_download_zip( self::$download );

        /* get upload path from download data */
        self::$download['extraction_path'] = self::get_upload_path( self::$download );

        self::install_download( self::$download );

        /* create global for download name */
        $download_name = self::$download[ 'post_title' ];
        /* add notification */
        add_action( 'admin_notices', function( ) {
            global $download_name;
            ?>
            <br>
            <div class="updated">
                <p><?php _e( $download_name . ' has been installed!', 'inbound-pro' ); ?></p>
            </div>
            <?php
        } );

        /* update configuration dataset & mark installed */
        self::update_configuration_memory('installed');

        /* switch downloads filter to 'installed' */
        $memory = Inbound_Options_API::get_option( 'inbound-pro' , 'memory' , array() );
        $memory['meta_filter'] = 'installed';
        Inbound_Options_API::update_option( 'inbound-pro' , 'memory' , $memory );

    }

    /**
     *  Runs upload commands
     */
    public static function run_uninstallation() {
        global $download_name;

        if ( ! current_user_can('delete_plugins') ) {
            wp_die( __('You do not have sufficient permissions to delete plugins for this site.') );
        }

        /* get pro templates dataset */
        self::build_main_dataset();

        /* get download array from */
        self::$download = self::$downloads[ $_REQUEST['download_name'] ];

        /* get upload path from download data */
        self::$download['extraction_path'] = self::get_upload_path( self::$download );

        /* delete download folder if there */
        self::delete_download_folder( self::$download['extraction_path'] );

        /* create global for download name */
        $download_name = self::$download[ 'post_title' ];

        /* add notification */
        add_action( 'admin_notices', function() {
            global $download_name;
            ?>
            <br>
            <div class="updated">
                <p><?php _e( $download_name . ' has been uninstalled!', 'inbound-pro' ); ?></p>
            </div>
            <?php
        } );



        /* update configuration dataset & mark installed */
        self::update_configuration_memory('uninstalled');

        /* switch downloads filter to 'installed' */
        $memory = Inbound_Options_API::get_option( 'inbound-pro' , 'memory' , array() );
        $memory['meta_filter'] = 'uninstalled';
        Inbound_Options_API::update_option( 'inbound-pro' , 'memory' , $memory );

    }



    /**
     * Install extension
     *
     */
    public static function install_download( $download ) {

        /* load pclzip */
        include_once( ABSPATH . '/wp-admin/includes/class-pclzip.php');

        /* delete download folder if there */
        self::delete_download_folder( $download['extraction_path'] );

        /* create temp file *///get_temp_dir()
        $temp_file = tempnam(sys_get_temp_dir(), 'TEMPPLUGIN' );

        /* get zip file contents from svn */
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $download['download_location'] );
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_FAILONERROR, true);
        curl_setopt($ch, CURLOPT_AUTOREFERER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_BINARYTRANSFER,true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        $file = curl_exec($ch);
        curl_close($ch);

        /* write zip file to temp file */
        $handle = fopen($temp_file, "w");
        fwrite($handle, $file);
        fclose($handle);

        /* make sure we get a filename */
        if(!isset($download['filename']) || !$download['filename']) {
            $download['filename'] = $download['post_name'];
        } else {
            $download['filename'] = str_replace('.zip' , '' , $download['filename']);
        }

        /* extract temp file to plugins direction */
        $archive = new PclZip($temp_file);
        $result = $archive->extract( PCLZIP_OPT_REMOVE_PATH, $download['filename'] , PCLZIP_OPT_PATH, $download['extraction_path'] , PCLZIP_OPT_REPLACE_NEWER );
        if ($result == 0) {
            die("Error : ".$archive->errorInfo(true));
        }

        /* delete templ file */
        unlink($temp_file);
    }

    /**
     * deletes download folder from uploads location
     * @param STRING $dirPath
     */
    public static function delete_download_folder( $dirPath ) {

        if ( !$dirPath || !is_dir($dirPath)) {
            return;
        }

        /* get all objects in folder */
        $objects = scandir($dirPath);

        /* if there is a .git directory assume local development and bail */
        if ( in_array( '.git' , $objects ) ) {
            return;
        }

        foreach ($objects as $object) {
            if ($object != "." && $object !="..") {
                if (filetype($dirPath . DIRECTORY_SEPARATOR . $object) == "dir") {
                    self::delete_download_folder($dirPath . DIRECTORY_SEPARATOR . $object);
                } else {
                    unlink($dirPath . DIRECTORY_SEPARATOR . $object);
                }
            }
        }
        reset($objects);
        rmdir($dirPath);

    }


    /**
     *  Build a stronger dataset from dataset imported from api
     */
    public static function build_main_dataset() {

        /* load management static vars based on page being loaded */
        self::load_management_vars();

        /* get install configuaration dataset from db */
        $configuration= Inbound_Options_API::get_option('inbound-pro', 'configuration', array());

        $i=0;

        foreach (self::$items as $key => $download ) {

            self::$downloads[ $download['post_name']  ] = $download;

            /* discover applicable plugins */
            $download['plugins'][] = 'all';
            self::$downloads[ $download['post_name'] ]['plugins'] = $download['plugins'];

            /* discover installed condition */
            self::$downloads[ $download['post_name'] ]['status'][] = ( isset($configuration[ $download['post_name'] ]['status'] ) ) ? $configuration[ $download['post_name'] ]['status'] : 'uninstalled' ;

            /* Discover current version */
            self::$downloads[ $download['post_name'] ]['current_version'] = ( isset($configuration[ $download['post_name'] ]['current_version'] ) ) ? $configuration[ $download['post_name'] ]['current_version'] : '' ;

            /* set next key inline */
            $prev = $i-1;
            $next = $i+1;

            self::$downloads[ $download['post_name'] ]['previous_post_name'] = (isset(self::$items[$prev]['post_name'])) ? self::$items[$prev]['post_name'] : self::$items[0]['post_name'];
            self::$downloads[ $download['post_name'] ]['next_post_name'] = (isset(self::$items[$next]['post_name'])) ? self::$items[$next]['post_name'] : self::$items[0]['post_name'];

            $i++;
        }

        return self::$downloads;
    }

    /**
     *  Update downloads configuration file with new status & version
     *  @param STRING $status
     */
    public static function update_configuration_memory( $status ) {

        /* get install configuaration dataset */
        $configuration = Inbound_Options_API::get_option( 'inbound-pro' , 'configuration' , array() );

        $configuration[ self::$download['post_name'] ]['status'] = $status;

        /* update current version to server_version */
        if ($status == 'installed') {
            $configuration[ self::$download['post_name'] ]['download_type'] = self::$download['download_type'];
            $configuration[ self::$download['post_name'] ]['current_version'] = self::$download['server_version'];
            $configuration[ self::$download['post_name'] ]['upload_path'] = self::get_upload_path( self::$download );
            $configuration[ self::$download['post_name'] ]['filename'] = self::$download['filename'];

        }

        /* now update configuaration dataset in db */
        Inbound_Options_API::update_option( 'inbound-pro' , 'configuration' , $configuration , 'yes' );

    }

    /**
     *  Loads all UI elements
     */
    public static function test_ui() {

        /* get download data */
        self::build_main_dataset();
        self::grid_container();
    }

    /**
     *
     */
    public static function grid_container() {
        // Conditional showing of tabs
        $showAll = true;
        $showLP = false;
        $showCTA = false;
        $showLeads = false;
        $showEmail = false;
        $openTab = 0;

        if (isset($_GET['show'])) {
            $showAll = false;
            if( $_GET['show'] === "landing-pages" ) {
                $showLP = true;
                $openTab = 1;
            }  else if( $_GET['show'] === "leads" ) {
                $showLeads = true;
                $openTab = 2;
            } else if( $_GET['show'] === "cta" ) {
                $showCTA = true;
                $openTab = 3;
            } else if( $_GET['show'] === "email" ) {
                $showEmail = true;
                $openTab = 4;
            }
        }

        $AllTabClass = ($showAll) ? 'tab-current' : '';
        $allClass = ($showAll) ? 'content-current' : '';
        $leadsTabClass = ($showLeads) ? 'tab-current' : '';
        $leadsClass = ($showLeads) ? 'content-current' : '';
        $emailTabClass = ($showEmail) ? 'tab-current' : '';
        $emailClass = ($showEmail) ? 'content-current' : '';
        $ctaTabClass = ($showCTA) ? 'tab-current' : '';
        $ctaClass = ($showCTA) ? 'content-current' : '';
        $lpTabClass = ($showLP) ? 'tab-current' : '';
        $lpClass = ($showLP) ? 'content-current' : '';

        ?>
        <link rel='stylesheet' id='edd-styles-css'  href='/wp-content/plugins/_inbound-pro/assets/css/store.css' type='text/css' media='all' />
        <!--START -->
        <div id="tabs" class="tabs">
            <nav>
                <ul>
                    <li class="<?php echo $AllTabClass; ?>"><a href="#section-1" ><span>All</span></a></li>
                    <li class="<?php echo $lpTabClass; ?>"><a href="#section-2" class="icon-article"><span>Landing Pages</span></a></li>
                    <li class="<?php echo $leadsTabClass; ?>"><a href="#section-3" class="icon-user"><span>Leads</span></a></li>
                    <li class="<?php echo $ctaTabClass; ?>"><a href="#section-4" class="icon-eye"><span>Calls to Action</span></a></li>
                    <li class="<?php echo $emailTabClass;?>"><a href="#section-5" class="fa fa-envelope-o"><span>Email</span></a></li>

                </ul>


            </nav>
            <div class="content" id="market-content">
                <section id="section-1" class="<?php echo $allClass;?>">

                    <div class="store-container">
                        <div class="main">
                            <span class="center-text area-desc">From email marketing to CRMs these add-ons will make your life easier</span>
                            <div id="cbp-vm" class="cbp-vm-switcher cbp-vm-view-grid">

                                <div class="cbp-vm-options">
                                    <span>Change View</span>
                                    <a href="#" class="cbp-vm-icon cbp-vm-grid cbp-vm-selected" data-view="cbp-vm-view-grid">Grid View</a>
                                    <a href="#" class="cbp-vm-icon cbp-vm-list" data-view="cbp-vm-view-list">List View</a>
                                </div>

                                <?php self::store_listings();?>
                            </div>
                        </div><!-- /main -->
                    </div><!-- /store container -->
                </section>

            </div><!-- /content -->
        </div>
        <!-- END -->

    <?php }
    /* Prepping for new layout */
    public static function store_listings($slug = 'default') {

        ?>

        <ul>
            <?php $count = 0;
            foreach (self::$downloads as $download) {
                $id = $download['ID'];
                $title = $download['post_title'];
                $title_class = (strlen($title) > 30 ) ? "long-title" : 'short-title';
                $exerpt = $download['post_excerpt'];
                $link = $download['permalink'];
                $terms = get_the_terms( $id, 'download_category' ); ?>

                <li class="">
                    <?php $img = $download['featured_image'];
                    if(!$img){
                        $img = '<img src="http://inboundnew.dev/wp-content/uploads/2014/08/medium_wype-1.jpg">';
                    }
                    ?>
                    <a class="cbp-vm-image" href="<?php echo $link;?>"><img src="<?php echo $img;?>"/></a>

                    <!--<div class="cbp-vm-price">$19.90</div>-->
                    <div class="cbp-vm-details">
                        <h3 class="cbp-vm-title <?php echo $title_class;?>"><a href="<?php echo $link;?>"><?php echo $title;?></a></h3>
                        <span class='details-text'>
                        <?php
                        if( $exerpt != "" ) :
                            echo $exerpt;
                        else :
                            echo "short description This is the headline text. This is the headline text. more text here. Testing testing";
                        endif;
                        ?>
                        </span>
                    </div>
                    <a class="cbp-vm-icon cbp-vm-add" href="<?php echo $link; ?>">Add to cart</a>
                </li>
                <?php $count++; ?>

            <?php }

            ?>

            <!--<div id="load_more">Load More</div> -->
        </ul>

    <?php
    }


    /**
     *  Checks if open_base dir
     */
    public static function check_open_base_dir() {
        global $post , $inbound_settings;


        if (!isset($_GET['page'])|| ( $_GET['page']!='inbound-manage-extensions' && $_GET['page']!='inbound-manage-templates' ) ){
            return false;
        }

        if ( !ini_get('open_basedir') ) {
            return;
        }

        ?>
        <div class="updated">
            <p><?php _e( 'ATTENTION: open_basedir restriction in effect which will cause problems with installation.' , 'inbound-pro'); ?></p>
        </div>

        <?php
    }

    /**
     *  Loads all UI elements
     */
    public static function display_ui() {

        /* get download data */
        self::build_main_dataset();

        /* displays filters */
        self::display_filters( );

        /* display grid items */
        self::display_grid_items();
    }

    /**
     *  Prints filters
     */
    public static function display_filters() {
        ?>
        <div class="filter-options row">

            <div class="col-xs-12 col-md-12">
                <div class="templates-filter-group left-group">
                    <h5 class="filter-label"><?php echo self::$headline; ?></h5>
                    <button class="btn btn-go" data-filter-value="all"><span class="visuallyhidden"><?php _e( 'All' , 'inbound-pro' ); ?></span></button>
                    <button class="btn btn-primary" data-filter-value="landing-pages"><span class="visuallyhidden"><?php _e( 'Landing Pages' , 'inbound-pro' ); ?></span></button>
                    <button class="btn btn-warning" data-filter-value="calls-to-action"><span class="visuallyhidden"><?php _e( 'Calls to Action' , 'inbound-pro' ); ?></span></button>
                    <?php
                    /* if extension management page then show more core components */
                    if ( self::$management_mode == 'extensions' ) {
                        ?>
                        <button class="btn btn-success" data-filter-value="leads"><span class="visuallyhidden"><?php _e( 'Leads' , 'inbound-pro' ); ?></span></button>
                        <button class="btn btn-danger" data-filter-value="automation"><span class="visuallyhidden"><?php _e( 'Automation' , 'inbound-pro' ); ?></span></button>

                        <?php
                    }
                    ?>
                    <button class="btn btn-info" data-filter-value="email"><span class="visuallyhidden"><?php _e( 'Email' , 'inbound-pro' ); ?></span></button>

                </div>
            </div>


            <div class="col-xs-12 col-md-12 right-group">
                <div class='templates-filter-group align-left '>
                    <input class="filter-search" type="search" placeholder="<?php _e(' Search... ' , 'inbound-pro' ); ?>">
                    <div class='radio-filters'>
                        <span class="ib">
                            <label  class='filter-label' for="uninstalled"><input type="radio" name="meta" value="uninstalled"  class='radio-filter'> <?php _e( 'Uninstalled' , 'inbound-pro' ); ?></label>
                        </span>
                        <span class="ib">
                            <label class='filter-label' for="installed"><input type="radio" name="meta" value="installed" class='radio-filter'> <?php _e( 'Installed' , 'inbound-pro' ); ?></label>
                        </span>

                        <span class="ib">
                            <label class='filter-label' for="needs-update"><input type="radio" name="meta" value="needs-update" class='radio-filter'> <?php _e( 'Needs Update' , 'inbound-pro' ); ?></label>
                        </span>
                    </div>
                </div>
            </div>

        </div>
        <?php
    }

    /**
     *  Loop through downloads datset and display grid items
     */
    public static function display_grid_items() {
        global $inbound_settings;

        $page = sanitize_text_field($_GET['page']);
        $inbound_settings['system']['counts']['needs-update'][self::$management_mode] = 0;
        ?>

        <div class="wrap">
            <?php
            /*
            echo "<pre>";
            print_r(self::$downloads);exit;
            /**/
            ?>
            <div id="grid" class="container-fluid">
                <?php $count = 1;

                /* determine permissions from customer access level*/
                $permitted = false;

                if (INBOUND_ACCESS_LEVEL > 0 &&  INBOUND_ACCESS_LEVEL != 9 ) {
                    $permitted = true;
                }

                foreach (self::$downloads as $download) {


                    if ($count % 3 == 0) {
                        echo "<div></div>";
                    }
                    $count++;

                    /* Determine if needs update */
                    if ( version_compare( $download['current_version'] ,  $download['server_version']) == -1  && !in_array('uninstalled', $download['status']) )  {
                        $download['status'][] = 'needs-update';
                        $inbound_settings['system']['counts']['needs-update'][self::$management_mode]++;
                    }


                    ?>
                    <div class="row col-md-2 col-xs-2 download-item " data-plugins='<?php echo json_encode( $download['plugins'] ); ?>' data-meta='<?php echo json_encode( $download['status'] ); ?>'  >

                        <?php
                        /* build ribbons */
                        $ribbons = array();
                        if ( in_array( 'landing-pages' , $download['plugins'] ) ) {
                            $ribbons['landing-pages']['ribbon'] = 'lp-ribbon';
                            $ribbons['landing-pages']['fa'] = 'fa-file-text-o';
                            $ribbons['landing-pages']['title'] = __( 'Landing Page' , 'inbound-pro' );
                        }

                        if ( in_array( 'calls-to-action' , $download['plugins'] ) ) {
                            $ribbons['calls-to-action']['ribbon'] = 'cta-ribbon';
                            $ribbons['calls-to-action']['fa'] = 'fa-crosshairs';
                            $ribbons['calls-to-action']['title'] = __( 'Call to Action' , 'inbound-pro' );
                        }

                        if ( in_array( 'leads' , $download['plugins'] ) ) {
                            $ribbons['leads']['ribbon'] = 'leads-ribbon';
                            $ribbons['leads']['fa'] = 'fa-users';
                            $ribbons['leads']['title'] = __( 'Leads' , 'inbound-pro' );
                        }

                        if ( in_array( 'email' , $download['plugins'] ) ) {
                            $ribbons['email']['ribbon'] = 'mail-ribbon';
                            $ribbons['email']['fa'] = 'fa-envelope-o';
                            $ribbons['email']['title'] = __( 'Email' , 'inbound-pro' );
                        }

                        if ( in_array( 'automation' , $download['plugins'] ) ) {
                            $ribbons['automation']['ribbon'] = 'automation-ribbon';
                            $ribbons['automation']['fa'] = 'fa-cog';
                            $ribbons['automation']['title'] = __( 'Email' , 'inbound-pro' );
                        }

                        /* print ribbons */
                        $i = 0;
                        foreach ($ribbons as $key => $ribbon) {
                            echo '<div class="download-ribbon '.$ribbon['ribbon'].' ribbon-'.$i.'"  title="'.$ribbon['title'].'" data-toggle="tooltip" data-placement="left" >
                                <div class="border-ribbon"></div>
                                <a class="fa '.$ribbon['fa'].'"></a>
                             </div>';
                            $i++;
                        }
                        ?>

                        <div class="download-image" style='background-image:url(<?php echo self::get_image_thumbnail($download); ?>);' >
                        </div>

                        <div class="col-template-content more-details" data-download='<?php echo $download['post_name']; ?>'  data-toggle="tooltip" data-placement="top" data-original-title='<?php _e( 'View Details' , 'inbound-pro' ); ?>'>
                            <div class="col-template-info-title"><?php echo $download['post_title']; ?></div>
                        </div>

                        <div class="col-template-actions">
                            <?php
                            if ( in_array( 'uninstalled' , $download['status'] )&& $permitted ) {
                                ?>
                                <div class="action-install">
                                    <a  href="admin.php?page=<?php echo $page; ?>&action=install&download_name=<?php echo $download['post_name']; ?>&download_type=<?php echo $download['download_type']; ?>&filename=<?php echo $download['filename']; ?>" class="power-toggle power-is-off fa fa-power-off"  data-toggle="tooltip" id='<?php echo $download['post_name']; ?>' title='<?php _e( 'Turn On' , 'inbound-pro' ); ?>'></a>
                                </div>
                                <?php
                            }

                            if ( in_array( 'installed' , $download['status'] ) && $permitted ) {
                                ?>
                                <div class="action-uninstall">
                                    <a href="admin.php?page=<?php echo $page; ?>&action=uninstall&download_name=<?php echo $download['post_name']; ?>&filename=<?php echo $download['filename']; ?>" class="power-toggle power-is-on fa fa-power-off"  data-toggle="tooltip" id='<?php echo $download['post_name']; ?>' title='<?php _e( 'Turn Off' , 'inbound-pro' ); ?>'></a>
                                </div>

                                <?php
                                if ( in_array( 'needs-update' , $download['status'] ) ) {
                                    ?>
                                    <div class="action-update">
                                        <a href="admin.php?page=<?php echo $page; ?>&action=install&download_name=<?php echo $download['post_name']; ?>&download_type=<?php echo $download['download_type']; ?>&filename=<?php echo $download['filename']; ?>" class="fa fa-floppy-o"  data-toggle="tooltip" id='<?php echo $download['post_name']; ?>' title='<?php _e( 'Update' , 'inbound-pro' ); ?>'></a>
                                    </div>
                                    <?php
                                }

                                if ($download['download_type'] == 'extension' ) {
                                    $settings_url = apply_filters(
                                            'inbound-pro/download-setting-url' ,
                                            add_query_arg( array( 'page'=>'inbound-pro' , 'tab' =>  'inbound-pro-settings' , 'setting' => $download['filename'] ) , admin_url( 'admin.php' ) )
                                            , $download );
                                    ?>
                                    <div class="action-settings">
                                        <a target="_blank" href="<?php echo $settings_url; ?>" class="fa fa-cog"  data-toggle="tooltip" id='<?php echo $download['post_name']; ?>' title='<?php _e( 'View Settings' , 'inbound-pro' ); ?>'></a>
                                    </div>
                                    <?php
                                }
                            }

                            if (!$permitted) {
                                ?>
                                <div class="action-locked">
                                    <i class="fa fa-lock"  data-toggle="tooltip" id='' title='<?php _e( 'Only available to subscribers.' , 'inbound-pro' ); ?>'></i>
                                </div>
                                <?php
                            }
                            ?>
                        </div>
                    </div>

                    <?php
                }
                ?>
            </div>
        </div>
        <?php

        /* update needs update count */
        Inbound_Options_API::update_option('inbound-pro', 'settings', $inbound_settings);
    }


    /**
     *  Discover weather download is installed or uninstalled and weather it needs an upgrade or not
     */
    public static function get_download_status() {


    }


    /**
     *  Determines uploads location
     */
    public static function get_upload_path( $download ) {

        /* get zip file name */
        $folder_name =  ( isset($download['filename']) ) ? $download['filename'] :  $download['post_name'];
        $folder_name = str_replace('.zip' , '' , $folder_name );

        if ( $download['download_type'] == 'extension' ) {
            return  INBOUND_PRO_UPLOADS_PATH . 'extensions/'. $folder_name;
        }

        if ( in_array( 'calls-to-action' , $download[ 'plugins' ] ) ) {
            return WP_CTA_UPLOADS_PATH . $folder_name . '/';
        }

        if ( in_array( 'landing-pages' , $download[ 'plugins' ] ) ) {
            return LANDINGPAGES_UPLOADS_PATH . $folder_name . '/';
        }

        if ( in_array( 'email' , $download[ 'plugins' ] ) ) {
            return INBOUND_EMAIL_UPLOADS_PATH . $folder_name . '/';
        }

    }

    public static function get_image_thumbnail($download) {
        global $inbound_paths_created;

        $path = INBOUND_PRO_UPLOADS_PATH . 'assets/images/';
        $url = INBOUND_PRO_UPLOADS_URLPATH . 'assets/images/';


        if(strstr( $download['featured_image'] , '.png')){
            $ext = '.png';
        }else if(strstr( $download['featured_image'] , '.jpg')){
            $ext = '.jpg';
        }

        if(file_exists( $path . $download['post_name'] . $ext)){
            return $url . $download['post_name'] .$ext;
        }

        $image_path_location = $path . $download['post_name'] . $ext;
        $image_url_location = $url . $download['post_name'] . $ext;

        /* create wp-content/inbound-pro/assets/images */
        if (!$inbound_paths_created) {
            $inbound_paths_created = true;
            Inbound_Pro_Activation::create_upload_folders();
        }


        $image_path_location = $path . $download['post_name'] . $ext;
        $image_url_location = $url . $download['post_name'] . $ext;

        /* create wp-content/inbound-pro/assets/images */
        if (!$inbound_paths_created) {
            $inbound_paths_created = true;
            Inbound_Pro_Activation::create_upload_folders();
        }

        /* get zip file contents from svn */
        $file = wp_remote_get($download['featured_image']);
        $image = wp_remote_retrieve_body($file);
        /* write zip file to temp file */
        $handle = fopen($image_path_location, "w");
        fwrite($handle, $image);
        fclose($handle);


        return $image_url_location;
    }

    /**
     *  Display management page
     */
    public static function load_management_vars( ) {

        $page = (isset($_REQUEST['page'])) ? $_REQUEST['page'] : 'inbound-manage-extensions';
        switch( $page ) {
            case 'inbound-manage-templates':

                /* set mode to templates */
                self::$management_mode = 'templates';

                /* set headline */
                self::$headline = __( 'Manage Templates' , 'inbound-pro' );

                /* set pre-processed download items */
                self::$items = Inbound_API_Wrapper::get_pro_templates();
                break;
            case 'inbound-manage-extensions':

                /* set mode to extensions */
                self::$management_mode = 'extensions';

                /* set headline */
                self::$headline = __( 'Manage Extensions' , 'inbound-pro' );

                /* set pre-processed download items */
                self::$items = Inbound_API_Wrapper::get_pro_extensions();
                break;
            default:
                /* if not calling from the template or extension management page let's make sure our download dataset is primed and up to date */
                Inbound_API_Wrapper::get_downloads();
                self::$items = array();
                break;
        }


    }


    /**
     *  Loads inline JS & CSS
     */
    public static function load_inline_js_css() {
        $screen = get_current_screen();

        if ( $screen->base != 'inbound-pro_page_inbound-manage-templates' &&  $screen->base != 'inbound-pro_page_inbound-manage-extensions' ) {
            return;
        }

        /* get filter memory */
        $memory = Inbound_Options_API::get_option( 'inbound-pro' , 'memory' , array() );
        $meta_filter = ( isset( $memory[ 'meta_filter'] ) ) ? $memory[ 'meta_filter'] : 'uninstalled' ;

        ?>
        <script>
            jQuery(document).ready(function() {

            });
        </script>
        <?php

        if ( intval(INBOUND_ACCESS_LEVEL) < 3) {
            ?>
            <style type="text/css">
            body .details-install {
                display:none !important;
            }
            body .details-update {
                display:none !important;
            }

            <?php
            if ($screen->base == 'inbound-pro_page_inbound-manage-extensions') {
            ?>

                body .details-preview {
                    display: none !important;
                }

            <?php
            }
            ?>
            </style>
            <?php
        }

    }

    public static function cron_check_for_updates() {
        global $inbound_settings;

        $configuration = Inbound_Options_API::get_option( 'inbound-pro' , 'configuration' , array() );


        $inbound_settings['system']['counts']['needs-update']['extensions'] = 0;
        $inbound_settings['system']['counts']['needs-update']['templates'] = 0;

        $data = Inbound_API_Wrapper::get_downloads();

        foreach ( $data as $key => $download ) {

            if (!isset($download->post_name)) {
                continue;
            }

            $status = ( isset($configuration[ $download->post_name ]['status'] ) ) ? $configuration[ $download->post_name ]['status'] : 'uninstalled' ;

            if($status=='uninstalled') {
                continue;
            }

            if ( isset($download->download_type) && $download->download_type == 'extension' ) {
                $extensions[] = (array) $download;
            }


            /* Determine if needs update */
            if ( version_compare( $configuration[ $download->post_name ]['current_version'] ,  $download->server_version) == -1   )  {
                $inbound_settings['system']['update-count'][self::$management_mode]++;
            }
        }

        /* update needs update count */
        Inbound_Options_API::update_option('inbound-pro', 'settings', $inbound_settings);
    }



}



/**
 *  Loads Inbound_Pro_Downloads on admin_init
 */
function load_Inbound_Pro_Downloads() {
    $Inbound_Pro_Downloads = new Inbound_Pro_Downloads;
}
add_action( 'init' , 'load_Inbound_Pro_Downloads' );
Inbound Pro Plugin - PHP Codex API documentation generated by ApiGen