settings->is_infinite_scroll() ) { add_action( 'wp_ajax_mwpal_infinite_scroll_events', array( $this, 'infinite_scroll_events' ) ); } if ( MWPAL_Extension\mwpal_extension()->is_mainwp_active() ) { if ( \version_compare( \MainWP_System::$version, '4.0-beta', '<' ) ) { add_action( 'mainwp_extensions_top_header_after_tab', array( $this, 'activitylog_settings_tab' ), 10, 1 ); add_action( 'admin_print_styles', array( $this, 'admin_print_styles' ) ); } else { add_filter( 'mainwp_page_navigation', array( $this, 'mwpal_extension_tabs' ), 10, 1 ); } } } /** * Setup extension tabs. */ public function setup_extension_tabs() { global $_mainwp_menu_active_slugs; $_mainwp_menu_active_slugs[ MWPAL_EXTENSION_NAME ] = MWPAL_EXTENSION_NAME; // Extension view URL. $extension_url = add_query_arg( 'page', MWPAL_EXTENSION_NAME, admin_url( 'admin.php' ) ); // Tab links. $mwpal_extension_tabs = array( 'activity-log' => array( 'name' => __( 'Activity Log', 'mwp-al-ext' ), 'link' => $extension_url, 'render' => array( $this, 'tab_activity_log' ), 'save' => array( $this, 'tab_activity_log_save' ), ), 'settings' => array( 'name' => __( 'Extension Settings', 'mwp-al-ext' ), 'link' => add_query_arg( 'tab', 'settings', $extension_url ), 'render' => array( $this, 'tab_settings' ), 'save' => array( $this, 'tab_settings_save' ), ), ); /** * `mwpal_extension_tabs` * * This filter is used to filter the tabs of WSAL settings page. * * Setting tabs structure: * $mwpal_extension_tabs['unique-tab-id'] = array( * 'name' => Name of the tab, * 'link' => Link of the tab, * 'render' => This function is used to render HTML elements in the tab, * 'name' => This function is used to save the related setting of the tab, * ); * * @param array $mwpal_extension_tabs - Array of extension tabs. * @param string $extension_url - URL of the extension. */ $this->mwpal_extension_tabs = apply_filters( 'mwpal_extension_tabs', $mwpal_extension_tabs, $extension_url ); // Get the current tab. $current_tab = filter_input( INPUT_GET, 'tab', FILTER_SANITIZE_STRING ); $this->current_tab = empty( $current_tab ) ? 'activity-log' : $current_tab; } /** * Returns current tab of the extension. * * @return string */ public function get_current_tab() { return $this->current_tab; } /** * Filter MainWP Dashboard Menu * * Modify MainWP Dashboard menu to include activity log's menu. * * @param array $mwp_sub_menu – MainWP Sub-Menu. * @return array */ public function mwp_left_menu_sub( $mwp_sub_menu ) { $activity_log_key = false; $extensions_menu = isset( $mwp_sub_menu['Extensions'] ) ? $mwp_sub_menu['Extensions'] : false; if ( $extensions_menu ) { foreach ( $extensions_menu as $key => $submenu ) { if ( MWPAL_EXTENSION_NAME === $submenu[1] ) { $activity_log_key = $key; break; } } // Set the menu name. $mwp_sub_menu['Extensions'][ $activity_log_key ][0] = __( 'Activity Log', 'mwp-al-ext' ); $sub_menu_before = array_slice( $mwp_sub_menu['mainwp_tab'], 0, 2 ); $sub_menu_after = array_splice( $mwp_sub_menu['mainwp_tab'], 2 ); $activity_log = $mwp_sub_menu['Extensions'][ $activity_log_key ]; $activity_log[3] = ''; $mwp_sub_menu['mainwp_tab'][] = $activity_log; $mwp_sub_menu['mainwp_tab'] = array_merge( $mwp_sub_menu['mainwp_tab'], $sub_menu_after ); unset( $mwp_sub_menu['Extensions'][ $activity_log_key ] ); } return $mwp_sub_menu; } /** * Filter MainWP Dropdown Menus * * Modify mainwp dropdown menu to include activity log's * dropdown menu. * * @param array $mwp_dropdown_menu – Dropdown menus of MainWP. * @return array */ public function mwp_sub_menu_dropdown( $mwp_dropdown_menu ) { $mwp_dropdown_menu[ MWPAL_EXTENSION_NAME ] = apply_filters( 'mwpal_left_submenu_dropdown', array( array( __( 'Extension Settings', 'mwp-al-ext' ), $this->mwpal_extension_tabs['settings']['link'], '', ), ) ); return $mwp_dropdown_menu; } /** * Extension left menu for MainWP v4 or later. * * @param array $mwpal_left_menu - Left menu array. * @return array */ public function mwpal_main_menu( $mwpal_left_menu ) { $sub_menu_before = array_slice( $mwpal_left_menu['mainwp_tab'], 0, 2 ); $sub_menu_after = array_splice( $mwpal_left_menu['mainwp_tab'], 2 ); $activity_log = array(); $activity_log[] = __( 'Activity Log', 'mwp-al-ext' ); $activity_log[] = MWPAL_EXTENSION_NAME; $activity_log[] = $this->mwpal_extension_tabs['activity-log']['link']; $mwpal_left_menu['mainwp_tab'][] = $activity_log; $mwpal_left_menu['mainwp_tab'] = array_merge( $mwpal_left_menu['mainwp_tab'], $sub_menu_after ); return $mwpal_left_menu; } /** * Extension sub left menu for MainWP v4 or later. * * @param array $mwpal_sub_left_menu - Left menu array. * @return array */ public function mwpal_main_menu_submenu( $mwpal_sub_left_menu ) { $mwpal_sub_left_menu[ MWPAL_EXTENSION_NAME ] = apply_filters( 'mwpal_main_menu_submenu', array( array( __( 'Extension Settings', 'mwp-al-ext' ), $this->mwpal_extension_tabs['settings']['link'], 'manage_options', ), ) ); return $mwpal_sub_left_menu; } /** * Add Activity Log Settings Tab. * * @param string $current_page – Path of the extension. */ public function activitylog_settings_tab( $current_page ) { $activity_log = basename( $current_page, '.php' ); if ( 'activity-log-mainwp' !== $activity_log ) { return; } $extension_tabs = $this->mwpal_extension_tabs; unset( $extension_tabs['activity-log'] ); // Due to the fact the activity log tab will already be added to the extension. foreach ( $extension_tabs as $tab_id => $tab ) : ?> current_tab; $extension_tabs = apply_filters( 'mwpal_page_navigation', array( array( 'title' => __( 'Extension Settings', 'mwp-al-ext' ), 'href' => $this->mwpal_extension_tabs['settings']['link'], 'active' => 'settings' === $this->current_tab, ), ) ); foreach ( $extension_tabs as $tab ) { $page_tabs[] = $tab; } return $page_tabs; } /** * Enqueue Styles in Head. */ public function enqueue_styles() { // Confirm extension page. global $pagenow; // @codingStandardsIgnoreStart $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : false; // @codingStandardsIgnoreEnd if ( 'admin.php' !== $pagenow ) { return; } elseif ( MWPAL_EXTENSION_NAME !== $page && 'ManageSitesActivityLog' !== $page ) { return; } if ( 'activity-log' === $this->current_tab ) { // Select2 styles. wp_enqueue_style( 'mwpal-select2-css', trailingslashit( MWPAL_BASE_URL ) . 'assets/js/dist/select2/select2.css', array(), '3.5.1' ); wp_enqueue_style( 'mwpal-select2-bootstrap-css', trailingslashit( MWPAL_BASE_URL ) . 'assets/js/dist/select2/select2-bootstrap.css', array(), '3.5.1' ); } // View styles. wp_enqueue_style( 'mwpal-view-styles', trailingslashit( MWPAL_BASE_URL ) . 'assets/css/dist/styles.build.css', array(), filemtime( trailingslashit( MWPAL_BASE_DIR ) . 'assets/css/dist/styles.build.css' ) ); } /** * Enqueue Scripts in Footer. */ public function enqueue_scripts() { // Confirm extension page. global $pagenow; // @codingStandardsIgnoreStart $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : false; // @codingStandardsIgnoreEnd if ( 'admin.php' !== $pagenow ) { return; } elseif ( MWPAL_EXTENSION_NAME !== $page && 'ManageSitesActivityLog' !== $page ) { return; } // Enqueue jQuery. wp_enqueue_script( 'jquery' ); if ( 'activity-log' === $this->current_tab ) { // Select2 script. wp_enqueue_script( 'mwpal-select2-js', trailingslashit( MWPAL_BASE_URL ) . 'assets/js/dist/select2/select2.min.js', array( 'jquery' ), '3.5.1', true ); } if ( in_array( $this->current_tab, array( 'activity-log', 'settings' ), true ) ) { wp_register_script( 'mwpal-view-script', trailingslashit( MWPAL_BASE_URL ) . 'assets/js/dist/index.js', array( 'jquery' ), filemtime( trailingslashit( MWPAL_BASE_DIR ) . 'assets/js/dist/index.js' ), false ); } // JS data. $script_data = array( 'ajaxURL' => admin_url( 'admin-ajax.php' ), 'scriptNonce' => wp_create_nonce( 'mwp-activitylog-nonce' ), 'currentTab' => $this->current_tab, 'selectSites' => __( 'Select Child Site(s)', 'mwp-al-ext' ), 'refreshing' => __( 'Refreshing Child Sites...', 'mwp-al-ext' ), 'retrieving' => __( 'Retrieving Logs...', 'mwp-al-ext' ), 'page' => isset( $this->page_args->page ) ? $this->page_args->page : false, 'siteId' => isset( $this->page_args->site_id ) ? $this->page_args->site_id : false, 'orderBy' => isset( $this->page_args->order_by ) ? $this->page_args->order_by : false, 'order' => isset( $this->page_args->order ) ? $this->page_args->order : false, 'getEvents' => isset( $this->page_args->get_events ) ? $this->page_args->get_events : false, 'searchTerm' => isset( $this->page_args->search_term ) ? $this->page_args->search_term : false, 'searchFilters' => isset( $this->page_args->search_filters ) ? $this->page_args->search_filters : false, 'infiniteScroll' => MWPAL_Extension\mwpal_extension()->settings->is_infinite_scroll(), ); wp_localize_script( 'mwpal-view-script', 'scriptData', $script_data ); wp_enqueue_script( 'mwpal-view-script' ); if ( 'activity-log' !== $this->current_tab ) { ?> settings->is_current_extension_page() ) { return; } if ( $this->current_tab && ! empty( $this->mwpal_extension_tabs[ $this->current_tab ]['save'] ) ) { call_user_func( $this->mwpal_extension_tabs[ $this->current_tab ]['save'] ); } } /** * Activity log form submit handler. */ public function tab_activity_log_save() { if ( isset( $_GET['_wpnonce'] ) ) { // Verify nonce for security. check_admin_referer( 'bulk-activity-logs' ); // Site id. $site_id = isset( $_GET['mwpal-site-id'] ) ? sanitize_text_field( wp_unslash( $_GET['mwpal-site-id'] ) ) : false; // Check for dashboard. if ( '0' === $site_id ) { $site_id = false; } elseif ( 'dashboard' !== $site_id ) { $site_id = (int) $site_id; } $this->get_list_view(); // Remove args array. $remove_args = array( '_wp_http_referer', '_wpnonce' ); $remove_args[] = ! $site_id ? 'mwpal-site-id' : false; $remove_args[] = ! $this->page_args->search_term ? 's' : false; $remove_args[] = ( ! is_int( $site_id ) && $this->page_args->get_events ) ? 'get-events' : false; $redirect_url = remove_query_arg( $remove_args ); if ( is_int( $site_id ) && ( $this->page_args->search_term || $this->page_args->search_filters ) ) { $redirect_url = add_query_arg( 'get-events', 'live', $redirect_url ); } wp_safe_redirect( $redirect_url ); exit(); } } /** * Settings form submit handler. */ public function tab_settings_save() { if ( isset( $_POST['_wpnonce'] ) && isset( $_POST['submit'] ) ) { // Verify nonce for security. check_admin_referer( 'mwpal-settings-nonce' ); // Get form options. $events_nav_type = isset( $_POST['events-nav-type'] ) ? sanitize_text_field( wp_unslash( $_POST['events-nav-type'] ) ) : false; $timezone = isset( $_POST['timezone'] ) ? sanitize_text_field( wp_unslash( $_POST['timezone'] ) ) : false; $type_username = isset( $_POST['type_username'] ) ? sanitize_text_field( wp_unslash( $_POST['type_username'] ) ) : false; $child_site_events = isset( $_POST['child-site-events'] ) ? (int) sanitize_text_field( wp_unslash( $_POST['child-site-events'] ) ) : false; $events_frequency = isset( $_POST['events-frequency'] ) ? (int) sanitize_text_field( wp_unslash( $_POST['events-frequency'] ) ) : false; $events_global_sync = isset( $_POST['global-sync-events'] ); $columns = isset( $_POST['columns'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['columns'] ) ) : false; $wsal_child_sites = isset( $_POST['mwpal-wsal-child-sites'] ) ? sanitize_text_field( wp_unslash( $_POST['mwpal-wsal-child-sites'] ) ) : false; $events_pruning = isset( $_POST['events-pruning'] ) ? sanitize_text_field( wp_unslash( $_POST['events-pruning'] ) ) : false; $pruning_date = ( isset( $_POST['events-pruning-date'] ) && 'enabled' === $events_pruning ) ? sanitize_text_field( wp_unslash( $_POST['events-pruning-date'] ) ) : false; $pruning_unit = ( isset( $_POST['events-pruning-unit'] ) && 'enabled' === $events_pruning ) ? sanitize_text_field( wp_unslash( $_POST['events-pruning-unit'] ) ) : false; // Get enabled events. $enabled = isset( $_POST['mwpal-event'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['mwpal-event'] ) ) : array(); $enabled = array_map( 'intval', $enabled ); $disabled = array(); $mwp_events = MWPAL_Extension\mwpal_extension()->alerts->get_alerts_by_sub_category( __( 'MainWP', 'mwp-al-ext' ) ); foreach ( $mwp_events as $event ) { if ( ! in_array( $event->type, $enabled, true ) ) { $disabled[] = $event->type; } } // Set options. MWPAL_Extension\mwpal_extension()->settings->set_events_type_nav( $events_nav_type ); MWPAL_Extension\mwpal_extension()->settings->set_timezone( $timezone ); MWPAL_Extension\mwpal_extension()->settings->set_type_username( $type_username ); MWPAL_Extension\mwpal_extension()->settings->set_child_site_events( $child_site_events ); MWPAL_Extension\mwpal_extension()->settings->set_events_frequency( $events_frequency ); MWPAL_Extension\mwpal_extension()->settings->set_events_global_sync( $events_global_sync ); MWPAL_Extension\mwpal_extension()->settings->set_columns( $columns ); MWPAL_Extension\mwpal_extension()->settings->set_wsal_child_sites( ! empty( $wsal_child_sites ) ? explode( ',', $wsal_child_sites ) : false ); MWPAL_Extension\mwpal_extension()->settings->set_disabled_events( $disabled ); MWPAL_Extension\mwpal_extension()->settings->set_events_pruning( $events_pruning ); MWPAL_Extension\mwpal_extension()->settings->set_pruning_date( $pruning_date, $pruning_unit ); } } /** * Render Header. */ public function header() { // The "mainwp-pageheader-extensions" action is used to render the tabs on the Extensions screen. // It's used together with mainwp-pagefooter-extensions and mainwp-getextensions. do_action( 'mainwp-pageheader-extensions', MWPAL_Extension\mwpal_extension()->get_child_file() ); } /** * Render Content. */ public function content() { // Fetch all child-sites. $this->mwp_child_sites = MWPAL_Extension\mwpal_extension()->settings->get_mwp_child_sites(); // Get MainWP child sites. $this->wsal_child_sites = MWPAL_Extension\mwpal_extension()->settings->get_wsal_child_sites(); // Get child sites with WSAL installed. if ( MWPAL_Extension\mwpal_extension()->is_child_enabled() ) : ?>