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: 
<?php

/**
 * Class adds dashboard widgets to wp-admin dashboard
 *
 * @package Leads
 * @subpackage Dashboard
 */

class Leads_Dashboard {

    static $user_id;
    static $hidden;

    public function __construct() {

        $enable = Leads_Settings::get_setting('wpl-main-enable-dashboard', 1);
        if (!$enable) {
            return;
        }

        add_action('wp_dashboard_setup', array($this, 'add_dashboard_widgets'));

        add_action('admin_enqueue_scripts', array(__CLASS__, 'load_static_vars'));

        add_action('admin_enqueue_scripts', array(__CLASS__, 'register_admin_scripts'));

        add_action('admin_head', array(__CLASS__, 'add_inline_header_scripts'));

        add_action( 'wp_ajax_leads_update_monitored_lists' , array( __CLASS__ , 'ajax_update_lists' ) );

    }

    /**
     * Loading Static Variables while in Dashboard screen
     */
    public static function load_static_vars( $hook ) {
        if ('index.php' != $hook) {
            return;
        }

        self::$user_id = get_current_user_id();
        self::$hidden = get_user_option(
            'metaboxhidden_dashboard',
            self::$user_id
        );
        self::$hidden =  ( isset(self::$hidden) && is_array(self::$hidden) ) ? self::$hidden : array() ;
    }

    /**
     * Add dashboard widgets
     */
    public static function add_dashboard_widgets() {

        /* check to see if user is administrator or inbound marketer role */
        if (!current_user_can('edit_leads') ) {
            return;
        }

        $custom_dashboard_widgets = array(
            'wp-lead-performance' => array(
                'title' => __('Lead Performance', 'inbound-pro'),
                'callback' => array(__CLASS__, 'display_lead_performance_report')
            ),
            'wp-lead-latest-leads' => array(
                'title' => __('Latest Leads', 'inbound-pro'),
                'callback' => array(__CLASS__, 'display_latest_leads_widget'),
            ),
            'wp-lead-list-performance' => array(
                'title' => __('List Performance', 'inbound-pro'),
                'callback' => array(__CLASS__, 'display_list_performance_widget'),
            ),
        );

        foreach ($custom_dashboard_widgets as $widget_id => $options) {
            wp_add_dashboard_widget(
                $widget_id,
                $options['title'],
                $options['callback']
            );
        }
    }

    /**
     * Enqueue scripts and styles for dashboard
     * @param $hook
     */
    public static function register_admin_scripts($hook) {

        if ('index.php' != $hook) {
            return;
        }

        wp_enqueue_script('jquery-cookie', WPL_URLPATH . 'assets/js/jquery.cookie.js', array(), null, true);
        wp_enqueue_script('flot', WPL_URLPATH . 'assets/js/jquery.flot.js', array(), null, false);
        wp_enqueue_script('flot-stack', WPL_URLPATH . 'assets/js/jquery.flot.stack.js', array(), null, false);
        wp_enqueue_script('flot-time', WPL_URLPATH . 'assets/js/jquery.flot.time.js', array(), null, false);
        wp_enqueue_script('flot-axislabels', WPL_URLPATH . 'assets/js/jquery.flot.axislabels.js', array(), null, false);
        wp_enqueue_script('lead-flot-functions', WPL_URLPATH . 'assets/js/lead-flot-functions.js', array(), null, false);

        wp_enqueue_script('custom-dashboard-js', WPL_URLPATH . 'assets/js/custom-dashboard.js', array(), false, true);
        wp_enqueue_style('custom-dashboard-css', WPL_URLPATH . '/assets/css/wpl.dashboard.css');

        /* load fontawesome */
        wp_enqueue_style('fontawesome', INBOUNDNOW_SHARED_URLPATH . 'assets/fonts/fontawesome/css/font-awesome.min.css');

    }

    /**
     * Adding inline header scripts and styling  - powers lead quick search in admin bar
     */
    public static function add_inline_header_scripts() {
        if (!class_exists('Inbound_Pro_Plugin')) {
            return;
        }
        ?>
        <style type="text/css">
            #wpadminbar .adminbar-leads-search .lead-quick-search {
                display: inline !important;
            }

            #wpadminbar .adminbar-leads-search .fa {
                font-family: 'FontAwesome'
            }

            #wpadminbar .adminbar-leads-search form {
                display: inline !important;
                width: auto;
                height: auto;
            }

            #wpadminbar .adminbar-leads-search .lead-quick-search input, #wpadminbar .adminbar-leads-search .lead-quick-search input, #wpadminbar .adminbar-leads-search .lead-quick-search input:focus {
                width: 1px;
                -webkit-transition: all .3s cubic-bezier(0, 0, .5, 1.5);
                transition: all .3s cubic-bezier(0, 0, .5, 1.5);
                font-size: 9px;
                height: 25px;
                margin-top: 3px;
                padding-bottom: 0px;
                padding-top: 0px;
                padding-left: 3px;
                color: #eee;
                background-color: #444;
                margin-right: 5px;
                border: none;
                line-height: 30px;
                display: none;
            }

        </style>
        <section class="lead-quick-search" style="display:none" method="get">
            <form action="<?php echo admin_url('edit.php?s=hudson.atwell%40gmail.com&post_status=all&post_type=wp-lead'); ?>">
                <input name="s" type="search" placeholder="<?php _e('Search Leads', 'inbound-pro'); ?>">
                <input type="hidden" name="post_type" value="wp-lead">
            </form>
        </section>

        <script type="text/javascript">
            jQuery(document).ready(function () {
                var on = false;
                running_ajax = new Object();

                jQuery('.lead-quick-search').prependTo('.adminbar-leads-search .ab-item');
                jQuery('.adminbar-leads-search .fa-search').click(function () {
                    if (!on) {
                        jQuery('.lead-quick-search input').show().animate({
                            width: '70%'
                        }, 200);
                        on = true;
                    } else {
                        jQuery('.lead-quick-search input').animate({
                            width: '0px'
                        }, 200).hide();
                        on = false;
                    }

                });

                jQuery('.plus-minus-toggle').on('click', function() {
                    jQuery(this).toggleClass('collapsed');
                });

                jQuery('#toggle-lead-list-selection').on('click' , function() {
                    jQuery('#list-performance-options').toggle();
                });

                jQuery('#list-performance-options input:checkbox').on('change' , function() {

                    if (typeof running_ajax['leads_update_monitored_lists'] != 'undefined' ) {
                        running_ajax['leads_update_monitored_lists'].abort();
                    }

                    running_ajax['leads_update_monitored_lists'] = jQuery.ajax({
                        url: "<?php echo admin_url( 'admin-ajax.php' ); ?>",
                        type: "post",
                        data: {
                            action: 'leads_update_monitored_lists',
                            lists: jQuery('input[name="dashboard-list-performance\[\]"]:checked').serialize()
                        },
                        dataType: 'html',
                        success: function(data) {
                            jQuery('#response').html(data);
                        }
                    });
                });

            });
        </script>
        <?php

    }

    /**
     *
     */
    public static function display_lead_performance_report() {
        global $wpdb;

        /*if the widget isn't supposed to display, echo a short message and exit*/
        if (in_array('wp-lead-performance' , self::$hidden)) {
            /*output a message for when the widget is re-enabled*/
            echo '<div style="height: 220px; text-align: center;">
                    <h3 style="position: relative; top:49%">' . __('Refresh page to enable. ', 'inbound-pro') . '</h3>
                </div>';
            return;
        }

        $count_posts = wp_count_posts('wp-lead');
        $url = site_url();

        $start_current = date("Y-m-01"); // start of current month
        $end_current = date("Y-m-t", strtotime('last day of this month')); // end of current month
        
        $previous_month_start = date("Y-m-01", strtotime("previous month"));
        $previous_month_end = date("Y-m-d", strtotime("-1 month"));

        $this_month = self::count_leads_by_time($start_current, $end_current);
        $last_month = self::count_leads_by_time($previous_month_start, $previous_month_end);

        $all_time_leads = $count_posts->publish;
        $all_lead_text = ($all_time_leads == 1) ? "Lead" : "Leads";
        $leads_today = Leads_Dashboard::get_lead_count_from_today('wp-lead');
        $leads_today_text = ($leads_today == 1) ? "Lead" : "Leads";
        $month_comparasion = $this_month - $last_month;

        if ($month_comparasion < 0) {
            $month_class = 'negative-leads';
            $sign = "";
            $sign_text = __('Decrease ', 'inbound-pro');
        } elseif ($month_comparasion === 0) {
            $month_class = 'no-change';
            $sign = "";
            $sign_text = __('No Change ', 'inbound-pro');
        } else {
            $month_class = 'positive-leads';
            $sign = "+";
            $sign_text = __('Increase ', 'inbound-pro');
        }
        echo '<div id="lead-before-dashboard">';
        do_action('wp_lead_before_dashboard');
        echo "</div>";

        $clean_dates = date("m", strtotime("first day of previous month"));
        $clean_date_two = date("m");
        ?>

        <!--[if lte IE 8]>
        <script language="javascript" type="text/javascript" src="/wp-content/plugins/lead-dashboard-widgets/assets/js/flot/excanvas.min.js"></script><![endif]-->

        <div class="wp_leads_dashboard_widget">

            <script type="text/javascript">
                /* <![CDATA[ */
                window.data1 = [ <?php echo self::get_lead_graph_data($clean_date_two, 'this-month'); ?> ];
                window.data2 = [ <?php echo self::get_lead_graph_data($clean_dates, 'last-month'); ?> ];
                /* ]]> */
            </script>
            <div id="flot-placeholder" style='width: 100%; height: 250px; margin: 10px auto 0px; padding: 0px; position: relative; margin-bottom:10px;'></div>


            <div id="wp-leads-stat-boxes">
                <div class='wp-leads-today'>
                    <a class="data-block widget-block" alt='Click to View Todays Leads' href="<?php echo $url . "/wp-admin/edit.php?post_type=wp-lead&current_date"; ?>">
                        <section>
                            <?php echo $leads_today; ?>
                            <br><?php echo $leads_today_text; ?>
                            <br><strong><?php _e('Today', 'inbound-pro'); ?></strong>
                        </section>
                    </a>
                </div>
                <div class='wp-leads-this-month'>
                    <a class="data-block widget-block" alt='Click to View This Months Leads' href="<?php echo $url . "/wp-admin/edit.php?post_type=wp-lead&current_month"; ?>">
                        <section>
                            <?php echo $this_month; ?>
                            <br><?php echo $all_lead_text; ?>
                            <br><strong><?php _e('This Month', 'inbound-pro'); ?></strong>
                        </section>
                    </a>
                </div>
                <div class='wp-leads-all-time'>
                    <a class="data-block widget-block" title='Click to View All Leads' href="<?php echo $url . "/wp-admin/edit.php?post_type=wp-lead"; ?>">
                        <section>
                            <?php echo $all_time_leads; ?>
                            <br><?php _e('Leads', 'inbound-pro'); ?>
                            <strong><?php _e('All Time', 'inbound-pro'); ?></strong>
                        </section>
                    </a>
                </div>
                <div class="wp-leads-change-box" style="text-align: center;">
                    <small class='<?php echo $month_class; ?>'><?php echo "<span>" . $sign . $month_comparasion . "</span> " . $sign_text; ?><?php _e('Since Last Month', 'inbound-pro'); ?></small>
                </div>
            </div>
            <!-- <div class='wp-leads-last-month'>
            last month: <?php echo $last_month; ?>

            <?php echo $this_month - $last_month; ?>
            </div>  -->
        </div>
        <?php
    }

    /**
     * Displays the latest converted leads.
     */
    public static function display_latest_leads_widget() {

        /*if the widget isn't supposed to display, echo a short message and exit*/
        if (in_array('wp-lead-latest-leads' , self::$hidden)) {
            /*output a message for when the widget is re-enabled*/
            echo '<div style="height: 220px; text-align: center;">
                    <h3 style="position: relative; top:49%">' . __('Refresh page to enable. ', 'inbound-pro') . '</h3>
                </div>';
            return;
        }

        ?>
        <div id='leads-list'>
            <?php $r = new WP_Query(apply_filters('widget_posts_args', array(
                'posts_per_page' => 20,
                'post_type' => 'wp-lead',
                'post_status' => 'publish')));

            if ($r->have_posts()) : ?>
                <ul id='lead-ul'>
                    <?php while ($r->have_posts()) : $r->the_post(); ?>
                        <li><?php

                            $id = get_the_ID();
                            $first_name = get_post_meta($id, 'wpleads_first_name', true);
                            $last_name = get_post_meta($id, 'wpleads_last_name', true);
                            $name = $first_name . " " . $last_name;

                            if ($name === " ") {
                                $name = get_the_title($id);
                            }

                            $avatar_link = Leads_Post_Type::get_gravatar($id, 20);
                            $img = "<img src=\"$avatar_link\" width=\"20\" height=\"20\" class=\"latest-leads-mini-avatar\" />";
                            ?>

                            <?php edit_post_link($img . $name); ?> on <?php the_time('F jS, Y'); ?>
                            (<?php echo sanitize_text_field(get_the_title()); ?>)
                        </li>
                    <?php endwhile; ?>
                </ul>
            <?php endif; ?>
        </div>
        <?php

    }

    /**
     * Shows the lead generation performance of lists compared to this time yesterday, and by this date last month
     */
    public static function display_list_performance_widget() {
        global $wpdb;

        /*if the widget isn't supposed to display, echo a short message and exit*/
        if (in_array('wp-lead-list-performance' , self::$hidden)) {
            /*output a message for when the widget is re-enabled*/
            echo '<div style="height: 220px; text-align: center;">
                    <h3 style="position: relative; top:49%">' . __('Refresh page to enable. ', 'inbound-pro') . '</h3>
                </div>';
            return;
        }

        $time = new DateTime(date_i18n('Y-m-d G:i:s'));
        $today = $time->format('Ymd');
        $this_month = $time->modify('first day of this month')->format('Ym');

        $lists = Inbound_Leads::get_lead_lists_as_array();
        $monitored_lists =  get_option( 'leads-dashboard-list-monitoring' , array() );

        ?>


        <table class="leads-list-performance-table">
            <thead>
            <tr>
                <td>
                    <?php _e('Lead List' , 'inbound-pro'); ?>
                </td>
                <td>
                    <?php _e('Current Day' , 'inbound-pro'); ?>
                </td>
                <td>
                    <?php _e('Current Month' , 'inbound-pro'); ?>
                </td>
            </tr>
            </thead>
            <tbody>
            <?php
            $table_count_number = 1;
            foreach ($monitored_lists as $key => $list_id ) {

                $list = get_term_by( 'id' , $list_id , 'wplead_list_category' );

                /* get days */
                $todays_leads = count(self::get_list_event_data($list_id, '12 am today'));
                $yesterdays_leads = count(self::get_list_event_data($list_id, '12 am today', '12 am today -1 days'));
                $yesterdays_leads_at_this_time = count(self::get_list_event_data($list_id, 'now -1 days', '12 am today'));

                if ($yesterdays_leads_at_this_time == 0 && $todays_leads == 0) {
                    /*if there were no leads yesterday and there's none today, set the displayed output to 0%*/
                    $day_change = '0%';
                    $day_difference_class = 'lead-count-no-change';
                } else if ($yesterdays_leads_at_this_time == 0 && $todays_leads > 0) {
                    /*if there were no leads yesterday but there are leads today, set the increase to 100%*/
                    $day_change = '100%';
                    $day_difference_class = 'lead-count-increase';
                } else {
                    /*if there were leads yesterday, get the percent difference between now and this time yesterday*/
                    $day_change = ($todays_leads / $yesterdays_leads_at_this_time * 100) - 100;

                    /*set the appropriate css class for the difference*/
                    if ($day_change > 0) {
                        $day_difference_class = 'lead-count-increase';
                    } else if ($day_change < 0) {
                        $day_difference_class = 'lead-count-decrease';
                    } else {
                        $day_difference_class = 'lead-count-no-change';
                    }

                    $day_change = round($day_change, 2) . '%';
                }

                /* get months */
                $this_months_leads = count(self::get_list_event_data($list_id, 'first day of this month'));
                $last_months_leads = count(self::get_list_event_data($list_id, 'first day of this month', 'first day of this month -1 months'));
                $last_month_at_this_time = count(self::get_list_event_data($list_id, 'now -1 months', 'first day of this month'));

                if ($last_month_at_this_time == 0 && $this_months_leads == 0) {
                    /*if there were no leads last month and there's none today, set the displayed output to 0%*/
                    $month_change = '0%';
                    $month_difference_class = 'lead-count-no-change';
                } else if ($last_month_at_this_time == 0 && $this_months_leads > 0) {
                    /*if there were no leads last month but there are leads today, set the increase to 100%*/
                    $month_change = '100%';
                    $month_difference_class = 'lead-count-increase';
                } else {
                    /*if there were leads last month, get the percent difference between the leads so far and the leads at this time last month*/
                    $month_change = ($this_months_leads / $last_month_at_this_time * 100) - 100;

                    /*set the appropriate css class for the difference*/
                    if ($month_change > 0) {
                        $month_difference_class = 'lead-count-increase';
                    } else if ($month_change < 0) {
                        $month_difference_class = 'lead-count-decrease';
                    } else {
                        $month_difference_class = 'lead-count-no-change';
                    }

                    $month_change = round($month_change, 2) . '%';
                }
                ?>
                <tr>
                    <td>
                        <?php echo $list->name; ?>
                    </td>
                    <td>
                        <span  class="list-stat">
                            <?php
                            if ( defined('INBOUND_PRO_PATH') ) {
                                ?>

                                <a href='<?php echo admin_url('index.php?action=inbound_generate_report&class=Inbound_Events_Report&range=1&event_name=inbound_add_list&show_graph=false&list_id=' . $list_id . '&title='.  $list->name .'&tb_hide_nav=true&TB_iframe=true&width=1000&height=600'); ?>' class='thickbox inbound-thickbox'>
                                    <?php echo $todays_leads; ?>
                                </a>
                                <?php
                            }   else {
                                 echo $todays_leads;
                            }
                            ?>
                        </span>
                         <span class="stat list-performance-change-pill <?php echo $day_difference_class; ?>" title="<?php printf(_n('By this time yesterday %s lead was added. ', 'At this time yesterday %s leads had been added. ', 'inbound-pro'), number_format_i18n($yesterdays_leads_at_this_time));
                         printf(_n('%s lead was added to &quot;' . $list->name . '&quot; yesterday. ', 'A total of %s leads were added yesterday.', 'inbound-pro'), number_format_i18n($yesterdays_leads)); ?>" data-toggle="tooltip" data-placement="left">
                                <?php echo self::get_formatted_difference($todays_leads , $yesterdays_leads_at_this_time) . ' ('.$yesterdays_leads.')'; ?>
                        </span>
                    </td>
                    <td >
                        <span class="list-stat">
                            <?php
                            if ( defined('INBOUND_PRO_PATH') ) {
                                ?>

                                <a href='<?php echo admin_url('index.php?action=inbound_generate_report&class=Inbound_Events_Report&range='.date('d').'&event_name=inbound_add_list&show_graph=false&list_id=' . $list_id . '&title='.  $list->name .'&tb_hide_nav=true&TB_iframe=true&width=1000&height=600'); ?>' class='thickbox inbound-thickbox'>
                                    <?php echo $this_months_leads; ?>
                                </a>
                                <?php
                            }   else {
                                echo $this_months_leads;
                            }
                            ?>
                        </span>
                        <span class="stat list-performance-change-pill no-wrap <?php echo $month_difference_class; ?>" title="<?php printf(_n('At this day last month, %s lead had been added to &quot;%s&quot;. ', 'At this day last month, %s leads were added. ', $last_month_at_this_time, 'inbound-pro'), number_format_i18n($last_month_at_this_time), $list->name);
                        printf(_n('Last month %s lead was added to &quot;' . $list->name . '&quot;. ', 'A total of %s leads added last month. ', $last_months_leads, 'inbound-pro'), number_format_i18n($last_months_leads)); ?>" data-toggle="tooltip" data-placement="left">
                               <?php echo self::get_formatted_difference($this_months_leads, $last_month_at_this_time) . ' ('.$last_months_leads.')' ; ?>
                        </span>
                    </td>
                </tr>

                <?php
                $table_count_number++;
            }
            ?>
            </tbody>
        </table>
        <div style="width:100%;text-align:right;">
            <div class="plus-minus-toggle collapsed" id="toggle-lead-list-selection"></div>
        </div>
        <div id="list-performance-options">
            <?php
            foreach ( $lists as $id=>$list_name ) {
                echo '<label><input name="dashboard-list-performance[]" type="checkbox" value="'.$id.'" ' . ( in_array( $id , $monitored_lists) ? 'checked="checked"' : '' ) .'>'.$list_name.'</label><br>';
            }
            ?>
        </div>
        <?php
    }

    /**
     * Get number of leads added between two datetimes.
     * @param $start_current
     * @param $end_current
     * @return mixed
     */
    public static function count_leads_by_time($start_current, $end_current) {
        global $wpdb;
        global $table_prefix;

        $numposts = $wpdb->get_var(
            $wpdb->prepare(
                "SELECT COUNT(ID) " .
                "FROM {$wpdb->posts} " .
                "WHERE post_status='publish' " .
                "AND post_type= %s " .
                "AND {$table_prefix}posts.post_date BETWEEN %s AND %s",
                'wp-lead', $start_current, $end_current
            )
        );

        return $numposts;
    }

    public static function get_formatted_difference($val_1 , $val_2) {
        $difference = $val_1 - $val_2;

        if (!strstr($difference, '-') && $difference) {
            $difference = '+'.$difference;
        }

        return $difference;
    }


    /**
     * Gets count of new leads generated today
     * @return mixed
     */
    public static function get_lead_count_from_today() {
        global $wpdb;
        global $table_prefix;

        $wordpress_date_time = $timezone_format = _x('Y-m-d', 'timezone date format');
        $wordpress_date_time = date_i18n($timezone_format);
        $wordpress_date = $timezone_day = _x('d', 'timezone date format');
        $wordpress_date = date_i18n($timezone_day);

        $today = $wordpress_date_time; // Corrected timezone
        $tomorrow = date("Y-m-d", strtotime("+2 day")); // Hack to look 2 days ahead


        $numposts = $wpdb->get_var(
            $wpdb->prepare(
                "SELECT COUNT(ID) " .
                "FROM {$wpdb->posts} " .
                "WHERE post_status='publish' " .
                "AND post_type= %s " .
                "AND {$table_prefix}posts.post_date BETWEEN %s AND %s",
                'wp-lead', $today, $tomorrow
            )
        );
        return $numposts;
    }

    /**
     * @param $month
     * @param $type
     */
    public static function get_lead_graph_data($month, $type) {
        global $wpdb;
        global $table_prefix;

        $wordpress_date_time = $timezone_format = _x('Y-m-d', 'timezone date format');
        $wordpress_date_time = date_i18n($timezone_format);
        $wordpress_date = $timezone_day = _x('d', 'timezone date format');
        $wordpress_date = date_i18n($timezone_day);
        $this_year = _x('Y', 'timezone date format');
        $this_year = date_i18n($this_year);
        $loop_count = date('d', strtotime('last day of this month'));


        $final_loop_count = cal_days_in_month(CAL_GREGORIAN, $month, $this_year); // Count of days in month

        /*if last month was december, wind back the year*/
        if ($type === "last-month" && $month == '12') {
            $this_year -= 1;
        }

        //echo $final_loop_count; // How many times to run
        $lead_increment = 0;
        for ($i = 1; $i < $final_loop_count + 1; $i++) {
            // echo "hi" . $i;
            $year = $this_year;
            $day = $i;
            $next_day = $i + 1;
            $m = $month;
            $Date = strtotime($year . "-" . $m . "-" . $day);
            $Date_next = strtotime($year . "-" . $m . "-" . $next_day);
            $clean_date_one = date('Y-m-d', $Date);
            $clean_date_one_formatted = date('Y, n, d', $Date);
            if ($type === "last-month") {
                $Date = strtotime($year . "-" . $m . "-" . $day . ' +1 months');
                $clean_date_one_formatted = date('Y, m, d', $Date);
            }
            $clean_date_two = date('Y-m-d', $Date_next);
            //echo $clean_date_one . "<br>";
            $numposts = $wpdb->get_var(
                $wpdb->prepare(
                    "SELECT COUNT(ID) " .
                    "FROM {$wpdb->posts} " .
                    "WHERE post_status='publish' " .
                    "AND post_type= %s " .
                    "AND {$table_prefix}posts.post_date BETWEEN %s AND %s",
                    'wp-lead', $clean_date_one, $clean_date_two
                )
            );
            $lead_increment += $numposts;
            //echo "Day is: ". $day . " " . $numposts . " on " . $clean_date_one    .   "<br>";
            echo "[gd(" . $clean_date_one_formatted . "), " . $lead_increment . ", " . $numposts . "], ";
        }

    }


    /**
     * Retrieves the leads added to a list between a start date and right now.
     * If second date argument is supplied, leads will be retrieved from a time period starting at
     * the second time arg and ending at the time specified by the first arg.
     */
    public static function get_list_event_data($id, $start_date = 'now', $older_start_date = false) {
        global $wpdb;

        if (empty($id)) {
            return;
        }

        $today = new DateTime(date_i18n('Y-m-d G:i:s'));
        $dates['end_date'] = $today->format('Y-m-d G:i:s T');
        $today->modify($start_date);
        $dates['start_date'] = $today->format('Y-m-d G:i:s T');

        $table_name = $wpdb->prefix . "inbound_events";

        $query = 'SELECT DISTINCT lead_id';
        $query .= ' FROM ' . $table_name . ' WHERE 1=1 ';
        $query .= ' AND event_name = "inbound_list_add"';
        $query .= ' AND list_id = ' . $id;

        /*if a second date is supplied, that is used as the new start date and $start_date is used as the new end date*/
        if (gettype($older_start_date) == 'string' && !empty($older_start_date)) {

            /* generate dates for previous date-range */
            $today->modify($older_start_date);
            $dates['past_start_date'] = $today->format('Y-m-d G:i:s T');
            $dates['past_end_date'] = $dates['start_date'];

            $query .= ' AND datetime >= "' . $dates['past_start_date'] . '" AND datetime <= "' . $dates['past_end_date'] . '" ';

        } else {

            $query .= ' AND datetime >= "' . $dates['start_date'] . '" AND datetime <= "' . $dates['end_date'] . '" ';
        }

        $results = $wpdb->get_results($query, ARRAY_A);

        return $results;
    }

    public static function get_color_from_string($str) {
        $code = dechex(crc32($str));
        $code = substr($code, 0, 6);
        return $code;

        /*
        function hsl2rgb($H, $S, $V) {
            $H *= 6;
            $h = intval($H);
            $H -= $h;
            $V *= 255;
            $m = $V*(1 - $S);
            $x = $V*(1 - $S*(1-$H));
            $y = $V*(1 - $S*$H);
            $a = [[$V, $x, $m], [$y, $V, $m],
                  [$m, $V, $x], [$m, $y, $V],
                  [$x, $m, $V], [$V, $m, $y]][$h];
            return sprintf("#%02X%02X%02X", $a[0], $a[1], $a[2]);
        }

        function hue($tstr) {
            return unpack('L', hash('adler32', $tstr, true))[1];
        }

        $phrase = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
        $words = [];
        foreach (explode(' ', $phrase) as $word)
            $words[hue($word)] = $word;
        ksort($words);
        foreach ($words as $h => $word) {
            $col = hsl2rgb($h/0xFFFFFFFF, 0.4, 1);
            printf('<span style="color:%s">%s</span> ', $col, $word);
        }*/
    }


    /**
     *  Ajax listener for saving updated custom field data
     */
    public static function ajax_update_lists() {
        /* parse string */
        parse_str($_POST['lists'] , $array );

        //error_log(print_r($array['dashboard-list-performance'],true));

        /* Update Setting */
        update_option( 'leads-dashboard-list-monitoring' , $array['dashboard-list-performance'] , false );

    }
}

new Leads_Dashboard();
Inbound Pro Plugin - PHP Codex API documentation generated by ApiGen