true, 'cost_monthly_renewals' => true, 'cost_yearly_renewals' => true, 'cost_monthly_totals' => true, 'cost_category_totals' => true, 'cost_payments_left_this_month' => true, ); /** * Current page. * * @static * @var string $page Current page. */ public static $page; /** * Check if there is a session, * if there isn't one create it. * * @return static::singlton Overview Page Session. * * @uses \MainWP\Dashboard\MainWP_Overview */ public static function instance() { if ( null === static::$instance ) { static::$instance = new self(); } return static::$instance; } /** * MainWP_Overview constructor. * * Run each time the class is called. */ public function __construct() { add_action( 'admin_init', array( $this, 'admin_init' ) ); } /** * Hook admin init. */ public function admin_init() { $this->handle_update_screen_options(); } /** * Handle update screen options. */ public function handle_update_screen_options() { //phpcs:ignore -- NOSONAR - complex. $update_opts = false; if ( isset( $_POST['module_cost_tracker_summay_options_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['module_cost_tracker_summay_options_nonce'] ), 'module_cost_tracker_summay_options_nonce' ) ) { $update_opts = true; } if ( $update_opts ) { $show_wids = array(); if ( isset( $_POST['mainwp_show_widgets'] ) && is_array( $_POST['mainwp_show_widgets'] ) ) { $selected_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_show_widgets'] ) ); foreach ( $selected_wids as $name ) { $show_wids[ $name ] = 1; } } if ( isset( $_POST['mainwp_widgets_name'] ) && is_array( $_POST['mainwp_widgets_name'] ) ) { $name_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_widgets_name'] ) ); foreach ( $name_wids as $name ) { if ( ! isset( $show_wids[ $name ] ) ) { $show_wids[ $name ] = 0; } } } global $current_user; if ( $current_user ) { update_user_option( $current_user->ID, 'mainwp_module_cost_tracker_summary_show_widgets', $show_wids, true ); if ( isset( $_POST['reset_module_cost_tracker_summary_widgets_settings'] ) && ! empty( $_POST['reset_module_cost_tracker_summary_widgets_settings'] ) ) { update_user_option( $current_user->ID, 'mainwp_module_cost_tracker_summary_show_widgets', false, true ); update_user_option( $current_user->ID, 'mainwp_widgets_sorted_' . strtolower( 'mainwp_page_CostSummary' ), false, true ); } } } } /** * Method on_load_page() * * Run on page load. * * @param mixed $page Page name. */ public function on_load_page( $page ) { static::$page = $page; $val = get_user_option( 'screen_layout_' . $page ); if ( ! $val ) { global $current_user; update_user_option( $current_user->ID, 'screen_layout_' . $page, 2, true ); } wp_enqueue_script( 'common' ); wp_enqueue_script( 'wp-lists' ); wp_enqueue_script( 'postbox' ); wp_enqueue_script( 'dashboard' ); wp_enqueue_script( 'widgets' ); static::add_meta_boxes( $page ); add_filter( 'mainwp_header_actions_right', array( $this, 'screen_options' ), 10, 2 ); add_filter( 'mainwp_widget_boxes_show_widgets', array( $this, 'hook_show_widgets' ), 10, 2 ); } /** * Method screen_options() * * Create Page Settings button. * * @param mixed $input Page Settings button HTML. * * @return mixed Page Settings button. */ public function screen_options( $input ) { return $input . ' '; } /** * Method hook_show_widgets() * * Hook show widgets. * * @param array $values Show widgets settings. * @param string $page Page slug. * * @return array $values Show widgets settings. */ public function hook_show_widgets( $values, $page ) { if ( strtolower( $page ) === strtolower( static::$page ) ) { return get_user_option( 'mainwp_module_cost_tracker_summary_show_widgets' ); } return $values; } /** * Method add_meta_boxes() * * Add MainWP Overview Page Widgets. * * @param array $page Current page. * * @uses \MainWP\Dashboard\MainWP_System_Handler::apply_filters() * @uses \MainWP\Dashboard\MainWP_System_Utility::get_current_wpid() * @uses \MainWP\Dashboard\MainWP_UI::add_widget_box() * @uses \MainWP\Dashboard\MainWP_Connection_Status::get_class_name() * @uses \MainWP\Dashboard\MainWP_Recent_Pages::get_class_name() * @uses \MainWP\Dashboard\MainWP_Recent_Posts::get_class_name() * @uses \MainWP\Dashboard\MainWP_Security_Issues_Widget::get_class_name() */ public static function add_meta_boxes( $page ) { //phpcs:ignore -- NOSONAR - complex method. /** * Get getmetaboxes * * Adds metaboxes (widgets) to the Overview page. * * @since 4.6 */ $extMetaBoxs = array(); $extMetaBoxs = apply_filters( 'mainwp_cost_summary_getmetaboxes', $extMetaBoxs ); foreach ( $extMetaBoxs as $box ) { if ( isset( $box['plugin'] ) ) { $name = basename( $box['plugin'], '.php' ); static::$enable_widgets[ $name ] = true; } elseif ( ! empty( $box['widget_id'] ) ) { static::$enable_widgets[ $box['widget_id'] ] = true; } } /** * Unset unwanted Widgets * * Contains the list of enabled widgets and allows user to unset unwanted widgets. * * @param array $enable_widgets Array containing enabled widgets. * @param int $dashboard_siteid Child site (Overview) ID. * * @since 4.6 */ $values = apply_filters( 'mainwp_module_cost_tracker_summary_enabled_widgets', static::$enable_widgets, null ); static::$enable_widgets = array_merge( static::$enable_widgets, $values ); // Load the widget. if ( ! empty( static::$enable_widgets['cost_monthly_totals'] ) ) { MainWP_UI::add_widget_box( 'cost_monthly_totals', array( Cost_Tracker_Monthly_Totals::instance(), 'render' ), $page, array( 1, 1, 12, 40 ) ); } // Load the widget. if ( ! empty( static::$enable_widgets['cost_payments_left_this_month'] ) ) { MainWP_UI::add_widget_box( 'cost_payments_left_this_month', array( Cost_Tracker_Payment_Left_This_Month::instance(), 'render' ), $page, array( -1, -1, 6, 40 ) ); } // Load the widget. if ( ! empty( static::$enable_widgets['cost_category_totals'] ) ) { MainWP_UI::add_widget_box( 'cost_category_totals', array( Cost_Tracker_Category_Totals::instance(), 'render' ), $page, array( -1, -1, 6, 40 ) ); } // Load the widget. if ( ! empty( static::$enable_widgets['cost_upcomming_renewals'] ) ) { MainWP_UI::add_widget_box( 'cost_upcomming_renewals', array( Cost_Tracker_Upcoming_Renewals::instance(), 'render' ), $page, array( -1, -1, 4, 30 ) ); } // Load the widget. if ( ! empty( static::$enable_widgets['cost_yearly_renewals'] ) ) { MainWP_UI::add_widget_box( 'cost_yearly_renewals', array( Cost_Tracker_Yearly_Renewals::instance(), 'render' ), $page, array( -1, -1, 4, 30 ) ); } // Load the widget. if ( ! empty( static::$enable_widgets['cost_monthly_renewals'] ) ) { MainWP_UI::add_widget_box( 'cost_monthly_renewals', array( Cost_Tracker_Monthly_Renewals::instance(), 'render' ), $page, array( -1, -1, 4, 30 ) ); } $i = 1; foreach ( $extMetaBoxs as $metaBox ) { $enabled = true; if ( isset( $metaBox['plugin'] ) ) { $name = basename( $metaBox['plugin'], '.php' ); if ( isset( static::$enable_widgets[ $name ] ) && ! static::$enable_widgets[ $name ] ) { $enabled = false; } } $id = isset( $metaBox['id'] ) ? $metaBox['id'] : $i++; $id = 'advanced-' . $id; $layout = ! empty( $metaBox['layout'] ) && is_array( $metaBox['layout'] ) ? $metaBox['layout'] : array( -1, -1, 6, 30 ); if ( $enabled ) { MainWP_UI::add_widget_box( $id, $metaBox['callback'], $page, $layout ); } } } /** * Method get default logs filters() */ public static function get_default_filters() { $format = 'Y-m-d'; return array( 'ranges' => 'thismonth', 'dtsstart' => gmdate( $format, strtotime( gmdate( 'Y-m-01' ) ) ), 'dtsstop' => gmdate( $format, time() ), ); } /** * Method render_footer() * * Render Insights page footer. Closes the page container. */ public static function render_footer() { echo ''; } /** * Render summary page. * * @return void */ public function render_summary_page() { if ( ! \mainwp_current_user_can( 'dashboard', 'access_cost_summary_dashboard' ) ) { \mainwp_do_not_have_permissions( esc_html__( 'cost summary', 'mainwp' ) ); return; } $this->on_show_page(); } /** * Method on_show_page() * * When the page loads render the body content. */ public function on_show_page() { static::render_header(); static::render_summary_body(); } /** * Method render_header() * * Render Insights page header. */ public static function render_header() { $params = array( 'title' => esc_html__( 'Cost Summary', 'mainwp' ), 'which' => 'page_cost_summary', 'wrap_class' => 'mainwp-module-cost-summary-wrapper', ); MainWP_UI::render_top_header( $params ); } /** * Method render_summary_body() * * Render the summary costs content. */ public static function render_summary_body() { $screen = get_current_screen(); $costs_data = Cost_Tracker_DB::get_instance()->get_summary_data( array( 'sum_data' => 'all' ) ); ?>
' ); ?>
id, array( 'costs_data' => $costs_data, ) ); ?>
esc_html__( 'Upcoming Renewals', 'mainwp' ), 'cost_monthly_renewals' => esc_html__( 'Upcoming Monthly Renewals', 'mainwp' ), 'cost_yearly_renewals' => esc_html__( 'Upcoming Yearly Renewals', 'mainwp' ), 'cost_monthly_totals' => esc_html__( 'Monthly Totals', 'mainwp' ), 'cost_category_totals' => esc_html__( 'Annual Expense Distribution by Category', 'mainwp' ), 'cost_payments_left_this_month' => esc_html__( 'Payment Left For This Month', 'mainwp' ), ); $custom_opts = array(); /** * Filter: mainwp_module_cost_tracker_summary_widgets_screen_options * * Filters available widgets on the Overview page allowing users to unsent unwanted widgets. * * @since 4.6 */ $custom_opts = apply_filters( 'mainwp_module_cost_tracker_summary_widgets_screen_options', $custom_opts ); if ( is_array( $custom_opts ) && ! empty( $custom_opts ) ) { $default_widgets = array_merge( $default_widgets, $custom_opts ); } $show_widgets = get_user_option( 'mainwp_module_cost_tracker_summary_show_widgets' ); if ( ! is_array( $show_widgets ) ) { $show_widgets = array(); } /** * Action: mainwp_screen_options_modal_top * * Fires at the top of the Page Settings modal element. * * @since 4.6 */ do_action( 'mainwp_screen_options_modal_top', 'costsummary' ); ?>