GitHub'; } return $links; } /** * Add plugin action links * * @param array $input Registered links * * @return array Merged links * * @since 1.0.0 */ public static function plugin_actions_links( $links, $file ) { $base = self::$multisite ? network_admin_url( 'settings.php' ) : admin_url( 'options-general.php' ); if ( $file == STATIFYBLACKLIST_BASE && current_user_can( 'manage_options' ) ) { array_unshift( $links, sprintf( '%s', esc_attr( add_query_arg( 'page', 'statify-blacklist', $base ) ), __( 'Settings' ) ) ); } return $links; } /** * Filter database for cleanup. * * @since 1.1.0 * @changed 1.4.0 */ public static function cleanup_database() { /* Check user permissions */ if ( ! current_user_can( 'manage_options' ) && ! ( defined( 'DOING_CRON' ) && DOING_CRON ) ) { die( __( 'Are you sure you want to do this?' ) ); } global $wpdb; if ( isset( self::$_options['referer_regexp'] ) && self::$_options['referer_regexp'] > 0 ) { /* Merge given regular expressions into one */ $refererRegexp = implode( "|", array_keys( self::$_options['referer'] ) ); } else { /* Sanitize URLs */ $referer = self::sanitizeURLs( self::$_options['referer'] ); /* Build filter regexp */ $refererRegexp = str_replace( '.', '\.', implode( '|', array_flip( $referer ) ) ); } if ( ! empty( $refererRegexp ) ) { /* Execute filter on database */ $wpdb->query( $wpdb->prepare( "DELETE FROM `$wpdb->statify` WHERE " . ( ( self::$_options['referer_regexp'] == 1 ) ? " BINARY " : "" ) . "referrer REGEXP %s", $refererRegexp ) ); /* Optimize DB */ $wpdb->query( "OPTIMIZE TABLE `$wpdb->statify`" ); /* Delete transient statify data */ delete_transient( 'statify_data' ); } } /** * Sanitize URLs and remove empty results * * @param $urls array given array of URLs * * @return array sanitized array * * @since 1.1.1 * @changed 1.2.0 */ private static function sanitizeURLs( $urls ) { return array_flip( array_filter( array_map( function ( $r ) { return preg_replace( '/[^\da-z\.-]/i', '', filter_var( $r, FILTER_SANITIZE_URL ) ); }, array_flip( $urls ) ) ) ); } }