Permalink
Browse files

Merge pull request #7 from franz-josef-kaiser/master

everything OOP, fixed bugs, etc.
  • Loading branch information...
2 parents 1e71dcb + a96936f commit 305304fac99a915d6f6b7e04b9089b5d4ce2ff5f @chrisguitarguy committed Jul 1, 2012
Showing with 283 additions and 31 deletions.
  1. +4 −0 .gitmodules
  2. +28 −0 changelog.txt
  3. +30 −7 inc/admin.php
  4. +4 −1 inc/api.php
  5. +1 −0 inc/updater
  6. +1 −0 index.html
  7. +214 −10 plugin-dirs.php
  8. +1 −13 readme.md
View
@@ -0,0 +1,4 @@
+
+[submodule "inc/updater"]
+ path = inc/updater
+ url = git://github.com/franz-josef-kaiser/WordPress-GitHub-Plugin-Updater.git
View
@@ -0,0 +1,28 @@
+*0.1*
+Initial version.
+*0.2*
+Clean Up & code styling alignment.
+*0.3*
+Minor styling fixes.
+*0.4*
+Moved to OOP concept.
+*0.5*
+Improved API: now supports different plugin locations aside from the `WP_CONTENT_DIR`.
+*0.5.1*
+Minor fix for left over debug code.
+*0.5.2*
+JS styling for readability.
+*0.6*
+Removed "activate" link when plugin is already active, as suggested by Julien Chaumond in Issue #3.
+*0.7*
+Added the "adp_root_{$root}" filter to allow completely custom locations. Moved changelog to separate file.
+*0.7.1*
+Fix script path for remote locations.
+*0.7.2*
+Renamed main plugin file to index.php to avoid accidental directory listing.
+*0.7.3*
+Reverted 0.7.2 to avoid plugin deactivation. Added index.html file instead.
+*0.8*
+Moved Bootstrap to OOP construct. Regular child plugins are now allowed to use the default priority.
+*0.9*
+Added better update message (as seen here).
View
@@ -5,7 +5,6 @@
if ( ! class_exists( 'CD_APD_Admin' ) )
{
- add_action( 'plugins_loaded', array( 'CD_APD_Admin', 'instance' ) );
/**
* Admin/Factory
@@ -81,7 +80,7 @@ public static function instance()
*/
public function __construct()
{
- add_action( 'plugins_loaded', array( $this, 'setup_actions' ), 1 );
+ add_action( 'plugins_loaded', array( $this, 'setup_actions' ), 11 );
add_action( 'load-plugins.php', array( $this, 'init' ) );
}
@@ -254,7 +253,10 @@ public function action_links( $links, $plugin_file )
/**
- * Enqueues on JS file for fun hacks
+ * Enqueues on JS file for fun hacks.
+ *
+ * @uses filemtime() to set the version number of files
+ * to their last changed date to prevent caching.
*
* @since 0.1
* @uses wp_enqueue_script()
@@ -266,10 +268,10 @@ public function scripts( $screen )
return;
wp_enqueue_script(
- 'cd-apd-js',
- CD_APD_URL.'js/apd.js',
- array( 'jquery' ),
- null
+ 'cd-apd-js'
+ ,$this->scripts_file_cb( 'url' )."apd.js"
+ ,array( 'jquery' )
+ ,filemtime( $this->scripts_file_cb( 'path' )."apd.js" )
);
wp_localize_script(
'cd-apd-js',
@@ -282,6 +284,27 @@ public function scripts( $screen )
/**
+ * Callback to get the Path or URl to register scripts.
+ *
+ * @since 0.7.3
+ * @param string $case (Valid are:) 'path', 'url'
+ * @param string $sub_dir Defaults to: 'js'
+ * @return string
+ */
+ public function scripts_file_cb( $case, $sub_dir = 'js' )
+ {
+ $root = 'path' === $case ? plugin_dir_path( __FILE__ ) : plugin_dir_url( __FILE__ );
+
+ return substr_replace(
+ $root
+ ,$sub_dir
+ ,strrpos( $root, basename( $root ) )
+ ,strlen( basename( $root ) )
+ );
+ }
+
+
+ /**
* Fetch all the custom plugins we have!
*
* @since 0.1
View
@@ -125,9 +125,12 @@ function _get_new_plugin_directory_root( $root )
break;
case 'content' :
- default :
$root = WP_CONTENT_DIR;
break;
+
+ default :
+ $root = apply_filters( "adp_root_{$root}", WP_CONTENT_DIR );
+ break;
}
return trailingslashit( $root );
Submodule updater added at e18b83
View
@@ -0,0 +1 @@
+<!-- Hi there. Nice try! ...but sorry, no. -->
View
@@ -1,24 +1,228 @@
<?php
! defined( 'ABSPATH' ) AND exit();
/*
-Plugin Name: Additional Plugin Directories
+Plugin Name: Additional Plugin Directories 2
Plugin URI: http://github.com/chrisguitarguy
Description: A framework to allow adding additional plugin directories to WordPress
-Version: 0.6
+Version: 1.0
Author: Christopher Davis
Contributors: Franz Josef Kaiser, Julien Chaumond
Author URI: http://christopherdavis.me
-License: GPL2
+License: GNU GPL 2
*/
-define( 'CD_APD_PATH', plugin_dir_path( __FILE__ ) );
-define( 'CD_APD_URL', plugin_dir_url( __FILE__ ) );
-require_once( CD_APD_PATH.'inc/api.php' );
-require_once( CD_APD_PATH.'inc/core.php' );
+// Avoid loading twice
+if ( ! class_exists( 'dmb_bootstrap' ) )
+{
+ add_action( 'plugins_loaded', array( 'CD_APD_Bootstrap', 'init' ), 5 );
-if ( is_admin() )
+/**
+ * Bootstrap for delayed Meta Boxes
+ *
+ * @author Franz Josef Kaiser, Christopher Davis
+ * @license GNU GPL 2
+ * @copyright © Franz Josef Kaiser, Christopher Davis 2011-2012
+ *
+ * @package WordPress
+ * @subpackage Additional Plugin Directories: Bootstrap
+ */
+class CD_APD_Bootstrap
{
- require_once( CD_APD_PATH.'inc/admin.php' );
-}
+ /**
+ * Instance
+ *
+ * @access protected
+ * @var object
+ */
+ static protected $instance;
+
+
+ /**
+ * The files that need to get included
+ *
+ * @since 0.8
+ * @access public
+ * @static
+ * @var array string Class Name w/o prefix (Hint: Naming convention!) Use the value to define if need to hook the class.
+ */
+ static public $includes = array(
+ 'api' => false
+ ,'core' => false
+ ,'admin' => true
+ );
+
+
+ /**
+ * Used for update notices
+ * Fetches the readme file from the official plugin repo trunk.
+ * Adds to the "in_plugin_update_message-$file" hook
+ *
+ * @var (string)
+ */
+ public $remote_changelog = 'https://raw.github.com/chrisguitarguy/WP-Plugin-Directories/master/changelog.txt';
+
+
+ /**
+ * Creates a new static instance
+ *
+ * @since 0.8
+ * @static
+ * @return void
+ */
+ static public function init()
+ {
+ null === self :: $instance AND self :: $instance = new self;
+ return self :: $instance;
+ }
+
+
+ /**
+ * Constructor
+ *
+ * @since 0.8
+ * @access public
+ * @return void
+ */
+ public function __construct()
+ {
+ // Localize
+ load_theme_textdomain( 'cd_apd_textdomain', plugin_dir_path( __FILE__ )."lang" );
+
+ // Load at the end of /wp-admin/admin.php
+ foreach ( self :: $includes as $inc => $init )
+ {
+ // Load file: trailingslashed by core
+ # Tested: calling plugin_dir_path() directly saves 1/2 time
+ # instead of saving the plugin_dir_path() in a $var and recalling here
+ require_once plugin_dir_path( __FILE__ )."inc/{$inc}.php";
+
+ if ( ! $init )
+ continue;
+
+ // Build class name
+ $class = "CD_APD_".ucwords( $inc );
+
+ class_exists( $class ) AND add_action( 'plugins_loaded', array( $class, 'instance' ) );
+ }
+
+ if ( ! is_admin() )
+ return;
+
+ // Updates from GitHub
+ // $ git submodule add git://github.com/franz-josef-kaiser/WordPress-GitHub-Plugin-Updater inc/updater
+ add_action( 'admin_init', array( $this, 'update_from_github' ) );
+
+ // Better update message
+ $folder = basename( dirname( __FILE__ ) );
+ $file = basename( __FILE__ );
+ $hook = "in_plugin_update_message-{$folder}/{$file}";
+ add_action( $hook, array( $this, 'update_message' ), 20, 2 );
+ }
+
+
+ /**
+ *
+ * @since 1.0
+ *
+ * @return void
+ */
+ public function update_from_github()
+ {
+ if ( 'plugins.php' !== $GLOBALS['pagenow'] )
+ return;
+
+ global $wp_version;
+
+ // Load the updater
+ include_once plugin_dir_path( __FILE__ ).'inc/updater/updater.php';
+
+ // Fix this strange WP bug(?)
+ add_action( 'http_request_args', array( $this, 'update_request_args' ), 0, 2 );
+
+ $host = 'github.com';
+ $http = 'https://';
+ $name = 'franz-josef-kaiser';
+ $repo = 'WP-Plugin-Directories';
+ new wp_github_updater( array(
+ 'slug' => plugin_basename( __FILE__ )
+ ,'proper_folder_name' => dirname( plugin_basename(__FILE__) ) #plugin_basename( __FILE__ )
+ ,'api_url' => "{$http}api.{$host}/repos/{$name}/{$repo}"
+ ,'raw_url' => "{$http}raw.{$host}/{$name}/{$repo}/master"
+ ,'github_url' => "{$http}{$host}/{$name}/{$repo}"
+ ,'zip_url' => "{$http}{$host}/{$name}/{$repo}/zipball/master"
+ ,'sslverify' => true
+ ,'requires' => $wp_version
+ ,'tested' => $wp_version
+ ,'readme_file' => 'readme.md'
+ ) );
+ }
+
+
+ public function update_request_args( $args, $url )
+ {
+ // Only needed once - this saves us checking the $url
+ remove_filter( current_filter(), __FUNCTION__ );
+
+ return array_merge( $args, array(
+ 'sslverify' => false
+ ) );
+ }
+
+
+ /**
+ * Displays an update message for plugin list screens.
+ * Shows only the version updates from the current until the newest version
+ *
+ * @uses WordPress HTTP API
+ *
+ * @since 0.9
+ * @param array $plugin_data Data of the plugin itself
+ * @param object $r Data of the remote request to the repo
+ * @return string The actual Output message
+ */
+ public function update_message( $plugin_data, $r )
+ {
+ if ( 'plugins.php' !== $GLOBALS['pagenow'] )
+ return;
+
+ // Get `changelog.txt` from GitHub via WP HTTP API
+ $changelog = wp_remote_get(
+ $this->remote_changelog
+ ,array(
+ // We can't force anyone to alter the `~/.ssh/config` on the server
+ 'sslverify' => false
+ )
+ );
+
+ // Die silently
+ if ( is_wp_error( $changelog ) )
+ return;
+
+ // Only retrieve what's new since the installed version
+ $details = explode(
+ '*'
+ ,stristr(
+ $changelog['body']
+ ,"*{$plugin_data['Version']}*"
+ )
+ );
+ // Build the update note
+ $whats_new = '';
+ for ( $i = 0; $i < count( $details ); $i++ )
+ {
+ $whats_new .= ( 0 != $i % 2 ) ? "<strong>{$details[ $i ]}" : "</strong><br />{$details[ $i ]}";
+ }
+
+ return printf(
+ "%sThe Update from %s to %s brings you the following new features, bug fixes and additions.%s"
+ ,'<hr />'
+ ,"<code>{$plugin_data['Version']}</code>"
+ ,"<code>{$r->new_version}</code>"
+ ,"<p style='font-weight:normal;'>{$whats_new}</p>"
+ );
+ }
+} // END Class CD_APD_Bootstrap
+
+} // endif;
View
@@ -10,16 +10,4 @@ For an example, take a look at the `example_plugin` folder and the `register_add
You need to copy this folder to your actual plugins folder and then activate it from within your plugins list. It only works if the main plugin is activated.
-*) the one you defined with the `WP_PLUGIN_DIR` or `WPMU_PLUGIN_DIR` in your wp-config.php file - or the default `plugins` folder in your install.
-
-
-CHANGELOG
-
-0.1 Initial version
-0.2 Clean Up & code styling alignment
-0.3 Minor styling fixes
-0.4 Moved to OOP concept
-0.5 Improved API - now supports different plugin locations aside from the `WP_CONTENT_DIR`.
-0.5.1 Minor fix for left over debug code
-0.5.2 JS styling for readability
-0.6 Removed "activate" link when plugin is already active, as suggested by Julien Chaumond in Issue #3
+*) the one you defined with the `WP_PLUGIN_DIR` or `WPMU_PLUGIN_DIR` in your wp-config.php file - or the default `plugins` folder in your install.

0 comments on commit 305304f

Please sign in to comment.