Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 228 lines (193 sloc) 5.823 kb
d59ce6f @chrisguitarguy first commit. works.
authored
1 <?php
f985bae moved to OOP, improved API, added example plugin
franz-josef-kaiser authored
2 ! defined( 'ABSPATH' ) AND exit();
d59ce6f @chrisguitarguy first commit. works.
authored
3 /*
a96936f first attempt to update from github repo
franz-josef-kaiser authored
4 Plugin Name: Additional Plugin Directories 2
f985bae moved to OOP, improved API, added example plugin
franz-josef-kaiser authored
5 Plugin URI: http://github.com/chrisguitarguy
6 Description: A framework to allow adding additional plugin directories to WordPress
a96936f first attempt to update from github repo
franz-josef-kaiser authored
7 Version: 1.0
f985bae moved to OOP, improved API, added example plugin
franz-josef-kaiser authored
8 Author: Christopher Davis
44aa630 remove active link for already active plugins
franz-josef-kaiser authored
9 Contributors: Franz Josef Kaiser, Julien Chaumond
f985bae moved to OOP, improved API, added example plugin
franz-josef-kaiser authored
10 Author URI: http://christopherdavis.me
c1b94a8 made bootstrap OOP
franz-josef-kaiser authored
11 License: GNU GPL 2
d59ce6f @chrisguitarguy first commit. works.
authored
12 */
b819902 clean up: from spaces to tabs
franz-josef-kaiser authored
13
d59ce6f @chrisguitarguy first commit. works.
authored
14
15
c1b94a8 made bootstrap OOP
franz-josef-kaiser authored
16 // Avoid loading twice
17 if ( ! class_exists( 'dmb_bootstrap' ) )
18 {
19 add_action( 'plugins_loaded', array( 'CD_APD_Bootstrap', 'init' ), 5 );
d59ce6f @chrisguitarguy first commit. works.
authored
20
c1b94a8 made bootstrap OOP
franz-josef-kaiser authored
21 /**
22 * Bootstrap for delayed Meta Boxes
23 *
24 * @author Franz Josef Kaiser, Christopher Davis
25 * @license GNU GPL 2
26 * @copyright © Franz Josef Kaiser, Christopher Davis 2011-2012
27 *
28 * @package WordPress
29 * @subpackage Additional Plugin Directories: Bootstrap
30 */
31 class CD_APD_Bootstrap
d59ce6f @chrisguitarguy first commit. works.
authored
32 {
c1b94a8 made bootstrap OOP
franz-josef-kaiser authored
33 /**
34 * Instance
35 *
36 * @access protected
37 * @var object
38 */
39 static protected $instance;
40
41
42 /**
43 * The files that need to get included
44 *
45 * @since 0.8
46 * @access public
47 * @static
48 * @var array string Class Name w/o prefix (Hint: Naming convention!) Use the value to define if need to hook the class.
49 */
50 static public $includes = array(
51 'api' => false
52 ,'core' => false
53 ,'admin' => true
54 );
55
56
57 /**
d593621 added better update message
franz-josef-kaiser authored
58 * Used for update notices
59 * Fetches the readme file from the official plugin repo trunk.
60 * Adds to the "in_plugin_update_message-$file" hook
61 *
62 * @var (string)
63 */
64 public $remote_changelog = 'https://raw.github.com/chrisguitarguy/WP-Plugin-Directories/master/changelog.txt';
65
66
67 /**
c1b94a8 made bootstrap OOP
franz-josef-kaiser authored
68 * Creates a new static instance
69 *
70 * @since 0.8
71 * @static
72 * @return void
73 */
74 static public function init()
75 {
76 null === self :: $instance AND self :: $instance = new self;
77 return self :: $instance;
78 }
79
80
81 /**
82 * Constructor
83 *
84 * @since 0.8
85 * @access public
86 * @return void
87 */
88 public function __construct()
89 {
90 // Localize
91 load_theme_textdomain( 'cd_apd_textdomain', plugin_dir_path( __FILE__ )."lang" );
92
93 // Load at the end of /wp-admin/admin.php
94 foreach ( self :: $includes as $inc => $init )
95 {
96 // Load file: trailingslashed by core
97 # Tested: calling plugin_dir_path() directly saves 1/2 time
98 # instead of saving the plugin_dir_path() in a $var and recalling here
99 require_once plugin_dir_path( __FILE__ )."inc/{$inc}.php";
100
101 if ( ! $init )
102 continue;
103
104 // Build class name
105 $class = "CD_APD_".ucwords( $inc );
106
107 class_exists( $class ) AND add_action( 'plugins_loaded', array( $class, 'instance' ) );
108 }
d593621 added better update message
franz-josef-kaiser authored
109
a96936f first attempt to update from github repo
franz-josef-kaiser authored
110 if ( ! is_admin() )
111 return;
112
113 // Updates from GitHub
114 // $ git submodule add git://github.com/franz-josef-kaiser/WordPress-GitHub-Plugin-Updater inc/updater
115 add_action( 'admin_init', array( $this, 'update_from_github' ) );
116
d593621 added better update message
franz-josef-kaiser authored
117 // Better update message
118 $folder = basename( dirname( __FILE__ ) );
119 $file = basename( __FILE__ );
120 $hook = "in_plugin_update_message-{$folder}/{$file}";
121 add_action( $hook, array( $this, 'update_message' ), 20, 2 );
122 }
123
124
125 /**
a96936f first attempt to update from github repo
franz-josef-kaiser authored
126 *
127 * @since 1.0
128 *
129 * @return void
130 */
131 public function update_from_github()
132 {
133 if ( 'plugins.php' !== $GLOBALS['pagenow'] )
134 return;
135
136 global $wp_version;
137
138 // Load the updater
139 include_once plugin_dir_path( __FILE__ ).'inc/updater/updater.php';
140
141 // Fix this strange WP bug(?)
142 add_action( 'http_request_args', array( $this, 'update_request_args' ), 0, 2 );
143
144 $host = 'github.com';
145 $http = 'https://';
146 $name = 'franz-josef-kaiser';
147 $repo = 'WP-Plugin-Directories';
148 new wp_github_updater( array(
149 'slug' => plugin_basename( __FILE__ )
150 ,'proper_folder_name' => dirname( plugin_basename(__FILE__) ) #plugin_basename( __FILE__ )
151 ,'api_url' => "{$http}api.{$host}/repos/{$name}/{$repo}"
152 ,'raw_url' => "{$http}raw.{$host}/{$name}/{$repo}/master"
153 ,'github_url' => "{$http}{$host}/{$name}/{$repo}"
154 ,'zip_url' => "{$http}{$host}/{$name}/{$repo}/zipball/master"
155 ,'sslverify' => true
156 ,'requires' => $wp_version
157 ,'tested' => $wp_version
158 ,'readme_file' => 'readme.md'
159 ) );
160 }
161
162
163 public function update_request_args( $args, $url )
164 {
165 // Only needed once - this saves us checking the $url
166 remove_filter( current_filter(), __FUNCTION__ );
167
168 return array_merge( $args, array(
169 'sslverify' => false
170 ) );
171 }
172
173
174 /**
d593621 added better update message
franz-josef-kaiser authored
175 * Displays an update message for plugin list screens.
176 * Shows only the version updates from the current until the newest version
177 *
178 * @uses WordPress HTTP API
179 *
180 * @since 0.9
181 * @param array $plugin_data Data of the plugin itself
182 * @param object $r Data of the remote request to the repo
183 * @return string The actual Output message
184 */
185 public function update_message( $plugin_data, $r )
186 {
187 if ( 'plugins.php' !== $GLOBALS['pagenow'] )
188 return;
189
190 // Get `changelog.txt` from GitHub via WP HTTP API
191 $changelog = wp_remote_get(
192 $this->remote_changelog
193 ,array(
194 // We can't force anyone to alter the `~/.ssh/config` on the server
195 'sslverify' => false
196 )
197 );
198
199 // Die silently
200 if ( is_wp_error( $changelog ) )
201 return;
202
203 // Only retrieve what's new since the installed version
204 $details = explode(
205 '*'
206 ,stristr(
207 $changelog['body']
208 ,"*{$plugin_data['Version']}*"
209 )
210 );
211 // Build the update note
212 $whats_new = '';
213 for ( $i = 0; $i < count( $details ); $i++ )
214 {
215 $whats_new .= ( 0 != $i % 2 ) ? "<strong>{$details[ $i ]}" : "</strong><br />{$details[ $i ]}";
216 }
217
218 return printf(
219 "%sThe Update from %s to %s brings you the following new features, bug fixes and additions.%s"
220 ,'<hr />'
221 ,"<code>{$plugin_data['Version']}</code>"
222 ,"<code>{$r->new_version}</code>"
223 ,"<p style='font-weight:normal;'>{$whats_new}</p>"
224 );
c1b94a8 made bootstrap OOP
franz-josef-kaiser authored
225 }
226 } // END Class CD_APD_Bootstrap
227
228 } // endif;
Something went wrong with that request. Please try again.