commit 4005f936cdd3e5504f712fef840d3d663d51fbd7 Author: Stefan Kalscheuer Date: Sun Aug 14 13:23:27 2016 +0200 Initial commit. Extracted from former pull request on Statify project diff --git a/inc/statifyblacklist.class.php b/inc/statifyblacklist.class.php new file mode 100644 index 0000000..8049bd6 --- /dev/null +++ b/inc/statifyblacklist.class.php @@ -0,0 +1,120 @@ + 0, + 'referer' => '' + ) + ); + } + + /** + * Apply the blacklist filter if active + * + * @return TRUE if referer matches blacklist. + * + * @since 1.0.0 + */ + public static function apply_blacklist_filter() { + /* Skip if blacklist is inactive */ + if (self::$_options['active_referer'] != 1) { + return false; + } + + /* Extract relevant domain parts */ + $referer = strtolower( ( isset($_SERVER['HTTP_REFERER']) ? parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST) : '' ) ); + $referer = explode('.', $referer); + if( count($referer) >1 ) + $referer = implode('.', array_slice($referer, -2)); + else + $referer = implode('.', $referer); + + /* Get blacklist */ + $blacklist = explode("\r\n", self::$_options['referer']); + + /* Check blacklist */ + return in_array($referer, $blacklist); + } +} diff --git a/inc/statifyblacklist_admin.class.php b/inc/statifyblacklist_admin.class.php new file mode 100644 index 0000000..0076687 --- /dev/null +++ b/inc/statifyblacklist_admin.class.php @@ -0,0 +1,54 @@ +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; + } +} \ No newline at end of file diff --git a/inc/statifyblacklist_system.class.php b/inc/statifyblacklist_system.class.php new file mode 100644 index 0000000..c4fe7b3 --- /dev/null +++ b/inc/statifyblacklist_system.class.php @@ -0,0 +1,80 @@ +get_col( "SELECT blog_id FROM `$wpdb->blogs`" ); + + foreach ( $ids as $site_id ) { + switch_to_blog( $site_id ); + add_option( + 'statify-blacklist', + array() + ); + } + + restore_current_blog(); + } else { + add_option( + 'statify-blacklist', + array() + ); + } + } + + /** + * Plugin deactivation actions + * + * @since 1.0.0 + */ + + public static function deactivate() + { + } + + /** + * Plugin uninstall handler. + * + * @since 1.0.0 + */ + public static function uninstall() { + global $wpdb; + + if ( is_multisite() ) { + $old = get_current_blog_id(); + + // Todo: Use get_sites() in WordPress 4.6+ + $ids = $wpdb->get_col( "SELECT blog_id FROM `$wpdb->blogs`" ); + + foreach ( $ids as $id ) { + switch_to_blog( $id ); + delete_option('statify-blacklist'); + } + + switch_to_blog( $old ); + } + + delete_option('statify-blacklist'); + } +} \ No newline at end of file diff --git a/statifyblacklist.php b/statifyblacklist.php new file mode 100644 index 0000000..d69d387 --- /dev/null +++ b/statifyblacklist.php @@ -0,0 +1,74 @@ + (int)@$_POST['statifyblacklist']['active_referer'], + 'referer' => (string)@$_POST['statifyblacklist']['referer'] + ) + ); +} + +?> + +
+

+
+
    +
  • + +
  • +
  • + +
  • +
+ + +

+
+