21600, // seconds. 'display' => __( 'Four time by Day', 'newstatpress' ), ); $schedules['weekly'] = array( 'interval' => 604800, 'display' => __( 'Once a Week', 'newstatpress' ), ); $schedules['monthly'] = array( 'interval' => 2635200, 'display' => __( 'Once a Month', 'newstatpress' ), ); return $schedules; } add_filter( 'cron_schedules', 'nsp_cron_intervals' ); /** * Calculate nsp_calculate_epoch_offset_time * * @param int $t1 time 1. * @param int $t2 time 2. * @param string $output_unit unit for output. * @return int delta */ function nsp_calculate_epoch_offset_time( $t1, $t2, $output_unit ) { // to complete with more output_unit. $offset_time_in_seconds = abs( $t1 - $t2 ); if ( 'day' === $output_unit ) { $offset_time = $offset_time_in_seconds / 86400; } if ( 'hour' === $output_unit ) { $offset_time = $offset_time_in_seconds / 3600; } else { $offset_time = $offset_time_in_seconds; } return $offset_time; } /** * Get the number of days since installation * * @return int the number */ function nsp_get_days_installed() { global $nsp_option_vars; $name = $nsp_option_vars['settings']['name']; $settings = get_option( $name ); $install_date = empty( $settings['install_date'] ) ? time() : $settings['install_date']; $num_days_inst = nsp_calculate_epoch_offset_time( $install_date, time(), 'day' ); if ( $num_days_inst < 1 ) { $num_days_inst = 1; } return $num_days_inst; } // --------------------------------------------------------------------------- // URL Functions // --------------------------------------------------------------------------- /** * Extract the feed from the given url * * @param string $url the url to parse. * @return the extracted url *************************************/ function nsp_extract_feed_from_url( $url ) { list($null,$q) = array_pad( explode( '?', $url, 2 ), 2, null ); if ( strpos( $q, '&' ) !== false ) { list($res,$null) = explode( '&', $q ); } else { $res = $q; } return $res; } /** * Get the url */ function nsp_get_url() { $url = nsp_connexion_is_ssl() ? 'https://' : 'http://'; if ( isset( $_SERVER['REQUEST_URI'] ) ) { $url .= NSP_SERVER_NAME . sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ); } return esc_url( $url ); } /** * Fix poorly formed URLs so as not to throw errors or cause problems * * @param string $url the url. * @param string $rem_frag the frag. * @param string $rem_query the query. * @param string $rev the rev. * @return $url the url */ function nsp_fix_url( $url, $rem_frag = false, $rem_query = false, $rev = false ) { $url = trim( $url ); /* Too many forward slashes or colons after http */ $url = preg_replace( '~^(https?)\:+/+~i', '$1://', $url ); /* Too many dots */ $url = preg_replace( '~\.+~i', '.', $url ); /* Too many slashes after the domain */ $url = preg_replace( '~([a-z0-9]+)/+([a-z0-9]+)~i', '$1/$2', $url ); /* Remove fragments */ if ( ! empty( $rem_frag ) && strpos( $url, '#' ) !== false ) { $url_arr = explode( '#', $url ); $url = $url_arr[0]; } /* Remove query string completely */ if ( ! empty( $rem_query ) && strpos( $url, '?' ) !== false ) { $url_arr = explode( '?', $url ); $url = $url_arr[0]; } /* Reverse */ if ( ! empty( $rev ) ) { $url = strrev( $url ); } return $url; } /** * Get query string array from URL * * @param string $url the url. */ function nsp_get_query_args( $url ) { if ( empty( $url ) ) { return array(); } $query_str = nsp_get_query_string( $url ); parse_str( $query_str, $args ); return $args; } /** * Get query string * * @param string $url the url. */ function nsp_get_query_string( $url ) { /*** * Get query string from URL * Filter URLs with nothing after http */ if ( empty( $url ) || preg_match( '~^https?\:*/*$~i', $url ) ) { return ''; } /* Fix poorly formed URLs so as not to throw errors when parsing */ $url = nsp_fix_url( $url ); /* NOW start parsing */ $parsed = @wp_parse_url( $url ); /* Filter URLs with no query string */ if ( empty( $parsed['query'] ) ) { return ''; } $query_str = $parsed['query']; return $query_str; } /** * Admin nag notices */ function nsp_admin_nag_notices() { global $current_user; $nag_notices = get_user_meta( $current_user->ID, 'newstatpress_nag_notices', true ); if ( ! empty( $nag_notices ) ) { $nid = $nag_notices['nid']; $style = $nag_notices['style']; $timenow = time(); $url = nsp_get_url(); $query_args = nsp_get_query_args( $url ); $query_str = '?' . http_build_query( array_merge( $query_args, array( 'newstatpress_hide_nag' => '1', 'nid' => $nid, ) ) ); $query_str_con = 'QUERYSTRING'; $notice = str_replace( array( $query_str_con ), array( $query_str ), $nag_notices['notice'] ); global $pagenow; $page_nsp = 0; if ( isset( $_GET['page'] ) ) { switch ( $_GET['page'] ) { case 'nsp-main': $page_nsp = 1; break; case 'nsp-details': $page_nsp = 1; break; case 'nsp-visits': $page_nsp = 1; break; case 'nsp-search': $page_nsp = 1; break; case 'nsp-tools': $page_nsp = 1; break; case 'nsp-options': $page_nsp = 1; break; case 'nsp-credits': $page_nsp = 1; break; default: $page_nsp = 0; break; } } // Display NSP box if user are in plugins page or nsp plugins. if ( ( 'n03' !== $nid && 1 === $page_nsp ) || ( 'n03' === $nid && 'plugins.php' === $pagenow ) ) { ?>
' . __( 'Since the introduction of new method for speed up the display (needed for dashboard and overview), you must activate the external API in Options>Api page.', 'newstatpress' ) . '
'; $notice_text .= __( 'This major change was necessary in aim to improve the plugin for users with big database. In addition, it will allow to be more flexible about the graphical informations in next versions.', 'newstatpress' ) . ''; $status['currentnag'] = true; $status['news'] = false; } if ( empty( $status['currentnag'] ) && ( empty( $status['lastnag'] ) || $status['lastnag'] <= $timenow - 1209600 ) ) { if ( empty( $status['vote'] ) && $num_days_inst >= $votedate ) { $nid = 'n01'; $style = 'notice'; $notice_text = '' . __( 'It looks like you\'ve been using NewStatPress for a while now. That\'s great!', 'newstatpress' ) . '
'; $notice_text .= '' . __( 'If you find this plugin useful, would you take a moment to give it a rating on WordPress.org?', 'newstatpress' );
$notice_text .= '
(' . __( 'NB: please open a ticket on the support page instead of adding it to your rating commentaries if you wish to report an issue with the plugin, it will be processed more quickly by the team.', 'newstatpress' ) . ')
' . __( 'You\'ve been using NewStatPress for several months now. We hope that means you like it and are finding it helpful.', 'newstatpress' ) . '
'; $notice_text .= '' . __( 'NewStatPress is provided for free and maintained only on free time. If you like the plugin, consider a donation to help further its development', 'newstatpress' ) . '
'; $notice_text .= '' . __( 'Yes, I\'d like to donate!', 'newstatpress' ) . ''; $notice_text .= ' '; $notice_text .= '' . __( 'I already did!', 'newstatpress' ) . ''; $status['currentnag'] = true; $status['donate'] = false; } } if ( ! empty( $status['currentnag'] ) ) { add_action( 'admin_notices', 'nsp_admin_nag_notices' ); $new_nag_notice = array( 'nid' => $nid, 'style' => $style, 'notice' => $notice_text, ); update_user_meta( $current_user->ID, 'newstatpress_nag_notices', $new_nag_notice ); update_user_meta( $current_user->ID, 'newstatpress_nag_status', $status ); } } /** * Admin notices */ function nsp_admin_notices() { $admin_notices = get_option( 'newstatpress_admin_notices' ); if ( ! empty( $admin_notices ) ) { $style = $admin_notices['style']; $notice = $admin_notices['notice']; $query_str_con = 'QUERYSTRING'; echo '' . esc_html( $notice ) . '