0 ) { foreach ( self::$errors as $error ) { echo '

' . esc_html( $error ) . '

'; } } elseif ( sizeof( self::$messages ) > 0 ) { foreach ( self::$messages as $message ) { echo '

' . esc_html( $message ) . '

'; } } } /** * Add an admin page */ public static function add_menu_page( ) { add_menu_page( 'Ajax Live Search', 'Ajax Live Search', 'manage_options', 'als-admin-page', 'Als_Admin_Settings::als_upgrade_screen_content', false, '2'); add_submenu_page( 'als-admin-page', 'Search Statistics', 'Statistics', 'manage_options', 'als-statistics', 'Als_Admin_Settings::show_statistics_page' ); add_submenu_page( 'als-admin-page', 'Als Settings', 'Settings', 'manage_options', 'als-settings', 'Als_Admin_Settings::output' ); add_dashboard_page( 'Welcome To Ajax Live Search', 'Welcome To Ajax Live Search', 'read', 'als-welcome-screen-about', 'Als_Admin_Settings::als_welcome_screen_content' ); /*add_submenu_page( 'als-admin-page', 'Get in touch', 'Contact Us', 'read', 'als-contact-screen', 'Als_Admin_Settings::als_contact_screen_content' );*/ } /** * Display the statistics page */ public static function show_statistics_page( ) { $dummy = false; $tabs = array('basic'=>'Basic'); // Graphs not available in lite mode $current_tab = 'basic'; if(isset($_GET['action']) && $_GET['action']=='dummy'){ als_dummy_data(); $dummy = true; } ?>

().

().

( 0')?>)

0','searches DESC' ); ?>

0','hits DESC' ); ?>

0','hits ASC' ); ?>
prefix . "als_log"; $sql = "SELECT * FROM $searches_log_table WHERE $conditions ORDER BY $order_by LIMIT $limit"; $results = $wpdb->get_results($sql); if(count($results)<1){ if(!$no_results_msg) { _e('No stats to show.','als'); } else { echo $no_results_msg; } return; } ?> time); echo ""; echo ""; echo ""; echo ""; echo ""; } ?>
Query Modified Searches Results Last Search
$single->query$single->modified$single->searches$single->hits$time
prefix . "als_log"; $sql = "SELECT SUM(searches) as total FROM $searches_log_table WHERE $where"; $results = $wpdb->get_results($sql); if ($echo) { echo intval($results[0]->total); } return intval($results[0]->total); } /** * Get a setting from the settings API. * * @param mixed $option_name the name of the option to retrieve * @param mixed $default the default value of the option name * @return string */ public static function get_option( $option_name, $default = '' ) { $option_value = get_option( $option_name, null ); if ( is_array( $option_value ) ) { $option_value = array_map( 'stripslashes', $option_value ); } elseif ( ! is_null( $option_value ) ) { $option_value = stripslashes( $option_value ); } return $option_value === null ? $default : $option_value; } /** * Settings page. * * Handles the display of the main als settings page in admin. */ public static function output() { global $current_tab; do_action( 'als_settings_start' ); // Include settings pages self::get_settings_pages(); // Get current tab $current_tab = empty( $_GET['tab'] ) ? 'general' : sanitize_title( $_GET['tab'] ); // Save settings if data has been posted if ( ! empty( $_POST ) ) { self::save(); } // Add any posted messages if ( ! empty( $_GET['als_error'] ) ) { self::add_error( stripslashes( $_GET['als_error'] ) ); } if ( ! empty( $_GET['als_message'] ) ) { self::add_message( stripslashes( $_GET['als_message'] ) ); } // Get tabs for the settings page $tabs = apply_filters( 'als_settings_tabs_array', array() ); include ALS__PLUGIN_DIR . 'includes/admin/html-admin-settings.php'; } /** * Save the settings. */ public static function save() { global $current_tab; if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'als-settings' ) ) { die( __( 'Action failed. Please refresh the page and retry.', 'als' ) ); } // Trigger actions do_action( 'als_settings_save_' . $current_tab ); do_action( 'als_update_options_' . $current_tab ); do_action( 'als_update_options' ); self::add_message( __( 'Your settings have been saved.', 'als' ) ); do_action( 'als_settings_saved' ); } /** * Include the settings page classes. */ public static function get_settings_pages() { if ( empty( self::$settings ) ) { $settings = array(); include_once( ALS__PLUGIN_DIR . 'includes/admin/class-als-settings-page.php' ); $settings[] = include( ALS__PLUGIN_DIR . 'includes/admin/general.php' ); $settings[] = include( ALS__PLUGIN_DIR . 'includes/admin/searching.php'); $settings[] = include( ALS__PLUGIN_DIR . 'includes/admin/result_pages.php' ); self::$settings = apply_filters( 'als_get_settings_pages', $settings ); } return self::$settings; } /** * Output admin fields. * * Loops though the als options array and outputs each field. * * @param array $options Opens array to output */ public static function output_fields( $options ) { foreach ( $options as $value ) { if ( ! isset( $value['type'] ) ) { continue; } if ( ! isset( $value['id'] ) ) { $value['id'] = ''; } if ( ! isset( $value['title'] ) ) { $value['title'] = isset( $value['name'] ) ? $value['name'] : ''; } if ( ! isset( $value['class'] ) ) { $value['class'] = ''; } if ( ! isset( $value['css'] ) ) { $value['css'] = ''; } if ( ! isset( $value['default'] ) ) { $value['default'] = ''; } if ( ! isset( $value['desc'] ) ) { $value['desc'] = ''; } if ( ! isset( $value['desc_tip'] ) ) { $value['desc_tip'] = false; } if ( ! isset( $value['placeholder'] ) ) { $value['placeholder'] = ''; } // Custom attribute handling $custom_attributes = array(); if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) { foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) { $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"'; } } // Description handling $field_description = self::get_field_description( $value ); extract( $field_description ); // Switch based on type switch ( $value['type'] ) { // Section Titles case 'title': if ( ! empty( $value['title'] ) ) { echo '

' . esc_html( $value['title'] ) . '

'; } if ( ! empty( $value['desc'] ) ) { echo wpautop( wptexturize( wp_kses_post( $value['desc'] ) ) ); } echo ''. "\n\n"; if ( ! empty( $value['id'] ) ) { do_action( 'als_settings_' . sanitize_title( $value['id'] ) ); } break; // Section Ends case 'sectionend': if ( ! empty( $value['id'] ) ) { do_action( 'als_settings_' . sanitize_title( $value['id'] ) . '_end' ); } echo '
'; if ( ! empty( $value['id'] ) ) { do_action( 'als_settings_' . sanitize_title( $value['id'] ) . '_after' ); } break; // Standard text inputs and subtypes like 'number' case 'text': case 'email': case 'number': case 'color' : case 'password' : $type = $value['type']; $option_value = self::get_option( $value['id'], $value['default'] ); ?> />
$value['id'], 'id' => $value['id'], 'sort_column' => 'menu_order', 'sort_order' => 'ASC', 'show_option_none' => ' ', 'class' => $value['class'], 'echo' => false, 'selected' => absint( self::get_option( $value['id'] ) ) ); if ( isset( $value['args'] ) ) { $args = wp_parse_args( $value['args'], $args ); } ?> ' . wp_kses_post( $description ) . '

'; } elseif ( $description && in_array( $value['type'], array( 'checkbox' ) ) ) { $description = wp_kses_post( $description ); } elseif ( $description ) { $description = '' . wp_kses_post( $description ) . ''; } if ( $tooltip_html && in_array( $value['type'], array( 'checkbox' ) ) ) { $tooltip_html = '

' . $tooltip_html . '

'; } elseif ( $tooltip_html ) { $tooltip_html = als_help_tip( $tooltip_html ); } return array( 'description' => $description, 'tooltip_html' => $tooltip_html ); } /** * Save admin fields. * * * @param array $options * @return bool */ public static function save_fields( $options ) { if ( empty( $_POST ) ) { return false; } // Options to update will be stored here and saved later $update_options = array(); // Loop options and get values to save foreach ( $options as $option ) { if ( ! isset( $option['id'] ) || ! isset( $option['type'] ) ) { continue; } // Get posted value if ( strstr( $option['id'], '[' ) ) { parse_str( $option['id'], $option_name_array ); $option_name = current( array_keys( $option_name_array ) ); $setting_name = key( $option_name_array[ $option_name ] ); $raw_value = isset( $_POST[ $option_name ][ $setting_name ] ) ? wp_unslash( $_POST[ $option_name ][ $setting_name ] ) : null; } else { $option_name = $option['id']; $setting_name = ''; $raw_value = isset( $_POST[ $option['id'] ] ) ? wp_unslash( $_POST[ $option['id'] ] ) : null; } // Format the value based on option type switch ( $option['type'] ) { case 'checkbox' : $value = is_null( $raw_value ) ? 'no' : 'yes'; break; case 'textarea' : $value = wp_kses_post( trim( $raw_value ) ); break; case 'multiselect' : case 'multi_select_countries' : $value = array_filter( array_map( 'als_clean', (array) $raw_value ) ); break; case 'image_width' : $value = array(); if ( isset( $raw_value['width'] ) ) { $value['width'] = als_clean( $raw_value['width'] ); $value['height'] = als_clean( $raw_value['height'] ); $value['crop'] = isset( $raw_value['crop'] ) ? 1 : 0; } else { $value['width'] = $option['default']['width']; $value['height'] = $option['default']['height']; $value['crop'] = $option['default']['crop']; } break; default : $value = als_clean( $raw_value ); break; } /** * Sanitize the value of an option. */ $value = apply_filters( 'als_admin_settings_sanitize_option', $value, $option, $raw_value ); /** * Sanitize the value of an option by option name. */ $value = apply_filters( "als_admin_settings_sanitize_option_$option_name", $value, $option, $raw_value ); if ( is_null( $value ) ) { continue; } // Check if option is an array and handle that differently to single values. if ( $option_name && $setting_name ) { if ( ! isset( $update_options[ $option_name ] ) ) { $update_options[ $option_name ] = get_option( $option_name, array() ); } if ( ! is_array( $update_options[ $option_name ] ) ) { $update_options[ $option_name ] = array(); } $update_options[ $option_name ][ $setting_name ] = $value; } else { $update_options[ $option_name ] = $value; } } // Save all options in our array foreach ( $update_options as $name => $value ) { update_option( $name, $value ); } return true; } }