never stop the refactoring

This commit is contained in:
Matthias Kretschmann 2013-11-09 14:38:40 +01:00
parent 35a6106257
commit 4b4dd1bc2b
31 changed files with 523 additions and 283 deletions

1
.gitignore vendored
View File

@ -1 +0,0 @@
design/

View File

@ -27,12 +27,13 @@ input.button-primary {
#badgedoptions .icon32 {
background-image: url(../img/icon-badged-32.png);
background-repeat: no-repeat;
background-position: center center;
}
#badgedoptions p.submit {
background: #fcfcfc;
padding: .7em .5em;
border-top: 1px solid #f7f7f7;
border-top: 1px solid #eee;
margin-top: 4em;
margin-bottom: 3em;
}

View File

Before

Width:  |  Height:  |  Size: 964 B

After

Width:  |  Height:  |  Size: 964 B

View File

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -0,0 +1,154 @@
<?php
/**
* Badged
*
* @package Badged
* @author Matthias Kretschmann <m@kretschmann.io>
* @license GPL-2.0+
* @link http://kremalicious.com/badged/
* @copyright 2013 Matthias Kretschmann
*/
/**
* Plugin class.
*
*
* @package Badged_Admin
* @author Matthias Kretschmann <m@kretschmann.io>
*/
class Badged_Admin {
/**
* Instance of this class.
*
* @since 2.0.0
* @var object
*/
protected static $instance = null;
/**
* Slug of the plugin screen.
*
* @since 2.0.0
* @var string
*/
protected $plugin_screen_hook_suffix = null;
/**
* Initialize the plugin by loading admin scripts & styles and adding a
* settings page and menu.
*
* @since 2.0.0
*/
private function __construct() {
$plugin = Badged::get_instance();
$this->plugin_slug = $plugin->get_plugin_slug();
// Load admin style sheet
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
// Add the options page and menu item.
add_action( 'admin_menu', array( $this, 'add_plugin_admin_menu' ) );
// Add an action link pointing to the options page.
$plugin_basename = plugin_basename( plugin_dir_path( __DIR__ ) . $this->plugin_slug . '.php' );
add_filter( 'plugin_action_links_' . $plugin_basename, array( $this, 'add_action_links' ) );
/*
* Do Custom Stuff
*
*/
}
/**
* Return an instance of this class.
*
* @since 2.0.0
* @return object A single instance of this class.
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Register and enqueue admin-specific style sheet.
*
* @since 2.0.0
* @return null Return early if no settings page is registered.
*/
public function enqueue_admin_styles() {
if ( ! isset( $this->plugin_screen_hook_suffix ) ) {
return;
}
$screen = get_current_screen();
if ( $screen->id == $this->plugin_screen_hook_suffix ) {
wp_enqueue_style( $this->plugin_slug .'-admin-styles', BADGED_URL . 'admin/assets/css/admin.css', array(), Badged::VERSION );
}
wp_enqueue_style( $this->plugin_slug .'-badged-styles', BADGED_URL . 'admin/assets/css/badged.css', array(), Badged::VERSION );
}
/**
* Register the administration menu for this plugin into the WordPress Dashboard menu.
* @since 2.0.0
*/
public function add_plugin_admin_menu() {
$this->plugin_screen_hook_suffix = add_options_page(
__( 'Badged Settings', $this->plugin_slug ),
__( 'Badged', $this->plugin_slug ),
'read',
$this->plugin_slug,
array( $this, 'display_plugin_admin_page' )
);
}
/**
* Render the settings page for this plugin.
* @since 2.0.0
*/
public function display_plugin_admin_page() {
include_once( 'views/admin.php' );
}
/**
* Add settings action link to the plugins page.
*
* @since 2.0.0
*/
public function add_action_links( $links ) {
return array_merge(
array(
'settings' => '<a href="' . admin_url( 'options-general.php?page=' . $this->plugin_slug ) . '">' . __( 'Settings', $this->plugin_slug ) . '</a>'
),
$links
);
}
/**
* WordPress Actions: http://codex.wordpress.org/Plugin_API#Actions
* Action Reference: http://codex.wordpress.org/Plugin_API/Action_Reference
*
* @since 2.0.0
*/
public function action_method_name() {
// TODO: Define your action hook callback here
}
}

View File

@ -0,0 +1,41 @@
<?php
/**
* Represents the view for the administration dashboard.
*
* This includes the header, options, and other information that should provide
* The User Interface to the end user.
*
* @package Badged
* @author Matthias Kretschmann <m@kretschmann.io>
* @license GPL-2.0+
* @link http://kremalicious.com/badged/
* @copyright 2013 Matthias Kretschmann
*/
?>
<div class="wrap" id="badgedoptions">
<header>
<?php screen_icon(); ?>
<h2><?php echo esc_html( get_admin_page_title() ); ?></h2>
</header>
<?php settings_errors(); ?>
<form action="options.php" method="POST">
<?php
settings_fields( 'badged_setting' );
do_settings_sections( 'badged_view_section' );
submit_button(); ?>
</form>
</div>
<footer>
<p>
<?php _e('Thanks for using', 'bdgd'); ?> <a href="http://www.kremalicious.com/2011/12/badged/" title="Badged Blog Post">Badged</a> (<a href="https://github.com/kremalicious/Badged/" title="Badged On Github">github</a>) &middot; <a href="http://krlc.us/givecoffee"><strong><?php _e('Donate', 'bdgd'); ?></strong></a>
<span class="alignright"><?php _e('Created by', 'bdgd'); ?> <a href="http://mkretschmann.com">Matthias Kretschmann</a> (<a href="https://twitter.com/kremalicious">@kremalicious</a>)</span>
</p>
</footer>
</div>

View File

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View File

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -6,7 +6,7 @@
* Just activate and enjoy the red badges.
*
* @package Badged
* @author Matthias Kretschmann <desk@kremalicious.com>
* @author Matthias Kretschmann <m@kretschmann.io>
* @license GPL-2.0+
* @link http://kremalicious.com/badged/
* @copyright 2013 Matthias Kretschmann
@ -17,10 +17,10 @@
* Description: Transforms the standard WordPress update & comment notification badges into iOS-styled ones. Just activate and enjoy the red badges.
* Author: Matthias Kretschmann
* Author URI: http://matthiaskretschmann.com
* Version: 1.0.0
* Version: 2.0.0
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Domain Path: /lang
* Domain Path: /languages
* Text Domain: bdgd
*/
@ -52,6 +52,9 @@ else if (isset($network_plugin)) {
}
// Define constants
if ( ! defined( 'BADGED_FILE' ) ){
define('BADGED_FILE', $badged_plugin_file);
}
if ( ! defined( 'BADGED_URL' ) ){
define('BADGED_URL', plugin_dir_url($badged_plugin_file));
}
@ -65,13 +68,26 @@ if ( ! defined( 'BADGED_BASENAME' ) ){
/**
* Let's roll
*
* @since 1.0.0
* @since 2.0.0
*
*/
require_once( BADGED_PATH . 'class-badged.php' );
//
// Public Stuff
//
require_once( BADGED_PATH . '/public/class-badged.php' );
register_activation_hook( $badged_plugin_file, array( 'Badged', 'activate' ) );
register_deactivation_hook( $badged_plugin_file, array( 'Badged', 'deactivate' ) );
Badged::get_instance();
add_action( 'plugins_loaded', array( 'Badged', 'get_instance' ) );
//
// Admin Stuff
//
if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
require_once( BADGED_PATH . '/admin/class-badged-admin.php' );
add_action( 'plugins_loaded', array( 'Badged_Admin', 'get_instance' ) );
}

235
badged/public/class-badged.php Executable file
View File

@ -0,0 +1,235 @@
<?php
/**
* Badged
*
* @package Badged
* @author Matthias Kretschmann <m@kretschmann.io>
* @license GPL-2.0+
* @link http://kremalicious.com/badged/
* @copyright 2013 Matthias Kretschmann
*/
/**
* Plugin class.
*
* @package Badged
* @author Matthias Kretschmann <m@kretschmann.io>
*/
class Badged {
/**
* Plugin version, used for cache-busting of style and script file references.
*
* @since 2.0.0
* @var string
*/
const VERSION = '2.0.0';
/**
*
* Unique identifier.
*
* @since 2.0.0
* @var string
*/
protected $plugin_slug = 'badged';
/**
* Instance of this class.
*
* @since 2.0.0
* @var object
*/
protected static $instance = null;
/**
* Initialize the plugin by setting localization and loading public scripts
* and styles.
*
* @since 2.0.0
*/
private function __construct() {
// Load plugin text domain
add_action( 'init', array( $this, 'load_badged_textdomain' ) );
// Activate plugin when new blog is added
add_action( 'wpmu_new_blog', array( $this, 'activate_new_site' ) );
}
/**
* Return the plugin slug.
*
* @since 2.0.0
*@return Plugin slug variable.
*/
public function get_plugin_slug() {
return $this->plugin_slug;
}
/**
* Return an instance of this class.
*
* @since 2.0.0
* @return object A single instance of this class.
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Fired when the plugin is activated.
*
* @since 2.0.0
* @param boolean $network_wide True if WPMU superadmin uses
* "Network Activate" action, false if
* WPMU is disabled or plugin is
* activated on an individual blog.
*/
public static function activate( $network_wide ) {
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
if ( $network_wide ) {
// Get all blog ids
$blog_ids = self::get_blog_ids();
foreach ( $blog_ids as $blog_id ) {
switch_to_blog( $blog_id );
self::single_activate();
}
restore_current_blog();
} else {
self::single_activate();
}
} else {
self::single_activate();
}
}
/**
* Fired when the plugin is deactivated.
*
* @since 2.0.0
* @param boolean $network_wide True if WPMU superadmin uses
* "Network Deactivate" action, false if
* WPMU is disabled or plugin is
* deactivated on an individual blog.
*/
public static function deactivate( $network_wide ) {
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
if ( $network_wide ) {
// Get all blog ids
$blog_ids = self::get_blog_ids();
foreach ( $blog_ids as $blog_id ) {
switch_to_blog( $blog_id );
self::single_deactivate();
}
restore_current_blog();
} else {
self::single_deactivate();
}
} else {
self::single_deactivate();
}
}
/**
* Fired when a new site is activated with a WPMU environment.
*
* @since 2.0.0
* @param int $blog_id ID of the new blog.
*/
public function activate_new_site( $blog_id ) {
if ( 1 !== did_action( 'wpmu_new_blog' ) ) {
return;
}
switch_to_blog( $blog_id );
self::single_activate();
restore_current_blog();
}
/**
* Get all blog ids of blogs in the current network that are:
* - not archived
* - not spam
* - not deleted
*
* @since 2.0.0
* @return array|false The blog ids, false if no matches.
*/
private static function get_blog_ids() {
global $wpdb;
// get an array of blog ids
$sql = "SELECT blog_id FROM $wpdb->blogs
WHERE archived = '0' AND spam = '0'
AND deleted = '0'";
return $wpdb->get_col( $sql );
}
/**
* Fired for each blog when the plugin is activated.
*
* @since 2.0.0
*/
private static function single_activate() {
// update_option('menu', 'yes');
// update_option('bar', 'no');
// update_option('ios6', 'yes');
}
/**
* Fired for each blog when the plugin is deactivated.
*
* @since 2.0.0
*/
private static function single_deactivate() {
// TODO: Define deactivation functionality here
}
/**
* Load the plugin text domain for translation.
*
* @since 2.0.0
*/
public function load_plugin_textdomain() {
$domain = $this->plugin_slug;
$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '/' . $domain . '-' . $locale . '.mo' );
load_plugin_textdomain( $domain, FALSE, basename( plugin_dir_path( dirname( __FILE__ ) ) ) . '/languages/' );
}
}

69
badged/readme.txt Normal file
View File

@ -0,0 +1,69 @@
=== Badged ===
Contributors: kremalicious
Donate link: http://krlc.us/givecoffee
Tags: notification, adminmenu, toolbar, ios, badge
Requires at least: 2.7
Tested up to: 3.4
Stable tag: 0.3.6
iOS Style Notification Badges for WordPress
== Description ==
Badged transforms the standard WordPress update & comment notification badges into iOS-styled ones. Upon activation it automatically replaces the badge styles in the admin menu and the toolbar. An optional settings page allows to control whether the badges show up in the admin menu or toolbar only.
The badges are created without any images by using only CSS (box shadows, gradients, pseudo elements, you name it) and were tested in current versions of Safari, Chrome, Firefox, Opera & Internet Explorer. It should degrade gracefully in older browsers with some details missing like drop shadows or the highlight shine.
The plugin is localized in english & german.
* * *
[Badged Blog Post](http://kremalicious.com/badged/) | [Badged on github](https://github.com/kremalicious/badged) | [Donate](http://krlc.us/givecoffee)
== Installation ==
Just install using the automatic backend installer under Plugins > Add New, activate and enjoy the red badges.
For manual installation:
1. Upload the badged plugin folder to the '/wp-content/plugins/' directory
2. Activate the plugin through the 'Plugins' menu in WordPress
3. Enjoy
(optional) Adjust options under Settings > Badges
== Screenshots ==
1. Restyled notifications in Toolbar
2. Restyled notifications in Admin Menu
3. Settings page
== Changelog ==
= v0.3.6 =
* tested for WP 3.4
* settings page: Retina ready icon for high dpi devices, css only submit button
* updated german translation
= v0.3.5 =
* IE 8 improvements: box shadow, light gradient through DXImageTransform filters (but no rounded corners, sorry)
* current versions of IE & Opera are now among the tested browsers
* updated settings page links
= v0.3.4 =
* more descriptive readme and settings footer with links to blog post & github page
* updated translation
= v0.3.2 =
* Make the plugin work if symlinked
= v0.3 =
* initial beta release
= v0.2 =
* added options to control whether the badges show up in admin menu or toolbar (default is both)
= v0.1 =
* initial alpha release

View File

@ -1,198 +0,0 @@
<?php
/**
* Badged
*
* @package Badged
* @author Matthias Kretschmann <desk@kremalicious.com>
* @license GPL-2.0+
* @link http://kremalicious.com/badged/
* @copyright 2013 Matthias Kretschmann
*/
/**
* Plugin class.
*
*
* @package Badged
* @author Matthias Kretschmann <desk@kremalicious.com>
*/
class Badged {
/**
* Plugin version, used for cache-busting of style and script file references.
*
* @since 1.0.0
* @var string
*/
protected $version = '1.0.0';
/**
* Unique identifier for your plugin.
*
* Use this value (not the variable name) as the text domain when internationalizing strings of text. It should
* match the Text Domain file header in the main plugin file.
*
* @since 1.0.0
* @var string
*/
protected $plugin_slug = 'badged';
/**
* Instance of this class.
*
* @since 1.0.0
* @var object
*/
protected static $instance = null;
/**
* Slug of the plugin screen.
*
* @since 1.0.0
* @var string
*/
protected $plugin_screen_hook_suffix = null;
/**
* Initialize the plugin by setting localization, filters, and administration functions.
*
* @since 1.0.0
*/
private function __construct() {
// Load plugin text domain
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
// Add the options page and menu item.
add_action( 'admin_menu', array( $this, 'add_plugin_admin_menu' ) );
// Load admin style sheet
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
// add settings link on plugins page
add_filter('plugin_action_links_'.$this->plugin_slug, array( $this, 'filter_settings_link' ) );
}
/**
* Return an instance of this class.
*
* @since 1.0.0
* @return object A single instance of this class.
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Fired when the plugin is activated.
*
* @since 1.0.0
* @param boolean $network_wide True if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin is activated on an individual blog.
*/
public static function activate( $network_wide ) {
register_setting('badged', 'menu');
register_setting('badged', 'bar');
register_setting('badged', 'ios6');
register_setting('badged', 'ios7');
update_option('menu', 'yes');
update_option('bar', 'no');
update_option('ios6', 'yes');
}
/**
* Fired when the plugin is deactivated.
*
* @since 1.0.0
* @param boolean $network_wide True if WPMU superadmin uses "Network Deactivate" action, false if WPMU is disabled or plugin is deactivated on an individual blog.
*/
public static function deactivate( $network_wide ) {
// TODO: Define deactivation functionality here
}
/**
* Load the plugin text domain for translation.
* @since 1.0.0
*/
public function load_plugin_textdomain() {
$domain = $this->plugin_slug;
$locale = apply_filters( 'bdgd', get_locale(), $domain );
load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' );
load_plugin_textdomain( $domain, FALSE, dirname( BADGED_BASENAME ) . '/lang/' );
}
/**
* Register and enqueue admin-specific style sheet.
*
* @since 1.0.0
* @return null Return early if no settings page is registered.
*/
public function enqueue_admin_styles() {
if ( ! isset( $this->plugin_screen_hook_suffix ) ) {
return;
}
$screen = get_current_screen();
if ( $screen->id == $this->plugin_screen_hook_suffix ) {
wp_enqueue_style( $this->plugin_slug .'-admin-styles', plugins_url( 'css/options.css', BADGED_BASENAME ), array(), $this->version );
}
wp_enqueue_style( $this->plugin_slug . '-plugin-styles', plugins_url( 'css/badged.css', BADGED_BASENAME ), array(), $this->version );
}
/**
* Register the administration menu for this plugin into the WordPress Dashboard menu.
* @since 1.0.0
*/
public function add_plugin_admin_menu() {
$this->plugin_screen_hook_suffix = add_options_page(
__( 'Badged Settings', $this->plugin_slug ),
__( 'Badged', $this->plugin_slug ),
'read',
$this->plugin_slug,
array( $this, 'display_plugin_admin_page' )
);
}
/**
* Render the settings page for this plugin.
* @since 1.0.0
*/
public function display_plugin_admin_page() {
include_once( 'views/options.php' );
}
/**
* WordPress Actions: http://codex.wordpress.org/Plugin_API#Actions
* Action Reference: http://codex.wordpress.org/Plugin_API/Action_Reference
*
* @since 1.0.0
*/
public function action_method_name() {
// TODO: Define your action hook callback here
}
/**
* Add settings link on plugin page
* @since 1.0.0
*/
public function filter_settings_link($links) {
$settings_link = '<a href="options-general.php?page=badged">'. __('Settings') .'</a>';
array_unshift($links, $settings_link);
return $links;
}
}

Binary file not shown.

BIN
design/Badged Teaser.psd Normal file

Binary file not shown.

BIN
design/Badged WP Icon.psd Normal file

Binary file not shown.

Binary file not shown.

View File

@ -1,77 +0,0 @@
<?php
/**
* Represents the view for the administration dashboard.
*
* This includes the header, options, and other information that should provide
* The User Interface to the end user.
*
* @package Badged
* @author Matthias Kretschmann <desk@kremalicious.com>
* @license GPL-2.0+
* @link http://kremalicious.com/badged/
* @copyright 2013 Matthias Kretschmann
*/
?>
<div class="wrap" id="badgedoptions">
<header>
<?php screen_icon(); ?>
<h2><?php echo esc_html( get_admin_page_title() ); ?></h2>
</header>
<form method="post" action="options.php">
<?php settings_fields( 'badged' ); ?>
<table class="form-table">
<tr valign="top">
<td colspan="2">
<h2><?php _e( 'View', 'bdgd' ); ?></h2>
</td>
</tr>
<tr valign="top">
<th scope="row" class="indent">
<?php _e( 'Style', 'bdgd' ); ?>
</th>
<td>
<fieldset>
<input type="radio" name="ios6" id="ios6" value="ios6"<?php echo get_option('ios6') == 'yes' ? ' checked' : '';?> />
<label for="ios6"><?php _e( 'iOS 6', 'bdgd' ); ?></label>
<br />
<input type="radio" name="ios7" id="ios7" value="ios7"<?php echo get_option('ios7') == 'yes' ? ' checked' : '';?> />
<label for="ios7"><?php _e( 'iOS 7', 'bdgd' ); ?></label>
</fieldset>
</td>
</tr>
<tr valign="top">
<th scope="row" class="indent">
<?php _e( 'Style Notifications in', 'bdgd' ); ?>
</th>
<td>
<fieldset>
<input type="checkbox" name="menu" id="menu" value="yes"<?php echo get_option('menu') == 'yes' ? ' checked' : '';?> />
<label for="menu"><?php _e( 'Admin Menu', 'bdgd' ); ?></label>
<br />
<input type="checkbox" name="bar" id="bar" value="yes"<?php echo get_option('bar') == 'yes' ? ' checked' : '';?> />
<label for="bar"><?php _e( 'Toolbar', 'bdgd' ); ?></label>
</fieldset>
</td>
</tr>
</table>
<?php submit_button(); ?>
</form>
<footer>
<p>
<?php _e('Thanks for using', 'bdgd'); ?> <a href="http://www.kremalicious.com/2011/12/badged/" title="Badged Blog Post">Badged</a> (<a href="https://github.com/kremalicious/Badged/" title="Badged On Github">github</a>) &middot; <a href="http://krlc.us/givecoffee"><strong><?php _e('Donate', 'bdgd'); ?></strong></a>
<span class="alignright"><?php _e('Created by', 'bdgd'); ?> <a href="http://mkretschmann.com">Matthias Kretschmann</a> (<a href="https://twitter.com/kremalicious">@kremalicious</a>)</span>
</p>
</footer>
</div>