Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 210 lines (177 sloc) 5.218 kb
d59ce6f @chrisguitarguy first commit. works.
authored
1 <?php
f985bae @franz-josef-kaiser moved to OOP, improved API, added example plugin
franz-josef-kaiser authored
2 ! defined( 'ABSPATH' ) AND exit();
d59ce6f @chrisguitarguy first commit. works.
authored
3 /*
75ff4d2 @franz-josef-kaiser fixed remote location
franz-josef-kaiser authored
4 Plugin Name: Additional Plugin Directories
f985bae @franz-josef-kaiser 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
04853ad @franz-josef-kaiser reversed order for changelog
franz-josef-kaiser authored
7 Version: 1.1
f985bae @franz-josef-kaiser moved to OOP, improved API, added example plugin
franz-josef-kaiser authored
8 Author: Christopher Davis
44aa630 @franz-josef-kaiser remove active link for already active plugins
franz-josef-kaiser authored
9 Contributors: Franz Josef Kaiser, Julien Chaumond
f985bae @franz-josef-kaiser moved to OOP, improved API, added example plugin
franz-josef-kaiser authored
10 Author URI: http://christopherdavis.me
c1b94a8 @franz-josef-kaiser made bootstrap OOP
franz-josef-kaiser authored
11 License: GNU GPL 2
d59ce6f @chrisguitarguy first commit. works.
authored
12 */
b819902 @franz-josef-kaiser clean up: from spaces to tabs
franz-josef-kaiser authored
13
d59ce6f @chrisguitarguy first commit. works.
authored
14
15
c1b94a8 @franz-josef-kaiser 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 @franz-josef-kaiser 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 @franz-josef-kaiser 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 @franz-josef-kaiser 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 */
04853ad @franz-josef-kaiser reversed order for changelog
franz-josef-kaiser authored
64 public $remote_changelog = 'https://raw.github.com/chrisguitarguy/WP-Plugin-Directories/master/changelog.html';
d593621 @franz-josef-kaiser added better update message
franz-josef-kaiser authored
65
66
67 /**
c1b94a8 @franz-josef-kaiser 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 @franz-josef-kaiser added better update message
franz-josef-kaiser authored
109
a96936f @franz-josef-kaiser 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
05a3daf @franz-josef-kaiser finalized updates from github
franz-josef-kaiser authored
115 add_action( 'init', array( $this, 'update_from_github' ), 0 );
d593621 @franz-josef-kaiser added better update message
franz-josef-kaiser authored
116 }
117
118
119 /**
a96936f @franz-josef-kaiser first attempt to update from github repo
franz-josef-kaiser authored
120 *
121 * @since 1.0
122 *
123 * @return void
124 */
125 public function update_from_github()
126 {
127 global $wp_version;
128
129 // Load the updater
130 include_once plugin_dir_path( __FILE__ ).'inc/updater/updater.php';
131
132 // Fix this strange WP bug(?)
133 add_action( 'http_request_args', array( $this, 'update_request_args' ), 0, 2 );
134
135 $host = 'github.com';
136 $http = 'https://';
75ff4d2 @franz-josef-kaiser fixed remote location
franz-josef-kaiser authored
137 $name = 'chrisguitarguy';
a96936f @franz-josef-kaiser first attempt to update from github repo
franz-josef-kaiser authored
138 $repo = 'WP-Plugin-Directories';
139 new wp_github_updater( array(
140 'slug' => plugin_basename( __FILE__ )
04853ad @franz-josef-kaiser reversed order for changelog
franz-josef-kaiser authored
141 ,'proper_folder_name' => dirname( plugin_basename(__FILE__) )
a96936f @franz-josef-kaiser first attempt to update from github repo
franz-josef-kaiser authored
142 ,'api_url' => "{$http}api.{$host}/repos/{$name}/{$repo}"
143 ,'raw_url' => "{$http}raw.{$host}/{$name}/{$repo}/master"
144 ,'github_url' => "{$http}{$host}/{$name}/{$repo}"
145 ,'zip_url' => "{$http}{$host}/{$name}/{$repo}/zipball/master"
146 ,'sslverify' => true
147 ,'requires' => $wp_version
148 ,'tested' => $wp_version
149 ,'readme_file' => 'readme.md'
05a3daf @franz-josef-kaiser finalized updates from github
franz-josef-kaiser authored
150 ,'description' => array(
151 'changelog' => $this->update_message()
152 )
a96936f @franz-josef-kaiser first attempt to update from github repo
franz-josef-kaiser authored
153 ) );
154 }
155
156
05a3daf @franz-josef-kaiser finalized updates from github
franz-josef-kaiser authored
157 /**
158 * Callback to set the SSL verification for HTTP requests to GitHub to false
159 *
160 * @since 1.0
161 * @param array $args
162 * @param string $url
163 * @return array $args
164 */
a96936f @franz-josef-kaiser first attempt to update from github repo
franz-josef-kaiser authored
165 public function update_request_args( $args, $url )
166 {
167 // Only needed once - this saves us checking the $url
168 remove_filter( current_filter(), __FUNCTION__ );
169
170 return array_merge( $args, array(
171 'sslverify' => false
172 ) );
173 }
174
175
176 /**
d593621 @franz-josef-kaiser added better update message
franz-josef-kaiser authored
177 * Displays an update message for plugin list screens.
178 * Shows only the version updates from the current until the newest version
179 *
180 * @uses WordPress HTTP API
05a3daf @franz-josef-kaiser finalized updates from github
franz-josef-kaiser authored
181 * @uses $allowed_html and $allowed_protocolls inside `install_plugin_information()`
d593621 @franz-josef-kaiser added better update message
franz-josef-kaiser authored
182 *
183 * @since 0.9
184 * @return string The actual Output message
185 */
05a3daf @franz-josef-kaiser finalized updates from github
franz-josef-kaiser authored
186 public function update_message()
d593621 @franz-josef-kaiser added better update message
franz-josef-kaiser authored
187 {
188 // Get `changelog.txt` from GitHub via WP HTTP API
04853ad @franz-josef-kaiser reversed order for changelog
franz-josef-kaiser authored
189 $remote_data = wp_remote_get(
190 $this->remote_changelog
191 ,false
192 );
193
d593621 @franz-josef-kaiser added better update message
franz-josef-kaiser authored
194 // Die silently
04853ad @franz-josef-kaiser reversed order for changelog
franz-josef-kaiser authored
195 $response = wp_remote_retrieve_response_code( $remote_data );
196
197 if ( is_wp_error( $remote_data ) )
05a3daf @franz-josef-kaiser finalized updates from github
franz-josef-kaiser authored
198 return _e( 'No changelog could get fetched.', 'cd_apd_textdomain' );
d593621 @franz-josef-kaiser added better update message
franz-josef-kaiser authored
199
04853ad @franz-josef-kaiser reversed order for changelog
franz-josef-kaiser authored
200 if ( 404 === $response )
201 return $remote_data['response']['message'];
202
05a3daf @franz-josef-kaiser finalized updates from github
franz-josef-kaiser authored
203 return sprintf(
204 "<p style='font-weight:normal;'>%s</p>"
04853ad @franz-josef-kaiser reversed order for changelog
franz-josef-kaiser authored
205 ,wp_remote_retrieve_body( $remote_data )
d593621 @franz-josef-kaiser added better update message
franz-josef-kaiser authored
206 );
c1b94a8 @franz-josef-kaiser made bootstrap OOP
franz-josef-kaiser authored
207 }
208 } // END Class CD_APD_Bootstrap
209
210 } // endif;
Something went wrong with that request. Please try again.