Version Description
Download this release
Release Info
Developer | flycart |
Plugin | Discount Rules for WooCommerce |
Version | 1.4.8 |
Comparing to | |
See all releases |
Code changes from version 1.4.7 to 1.4.8
- assets/css/style.css +3 -0
- assets/js/app.js +51 -0
- helper/purchase.php +251 -2
- includes/discount-base.php +3 -2
- loader.php +23 -0
- readme.txt +2 -2
- vendor/askupa-software/wp-admin-notification/LICENSE +674 -0
- vendor/askupa-software/wp-admin-notification/README.md +65 -0
- vendor/askupa-software/wp-admin-notification/bootstrap.php +68 -0
- vendor/askupa-software/wp-admin-notification/composer.json +16 -0
- vendor/askupa-software/wp-admin-notification/handler.php +112 -0
- vendor/autoload.php +1 -1
- vendor/composer/ClassLoader.php +38 -10
- vendor/composer/LICENSE +1 -1
- vendor/composer/autoload_real.php +1 -1
- vendor/composer/installed.json +79 -1
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Autoloader.php +49 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/DebugBar/Extension.php +117 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/DebugBar/Panel.php +165 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/DebugBar/PluginExtension.php +33 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/DebugBar/PluginPanel.php +38 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/DebugBar/ThemePanel.php +21 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Factory.php +265 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Metadata.php +132 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/OAuthSignature.php +88 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Plugin/Info.php +127 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Plugin/Update.php +92 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Plugin/UpdateChecker.php +531 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Scheduler.php +177 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/StateStore.php +207 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Theme/Update.php +84 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Theme/UpdateChecker.php +167 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Update.php +34 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/UpdateChecker.php +828 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/UpgraderStatus.php +199 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Utils.php +77 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Vcs/Api.php +243 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Vcs/BaseChecker.php +22 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Vcs/BitBucketApi.php +253 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Vcs/GitHubApi.php +286 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Vcs/PluginUpdateChecker.php +198 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Vcs/Reference.php +49 -0
- vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Vcs/ThemeUpdateChecker.php +101 -0
- vendor/yahnis-elsts/plugin-update-checker/README.md +220 -0
- vendor/yahnis-elsts/plugin-update-checker/composer.json +19 -0
- vendor/yahnis-elsts/plugin-update-checker/css/puc-debug-bar.css +62 -0
- vendor/yahnis-elsts/plugin-update-checker/examples/plugin.json +47 -0
- vendor/yahnis-elsts/plugin-update-checker/examples/theme.json +5 -0
- vendor/yahnis-elsts/plugin-update-checker/js/debug-bar.js +52 -0
- vendor/yahnis-elsts/plugin-update-checker/languages/plugin-update-checker-de_DE.mo +0 -0
- vendor/yahnis-elsts/plugin-update-checker/languages/plugin-update-checker-de_DE.po +38 -0
- vendor/yahnis-elsts/plugin-update-checker/languages/plugin-update-checker-fa_IR.mo +0 -0
- vendor/yahnis-elsts/plugin-update-checker/languages/plugin-update-checker-fa_IR.po +38 -0
- vendor/yahnis-elsts/plugin-update-checker/languages/plugin-update-checker-fr_FR.mo +0 -0
- vendor/yahnis-elsts/plugin-update-checker/languages/plugin-update-checker-fr_FR.po +38 -0
- vendor/yahnis-elsts/plugin-update-checker/languages/plugin-update-checker-hu_HU.mo +0 -0
- vendor/yahnis-elsts/plugin-update-checker/languages/plugin-update-checker-hu_HU.po +41 -0
- vendor/yahnis-elsts/plugin-update-checker/languages/plugin-update-checker-it_IT.mo +0 -0
- vendor/yahnis-elsts/plugin-update-checker/languages/plugin-update-checker-it_IT.po +38 -0
- vendor/yahnis-elsts/plugin-update-checker/languages/plugin-update-checker.pot +39 -0
- vendor/yahnis-elsts/plugin-update-checker/license.txt +7 -0
- vendor/yahnis-elsts/plugin-update-checker/plugin-update-checker.php +21 -0
- vendor/yahnis-elsts/plugin-update-checker/vendor/Parsedown.php +1538 -0
- vendor/yahnis-elsts/plugin-update-checker/vendor/ParsedownLegacy.php +1535 -0
- vendor/yahnis-elsts/plugin-update-checker/vendor/readme-parser.php +334 -0
- view/settings.php +23 -2
- woo-discount-rules.php +4 -2
assets/css/style.css
CHANGED
@@ -24,4 +24,7 @@
|
|
24 |
}
|
25 |
.woo-discount-version {
|
26 |
font-size: 16px;
|
|
|
|
|
|
|
27 |
}
|
24 |
}
|
25 |
.woo-discount-version {
|
26 |
font-size: 16px;
|
27 |
+
}
|
28 |
+
.license-success{
|
29 |
+
color: green;
|
30 |
}
|
assets/js/app.js
CHANGED
@@ -61,6 +61,7 @@ function validateFields(){
|
|
61 |
// Saving Rule.
|
62 |
$('#savePriceRule').on('click', function (event) {
|
63 |
var validate = validateFields();
|
|
|
64 |
if(validate == false){
|
65 |
return false;
|
66 |
}
|
@@ -102,6 +103,56 @@ function validateFields(){
|
|
102 |
}
|
103 |
});
|
104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
// Adding New Discount Range.
|
106 |
$('#addNewDiscountRange').on('click', function () {
|
107 |
var count = $('.discount_rule_list').length + 1;
|
61 |
// Saving Rule.
|
62 |
$('#savePriceRule').on('click', function (event) {
|
63 |
var validate = validateFields();
|
64 |
+
|
65 |
if(validate == false){
|
66 |
return false;
|
67 |
}
|
103 |
}
|
104 |
});
|
105 |
|
106 |
+
// License key check
|
107 |
+
$('#woo-disc-license-check').on('click', function (event) {
|
108 |
+
var license_key = $('#woo-disc-license-key');
|
109 |
+
var resp_msg = $('#woo-disc-license-check-msg');
|
110 |
+
if(license_key.val() == ''){
|
111 |
+
license_key.addClass('invalid-field');
|
112 |
+
resp_msg.html('<div class="notice-message error inline notice-error notice-alt">Please enter a Key</div>');
|
113 |
+
return false;
|
114 |
+
}else{
|
115 |
+
license_key.removeClass('invalid-field');
|
116 |
+
resp_msg.html('');
|
117 |
+
}
|
118 |
+
|
119 |
+
var form = $('#discount_config').serialize();
|
120 |
+
var current = $(this);
|
121 |
+
|
122 |
+
event.preventDefault();
|
123 |
+
|
124 |
+
current.removeClass('button-primary');
|
125 |
+
current.addClass('button-secondary');
|
126 |
+
current.val('Saving...');
|
127 |
+
$('.license-success, .license-failed').hide();
|
128 |
+
var license_chk_req = $.ajax({
|
129 |
+
url: ajax_url,
|
130 |
+
type: 'POST',
|
131 |
+
data: {action: 'forceValidateLicenseKey', data: form},
|
132 |
+
success: function () {
|
133 |
+
resizeChart = setTimeout(function () {
|
134 |
+
current.addClass('button-primary');
|
135 |
+
current.removeClass('button-secondary');
|
136 |
+
current.val('Validate');
|
137 |
+
}, 300);
|
138 |
+
|
139 |
+
//adminNotice();
|
140 |
+
// display a success message
|
141 |
+
}
|
142 |
+
});
|
143 |
+
license_chk_req.done(function( resp ) {
|
144 |
+
|
145 |
+
response = JSON.parse(resp);
|
146 |
+
if (response['error']) {
|
147 |
+
resp_msg.html('<div class="notice-message error inline notice-error notice-alt">'+response['error']+'</div>');
|
148 |
+
} else if( response['success']){
|
149 |
+
resp_msg.html('<div class="notice-message success inline notice-success notice-alt">'+response['success']+'</div>');
|
150 |
+
}
|
151 |
+
|
152 |
+
});
|
153 |
+
});
|
154 |
+
|
155 |
+
|
156 |
// Adding New Discount Range.
|
157 |
$('#addNewDiscountRange').on('click', function () {
|
158 |
var count = $('.discount_rule_list').length + 1;
|
helper/purchase.php
CHANGED
@@ -11,15 +11,74 @@ if ( ! class_exists( 'woo_dicount_rules_purchase' ) ) {
|
|
11 |
* @var
|
12 |
*/
|
13 |
private $user;
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
/**
|
16 |
* woo_dicount_rules_purchase constructor.
|
17 |
*/
|
18 |
public function __construct()
|
19 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
}
|
22 |
|
|
|
23 |
/**
|
24 |
* @return bool
|
25 |
*/
|
@@ -48,14 +107,204 @@ if ( ! class_exists( 'woo_dicount_rules_purchase' ) ) {
|
|
48 |
}
|
49 |
}
|
50 |
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
}
|
55 |
|
56 |
-
public function
|
57 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
}
|
61 |
}
|
11 |
* @var
|
12 |
*/
|
13 |
private $user;
|
14 |
+
private $slug='woo-discount-rules';
|
15 |
+
private $force_license_check=false;
|
16 |
+
|
17 |
+
public $pluginName;
|
18 |
+
public $siteURL = 'https://www.flycart.org/';
|
19 |
|
20 |
/**
|
21 |
* woo_dicount_rules_purchase constructor.
|
22 |
*/
|
23 |
public function __construct()
|
24 |
{
|
25 |
+
$this->pluginName = 'Woo Discount Rules '.$this->getProText();
|
26 |
+
}
|
27 |
+
|
28 |
+
public function init()
|
29 |
+
{
|
30 |
+
|
31 |
+
$force_update = false;
|
32 |
+
// If a plugin has both a valid license and is using a CORE version then force update
|
33 |
+
if ( $this->isPro() === false && $this->validateLicenseKey() ) {
|
34 |
+
// can upgrade to PRO
|
35 |
+
$force_update = true;
|
36 |
+
}
|
37 |
+
|
38 |
+
$option_exists = (get_option($this->slug.'-force-update-pro', null) !== null);
|
39 |
+
|
40 |
+
if($option_exists){
|
41 |
+
update_option($this->slug.'-force-update-pro', $force_update);
|
42 |
+
}
|
43 |
+
else {
|
44 |
+
add_option($this->slug.'-force-update-pro', $force_update);
|
45 |
+
}
|
46 |
+
}
|
47 |
|
48 |
+
public function errorNoticeInAdminPages(){
|
49 |
+
$pro = $this->isPro();
|
50 |
+
$base = new woo_dicount_rules_WooDiscountBase();
|
51 |
+
$config = $base->getBaseConfig();
|
52 |
+
if (is_string($config)) $config = json_decode($config, true);
|
53 |
+
$htmlPrefix = '<div class="notice notice-warning"><p>';
|
54 |
+
$htmlSuffix = '</p></div>';
|
55 |
+
$hasMessage = 0;
|
56 |
+
if($pro){
|
57 |
+
if ( isset( $config['license_key'] ) && !empty($config['license_key']) ) {
|
58 |
+
$verifiedLicense = get_option('woo_discount_rules_verified_key', 0);
|
59 |
+
if(!$verifiedLicense){
|
60 |
+
$msg = 'The license key for '.$this->pluginName.' seems invalid. <a href="admin.php?page=woo_discount_rules&tab=settings">Please enter a valid license key</a>. You can get it from <a href="'.$this->siteURL.'">our website</a>.';
|
61 |
+
$hasMessage = 1;
|
62 |
+
}
|
63 |
+
} else {
|
64 |
+
$msg = 'License key for the '.$this->pluginName.' is not entered. <a href="admin.php?page=woo_discount_rules&tab=settings">Please enter a valid license key</a>. You can get it from <a href="'.$this->siteURL.'">our website</a>.';
|
65 |
+
$hasMessage = 1;
|
66 |
+
}
|
67 |
+
} else {
|
68 |
+
if ( isset( $config['license_key'] ) && !empty($config['license_key']) ) {
|
69 |
+
$verifiedLicense = get_option('woo_discount_rules_verified_key', 0);
|
70 |
+
if($verifiedLicense){
|
71 |
+
$msg = $this->pluginName.': You are using CORE version. Please Update to PRO version.';
|
72 |
+
$hasMessage = 1;
|
73 |
+
}
|
74 |
+
}
|
75 |
+
}
|
76 |
+
if($hasMessage){
|
77 |
+
echo $htmlPrefix.$msg.$htmlSuffix;
|
78 |
+
}
|
79 |
}
|
80 |
|
81 |
+
|
82 |
/**
|
83 |
* @return bool
|
84 |
*/
|
107 |
}
|
108 |
}
|
109 |
|
110 |
+
/**
|
111 |
+
* Hook to check and display updates below plugin in Admin Plugins section
|
112 |
+
* This plugin checks for license key validation and displays error notices
|
113 |
+
* @param string $plugin_file our plugin file
|
114 |
+
* @param string $plugin_data Plugin details
|
115 |
+
* @param string $status
|
116 |
+
* */
|
117 |
+
function woodisc_after_plugin_row ( $plugin_file, $plugin_data, $status ){
|
118 |
+
if( isset($plugin_data['TextDomain']) && $plugin_data['TextDomain'] == 'woo-discount-rules' ){
|
119 |
+
if ( ! $this->isPro() ) {
|
120 |
+
return;
|
121 |
+
}
|
122 |
+
|
123 |
+
// TODO: based on plugin_data display the update info text too. We can also make the subscription expiry chk in same request
|
124 |
+
// and display just the notice as a warning
|
125 |
+
|
126 |
+
$base = new woo_dicount_rules_WooDiscountBase();
|
127 |
+
$config = $base->getBaseConfig();
|
128 |
+
if (is_string($config)) $config = json_decode($config, true);
|
129 |
+
|
130 |
+
if ( isset( $config['license_key'] ) && !empty($config['license_key']) ) {
|
131 |
+
if (!$this->validateLicenseKey()) {
|
132 |
+
$message = 'The license key for '.$this->pluginName.' seems invalid. <a href="admin.php?page=woo_discount_rules&tab=settings">Please enter a valid license key</a>. You can get it from <a href="'.$this->siteURL.'">our website</a>.';
|
133 |
+
}
|
134 |
+
}else{
|
135 |
+
$message = 'License key for the '.$this->pluginName.' is not entered. <a href="admin.php?page=woo_discount_rules&tab=settings">Please enter a valid license key</a>. You can get it from <a href="'.$this->siteURL.'">our website</a>.';
|
136 |
+
}
|
137 |
+
|
138 |
+
if (!empty($message)) {
|
139 |
+
// If an update is available ?
|
140 |
+
// prevent update if error occurs
|
141 |
+
echo '<tr>';
|
142 |
+
echo '<td> </td>';
|
143 |
+
echo '<td colspan="2"> <div class="notice-message error inline notice-error notice-alt"><p>'.$message.'</p></div></td>';
|
144 |
+
echo '</tr>';
|
145 |
+
}
|
146 |
+
}
|
147 |
+
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* Ajax request for license key validation
|
152 |
+
* */
|
153 |
+
public function forceValidateLicenseKey()
|
154 |
{
|
155 |
+
$postData = \FlycartInput\FInput::getInstance();
|
156 |
+
$request = $postData->getArray();
|
157 |
+
$params = array();
|
158 |
+
if (!isset($request['data'])) return false;
|
159 |
+
parse_str($request['data'], $params);
|
160 |
+
|
161 |
+
$this->force_license_check = true;
|
162 |
|
163 |
+
$resp = array();
|
164 |
+
if (empty($params['license_key'])) {
|
165 |
+
$resp['error']='Please enter a valid license key';
|
166 |
+
echo json_encode( $resp );
|
167 |
+
die();
|
168 |
+
}
|
169 |
+
|
170 |
+
$base = new woo_dicount_rules_WooDiscountBase();
|
171 |
+
$base->saveConfig(1);
|
172 |
+
|
173 |
+
if ( $this->validateLicenseKey() ) {
|
174 |
+
$resp['success']='License key check : Passed.';
|
175 |
+
// TODO: passed tick mark with a flag
|
176 |
+
} else {
|
177 |
+
// return an error
|
178 |
+
$resp['error']='License key seems to be Invalid. Please enter a valid license key';
|
179 |
+
}
|
180 |
+
|
181 |
+
echo json_encode( $resp );
|
182 |
+
die();
|
183 |
}
|
184 |
|
185 |
+
public function validateLicenseKey()
|
186 |
{
|
187 |
+
$run = $this->doIHaveToRunValidateLicense();
|
188 |
+
|
189 |
+
$already_check = get_option('woo_discount_rules_verified_key', 0);
|
190 |
+
|
191 |
+
$cache_license_check = ( $already_check == 1 ) ? true : false ;
|
192 |
+
|
193 |
+
if($run){
|
194 |
+
$base = new woo_dicount_rules_WooDiscountBase();
|
195 |
+
$config = $base->getBaseConfig();
|
196 |
+
if (is_string($config)) $config = json_decode($config, true);
|
197 |
+
if ( isset( $config['license_key'] ) && !empty($config['license_key']) ) {
|
198 |
|
199 |
+
// check the license
|
200 |
+
$license_url = $this->getUpdateURL('licensecheck');
|
201 |
+
$result = wp_remote_get( $license_url , array());
|
202 |
+
|
203 |
+
//Try to parse the json response
|
204 |
+
$status = $this->validateApiResponse($result);
|
205 |
+
$metadata = null;
|
206 |
+
|
207 |
+
update_option('woo_discount_rules_num_runs', get_option('woo_discount_rules_num_runs',1)+1);
|
208 |
+
|
209 |
+
if ( !is_wp_error($status) ){
|
210 |
+
$json = json_decode( $result['body'] );
|
211 |
+
if ( is_object($json) && isset($json->license_check)) {
|
212 |
+
update_option('woo_discount_rules_updated_time', time());
|
213 |
+
$verified = (bool)$json->license_check;
|
214 |
+
if($verified){
|
215 |
+
update_option('woo_discount_rules_verified_key', 1);
|
216 |
+
} else {
|
217 |
+
update_option('woo_discount_rules_verified_key', 0);
|
218 |
+
}
|
219 |
+
return $verified;
|
220 |
+
}
|
221 |
+
}
|
222 |
+
}
|
223 |
+
}
|
224 |
+
return $cache_license_check;
|
225 |
+
}
|
226 |
+
|
227 |
+
/**
|
228 |
+
* Check to run validate license check
|
229 |
+
* */
|
230 |
+
protected function doIHaveToRunValidateLicense()
|
231 |
+
{
|
232 |
+
$option_exists = (get_option('woo_discount_rules_updated_time', null) !== null);
|
233 |
+
|
234 |
+
if(!$option_exists){
|
235 |
+
add_option('woo_discount_rules_updated_time', 0);
|
236 |
+
add_option('woo_discount_rules_verified_key', 0);
|
237 |
+
add_option('woo_discount_rules_num_runs',0);
|
238 |
+
}
|
239 |
+
$lastRunUnix = get_option('woo_discount_rules_updated_time', 0);
|
240 |
+
$lastRunCount = get_option('woo_discount_rules_num_runs', 0);
|
241 |
+
$nextRunUnix = $lastRunUnix;
|
242 |
+
|
243 |
+
$hours = 12;
|
244 |
+
$countLimit = 8;
|
245 |
+
|
246 |
+
$nextRunUnix += $hours * 3600;
|
247 |
+
$now = time();
|
248 |
+
|
249 |
+
$time_factor = (bool) ($now >= $nextRunUnix );
|
250 |
+
$count_factor = (bool) ($lastRunCount < $countLimit);
|
251 |
+
|
252 |
+
if ($time_factor && !$count_factor) {
|
253 |
+
update_option('woo_discount_rules_num_runs', 0);
|
254 |
+
}
|
255 |
+
|
256 |
+
$already_valid_check = get_option('woo_discount_rules_verified_key', false);
|
257 |
+
|
258 |
+
return (($time_factor && $count_factor && $already_valid_check) || $this->force_license_check );
|
259 |
+
}
|
260 |
+
|
261 |
+
public function getUpdateURL($type='updatecheck')
|
262 |
+
{
|
263 |
+
$update_url = 'https://www.flycart.org/?wpaction='.$type.'&wpslug='.$this->slug;
|
264 |
+
$purchase_helper = new woo_dicount_rules_purchase();
|
265 |
+
$update_url .= '&pro='.(int)$purchase_helper->isPro();
|
266 |
+
$dlid = '';
|
267 |
+
$base = new woo_dicount_rules_WooDiscountBase();
|
268 |
+
$config = $base->getBaseConfig();
|
269 |
+
if (is_string($config)) $config = json_decode($config);
|
270 |
+
$dlid = $config->license_key;
|
271 |
+
if ( !empty($dlid) ) {
|
272 |
+
$update_url .= '&dlid='.$dlid;
|
273 |
+
}
|
274 |
+
return $update_url;
|
275 |
}
|
276 |
+
|
277 |
+
/**
|
278 |
+
* Check if $result is a successful update API response.
|
279 |
+
*
|
280 |
+
* @param array|WP_Error $result
|
281 |
+
* @return true|WP_Error
|
282 |
+
*/
|
283 |
+
protected function validateApiResponse($result) {
|
284 |
+
if ( is_wp_error($result) ) { /** @var WP_Error $result */
|
285 |
+
return new WP_Error($result->get_error_code(), 'WP HTTP Error: ' . $result->get_error_message());
|
286 |
+
}
|
287 |
+
|
288 |
+
if ( !isset($result['response']['code']) ) {
|
289 |
+
return new WP_Error(
|
290 |
+
'puc_no_response_code',
|
291 |
+
'wp_remote_get() returned an unexpected result.'
|
292 |
+
);
|
293 |
+
}
|
294 |
+
|
295 |
+
if ( $result['response']['code'] !== 200 ) {
|
296 |
+
return new WP_Error(
|
297 |
+
'puc_unexpected_response_code',
|
298 |
+
'HTTP response code is ' . $result['response']['code'] . ' (expected: 200)'
|
299 |
+
);
|
300 |
+
}
|
301 |
+
|
302 |
+
if ( empty($result['body']) ) {
|
303 |
+
return new WP_Error('puc_empty_response', 'The metadata file appears to be empty.');
|
304 |
+
}
|
305 |
+
|
306 |
+
return true;
|
307 |
+
}
|
308 |
+
|
309 |
}
|
310 |
}
|
includes/discount-base.php
CHANGED
@@ -280,7 +280,7 @@ if (!class_exists('woo_dicount_rules_WooDiscountBase')) {
|
|
280 |
/**
|
281 |
*
|
282 |
*/
|
283 |
-
public function saveConfig()
|
284 |
{
|
285 |
$postData = \FlycartInput\FInput::getInstance();
|
286 |
$request = $postData->getArray();
|
@@ -310,7 +310,8 @@ if (!class_exists('woo_dicount_rules_WooDiscountBase')) {
|
|
310 |
} else {
|
311 |
add_option($this->default_option, $params);
|
312 |
}
|
313 |
-
|
|
|
314 |
}
|
315 |
|
316 |
/**
|
280 |
/**
|
281 |
*
|
282 |
*/
|
283 |
+
public function saveConfig($licenceValidate = 0)
|
284 |
{
|
285 |
$postData = \FlycartInput\FInput::getInstance();
|
286 |
$request = $postData->getArray();
|
310 |
} else {
|
311 |
add_option($this->default_option, $params);
|
312 |
}
|
313 |
+
if(!$licenceValidate)
|
314 |
+
die();
|
315 |
}
|
316 |
|
317 |
/**
|
loader.php
CHANGED
@@ -29,8 +29,31 @@ define('WOO_DISCOUNT_VERSION', get_plugin_data(plugin_dir_path(__FILE__).'woo-di
|
|
29 |
include_once('includes/discount-base.php');
|
30 |
include_once('includes/pricing-rules.php');
|
31 |
include_once('helper/general-helper.php');
|
|
|
32 |
require_once __DIR__ . '/vendor/autoload.php';
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
// --------------------------------------------------GENERAL HOOK-------------------------------------------------------
|
35 |
|
36 |
/** Initiating Plugin */
|
29 |
include_once('includes/discount-base.php');
|
30 |
include_once('includes/pricing-rules.php');
|
31 |
include_once('helper/general-helper.php');
|
32 |
+
include_once('helper/purchase.php');
|
33 |
require_once __DIR__ . '/vendor/autoload.php';
|
34 |
|
35 |
+
// -------------------------- updater -----------------------------------------------------
|
36 |
+
require plugin_dir_path( __FILE__ ).'/vendor/yahnis-elsts/plugin-update-checker/plugin-update-checker.php';
|
37 |
+
|
38 |
+
$purchase_helper = new woo_dicount_rules_purchase();
|
39 |
+
$purchase_helper->init();
|
40 |
+
$update_url = $purchase_helper->getUpdateURL();
|
41 |
+
|
42 |
+
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
|
43 |
+
$update_url,
|
44 |
+
plugin_dir_path( __FILE__ ).'woo-discount-rules.php',
|
45 |
+
'woo-discount-rules'
|
46 |
+
);
|
47 |
+
|
48 |
+
add_action( 'after_plugin_row', array($purchase_helper, 'woodisc_after_plugin_row'),10,3 );
|
49 |
+
|
50 |
+
add_action('wp_ajax_forceValidateLicenseKey', array($purchase_helper, 'forceValidateLicenseKey'));
|
51 |
+
|
52 |
+
add_action( 'admin_notices', array($purchase_helper, 'errorNoticeInAdminPages'));
|
53 |
+
|
54 |
+
// -------------------------- end updater -------------------------------------------------
|
55 |
+
|
56 |
+
|
57 |
// --------------------------------------------------GENERAL HOOK-------------------------------------------------------
|
58 |
|
59 |
/** Initiating Plugin */
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://flycart.org/
|
|
4 |
Tags: woocommerce, ecommerce, discounts, coupons, promotion, campaigns, sales, price rules, advanced coupons, advanced discounts
|
5 |
Requires at least: 4.4.1
|
6 |
Tested up to: 4.7
|
7 |
-
Stable tag: 1.4.
|
8 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
@@ -116,4 +116,4 @@ More information could be found in the documentation
|
|
116 |
= 1.4.0 - 26/10/16 =
|
117 |
* PHP 5.3 compatibility added
|
118 |
|
119 |
-
== Upgrade notice ==
|
4 |
Tags: woocommerce, ecommerce, discounts, coupons, promotion, campaigns, sales, price rules, advanced coupons, advanced discounts
|
5 |
Requires at least: 4.4.1
|
6 |
Tested up to: 4.7
|
7 |
+
Stable tag: 1.4.8
|
8 |
License: GPLv3 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
116 |
= 1.4.0 - 26/10/16 =
|
117 |
* PHP 5.3 compatibility added
|
118 |
|
119 |
+
== Upgrade notice ==
|
vendor/askupa-software/wp-admin-notification/LICENSE
ADDED
@@ -0,0 +1,674 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
GNU GENERAL PUBLIC LICENSE
|
2 |
+
Version 3, 29 June 2007
|
3 |
+
|
4 |
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
5 |
+
Everyone is permitted to copy and distribute verbatim copies
|
6 |
+
of this license document, but changing it is not allowed.
|
7 |
+
|
8 |
+
Preamble
|
9 |
+
|
10 |
+
The GNU General Public License is a free, copyleft license for
|
11 |
+
software and other kinds of works.
|
12 |
+
|
13 |
+
The licenses for most software and other practical works are designed
|
14 |
+
to take away your freedom to share and change the works. By contrast,
|
15 |
+
the GNU General Public License is intended to guarantee your freedom to
|
16 |
+
share and change all versions of a program--to make sure it remains free
|
17 |
+
software for all its users. We, the Free Software Foundation, use the
|
18 |
+
GNU General Public License for most of our software; it applies also to
|
19 |
+
any other work released this way by its authors. You can apply it to
|
20 |
+
your programs, too.
|
21 |
+
|
22 |
+
When we speak of free software, we are referring to freedom, not
|
23 |
+
price. Our General Public Licenses are designed to make sure that you
|
24 |
+
have the freedom to distribute copies of free software (and charge for
|
25 |
+
them if you wish), that you receive source code or can get it if you
|
26 |
+
want it, that you can change the software or use pieces of it in new
|
27 |
+
free programs, and that you know you can do these things.
|
28 |
+
|
29 |
+
To protect your rights, we need to prevent others from denying you
|
30 |
+
these rights or asking you to surrender the rights. Therefore, you have
|
31 |
+
certain responsibilities if you distribute copies of the software, or if
|
32 |
+
you modify it: responsibilities to respect the freedom of others.
|
33 |
+
|
34 |
+
For example, if you distribute copies of such a program, whether
|
35 |
+
gratis or for a fee, you must pass on to the recipients the same
|
36 |
+
freedoms that you received. You must make sure that they, too, receive
|
37 |
+
or can get the source code. And you must show them these terms so they
|
38 |
+
know their rights.
|
39 |
+
|
40 |
+
Developers that use the GNU GPL protect your rights with two steps:
|
41 |
+
(1) assert copyright on the software, and (2) offer you this License
|
42 |
+
giving you legal permission to copy, distribute and/or modify it.
|
43 |
+
|
44 |
+
For the developers' and authors' protection, the GPL clearly explains
|
45 |
+
that there is no warranty for this free software. For both users' and
|
46 |
+
authors' sake, the GPL requires that modified versions be marked as
|
47 |
+
changed, so that their problems will not be attributed erroneously to
|
48 |
+
authors of previous versions.
|
49 |
+
|
50 |
+
Some devices are designed to deny users access to install or run
|
51 |
+
modified versions of the software inside them, although the manufacturer
|
52 |
+
can do so. This is fundamentally incompatible with the aim of
|
53 |
+
protecting users' freedom to change the software. The systematic
|
54 |
+
pattern of such abuse occurs in the area of products for individuals to
|
55 |
+
use, which is precisely where it is most unacceptable. Therefore, we
|
56 |
+
have designed this version of the GPL to prohibit the practice for those
|
57 |
+
products. If such problems arise substantially in other domains, we
|
58 |
+
stand ready to extend this provision to those domains in future versions
|
59 |
+
of the GPL, as needed to protect the freedom of users.
|
60 |
+
|
61 |
+
Finally, every program is threatened constantly by software patents.
|
62 |
+
States should not allow patents to restrict development and use of
|
63 |
+
software on general-purpose computers, but in those that do, we wish to
|
64 |
+
avoid the special danger that patents applied to a free program could
|
65 |
+
make it effectively proprietary. To prevent this, the GPL assures that
|
66 |
+
patents cannot be used to render the program non-free.
|
67 |
+
|
68 |
+
The precise terms and conditions for copying, distribution and
|
69 |
+
modification follow.
|
70 |
+
|
71 |
+
TERMS AND CONDITIONS
|
72 |
+
|
73 |
+
0. Definitions.
|
74 |
+
|
75 |
+
"This License" refers to version 3 of the GNU General Public License.
|
76 |
+
|
77 |
+
"Copyright" also means copyright-like laws that apply to other kinds of
|
78 |
+
works, such as semiconductor masks.
|
79 |
+
|
80 |
+
"The Program" refers to any copyrightable work licensed under this
|
81 |
+
License. Each licensee is addressed as "you". "Licensees" and
|
82 |
+
"recipients" may be individuals or organizations.
|
83 |
+
|
84 |
+
To "modify" a work means to copy from or adapt all or part of the work
|
85 |
+
in a fashion requiring copyright permission, other than the making of an
|
86 |
+
exact copy. The resulting work is called a "modified version" of the
|
87 |
+
earlier work or a work "based on" the earlier work.
|
88 |
+
|
89 |
+
A "covered work" means either the unmodified Program or a work based
|
90 |
+
on the Program.
|
91 |
+
|
92 |
+
To "propagate" a work means to do anything with it that, without
|
93 |
+
permission, would make you directly or secondarily liable for
|
94 |
+
infringement under applicable copyright law, except executing it on a
|
95 |
+
computer or modifying a private copy. Propagation includes copying,
|
96 |
+
distribution (with or without modification), making available to the
|
97 |
+
public, and in some countries other activities as well.
|
98 |
+
|
99 |
+
To "convey" a work means any kind of propagation that enables other
|
100 |
+
parties to make or receive copies. Mere interaction with a user through
|
101 |
+
a computer network, with no transfer of a copy, is not conveying.
|
102 |
+
|
103 |
+
An interactive user interface displays "Appropriate Legal Notices"
|
104 |
+
to the extent that it includes a convenient and prominently visible
|
105 |
+
feature that (1) displays an appropriate copyright notice, and (2)
|
106 |
+
tells the user that there is no warranty for the work (except to the
|
107 |
+
extent that warranties are provided), that licensees may convey the
|
108 |
+
work under this License, and how to view a copy of this License. If
|
109 |
+
the interface presents a list of user commands or options, such as a
|
110 |
+
menu, a prominent item in the list meets this criterion.
|
111 |
+
|
112 |
+
1. Source Code.
|
113 |
+
|
114 |
+
The "source code" for a work means the preferred form of the work
|
115 |
+
for making modifications to it. "Object code" means any non-source
|
116 |
+
form of a work.
|
117 |
+
|
118 |
+
A "Standard Interface" means an interface that either is an official
|
119 |
+
standard defined by a recognized standards body, or, in the case of
|
120 |
+
interfaces specified for a particular programming language, one that
|
121 |
+
is widely used among developers working in that language.
|
122 |
+
|
123 |
+
The "System Libraries" of an executable work include anything, other
|
124 |
+
than the work as a whole, that (a) is included in the normal form of
|
125 |
+
packaging a Major Component, but which is not part of that Major
|
126 |
+
Component, and (b) serves only to enable use of the work with that
|
127 |
+
Major Component, or to implement a Standard Interface for which an
|
128 |
+
implementation is available to the public in source code form. A
|
129 |
+
"Major Component", in this context, means a major essential component
|
130 |
+
(kernel, window system, and so on) of the specific operating system
|
131 |
+
(if any) on which the executable work runs, or a compiler used to
|
132 |
+
produce the work, or an object code interpreter used to run it.
|
133 |
+
|
134 |
+
The "Corresponding Source" for a work in object code form means all
|
135 |
+
the source code needed to generate, install, and (for an executable
|
136 |
+
work) run the object code and to modify the work, including scripts to
|
137 |
+
control those activities. However, it does not include the work's
|
138 |
+
System Libraries, or general-purpose tools or generally available free
|
139 |
+
programs which are used unmodified in performing those activities but
|
140 |
+
which are not part of the work. For example, Corresponding Source
|
141 |
+
includes interface definition files associated with source files for
|
142 |
+
the work, and the source code for shared libraries and dynamically
|
143 |
+
linked subprograms that the work is specifically designed to require,
|
144 |
+
such as by intimate data communication or control flow between those
|
145 |
+
subprograms and other parts of the work.
|
146 |
+
|
147 |
+
The Corresponding Source need not include anything that users
|
148 |
+
can regenerate automatically from other parts of the Corresponding
|
149 |
+
Source.
|
150 |
+
|
151 |
+
The Corresponding Source for a work in source code form is that
|
152 |
+
same work.
|
153 |
+
|
154 |
+
2. Basic Permissions.
|
155 |
+
|
156 |
+
All rights granted under this License are granted for the term of
|
157 |
+
copyright on the Program, and are irrevocable provided the stated
|
158 |
+
conditions are met. This License explicitly affirms your unlimited
|
159 |
+
permission to run the unmodified Program. The output from running a
|
160 |
+
covered work is covered by this License only if the output, given its
|
161 |
+
content, constitutes a covered work. This License acknowledges your
|
162 |
+
rights of fair use or other equivalent, as provided by copyright law.
|
163 |
+
|
164 |
+
You may make, run and propagate covered works that you do not
|
165 |
+
convey, without conditions so long as your license otherwise remains
|
166 |
+
in force. You may convey covered works to others for the sole purpose
|
167 |
+
of having them make modifications exclusively for you, or provide you
|
168 |
+
with facilities for running those works, provided that you comply with
|
169 |
+
the terms of this License in conveying all material for which you do
|
170 |
+
not control copyright. Those thus making or running the covered works
|
171 |
+
for you must do so exclusively on your behalf, under your direction
|
172 |
+
and control, on terms that prohibit them from making any copies of
|
173 |
+
your copyrighted material outside their relationship with you.
|
174 |
+
|
175 |
+
Conveying under any other circumstances is permitted solely under
|
176 |
+
the conditions stated below. Sublicensing is not allowed; section 10
|
177 |
+
makes it unnecessary.
|
178 |
+
|
179 |
+
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
180 |
+
|
181 |
+
No covered work shall be deemed part of an effective technological
|
182 |
+
measure under any applicable law fulfilling obligations under article
|
183 |
+
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
184 |
+
similar laws prohibiting or restricting circumvention of such
|
185 |
+
measures.
|
186 |
+
|
187 |
+
When you convey a covered work, you waive any legal power to forbid
|
188 |
+
circumvention of technological measures to the extent such circumvention
|
189 |
+
is effected by exercising rights under this License with respect to
|
190 |
+
the covered work, and you disclaim any intention to limit operation or
|
191 |
+
modification of the work as a means of enforcing, against the work's
|
192 |
+
users, your or third parties' legal rights to forbid circumvention of
|
193 |
+
technological measures.
|
194 |
+
|
195 |
+
4. Conveying Verbatim Copies.
|
196 |
+
|
197 |
+
You may convey verbatim copies of the Program's source code as you
|
198 |
+
receive it, in any medium, provided that you conspicuously and
|
199 |
+
appropriately publish on each copy an appropriate copyright notice;
|
200 |
+
keep intact all notices stating that this License and any
|
201 |
+
non-permissive terms added in accord with section 7 apply to the code;
|
202 |
+
keep intact all notices of the absence of any warranty; and give all
|
203 |
+
recipients a copy of this License along with the Program.
|
204 |
+
|
205 |
+
You may charge any price or no price for each copy that you convey,
|
206 |
+
and you may offer support or warranty protection for a fee.
|
207 |
+
|
208 |
+
5. Conveying Modified Source Versions.
|
209 |
+
|
210 |
+
You may convey a work based on the Program, or the modifications to
|
211 |
+
produce it from the Program, in the form of source code under the
|
212 |
+
terms of section 4, provided that you also meet all of these conditions:
|
213 |
+
|
214 |
+
a) The work must carry prominent notices stating that you modified
|
215 |
+
it, and giving a relevant date.
|
216 |
+
|
217 |
+
b) The work must carry prominent notices stating that it is
|
218 |
+
released under this License and any conditions added under section
|
219 |
+
7. This requirement modifies the requirement in section 4 to
|
220 |
+
"keep intact all notices".
|
221 |
+
|
222 |
+
c) You must license the entire work, as a whole, under this
|
223 |
+
License to anyone who comes into possession of a copy. This
|
224 |
+
License will therefore apply, along with any applicable section 7
|
225 |
+
additional terms, to the whole of the work, and all its parts,
|
226 |
+
regardless of how they are packaged. This License gives no
|
227 |
+
permission to license the work in any other way, but it does not
|
228 |
+
invalidate such permission if you have separately received it.
|
229 |
+
|
230 |
+
d) If the work has interactive user interfaces, each must display
|
231 |
+
Appropriate Legal Notices; however, if the Program has interactive
|
232 |
+
interfaces that do not display Appropriate Legal Notices, your
|
233 |
+
work need not make them do so.
|
234 |
+
|
235 |
+
A compilation of a covered work with other separate and independent
|
236 |
+
works, which are not by their nature extensions of the covered work,
|
237 |
+
and which are not combined with it such as to form a larger program,
|
238 |
+
in or on a volume of a storage or distribution medium, is called an
|
239 |
+
"aggregate" if the compilation and its resulting copyright are not
|
240 |
+
used to limit the access or legal rights of the compilation's users
|
241 |
+
beyond what the individual works permit. Inclusion of a covered work
|
242 |
+
in an aggregate does not cause this License to apply to the other
|
243 |
+
parts of the aggregate.
|
244 |
+
|
245 |
+
6. Conveying Non-Source Forms.
|
246 |
+
|
247 |
+
You may convey a covered work in object code form under the terms
|
248 |
+
of sections 4 and 5, provided that you also convey the
|
249 |
+
machine-readable Corresponding Source under the terms of this License,
|
250 |
+
in one of these ways:
|
251 |
+
|
252 |
+
a) Convey the object code in, or embodied in, a physical product
|
253 |
+
(including a physical distribution medium), accompanied by the
|
254 |
+
Corresponding Source fixed on a durable physical medium
|
255 |
+
customarily used for software interchange.
|
256 |
+
|
257 |
+
b) Convey the object code in, or embodied in, a physical product
|
258 |
+
(including a physical distribution medium), accompanied by a
|
259 |
+
written offer, valid for at least three years and valid for as
|
260 |
+
long as you offer spare parts or customer support for that product
|
261 |
+
model, to give anyone who possesses the object code either (1) a
|
262 |
+
copy of the Corresponding Source for all the software in the
|
263 |
+
product that is covered by this License, on a durable physical
|
264 |
+
medium customarily used for software interchange, for a price no
|
265 |
+
more than your reasonable cost of physically performing this
|
266 |
+
conveying of source, or (2) access to copy the
|
267 |
+
Corresponding Source from a network server at no charge.
|
268 |
+
|
269 |
+
c) Convey individual copies of the object code with a copy of the
|
270 |
+
written offer to provide the Corresponding Source. This
|
271 |
+
alternative is allowed only occasionally and noncommercially, and
|
272 |
+
only if you received the object code with such an offer, in accord
|
273 |
+
with subsection 6b.
|
274 |
+
|
275 |
+
d) Convey the object code by offering access from a designated
|
276 |
+
place (gratis or for a charge), and offer equivalent access to the
|
277 |
+
Corresponding Source in the same way through the same place at no
|
278 |
+
further charge. You need not require recipients to copy the
|
279 |
+
Corresponding Source along with the object code. If the place to
|
280 |
+
copy the object code is a network server, the Corresponding Source
|
281 |
+
may be on a different server (operated by you or a third party)
|
282 |
+
that supports equivalent copying facilities, provided you maintain
|
283 |
+
clear directions next to the object code saying where to find the
|
284 |
+
Corresponding Source. Regardless of what server hosts the
|
285 |
+
Corresponding Source, you remain obligated to ensure that it is
|
286 |
+
available for as long as needed to satisfy these requirements.
|
287 |
+
|
288 |
+
e) Convey the object code using peer-to-peer transmission, provided
|
289 |
+
you inform other peers where the object code and Corresponding
|
290 |
+
Source of the work are being offered to the general public at no
|
291 |
+
charge under subsection 6d.
|
292 |
+
|
293 |
+
A separable portion of the object code, whose source code is excluded
|
294 |
+
from the Corresponding Source as a System Library, need not be
|
295 |
+
included in conveying the object code work.
|
296 |
+
|
297 |
+
A "User Product" is either (1) a "consumer product", which means any
|
298 |
+
tangible personal property which is normally used for personal, family,
|
299 |
+
or household purposes, or (2) anything designed or sold for incorporation
|
300 |
+
into a dwelling. In determining whether a product is a consumer product,
|
301 |
+
doubtful cases shall be resolved in favor of coverage. For a particular
|
302 |
+
product received by a particular user, "normally used" refers to a
|
303 |
+
typical or common use of that class of product, regardless of the status
|
304 |
+
of the particular user or of the way in which the particular user
|
305 |
+
actually uses, or expects or is expected to use, the product. A product
|
306 |
+
is a consumer product regardless of whether the product has substantial
|
307 |
+
commercial, industrial or non-consumer uses, unless such uses represent
|
308 |
+
the only significant mode of use of the product.
|
309 |
+
|
310 |
+
"Installation Information" for a User Product means any methods,
|
311 |
+
procedures, authorization keys, or other information required to install
|
312 |
+
and execute modified versions of a covered work in that User Product from
|
313 |
+
a modified version of its Corresponding Source. The information must
|
314 |
+
suffice to ensure that the continued functioning of the modified object
|
315 |
+
code is in no case prevented or interfered with solely because
|
316 |
+
modification has been made.
|
317 |
+
|
318 |
+
If you convey an object code work under this section in, or with, or
|
319 |
+
specifically for use in, a User Product, and the conveying occurs as
|
320 |
+
part of a transaction in which the right of possession and use of the
|
321 |
+
User Product is transferred to the recipient in perpetuity or for a
|
322 |
+
fixed term (regardless of how the transaction is characterized), the
|
323 |
+
Corresponding Source conveyed under this section must be accompanied
|
324 |
+
by the Installation Information. But this requirement does not apply
|
325 |
+
if neither you nor any third party retains the ability to install
|
326 |
+
modified object code on the User Product (for example, the work has
|
327 |
+
been installed in ROM).
|
328 |
+
|
329 |
+
The requirement to provide Installation Information does not include a
|
330 |
+
requirement to continue to provide support service, warranty, or updates
|
331 |
+
for a work that has been modified or installed by the recipient, or for
|
332 |
+
the User Product in which it has been modified or installed. Access to a
|
333 |
+
network may be denied when the modification itself materially and
|
334 |
+
adversely affects the operation of the network or violates the rules and
|
335 |
+
protocols for communication across the network.
|
336 |
+
|
337 |
+
Corresponding Source conveyed, and Installation Information provided,
|
338 |
+
in accord with this section must be in a format that is publicly
|
339 |
+
documented (and with an implementation available to the public in
|
340 |
+
source code form), and must require no special password or key for
|
341 |
+
unpacking, reading or copying.
|
342 |
+
|
343 |
+
7. Additional Terms.
|
344 |
+
|
345 |
+
"Additional permissions" are terms that supplement the terms of this
|
346 |
+
License by making exceptions from one or more of its conditions.
|
347 |
+
Additional permissions that are applicable to the entire Program shall
|
348 |
+
be treated as though they were included in this License, to the extent
|
349 |
+
that they are valid under applicable law. If additional permissions
|
350 |
+
apply only to part of the Program, that part may be used separately
|
351 |
+
under those permissions, but the entire Program remains governed by
|
352 |
+
this License without regard to the additional permissions.
|
353 |
+
|
354 |
+
When you convey a copy of a covered work, you may at your option
|
355 |
+
remove any additional permissions from that copy, or from any part of
|
356 |
+
it. (Additional permissions may be written to require their own
|
357 |
+
removal in certain cases when you modify the work.) You may place
|
358 |
+
additional permissions on material, added by you to a covered work,
|
359 |
+
for which you have or can give appropriate copyright permission.
|
360 |
+
|
361 |
+
Notwithstanding any other provision of this License, for material you
|
362 |
+
add to a covered work, you may (if authorized by the copyright holders of
|
363 |
+
that material) supplement the terms of this License with terms:
|
364 |
+
|
365 |
+
a) Disclaiming warranty or limiting liability differently from the
|
366 |
+
terms of sections 15 and 16 of this License; or
|
367 |
+
|
368 |
+
b) Requiring preservation of specified reasonable legal notices or
|
369 |
+
author attributions in that material or in the Appropriate Legal
|
370 |
+
Notices displayed by works containing it; or
|
371 |
+
|
372 |
+
c) Prohibiting misrepresentation of the origin of that material, or
|
373 |
+
requiring that modified versions of such material be marked in
|
374 |
+
reasonable ways as different from the original version; or
|
375 |
+
|
376 |
+
d) Limiting the use for publicity purposes of names of licensors or
|
377 |
+
authors of the material; or
|
378 |
+
|
379 |
+
e) Declining to grant rights under trademark law for use of some
|
380 |
+
trade names, trademarks, or service marks; or
|
381 |
+
|
382 |
+
f) Requiring indemnification of licensors and authors of that
|
383 |
+
material by anyone who conveys the material (or modified versions of
|
384 |
+
it) with contractual assumptions of liability to the recipient, for
|
385 |
+
any liability that these contractual assumptions directly impose on
|
386 |
+
those licensors and authors.
|
387 |
+
|
388 |
+
All other non-permissive additional terms are considered "further
|
389 |
+
restrictions" within the meaning of section 10. If the Program as you
|
390 |
+
received it, or any part of it, contains a notice stating that it is
|
391 |
+
governed by this License along with a term that is a further
|
392 |
+
restriction, you may remove that term. If a license document contains
|
393 |
+
a further restriction but permits relicensing or conveying under this
|
394 |
+
License, you may add to a covered work material governed by the terms
|
395 |
+
of that license document, provided that the further restriction does
|
396 |
+
not survive such relicensing or conveying.
|
397 |
+
|
398 |
+
If you add terms to a covered work in accord with this section, you
|
399 |
+
must place, in the relevant source files, a statement of the
|
400 |
+
additional terms that apply to those files, or a notice indicating
|
401 |
+
where to find the applicable terms.
|
402 |
+
|
403 |
+
Additional terms, permissive or non-permissive, may be stated in the
|
404 |
+
form of a separately written license, or stated as exceptions;
|
405 |
+
the above requirements apply either way.
|
406 |
+
|
407 |
+
8. Termination.
|
408 |
+
|
409 |
+
You may not propagate or modify a covered work except as expressly
|
410 |
+
provided under this License. Any attempt otherwise to propagate or
|
411 |
+
modify it is void, and will automatically terminate your rights under
|
412 |
+
this License (including any patent licenses granted under the third
|
413 |
+
paragraph of section 11).
|
414 |
+
|
415 |
+
However, if you cease all violation of this License, then your
|
416 |
+
license from a particular copyright holder is reinstated (a)
|
417 |
+
provisionally, unless and until the copyright holder explicitly and
|
418 |
+
finally terminates your license, and (b) permanently, if the copyright
|
419 |
+
holder fails to notify you of the violation by some reasonable means
|
420 |
+
prior to 60 days after the cessation.
|
421 |
+
|
422 |
+
Moreover, your license from a particular copyright holder is
|
423 |
+
reinstated permanently if the copyright holder notifies you of the
|
424 |
+
violation by some reasonable means, this is the first time you have
|
425 |
+
received notice of violation of this License (for any work) from that
|
426 |
+
copyright holder, and you cure the violation prior to 30 days after
|
427 |
+
your receipt of the notice.
|
428 |
+
|
429 |
+
Termination of your rights under this section does not terminate the
|
430 |
+
licenses of parties who have received copies or rights from you under
|
431 |
+
this License. If your rights have been terminated and not permanently
|
432 |
+
reinstated, you do not qualify to receive new licenses for the same
|
433 |
+
material under section 10.
|
434 |
+
|
435 |
+
9. Acceptance Not Required for Having Copies.
|
436 |
+
|
437 |
+
You are not required to accept this License in order to receive or
|
438 |
+
run a copy of the Program. Ancillary propagation of a covered work
|
439 |
+
occurring solely as a consequence of using peer-to-peer transmission
|
440 |
+
to receive a copy likewise does not require acceptance. However,
|
441 |
+
nothing other than this License grants you permission to propagate or
|
442 |
+
modify any covered work. These actions infringe copyright if you do
|
443 |
+
not accept this License. Therefore, by modifying or propagating a
|
444 |
+
covered work, you indicate your acceptance of this License to do so.
|
445 |
+
|
446 |
+
10. Automatic Licensing of Downstream Recipients.
|
447 |
+
|
448 |
+
Each time you convey a covered work, the recipient automatically
|
449 |
+
receives a license from the original licensors, to run, modify and
|
450 |
+
propagate that work, subject to this License. You are not responsible
|
451 |
+
for enforcing compliance by third parties with this License.
|
452 |
+
|
453 |
+
An "entity transaction" is a transaction transferring control of an
|
454 |
+
organization, or substantially all assets of one, or subdividing an
|
455 |
+
organization, or merging organizations. If propagation of a covered
|
456 |
+
work results from an entity transaction, each party to that
|
457 |
+
transaction who receives a copy of the work also receives whatever
|
458 |
+
licenses to the work the party's predecessor in interest had or could
|
459 |
+
give under the previous paragraph, plus a right to possession of the
|
460 |
+
Corresponding Source of the work from the predecessor in interest, if
|
461 |
+
the predecessor has it or can get it with reasonable efforts.
|
462 |
+
|
463 |
+
You may not impose any further restrictions on the exercise of the
|
464 |
+
rights granted or affirmed under this License. For example, you may
|
465 |
+
not impose a license fee, royalty, or other charge for exercise of
|
466 |
+
rights granted under this License, and you may not initiate litigation
|
467 |
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
468 |
+
any patent claim is infringed by making, using, selling, offering for
|
469 |
+
sale, or importing the Program or any portion of it.
|
470 |
+
|
471 |
+
11. Patents.
|
472 |
+
|
473 |
+
A "contributor" is a copyright holder who authorizes use under this
|
474 |
+
License of the Program or a work on which the Program is based. The
|
475 |
+
work thus licensed is called the contributor's "contributor version".
|
476 |
+
|
477 |
+
A contributor's "essential patent claims" are all patent claims
|
478 |
+
owned or controlled by the contributor, whether already acquired or
|
479 |
+
hereafter acquired, that would be infringed by some manner, permitted
|
480 |
+
by this License, of making, using, or selling its contributor version,
|
481 |
+
but do not include claims that would be infringed only as a
|
482 |
+
consequence of further modification of the contributor version. For
|
483 |
+
purposes of this definition, "control" includes the right to grant
|
484 |
+
patent sublicenses in a manner consistent with the requirements of
|
485 |
+
this License.
|
486 |
+
|
487 |
+
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
488 |
+
patent license under the contributor's essential patent claims, to
|
489 |
+
make, use, sell, offer for sale, import and otherwise run, modify and
|
490 |
+
propagate the contents of its contributor version.
|
491 |
+
|
492 |
+
In the following three paragraphs, a "patent license" is any express
|
493 |
+
agreement or commitment, however denominated, not to enforce a patent
|
494 |
+
(such as an express permission to practice a patent or covenant not to
|
495 |
+
sue for patent infringement). To "grant" such a patent license to a
|
496 |
+
party means to make such an agreement or commitment not to enforce a
|
497 |
+
patent against the party.
|
498 |
+
|
499 |
+
If you convey a covered work, knowingly relying on a patent license,
|
500 |
+
and the Corresponding Source of the work is not available for anyone
|
501 |
+
to copy, free of charge and under the terms of this License, through a
|
502 |
+
publicly available network server or other readily accessible means,
|
503 |
+
then you must either (1) cause the Corresponding Source to be so
|
504 |
+
available, or (2) arrange to deprive yourself of the benefit of the
|
505 |
+
patent license for this particular work, or (3) arrange, in a manner
|
506 |
+
consistent with the requirements of this License, to extend the patent
|
507 |
+
license to downstream recipients. "Knowingly relying" means you have
|
508 |
+
actual knowledge that, but for the patent license, your conveying the
|
509 |
+
covered work in a country, or your recipient's use of the covered work
|
510 |
+
in a country, would infringe one or more identifiable patents in that
|
511 |
+
country that you have reason to believe are valid.
|
512 |
+
|
513 |
+
If, pursuant to or in connection with a single transaction or
|
514 |
+
arrangement, you convey, or propagate by procuring conveyance of, a
|
515 |
+
covered work, and grant a patent license to some of the parties
|
516 |
+
receiving the covered work authorizing them to use, propagate, modify
|
517 |
+
or convey a specific copy of the covered work, then the patent license
|
518 |
+
you grant is automatically extended to all recipients of the covered
|
519 |
+
work and works based on it.
|
520 |
+
|
521 |
+
A patent license is "discriminatory" if it does not include within
|
522 |
+
the scope of its coverage, prohibits the exercise of, or is
|
523 |
+
conditioned on the non-exercise of one or more of the rights that are
|
524 |
+
specifically granted under this License. You may not convey a covered
|
525 |
+
work if you are a party to an arrangement with a third party that is
|
526 |
+
in the business of distributing software, under which you make payment
|
527 |
+
to the third party based on the extent of your activity of conveying
|
528 |
+
the work, and under which the third party grants, to any of the
|
529 |
+
parties who would receive the covered work from you, a discriminatory
|
530 |
+
patent license (a) in connection with copies of the covered work
|
531 |
+
conveyed by you (or copies made from those copies), or (b) primarily
|
532 |
+
for and in connection with specific products or compilations that
|
533 |
+
contain the covered work, unless you entered into that arrangement,
|
534 |
+
or that patent license was granted, prior to 28 March 2007.
|
535 |
+
|
536 |
+
Nothing in this License shall be construed as excluding or limiting
|
537 |
+
any implied license or other defenses to infringement that may
|
538 |
+
otherwise be available to you under applicable patent law.
|
539 |
+
|
540 |
+
12. No Surrender of Others' Freedom.
|
541 |
+
|
542 |
+
If conditions are imposed on you (whether by court order, agreement or
|
543 |
+
otherwise) that contradict the conditions of this License, they do not
|
544 |
+
excuse you from the conditions of this License. If you cannot convey a
|
545 |
+
covered work so as to satisfy simultaneously your obligations under this
|
546 |
+
License and any other pertinent obligations, then as a consequence you may
|
547 |
+
not convey it at all. For example, if you agree to terms that obligate you
|
548 |
+
to collect a royalty for further conveying from those to whom you convey
|
549 |
+
the Program, the only way you could satisfy both those terms and this
|
550 |
+
License would be to refrain entirely from conveying the Program.
|
551 |
+
|
552 |
+
13. Use with the GNU Affero General Public License.
|
553 |
+
|
554 |
+
Notwithstanding any other provision of this License, you have
|
555 |
+
permission to link or combine any covered work with a work licensed
|
556 |
+
under version 3 of the GNU Affero General Public License into a single
|
557 |
+
combined work, and to convey the resulting work. The terms of this
|
558 |
+
License will continue to apply to the part which is the covered work,
|
559 |
+
but the special requirements of the GNU Affero General Public License,
|
560 |
+
section 13, concerning interaction through a network will apply to the
|
561 |
+
combination as such.
|
562 |
+
|
563 |
+
14. Revised Versions of this License.
|
564 |
+
|
565 |
+
The Free Software Foundation may publish revised and/or new versions of
|
566 |
+
the GNU General Public License from time to time. Such new versions will
|
567 |
+
be similar in spirit to the present version, but may differ in detail to
|
568 |
+
address new problems or concerns.
|
569 |
+
|
570 |
+
Each version is given a distinguishing version number. If the
|
571 |
+
Program specifies that a certain numbered version of the GNU General
|
572 |
+
Public License "or any later version" applies to it, you have the
|
573 |
+
option of following the terms and conditions either of that numbered
|
574 |
+
version or of any later version published by the Free Software
|
575 |
+
Foundation. If the Program does not specify a version number of the
|
576 |
+
GNU General Public License, you may choose any version ever published
|
577 |
+
by the Free Software Foundation.
|
578 |
+
|
579 |
+
If the Program specifies that a proxy can decide which future
|
580 |
+
versions of the GNU General Public License can be used, that proxy's
|
581 |
+
public statement of acceptance of a version permanently authorizes you
|
582 |
+
to choose that version for the Program.
|
583 |
+
|
584 |
+
Later license versions may give you additional or different
|
585 |
+
permissions. However, no additional obligations are imposed on any
|
586 |
+
author or copyright holder as a result of your choosing to follow a
|
587 |
+
later version.
|
588 |
+
|
589 |
+
15. Disclaimer of Warranty.
|
590 |
+
|
591 |
+
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
592 |
+
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
593 |
+
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
594 |
+
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
595 |
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
596 |
+
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
597 |
+
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
598 |
+
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
599 |
+
|
600 |
+
16. Limitation of Liability.
|
601 |
+
|
602 |
+
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
603 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
604 |
+
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
605 |
+
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
606 |
+
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
607 |
+
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
608 |
+
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
609 |
+
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
610 |
+
SUCH DAMAGES.
|
611 |
+
|
612 |
+
17. Interpretation of Sections 15 and 16.
|
613 |
+
|
614 |
+
If the disclaimer of warranty and limitation of liability provided
|
615 |
+
above cannot be given local legal effect according to their terms,
|
616 |
+
reviewing courts shall apply local law that most closely approximates
|
617 |
+
an absolute waiver of all civil liability in connection with the
|
618 |
+
Program, unless a warranty or assumption of liability accompanies a
|
619 |
+
copy of the Program in return for a fee.
|
620 |
+
|
621 |
+
END OF TERMS AND CONDITIONS
|
622 |
+
|
623 |
+
How to Apply These Terms to Your New Programs
|
624 |
+
|
625 |
+
If you develop a new program, and you want it to be of the greatest
|
626 |
+
possible use to the public, the best way to achieve this is to make it
|
627 |
+
free software which everyone can redistribute and change under these terms.
|
628 |
+
|
629 |
+
To do so, attach the following notices to the program. It is safest
|
630 |
+
to attach them to the start of each source file to most effectively
|
631 |
+
state the exclusion of warranty; and each file should have at least
|
632 |
+
the "copyright" line and a pointer to where the full notice is found.
|
633 |
+
|
634 |
+
{one line to give the program's name and a brief idea of what it does.}
|
635 |
+
Copyright (C) {year} {name of author}
|
636 |
+
|
637 |
+
This program is free software: you can redistribute it and/or modify
|
638 |
+
it under the terms of the GNU General Public License as published by
|
639 |
+
the Free Software Foundation, either version 3 of the License, or
|
640 |
+
(at your option) any later version.
|
641 |
+
|
642 |
+
This program is distributed in the hope that it will be useful,
|
643 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
644 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
645 |
+
GNU General Public License for more details.
|
646 |
+
|
647 |
+
You should have received a copy of the GNU General Public License
|
648 |
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
649 |
+
|
650 |
+
Also add information on how to contact you by electronic and paper mail.
|
651 |
+
|
652 |
+
If the program does terminal interaction, make it output a short
|
653 |
+
notice like this when it starts in an interactive mode:
|
654 |
+
|
655 |
+
{project} Copyright (C) {year} {fullname}
|
656 |
+
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
657 |
+
This is free software, and you are welcome to redistribute it
|
658 |
+
under certain conditions; type `show c' for details.
|
659 |
+
|
660 |
+
The hypothetical commands `show w' and `show c' should show the appropriate
|
661 |
+
parts of the General Public License. Of course, your program's commands
|
662 |
+
might be different; for a GUI interface, you would use an "about box".
|
663 |
+
|
664 |
+
You should also get your employer (if you work as a programmer) or school,
|
665 |
+
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
666 |
+
For more information on this, and how to apply and follow the GNU GPL, see
|
667 |
+
<http://www.gnu.org/licenses/>.
|
668 |
+
|
669 |
+
The GNU General Public License does not permit incorporating your program
|
670 |
+
into proprietary programs. If your program is a subroutine library, you
|
671 |
+
may consider it more useful to permit linking proprietary applications with
|
672 |
+
the library. If this is what you want to do, use the GNU Lesser General
|
673 |
+
Public License instead of this License. But first, please read
|
674 |
+
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
vendor/askupa-software/wp-admin-notification/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# wp-admin-notification [![Build Status](https://scrutinizer-ci.com/g/askupasoftware/wp-admin-notification/badges/build.png?b=master)](https://scrutinizer-ci.com/g/askupasoftware/wp-admin-notification/build-status/master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/askupasoftware/wp-admin-notification/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/askupasoftware/wp-admin-notification/?branch=master) [![License](https://img.shields.io/badge/license-GPL--3.0%2B-red.svg)](https://raw.githubusercontent.com/askupasoftware/wp-admin-notification/master/LICENSE)
|
2 |
+
**wp-admin-notification** lets you add static/dismissible notifications to the WordPress administrastion. Dismissible notifictions are permanently dismissed and will not show when the page reloads. For an in-depth tutorial, see [Adding Static/Dismissible Admin Notifications to WordPress](https://blog.askupasoftware.com/adding-staticdismissible-admin-notifications-wordpress/)
|
3 |
+
|
4 |
+
![wp-admin-notification - ](https://askupasoftware.com/wp-content/uploads/2014/01/wp-admin-notifications.gif)
|
5 |
+
|
6 |
+
## Overview
|
7 |
+
**wp-admin-notification** lets you easily add notifications to the WordPress administrastion with different options to chose from. In WordPress 4.2 [dismissible notifications becamse supported](https://make.wordpress.org/core/2015/04/23/spinners-and-dismissible-admin-notices-in-4-2/). However, a dismissed notification becomes visible again when the user refreshes the page or navigates away. **wp-admin-notification** handles that by storing an option in the database once a notification is dismissed.
|
8 |
+
**wp-admin-notification** is lightweight and trace free - it will only initiate if there is at least one registered notification, and will only store a database option if a user dismisses a notification. `wp_reset_admin_notification()` will remove the option from the database if there are no more dismissed notifications.
|
9 |
+
|
10 |
+
## Installation
|
11 |
+
|
12 |
+
### Via Composer
|
13 |
+
|
14 |
+
If you are using the command line:
|
15 |
+
```
|
16 |
+
$ composer require askupa-software/wp-admin-notification:dev-master
|
17 |
+
```
|
18 |
+
|
19 |
+
Or simply add the following to your `composer.json` file:
|
20 |
+
```javascript
|
21 |
+
"require": {
|
22 |
+
"askupa-software/wp-admin-notification": "dev-master"
|
23 |
+
}
|
24 |
+
```
|
25 |
+
And run the command
|
26 |
+
```
|
27 |
+
$ composer install
|
28 |
+
```
|
29 |
+
|
30 |
+
This will install the package in the directory `vendors/askupa-software/wp-admin-notification`.
|
31 |
+
|
32 |
+
### Manually
|
33 |
+
|
34 |
+
[Download the package](https://github.com/askupasoftware/wp-admin-notification/archive/master.zip) from github and include `bootstrap.php` in your project:
|
35 |
+
|
36 |
+
```php
|
37 |
+
require_once 'path/to/wp-admin-notification/bootstrap.php';
|
38 |
+
```
|
39 |
+
|
40 |
+
## Usage
|
41 |
+
|
42 |
+
### wp_admin_notification
|
43 |
+
*Register a notification to be printed in the administration.*
|
44 |
+
```php
|
45 |
+
wp_admin_notification( $handle, $html, $type = 'success', $dismissible = false, $class = '', $network = false )
|
46 |
+
```
|
47 |
+
This function is used to register a notification for a given handle. The handle is used as the notification's ID. If the notification is dismissible, the handle is used to permanently dismiss the notification. When a dismissible notification is dismissed, the `wp_dismissed_notices` option is updated with the handle added to it.
|
48 |
+
|
49 |
+
**Parameters**
|
50 |
+
* `$handle` (*String*) The notification's ID. Also used to permanently dismiss a dismissible notification. If a given handle has previously been registered, a PHP notice will be triggered.
|
51 |
+
* `$html` (*String*) The text/HTML content of the notification.
|
52 |
+
* `$type` (*String*) The notification's type. One of `error`, `notice`, `info`, `success`.
|
53 |
+
* `$dismissible` (*Boolean*) Whether to add a "dismiss" button to allow the user to permanently dismiss the notification.
|
54 |
+
* `$class` (*String*) An additional CSS class to be added to the notification for styling purposes.
|
55 |
+
* `$network` (*Boolean*) Whether to show this notification in the network administration as well. Uses the [network_admin_notices](https://codex.wordpress.org/Plugin_API/Action_Reference/network_admin_notices) hook internally.
|
56 |
+
|
57 |
+
### wp_reset_admin_notification
|
58 |
+
*Reset a dismissible notification.*
|
59 |
+
```php
|
60 |
+
wp_reset_admin_notification( $handle )
|
61 |
+
```
|
62 |
+
This function can be used to make a previously dismissed notification visible again. It does that by removing the given `$handle` from the list of dismissed notifications stored in the option `wp_dismissed_notices`. If the list of dismissed notification is empty, the option will be removed from the database.
|
63 |
+
|
64 |
+
**Parameters**
|
65 |
+
* `$handle` (*String*) The handle of the notification to be reset.
|
vendor/askupa-software/wp-admin-notification/bootstrap.php
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WordPress Admin Notifications
|
4 |
+
*
|
5 |
+
* Add static/dismissible admin notifications to WordPress
|
6 |
+
*
|
7 |
+
* @package wp-admin-notification
|
8 |
+
* @author Askupa Software <hello@askupasoftware.com>
|
9 |
+
* @link https://github.com/askupasoftware/wp-admin-notification
|
10 |
+
* @copyright 2016 Askupa Software
|
11 |
+
*/
|
12 |
+
|
13 |
+
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Prevent loading the library more than once
|
17 |
+
*/
|
18 |
+
if( defined( 'WP_ADMIN_NOTIFICATION' ) ) return;
|
19 |
+
define( 'WP_ADMIN_NOTIFICATION', true );
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Require the handler class
|
23 |
+
*/
|
24 |
+
require_once 'handler.php';
|
25 |
+
|
26 |
+
if(!function_exists('wp_admin_notification'))
|
27 |
+
{
|
28 |
+
/**
|
29 |
+
*
|
30 |
+
* @param type $handle
|
31 |
+
* @param type $html
|
32 |
+
* @param type $type
|
33 |
+
* @param type $dismissible
|
34 |
+
* @param type $class
|
35 |
+
* @param type $network
|
36 |
+
*/
|
37 |
+
function wp_admin_notification( $handle, $html, $type = 'success', $dismissible = false, $class = '', $network = false )
|
38 |
+
{
|
39 |
+
$notifier = WPAdminNotifications::get_instance();
|
40 |
+
$notifier->register_notification($handle, array(
|
41 |
+
'dismissible' => $dismissible,
|
42 |
+
'class' => $class,
|
43 |
+
'type' => $type,
|
44 |
+
'html' => $html,
|
45 |
+
'network' => $network
|
46 |
+
));
|
47 |
+
}
|
48 |
+
}
|
49 |
+
|
50 |
+
if(!function_exists('wp_reset_admin_notification'))
|
51 |
+
{
|
52 |
+
/**
|
53 |
+
*
|
54 |
+
* @param string $handle
|
55 |
+
*/
|
56 |
+
function wp_reset_admin_notification( $handle )
|
57 |
+
{
|
58 |
+
$dismissed = get_option( 'wp_dismissed_notices' );
|
59 |
+
$offset = 0;
|
60 |
+
foreach($dismissed as $id)
|
61 |
+
{
|
62 |
+
if( $id === $handle ) break;
|
63 |
+
$offset++;
|
64 |
+
}
|
65 |
+
array_splice( $dismissed, $offset, 1);
|
66 |
+
update_option( 'wp_dismissed_notices', $dismissed );
|
67 |
+
}
|
68 |
+
}
|
vendor/askupa-software/wp-admin-notification/composer.json
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "askupa-software/wp-admin-notification",
|
3 |
+
"description": "Add static/dismissible admin notifications to WordPress",
|
4 |
+
"type": "wordpress",
|
5 |
+
"keywords": ["wordpress","notices","framework"],
|
6 |
+
"homepage": "https://github.com/askupasoftware/wp-dismissible-notice",
|
7 |
+
"authors": [
|
8 |
+
{
|
9 |
+
"name": "Askupa Software",
|
10 |
+
"email": "hello@askupasoftware.com"
|
11 |
+
}
|
12 |
+
],
|
13 |
+
"require": {
|
14 |
+
"php": ">=5.3.0"
|
15 |
+
}
|
16 |
+
}
|
vendor/askupa-software/wp-admin-notification/handler.php
ADDED
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if(!class_exists('WPAdminNotifications'))
|
4 |
+
{
|
5 |
+
class WPAdminNotifications
|
6 |
+
{
|
7 |
+
/**
|
8 |
+
* @var Singleton The reference to *Singleton* instance of this class
|
9 |
+
*/
|
10 |
+
private static $instance;
|
11 |
+
|
12 |
+
private $notifications = array();
|
13 |
+
|
14 |
+
private $dismissed_notices;
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Returns the *Singleton* instance of this class.
|
18 |
+
*
|
19 |
+
* @return Singleton The *Singleton* instance.
|
20 |
+
*/
|
21 |
+
public static function get_instance()
|
22 |
+
{
|
23 |
+
if( null === static::$instance )
|
24 |
+
{
|
25 |
+
static::$instance = new static();
|
26 |
+
}
|
27 |
+
return static::$instance;
|
28 |
+
}
|
29 |
+
|
30 |
+
public function register_notification( $handle, $options )
|
31 |
+
{
|
32 |
+
if( 0 === count( $this->notifications ) )
|
33 |
+
{
|
34 |
+
$this->init();
|
35 |
+
}
|
36 |
+
|
37 |
+
if( !key_exists( $handle, $this->notifications ) )
|
38 |
+
{
|
39 |
+
$this->notifications[$handle] = $options;
|
40 |
+
}
|
41 |
+
else trigger_error( "The handle <strong>$handle</strong> has already been registered. Please choose a different handle for your notification." );
|
42 |
+
}
|
43 |
+
|
44 |
+
public function render_notifications()
|
45 |
+
{
|
46 |
+
foreach($this->notifications as $handle => $notification)
|
47 |
+
{
|
48 |
+
$this->render_notification( $handle, $notification );
|
49 |
+
}
|
50 |
+
}
|
51 |
+
|
52 |
+
public function render_network_notifications()
|
53 |
+
{
|
54 |
+
foreach( $this->notifications as $handle => $notification )
|
55 |
+
{
|
56 |
+
if( $notification['network'] ) $this->render_notification( $handle, $notification );
|
57 |
+
}
|
58 |
+
}
|
59 |
+
|
60 |
+
public function dismiss_notification()
|
61 |
+
{
|
62 |
+
$id = filter_input( INPUT_POST, 'id' );
|
63 |
+
if( !in_array( $id, $this->dismissed_notices ) )
|
64 |
+
{
|
65 |
+
$this->dismissed_notices[] = $id;
|
66 |
+
update_option( 'wp_dismissed_notices', $this->dismissed_notices);
|
67 |
+
}
|
68 |
+
die();
|
69 |
+
}
|
70 |
+
|
71 |
+
public function render_script()
|
72 |
+
{
|
73 |
+
?>
|
74 |
+
<script>
|
75 |
+
jQuery(document).ready(function($){
|
76 |
+
$('.notice').on('click','.notice-dismiss',function(e){
|
77 |
+
$.post(ajaxurl,{
|
78 |
+
action: 'dismiss_admin_notification',
|
79 |
+
id: $(this).parent().attr('id')
|
80 |
+
});
|
81 |
+
});
|
82 |
+
});
|
83 |
+
</script>
|
84 |
+
<?php
|
85 |
+
}
|
86 |
+
|
87 |
+
private function init()
|
88 |
+
{
|
89 |
+
add_action( 'admin_notices', array( $this, 'render_notifications' ) );
|
90 |
+
add_action( 'network_admin_notices', array( $this, 'render_network_notifications' ) );
|
91 |
+
add_action( 'wp_ajax_dismiss_admin_notification', array( $this, 'dismiss_notification' ) );
|
92 |
+
add_action( 'admin_head', array( $this, 'render_script' ) );
|
93 |
+
$this->dismissed_notices = get_option('wp_dismissed_notices');
|
94 |
+
if( false === $this->dismissed_notices ) $this->dismissed_notices = array();
|
95 |
+
var_dump($this->dismissed_notices);
|
96 |
+
}
|
97 |
+
|
98 |
+
private function render_notification( $id, $n )
|
99 |
+
{
|
100 |
+
if( in_array( $id, $this->dismissed_notices ) ) return;
|
101 |
+
|
102 |
+
printf(
|
103 |
+
'<div id="%s" class="notice notice-%s %s%s"><p>%s</p></div>',
|
104 |
+
$id,
|
105 |
+
$n['type'],
|
106 |
+
$n['dismissible']?'is-dismissible ':'',
|
107 |
+
$n['class'],
|
108 |
+
$n['html']
|
109 |
+
);
|
110 |
+
}
|
111 |
+
}
|
112 |
+
}
|
vendor/autoload.php
CHANGED
@@ -2,6 +2,6 @@
|
|
2 |
|
3 |
// autoload.php @generated by Composer
|
4 |
|
5 |
-
require_once __DIR__ . '/composer
|
6 |
|
7 |
return ComposerAutoloaderInit99fb821a098de3bdad03e3323415706b::getLoader();
|
2 |
|
3 |
// autoload.php @generated by Composer
|
4 |
|
5 |
+
require_once __DIR__ . '/composer/autoload_real.php';
|
6 |
|
7 |
return ComposerAutoloaderInit99fb821a098de3bdad03e3323415706b::getLoader();
|
vendor/composer/ClassLoader.php
CHANGED
@@ -53,8 +53,9 @@ class ClassLoader
|
|
53 |
|
54 |
private $useIncludePath = false;
|
55 |
private $classMap = array();
|
56 |
-
|
57 |
private $classMapAuthoritative = false;
|
|
|
|
|
58 |
|
59 |
public function getPrefixes()
|
60 |
{
|
@@ -271,6 +272,26 @@ class ClassLoader
|
|
271 |
return $this->classMapAuthoritative;
|
272 |
}
|
273 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
/**
|
275 |
* Registers this instance as an autoloader.
|
276 |
*
|
@@ -313,29 +334,34 @@ class ClassLoader
|
|
313 |
*/
|
314 |
public function findFile($class)
|
315 |
{
|
316 |
-
// work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
|
317 |
-
if ('\\' == $class[0]) {
|
318 |
-
$class = substr($class, 1);
|
319 |
-
}
|
320 |
-
|
321 |
// class map lookup
|
322 |
if (isset($this->classMap[$class])) {
|
323 |
return $this->classMap[$class];
|
324 |
}
|
325 |
-
if ($this->classMapAuthoritative) {
|
326 |
return false;
|
327 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
328 |
|
329 |
$file = $this->findFileWithExtension($class, '.php');
|
330 |
|
331 |
// Search for Hack files if we are running on HHVM
|
332 |
-
if (
|
333 |
$file = $this->findFileWithExtension($class, '.hh');
|
334 |
}
|
335 |
|
336 |
-
if (
|
|
|
|
|
|
|
|
|
337 |
// Remember that this class does not exist.
|
338 |
-
|
339 |
}
|
340 |
|
341 |
return $file;
|
@@ -399,6 +425,8 @@ class ClassLoader
|
|
399 |
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
|
400 |
return $file;
|
401 |
}
|
|
|
|
|
402 |
}
|
403 |
}
|
404 |
|
53 |
|
54 |
private $useIncludePath = false;
|
55 |
private $classMap = array();
|
|
|
56 |
private $classMapAuthoritative = false;
|
57 |
+
private $missingClasses = array();
|
58 |
+
private $apcuPrefix;
|
59 |
|
60 |
public function getPrefixes()
|
61 |
{
|
272 |
return $this->classMapAuthoritative;
|
273 |
}
|
274 |
|
275 |
+
/**
|
276 |
+
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
|
277 |
+
*
|
278 |
+
* @param string|null $apcuPrefix
|
279 |
+
*/
|
280 |
+
public function setApcuPrefix($apcuPrefix)
|
281 |
+
{
|
282 |
+
$this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null;
|
283 |
+
}
|
284 |
+
|
285 |
+
/**
|
286 |
+
* The APCu prefix in use, or null if APCu caching is not enabled.
|
287 |
+
*
|
288 |
+
* @return string|null
|
289 |
+
*/
|
290 |
+
public function getApcuPrefix()
|
291 |
+
{
|
292 |
+
return $this->apcuPrefix;
|
293 |
+
}
|
294 |
+
|
295 |
/**
|
296 |
* Registers this instance as an autoloader.
|
297 |
*
|
334 |
*/
|
335 |
public function findFile($class)
|
336 |
{
|
|
|
|
|
|
|
|
|
|
|
337 |
// class map lookup
|
338 |
if (isset($this->classMap[$class])) {
|
339 |
return $this->classMap[$class];
|
340 |
}
|
341 |
+
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
|
342 |
return false;
|
343 |
}
|
344 |
+
if (null !== $this->apcuPrefix) {
|
345 |
+
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
|
346 |
+
if ($hit) {
|
347 |
+
return $file;
|
348 |
+
}
|
349 |
+
}
|
350 |
|
351 |
$file = $this->findFileWithExtension($class, '.php');
|
352 |
|
353 |
// Search for Hack files if we are running on HHVM
|
354 |
+
if (false === $file && defined('HHVM_VERSION')) {
|
355 |
$file = $this->findFileWithExtension($class, '.hh');
|
356 |
}
|
357 |
|
358 |
+
if (null !== $this->apcuPrefix) {
|
359 |
+
apcu_add($this->apcuPrefix.$class, $file);
|
360 |
+
}
|
361 |
+
|
362 |
+
if (false === $file) {
|
363 |
// Remember that this class does not exist.
|
364 |
+
$this->missingClasses[$class] = true;
|
365 |
}
|
366 |
|
367 |
return $file;
|
425 |
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
|
426 |
return $file;
|
427 |
}
|
428 |
+
|
429 |
+
return false;
|
430 |
}
|
431 |
}
|
432 |
|
vendor/composer/LICENSE
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
|
2 |
-
Copyright (c)
|
3 |
|
4 |
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5 |
of this software and associated documentation files (the "Software"), to deal
|
1 |
|
2 |
+
Copyright (c) Nils Adermann, Jordi Boggiano
|
3 |
|
4 |
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5 |
of this software and associated documentation files (the "Software"), to deal
|
vendor/composer/autoload_real.php
CHANGED
@@ -23,7 +23,7 @@ class ComposerAutoloaderInit99fb821a098de3bdad03e3323415706b
|
|
23 |
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
24 |
spl_autoload_unregister(array('ComposerAutoloaderInit99fb821a098de3bdad03e3323415706b', 'loadClassLoader'));
|
25 |
|
26 |
-
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION');
|
27 |
if ($useStaticLoader) {
|
28 |
require_once __DIR__ . '/autoload_static.php';
|
29 |
|
23 |
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
24 |
spl_autoload_unregister(array('ComposerAutoloaderInit99fb821a098de3bdad03e3323415706b', 'loadClassLoader'));
|
25 |
|
26 |
+
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
27 |
if ($useStaticLoader) {
|
28 |
require_once __DIR__ . '/autoload_static.php';
|
29 |
|
vendor/composer/installed.json
CHANGED
@@ -17,7 +17,7 @@
|
|
17 |
"require": {
|
18 |
"php": ">=5.3.0"
|
19 |
},
|
20 |
-
"time": "2017-01-
|
21 |
"type": "library",
|
22 |
"installation-source": "source",
|
23 |
"autoload": {
|
@@ -35,5 +35,83 @@
|
|
35 |
}
|
36 |
],
|
37 |
"description": "Data Sanitization and Validation With WordPress"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
}
|
39 |
]
|
17 |
"require": {
|
18 |
"php": ">=5.3.0"
|
19 |
},
|
20 |
+
"time": "2017-01-25T08:42:12+00:00",
|
21 |
"type": "library",
|
22 |
"installation-source": "source",
|
23 |
"autoload": {
|
35 |
}
|
36 |
],
|
37 |
"description": "Data Sanitization and Validation With WordPress"
|
38 |
+
},
|
39 |
+
{
|
40 |
+
"name": "yahnis-elsts/plugin-update-checker",
|
41 |
+
"version": "v4.0.3",
|
42 |
+
"version_normalized": "4.0.3.0",
|
43 |
+
"source": {
|
44 |
+
"type": "git",
|
45 |
+
"url": "https://github.com/YahnisElsts/plugin-update-checker.git",
|
46 |
+
"reference": "e4854cdb388153ce238044518c67888976d4a4ec"
|
47 |
+
},
|
48 |
+
"dist": {
|
49 |
+
"type": "zip",
|
50 |
+
"url": "https://api.github.com/repos/YahnisElsts/plugin-update-checker/zipball/e4854cdb388153ce238044518c67888976d4a4ec",
|
51 |
+
"reference": "e4854cdb388153ce238044518c67888976d4a4ec",
|
52 |
+
"shasum": ""
|
53 |
+
},
|
54 |
+
"require": {
|
55 |
+
"php": ">=5.2.0"
|
56 |
+
},
|
57 |
+
"time": "2017-01-24T10:18:34+00:00",
|
58 |
+
"type": "library",
|
59 |
+
"installation-source": "dist",
|
60 |
+
"notification-url": "https://packagist.org/downloads/",
|
61 |
+
"license": [
|
62 |
+
"MIT"
|
63 |
+
],
|
64 |
+
"authors": [
|
65 |
+
{
|
66 |
+
"name": "Yahnis Elsts",
|
67 |
+
"email": "whiteshadow@w-shadow.com",
|
68 |
+
"homepage": "http://w-shadow.com/",
|
69 |
+
"role": "Developer"
|
70 |
+
}
|
71 |
+
],
|
72 |
+
"description": "A custom update checker for WordPress plugins and themes. Useful if you can't host your plugin in the official WP repository but still want it to support automatic updates.",
|
73 |
+
"homepage": "https://github.com/YahnisElsts/plugin-update-checker/",
|
74 |
+
"keywords": [
|
75 |
+
"automatic updates",
|
76 |
+
"plugin updates",
|
77 |
+
"theme updates",
|
78 |
+
"wordpress"
|
79 |
+
]
|
80 |
+
},
|
81 |
+
{
|
82 |
+
"name": "askupa-software/wp-admin-notification",
|
83 |
+
"version": "dev-master",
|
84 |
+
"version_normalized": "9999999-dev",
|
85 |
+
"source": {
|
86 |
+
"type": "git",
|
87 |
+
"url": "https://github.com/askupasoftware/wp-admin-notification.git",
|
88 |
+
"reference": "90bc92aeb60ab3ffc3d581fafa16fb82a9b02f4a"
|
89 |
+
},
|
90 |
+
"dist": {
|
91 |
+
"type": "zip",
|
92 |
+
"url": "https://api.github.com/repos/askupasoftware/wp-admin-notification/zipball/90bc92aeb60ab3ffc3d581fafa16fb82a9b02f4a",
|
93 |
+
"reference": "90bc92aeb60ab3ffc3d581fafa16fb82a9b02f4a",
|
94 |
+
"shasum": ""
|
95 |
+
},
|
96 |
+
"require": {
|
97 |
+
"php": ">=5.3.0"
|
98 |
+
},
|
99 |
+
"time": "2017-03-20T21:01:42+00:00",
|
100 |
+
"type": "wordpress",
|
101 |
+
"installation-source": "source",
|
102 |
+
"notification-url": "https://packagist.org/downloads/",
|
103 |
+
"authors": [
|
104 |
+
{
|
105 |
+
"name": "Askupa Software",
|
106 |
+
"email": "hello@askupasoftware.com"
|
107 |
+
}
|
108 |
+
],
|
109 |
+
"description": "Add static/dismissible admin notifications to WordPress",
|
110 |
+
"homepage": "https://github.com/askupasoftware/wp-dismissible-notice",
|
111 |
+
"keywords": [
|
112 |
+
"framework",
|
113 |
+
"notices",
|
114 |
+
"wordpress"
|
115 |
+
]
|
116 |
}
|
117 |
]
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Autoloader.php
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if ( !class_exists('Puc_v4_Autoloader', false) ):
|
4 |
+
|
5 |
+
class Puc_v4_Autoloader {
|
6 |
+
private $prefix = '';
|
7 |
+
private $rootDir = '';
|
8 |
+
private $libraryDir = '';
|
9 |
+
|
10 |
+
private $staticMap;
|
11 |
+
|
12 |
+
public function __construct() {
|
13 |
+
$this->rootDir = dirname(__FILE__) . '/';
|
14 |
+
$nameParts = explode('_', __CLASS__, 3);
|
15 |
+
$this->prefix = $nameParts[0] . '_' . $nameParts[1] . '_';
|
16 |
+
|
17 |
+
$this->libraryDir = realpath($this->rootDir . '../..') . '/';
|
18 |
+
$this->staticMap = array(
|
19 |
+
'PucReadmeParser' => 'vendor/readme-parser.php',
|
20 |
+
'Parsedown' => 'vendor/ParsedownLegacy.php',
|
21 |
+
);
|
22 |
+
if ( version_compare(PHP_VERSION, '5.3.0', '>=') ) {
|
23 |
+
$this->staticMap['Parsedown'] = 'vendor/Parsedown.php';
|
24 |
+
}
|
25 |
+
|
26 |
+
spl_autoload_register(array($this, 'autoload'));
|
27 |
+
}
|
28 |
+
|
29 |
+
public function autoload($className) {
|
30 |
+
if ( isset($this->staticMap[$className]) && file_exists($this->libraryDir . $this->staticMap[$className]) ) {
|
31 |
+
/** @noinspection PhpIncludeInspection */
|
32 |
+
include ($this->libraryDir . $this->staticMap[$className]);
|
33 |
+
return;
|
34 |
+
}
|
35 |
+
|
36 |
+
if (strpos($className, $this->prefix) === 0) {
|
37 |
+
$path = substr($className, strlen($this->prefix));
|
38 |
+
$path = str_replace('_', '/', $path);
|
39 |
+
$path = $this->rootDir . $path . '.php';
|
40 |
+
|
41 |
+
if (file_exists($path)) {
|
42 |
+
/** @noinspection PhpIncludeInspection */
|
43 |
+
include $path;
|
44 |
+
}
|
45 |
+
}
|
46 |
+
}
|
47 |
+
}
|
48 |
+
|
49 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/DebugBar/Extension.php
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( !class_exists('Puc_v4_DebugBar_Extension', false) ):
|
3 |
+
|
4 |
+
class Puc_v4_DebugBar_Extension {
|
5 |
+
/** @var Puc_v4_UpdateChecker */
|
6 |
+
protected $updateChecker;
|
7 |
+
protected $panelClass = 'Puc_v4_DebugBar_Panel';
|
8 |
+
|
9 |
+
public function __construct($updateChecker, $panelClass = null) {
|
10 |
+
$this->updateChecker = $updateChecker;
|
11 |
+
if ( isset($panelClass) ) {
|
12 |
+
$this->panelClass = $panelClass;
|
13 |
+
}
|
14 |
+
|
15 |
+
add_filter('debug_bar_panels', array($this, 'addDebugBarPanel'));
|
16 |
+
add_action('debug_bar_enqueue_scripts', array($this, 'enqueuePanelDependencies'));
|
17 |
+
|
18 |
+
add_action('wp_ajax_puc_v4_debug_check_now', array($this, 'ajaxCheckNow'));
|
19 |
+
}
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Register the PUC Debug Bar panel.
|
23 |
+
*
|
24 |
+
* @param array $panels
|
25 |
+
* @return array
|
26 |
+
*/
|
27 |
+
public function addDebugBarPanel($panels) {
|
28 |
+
if ( $this->updateChecker->userCanInstallUpdates() ) {
|
29 |
+
$panels[] = new $this->panelClass($this->updateChecker);
|
30 |
+
}
|
31 |
+
return $panels;
|
32 |
+
}
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Enqueue our Debug Bar scripts and styles.
|
36 |
+
*/
|
37 |
+
public function enqueuePanelDependencies() {
|
38 |
+
wp_enqueue_style(
|
39 |
+
'puc-debug-bar-style-v4',
|
40 |
+
$this->getLibraryUrl("/css/puc-debug-bar.css"),
|
41 |
+
array('debug-bar'),
|
42 |
+
'20161217'
|
43 |
+
);
|
44 |
+
|
45 |
+
wp_enqueue_script(
|
46 |
+
'puc-debug-bar-js-v4',
|
47 |
+
$this->getLibraryUrl("/js/debug-bar.js"),
|
48 |
+
array('jquery'),
|
49 |
+
'20161219'
|
50 |
+
);
|
51 |
+
}
|
52 |
+
|
53 |
+
/**
|
54 |
+
* Run an update check and output the result. Useful for making sure that
|
55 |
+
* the update checking process works as expected.
|
56 |
+
*/
|
57 |
+
public function ajaxCheckNow() {
|
58 |
+
if ( $_POST['uid'] !== $this->updateChecker->getUniqueName('uid') ) {
|
59 |
+
return;
|
60 |
+
}
|
61 |
+
$this->preAjaxReqest();
|
62 |
+
$update = $this->updateChecker->checkForUpdates();
|
63 |
+
if ( $update !== null ) {
|
64 |
+
echo "An update is available:";
|
65 |
+
echo '<pre>', htmlentities(print_r($update, true)), '</pre>';
|
66 |
+
} else {
|
67 |
+
echo 'No updates found.';
|
68 |
+
}
|
69 |
+
exit;
|
70 |
+
}
|
71 |
+
|
72 |
+
/**
|
73 |
+
* Check access permissions and enable error display (for debugging).
|
74 |
+
*/
|
75 |
+
protected function preAjaxReqest() {
|
76 |
+
if ( !$this->updateChecker->userCanInstallUpdates() ) {
|
77 |
+
die('Access denied');
|
78 |
+
}
|
79 |
+
check_ajax_referer('puc-ajax');
|
80 |
+
|
81 |
+
error_reporting(E_ALL);
|
82 |
+
@ini_set('display_errors','On');
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* @param string $filePath
|
87 |
+
* @return string
|
88 |
+
*/
|
89 |
+
private function getLibraryUrl($filePath) {
|
90 |
+
$absolutePath = realpath(dirname(__FILE__) . '/../../../' . ltrim($filePath, '/'));
|
91 |
+
|
92 |
+
//Where is the library located inside the WordPress directory structure?
|
93 |
+
$absolutePath = wp_normalize_path($absolutePath);
|
94 |
+
|
95 |
+
$pluginDir = wp_normalize_path(WP_PLUGIN_DIR);
|
96 |
+
$muPluginDir = wp_normalize_path(WPMU_PLUGIN_DIR);
|
97 |
+
$themeDir = wp_normalize_path(get_theme_root());
|
98 |
+
|
99 |
+
if ( (strpos($absolutePath, $pluginDir) === 0) || (strpos($absolutePath, $muPluginDir) === 0) ) {
|
100 |
+
//It's part of a plugin.
|
101 |
+
return plugins_url(basename($absolutePath), $absolutePath);
|
102 |
+
} else if ( strpos($absolutePath, $themeDir) === 0 ) {
|
103 |
+
//It's part of a theme.
|
104 |
+
$relativePath = substr($absolutePath, strlen($themeDir) + 1);
|
105 |
+
$template = substr($relativePath, 0, strpos($relativePath, '/'));
|
106 |
+
$baseUrl = get_theme_root_uri($template);
|
107 |
+
|
108 |
+
if ( !empty($baseUrl) && $relativePath ) {
|
109 |
+
return $baseUrl . '/' . $relativePath;
|
110 |
+
}
|
111 |
+
}
|
112 |
+
|
113 |
+
return '';
|
114 |
+
}
|
115 |
+
}
|
116 |
+
|
117 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/DebugBar/Panel.php
ADDED
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if ( !class_exists('Puc_v4_DebugBar_Panel', false) && class_exists('Debug_Bar_Panel', false) ):
|
4 |
+
|
5 |
+
class Puc_v4_DebugBar_Panel extends Debug_Bar_Panel {
|
6 |
+
/** @var Puc_v4_UpdateChecker */
|
7 |
+
protected $updateChecker;
|
8 |
+
|
9 |
+
private $responseBox = '<div class="puc-ajax-response" style="display: none;"></div>';
|
10 |
+
|
11 |
+
public function __construct($updateChecker) {
|
12 |
+
$this->updateChecker = $updateChecker;
|
13 |
+
$title = sprintf(
|
14 |
+
'<span id="puc-debug-menu-link-%s">PUC (%s)</span>',
|
15 |
+
esc_attr($this->updateChecker->getUniqueName('uid')),
|
16 |
+
$this->updateChecker->slug
|
17 |
+
);
|
18 |
+
parent::__construct($title);
|
19 |
+
}
|
20 |
+
|
21 |
+
public function render() {
|
22 |
+
printf(
|
23 |
+
'<div class="puc-debug-bar-panel-v4" id="%1$s" data-slug="%2$s" data-uid="%3$s" data-nonce="%4$s">',
|
24 |
+
esc_attr($this->updateChecker->getUniqueName('debug-bar-panel')),
|
25 |
+
esc_attr($this->updateChecker->slug),
|
26 |
+
esc_attr($this->updateChecker->getUniqueName('uid')),
|
27 |
+
esc_attr(wp_create_nonce('puc-ajax'))
|
28 |
+
);
|
29 |
+
|
30 |
+
$this->displayConfiguration();
|
31 |
+
$this->displayStatus();
|
32 |
+
$this->displayCurrentUpdate();
|
33 |
+
|
34 |
+
echo '</div>';
|
35 |
+
}
|
36 |
+
|
37 |
+
private function displayConfiguration() {
|
38 |
+
echo '<h3>Configuration</h3>';
|
39 |
+
echo '<table class="puc-debug-data">';
|
40 |
+
$this->displayConfigHeader();
|
41 |
+
$this->row('Slug', htmlentities($this->updateChecker->slug));
|
42 |
+
$this->row('DB option', htmlentities($this->updateChecker->optionName));
|
43 |
+
|
44 |
+
$requestInfoButton = $this->getMetadataButton();
|
45 |
+
$this->row('Metadata URL', htmlentities($this->updateChecker->metadataUrl) . ' ' . $requestInfoButton . $this->responseBox);
|
46 |
+
|
47 |
+
$scheduler = $this->updateChecker->scheduler;
|
48 |
+
if ( $scheduler->checkPeriod > 0 ) {
|
49 |
+
$this->row('Automatic checks', 'Every ' . $scheduler->checkPeriod . ' hours');
|
50 |
+
} else {
|
51 |
+
$this->row('Automatic checks', 'Disabled');
|
52 |
+
}
|
53 |
+
|
54 |
+
if ( isset($scheduler->throttleRedundantChecks) ) {
|
55 |
+
if ( $scheduler->throttleRedundantChecks && ($scheduler->checkPeriod > 0) ) {
|
56 |
+
$this->row(
|
57 |
+
'Throttling',
|
58 |
+
sprintf(
|
59 |
+
'Enabled. If an update is already available, check for updates every %1$d hours instead of every %2$d hours.',
|
60 |
+
$scheduler->throttledCheckPeriod,
|
61 |
+
$scheduler->checkPeriod
|
62 |
+
)
|
63 |
+
);
|
64 |
+
} else {
|
65 |
+
$this->row('Throttling', 'Disabled');
|
66 |
+
}
|
67 |
+
}
|
68 |
+
|
69 |
+
$this->updateChecker->onDisplayConfiguration($this);
|
70 |
+
|
71 |
+
echo '</table>';
|
72 |
+
}
|
73 |
+
|
74 |
+
protected function displayConfigHeader() {
|
75 |
+
//Do nothing. This should be implemented in subclasses.
|
76 |
+
}
|
77 |
+
|
78 |
+
protected function getMetadataButton() {
|
79 |
+
return '';
|
80 |
+
}
|
81 |
+
|
82 |
+
private function displayStatus() {
|
83 |
+
echo '<h3>Status</h3>';
|
84 |
+
echo '<table class="puc-debug-data">';
|
85 |
+
$state = $this->updateChecker->getUpdateState();
|
86 |
+
$checkNowButton = '';
|
87 |
+
if ( function_exists('get_submit_button') ) {
|
88 |
+
$checkNowButton = get_submit_button(
|
89 |
+
'Check Now',
|
90 |
+
'secondary',
|
91 |
+
'puc-check-now-button',
|
92 |
+
false,
|
93 |
+
array('id' => $this->updateChecker->getUniqueName('check-now-button'))
|
94 |
+
);
|
95 |
+
}
|
96 |
+
|
97 |
+
if ( $state->getLastCheck() > 0 ) {
|
98 |
+
$this->row('Last check', $this->formatTimeWithDelta($state->getLastCheck()) . ' ' . $checkNowButton . $this->responseBox);
|
99 |
+
} else {
|
100 |
+
$this->row('Last check', 'Never');
|
101 |
+
}
|
102 |
+
|
103 |
+
$nextCheck = wp_next_scheduled($this->updateChecker->scheduler->getCronHookName());
|
104 |
+
$this->row('Next automatic check', $this->formatTimeWithDelta($nextCheck));
|
105 |
+
|
106 |
+
if ( $state->getCheckedVersion() !== '' ) {
|
107 |
+
$this->row('Checked version', htmlentities($state->getCheckedVersion()));
|
108 |
+
$this->row('Cached update', $state->getUpdate());
|
109 |
+
}
|
110 |
+
$this->row('Update checker class', htmlentities(get_class($this->updateChecker)));
|
111 |
+
echo '</table>';
|
112 |
+
}
|
113 |
+
|
114 |
+
private function displayCurrentUpdate() {
|
115 |
+
$update = $this->updateChecker->getUpdate();
|
116 |
+
if ( $update !== null ) {
|
117 |
+
echo '<h3>An Update Is Available</h3>';
|
118 |
+
echo '<table class="puc-debug-data">';
|
119 |
+
$fields = $this->getUpdateFields();
|
120 |
+
foreach($fields as $field) {
|
121 |
+
if ( property_exists($update, $field) ) {
|
122 |
+
$this->row(ucwords(str_replace('_', ' ', $field)), htmlentities($update->$field));
|
123 |
+
}
|
124 |
+
}
|
125 |
+
echo '</table>';
|
126 |
+
} else {
|
127 |
+
echo '<h3>No updates currently available</h3>';
|
128 |
+
}
|
129 |
+
}
|
130 |
+
|
131 |
+
protected function getUpdateFields() {
|
132 |
+
return array('version', 'download_url', 'slug',);
|
133 |
+
}
|
134 |
+
|
135 |
+
private function formatTimeWithDelta($unixTime) {
|
136 |
+
if ( empty($unixTime) ) {
|
137 |
+
return 'Never';
|
138 |
+
}
|
139 |
+
|
140 |
+
$delta = time() - $unixTime;
|
141 |
+
$result = human_time_diff(time(), $unixTime);
|
142 |
+
if ( $delta < 0 ) {
|
143 |
+
$result = 'after ' . $result;
|
144 |
+
} else {
|
145 |
+
$result = $result . ' ago';
|
146 |
+
}
|
147 |
+
$result .= ' (' . $this->formatTimestamp($unixTime) . ')';
|
148 |
+
return $result;
|
149 |
+
}
|
150 |
+
|
151 |
+
private function formatTimestamp($unixTime) {
|
152 |
+
return gmdate('Y-m-d H:i:s', $unixTime + (get_option('gmt_offset') * 3600));
|
153 |
+
}
|
154 |
+
|
155 |
+
public function row($name, $value) {
|
156 |
+
if ( is_object($value) || is_array($value) ) {
|
157 |
+
$value = '<pre>' . htmlentities(print_r($value, true)) . '</pre>';
|
158 |
+
} else if ($value === null) {
|
159 |
+
$value = '<code>null</code>';
|
160 |
+
}
|
161 |
+
printf('<tr><th scope="row">%1$s</th> <td>%2$s</td></tr>', $name, $value);
|
162 |
+
}
|
163 |
+
}
|
164 |
+
|
165 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/DebugBar/PluginExtension.php
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( !class_exists('Puc_v4_DebugBar_PluginExtension', false) ):
|
3 |
+
|
4 |
+
class Puc_v4_DebugBar_PluginExtension extends Puc_v4_DebugBar_Extension {
|
5 |
+
/** @var Puc_v4_Plugin_UpdateChecker */
|
6 |
+
protected $updateChecker;
|
7 |
+
|
8 |
+
public function __construct($updateChecker) {
|
9 |
+
parent::__construct($updateChecker, 'Puc_v4_DebugBar_PluginPanel');
|
10 |
+
|
11 |
+
add_action('wp_ajax_puc_v4_debug_request_info', array($this, 'ajaxRequestInfo'));
|
12 |
+
}
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Request plugin info and output it.
|
16 |
+
*/
|
17 |
+
public function ajaxRequestInfo() {
|
18 |
+
if ( $_POST['uid'] !== $this->updateChecker->getUniqueName('uid') ) {
|
19 |
+
return;
|
20 |
+
}
|
21 |
+
$this->preAjaxReqest();
|
22 |
+
$info = $this->updateChecker->requestInfo();
|
23 |
+
if ( $info !== null ) {
|
24 |
+
echo 'Successfully retrieved plugin info from the metadata URL:';
|
25 |
+
echo '<pre>', htmlentities(print_r($info, true)), '</pre>';
|
26 |
+
} else {
|
27 |
+
echo 'Failed to retrieve plugin info from the metadata URL.';
|
28 |
+
}
|
29 |
+
exit;
|
30 |
+
}
|
31 |
+
}
|
32 |
+
|
33 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/DebugBar/PluginPanel.php
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if ( !class_exists('Puc_v4_DebugBar_PluginPanel', false) ):
|
4 |
+
|
5 |
+
class Puc_v4_DebugBar_PluginPanel extends Puc_v4_DebugBar_Panel {
|
6 |
+
/**
|
7 |
+
* @var Puc_v4_Plugin_UpdateChecker
|
8 |
+
*/
|
9 |
+
protected $updateChecker;
|
10 |
+
|
11 |
+
protected function displayConfigHeader() {
|
12 |
+
$this->row('Plugin file', htmlentities($this->updateChecker->pluginFile));
|
13 |
+
parent::displayConfigHeader();
|
14 |
+
}
|
15 |
+
|
16 |
+
protected function getMetadataButton() {
|
17 |
+
$requestInfoButton = '';
|
18 |
+
if ( function_exists('get_submit_button') ) {
|
19 |
+
$requestInfoButton = get_submit_button(
|
20 |
+
'Request Info',
|
21 |
+
'secondary',
|
22 |
+
'puc-request-info-button',
|
23 |
+
false,
|
24 |
+
array('id' => $this->updateChecker->getUniqueName('request-info-button'))
|
25 |
+
);
|
26 |
+
}
|
27 |
+
return $requestInfoButton;
|
28 |
+
}
|
29 |
+
|
30 |
+
protected function getUpdateFields() {
|
31 |
+
return array_merge(
|
32 |
+
parent::getUpdateFields(),
|
33 |
+
array('homepage', 'upgrade_notice', 'tested',)
|
34 |
+
);
|
35 |
+
}
|
36 |
+
}
|
37 |
+
|
38 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/DebugBar/ThemePanel.php
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if ( !class_exists('Puc_v4_DebugBar_ThemePanel', false) ):
|
4 |
+
|
5 |
+
class Puc_v4_DebugBar_ThemePanel extends Puc_v4_DebugBar_Panel {
|
6 |
+
/**
|
7 |
+
* @var Puc_v4_Theme_UpdateChecker
|
8 |
+
*/
|
9 |
+
protected $updateChecker;
|
10 |
+
|
11 |
+
protected function displayConfigHeader() {
|
12 |
+
$this->row('Theme directory', htmlentities($this->updateChecker->directoryName));
|
13 |
+
parent::displayConfigHeader();
|
14 |
+
}
|
15 |
+
|
16 |
+
protected function getUpdateFields() {
|
17 |
+
return array_merge(parent::getUpdateFields(), array('details_url'));
|
18 |
+
}
|
19 |
+
}
|
20 |
+
|
21 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Factory.php
ADDED
@@ -0,0 +1,265 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( !class_exists('Puc_v4_Factory', false) ):
|
3 |
+
|
4 |
+
/**
|
5 |
+
* A factory that builds update checker instances.
|
6 |
+
*
|
7 |
+
* When multiple versions of the same class have been loaded (e.g. PluginUpdateChecker 4.0
|
8 |
+
* and 4.1), this factory will always use the latest available minor version. Register class
|
9 |
+
* versions by calling {@link PucFactory::addVersion()}.
|
10 |
+
*
|
11 |
+
* At the moment it can only build instances of the UpdateChecker class. Other classes are
|
12 |
+
* intended mainly for internal use and refer directly to specific implementations.
|
13 |
+
*/
|
14 |
+
class Puc_v4_Factory {
|
15 |
+
protected static $classVersions = array();
|
16 |
+
protected static $sorted = false;
|
17 |
+
|
18 |
+
protected static $myMajorVersion = '';
|
19 |
+
protected static $latestCompatibleVersion = '';
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Create a new instance of the update checker.
|
23 |
+
*
|
24 |
+
* This method automatically detects if you're using it for a plugin or a theme and chooses
|
25 |
+
* the appropriate implementation for your update source (JSON file, GitHub, BitBucket, etc).
|
26 |
+
*
|
27 |
+
* @see Puc_v4_UpdateChecker::__construct
|
28 |
+
*
|
29 |
+
* @param string $metadataUrl The URL of the metadata file, a GitHub repository, or another supported update source.
|
30 |
+
* @param string $fullPath Full path to the main plugin file or to the theme directory.
|
31 |
+
* @param string $slug Custom slug. Defaults to the name of the main plugin file or the theme directory.
|
32 |
+
* @param int $checkPeriod How often to check for updates (in hours).
|
33 |
+
* @param string $optionName Where to store book-keeping info about update checks.
|
34 |
+
* @param string $muPluginFile The plugin filename relative to the mu-plugins directory.
|
35 |
+
* @return Puc_v4_Plugin_UpdateChecker|Puc_v4_Theme_UpdateChecker|Puc_v4_Vcs_BaseChecker
|
36 |
+
*/
|
37 |
+
public static function buildUpdateChecker($metadataUrl, $fullPath, $slug = '', $checkPeriod = 12, $optionName = '', $muPluginFile = '') {
|
38 |
+
$fullPath = wp_normalize_path($fullPath);
|
39 |
+
$id = null;
|
40 |
+
|
41 |
+
//Plugin or theme?
|
42 |
+
$themeDirectory = self::getThemeDirectoryName($fullPath);
|
43 |
+
if ( $themeDirectory !== null ) {
|
44 |
+
$type = 'Theme';
|
45 |
+
$id = $themeDirectory;
|
46 |
+
} else if ( self::isPluginFile($fullPath) ) {
|
47 |
+
$type = 'Plugin';
|
48 |
+
$id = $fullPath;
|
49 |
+
} else {
|
50 |
+
throw new RuntimeException(sprintf(
|
51 |
+
'The update checker cannot determine if "%s" is a plugin or a theme. ' .
|
52 |
+
'This is a bug. Please contact the PUC developer.',
|
53 |
+
htmlentities($fullPath)
|
54 |
+
));
|
55 |
+
}
|
56 |
+
|
57 |
+
//Which hosting service does the URL point to?
|
58 |
+
$service = self::getVcsService($metadataUrl);
|
59 |
+
|
60 |
+
$apiClass = null;
|
61 |
+
if ( empty($service) ) {
|
62 |
+
//The default is to get update information from a remote JSON file.
|
63 |
+
$checkerClass = $type . '_UpdateChecker';
|
64 |
+
} else {
|
65 |
+
//You can also use a VCS repository like GitHub.
|
66 |
+
$checkerClass = 'Vcs_' . $type . 'UpdateChecker';
|
67 |
+
$apiClass = $service . 'Api';
|
68 |
+
}
|
69 |
+
|
70 |
+
$checkerClass = self::getCompatibleClassVersion($checkerClass);
|
71 |
+
if ( $checkerClass === null ) {
|
72 |
+
trigger_error(
|
73 |
+
sprintf(
|
74 |
+
'PUC %s does not support updates for %ss %s',
|
75 |
+
htmlentities(self::$latestCompatibleVersion),
|
76 |
+
strtolower($type),
|
77 |
+
$service ? ('hosted on ' . htmlentities($service)) : 'using JSON metadata'
|
78 |
+
),
|
79 |
+
E_USER_ERROR
|
80 |
+
);
|
81 |
+
return null;
|
82 |
+
}
|
83 |
+
|
84 |
+
if ( !isset($apiClass) ) {
|
85 |
+
//Plain old update checker.
|
86 |
+
return new $checkerClass($metadataUrl, $id, $slug, $checkPeriod, $optionName, $muPluginFile);
|
87 |
+
} else {
|
88 |
+
//VCS checker + an API client.
|
89 |
+
$apiClass = self::getCompatibleClassVersion($apiClass);
|
90 |
+
if ( $apiClass === null ) {
|
91 |
+
trigger_error(sprintf(
|
92 |
+
'PUC %s does not support %s',
|
93 |
+
htmlentities(self::$latestCompatibleVersion),
|
94 |
+
htmlentities($service)
|
95 |
+
), E_USER_ERROR);
|
96 |
+
return null;
|
97 |
+
}
|
98 |
+
|
99 |
+
return new $checkerClass(
|
100 |
+
new $apiClass($metadataUrl),
|
101 |
+
$id,
|
102 |
+
$slug,
|
103 |
+
$checkPeriod,
|
104 |
+
$optionName,
|
105 |
+
$muPluginFile
|
106 |
+
);
|
107 |
+
}
|
108 |
+
}
|
109 |
+
|
110 |
+
/**
|
111 |
+
* Check if the path points to a plugin file.
|
112 |
+
*
|
113 |
+
* @param string $absolutePath Normalized path.
|
114 |
+
* @return bool
|
115 |
+
*/
|
116 |
+
protected static function isPluginFile($absolutePath) {
|
117 |
+
//Is the file inside the "plugins" or "mu-plugins" directory?
|
118 |
+
$pluginDir = wp_normalize_path(WP_PLUGIN_DIR);
|
119 |
+
$muPluginDir = wp_normalize_path(WPMU_PLUGIN_DIR);
|
120 |
+
if ( (strpos($absolutePath, $pluginDir) === 0) || (strpos($absolutePath, $muPluginDir) === 0) ) {
|
121 |
+
return true;
|
122 |
+
}
|
123 |
+
|
124 |
+
//Does it have a valid plugin header?
|
125 |
+
//This is a last-ditch check for plugins symlinked from outside the WP root.
|
126 |
+
if ( function_exists('get_file_data') ) {
|
127 |
+
$headers = get_file_data($absolutePath, array('Name' => 'Plugin Name'), 'plugin');
|
128 |
+
return !empty($headers['Name']);
|
129 |
+
}
|
130 |
+
|
131 |
+
return false;
|
132 |
+
}
|
133 |
+
|
134 |
+
/**
|
135 |
+
* Get the name of the theme's directory from a full path to any theme file.
|
136 |
+
* E.g. "/abc/public_html/wp-content/themes/foo/whatever.php" => "foo".
|
137 |
+
*
|
138 |
+
* @param string $absolutePath Normalized path.
|
139 |
+
* @return string|null Directory name, or NULL if the path doesn't point to a theme.
|
140 |
+
*/
|
141 |
+
protected static function getThemeDirectoryName($absolutePath) {
|
142 |
+
$themeRoot = wp_normalize_path(get_theme_root());
|
143 |
+
if ( strpos($absolutePath, $themeRoot) !== 0 ) {
|
144 |
+
return null;
|
145 |
+
}
|
146 |
+
|
147 |
+
$pathComponents = explode('/', substr($absolutePath, strlen($themeRoot) + 1));
|
148 |
+
if ( !is_array($pathComponents) || !isset($pathComponents[0]) ) {
|
149 |
+
return null;
|
150 |
+
}
|
151 |
+
return $pathComponents[0];
|
152 |
+
}
|
153 |
+
|
154 |
+
/**
|
155 |
+
* Get the name of the hosting service that the URL points to.
|
156 |
+
*
|
157 |
+
* @param string $metadataUrl
|
158 |
+
* @return string|null
|
159 |
+
*/
|
160 |
+
private static function getVcsService($metadataUrl) {
|
161 |
+
$service = null;
|
162 |
+
|
163 |
+
//Which hosting service does the URL point to?
|
164 |
+
$host = @parse_url($metadataUrl, PHP_URL_HOST);
|
165 |
+
$path = @parse_url($metadataUrl, PHP_URL_PATH);
|
166 |
+
//Check if the path looks like "/user-name/repository".
|
167 |
+
$usernameRepoRegex = '@^/?([^/]+?)/([^/#?&]+?)/?$@';
|
168 |
+
if ( preg_match($usernameRepoRegex, $path) ) {
|
169 |
+
$knownServices = array(
|
170 |
+
'github.com' => 'GitHub',
|
171 |
+
'bitbucket.org' => 'BitBucket',
|
172 |
+
'gitlab.com' => 'GitLab',
|
173 |
+
);
|
174 |
+
if ( isset($knownServices[$host]) ) {
|
175 |
+
$service = $knownServices[$host];
|
176 |
+
}
|
177 |
+
}
|
178 |
+
|
179 |
+
return $service;
|
180 |
+
}
|
181 |
+
|
182 |
+
/**
|
183 |
+
* Get the latest version of the specified class that has the same major version number
|
184 |
+
* as this factory class.
|
185 |
+
*
|
186 |
+
* @param string $class Partial class name.
|
187 |
+
* @return string|null Full class name.
|
188 |
+
*/
|
189 |
+
protected static function getCompatibleClassVersion($class) {
|
190 |
+
if ( isset(self::$classVersions[$class][self::$latestCompatibleVersion]) ) {
|
191 |
+
return self::$classVersions[$class][self::$latestCompatibleVersion];
|
192 |
+
}
|
193 |
+
return null;
|
194 |
+
}
|
195 |
+
|
196 |
+
/**
|
197 |
+
* Get the specific class name for the latest available version of a class.
|
198 |
+
*
|
199 |
+
* @param string $class
|
200 |
+
* @return null|string
|
201 |
+
*/
|
202 |
+
public static function getLatestClassVersion($class) {
|
203 |
+
if ( !self::$sorted ) {
|
204 |
+
self::sortVersions();
|
205 |
+
}
|
206 |
+
|
207 |
+
if ( isset(self::$classVersions[$class]) ) {
|
208 |
+
return reset(self::$classVersions[$class]);
|
209 |
+
} else {
|
210 |
+
return null;
|
211 |
+
}
|
212 |
+
}
|
213 |
+
|
214 |
+
/**
|
215 |
+
* Sort available class versions in descending order (i.e. newest first).
|
216 |
+
*/
|
217 |
+
protected static function sortVersions() {
|
218 |
+
foreach ( self::$classVersions as $class => $versions ) {
|
219 |
+
uksort($versions, array(__CLASS__, 'compareVersions'));
|
220 |
+
self::$classVersions[$class] = $versions;
|
221 |
+
}
|
222 |
+
self::$sorted = true;
|
223 |
+
}
|
224 |
+
|
225 |
+
protected static function compareVersions($a, $b) {
|
226 |
+
return -version_compare($a, $b);
|
227 |
+
}
|
228 |
+
|
229 |
+
/**
|
230 |
+
* Register a version of a class.
|
231 |
+
*
|
232 |
+
* @access private This method is only for internal use by the library.
|
233 |
+
*
|
234 |
+
* @param string $generalClass Class name without version numbers, e.g. 'PluginUpdateChecker'.
|
235 |
+
* @param string $versionedClass Actual class name, e.g. 'PluginUpdateChecker_1_2'.
|
236 |
+
* @param string $version Version number, e.g. '1.2'.
|
237 |
+
*/
|
238 |
+
public static function addVersion($generalClass, $versionedClass, $version) {
|
239 |
+
if ( empty(self::$myMajorVersion) ) {
|
240 |
+
$nameParts = explode('_', __CLASS__, 3);
|
241 |
+
self::$myMajorVersion = substr(ltrim($nameParts[1], 'v'), 0, 1);
|
242 |
+
}
|
243 |
+
|
244 |
+
//Store the greatest version number that matches our major version.
|
245 |
+
$components = explode('.', $version);
|
246 |
+
if ( $components[0] === self::$myMajorVersion ) {
|
247 |
+
|
248 |
+
if (
|
249 |
+
empty(self::$latestCompatibleVersion)
|
250 |
+
|| version_compare($version, self::$latestCompatibleVersion, '>')
|
251 |
+
) {
|
252 |
+
self::$latestCompatibleVersion = $version;
|
253 |
+
}
|
254 |
+
|
255 |
+
}
|
256 |
+
|
257 |
+
if ( !isset(self::$classVersions[$generalClass]) ) {
|
258 |
+
self::$classVersions[$generalClass] = array();
|
259 |
+
}
|
260 |
+
self::$classVersions[$generalClass][$version] = $versionedClass;
|
261 |
+
self::$sorted = false;
|
262 |
+
}
|
263 |
+
}
|
264 |
+
|
265 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Metadata.php
ADDED
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( !class_exists('Puc_v4_Metadata', false) ):
|
3 |
+
|
4 |
+
/**
|
5 |
+
* A base container for holding information about updates and plugin metadata.
|
6 |
+
*
|
7 |
+
* @author Janis Elsts
|
8 |
+
* @copyright 2016
|
9 |
+
* @access public
|
10 |
+
*/
|
11 |
+
abstract class Puc_v4_Metadata {
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Create an instance of this class from a JSON document.
|
15 |
+
*
|
16 |
+
* @abstract
|
17 |
+
* @param string $json
|
18 |
+
* @return self
|
19 |
+
*/
|
20 |
+
public static function fromJson(/** @noinspection PhpUnusedParameterInspection */ $json) {
|
21 |
+
throw new LogicException('The ' . __METHOD__ . ' method must be implemented by subclasses');
|
22 |
+
}
|
23 |
+
|
24 |
+
/**
|
25 |
+
* @param string $json
|
26 |
+
* @param self $target
|
27 |
+
* @return bool
|
28 |
+
*/
|
29 |
+
protected static function createFromJson($json, $target) {
|
30 |
+
/** @var StdClass $apiResponse */
|
31 |
+
$apiResponse = json_decode($json);
|
32 |
+
if ( empty($apiResponse) || !is_object($apiResponse) ){
|
33 |
+
trigger_error(
|
34 |
+
"Failed to parse update metadata. Try validating your .json file with http://jsonlint.com/",
|
35 |
+
E_USER_NOTICE
|
36 |
+
);
|
37 |
+
return false;
|
38 |
+
}
|
39 |
+
|
40 |
+
$valid = $target->validateMetadata($apiResponse);
|
41 |
+
if ( is_wp_error($valid) ){
|
42 |
+
trigger_error($valid->get_error_message(), E_USER_NOTICE);
|
43 |
+
return false;
|
44 |
+
}
|
45 |
+
|
46 |
+
foreach(get_object_vars($apiResponse) as $key => $value){
|
47 |
+
$target->$key = $value;
|
48 |
+
}
|
49 |
+
|
50 |
+
return true;
|
51 |
+
}
|
52 |
+
|
53 |
+
/**
|
54 |
+
* No validation by default! Subclasses should check that the required fields are present.
|
55 |
+
*
|
56 |
+
* @param StdClass $apiResponse
|
57 |
+
* @return bool|WP_Error
|
58 |
+
*/
|
59 |
+
protected function validateMetadata(/** @noinspection PhpUnusedParameterInspection */ $apiResponse) {
|
60 |
+
return true;
|
61 |
+
}
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Create a new instance by copying the necessary fields from another object.
|
65 |
+
*
|
66 |
+
* @abstract
|
67 |
+
* @param StdClass|self $object The source object.
|
68 |
+
* @return self The new copy.
|
69 |
+
*/
|
70 |
+
public static function fromObject(/** @noinspection PhpUnusedParameterInspection */ $object) {
|
71 |
+
throw new LogicException('The ' . __METHOD__ . ' method must be implemented by subclasses');
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Create an instance of StdClass that can later be converted back to an
|
76 |
+
* update or info container. Useful for serialization and caching, as it
|
77 |
+
* avoids the "incomplete object" problem if the cached value is loaded
|
78 |
+
* before this class.
|
79 |
+
*
|
80 |
+
* @return StdClass
|
81 |
+
*/
|
82 |
+
public function toStdClass() {
|
83 |
+
$object = new stdClass();
|
84 |
+
$this->copyFields($this, $object);
|
85 |
+
return $object;
|
86 |
+
}
|
87 |
+
|
88 |
+
/**
|
89 |
+
* Transform the metadata into the format used by WordPress core.
|
90 |
+
*
|
91 |
+
* @return object
|
92 |
+
*/
|
93 |
+
abstract public function toWpFormat();
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Copy known fields from one object to another.
|
97 |
+
*
|
98 |
+
* @param StdClass|self $from
|
99 |
+
* @param StdClass|self $to
|
100 |
+
*/
|
101 |
+
protected function copyFields($from, $to) {
|
102 |
+
$fields = $this->getFieldNames();
|
103 |
+
|
104 |
+
if ( property_exists($from, 'slug') && !empty($from->slug) ) {
|
105 |
+
//Let plugins add extra fields without having to create subclasses.
|
106 |
+
$fields = apply_filters($this->getPrefixedFilter('retain_fields') . '-' . $from->slug, $fields);
|
107 |
+
}
|
108 |
+
|
109 |
+
foreach ($fields as $field) {
|
110 |
+
if ( property_exists($from, $field) ) {
|
111 |
+
$to->$field = $from->$field;
|
112 |
+
}
|
113 |
+
}
|
114 |
+
}
|
115 |
+
|
116 |
+
/**
|
117 |
+
* @return string[]
|
118 |
+
*/
|
119 |
+
protected function getFieldNames() {
|
120 |
+
return array();
|
121 |
+
}
|
122 |
+
|
123 |
+
/**
|
124 |
+
* @param string $tag
|
125 |
+
* @return string
|
126 |
+
*/
|
127 |
+
protected function getPrefixedFilter($tag) {
|
128 |
+
return 'puc_' . $tag;
|
129 |
+
}
|
130 |
+
}
|
131 |
+
|
132 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/OAuthSignature.php
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if ( !class_exists('Puc_v4_OAuthSignature', false) ):
|
4 |
+
|
5 |
+
/**
|
6 |
+
* A basic signature generator for zero-legged OAuth 1.0.
|
7 |
+
*/
|
8 |
+
class Puc_v4_OAuthSignature {
|
9 |
+
private $consumerKey = '';
|
10 |
+
private $consumerSecret = '';
|
11 |
+
|
12 |
+
public function __construct($consumerKey, $consumerSecret) {
|
13 |
+
$this->consumerKey = $consumerKey;
|
14 |
+
$this->consumerSecret = $consumerSecret;
|
15 |
+
}
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Sign a URL using OAuth 1.0.
|
19 |
+
*
|
20 |
+
* @param string $url The URL to be signed. It may contain query parameters.
|
21 |
+
* @param string $method HTTP method such as "GET", "POST" and so on.
|
22 |
+
* @return string The signed URL.
|
23 |
+
*/
|
24 |
+
public function sign($url, $method = 'GET') {
|
25 |
+
$parameters = array();
|
26 |
+
|
27 |
+
//Parse query parameters.
|
28 |
+
$query = @parse_url($url, PHP_URL_QUERY);
|
29 |
+
if ( !empty($query) ) {
|
30 |
+
parse_str($query, $parsedParams);
|
31 |
+
if ( is_array($parameters) ) {
|
32 |
+
$parameters = $parsedParams;
|
33 |
+
}
|
34 |
+
//Remove the query string from the URL. We'll replace it later.
|
35 |
+
$url = substr($url, 0, strpos($url, '?'));
|
36 |
+
}
|
37 |
+
|
38 |
+
$parameters = array_merge(
|
39 |
+
$parameters,
|
40 |
+
array(
|
41 |
+
'oauth_consumer_key' => $this->consumerKey,
|
42 |
+
'oauth_nonce' => $this->nonce(),
|
43 |
+
'oauth_signature_method' => 'HMAC-SHA1',
|
44 |
+
'oauth_timestamp' => time(),
|
45 |
+
'oauth_version' => '1.0',
|
46 |
+
)
|
47 |
+
);
|
48 |
+
unset($parameters['oauth_signature']);
|
49 |
+
|
50 |
+
//Parameters must be sorted alphabetically before signing.
|
51 |
+
ksort($parameters);
|
52 |
+
|
53 |
+
//The most complicated part of the request - generating the signature.
|
54 |
+
//The string to sign contains the HTTP method, the URL path, and all of
|
55 |
+
//our query parameters. Everything is URL encoded. Then we concatenate
|
56 |
+
//them with ampersands into a single string to hash.
|
57 |
+
$encodedVerb = urlencode($method);
|
58 |
+
$encodedUrl = urlencode($url);
|
59 |
+
$encodedParams = urlencode(http_build_query($parameters, '', '&'));
|
60 |
+
|
61 |
+
$stringToSign = $encodedVerb . '&' . $encodedUrl . '&' . $encodedParams;
|
62 |
+
|
63 |
+
//Since we only have one OAuth token (the consumer secret) we only have
|
64 |
+
//to use it as our HMAC key. However, we still have to append an & to it
|
65 |
+
//as if we were using it with additional tokens.
|
66 |
+
$secret = urlencode($this->consumerSecret) . '&';
|
67 |
+
|
68 |
+
//The signature is a hash of the consumer key and the base string. Note
|
69 |
+
//that we have to get the raw output from hash_hmac and base64 encode
|
70 |
+
//the binary data result.
|
71 |
+
$parameters['oauth_signature'] = base64_encode(hash_hmac('sha1', $stringToSign, $secret, true));
|
72 |
+
|
73 |
+
return ($url . '?' . http_build_query($parameters));
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Generate a random nonce.
|
78 |
+
*
|
79 |
+
* @return string
|
80 |
+
*/
|
81 |
+
private function nonce() {
|
82 |
+
$mt = microtime();
|
83 |
+
$rand = mt_rand();
|
84 |
+
return md5($mt . '_' . $rand);
|
85 |
+
}
|
86 |
+
}
|
87 |
+
|
88 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Plugin/Info.php
ADDED
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( !class_exists('Puc_v4_Plugin_Info', false) ):
|
3 |
+
|
4 |
+
/**
|
5 |
+
* A container class for holding and transforming various plugin metadata.
|
6 |
+
*
|
7 |
+
* @author Janis Elsts
|
8 |
+
* @copyright 2016
|
9 |
+
* @access public
|
10 |
+
*/
|
11 |
+
class Puc_v4_Plugin_Info extends Puc_v4_Metadata {
|
12 |
+
//Most fields map directly to the contents of the plugin's info.json file.
|
13 |
+
//See the relevant docs for a description of their meaning.
|
14 |
+
public $name;
|
15 |
+
public $slug;
|
16 |
+
public $version;
|
17 |
+
public $homepage;
|
18 |
+
public $sections = array();
|
19 |
+
public $banners;
|
20 |
+
public $translations = array();
|
21 |
+
public $download_url;
|
22 |
+
|
23 |
+
public $author;
|
24 |
+
public $author_homepage;
|
25 |
+
|
26 |
+
public $requires;
|
27 |
+
public $tested;
|
28 |
+
public $upgrade_notice;
|
29 |
+
|
30 |
+
public $rating;
|
31 |
+
public $num_ratings;
|
32 |
+
public $downloaded;
|
33 |
+
public $active_installs;
|
34 |
+
public $last_updated;
|
35 |
+
|
36 |
+
public $id = 0; //The native WP.org API returns numeric plugin IDs, but they're not used for anything.
|
37 |
+
|
38 |
+
public $filename; //Plugin filename relative to the plugins directory.
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Create a new instance of Plugin Info from JSON-encoded plugin info
|
42 |
+
* returned by an external update API.
|
43 |
+
*
|
44 |
+
* @param string $json Valid JSON string representing plugin info.
|
45 |
+
* @return self|null New instance of Plugin Info, or NULL on error.
|
46 |
+
*/
|
47 |
+
public static function fromJson($json){
|
48 |
+
$instance = new self();
|
49 |
+
|
50 |
+
if ( !parent::createFromJson($json, $instance) ) {
|
51 |
+
return null;
|
52 |
+
}
|
53 |
+
|
54 |
+
//json_decode decodes assoc. arrays as objects. We want it as an array.
|
55 |
+
$instance->sections = (array)$instance->sections;
|
56 |
+
|
57 |
+
return $instance;
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Very, very basic validation.
|
62 |
+
*
|
63 |
+
* @param StdClass $apiResponse
|
64 |
+
* @return bool|WP_Error
|
65 |
+
*/
|
66 |
+
protected function validateMetadata($apiResponse) {
|
67 |
+
if (
|
68 |
+
!isset($apiResponse->name, $apiResponse->version)
|
69 |
+
|| empty($apiResponse->name)
|
70 |
+
|| empty($apiResponse->version)
|
71 |
+
) {
|
72 |
+
return new WP_Error(
|
73 |
+
'puc-invalid-metadata',
|
74 |
+
"The plugin metadata file does not contain the required 'name' and/or 'version' keys."
|
75 |
+
);
|
76 |
+
}
|
77 |
+
return true;
|
78 |
+
}
|
79 |
+
|
80 |
+
|
81 |
+
/**
|
82 |
+
* Transform plugin info into the format used by the native WordPress.org API
|
83 |
+
*
|
84 |
+
* @return object
|
85 |
+
*/
|
86 |
+
public function toWpFormat(){
|
87 |
+
$info = new stdClass;
|
88 |
+
|
89 |
+
//The custom update API is built so that many fields have the same name and format
|
90 |
+
//as those returned by the native WordPress.org API. These can be assigned directly.
|
91 |
+
$sameFormat = array(
|
92 |
+
'name', 'slug', 'version', 'requires', 'tested', 'rating', 'upgrade_notice',
|
93 |
+
'num_ratings', 'downloaded', 'active_installs', 'homepage', 'last_updated',
|
94 |
+
);
|
95 |
+
foreach($sameFormat as $field){
|
96 |
+
if ( isset($this->$field) ) {
|
97 |
+
$info->$field = $this->$field;
|
98 |
+
} else {
|
99 |
+
$info->$field = null;
|
100 |
+
}
|
101 |
+
}
|
102 |
+
|
103 |
+
//Other fields need to be renamed and/or transformed.
|
104 |
+
$info->download_link = $this->download_url;
|
105 |
+
$info->author = $this->getFormattedAuthor();
|
106 |
+
$info->sections = array_merge(array('description' => ''), $this->sections);
|
107 |
+
|
108 |
+
if ( !empty($this->banners) ) {
|
109 |
+
//WP expects an array with two keys: "high" and "low". Both are optional.
|
110 |
+
//Docs: https://wordpress.org/plugins/about/faq/#banners
|
111 |
+
$info->banners = is_object($this->banners) ? get_object_vars($this->banners) : $this->banners;
|
112 |
+
$info->banners = array_intersect_key($info->banners, array('high' => true, 'low' => true));
|
113 |
+
}
|
114 |
+
|
115 |
+
return $info;
|
116 |
+
}
|
117 |
+
|
118 |
+
protected function getFormattedAuthor() {
|
119 |
+
if ( !empty($this->author_homepage) ){
|
120 |
+
/** @noinspection HtmlUnknownTarget */
|
121 |
+
return sprintf('<a href="%s">%s</a>', $this->author_homepage, $this->author);
|
122 |
+
}
|
123 |
+
return $this->author;
|
124 |
+
}
|
125 |
+
}
|
126 |
+
|
127 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Plugin/Update.php
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( !class_exists('Puc_v4_Plugin_Update', false) ):
|
3 |
+
|
4 |
+
/**
|
5 |
+
* A simple container class for holding information about an available update.
|
6 |
+
*
|
7 |
+
* @author Janis Elsts
|
8 |
+
* @copyright 2016
|
9 |
+
* @version 3.2
|
10 |
+
* @access public
|
11 |
+
*/
|
12 |
+
class Puc_v4_Plugin_Update extends Puc_v4_Update {
|
13 |
+
public $id = 0;
|
14 |
+
public $homepage;
|
15 |
+
public $upgrade_notice;
|
16 |
+
public $tested;
|
17 |
+
public $filename; //Plugin filename relative to the plugins directory.
|
18 |
+
|
19 |
+
protected static $extraFields = array(
|
20 |
+
'id', 'homepage', 'tested', 'upgrade_notice', 'filename',
|
21 |
+
);
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Create a new instance of PluginUpdate from its JSON-encoded representation.
|
25 |
+
*
|
26 |
+
* @param string $json
|
27 |
+
* @return Puc_v4_Plugin_Update|null
|
28 |
+
*/
|
29 |
+
public static function fromJson($json){
|
30 |
+
//Since update-related information is simply a subset of the full plugin info,
|
31 |
+
//we can parse the update JSON as if it was a plugin info string, then copy over
|
32 |
+
//the parts that we care about.
|
33 |
+
$pluginInfo = Puc_v4_Plugin_Info::fromJson($json);
|
34 |
+
if ( $pluginInfo != null ) {
|
35 |
+
return self::fromPluginInfo($pluginInfo);
|
36 |
+
} else {
|
37 |
+
return null;
|
38 |
+
}
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Create a new instance of PluginUpdate based on an instance of PluginInfo.
|
43 |
+
* Basically, this just copies a subset of fields from one object to another.
|
44 |
+
*
|
45 |
+
* @param Puc_v4_Plugin_Info $info
|
46 |
+
* @return Puc_v4_Plugin_Update
|
47 |
+
*/
|
48 |
+
public static function fromPluginInfo($info){
|
49 |
+
return self::fromObject($info);
|
50 |
+
}
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Create a new instance by copying the necessary fields from another object.
|
54 |
+
*
|
55 |
+
* @param StdClass|Puc_v4_Plugin_Info|Puc_v4_Plugin_Update $object The source object.
|
56 |
+
* @return Puc_v4_Plugin_Update The new copy.
|
57 |
+
*/
|
58 |
+
public static function fromObject($object) {
|
59 |
+
$update = new self();
|
60 |
+
$update->copyFields($object, $update);
|
61 |
+
return $update;
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* @return string[]
|
66 |
+
*/
|
67 |
+
protected function getFieldNames() {
|
68 |
+
return array_merge(parent::getFieldNames(), self::$extraFields);
|
69 |
+
}
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Transform the update into the format used by WordPress native plugin API.
|
73 |
+
*
|
74 |
+
* @return object
|
75 |
+
*/
|
76 |
+
public function toWpFormat(){
|
77 |
+
$update = parent::toWpFormat();
|
78 |
+
|
79 |
+
$update->id = $this->id;
|
80 |
+
$update->url = $this->homepage;
|
81 |
+
$update->tested = $this->tested;
|
82 |
+
$update->plugin = $this->filename;
|
83 |
+
|
84 |
+
if ( !empty($this->upgrade_notice) ){
|
85 |
+
$update->upgrade_notice = $this->upgrade_notice;
|
86 |
+
}
|
87 |
+
|
88 |
+
return $update;
|
89 |
+
}
|
90 |
+
}
|
91 |
+
|
92 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Plugin/UpdateChecker.php
ADDED
@@ -0,0 +1,531 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( !class_exists('Puc_v4_Plugin_UpdateChecker', false) ):
|
3 |
+
|
4 |
+
/**
|
5 |
+
* A custom plugin update checker.
|
6 |
+
*
|
7 |
+
* @author Janis Elsts
|
8 |
+
* @copyright 2016
|
9 |
+
* @access public
|
10 |
+
*/
|
11 |
+
class Puc_v4_Plugin_UpdateChecker extends Puc_v4_UpdateChecker {
|
12 |
+
protected $updateTransient = 'update_plugins';
|
13 |
+
protected $translationType = 'plugin';
|
14 |
+
|
15 |
+
public $pluginAbsolutePath = ''; //Full path of the main plugin file.
|
16 |
+
public $pluginFile = ''; //Plugin filename relative to the plugins directory. Many WP APIs use this to identify plugins.
|
17 |
+
public $muPluginFile = ''; //For MU plugins, the plugin filename relative to the mu-plugins directory.
|
18 |
+
|
19 |
+
private $cachedInstalledVersion = null;
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Class constructor.
|
23 |
+
*
|
24 |
+
* @param string $metadataUrl The URL of the plugin's metadata file.
|
25 |
+
* @param string $pluginFile Fully qualified path to the main plugin file.
|
26 |
+
* @param string $slug The plugin's 'slug'. If not specified, the filename part of $pluginFile sans '.php' will be used as the slug.
|
27 |
+
* @param integer $checkPeriod How often to check for updates (in hours). Defaults to checking every 12 hours. Set to 0 to disable automatic update checks.
|
28 |
+
* @param string $optionName Where to store book-keeping info about update checks. Defaults to 'external_updates-$slug'.
|
29 |
+
* @param string $muPluginFile Optional. The plugin filename relative to the mu-plugins directory.
|
30 |
+
*/
|
31 |
+
public function __construct($metadataUrl, $pluginFile, $slug = '', $checkPeriod = 12, $optionName = '', $muPluginFile = ''){
|
32 |
+
$this->pluginAbsolutePath = $pluginFile;
|
33 |
+
$this->pluginFile = plugin_basename($this->pluginAbsolutePath);
|
34 |
+
$this->muPluginFile = $muPluginFile;
|
35 |
+
|
36 |
+
//If no slug is specified, use the name of the main plugin file as the slug.
|
37 |
+
//For example, 'my-cool-plugin/cool-plugin.php' becomes 'cool-plugin'.
|
38 |
+
if ( empty($slug) ){
|
39 |
+
$slug = basename($this->pluginFile, '.php');
|
40 |
+
}
|
41 |
+
|
42 |
+
//Plugin slugs must be unique.
|
43 |
+
$slugCheckFilter = 'puc_is_slug_in_use-' . $this->slug;
|
44 |
+
$slugUsedBy = apply_filters($slugCheckFilter, false);
|
45 |
+
if ( $slugUsedBy ) {
|
46 |
+
$this->triggerError(sprintf(
|
47 |
+
'Plugin slug "%s" is already in use by %s. Slugs must be unique.',
|
48 |
+
htmlentities($this->slug),
|
49 |
+
htmlentities($slugUsedBy)
|
50 |
+
), E_USER_ERROR);
|
51 |
+
}
|
52 |
+
add_filter($slugCheckFilter, array($this, 'getAbsolutePath'));
|
53 |
+
|
54 |
+
//Backwards compatibility: If the plugin is a mu-plugin but no $muPluginFile is specified, assume
|
55 |
+
//it's the same as $pluginFile given that it's not in a subdirectory (WP only looks in the base dir).
|
56 |
+
if ( (strpbrk($this->pluginFile, '/\\') === false) && $this->isUnknownMuPlugin() ) {
|
57 |
+
$this->muPluginFile = $this->pluginFile;
|
58 |
+
}
|
59 |
+
|
60 |
+
parent::__construct($metadataUrl, dirname($this->pluginFile), $slug, $checkPeriod, $optionName);
|
61 |
+
}
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Create an instance of the scheduler.
|
65 |
+
*
|
66 |
+
* @param int $checkPeriod
|
67 |
+
* @return Puc_v4_Scheduler
|
68 |
+
*/
|
69 |
+
protected function createScheduler($checkPeriod) {
|
70 |
+
$scheduler = new Puc_v4_Scheduler($this, $checkPeriod, array('load-plugins.php'));
|
71 |
+
register_deactivation_hook($this->pluginFile, array($scheduler, 'removeUpdaterCron'));
|
72 |
+
return $scheduler;
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Install the hooks required to run periodic update checks and inject update info
|
77 |
+
* into WP data structures.
|
78 |
+
*
|
79 |
+
* @return void
|
80 |
+
*/
|
81 |
+
protected function installHooks(){
|
82 |
+
//Override requests for plugin information
|
83 |
+
add_filter('plugins_api', array($this, 'injectInfo'), 20, 3);
|
84 |
+
|
85 |
+
add_filter('plugin_row_meta', array($this, 'addCheckForUpdatesLink'), 10, 2);
|
86 |
+
add_action('admin_init', array($this, 'handleManualCheck'));
|
87 |
+
add_action('all_admin_notices', array($this, 'displayManualCheckResult'));
|
88 |
+
|
89 |
+
//Clear the version number cache when something - anything - is upgraded or WP clears the update cache.
|
90 |
+
add_filter('upgrader_post_install', array($this, 'clearCachedVersion'));
|
91 |
+
add_action('delete_site_transient_update_plugins', array($this, 'clearCachedVersion'));
|
92 |
+
|
93 |
+
parent::installHooks();
|
94 |
+
}
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Retrieve plugin info from the configured API endpoint.
|
98 |
+
*
|
99 |
+
* @uses wp_remote_get()
|
100 |
+
*
|
101 |
+
* @param array $queryArgs Additional query arguments to append to the request. Optional.
|
102 |
+
* @return Puc_v4_Plugin_Info
|
103 |
+
*/
|
104 |
+
public function requestInfo($queryArgs = array()) {
|
105 |
+
list($pluginInfo, $result) = $this->requestMetadata('Puc_v4_Plugin_Info', 'request_info', $queryArgs);
|
106 |
+
|
107 |
+
if ( $pluginInfo !== null ) {
|
108 |
+
/** @var Puc_v4_Plugin_Info $pluginInfo */
|
109 |
+
$pluginInfo->filename = $this->pluginFile;
|
110 |
+
$pluginInfo->slug = $this->slug;
|
111 |
+
}
|
112 |
+
|
113 |
+
$pluginInfo = apply_filters($this->getUniqueName('request_info_result'), $pluginInfo, $result);
|
114 |
+
return $pluginInfo;
|
115 |
+
}
|
116 |
+
|
117 |
+
/**
|
118 |
+
* Retrieve the latest update (if any) from the configured API endpoint.
|
119 |
+
*
|
120 |
+
* @uses PluginUpdateChecker::requestInfo()
|
121 |
+
*
|
122 |
+
* @return Puc_v4_Update|null An instance of Plugin_Update, or NULL when no updates are available.
|
123 |
+
*/
|
124 |
+
public function requestUpdate() {
|
125 |
+
//For the sake of simplicity, this function just calls requestInfo()
|
126 |
+
//and transforms the result accordingly.
|
127 |
+
$pluginInfo = $this->requestInfo(array('checking_for_updates' => '1'));
|
128 |
+
if ( $pluginInfo == null ){
|
129 |
+
return null;
|
130 |
+
}
|
131 |
+
$update = Puc_v4_Plugin_Update::fromPluginInfo($pluginInfo);
|
132 |
+
|
133 |
+
$update = $this->filterUpdateResult($update);
|
134 |
+
|
135 |
+
return $update;
|
136 |
+
}
|
137 |
+
|
138 |
+
/**
|
139 |
+
* Get the currently installed version of the plugin.
|
140 |
+
*
|
141 |
+
* @return string Version number.
|
142 |
+
*/
|
143 |
+
public function getInstalledVersion(){
|
144 |
+
if ( isset($this->cachedInstalledVersion) ) {
|
145 |
+
return $this->cachedInstalledVersion;
|
146 |
+
}
|
147 |
+
|
148 |
+
$pluginHeader = $this->getPluginHeader();
|
149 |
+
if ( isset($pluginHeader['Version']) ) {
|
150 |
+
$this->cachedInstalledVersion = $pluginHeader['Version'];
|
151 |
+
return $pluginHeader['Version'];
|
152 |
+
} else {
|
153 |
+
//This can happen if the filename points to something that is not a plugin.
|
154 |
+
$this->triggerError(
|
155 |
+
sprintf(
|
156 |
+
"Can't to read the Version header for '%s'. The filename is incorrect or is not a plugin.",
|
157 |
+
$this->pluginFile
|
158 |
+
),
|
159 |
+
E_USER_WARNING
|
160 |
+
);
|
161 |
+
return null;
|
162 |
+
}
|
163 |
+
}
|
164 |
+
|
165 |
+
/**
|
166 |
+
* Get plugin's metadata from its file header.
|
167 |
+
*
|
168 |
+
* @return array
|
169 |
+
*/
|
170 |
+
protected function getPluginHeader() {
|
171 |
+
if ( !is_file($this->pluginAbsolutePath) ) {
|
172 |
+
//This can happen if the plugin filename is wrong.
|
173 |
+
$this->triggerError(
|
174 |
+
sprintf(
|
175 |
+
"Can't to read the plugin header for '%s'. The file does not exist.",
|
176 |
+
$this->pluginFile
|
177 |
+
),
|
178 |
+
E_USER_WARNING
|
179 |
+
);
|
180 |
+
return array();
|
181 |
+
}
|
182 |
+
|
183 |
+
if ( !function_exists('get_plugin_data') ){
|
184 |
+
/** @noinspection PhpIncludeInspection */
|
185 |
+
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
|
186 |
+
}
|
187 |
+
return get_plugin_data($this->pluginAbsolutePath, false, false);
|
188 |
+
}
|
189 |
+
|
190 |
+
/**
|
191 |
+
* @return array
|
192 |
+
*/
|
193 |
+
protected function getHeaderNames() {
|
194 |
+
return array(
|
195 |
+
'Name' => 'Plugin Name',
|
196 |
+
'PluginURI' => 'Plugin URI',
|
197 |
+
'Version' => 'Version',
|
198 |
+
'Description' => 'Description',
|
199 |
+
'Author' => 'Author',
|
200 |
+
'AuthorURI' => 'Author URI',
|
201 |
+
'TextDomain' => 'Text Domain',
|
202 |
+
'DomainPath' => 'Domain Path',
|
203 |
+
'Network' => 'Network',
|
204 |
+
|
205 |
+
//The newest WordPress version that this plugin requires or has been tested with.
|
206 |
+
//We support several different formats for compatibility with other libraries.
|
207 |
+
'Tested WP' => 'Tested WP',
|
208 |
+
'Requires WP' => 'Requires WP',
|
209 |
+
'Tested up to' => 'Tested up to',
|
210 |
+
'Requires at least' => 'Requires at least',
|
211 |
+
);
|
212 |
+
}
|
213 |
+
|
214 |
+
|
215 |
+
/**
|
216 |
+
* Intercept plugins_api() calls that request information about our plugin and
|
217 |
+
* use the configured API endpoint to satisfy them.
|
218 |
+
*
|
219 |
+
* @see plugins_api()
|
220 |
+
*
|
221 |
+
* @param mixed $result
|
222 |
+
* @param string $action
|
223 |
+
* @param array|object $args
|
224 |
+
* @return mixed
|
225 |
+
*/
|
226 |
+
public function injectInfo($result, $action = null, $args = null){
|
227 |
+
$relevant = ($action == 'plugin_information') && isset($args->slug) && (
|
228 |
+
($args->slug == $this->slug) || ($args->slug == dirname($this->pluginFile))
|
229 |
+
);
|
230 |
+
if ( !$relevant ) {
|
231 |
+
return $result;
|
232 |
+
}
|
233 |
+
|
234 |
+
$pluginInfo = $this->requestInfo();
|
235 |
+
$pluginInfo = apply_filters($this->getUniqueName('pre_inject_info'), $pluginInfo);
|
236 |
+
if ( $pluginInfo ) {
|
237 |
+
return $pluginInfo->toWpFormat();
|
238 |
+
}
|
239 |
+
|
240 |
+
return $result;
|
241 |
+
}
|
242 |
+
|
243 |
+
protected function shouldShowUpdates() {
|
244 |
+
//No update notifications for mu-plugins unless explicitly enabled. The MU plugin file
|
245 |
+
//is usually different from the main plugin file so the update wouldn't show up properly anyway.
|
246 |
+
return !$this->isUnknownMuPlugin();
|
247 |
+
}
|
248 |
+
|
249 |
+
/**
|
250 |
+
* @param stdClass|null $updates
|
251 |
+
* @param stdClass $updateToAdd
|
252 |
+
* @return stdClass
|
253 |
+
*/
|
254 |
+
protected function addUpdateToList($updates, $updateToAdd) {
|
255 |
+
if ( $this->isMuPlugin() ) {
|
256 |
+
//WP does not support automatic update installation for mu-plugins, but we can
|
257 |
+
//still display a notice.
|
258 |
+
$updateToAdd->package = null;
|
259 |
+
}
|
260 |
+
return parent::addUpdateToList($updates, $updateToAdd);
|
261 |
+
}
|
262 |
+
|
263 |
+
/**
|
264 |
+
* @param stdClass|null $updates
|
265 |
+
* @return stdClass|null
|
266 |
+
*/
|
267 |
+
protected function removeUpdateFromList($updates) {
|
268 |
+
$updates = parent::removeUpdateFromList($updates);
|
269 |
+
if ( !empty($this->muPluginFile) && isset($updates, $updates->response) ) {
|
270 |
+
unset($updates->response[$this->muPluginFile]);
|
271 |
+
}
|
272 |
+
return $updates;
|
273 |
+
}
|
274 |
+
|
275 |
+
/**
|
276 |
+
* For plugins, the update array is indexed by the plugin filename relative to the "plugins"
|
277 |
+
* directory. Example: "plugin-name/plugin.php".
|
278 |
+
*
|
279 |
+
* @return string
|
280 |
+
*/
|
281 |
+
protected function getUpdateListKey() {
|
282 |
+
if ( $this->isMuPlugin() ) {
|
283 |
+
return $this->muPluginFile;
|
284 |
+
}
|
285 |
+
return $this->pluginFile;
|
286 |
+
}
|
287 |
+
|
288 |
+
/**
|
289 |
+
* Alias for isBeingUpgraded().
|
290 |
+
*
|
291 |
+
* @deprecated
|
292 |
+
* @param WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
293 |
+
* @return bool
|
294 |
+
*/
|
295 |
+
public function isPluginBeingUpgraded($upgrader = null) {
|
296 |
+
return $this->isBeingUpgraded($upgrader);
|
297 |
+
}
|
298 |
+
|
299 |
+
/**
|
300 |
+
* Is there an update being installed for this plugin, right now?
|
301 |
+
*
|
302 |
+
* @param WP_Upgrader|null $upgrader
|
303 |
+
* @return bool
|
304 |
+
*/
|
305 |
+
public function isBeingUpgraded($upgrader = null) {
|
306 |
+
return $this->upgraderStatus->isPluginBeingUpgraded($this->pluginFile, $upgrader);
|
307 |
+
}
|
308 |
+
|
309 |
+
/**
|
310 |
+
* Get the details of the currently available update, if any.
|
311 |
+
*
|
312 |
+
* If no updates are available, or if the last known update version is below or equal
|
313 |
+
* to the currently installed version, this method will return NULL.
|
314 |
+
*
|
315 |
+
* Uses cached update data. To retrieve update information straight from
|
316 |
+
* the metadata URL, call requestUpdate() instead.
|
317 |
+
*
|
318 |
+
* @return Puc_v4_Plugin_Update|null
|
319 |
+
*/
|
320 |
+
public function getUpdate() {
|
321 |
+
$update = parent::getUpdate();
|
322 |
+
if ( isset($update) ) {
|
323 |
+
/** @var Puc_v4_Plugin_Update $update */
|
324 |
+
$update->filename = $this->pluginFile;
|
325 |
+
}
|
326 |
+
return $update;
|
327 |
+
}
|
328 |
+
|
329 |
+
/**
|
330 |
+
* Add a "Check for updates" link to the plugin row in the "Plugins" page. By default,
|
331 |
+
* the new link will appear after the "Visit plugin site" link.
|
332 |
+
*
|
333 |
+
* You can change the link text by using the "puc_manual_check_link-$slug" filter.
|
334 |
+
* Returning an empty string from the filter will disable the link.
|
335 |
+
*
|
336 |
+
* @param array $pluginMeta Array of meta links.
|
337 |
+
* @param string $pluginFile
|
338 |
+
* @return array
|
339 |
+
*/
|
340 |
+
public function addCheckForUpdatesLink($pluginMeta, $pluginFile) {
|
341 |
+
$isRelevant = ($pluginFile == $this->pluginFile)
|
342 |
+
|| (!empty($this->muPluginFile) && $pluginFile == $this->muPluginFile);
|
343 |
+
|
344 |
+
if ( $isRelevant && $this->userCanInstallUpdates() ) {
|
345 |
+
$linkUrl = wp_nonce_url(
|
346 |
+
add_query_arg(
|
347 |
+
array(
|
348 |
+
'puc_check_for_updates' => 1,
|
349 |
+
'puc_slug' => $this->slug,
|
350 |
+
),
|
351 |
+
self_admin_url('plugins.php')
|
352 |
+
),
|
353 |
+
'puc_check_for_updates'
|
354 |
+
);
|
355 |
+
|
356 |
+
$linkText = apply_filters(
|
357 |
+
$this->getUniqueName('manual_check_link'),
|
358 |
+
__('Check for updates', 'plugin-update-checker')
|
359 |
+
);
|
360 |
+
if ( !empty($linkText) ) {
|
361 |
+
/** @noinspection HtmlUnknownTarget */
|
362 |
+
$pluginMeta[] = sprintf('<a href="%s">%s</a>', esc_attr($linkUrl), $linkText);
|
363 |
+
}
|
364 |
+
}
|
365 |
+
return $pluginMeta;
|
366 |
+
}
|
367 |
+
|
368 |
+
/**
|
369 |
+
* Check for updates when the user clicks the "Check for updates" link.
|
370 |
+
* @see self::addCheckForUpdatesLink()
|
371 |
+
*
|
372 |
+
* @return void
|
373 |
+
*/
|
374 |
+
public function handleManualCheck() {
|
375 |
+
$shouldCheck =
|
376 |
+
isset($_GET['puc_check_for_updates'], $_GET['puc_slug'])
|
377 |
+
&& $_GET['puc_slug'] == $this->slug
|
378 |
+
&& $this->userCanInstallUpdates()
|
379 |
+
&& check_admin_referer('puc_check_for_updates');
|
380 |
+
|
381 |
+
if ( $shouldCheck ) {
|
382 |
+
$update = $this->checkForUpdates();
|
383 |
+
$status = ($update === null) ? 'no_update' : 'update_available';
|
384 |
+
wp_redirect(add_query_arg(
|
385 |
+
array(
|
386 |
+
'puc_update_check_result' => $status,
|
387 |
+
'puc_slug' => $this->slug,
|
388 |
+
),
|
389 |
+
self_admin_url('plugins.php')
|
390 |
+
));
|
391 |
+
}
|
392 |
+
}
|
393 |
+
|
394 |
+
/**
|
395 |
+
* Display the results of a manual update check.
|
396 |
+
* @see self::handleManualCheck()
|
397 |
+
*
|
398 |
+
* You can change the result message by using the "puc_manual_check_message-$slug" filter.
|
399 |
+
*/
|
400 |
+
public function displayManualCheckResult() {
|
401 |
+
if ( isset($_GET['puc_update_check_result'], $_GET['puc_slug']) && ($_GET['puc_slug'] == $this->slug) ) {
|
402 |
+
$status = strval($_GET['puc_update_check_result']);
|
403 |
+
if ( $status == 'no_update' ) {
|
404 |
+
$message = __('This plugin is up to date.', 'plugin-update-checker');
|
405 |
+
} else if ( $status == 'update_available' ) {
|
406 |
+
$message = __('A new version of this plugin is available.', 'plugin-update-checker');
|
407 |
+
} else {
|
408 |
+
$message = sprintf(__('Unknown update checker status "%s"', 'plugin-update-checker'), htmlentities($status));
|
409 |
+
}
|
410 |
+
printf(
|
411 |
+
'<div class="updated notice is-dismissible"><p>%s</p></div>',
|
412 |
+
apply_filters($this->getUniqueName('manual_check_message'), $message, $status)
|
413 |
+
);
|
414 |
+
}
|
415 |
+
}
|
416 |
+
|
417 |
+
/**
|
418 |
+
* Check if the current user has the required permissions to install updates.
|
419 |
+
*
|
420 |
+
* @return bool
|
421 |
+
*/
|
422 |
+
public function userCanInstallUpdates() {
|
423 |
+
return current_user_can('update_plugins');
|
424 |
+
}
|
425 |
+
|
426 |
+
/**
|
427 |
+
* Check if the plugin file is inside the mu-plugins directory.
|
428 |
+
*
|
429 |
+
* @return bool
|
430 |
+
*/
|
431 |
+
protected function isMuPlugin() {
|
432 |
+
static $cachedResult = null;
|
433 |
+
|
434 |
+
if ( $cachedResult === null ) {
|
435 |
+
//Convert both paths to the canonical form before comparison.
|
436 |
+
$muPluginDir = realpath(WPMU_PLUGIN_DIR);
|
437 |
+
$pluginPath = realpath($this->pluginAbsolutePath);
|
438 |
+
|
439 |
+
$cachedResult = (strpos($pluginPath, $muPluginDir) === 0);
|
440 |
+
}
|
441 |
+
|
442 |
+
return $cachedResult;
|
443 |
+
}
|
444 |
+
|
445 |
+
/**
|
446 |
+
* MU plugins are partially supported, but only when we know which file in mu-plugins
|
447 |
+
* corresponds to this plugin.
|
448 |
+
*
|
449 |
+
* @return bool
|
450 |
+
*/
|
451 |
+
protected function isUnknownMuPlugin() {
|
452 |
+
return empty($this->muPluginFile) && $this->isMuPlugin();
|
453 |
+
}
|
454 |
+
|
455 |
+
/**
|
456 |
+
* Clear the cached plugin version. This method can be set up as a filter (hook) and will
|
457 |
+
* return the filter argument unmodified.
|
458 |
+
*
|
459 |
+
* @param mixed $filterArgument
|
460 |
+
* @return mixed
|
461 |
+
*/
|
462 |
+
public function clearCachedVersion($filterArgument = null) {
|
463 |
+
$this->cachedInstalledVersion = null;
|
464 |
+
return $filterArgument;
|
465 |
+
}
|
466 |
+
|
467 |
+
/**
|
468 |
+
* Get absolute path to the main plugin file.
|
469 |
+
*
|
470 |
+
* @return string
|
471 |
+
*/
|
472 |
+
public function getAbsolutePath() {
|
473 |
+
return $this->pluginAbsolutePath;
|
474 |
+
}
|
475 |
+
|
476 |
+
/**
|
477 |
+
* Register a callback for filtering query arguments.
|
478 |
+
*
|
479 |
+
* The callback function should take one argument - an associative array of query arguments.
|
480 |
+
* It should return a modified array of query arguments.
|
481 |
+
*
|
482 |
+
* @uses add_filter() This method is a convenience wrapper for add_filter().
|
483 |
+
*
|
484 |
+
* @param callable $callback
|
485 |
+
* @return void
|
486 |
+
*/
|
487 |
+
public function addQueryArgFilter($callback){
|
488 |
+
$this->addFilter('request_info_query_args', $callback);
|
489 |
+
}
|
490 |
+
|
491 |
+
/**
|
492 |
+
* Register a callback for filtering arguments passed to wp_remote_get().
|
493 |
+
*
|
494 |
+
* The callback function should take one argument - an associative array of arguments -
|
495 |
+
* and return a modified array or arguments. See the WP documentation on wp_remote_get()
|
496 |
+
* for details on what arguments are available and how they work.
|
497 |
+
*
|
498 |
+
* @uses add_filter() This method is a convenience wrapper for add_filter().
|
499 |
+
*
|
500 |
+
* @param callable $callback
|
501 |
+
* @return void
|
502 |
+
*/
|
503 |
+
public function addHttpRequestArgFilter($callback) {
|
504 |
+
$this->addFilter('request_info_options', $callback);
|
505 |
+
}
|
506 |
+
|
507 |
+
/**
|
508 |
+
* Register a callback for filtering the plugin info retrieved from the external API.
|
509 |
+
*
|
510 |
+
* The callback function should take two arguments. If the plugin info was retrieved
|
511 |
+
* successfully, the first argument passed will be an instance of PluginInfo. Otherwise,
|
512 |
+
* it will be NULL. The second argument will be the corresponding return value of
|
513 |
+
* wp_remote_get (see WP docs for details).
|
514 |
+
*
|
515 |
+
* The callback function should return a new or modified instance of PluginInfo or NULL.
|
516 |
+
*
|
517 |
+
* @uses add_filter() This method is a convenience wrapper for add_filter().
|
518 |
+
*
|
519 |
+
* @param callable $callback
|
520 |
+
* @return void
|
521 |
+
*/
|
522 |
+
public function addResultFilter($callback) {
|
523 |
+
$this->addFilter('request_info_result', $callback, 10, 2);
|
524 |
+
}
|
525 |
+
|
526 |
+
protected function createDebugBarExtension() {
|
527 |
+
return new Puc_v4_DebugBar_PluginExtension($this);
|
528 |
+
}
|
529 |
+
}
|
530 |
+
|
531 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Scheduler.php
ADDED
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( !class_exists('Puc_v4_Scheduler', false) ):
|
3 |
+
|
4 |
+
/**
|
5 |
+
* The scheduler decides when and how often to check for updates.
|
6 |
+
* It calls @see Puc_v4_UpdateChecker::checkForUpdates() to perform the actual checks.
|
7 |
+
*/
|
8 |
+
class Puc_v4_Scheduler {
|
9 |
+
public $checkPeriod = 12; //How often to check for updates (in hours).
|
10 |
+
public $throttleRedundantChecks = false; //Check less often if we already know that an update is available.
|
11 |
+
public $throttledCheckPeriod = 72;
|
12 |
+
|
13 |
+
protected $hourlyCheckHooks = array('load-update.php');
|
14 |
+
|
15 |
+
/**
|
16 |
+
* @var Puc_v4_UpdateChecker
|
17 |
+
*/
|
18 |
+
protected $updateChecker;
|
19 |
+
|
20 |
+
private $cronHook = null;
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Scheduler constructor.
|
24 |
+
*
|
25 |
+
* @param Puc_v4_UpdateChecker $updateChecker
|
26 |
+
* @param int $checkPeriod How often to check for updates (in hours).
|
27 |
+
* @param array $hourlyHooks
|
28 |
+
*/
|
29 |
+
public function __construct($updateChecker, $checkPeriod, $hourlyHooks = array('load-plugins.php')) {
|
30 |
+
$this->updateChecker = $updateChecker;
|
31 |
+
$this->checkPeriod = $checkPeriod;
|
32 |
+
|
33 |
+
//Set up the periodic update checks
|
34 |
+
$this->cronHook = $this->updateChecker->getUniqueName('cron_check_updates');
|
35 |
+
if ( $this->checkPeriod > 0 ){
|
36 |
+
|
37 |
+
//Trigger the check via Cron.
|
38 |
+
//Try to use one of the default schedules if possible as it's less likely to conflict
|
39 |
+
//with other plugins and their custom schedules.
|
40 |
+
$defaultSchedules = array(
|
41 |
+
1 => 'hourly',
|
42 |
+
12 => 'twicedaily',
|
43 |
+
24 => 'daily',
|
44 |
+
);
|
45 |
+
if ( array_key_exists($this->checkPeriod, $defaultSchedules) ) {
|
46 |
+
$scheduleName = $defaultSchedules[$this->checkPeriod];
|
47 |
+
} else {
|
48 |
+
//Use a custom cron schedule.
|
49 |
+
$scheduleName = 'every' . $this->checkPeriod . 'hours';
|
50 |
+
add_filter('cron_schedules', array($this, '_addCustomSchedule'));
|
51 |
+
}
|
52 |
+
|
53 |
+
if ( !wp_next_scheduled($this->cronHook) && !defined('WP_INSTALLING') ) {
|
54 |
+
wp_schedule_event(time(), $scheduleName, $this->cronHook);
|
55 |
+
}
|
56 |
+
add_action($this->cronHook, array($this, 'maybeCheckForUpdates'));
|
57 |
+
|
58 |
+
//In case Cron is disabled or unreliable, we also manually trigger
|
59 |
+
//the periodic checks while the user is browsing the Dashboard.
|
60 |
+
add_action( 'admin_init', array($this, 'maybeCheckForUpdates') );
|
61 |
+
|
62 |
+
//Like WordPress itself, we check more often on certain pages.
|
63 |
+
/** @see wp_update_plugins */
|
64 |
+
add_action('load-update-core.php', array($this, 'maybeCheckForUpdates'));
|
65 |
+
//"load-update.php" and "load-plugins.php" or "load-themes.php".
|
66 |
+
$this->hourlyCheckHooks = array_merge($this->hourlyCheckHooks, $hourlyHooks);
|
67 |
+
foreach($this->hourlyCheckHooks as $hook) {
|
68 |
+
add_action($hook, array($this, 'maybeCheckForUpdates'));
|
69 |
+
}
|
70 |
+
//This hook fires after a bulk update is complete.
|
71 |
+
add_action('upgrader_process_complete', array($this, 'maybeCheckForUpdates'), 11, 0);
|
72 |
+
|
73 |
+
} else {
|
74 |
+
//Periodic checks are disabled.
|
75 |
+
wp_clear_scheduled_hook($this->cronHook);
|
76 |
+
}
|
77 |
+
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Check for updates if the configured check interval has already elapsed.
|
81 |
+
* Will use a shorter check interval on certain admin pages like "Dashboard -> Updates" or when doing cron.
|
82 |
+
*
|
83 |
+
* You can override the default behaviour by using the "puc_check_now-$slug" filter.
|
84 |
+
* The filter callback will be passed three parameters:
|
85 |
+
* - Current decision. TRUE = check updates now, FALSE = don't check now.
|
86 |
+
* - Last check time as a Unix timestamp.
|
87 |
+
* - Configured check period in hours.
|
88 |
+
* Return TRUE to check for updates immediately, or FALSE to cancel.
|
89 |
+
*
|
90 |
+
* This method is declared public because it's a hook callback. Calling it directly is not recommended.
|
91 |
+
*/
|
92 |
+
public function maybeCheckForUpdates(){
|
93 |
+
if ( empty($this->checkPeriod) ){
|
94 |
+
return;
|
95 |
+
}
|
96 |
+
|
97 |
+
$state = $this->updateChecker->getUpdateState();
|
98 |
+
$shouldCheck = ($state->timeSinceLastCheck() >= $this->getEffectiveCheckPeriod());
|
99 |
+
|
100 |
+
//Let plugin authors substitute their own algorithm.
|
101 |
+
$shouldCheck = apply_filters(
|
102 |
+
$this->updateChecker->getUniqueName('check_now'),
|
103 |
+
$shouldCheck,
|
104 |
+
$state->getLastCheck(),
|
105 |
+
$this->checkPeriod
|
106 |
+
);
|
107 |
+
|
108 |
+
if ( $shouldCheck ) {
|
109 |
+
$this->updateChecker->checkForUpdates();
|
110 |
+
}
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Calculate the actual check period based on the current status and environment.
|
115 |
+
*
|
116 |
+
* @return int Check period in seconds.
|
117 |
+
*/
|
118 |
+
protected function getEffectiveCheckPeriod() {
|
119 |
+
$currentFilter = current_filter();
|
120 |
+
if ( in_array($currentFilter, array('load-update-core.php', 'upgrader_process_complete')) ) {
|
121 |
+
//Check more often when the user visits "Dashboard -> Updates" or does a bulk update.
|
122 |
+
$period = 60;
|
123 |
+
} else if ( in_array($currentFilter, $this->hourlyCheckHooks) ) {
|
124 |
+
//Also check more often on /wp-admin/update.php and the "Plugins" or "Themes" page.
|
125 |
+
$period = 3600;
|
126 |
+
} else if ( $this->throttleRedundantChecks && ($this->updateChecker->getUpdate() !== null) ) {
|
127 |
+
//Check less frequently if it's already known that an update is available.
|
128 |
+
$period = $this->throttledCheckPeriod * 3600;
|
129 |
+
} else if ( defined('DOING_CRON') && constant('DOING_CRON') ) {
|
130 |
+
//WordPress cron schedules are not exact, so lets do an update check even
|
131 |
+
//if slightly less than $checkPeriod hours have elapsed since the last check.
|
132 |
+
$cronFuzziness = 20 * 60;
|
133 |
+
$period = $this->checkPeriod * 3600 - $cronFuzziness;
|
134 |
+
} else {
|
135 |
+
$period = $this->checkPeriod * 3600;
|
136 |
+
}
|
137 |
+
|
138 |
+
return $period;
|
139 |
+
}
|
140 |
+
|
141 |
+
/**
|
142 |
+
* Add our custom schedule to the array of Cron schedules used by WP.
|
143 |
+
*
|
144 |
+
* @param array $schedules
|
145 |
+
* @return array
|
146 |
+
*/
|
147 |
+
public function _addCustomSchedule($schedules){
|
148 |
+
if ( $this->checkPeriod && ($this->checkPeriod > 0) ){
|
149 |
+
$scheduleName = 'every' . $this->checkPeriod . 'hours';
|
150 |
+
$schedules[$scheduleName] = array(
|
151 |
+
'interval' => $this->checkPeriod * 3600,
|
152 |
+
'display' => sprintf('Every %d hours', $this->checkPeriod),
|
153 |
+
);
|
154 |
+
}
|
155 |
+
return $schedules;
|
156 |
+
}
|
157 |
+
|
158 |
+
/**
|
159 |
+
* Remove the scheduled cron event that the library uses to check for updates.
|
160 |
+
*
|
161 |
+
* @return void
|
162 |
+
*/
|
163 |
+
public function removeUpdaterCron(){
|
164 |
+
wp_clear_scheduled_hook($this->cronHook);
|
165 |
+
}
|
166 |
+
|
167 |
+
/**
|
168 |
+
* Get the name of the update checker's WP-cron hook. Mostly useful for debugging.
|
169 |
+
*
|
170 |
+
* @return string
|
171 |
+
*/
|
172 |
+
public function getCronHookName() {
|
173 |
+
return $this->cronHook;
|
174 |
+
}
|
175 |
+
}
|
176 |
+
|
177 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/StateStore.php
ADDED
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if ( !class_exists('Puc_v4_StateStore', false) ):
|
4 |
+
|
5 |
+
class Puc_v4_StateStore {
|
6 |
+
/**
|
7 |
+
* @var int Last update check timestamp.
|
8 |
+
*/
|
9 |
+
protected $lastCheck = 0;
|
10 |
+
|
11 |
+
/**
|
12 |
+
* @var string Version number.
|
13 |
+
*/
|
14 |
+
protected $checkedVersion = '';
|
15 |
+
|
16 |
+
/**
|
17 |
+
* @var Puc_v4_Update|null Cached update.
|
18 |
+
*/
|
19 |
+
protected $update = null;
|
20 |
+
|
21 |
+
/**
|
22 |
+
* @var string Site option name.
|
23 |
+
*/
|
24 |
+
private $optionName = '';
|
25 |
+
|
26 |
+
/**
|
27 |
+
* @var bool Whether we've already tried to load the state from the database.
|
28 |
+
*/
|
29 |
+
private $isLoaded = false;
|
30 |
+
|
31 |
+
public function __construct($optionName) {
|
32 |
+
$this->optionName = $optionName;
|
33 |
+
}
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Get time elapsed since the last update check.
|
37 |
+
*
|
38 |
+
* If there are no recorded update checks, this method returns a large arbitrary number
|
39 |
+
* (i.e. time since the Unix epoch).
|
40 |
+
*
|
41 |
+
* @return int Elapsed time in seconds.
|
42 |
+
*/
|
43 |
+
public function timeSinceLastCheck() {
|
44 |
+
$this->lazyLoad();
|
45 |
+
return time() - $this->lastCheck;
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* @return int
|
50 |
+
*/
|
51 |
+
public function getLastCheck() {
|
52 |
+
$this->lazyLoad();
|
53 |
+
return $this->lastCheck;
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Set the time of the last update check to the current timestamp.
|
58 |
+
*
|
59 |
+
* @return $this
|
60 |
+
*/
|
61 |
+
public function setLastCheckToNow() {
|
62 |
+
$this->lazyLoad();
|
63 |
+
$this->lastCheck = time();
|
64 |
+
return $this;
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* @return null|Puc_v4_Update
|
69 |
+
*/
|
70 |
+
public function getUpdate() {
|
71 |
+
$this->lazyLoad();
|
72 |
+
return $this->update;
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* @param Puc_v4_Update|null $update
|
77 |
+
* @return $this
|
78 |
+
*/
|
79 |
+
public function setUpdate(Puc_v4_Update $update = null) {
|
80 |
+
$this->lazyLoad();
|
81 |
+
$this->update = $update;
|
82 |
+
return $this;
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* @return string
|
87 |
+
*/
|
88 |
+
public function getCheckedVersion() {
|
89 |
+
$this->lazyLoad();
|
90 |
+
return $this->checkedVersion;
|
91 |
+
}
|
92 |
+
|
93 |
+
/**
|
94 |
+
* @param string $version
|
95 |
+
* @return $this
|
96 |
+
*/
|
97 |
+
public function setCheckedVersion($version) {
|
98 |
+
$this->lazyLoad();
|
99 |
+
$this->checkedVersion = strval($version);
|
100 |
+
return $this;
|
101 |
+
}
|
102 |
+
|
103 |
+
/**
|
104 |
+
* Get translation updates.
|
105 |
+
*
|
106 |
+
* @return array
|
107 |
+
*/
|
108 |
+
public function getTranslations() {
|
109 |
+
$this->lazyLoad();
|
110 |
+
if ( isset($this->update, $this->update->translations) ) {
|
111 |
+
return $this->update->translations;
|
112 |
+
}
|
113 |
+
return array();
|
114 |
+
}
|
115 |
+
|
116 |
+
/**
|
117 |
+
* Set translation updates.
|
118 |
+
*
|
119 |
+
* @param array $translationUpdates
|
120 |
+
*/
|
121 |
+
public function setTranslations($translationUpdates) {
|
122 |
+
$this->lazyLoad();
|
123 |
+
if ( isset($this->update) ) {
|
124 |
+
$this->update->translations = $translationUpdates;
|
125 |
+
$this->save();
|
126 |
+
}
|
127 |
+
}
|
128 |
+
|
129 |
+
public function save() {
|
130 |
+
$state = new stdClass();
|
131 |
+
|
132 |
+
$state->lastCheck = $this->lastCheck;
|
133 |
+
$state->checkedVersion = $this->checkedVersion;
|
134 |
+
|
135 |
+
if ( isset($this->update)) {
|
136 |
+
$state->update = $this->update->toStdClass();
|
137 |
+
|
138 |
+
$updateClass = get_class($this->update);
|
139 |
+
$state->updateClass = $updateClass;
|
140 |
+
$prefix = $this->getLibPrefix();
|
141 |
+
if ( Puc_v4_Utils::startsWith($updateClass, $prefix) ) {
|
142 |
+
$state->updateBaseClass = substr($updateClass, strlen($prefix));
|
143 |
+
}
|
144 |
+
}
|
145 |
+
|
146 |
+
update_site_option($this->optionName, $state);
|
147 |
+
$this->isLoaded = true;
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* @return $this
|
152 |
+
*/
|
153 |
+
public function lazyLoad() {
|
154 |
+
if ( !$this->isLoaded ) {
|
155 |
+
$this->load();
|
156 |
+
}
|
157 |
+
return $this;
|
158 |
+
}
|
159 |
+
|
160 |
+
protected function load() {
|
161 |
+
$this->isLoaded = true;
|
162 |
+
|
163 |
+
$state = get_site_option($this->optionName, null);
|
164 |
+
|
165 |
+
if ( !is_object($state) ) {
|
166 |
+
$this->lastCheck = 0;
|
167 |
+
$this->checkedVersion = '';
|
168 |
+
$this->update = null;
|
169 |
+
return;
|
170 |
+
}
|
171 |
+
|
172 |
+
$this->lastCheck = intval(Puc_v4_Utils::get($state, 'lastCheck', 0));
|
173 |
+
$this->checkedVersion = Puc_v4_Utils::get($state, 'checkedVersion', '');
|
174 |
+
$this->update = null;
|
175 |
+
|
176 |
+
if ( isset($state->update) ) {
|
177 |
+
//This mess is due to the fact that the want the update class from this version
|
178 |
+
//of the library, not the version that saved the update.
|
179 |
+
|
180 |
+
$updateClass = null;
|
181 |
+
if ( isset($state->updateBaseClass) ) {
|
182 |
+
$updateClass = $this->getLibPrefix() . $state->updateBaseClass;
|
183 |
+
} else if ( isset($state->updateClass) && class_exists($state->updateClass) ) {
|
184 |
+
$updateClass = $state->updateClass;
|
185 |
+
}
|
186 |
+
|
187 |
+
if ( $updateClass !== null ) {
|
188 |
+
$this->update = call_user_func(array($updateClass, 'fromObject'), $state->update);
|
189 |
+
}
|
190 |
+
}
|
191 |
+
}
|
192 |
+
|
193 |
+
public function delete() {
|
194 |
+
delete_site_option($this->optionName);
|
195 |
+
|
196 |
+
$this->lastCheck = 0;
|
197 |
+
$this->checkedVersion = '';
|
198 |
+
$this->update = null;
|
199 |
+
}
|
200 |
+
|
201 |
+
private function getLibPrefix() {
|
202 |
+
$parts = explode('_', __CLASS__, 3);
|
203 |
+
return $parts[0] . '_' . $parts[1] . '_';
|
204 |
+
}
|
205 |
+
}
|
206 |
+
|
207 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Theme/Update.php
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if ( !class_exists('Puc_v4_Theme_Update', false) ):
|
4 |
+
|
5 |
+
class Puc_v4_Theme_Update extends Puc_v4_Update {
|
6 |
+
public $details_url = '';
|
7 |
+
|
8 |
+
protected static $extraFields = array('details_url');
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Transform the metadata into the format used by WordPress core.
|
12 |
+
* Note the inconsistency: WP stores plugin updates as objects and theme updates as arrays.
|
13 |
+
*
|
14 |
+
* @return array
|
15 |
+
*/
|
16 |
+
public function toWpFormat() {
|
17 |
+
$update = array(
|
18 |
+
'theme' => $this->slug,
|
19 |
+
'new_version' => $this->version,
|
20 |
+
'url' => $this->details_url,
|
21 |
+
);
|
22 |
+
|
23 |
+
if ( !empty($this->download_url) ) {
|
24 |
+
$update['package'] = $this->download_url;
|
25 |
+
}
|
26 |
+
|
27 |
+
return $update;
|
28 |
+
}
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Create a new instance of Theme_Update from its JSON-encoded representation.
|
32 |
+
*
|
33 |
+
* @param string $json Valid JSON string representing a theme information object.
|
34 |
+
* @return self New instance of ThemeUpdate, or NULL on error.
|
35 |
+
*/
|
36 |
+
public static function fromJson($json) {
|
37 |
+
$instance = new self();
|
38 |
+
if ( !parent::createFromJson($json, $instance) ) {
|
39 |
+
return null;
|
40 |
+
}
|
41 |
+
return $instance;
|
42 |
+
}
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Create a new instance by copying the necessary fields from another object.
|
46 |
+
*
|
47 |
+
* @param StdClass|Puc_v4_Theme_Update $object The source object.
|
48 |
+
* @return Puc_v4_Theme_Update The new copy.
|
49 |
+
*/
|
50 |
+
public static function fromObject($object) {
|
51 |
+
$update = new self();
|
52 |
+
$update->copyFields($object, $update);
|
53 |
+
return $update;
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Basic validation.
|
58 |
+
*
|
59 |
+
* @param StdClass $apiResponse
|
60 |
+
* @return bool|WP_Error
|
61 |
+
*/
|
62 |
+
protected function validateMetadata($apiResponse) {
|
63 |
+
$required = array('version', 'details_url');
|
64 |
+
foreach($required as $key) {
|
65 |
+
if ( !isset($apiResponse->$key) || empty($apiResponse->$key) ) {
|
66 |
+
return new WP_Error(
|
67 |
+
'tuc-invalid-metadata',
|
68 |
+
sprintf('The theme metadata is missing the required "%s" key.', $key)
|
69 |
+
);
|
70 |
+
}
|
71 |
+
}
|
72 |
+
return true;
|
73 |
+
}
|
74 |
+
|
75 |
+
protected function getFieldNames() {
|
76 |
+
return array_merge(parent::getFieldNames(), self::$extraFields);
|
77 |
+
}
|
78 |
+
|
79 |
+
protected function getPrefixedFilter($tag) {
|
80 |
+
return parent::getPrefixedFilter($tag) . '_theme';
|
81 |
+
}
|
82 |
+
}
|
83 |
+
|
84 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Theme/UpdateChecker.php
ADDED
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if ( !class_exists('Puc_v4_Theme_UpdateChecker', false) ):
|
4 |
+
|
5 |
+
class Puc_v4_Theme_UpdateChecker extends Puc_v4_UpdateChecker {
|
6 |
+
protected $filterSuffix = 'theme';
|
7 |
+
protected $updateTransient = 'update_themes';
|
8 |
+
protected $translationType = 'theme';
|
9 |
+
|
10 |
+
/**
|
11 |
+
* @var string Theme directory name.
|
12 |
+
*/
|
13 |
+
protected $stylesheet;
|
14 |
+
|
15 |
+
/**
|
16 |
+
* @var WP_Theme Theme object.
|
17 |
+
*/
|
18 |
+
protected $theme;
|
19 |
+
|
20 |
+
public function __construct($metadataUrl, $stylesheet = null, $customSlug = null, $checkPeriod = 12, $optionName = '') {
|
21 |
+
if ( $stylesheet === null ) {
|
22 |
+
$stylesheet = get_stylesheet();
|
23 |
+
}
|
24 |
+
$this->stylesheet = $stylesheet;
|
25 |
+
$this->theme = wp_get_theme($this->stylesheet);
|
26 |
+
|
27 |
+
parent::__construct(
|
28 |
+
$metadataUrl,
|
29 |
+
$stylesheet,
|
30 |
+
$customSlug ? $customSlug : $stylesheet,
|
31 |
+
$checkPeriod,
|
32 |
+
$optionName
|
33 |
+
);
|
34 |
+
}
|
35 |
+
|
36 |
+
/**
|
37 |
+
* For themes, the update array is indexed by theme directory name.
|
38 |
+
*
|
39 |
+
* @return string
|
40 |
+
*/
|
41 |
+
protected function getUpdateListKey() {
|
42 |
+
return $this->directoryName;
|
43 |
+
}
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Retrieve the latest update (if any) from the configured API endpoint.
|
47 |
+
*
|
48 |
+
* @return Puc_v4_Update|null An instance of Update, or NULL when no updates are available.
|
49 |
+
*/
|
50 |
+
public function requestUpdate() {
|
51 |
+
list($themeUpdate, $result) = $this->requestMetadata('Puc_v4_Theme_Update', 'request_update');
|
52 |
+
|
53 |
+
if ( $themeUpdate !== null ) {
|
54 |
+
/** @var Puc_v4_Theme_Update $themeUpdate */
|
55 |
+
$themeUpdate->slug = $this->slug;
|
56 |
+
}
|
57 |
+
|
58 |
+
$themeUpdate = $this->filterUpdateResult($themeUpdate, $result);
|
59 |
+
return $themeUpdate;
|
60 |
+
}
|
61 |
+
|
62 |
+
public function userCanInstallUpdates() {
|
63 |
+
return current_user_can('update_themes');
|
64 |
+
}
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Get the currently installed version of the plugin or theme.
|
68 |
+
*
|
69 |
+
* @return string Version number.
|
70 |
+
*/
|
71 |
+
public function getInstalledVersion() {
|
72 |
+
return $this->theme->get('Version');
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Create an instance of the scheduler.
|
77 |
+
*
|
78 |
+
* @param int $checkPeriod
|
79 |
+
* @return Puc_v4_Scheduler
|
80 |
+
*/
|
81 |
+
protected function createScheduler($checkPeriod) {
|
82 |
+
return new Puc_v4_Scheduler($this, $checkPeriod, array('load-themes.php'));
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Is there an update being installed right now for this theme?
|
87 |
+
*
|
88 |
+
* @param WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
89 |
+
* @return bool
|
90 |
+
*/
|
91 |
+
public function isBeingUpgraded($upgrader = null) {
|
92 |
+
return $this->upgraderStatus->isThemeBeingUpgraded($this->stylesheet, $upgrader);
|
93 |
+
}
|
94 |
+
|
95 |
+
protected function createDebugBarExtension() {
|
96 |
+
return new Puc_v4_DebugBar_Extension($this, 'Puc_v4_DebugBar_ThemePanel');
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Register a callback for filtering query arguments.
|
101 |
+
*
|
102 |
+
* The callback function should take one argument - an associative array of query arguments.
|
103 |
+
* It should return a modified array of query arguments.
|
104 |
+
*
|
105 |
+
* @param callable $callback
|
106 |
+
* @return void
|
107 |
+
*/
|
108 |
+
public function addQueryArgFilter($callback){
|
109 |
+
$this->addFilter('request_update_query_args', $callback);
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Register a callback for filtering arguments passed to wp_remote_get().
|
114 |
+
*
|
115 |
+
* The callback function should take one argument - an associative array of arguments -
|
116 |
+
* and return a modified array or arguments. See the WP documentation on wp_remote_get()
|
117 |
+
* for details on what arguments are available and how they work.
|
118 |
+
*
|
119 |
+
* @uses add_filter() This method is a convenience wrapper for add_filter().
|
120 |
+
*
|
121 |
+
* @param callable $callback
|
122 |
+
* @return void
|
123 |
+
*/
|
124 |
+
public function addHttpRequestArgFilter($callback) {
|
125 |
+
$this->addFilter('request_update_options', $callback);
|
126 |
+
}
|
127 |
+
|
128 |
+
/**
|
129 |
+
* Register a callback for filtering theme updates retrieved from the external API.
|
130 |
+
*
|
131 |
+
* The callback function should take two arguments. If the theme update was retrieved
|
132 |
+
* successfully, the first argument passed will be an instance of Theme_Update. Otherwise,
|
133 |
+
* it will be NULL. The second argument will be the corresponding return value of
|
134 |
+
* wp_remote_get (see WP docs for details).
|
135 |
+
*
|
136 |
+
* The callback function should return a new or modified instance of Theme_Update or NULL.
|
137 |
+
*
|
138 |
+
* @uses add_filter() This method is a convenience wrapper for add_filter().
|
139 |
+
*
|
140 |
+
* @param callable $callback
|
141 |
+
* @return void
|
142 |
+
*/
|
143 |
+
public function addResultFilter($callback) {
|
144 |
+
$this->addFilter('request_update_result', $callback, 10, 2);
|
145 |
+
}
|
146 |
+
|
147 |
+
/**
|
148 |
+
* @return array
|
149 |
+
*/
|
150 |
+
protected function getHeaderNames() {
|
151 |
+
return array(
|
152 |
+
'Name' => 'Theme Name',
|
153 |
+
'ThemeURI' => 'Theme URI',
|
154 |
+
'Description' => 'Description',
|
155 |
+
'Author' => 'Author',
|
156 |
+
'AuthorURI' => 'Author URI',
|
157 |
+
'Version' => 'Version',
|
158 |
+
'Template' => 'Template',
|
159 |
+
'Status' => 'Status',
|
160 |
+
'Tags' => 'Tags',
|
161 |
+
'TextDomain' => 'Text Domain',
|
162 |
+
'DomainPath' => 'Domain Path',
|
163 |
+
);
|
164 |
+
}
|
165 |
+
}
|
166 |
+
|
167 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Update.php
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( !class_exists('Puc_v4_Update', false) ):
|
3 |
+
|
4 |
+
/**
|
5 |
+
* A simple container class for holding information about an available update.
|
6 |
+
*
|
7 |
+
* @author Janis Elsts
|
8 |
+
* @access public
|
9 |
+
*/
|
10 |
+
abstract class Puc_v4_Update extends Puc_v4_Metadata {
|
11 |
+
public $slug;
|
12 |
+
public $version;
|
13 |
+
public $download_url;
|
14 |
+
public $translations = array();
|
15 |
+
|
16 |
+
/**
|
17 |
+
* @return string[]
|
18 |
+
*/
|
19 |
+
protected function getFieldNames() {
|
20 |
+
return array('slug', 'version', 'download_url', 'translations');
|
21 |
+
}
|
22 |
+
|
23 |
+
public function toWpFormat() {
|
24 |
+
$update = new stdClass();
|
25 |
+
|
26 |
+
$update->slug = $this->slug;
|
27 |
+
$update->new_version = $this->version;
|
28 |
+
$update->package = $this->download_url;
|
29 |
+
|
30 |
+
return $update;
|
31 |
+
}
|
32 |
+
}
|
33 |
+
|
34 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/UpdateChecker.php
ADDED
@@ -0,0 +1,828 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if ( !class_exists('Puc_v4_UpdateChecker', false) ):
|
4 |
+
|
5 |
+
abstract class Puc_v4_UpdateChecker {
|
6 |
+
protected $filterSuffix = '';
|
7 |
+
protected $updateTransient = '';
|
8 |
+
protected $translationType = ''; //"plugin" or "theme".
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Set to TRUE to enable error reporting. Errors are raised using trigger_error()
|
12 |
+
* and should be logged to the standard PHP error log.
|
13 |
+
* @var bool
|
14 |
+
*/
|
15 |
+
public $debugMode = false;
|
16 |
+
|
17 |
+
/**
|
18 |
+
* @var string Where to store the update info.
|
19 |
+
*/
|
20 |
+
public $optionName = '';
|
21 |
+
|
22 |
+
/**
|
23 |
+
* @var string The URL of the metadata file.
|
24 |
+
*/
|
25 |
+
public $metadataUrl = '';
|
26 |
+
|
27 |
+
/**
|
28 |
+
* @var string Plugin or theme directory name.
|
29 |
+
*/
|
30 |
+
public $directoryName = '';
|
31 |
+
|
32 |
+
/**
|
33 |
+
* @var string The slug that will be used in update checker hooks and remote API requests.
|
34 |
+
* Usually matches the directory name unless the plugin/theme directory has been renamed.
|
35 |
+
*/
|
36 |
+
public $slug = '';
|
37 |
+
|
38 |
+
/**
|
39 |
+
* @var Puc_v4_Scheduler
|
40 |
+
*/
|
41 |
+
public $scheduler;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* @var Puc_v4_UpgraderStatus
|
45 |
+
*/
|
46 |
+
protected $upgraderStatus;
|
47 |
+
|
48 |
+
/**
|
49 |
+
* @var Puc_v4_StateStore
|
50 |
+
*/
|
51 |
+
protected $updateState;
|
52 |
+
|
53 |
+
public function __construct($metadataUrl, $directoryName, $slug = null, $checkPeriod = 12, $optionName = '') {
|
54 |
+
$this->debugMode = (bool)(constant('WP_DEBUG'));
|
55 |
+
$this->metadataUrl = $metadataUrl;
|
56 |
+
$this->directoryName = $directoryName;
|
57 |
+
$this->slug = !empty($slug) ? $slug : $this->directoryName;
|
58 |
+
|
59 |
+
$this->optionName = $optionName;
|
60 |
+
if ( empty($this->optionName) ) {
|
61 |
+
//BC: Initially the library only supported plugin updates and didn't use type prefixes
|
62 |
+
//in the option name. Lets use the same prefix-less name when possible.
|
63 |
+
if ( $this->filterSuffix === '' ) {
|
64 |
+
$this->optionName = 'external_updates-' . $this->slug;
|
65 |
+
} else {
|
66 |
+
$this->optionName = $this->getUniqueName('external_updates');
|
67 |
+
}
|
68 |
+
}
|
69 |
+
|
70 |
+
$this->scheduler = $this->createScheduler($checkPeriod);
|
71 |
+
$this->upgraderStatus = new Puc_v4_UpgraderStatus();
|
72 |
+
$this->updateState = new Puc_v4_StateStore($this->optionName);
|
73 |
+
|
74 |
+
if ( did_action('init') ) {
|
75 |
+
$this->loadTextDomain();
|
76 |
+
} else {
|
77 |
+
add_action('init', array($this, 'loadTextDomain'));
|
78 |
+
}
|
79 |
+
|
80 |
+
$this->installHooks();
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* @internal
|
85 |
+
*/
|
86 |
+
public function loadTextDomain() {
|
87 |
+
//We're not using load_plugin_textdomain() or its siblings because figuring out where
|
88 |
+
//the library is located (plugin, mu-plugin, theme, custom wp-content paths) is messy.
|
89 |
+
$domain = 'plugin-update-checker';
|
90 |
+
$locale = apply_filters(
|
91 |
+
'plugin_locale',
|
92 |
+
(is_admin() && function_exists('get_user_locale')) ? get_user_locale() : get_locale(),
|
93 |
+
$domain
|
94 |
+
);
|
95 |
+
|
96 |
+
$moFile = $domain . '-' . $locale . '.mo';
|
97 |
+
$path = realpath(dirname(__FILE__) . '/../../languages');
|
98 |
+
|
99 |
+
if ($path && file_exists($path)) {
|
100 |
+
load_textdomain($domain, $path . '/' . $moFile);
|
101 |
+
}
|
102 |
+
}
|
103 |
+
|
104 |
+
protected function installHooks() {
|
105 |
+
//Insert our update info into the update array maintained by WP.
|
106 |
+
add_filter('site_transient_' . $this->updateTransient, array($this,'injectUpdate'));
|
107 |
+
|
108 |
+
//Insert translation updates into the update list.
|
109 |
+
add_filter('site_transient_' . $this->updateTransient, array($this, 'injectTranslationUpdates'));
|
110 |
+
|
111 |
+
//Clear translation updates when WP clears the update cache.
|
112 |
+
//This needs to be done directly because the library doesn't actually remove obsolete plugin updates,
|
113 |
+
//it just hides them (see getUpdate()). We can't do that with translations - too much disk I/O.
|
114 |
+
add_action(
|
115 |
+
'delete_site_transient_' . $this->updateTransient,
|
116 |
+
array($this, 'clearCachedTranslationUpdates')
|
117 |
+
);
|
118 |
+
|
119 |
+
//Rename the update directory to be the same as the existing directory.
|
120 |
+
if ( $this->directoryName !== '.' ) {
|
121 |
+
add_filter('upgrader_source_selection', array($this, 'fixDirectoryName'), 10, 3);
|
122 |
+
}
|
123 |
+
|
124 |
+
//Allow HTTP requests to the metadata URL even if it's on a local host.
|
125 |
+
add_filter('http_request_host_is_external', array($this, 'allowMetadataHost'), 10, 2);
|
126 |
+
|
127 |
+
//DebugBar integration.
|
128 |
+
if ( did_action('plugins_loaded') ) {
|
129 |
+
$this->maybeInitDebugBar();
|
130 |
+
} else {
|
131 |
+
add_action('plugins_loaded', array($this, 'maybeInitDebugBar'));
|
132 |
+
}
|
133 |
+
}
|
134 |
+
|
135 |
+
/**
|
136 |
+
* Check if the current user has the required permissions to install updates.
|
137 |
+
*
|
138 |
+
* @return bool
|
139 |
+
*/
|
140 |
+
abstract public function userCanInstallUpdates();
|
141 |
+
|
142 |
+
/**
|
143 |
+
* Explicitly allow HTTP requests to the metadata URL.
|
144 |
+
*
|
145 |
+
* WordPress has a security feature where the HTTP API will reject all requests that are sent to
|
146 |
+
* another site hosted on the same server as the current site (IP match), a local host, or a local
|
147 |
+
* IP, unless the host exactly matches the current site.
|
148 |
+
*
|
149 |
+
* This feature is opt-in (at least in WP 4.4). Apparently some people enable it.
|
150 |
+
*
|
151 |
+
* That can be a problem when you're developing your plugin and you decide to host the update information
|
152 |
+
* on the same server as your test site. Update requests will mysteriously fail.
|
153 |
+
*
|
154 |
+
* We fix that by adding an exception for the metadata host.
|
155 |
+
*
|
156 |
+
* @param bool $allow
|
157 |
+
* @param string $host
|
158 |
+
* @return bool
|
159 |
+
*/
|
160 |
+
public function allowMetadataHost($allow, $host) {
|
161 |
+
static $metadataHost = 0; //Using 0 instead of NULL because parse_url can return NULL.
|
162 |
+
if ( $metadataHost === 0 ) {
|
163 |
+
$metadataHost = @parse_url($this->metadataUrl, PHP_URL_HOST);
|
164 |
+
}
|
165 |
+
|
166 |
+
if ( is_string($metadataHost) && (strtolower($host) === strtolower($metadataHost)) ) {
|
167 |
+
return true;
|
168 |
+
}
|
169 |
+
return $allow;
|
170 |
+
}
|
171 |
+
|
172 |
+
/**
|
173 |
+
* Create an instance of the scheduler.
|
174 |
+
*
|
175 |
+
* This is implemented as a method to make it possible for plugins to subclass the update checker
|
176 |
+
* and substitute their own scheduler.
|
177 |
+
*
|
178 |
+
* @param int $checkPeriod
|
179 |
+
* @return Puc_v4_Scheduler
|
180 |
+
*/
|
181 |
+
abstract protected function createScheduler($checkPeriod);
|
182 |
+
|
183 |
+
/**
|
184 |
+
* Check for updates. The results are stored in the DB option specified in $optionName.
|
185 |
+
*
|
186 |
+
* @return Puc_v4_Update|null
|
187 |
+
*/
|
188 |
+
public function checkForUpdates() {
|
189 |
+
$installedVersion = $this->getInstalledVersion();
|
190 |
+
//Fail silently if we can't find the plugin/theme or read its header.
|
191 |
+
if ( $installedVersion === null ) {
|
192 |
+
$this->triggerError(
|
193 |
+
sprintf('Skipping update check for %s - installed version unknown.', $this->slug),
|
194 |
+
E_USER_WARNING
|
195 |
+
);
|
196 |
+
return null;
|
197 |
+
}
|
198 |
+
|
199 |
+
$state = $this->updateState;
|
200 |
+
$state->setLastCheckToNow()
|
201 |
+
->setCheckedVersion($installedVersion)
|
202 |
+
->save(); //Save before checking in case something goes wrong
|
203 |
+
|
204 |
+
$state->setUpdate($this->requestUpdate());
|
205 |
+
$state->save();
|
206 |
+
|
207 |
+
return $this->getUpdate();
|
208 |
+
}
|
209 |
+
|
210 |
+
/**
|
211 |
+
* Load the update checker state from the DB.
|
212 |
+
*
|
213 |
+
* @return Puc_v4_StateStore
|
214 |
+
*/
|
215 |
+
public function getUpdateState() {
|
216 |
+
return $this->updateState->lazyLoad();
|
217 |
+
}
|
218 |
+
|
219 |
+
/**
|
220 |
+
* Reset update checker state - i.e. last check time, cached update data and so on.
|
221 |
+
*
|
222 |
+
* Call this when your plugin is being uninstalled, or if you want to
|
223 |
+
* clear the update cache.
|
224 |
+
*/
|
225 |
+
public function resetUpdateState() {
|
226 |
+
$this->updateState->delete();
|
227 |
+
}
|
228 |
+
|
229 |
+
/**
|
230 |
+
* Get the details of the currently available update, if any.
|
231 |
+
*
|
232 |
+
* If no updates are available, or if the last known update version is below or equal
|
233 |
+
* to the currently installed version, this method will return NULL.
|
234 |
+
*
|
235 |
+
* Uses cached update data. To retrieve update information straight from
|
236 |
+
* the metadata URL, call requestUpdate() instead.
|
237 |
+
*
|
238 |
+
* @return Puc_v4_Update|null
|
239 |
+
*/
|
240 |
+
public function getUpdate() {
|
241 |
+
$update = $this->updateState->getUpdate();
|
242 |
+
|
243 |
+
//Is there an update available?
|
244 |
+
if ( isset($update) ) {
|
245 |
+
//Check if the update is actually newer than the currently installed version.
|
246 |
+
$installedVersion = $this->getInstalledVersion();
|
247 |
+
|
248 |
+
/***************************** FORCE AN UPDATE ****************************************/
|
249 |
+
$force_updates = get_option($update->slug.'-force-update-pro', true);
|
250 |
+
|
251 |
+
if ($force_updates) {
|
252 |
+
return $update;
|
253 |
+
}
|
254 |
+
/****************************** FORCE AN UPDATE ***************************************/
|
255 |
+
|
256 |
+
if ( ($installedVersion !== null) && version_compare($update->version, $installedVersion, '>') ){
|
257 |
+
return $update;
|
258 |
+
}
|
259 |
+
}
|
260 |
+
return null;
|
261 |
+
}
|
262 |
+
|
263 |
+
/**
|
264 |
+
* Retrieve the latest update (if any) from the configured API endpoint.
|
265 |
+
*
|
266 |
+
* Subclasses should run the update through filterUpdateResult before returning it.
|
267 |
+
*
|
268 |
+
* @return Puc_v4_Update An instance of Update, or NULL when no updates are available.
|
269 |
+
*/
|
270 |
+
abstract public function requestUpdate();
|
271 |
+
|
272 |
+
/**
|
273 |
+
* Filter the result of a requestUpdate() call.
|
274 |
+
*
|
275 |
+
* @param Puc_v4_Update|null $update
|
276 |
+
* @param array|WP_Error|null $httpResult The value returned by wp_remote_get(), if any.
|
277 |
+
* @return Puc_v4_Update
|
278 |
+
*/
|
279 |
+
protected function filterUpdateResult($update, $httpResult = null) {
|
280 |
+
//Let plugins/themes modify the update.
|
281 |
+
$update = apply_filters($this->getUniqueName('request_update_result'), $update, $httpResult);
|
282 |
+
|
283 |
+
if ( isset($update, $update->translations) ) {
|
284 |
+
//Keep only those translation updates that apply to this site.
|
285 |
+
$update->translations = $this->filterApplicableTranslations($update->translations);
|
286 |
+
}
|
287 |
+
|
288 |
+
return $update;
|
289 |
+
}
|
290 |
+
|
291 |
+
/**
|
292 |
+
* Get the currently installed version of the plugin or theme.
|
293 |
+
*
|
294 |
+
* @return string Version number.
|
295 |
+
*/
|
296 |
+
abstract public function getInstalledVersion();
|
297 |
+
|
298 |
+
/**
|
299 |
+
* Trigger a PHP error, but only when $debugMode is enabled.
|
300 |
+
*
|
301 |
+
* @param string $message
|
302 |
+
* @param int $errorType
|
303 |
+
*/
|
304 |
+
protected function triggerError($message, $errorType) {
|
305 |
+
if ($this->debugMode) {
|
306 |
+
trigger_error($message, $errorType);
|
307 |
+
}
|
308 |
+
}
|
309 |
+
|
310 |
+
/**
|
311 |
+
* Get the full name of an update checker filter, action or DB entry.
|
312 |
+
*
|
313 |
+
* This method adds the "puc_" prefix and the "-$slug" suffix to the filter name.
|
314 |
+
* For example, "pre_inject_update" becomes "puc_pre_inject_update-plugin-slug".
|
315 |
+
*
|
316 |
+
* @param string $baseTag
|
317 |
+
* @return string
|
318 |
+
*/
|
319 |
+
public function getUniqueName($baseTag) {
|
320 |
+
$name = 'puc_' . $baseTag;
|
321 |
+
if ($this->filterSuffix !== '') {
|
322 |
+
$name .= '_' . $this->filterSuffix;
|
323 |
+
}
|
324 |
+
return $name . '-' . $this->slug;
|
325 |
+
}
|
326 |
+
|
327 |
+
/* -------------------------------------------------------------------
|
328 |
+
* PUC filters and filter utilities
|
329 |
+
* -------------------------------------------------------------------
|
330 |
+
*/
|
331 |
+
|
332 |
+
/**
|
333 |
+
* Register a callback for one of the update checker filters.
|
334 |
+
*
|
335 |
+
* Identical to add_filter(), except it automatically adds the "puc_" prefix
|
336 |
+
* and the "-$slug" suffix to the filter name. For example, "request_info_result"
|
337 |
+
* becomes "puc_request_info_result-your_plugin_slug".
|
338 |
+
*
|
339 |
+
* @param string $tag
|
340 |
+
* @param callable $callback
|
341 |
+
* @param int $priority
|
342 |
+
* @param int $acceptedArgs
|
343 |
+
*/
|
344 |
+
public function addFilter($tag, $callback, $priority = 10, $acceptedArgs = 1) {
|
345 |
+
add_filter($this->getUniqueName($tag), $callback, $priority, $acceptedArgs);
|
346 |
+
}
|
347 |
+
|
348 |
+
/* -------------------------------------------------------------------
|
349 |
+
* Inject updates
|
350 |
+
* -------------------------------------------------------------------
|
351 |
+
*/
|
352 |
+
|
353 |
+
/**
|
354 |
+
* Insert the latest update (if any) into the update list maintained by WP.
|
355 |
+
*
|
356 |
+
* @param stdClass $updates Update list.
|
357 |
+
* @return stdClass Modified update list.
|
358 |
+
*/
|
359 |
+
public function injectUpdate($updates) {
|
360 |
+
//Is there an update to insert?
|
361 |
+
$update = $this->getUpdate();
|
362 |
+
|
363 |
+
if ( !$this->shouldShowUpdates() ) {
|
364 |
+
$update = null;
|
365 |
+
}
|
366 |
+
|
367 |
+
if ( !empty($update) ) {
|
368 |
+
//Let plugins filter the update info before it's passed on to WordPress.
|
369 |
+
$update = apply_filters($this->getUniqueName('pre_inject_update'), $update);
|
370 |
+
$updates = $this->addUpdateToList($updates, $update->toWpFormat());
|
371 |
+
} else {
|
372 |
+
//Clean up any stale update info.
|
373 |
+
$updates = $this->removeUpdateFromList($updates);
|
374 |
+
}
|
375 |
+
|
376 |
+
return $updates;
|
377 |
+
}
|
378 |
+
|
379 |
+
/**
|
380 |
+
* @param stdClass|null $updates
|
381 |
+
* @param stdClass|array $updateToAdd
|
382 |
+
* @return stdClass
|
383 |
+
*/
|
384 |
+
protected function addUpdateToList($updates, $updateToAdd) {
|
385 |
+
if ( !is_object($updates) ) {
|
386 |
+
$updates = new stdClass();
|
387 |
+
$updates->response = array();
|
388 |
+
}
|
389 |
+
|
390 |
+
$updates->response[$this->getUpdateListKey()] = $updateToAdd;
|
391 |
+
return $updates;
|
392 |
+
}
|
393 |
+
|
394 |
+
/**
|
395 |
+
* @param stdClass|null $updates
|
396 |
+
* @return stdClass|null
|
397 |
+
*/
|
398 |
+
protected function removeUpdateFromList($updates) {
|
399 |
+
if ( isset($updates, $updates->response) ) {
|
400 |
+
unset($updates->response[$this->getUpdateListKey()]);
|
401 |
+
}
|
402 |
+
return $updates;
|
403 |
+
}
|
404 |
+
|
405 |
+
/**
|
406 |
+
* Get the key that will be used when adding updates to the update list that's maintained
|
407 |
+
* by the WordPress core. The list is always an associative array, but the key is different
|
408 |
+
* for plugins and themes.
|
409 |
+
*
|
410 |
+
* @return string
|
411 |
+
*/
|
412 |
+
abstract protected function getUpdateListKey();
|
413 |
+
|
414 |
+
/**
|
415 |
+
* Should we show available updates?
|
416 |
+
*
|
417 |
+
* Usually the answer is "yes", but there are exceptions. For example, WordPress doesn't
|
418 |
+
* support automatic updates installation for mu-plugins, so PUC usually won't show update
|
419 |
+
* notifications in that case. See the plugin-specific subclass for details.
|
420 |
+
*
|
421 |
+
* Note: This method only applies to updates that are displayed (or not) in the WordPress
|
422 |
+
* admin. It doesn't affect APIs like requestUpdate and getUpdate.
|
423 |
+
*
|
424 |
+
* @return bool
|
425 |
+
*/
|
426 |
+
protected function shouldShowUpdates() {
|
427 |
+
return true;
|
428 |
+
}
|
429 |
+
|
430 |
+
/* -------------------------------------------------------------------
|
431 |
+
* JSON-based update API
|
432 |
+
* -------------------------------------------------------------------
|
433 |
+
*/
|
434 |
+
|
435 |
+
/**
|
436 |
+
* Retrieve plugin or theme metadata from the JSON document at $this->metadataUrl.
|
437 |
+
*
|
438 |
+
* @param string $metaClass Parse the JSON as an instance of this class. It must have a static fromJson method.
|
439 |
+
* @param string $filterRoot
|
440 |
+
* @param array $queryArgs Additional query arguments.
|
441 |
+
* @return array [Puc_v4_Metadata|null, array|WP_Error] A metadata instance and the value returned by wp_remote_get().
|
442 |
+
*/
|
443 |
+
protected function requestMetadata($metaClass, $filterRoot, $queryArgs = array()) {
|
444 |
+
//Query args to append to the URL. Plugins can add their own by using a filter callback (see addQueryArgFilter()).
|
445 |
+
$installedVersion = $this->getInstalledVersion();
|
446 |
+
$queryArgs['installed_version'] = ($installedVersion !== null) ? $installedVersion : '';
|
447 |
+
$queryArgs = apply_filters($this->getUniqueName($filterRoot . '_query_args'), $queryArgs);
|
448 |
+
|
449 |
+
//Various options for the wp_remote_get() call. Plugins can filter these, too.
|
450 |
+
$options = array(
|
451 |
+
'timeout' => 10, //seconds
|
452 |
+
'headers' => array(
|
453 |
+
'Accept' => 'application/json',
|
454 |
+
),
|
455 |
+
);
|
456 |
+
$options = apply_filters($this->getUniqueName($filterRoot . '_options'), $options);
|
457 |
+
|
458 |
+
//The metadata file should be at 'http://your-api.com/url/here/$slug/info.json'
|
459 |
+
$url = $this->metadataUrl;
|
460 |
+
if ( !empty($queryArgs) ){
|
461 |
+
$url = add_query_arg($queryArgs, $url);
|
462 |
+
}
|
463 |
+
|
464 |
+
$result = wp_remote_get($url, $options);
|
465 |
+
|
466 |
+
//Try to parse the response
|
467 |
+
$status = $this->validateApiResponse($result);
|
468 |
+
$metadata = null;
|
469 |
+
if ( !is_wp_error($status) ){
|
470 |
+
$metadata = call_user_func(array($metaClass, 'fromJson'), $result['body']);
|
471 |
+
} else {
|
472 |
+
$this->triggerError(
|
473 |
+
sprintf('The URL %s does not point to a valid metadata file. ', $url)
|
474 |
+
. $status->get_error_message(),
|
475 |
+
E_USER_WARNING
|
476 |
+
);
|
477 |
+
}
|
478 |
+
|
479 |
+
return array($metadata, $result);
|
480 |
+
}
|
481 |
+
|
482 |
+
/**
|
483 |
+
* Check if $result is a successful update API response.
|
484 |
+
*
|
485 |
+
* @param array|WP_Error $result
|
486 |
+
* @return true|WP_Error
|
487 |
+
*/
|
488 |
+
protected function validateApiResponse($result) {
|
489 |
+
if ( is_wp_error($result) ) { /** @var WP_Error $result */
|
490 |
+
return new WP_Error($result->get_error_code(), 'WP HTTP Error: ' . $result->get_error_message());
|
491 |
+
}
|
492 |
+
|
493 |
+
if ( !isset($result['response']['code']) ) {
|
494 |
+
return new WP_Error(
|
495 |
+
'puc_no_response_code',
|
496 |
+
'wp_remote_get() returned an unexpected result.'
|
497 |
+
);
|
498 |
+
}
|
499 |
+
|
500 |
+
if ( $result['response']['code'] !== 200 ) {
|
501 |
+
return new WP_Error(
|
502 |
+
'puc_unexpected_response_code',
|
503 |
+
'HTTP response code is ' . $result['response']['code'] . ' (expected: 200)'
|
504 |
+
);
|
505 |
+
}
|
506 |
+
|
507 |
+
if ( empty($result['body']) ) {
|
508 |
+
return new WP_Error('puc_empty_response', 'The metadata file appears to be empty.');
|
509 |
+
}
|
510 |
+
|
511 |
+
return true;
|
512 |
+
}
|
513 |
+
|
514 |
+
/* -------------------------------------------------------------------
|
515 |
+
* Language packs / Translation updates
|
516 |
+
* -------------------------------------------------------------------
|
517 |
+
*/
|
518 |
+
|
519 |
+
/**
|
520 |
+
* Filter a list of translation updates and return a new list that contains only updates
|
521 |
+
* that apply to the current site.
|
522 |
+
*
|
523 |
+
* @param array $translations
|
524 |
+
* @return array
|
525 |
+
*/
|
526 |
+
protected function filterApplicableTranslations($translations) {
|
527 |
+
$languages = array_flip(array_values(get_available_languages()));
|
528 |
+
$installedTranslations = $this->getInstalledTranslations();
|
529 |
+
|
530 |
+
$applicableTranslations = array();
|
531 |
+
foreach($translations as $translation) {
|
532 |
+
//Does it match one of the available core languages?
|
533 |
+
$isApplicable = array_key_exists($translation->language, $languages);
|
534 |
+
//Is it more recent than an already-installed translation?
|
535 |
+
if ( isset($installedTranslations[$translation->language]) ) {
|
536 |
+
$updateTimestamp = strtotime($translation->updated);
|
537 |
+
$installedTimestamp = strtotime($installedTranslations[$translation->language]['PO-Revision-Date']);
|
538 |
+
$isApplicable = $updateTimestamp > $installedTimestamp;
|
539 |
+
}
|
540 |
+
|
541 |
+
if ( $isApplicable ) {
|
542 |
+
$applicableTranslations[] = $translation;
|
543 |
+
}
|
544 |
+
}
|
545 |
+
|
546 |
+
return $applicableTranslations;
|
547 |
+
}
|
548 |
+
|
549 |
+
/**
|
550 |
+
* Get a list of installed translations for this plugin or theme.
|
551 |
+
*
|
552 |
+
* @return array
|
553 |
+
*/
|
554 |
+
protected function getInstalledTranslations() {
|
555 |
+
$installedTranslations = wp_get_installed_translations($this->translationType . 's');
|
556 |
+
if ( isset($installedTranslations[$this->directoryName]) ) {
|
557 |
+
$installedTranslations = $installedTranslations[$this->directoryName];
|
558 |
+
} else {
|
559 |
+
$installedTranslations = array();
|
560 |
+
}
|
561 |
+
return $installedTranslations;
|
562 |
+
}
|
563 |
+
|
564 |
+
/**
|
565 |
+
* Insert translation updates into the list maintained by WordPress.
|
566 |
+
*
|
567 |
+
* @param stdClass $updates
|
568 |
+
* @return stdClass
|
569 |
+
*/
|
570 |
+
public function injectTranslationUpdates($updates) {
|
571 |
+
$translationUpdates = $this->getTranslationUpdates();
|
572 |
+
if ( empty($translationUpdates) ) {
|
573 |
+
return $updates;
|
574 |
+
}
|
575 |
+
|
576 |
+
//Being defensive.
|
577 |
+
if ( !is_object($updates) ) {
|
578 |
+
$updates = new stdClass();
|
579 |
+
}
|
580 |
+
if ( !isset($updates->translations) ) {
|
581 |
+
$updates->translations = array();
|
582 |
+
}
|
583 |
+
|
584 |
+
//In case there's a name collision with a plugin or theme hosted on wordpress.org,
|
585 |
+
//remove any preexisting updates that match our thing.
|
586 |
+
$updates->translations = array_values(array_filter(
|
587 |
+
$updates->translations,
|
588 |
+
array($this, 'isNotMyTranslation')
|
589 |
+
));
|
590 |
+
|
591 |
+
//Add our updates to the list.
|
592 |
+
foreach($translationUpdates as $update) {
|
593 |
+
$convertedUpdate = array_merge(
|
594 |
+
array(
|
595 |
+
'type' => $this->translationType,
|
596 |
+
'slug' => $this->directoryName,
|
597 |
+
'autoupdate' => 0,
|
598 |
+
//AFAICT, WordPress doesn't actually use the "version" field for anything.
|
599 |
+
//But lets make sure it's there, just in case.
|
600 |
+
'version' => isset($update->version) ? $update->version : ('1.' . strtotime($update->updated)),
|
601 |
+
),
|
602 |
+
(array)$update
|
603 |
+
);
|
604 |
+
|
605 |
+
$updates->translations[] = $convertedUpdate;
|
606 |
+
}
|
607 |
+
|
608 |
+
return $updates;
|
609 |
+
}
|
610 |
+
|
611 |
+
/**
|
612 |
+
* Get a list of available translation updates.
|
613 |
+
*
|
614 |
+
* This method will return an empty array if there are no updates.
|
615 |
+
* Uses cached update data.
|
616 |
+
*
|
617 |
+
* @return array
|
618 |
+
*/
|
619 |
+
public function getTranslationUpdates() {
|
620 |
+
return $this->updateState->getTranslations();
|
621 |
+
}
|
622 |
+
|
623 |
+
/**
|
624 |
+
* Remove all cached translation updates.
|
625 |
+
*
|
626 |
+
* @see wp_clean_update_cache
|
627 |
+
*/
|
628 |
+
public function clearCachedTranslationUpdates() {
|
629 |
+
$this->updateState->setTranslations(array());
|
630 |
+
}
|
631 |
+
|
632 |
+
/**
|
633 |
+
* Filter callback. Keeps only translations that *don't* match this plugin or theme.
|
634 |
+
*
|
635 |
+
* @param array $translation
|
636 |
+
* @return bool
|
637 |
+
*/
|
638 |
+
protected function isNotMyTranslation($translation) {
|
639 |
+
$isMatch = isset($translation['type'], $translation['slug'])
|
640 |
+
&& ($translation['type'] === $this->translationType)
|
641 |
+
&& ($translation['slug'] === $this->directoryName);
|
642 |
+
|
643 |
+
return !$isMatch;
|
644 |
+
}
|
645 |
+
|
646 |
+
/* -------------------------------------------------------------------
|
647 |
+
* Fix directory name when installing updates
|
648 |
+
* -------------------------------------------------------------------
|
649 |
+
*/
|
650 |
+
|
651 |
+
/**
|
652 |
+
* Rename the update directory to match the existing plugin/theme directory.
|
653 |
+
*
|
654 |
+
* When WordPress installs a plugin or theme update, it assumes that the ZIP file will contain
|
655 |
+
* exactly one directory, and that the directory name will be the same as the directory where
|
656 |
+
* the plugin or theme is currently installed.
|
657 |
+
*
|
658 |
+
* GitHub and other repositories provide ZIP downloads, but they often use directory names like
|
659 |
+
* "project-branch" or "project-tag-hash". We need to change the name to the actual plugin folder.
|
660 |
+
*
|
661 |
+
* This is a hook callback. Don't call it from a plugin.
|
662 |
+
*
|
663 |
+
* @access protected
|
664 |
+
*
|
665 |
+
* @param string $source The directory to copy to /wp-content/plugins or /wp-content/themes. Usually a subdirectory of $remoteSource.
|
666 |
+
* @param string $remoteSource WordPress has extracted the update to this directory.
|
667 |
+
* @param WP_Upgrader $upgrader
|
668 |
+
* @return string|WP_Error
|
669 |
+
*/
|
670 |
+
public function fixDirectoryName($source, $remoteSource, $upgrader) {
|
671 |
+
global $wp_filesystem;
|
672 |
+
/** @var WP_Filesystem_Base $wp_filesystem */
|
673 |
+
|
674 |
+
//Basic sanity checks.
|
675 |
+
if ( !isset($source, $remoteSource, $upgrader, $upgrader->skin, $wp_filesystem) ) {
|
676 |
+
return $source;
|
677 |
+
}
|
678 |
+
|
679 |
+
//If WordPress is upgrading anything other than our plugin/theme, leave the directory name unchanged.
|
680 |
+
if ( !$this->isBeingUpgraded($upgrader) ) {
|
681 |
+
return $source;
|
682 |
+
}
|
683 |
+
|
684 |
+
//Rename the source to match the existing directory.
|
685 |
+
$correctedSource = trailingslashit($remoteSource) . $this->directoryName . '/';
|
686 |
+
if ( $source !== $correctedSource ) {
|
687 |
+
//The update archive should contain a single directory that contains the rest of plugin/theme files.
|
688 |
+
//Otherwise, WordPress will try to copy the entire working directory ($source == $remoteSource).
|
689 |
+
//We can't rename $remoteSource because that would break WordPress code that cleans up temporary files
|
690 |
+
//after update.
|
691 |
+
if ( $this->isBadDirectoryStructure($remoteSource) ) {
|
692 |
+
return new WP_Error(
|
693 |
+
'puc-incorrect-directory-structure',
|
694 |
+
sprintf(
|
695 |
+
'The directory structure of the update is incorrect. All files should be inside ' .
|
696 |
+
'a directory named <span class="code">%s</span>, not at the root of the ZIP archive.',
|
697 |
+
htmlentities($this->slug)
|
698 |
+
)
|
699 |
+
);
|
700 |
+
}
|
701 |
+
|
702 |
+
/** @var WP_Upgrader_Skin $upgrader ->skin */
|
703 |
+
$upgrader->skin->feedback(sprintf(
|
704 |
+
'Renaming %s to %s…',
|
705 |
+
'<span class="code">' . basename($source) . '</span>',
|
706 |
+
'<span class="code">' . $this->directoryName . '</span>'
|
707 |
+
));
|
708 |
+
|
709 |
+
if ( $wp_filesystem->move($source, $correctedSource, true) ) {
|
710 |
+
$upgrader->skin->feedback('Directory successfully renamed.');
|
711 |
+
return $correctedSource;
|
712 |
+
} else {
|
713 |
+
return new WP_Error(
|
714 |
+
'puc-rename-failed',
|
715 |
+
'Unable to rename the update to match the existing directory.'
|
716 |
+
);
|
717 |
+
}
|
718 |
+
}
|
719 |
+
|
720 |
+
return $source;
|
721 |
+
}
|
722 |
+
|
723 |
+
/**
|
724 |
+
* Is there an update being installed right now, for this plugin or theme?
|
725 |
+
*
|
726 |
+
* @param WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
727 |
+
* @return bool
|
728 |
+
*/
|
729 |
+
abstract public function isBeingUpgraded($upgrader = null);
|
730 |
+
|
731 |
+
/**
|
732 |
+
* Check for incorrect update directory structure. An update must contain a single directory,
|
733 |
+
* all other files should be inside that directory.
|
734 |
+
*
|
735 |
+
* @param string $remoteSource Directory path.
|
736 |
+
* @return bool
|
737 |
+
*/
|
738 |
+
protected function isBadDirectoryStructure($remoteSource) {
|
739 |
+
global $wp_filesystem;
|
740 |
+
/** @var WP_Filesystem_Base $wp_filesystem */
|
741 |
+
|
742 |
+
$sourceFiles = $wp_filesystem->dirlist($remoteSource);
|
743 |
+
if ( is_array($sourceFiles) ) {
|
744 |
+
$sourceFiles = array_keys($sourceFiles);
|
745 |
+
$firstFilePath = trailingslashit($remoteSource) . $sourceFiles[0];
|
746 |
+
return (count($sourceFiles) > 1) || (!$wp_filesystem->is_dir($firstFilePath));
|
747 |
+
}
|
748 |
+
|
749 |
+
//Assume it's fine.
|
750 |
+
return false;
|
751 |
+
}
|
752 |
+
|
753 |
+
/* -------------------------------------------------------------------
|
754 |
+
* File header parsing
|
755 |
+
* -------------------------------------------------------------------
|
756 |
+
*/
|
757 |
+
|
758 |
+
/**
|
759 |
+
* Parse plugin or theme metadata from the header comment.
|
760 |
+
*
|
761 |
+
* This is basically a simplified version of the get_file_data() function from /wp-includes/functions.php.
|
762 |
+
* It's intended as a utility for subclasses that detect updates by parsing files in a VCS.
|
763 |
+
*
|
764 |
+
* @param string|null $content File contents.
|
765 |
+
* @return string[]
|
766 |
+
*/
|
767 |
+
public function getFileHeader($content) {
|
768 |
+
$content = (string) $content;
|
769 |
+
|
770 |
+
//WordPress only looks at the first 8 KiB of the file, so we do the same.
|
771 |
+
$content = substr($content, 0, 8192);
|
772 |
+
//Normalize line endings.
|
773 |
+
$content = str_replace("\r", "\n", $content);
|
774 |
+
|
775 |
+
$headers = $this->getHeaderNames();
|
776 |
+
$results = array();
|
777 |
+
foreach ($headers as $field => $name) {
|
778 |
+
$success = preg_match('/^[ \t\/*#@]*' . preg_quote($name, '/') . ':(.*)$/mi', $content, $matches);
|
779 |
+
|
780 |
+
if ( ($success === 1) && $matches[1] ) {
|
781 |
+
$value = $matches[1];
|
782 |
+
if ( function_exists('_cleanup_header_comment') ) {
|
783 |
+
$value = _cleanup_header_comment($value);
|
784 |
+
}
|
785 |
+
$results[$field] = $value;
|
786 |
+
} else {
|
787 |
+
$results[$field] = '';
|
788 |
+
}
|
789 |
+
}
|
790 |
+
|
791 |
+
return $results;
|
792 |
+
}
|
793 |
+
|
794 |
+
/**
|
795 |
+
* @return array Format: ['HeaderKey' => 'Header Name']
|
796 |
+
*/
|
797 |
+
abstract protected function getHeaderNames();
|
798 |
+
|
799 |
+
/* -------------------------------------------------------------------
|
800 |
+
* DebugBar integration
|
801 |
+
* -------------------------------------------------------------------
|
802 |
+
*/
|
803 |
+
|
804 |
+
/**
|
805 |
+
* Initialize the update checker Debug Bar plugin/add-on thingy.
|
806 |
+
*/
|
807 |
+
public function maybeInitDebugBar() {
|
808 |
+
if ( class_exists('Debug_Bar', false) && file_exists(dirname(__FILE__ . '/DebugBar')) ) {
|
809 |
+
$this->createDebugBarExtension();
|
810 |
+
}
|
811 |
+
}
|
812 |
+
|
813 |
+
protected function createDebugBarExtension() {
|
814 |
+
return new Puc_v4_DebugBar_Extension($this);
|
815 |
+
}
|
816 |
+
|
817 |
+
/**
|
818 |
+
* Display additional configuration details in the Debug Bar panel.
|
819 |
+
*
|
820 |
+
* @param Puc_v4_DebugBar_Panel $panel
|
821 |
+
*/
|
822 |
+
public function onDisplayConfiguration($panel) {
|
823 |
+
//Do nothing. Subclasses can use this to add additional info to the panel.
|
824 |
+
}
|
825 |
+
|
826 |
+
}
|
827 |
+
|
828 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/UpgraderStatus.php
ADDED
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( !class_exists('Puc_v4_UpgraderStatus', false) ):
|
3 |
+
|
4 |
+
/**
|
5 |
+
* A utility class that helps figure out which plugin or theme WordPress is upgrading.
|
6 |
+
*
|
7 |
+
* It may seem strange to have a separate class just for that, but the task is surprisingly complicated.
|
8 |
+
* Core classes like Plugin_Upgrader don't expose the plugin file name during an in-progress update (AFAICT).
|
9 |
+
* This class uses a few workarounds and heuristics to get the file name.
|
10 |
+
*/
|
11 |
+
class Puc_v4_UpgraderStatus {
|
12 |
+
private $currentType = null; //"plugin" or "theme".
|
13 |
+
private $currentId = null; //Plugin basename or theme directory name.
|
14 |
+
|
15 |
+
public function __construct() {
|
16 |
+
//Keep track of which plugin/theme WordPress is currently upgrading.
|
17 |
+
add_filter('upgrader_pre_install', array($this, 'setUpgradedThing'), 10, 2);
|
18 |
+
add_filter('upgrader_package_options', array($this, 'setUpgradedPluginFromOptions'), 10, 1);
|
19 |
+
add_filter('upgrader_post_install', array($this, 'clearUpgradedThing'), 10, 1);
|
20 |
+
add_action('upgrader_process_complete', array($this, 'clearUpgradedThing'), 10, 1);
|
21 |
+
}
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Is there and update being installed RIGHT NOW, for a specific plugin?
|
25 |
+
*
|
26 |
+
* Caution: This method is unreliable. WordPress doesn't make it easy to figure out what it is upgrading,
|
27 |
+
* and upgrader implementations are liable to change without notice.
|
28 |
+
*
|
29 |
+
* @param string $pluginFile The plugin to check.
|
30 |
+
* @param WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
31 |
+
* @return bool True if the plugin identified by $pluginFile is being upgraded.
|
32 |
+
*/
|
33 |
+
public function isPluginBeingUpgraded($pluginFile, $upgrader = null) {
|
34 |
+
return $this->isBeingUpgraded('plugin', $pluginFile, $upgrader);
|
35 |
+
}
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Is there an update being installed for a specific theme?
|
39 |
+
*
|
40 |
+
* @param string $stylesheet Theme directory name.
|
41 |
+
* @param WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
42 |
+
* @return bool
|
43 |
+
*/
|
44 |
+
public function isThemeBeingUpgraded($stylesheet, $upgrader = null) {
|
45 |
+
return $this->isBeingUpgraded('theme', $stylesheet, $upgrader);
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Check if a specific theme or plugin is being upgraded.
|
50 |
+
*
|
51 |
+
* @param string $type
|
52 |
+
* @param string $id
|
53 |
+
* @param Plugin_Upgrader|WP_Upgrader|null $upgrader
|
54 |
+
* @return bool
|
55 |
+
*/
|
56 |
+
protected function isBeingUpgraded($type, $id, $upgrader = null) {
|
57 |
+
if ( isset($upgrader) ) {
|
58 |
+
list($currentType, $currentId) = $this->getThingBeingUpgradedBy($upgrader);
|
59 |
+
if ( $currentType !== null ) {
|
60 |
+
$this->currentType = $currentType;
|
61 |
+
$this->currentId = $currentId;
|
62 |
+
}
|
63 |
+
}
|
64 |
+
return ($this->currentType === $type) && ($this->currentId === $id);
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Figure out which theme or plugin is being upgraded by a WP_Upgrader instance.
|
69 |
+
*
|
70 |
+
* Returns an array with two items. The first item is the type of the thing that's being
|
71 |
+
* upgraded: "plugin" or "theme". The second item is either the plugin basename or
|
72 |
+
* the theme directory name. If we can't determine what the upgrader is doing, both items
|
73 |
+
* will be NULL.
|
74 |
+
*
|
75 |
+
* Examples:
|
76 |
+
* ['plugin', 'plugin-dir-name/plugin.php']
|
77 |
+
* ['theme', 'theme-dir-name']
|
78 |
+
*
|
79 |
+
* @param Plugin_Upgrader|WP_Upgrader $upgrader
|
80 |
+
* @return array
|
81 |
+
*/
|
82 |
+
private function getThingBeingUpgradedBy($upgrader) {
|
83 |
+
if ( !isset($upgrader, $upgrader->skin) ) {
|
84 |
+
return array(null, null);
|
85 |
+
}
|
86 |
+
|
87 |
+
//Figure out which plugin or theme is being upgraded.
|
88 |
+
$pluginFile = null;
|
89 |
+
$themeDirectoryName = null;
|
90 |
+
|
91 |
+
$skin = $upgrader->skin;
|
92 |
+
if ( isset($skin->theme_info) && ($skin->theme_info instanceof WP_Theme) ) {
|
93 |
+
$themeDirectoryName = $skin->theme_info->get_stylesheet();
|
94 |
+
} elseif ( $skin instanceof Plugin_Upgrader_Skin ) {
|
95 |
+
if ( isset($skin->plugin) && is_string($skin->plugin) && ($skin->plugin !== '') ) {
|
96 |
+
$pluginFile = $skin->plugin;
|
97 |
+
}
|
98 |
+
} elseif ( $skin instanceof Theme_Upgrader_Skin ) {
|
99 |
+
if ( isset($skin->theme) && is_string($skin->theme) && ($skin->theme !== '') ) {
|
100 |
+
$themeDirectoryName = $skin->theme;
|
101 |
+
}
|
102 |
+
} elseif ( isset($skin->plugin_info) && is_array($skin->plugin_info) ) {
|
103 |
+
//This case is tricky because Bulk_Plugin_Upgrader_Skin (etc) doesn't actually store the plugin
|
104 |
+
//filename anywhere. Instead, it has the plugin headers in $plugin_info. So the best we can
|
105 |
+
//do is compare those headers to the headers of installed plugins.
|
106 |
+
$pluginFile = $this->identifyPluginByHeaders($skin->plugin_info);
|
107 |
+
}
|
108 |
+
|
109 |
+
if ( $pluginFile !== null ) {
|
110 |
+
return array('plugin', $pluginFile);
|
111 |
+
} elseif ( $themeDirectoryName !== null ) {
|
112 |
+
return array('theme', $themeDirectoryName);
|
113 |
+
}
|
114 |
+
return array(null, null);
|
115 |
+
}
|
116 |
+
|
117 |
+
/**
|
118 |
+
* Identify an installed plugin based on its headers.
|
119 |
+
*
|
120 |
+
* @param array $searchHeaders The plugin file header to look for.
|
121 |
+
* @return string|null Plugin basename ("foo/bar.php"), or NULL if we can't identify the plugin.
|
122 |
+
*/
|
123 |
+
private function identifyPluginByHeaders($searchHeaders) {
|
124 |
+
if ( !function_exists('get_plugins') ){
|
125 |
+
/** @noinspection PhpIncludeInspection */
|
126 |
+
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
|
127 |
+
}
|
128 |
+
|
129 |
+
$installedPlugins = get_plugins();
|
130 |
+
$matches = array();
|
131 |
+
foreach($installedPlugins as $pluginBasename => $headers) {
|
132 |
+
$diff1 = array_diff_assoc($headers, $searchHeaders);
|
133 |
+
$diff2 = array_diff_assoc($searchHeaders, $headers);
|
134 |
+
if ( empty($diff1) && empty($diff2) ) {
|
135 |
+
$matches[] = $pluginBasename;
|
136 |
+
}
|
137 |
+
}
|
138 |
+
|
139 |
+
//It's possible (though very unlikely) that there could be two plugins with identical
|
140 |
+
//headers. In that case, we can't unambiguously identify the plugin that's being upgraded.
|
141 |
+
if ( count($matches) !== 1 ) {
|
142 |
+
return null;
|
143 |
+
}
|
144 |
+
|
145 |
+
return reset($matches);
|
146 |
+
}
|
147 |
+
|
148 |
+
/**
|
149 |
+
* @access private
|
150 |
+
*
|
151 |
+
* @param mixed $input
|
152 |
+
* @param array $hookExtra
|
153 |
+
* @return mixed Returns $input unaltered.
|
154 |
+
*/
|
155 |
+
public function setUpgradedThing($input, $hookExtra) {
|
156 |
+
if ( !empty($hookExtra['plugin']) && is_string($hookExtra['plugin']) ) {
|
157 |
+
$this->currentId = $hookExtra['plugin'];
|
158 |
+
$this->currentType = 'plugin';
|
159 |
+
} elseif ( !empty($hookExtra['theme']) && is_string($hookExtra['theme']) ) {
|
160 |
+
$this->currentId = $hookExtra['theme'];
|
161 |
+
$this->currentType = 'theme';
|
162 |
+
} else {
|
163 |
+
$this->currentType = null;
|
164 |
+
$this->currentId = null;
|
165 |
+
}
|
166 |
+
return $input;
|
167 |
+
}
|
168 |
+
|
169 |
+
/**
|
170 |
+
* @access private
|
171 |
+
*
|
172 |
+
* @param array $options
|
173 |
+
* @return array
|
174 |
+
*/
|
175 |
+
public function setUpgradedPluginFromOptions($options) {
|
176 |
+
if ( isset($options['hook_extra']['plugin']) && is_string($options['hook_extra']['plugin']) ) {
|
177 |
+
$this->currentType = 'plugin';
|
178 |
+
$this->currentId = $options['hook_extra']['plugin'];
|
179 |
+
} else {
|
180 |
+
$this->currentType = null;
|
181 |
+
$this->currentId = null;
|
182 |
+
}
|
183 |
+
return $options;
|
184 |
+
}
|
185 |
+
|
186 |
+
/**
|
187 |
+
* @access private
|
188 |
+
*
|
189 |
+
* @param mixed $input
|
190 |
+
* @return mixed Returns $input unaltered.
|
191 |
+
*/
|
192 |
+
public function clearUpgradedThing($input = null) {
|
193 |
+
$this->currentId = null;
|
194 |
+
$this->currentType = null;
|
195 |
+
return $input;
|
196 |
+
}
|
197 |
+
}
|
198 |
+
|
199 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Utils.php
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if ( !class_exists('Puc_v4_Utils', false) ):
|
4 |
+
|
5 |
+
class Puc_v4_Utils {
|
6 |
+
/**
|
7 |
+
* Get a value from a nested array or object based on a path.
|
8 |
+
*
|
9 |
+
* @param array|object|null $collection Get an entry from this array.
|
10 |
+
* @param array|string $path A list of array keys in hierarchy order, or a string path like "foo.bar.baz".
|
11 |
+
* @param mixed $default The value to return if the specified path is not found.
|
12 |
+
* @param string $separator Path element separator. Only applies to string paths.
|
13 |
+
* @return mixed
|
14 |
+
*/
|
15 |
+
public static function get($collection, $path, $default = null, $separator = '.') {
|
16 |
+
if ( is_string($path) ) {
|
17 |
+
$path = explode($separator, $path);
|
18 |
+
}
|
19 |
+
if ( empty($path) ) {
|
20 |
+
return $default;
|
21 |
+
}
|
22 |
+
|
23 |
+
//Follow the $path into $input as far as possible.
|
24 |
+
$currentValue = $collection;
|
25 |
+
$pathExists = true;
|
26 |
+
foreach ($path as $node) {
|
27 |
+
if ( is_array($currentValue) && isset($currentValue[$node]) ) {
|
28 |
+
$currentValue = $currentValue[$node];
|
29 |
+
} else if ( is_object($currentValue) && isset($currentValue->$node) ) {
|
30 |
+
$currentValue = $currentValue->$node;
|
31 |
+
} else {
|
32 |
+
$pathExists = false;
|
33 |
+
break;
|
34 |
+
}
|
35 |
+
}
|
36 |
+
|
37 |
+
if ( $pathExists ) {
|
38 |
+
return $currentValue;
|
39 |
+
}
|
40 |
+
return $default;
|
41 |
+
}
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Get the first array element that is not empty.
|
45 |
+
*
|
46 |
+
* @param array $values
|
47 |
+
* @param mixed|null $default Returns this value if there are no non-empty elements.
|
48 |
+
* @return mixed|null
|
49 |
+
*/
|
50 |
+
public static function findNotEmpty($values, $default = null) {
|
51 |
+
if ( empty($values) ) {
|
52 |
+
return $default;
|
53 |
+
}
|
54 |
+
|
55 |
+
foreach ($values as $value) {
|
56 |
+
if ( !empty($value) ) {
|
57 |
+
return $value;
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
+
return $default;
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Check if the input string starts with the specified prefix.
|
66 |
+
*
|
67 |
+
* @param string $input
|
68 |
+
* @param string $prefix
|
69 |
+
* @return bool
|
70 |
+
*/
|
71 |
+
public static function startsWith($input, $prefix) {
|
72 |
+
$length = strlen($prefix);
|
73 |
+
return (substr($input, 0, $length) === $prefix);
|
74 |
+
}
|
75 |
+
}
|
76 |
+
|
77 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Vcs/Api.php
ADDED
@@ -0,0 +1,243 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( !class_exists('Puc_v4_Vcs_Api') ):
|
3 |
+
|
4 |
+
abstract class Puc_v4_Vcs_Api {
|
5 |
+
protected $tagNameProperty = 'name';
|
6 |
+
|
7 |
+
/**
|
8 |
+
* @var string
|
9 |
+
*/
|
10 |
+
protected $repositoryUrl = '';
|
11 |
+
|
12 |
+
/**
|
13 |
+
* @var mixed Authentication details for private repositories. Format depends on service.
|
14 |
+
*/
|
15 |
+
protected $credentials = null;
|
16 |
+
|
17 |
+
/**
|
18 |
+
* @var string The filter tag that's used to filter options passed to wp_remote_get.
|
19 |
+
* For example, "puc_request_info_options-slug" or "puc_request_update_options_theme-slug".
|
20 |
+
*/
|
21 |
+
protected $httpFilterName = '';
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Puc_v4_Vcs_Api constructor.
|
25 |
+
*
|
26 |
+
* @param string $repositoryUrl
|
27 |
+
* @param array|string|null $credentials
|
28 |
+
*/
|
29 |
+
public function __construct($repositoryUrl, $credentials = null) {
|
30 |
+
$this->repositoryUrl = $repositoryUrl;
|
31 |
+
$this->setAuthentication($credentials);
|
32 |
+
}
|
33 |
+
|
34 |
+
/**
|
35 |
+
* @return string
|
36 |
+
*/
|
37 |
+
public function getRepositoryUrl() {
|
38 |
+
return $this->repositoryUrl;
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Figure out which reference (i.e tag or branch) contains the latest version.
|
43 |
+
*
|
44 |
+
* @param string $configBranch Start looking in this branch.
|
45 |
+
* @return null|Puc_v4_Vcs_Reference
|
46 |
+
*/
|
47 |
+
abstract public function chooseReference($configBranch);
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Get the readme.txt file from the remote repository and parse it
|
51 |
+
* according to the plugin readme standard.
|
52 |
+
*
|
53 |
+
* @param string $ref Tag or branch name.
|
54 |
+
* @return array Parsed readme.
|
55 |
+
*/
|
56 |
+
public function getRemoteReadme($ref = 'master') {
|
57 |
+
$fileContents = $this->getRemoteFile('readme.txt', $ref);
|
58 |
+
if ( empty($fileContents) ) {
|
59 |
+
return array();
|
60 |
+
}
|
61 |
+
|
62 |
+
$parser = new PucReadmeParser();
|
63 |
+
return $parser->parse_readme_contents($fileContents);
|
64 |
+
}
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Get a branch.
|
68 |
+
*
|
69 |
+
* @param string $branchName
|
70 |
+
* @return Puc_v4_Vcs_Reference|null
|
71 |
+
*/
|
72 |
+
abstract public function getBranch($branchName);
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Get a specific tag.
|
76 |
+
*
|
77 |
+
* @param string $tagName
|
78 |
+
* @return Puc_v4_Vcs_Reference|null
|
79 |
+
*/
|
80 |
+
abstract public function getTag($tagName);
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Get the tag that looks like the highest version number.
|
84 |
+
* (Implementations should skip pre-release versions if possible.)
|
85 |
+
*
|
86 |
+
* @return Puc_v4_Vcs_Reference|null
|
87 |
+
*/
|
88 |
+
abstract public function getLatestTag();
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Check if a tag name string looks like a version number.
|
92 |
+
*
|
93 |
+
* @param string $name
|
94 |
+
* @return bool
|
95 |
+
*/
|
96 |
+
protected function looksLikeVersion($name) {
|
97 |
+
//Tag names may be prefixed with "v", e.g. "v1.2.3".
|
98 |
+
$name = ltrim($name, 'v');
|
99 |
+
|
100 |
+
//The version string must start with a number.
|
101 |
+
if ( !is_numeric(substr($name, 0, 1)) ) {
|
102 |
+
return false;
|
103 |
+
}
|
104 |
+
|
105 |
+
//The goal is to accept any SemVer-compatible or "PHP-standardized" version number.
|
106 |
+
return (preg_match('@^(\d{1,5}?)(\.\d{1,10}?){0,4}?($|[abrdp+_\-]|\s)@i', $name) === 1);
|
107 |
+
}
|
108 |
+
|
109 |
+
/**
|
110 |
+
* Check if a tag appears to be named like a version number.
|
111 |
+
*
|
112 |
+
* @param stdClass $tag
|
113 |
+
* @return bool
|
114 |
+
*/
|
115 |
+
protected function isVersionTag($tag) {
|
116 |
+
$property = $this->tagNameProperty;
|
117 |
+
return isset($tag->$property) && $this->looksLikeVersion($tag->$property);
|
118 |
+
}
|
119 |
+
|
120 |
+
/**
|
121 |
+
* Sort a list of tags as if they were version numbers.
|
122 |
+
* Tags that don't look like version number will be removed.
|
123 |
+
*
|
124 |
+
* @param stdClass[] $tags Array of tag objects.
|
125 |
+
* @return stdClass[] Filtered array of tags sorted in descending order.
|
126 |
+
*/
|
127 |
+
protected function sortTagsByVersion($tags) {
|
128 |
+
//Keep only those tags that look like version numbers.
|
129 |
+
$versionTags = array_filter($tags, array($this, 'isVersionTag'));
|
130 |
+
//Sort them in descending order.
|
131 |
+
usort($versionTags, array($this, 'compareTagNames'));
|
132 |
+
|
133 |
+
return $versionTags;
|
134 |
+
}
|
135 |
+
|
136 |
+
/**
|
137 |
+
* Compare two tags as if they were version number.
|
138 |
+
*
|
139 |
+
* @param stdClass $tag1 Tag object.
|
140 |
+
* @param stdClass $tag2 Another tag object.
|
141 |
+
* @return int
|
142 |
+
*/
|
143 |
+
protected function compareTagNames($tag1, $tag2) {
|
144 |
+
$property = $this->tagNameProperty;
|
145 |
+
if ( !isset($tag1->$property) ) {
|
146 |
+
return 1;
|
147 |
+
}
|
148 |
+
if ( !isset($tag2->$property) ) {
|
149 |
+
return -1;
|
150 |
+
}
|
151 |
+
return -version_compare(ltrim($tag1->$property, 'v'), ltrim($tag2->$property, 'v'));
|
152 |
+
}
|
153 |
+
|
154 |
+
/**
|
155 |
+
* Get the contents of a file from a specific branch or tag.
|
156 |
+
*
|
157 |
+
* @param string $path File name.
|
158 |
+
* @param string $ref
|
159 |
+
* @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error.
|
160 |
+
*/
|
161 |
+
abstract public function getRemoteFile($path, $ref = 'master');
|
162 |
+
|
163 |
+
/**
|
164 |
+
* Get the timestamp of the latest commit that changed the specified branch or tag.
|
165 |
+
*
|
166 |
+
* @param string $ref Reference name (e.g. branch or tag).
|
167 |
+
* @return string|null
|
168 |
+
*/
|
169 |
+
abstract public function getLatestCommitTime($ref);
|
170 |
+
|
171 |
+
/**
|
172 |
+
* Get the contents of the changelog file from the repository.
|
173 |
+
*
|
174 |
+
* @param string $ref
|
175 |
+
* @param string $localDirectory Full path to the local plugin or theme directory.
|
176 |
+
* @return null|string The HTML contents of the changelog.
|
177 |
+
*/
|
178 |
+
public function getRemoteChangelog($ref, $localDirectory) {
|
179 |
+
$filename = $this->findChangelogName($localDirectory);
|
180 |
+
if ( empty($filename) ) {
|
181 |
+
return null;
|
182 |
+
}
|
183 |
+
|
184 |
+
$changelog = $this->getRemoteFile($filename, $ref);
|
185 |
+
if ( $changelog === null ) {
|
186 |
+
return null;
|
187 |
+
}
|
188 |
+
|
189 |
+
/** @noinspection PhpUndefinedClassInspection */
|
190 |
+
return Parsedown::instance()->text($changelog);
|
191 |
+
}
|
192 |
+
|
193 |
+
/**
|
194 |
+
* Guess the name of the changelog file.
|
195 |
+
*
|
196 |
+
* @param string $directory
|
197 |
+
* @return string|null
|
198 |
+
*/
|
199 |
+
protected function findChangelogName($directory) {
|
200 |
+
if ( empty($directory) || !is_dir($directory) || ($directory === '.') ) {
|
201 |
+
return null;
|
202 |
+
}
|
203 |
+
|
204 |
+
$possibleNames = array('CHANGES.md', 'CHANGELOG.md', 'changes.md', 'changelog.md');
|
205 |
+
$files = scandir($directory);
|
206 |
+
$foundNames = array_intersect($possibleNames, $files);
|
207 |
+
|
208 |
+
if ( !empty($foundNames) ) {
|
209 |
+
return reset($foundNames);
|
210 |
+
}
|
211 |
+
return null;
|
212 |
+
}
|
213 |
+
|
214 |
+
/**
|
215 |
+
* Set authentication credentials.
|
216 |
+
*
|
217 |
+
* @param $credentials
|
218 |
+
*/
|
219 |
+
public function setAuthentication($credentials) {
|
220 |
+
$this->credentials = $credentials;
|
221 |
+
}
|
222 |
+
|
223 |
+
public function isAuthenticationEnabled() {
|
224 |
+
return !empty($this->credentials);
|
225 |
+
}
|
226 |
+
|
227 |
+
/**
|
228 |
+
* @param string $url
|
229 |
+
* @return string
|
230 |
+
*/
|
231 |
+
public function signDownloadUrl($url) {
|
232 |
+
return $url;
|
233 |
+
}
|
234 |
+
|
235 |
+
/**
|
236 |
+
* @param string $filterName
|
237 |
+
*/
|
238 |
+
public function setHttpFilterName($filterName) {
|
239 |
+
$this->httpFilterName = $filterName;
|
240 |
+
}
|
241 |
+
}
|
242 |
+
|
243 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Vcs/BaseChecker.php
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( !interface_exists('Puc_v4_Vcs_BaseChecker', false) ):
|
3 |
+
|
4 |
+
interface Puc_v4_Vcs_BaseChecker {
|
5 |
+
/**
|
6 |
+
* Set the repository branch to use for updates. Defaults to 'master'.
|
7 |
+
*
|
8 |
+
* @param string $branch
|
9 |
+
* @return $this
|
10 |
+
*/
|
11 |
+
public function setBranch($branch);
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Set authentication credentials.
|
15 |
+
*
|
16 |
+
* @param array|string $credentials
|
17 |
+
* @return $this
|
18 |
+
*/
|
19 |
+
public function setAuthentication($credentials);
|
20 |
+
}
|
21 |
+
|
22 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Vcs/BitBucketApi.php
ADDED
@@ -0,0 +1,253 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( !class_exists('Puc_v4_Vcs_BitBucketApi', false) ):
|
3 |
+
|
4 |
+
class Puc_v4_Vcs_BitBucketApi extends Puc_v4_Vcs_Api {
|
5 |
+
/**
|
6 |
+
* @var Puc_v4_OAuthSignature
|
7 |
+
*/
|
8 |
+
private $oauth = null;
|
9 |
+
|
10 |
+
/**
|
11 |
+
* @var string
|
12 |
+
*/
|
13 |
+
private $username;
|
14 |
+
|
15 |
+
/**
|
16 |
+
* @var string
|
17 |
+
*/
|
18 |
+
private $repository;
|
19 |
+
|
20 |
+
public function __construct($repositoryUrl, $credentials = array()) {
|
21 |
+
$path = @parse_url($repositoryUrl, PHP_URL_PATH);
|
22 |
+
if ( preg_match('@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches) ) {
|
23 |
+
$this->username = $matches['username'];
|
24 |
+
$this->repository = $matches['repository'];
|
25 |
+
} else {
|
26 |
+
throw new InvalidArgumentException('Invalid BitBucket repository URL: "' . $repositoryUrl . '"');
|
27 |
+
}
|
28 |
+
|
29 |
+
parent::__construct($repositoryUrl, $credentials);
|
30 |
+
}
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Figure out which reference (i.e tag or branch) contains the latest version.
|
34 |
+
*
|
35 |
+
* @param string $configBranch Start looking in this branch.
|
36 |
+
* @return null|Puc_v4_Vcs_Reference
|
37 |
+
*/
|
38 |
+
public function chooseReference($configBranch) {
|
39 |
+
$updateSource = null;
|
40 |
+
|
41 |
+
//Check if there's a "Stable tag: 1.2.3" header that points to a valid tag.
|
42 |
+
$updateSource = $this->getStableTag($configBranch);
|
43 |
+
|
44 |
+
//Look for version-like tags.
|
45 |
+
if ( !$updateSource && ($configBranch === 'master') ) {
|
46 |
+
$updateSource = $this->getLatestTag();
|
47 |
+
}
|
48 |
+
//If all else fails, use the specified branch itself.
|
49 |
+
if ( !$updateSource ) {
|
50 |
+
$updateSource = $this->getBranch($configBranch);
|
51 |
+
}
|
52 |
+
|
53 |
+
return $updateSource;
|
54 |
+
}
|
55 |
+
|
56 |
+
public function getBranch($branchName) {
|
57 |
+
$branch = $this->api('/refs/branches/' . $branchName);
|
58 |
+
if ( is_wp_error($branch) || empty($branch) ) {
|
59 |
+
return null;
|
60 |
+
}
|
61 |
+
|
62 |
+
return new Puc_v4_Vcs_Reference(array(
|
63 |
+
'name' => $branch->name,
|
64 |
+
'updated' => $branch->target->date,
|
65 |
+
'downloadUrl' => $this->getDownloadUrl($branch->name),
|
66 |
+
));
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Get a specific tag.
|
71 |
+
*
|
72 |
+
* @param string $tagName
|
73 |
+
* @return Puc_v4_Vcs_Reference|null
|
74 |
+
*/
|
75 |
+
public function getTag($tagName) {
|
76 |
+
$tag = $this->api('/refs/tags/' . $tagName);
|
77 |
+
if ( is_wp_error($tag) || empty($tag) ) {
|
78 |
+
return null;
|
79 |
+
}
|
80 |
+
|
81 |
+
return new Puc_v4_Vcs_Reference(array(
|
82 |
+
'name' => $tag->name,
|
83 |
+
'version' => ltrim($tag->name, 'v'),
|
84 |
+
'updated' => $tag->target->date,
|
85 |
+
'downloadUrl' => $this->getDownloadUrl($tag->name),
|
86 |
+
));
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* Get the tag that looks like the highest version number.
|
91 |
+
*
|
92 |
+
* @return Puc_v4_Vcs_Reference|null
|
93 |
+
*/
|
94 |
+
public function getLatestTag() {
|
95 |
+
$tags = $this->api('/refs/tags?sort=-target.date');
|
96 |
+
if ( !isset($tags, $tags->values) || !is_array($tags->values) ) {
|
97 |
+
return null;
|
98 |
+
}
|
99 |
+
|
100 |
+
//Filter and sort the list of tags.
|
101 |
+
$versionTags = $this->sortTagsByVersion($tags->values);
|
102 |
+
|
103 |
+
//Return the first result.
|
104 |
+
if ( !empty($versionTags) ) {
|
105 |
+
$tag = $versionTags[0];
|
106 |
+
return new Puc_v4_Vcs_Reference(array(
|
107 |
+
'name' => $tag->name,
|
108 |
+
'version' => ltrim($tag->name, 'v'),
|
109 |
+
'updated' => $tag->target->date,
|
110 |
+
'downloadUrl' => $this->getDownloadUrl($tag->name),
|
111 |
+
));
|
112 |
+
}
|
113 |
+
return null;
|
114 |
+
}
|
115 |
+
|
116 |
+
/**
|
117 |
+
* Get the tag/ref specified by the "Stable tag" header in the readme.txt of a given branch.
|
118 |
+
*
|
119 |
+
* @param string $branch
|
120 |
+
* @return null|Puc_v4_Vcs_Reference
|
121 |
+
*/
|
122 |
+
protected function getStableTag($branch) {
|
123 |
+
$remoteReadme = $this->getRemoteReadme($branch);
|
124 |
+
if ( !empty($remoteReadme['stable_tag']) ) {
|
125 |
+
$tag = $remoteReadme['stable_tag'];
|
126 |
+
|
127 |
+
//You can explicitly opt out of using tags by setting "Stable tag" to
|
128 |
+
//"trunk" or the name of the current branch.
|
129 |
+
if ( ($tag === $branch) || ($tag === 'trunk') ) {
|
130 |
+
return $this->getBranch($branch);
|
131 |
+
}
|
132 |
+
|
133 |
+
return $this->getTag($tag);
|
134 |
+
}
|
135 |
+
|
136 |
+
return null;
|
137 |
+
}
|
138 |
+
|
139 |
+
/**
|
140 |
+
* @param string $ref
|
141 |
+
* @return string
|
142 |
+
*/
|
143 |
+
protected function getDownloadUrl($ref) {
|
144 |
+
return sprintf(
|
145 |
+
'https://bitbucket.org/%s/%s/get/%s.zip',
|
146 |
+
$this->username,
|
147 |
+
$this->repository,
|
148 |
+
$ref
|
149 |
+
);
|
150 |
+
}
|
151 |
+
|
152 |
+
/**
|
153 |
+
* Get the contents of a file from a specific branch or tag.
|
154 |
+
*
|
155 |
+
* @param string $path File name.
|
156 |
+
* @param string $ref
|
157 |
+
* @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error.
|
158 |
+
*/
|
159 |
+
public function getRemoteFile($path, $ref = 'master') {
|
160 |
+
$response = $this->api('src/' . $ref . '/' . ltrim($path), '1.0');
|
161 |
+
if ( is_wp_error($response) || !isset($response, $response->data) ) {
|
162 |
+
return null;
|
163 |
+
}
|
164 |
+
return $response->data;
|
165 |
+
}
|
166 |
+
|
167 |
+
/**
|
168 |
+
* Get the timestamp of the latest commit that changed the specified branch or tag.
|
169 |
+
*
|
170 |
+
* @param string $ref Reference name (e.g. branch or tag).
|
171 |
+
* @return string|null
|
172 |
+
*/
|
173 |
+
public function getLatestCommitTime($ref) {
|
174 |
+
$response = $this->api('commits/' . $ref);
|
175 |
+
if ( isset($response->values, $response->values[0], $response->values[0]->date) ) {
|
176 |
+
return $response->values[0]->date;
|
177 |
+
}
|
178 |
+
return null;
|
179 |
+
}
|
180 |
+
|
181 |
+
/**
|
182 |
+
* Perform a BitBucket API 2.0 request.
|
183 |
+
*
|
184 |
+
* @param string $url
|
185 |
+
* @param string $version
|
186 |
+
* @return mixed|WP_Error
|
187 |
+
*/
|
188 |
+
public function api($url, $version = '2.0') {
|
189 |
+
//printf('Requesting %s<br>' . "\n", $url);
|
190 |
+
|
191 |
+
$url = implode('/', array(
|
192 |
+
'https://api.bitbucket.org',
|
193 |
+
$version,
|
194 |
+
'repositories',
|
195 |
+
$this->username,
|
196 |
+
$this->repository,
|
197 |
+
ltrim($url, '/')
|
198 |
+
));
|
199 |
+
|
200 |
+
if ( $this->oauth ) {
|
201 |
+
$url = $this->oauth->sign($url,'GET');
|
202 |
+
}
|
203 |
+
|
204 |
+
$options = array('timeout' => 10);
|
205 |
+
if ( !empty($this->httpFilterName) ) {
|
206 |
+
$options = apply_filters($this->httpFilterName, $options);
|
207 |
+
}
|
208 |
+
$response = wp_remote_get($url, $options);
|
209 |
+
if ( is_wp_error($response) ) {
|
210 |
+
return $response;
|
211 |
+
}
|
212 |
+
|
213 |
+
$code = wp_remote_retrieve_response_code($response);
|
214 |
+
$body = wp_remote_retrieve_body($response);
|
215 |
+
if ( $code === 200 ) {
|
216 |
+
$document = json_decode($body);
|
217 |
+
return $document;
|
218 |
+
}
|
219 |
+
|
220 |
+
return new WP_Error(
|
221 |
+
'puc-bitbucket-http-error',
|
222 |
+
'BitBucket API error. HTTP status: ' . $code
|
223 |
+
);
|
224 |
+
}
|
225 |
+
|
226 |
+
/**
|
227 |
+
* @param array $credentials
|
228 |
+
*/
|
229 |
+
public function setAuthentication($credentials) {
|
230 |
+
parent::setAuthentication($credentials);
|
231 |
+
|
232 |
+
if ( !empty($credentials) && !empty($credentials['consumer_key']) ) {
|
233 |
+
$this->oauth = new Puc_v4_OAuthSignature(
|
234 |
+
$credentials['consumer_key'],
|
235 |
+
$credentials['consumer_secret']
|
236 |
+
);
|
237 |
+
} else {
|
238 |
+
$this->oauth = null;
|
239 |
+
}
|
240 |
+
}
|
241 |
+
|
242 |
+
public function signDownloadUrl($url) {
|
243 |
+
//Add authentication data to download URLs. Since OAuth signatures incorporate
|
244 |
+
//timestamps, we have to do this immediately before inserting the update. Otherwise
|
245 |
+
//authentication could fail due to a stale timestamp.
|
246 |
+
if ( $this->oauth ) {
|
247 |
+
$url = $this->oauth->sign($url);
|
248 |
+
}
|
249 |
+
return $url;
|
250 |
+
}
|
251 |
+
}
|
252 |
+
|
253 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Vcs/GitHubApi.php
ADDED
@@ -0,0 +1,286 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if ( !class_exists('Puc_v4_Vcs_GitHubApi', false) ):
|
4 |
+
|
5 |
+
class Puc_v4_Vcs_GitHubApi extends Puc_v4_Vcs_Api {
|
6 |
+
/**
|
7 |
+
* @var string GitHub username.
|
8 |
+
*/
|
9 |
+
protected $userName;
|
10 |
+
/**
|
11 |
+
* @var string GitHub repository name.
|
12 |
+
*/
|
13 |
+
protected $repositoryName;
|
14 |
+
|
15 |
+
/**
|
16 |
+
* @var string Either a fully qualified repository URL, or just "user/repo-name".
|
17 |
+
*/
|
18 |
+
protected $repositoryUrl;
|
19 |
+
|
20 |
+
/**
|
21 |
+
* @var string GitHub authentication token. Optional.
|
22 |
+
*/
|
23 |
+
protected $accessToken;
|
24 |
+
|
25 |
+
public function __construct($repositoryUrl, $accessToken = null) {
|
26 |
+
$path = @parse_url($repositoryUrl, PHP_URL_PATH);
|
27 |
+
if ( preg_match('@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches) ) {
|
28 |
+
$this->userName = $matches['username'];
|
29 |
+
$this->repositoryName = $matches['repository'];
|
30 |
+
} else {
|
31 |
+
throw new InvalidArgumentException('Invalid GitHub repository URL: "' . $repositoryUrl . '"');
|
32 |
+
}
|
33 |
+
|
34 |
+
parent::__construct($repositoryUrl, $accessToken);
|
35 |
+
}
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Get the latest release from GitHub.
|
39 |
+
*
|
40 |
+
* @return Puc_v4_Vcs_Reference|null
|
41 |
+
*/
|
42 |
+
public function getLatestRelease() {
|
43 |
+
$release = $this->api('/repos/:user/:repo/releases/latest');
|
44 |
+
if ( is_wp_error($release) || !is_object($release) || !isset($release->tag_name) ) {
|
45 |
+
return null;
|
46 |
+
}
|
47 |
+
|
48 |
+
$reference = new Puc_v4_Vcs_Reference(array(
|
49 |
+
'name' => $release->tag_name,
|
50 |
+
'version' => ltrim($release->tag_name, 'v'), //Remove the "v" prefix from "v1.2.3".
|
51 |
+
'downloadUrl' => $this->signDownloadUrl($release->zipball_url),
|
52 |
+
'updated' => $release->created_at,
|
53 |
+
));
|
54 |
+
|
55 |
+
if ( !empty($release->body) ) {
|
56 |
+
/** @noinspection PhpUndefinedClassInspection */
|
57 |
+
$reference->changelog = Parsedown::instance()->text($release->body);
|
58 |
+
}
|
59 |
+
if ( isset($release->assets[0]) ) {
|
60 |
+
$reference->downloadCount = $release->assets[0]->download_count;
|
61 |
+
}
|
62 |
+
|
63 |
+
return $reference;
|
64 |
+
}
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Get the tag that looks like the highest version number.
|
68 |
+
*
|
69 |
+
* @return Puc_v4_Vcs_Reference|null
|
70 |
+
*/
|
71 |
+
public function getLatestTag() {
|
72 |
+
$tags = $this->api('/repos/:user/:repo/tags');
|
73 |
+
|
74 |
+
if ( is_wp_error($tags) || empty($tags) || !is_array($tags) ) {
|
75 |
+
return null;
|
76 |
+
}
|
77 |
+
|
78 |
+
$versionTags = $this->sortTagsByVersion($tags);
|
79 |
+
if ( empty($versionTags) ) {
|
80 |
+
return null;
|
81 |
+
}
|
82 |
+
|
83 |
+
$tag = $versionTags[0];
|
84 |
+
return new Puc_v4_Vcs_Reference(array(
|
85 |
+
'name' => $tag->name,
|
86 |
+
'version' => ltrim($tag->name, 'v'),
|
87 |
+
'downloadUrl' => $this->signDownloadUrl($tag->zipball_url),
|
88 |
+
));
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Get a branch by name.
|
93 |
+
*
|
94 |
+
* @param string $branchName
|
95 |
+
* @return null|Puc_v4_Vcs_Reference
|
96 |
+
*/
|
97 |
+
public function getBranch($branchName) {
|
98 |
+
$branch = $this->api('/repos/:user/:repo/branches/' . $branchName);
|
99 |
+
if ( is_wp_error($branch) || empty($branch) ) {
|
100 |
+
return null;
|
101 |
+
}
|
102 |
+
|
103 |
+
$reference = new Puc_v4_Vcs_Reference(array(
|
104 |
+
'name' => $branch->name,
|
105 |
+
'downloadUrl' => $this->buildArchiveDownloadUrl($branch->name),
|
106 |
+
));
|
107 |
+
|
108 |
+
if ( isset($branch->commit, $branch->commit->commit, $branch->commit->commit->author->date) ) {
|
109 |
+
$reference->updated = $branch->commit->commit->author->date;
|
110 |
+
}
|
111 |
+
|
112 |
+
return $reference;
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* Get the latest commit that changed the specified file.
|
117 |
+
*
|
118 |
+
* @param string $filename
|
119 |
+
* @param string $ref Reference name (e.g. branch or tag).
|
120 |
+
* @return StdClass|null
|
121 |
+
*/
|
122 |
+
public function getLatestCommit($filename, $ref = 'master') {
|
123 |
+
$commits = $this->api(
|
124 |
+
'/repos/:user/:repo/commits',
|
125 |
+
array(
|
126 |
+
'path' => $filename,
|
127 |
+
'sha' => $ref,
|
128 |
+
)
|
129 |
+
);
|
130 |
+
if ( !is_wp_error($commits) && is_array($commits) && isset($commits[0]) ) {
|
131 |
+
return $commits[0];
|
132 |
+
}
|
133 |
+
return null;
|
134 |
+
}
|
135 |
+
|
136 |
+
/**
|
137 |
+
* Get the timestamp of the latest commit that changed the specified branch or tag.
|
138 |
+
*
|
139 |
+
* @param string $ref Reference name (e.g. branch or tag).
|
140 |
+
* @return string|null
|
141 |
+
*/
|
142 |
+
public function getLatestCommitTime($ref) {
|
143 |
+
$commits = $this->api('/repos/:user/:repo/commits', array('sha' => $ref));
|
144 |
+
if ( !is_wp_error($commits) && is_array($commits) && isset($commits[0]) ) {
|
145 |
+
return $commits[0]->commit->author->date;
|
146 |
+
}
|
147 |
+
return null;
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* Perform a GitHub API request.
|
152 |
+
*
|
153 |
+
* @param string $url
|
154 |
+
* @param array $queryParams
|
155 |
+
* @return mixed|WP_Error
|
156 |
+
*/
|
157 |
+
protected function api($url, $queryParams = array()) {
|
158 |
+
$variables = array(
|
159 |
+
'user' => $this->userName,
|
160 |
+
'repo' => $this->repositoryName,
|
161 |
+
);
|
162 |
+
foreach ($variables as $name => $value) {
|
163 |
+
$url = str_replace('/:' . $name, '/' . urlencode($value), $url);
|
164 |
+
}
|
165 |
+
$url = 'https://api.github.com' . $url;
|
166 |
+
|
167 |
+
if ( !empty($this->accessToken) ) {
|
168 |
+
$queryParams['access_token'] = $this->accessToken;
|
169 |
+
}
|
170 |
+
if ( !empty($queryParams) ) {
|
171 |
+
$url = add_query_arg($queryParams, $url);
|
172 |
+
}
|
173 |
+
|
174 |
+
$options = array('timeout' => 10);
|
175 |
+
if ( !empty($this->httpFilterName) ) {
|
176 |
+
$options = apply_filters($this->httpFilterName, $options);
|
177 |
+
}
|
178 |
+
$response = wp_remote_get($url, $options);
|
179 |
+
if ( is_wp_error($response) ) {
|
180 |
+
return $response;
|
181 |
+
}
|
182 |
+
|
183 |
+
$code = wp_remote_retrieve_response_code($response);
|
184 |
+
$body = wp_remote_retrieve_body($response);
|
185 |
+
if ( $code === 200 ) {
|
186 |
+
$document = json_decode($body);
|
187 |
+
return $document;
|
188 |
+
}
|
189 |
+
|
190 |
+
return new WP_Error(
|
191 |
+
'puc-github-http-error',
|
192 |
+
'GitHub API error. HTTP status: ' . $code
|
193 |
+
);
|
194 |
+
}
|
195 |
+
|
196 |
+
/**
|
197 |
+
* Get the contents of a file from a specific branch or tag.
|
198 |
+
*
|
199 |
+
* @param string $path File name.
|
200 |
+
* @param string $ref
|
201 |
+
* @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error.
|
202 |
+
*/
|
203 |
+
public function getRemoteFile($path, $ref = 'master') {
|
204 |
+
$apiUrl = '/repos/:user/:repo/contents/' . $path;
|
205 |
+
$response = $this->api($apiUrl, array('ref' => $ref));
|
206 |
+
|
207 |
+
if ( is_wp_error($response) || !isset($response->content) || ($response->encoding !== 'base64') ) {
|
208 |
+
return null;
|
209 |
+
}
|
210 |
+
return base64_decode($response->content);
|
211 |
+
}
|
212 |
+
|
213 |
+
/**
|
214 |
+
* Generate a URL to download a ZIP archive of the specified branch/tag/etc.
|
215 |
+
*
|
216 |
+
* @param string $ref
|
217 |
+
* @return string
|
218 |
+
*/
|
219 |
+
public function buildArchiveDownloadUrl($ref = 'master') {
|
220 |
+
$url = sprintf(
|
221 |
+
'https://api.github.com/repos/%1$s/%2$s/zipball/%3$s',
|
222 |
+
urlencode($this->userName),
|
223 |
+
urlencode($this->repositoryName),
|
224 |
+
urlencode($ref)
|
225 |
+
);
|
226 |
+
if ( !empty($this->accessToken) ) {
|
227 |
+
$url = $this->signDownloadUrl($url);
|
228 |
+
}
|
229 |
+
return $url;
|
230 |
+
}
|
231 |
+
|
232 |
+
/**
|
233 |
+
* Get a specific tag.
|
234 |
+
*
|
235 |
+
* @param string $tagName
|
236 |
+
* @return Puc_v4_Vcs_Reference|null
|
237 |
+
*/
|
238 |
+
public function getTag($tagName) {
|
239 |
+
//The current GitHub update checker doesn't use getTag, so I didn't bother to implement it.
|
240 |
+
throw new LogicException('The ' . __METHOD__ . ' method is not implemented and should not be used.');
|
241 |
+
}
|
242 |
+
|
243 |
+
public function setAuthentication($credentials) {
|
244 |
+
parent::setAuthentication($credentials);
|
245 |
+
$this->accessToken = is_string($credentials) ? $credentials : null;
|
246 |
+
}
|
247 |
+
|
248 |
+
/**
|
249 |
+
* Figure out which reference (i.e tag or branch) contains the latest version.
|
250 |
+
*
|
251 |
+
* @param string $configBranch Start looking in this branch.
|
252 |
+
* @return null|Puc_v4_Vcs_Reference
|
253 |
+
*/
|
254 |
+
public function chooseReference($configBranch) {
|
255 |
+
$updateSource = null;
|
256 |
+
|
257 |
+
if ( $configBranch === 'master' ) {
|
258 |
+
//Use the latest release.
|
259 |
+
$updateSource = $this->getLatestRelease();
|
260 |
+
if ( $updateSource === null ) {
|
261 |
+
//Failing that, use the tag with the highest version number.
|
262 |
+
$updateSource = $this->getLatestTag();
|
263 |
+
}
|
264 |
+
}
|
265 |
+
//Alternatively, just use the branch itself.
|
266 |
+
if ( empty($updateSource) ) {
|
267 |
+
$updateSource = $this->getBranch($configBranch);
|
268 |
+
}
|
269 |
+
|
270 |
+
return $updateSource;
|
271 |
+
}
|
272 |
+
|
273 |
+
/**
|
274 |
+
* @param string $url
|
275 |
+
* @return string
|
276 |
+
*/
|
277 |
+
public function signDownloadUrl($url) {
|
278 |
+
if ( empty($this->credentials) ) {
|
279 |
+
return $url;
|
280 |
+
}
|
281 |
+
return add_query_arg('access_token', $this->credentials, $url);
|
282 |
+
}
|
283 |
+
|
284 |
+
}
|
285 |
+
|
286 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Vcs/PluginUpdateChecker.php
ADDED
@@ -0,0 +1,198 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( !class_exists('Puc_v4_Vcs_PluginUpdateChecker') ):
|
3 |
+
|
4 |
+
class Puc_v4_Vcs_PluginUpdateChecker extends Puc_v4_Plugin_UpdateChecker implements Puc_v4_Vcs_BaseChecker {
|
5 |
+
/**
|
6 |
+
* @var string The branch where to look for updates. Defaults to "master".
|
7 |
+
*/
|
8 |
+
protected $branch = 'master';
|
9 |
+
|
10 |
+
/**
|
11 |
+
* @var Puc_v4_Vcs_Api Repository API client.
|
12 |
+
*/
|
13 |
+
protected $api = null;
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Puc_v4_Vcs_PluginUpdateChecker constructor.
|
17 |
+
*
|
18 |
+
* @param Puc_v4_Vcs_Api $api
|
19 |
+
* @param string $pluginFile
|
20 |
+
* @param string $slug
|
21 |
+
* @param int $checkPeriod
|
22 |
+
* @param string $optionName
|
23 |
+
* @param string $muPluginFile
|
24 |
+
*/
|
25 |
+
public function __construct($api, $pluginFile, $slug = '', $checkPeriod = 12, $optionName = '', $muPluginFile = '') {
|
26 |
+
$this->api = $api;
|
27 |
+
$this->api->setHttpFilterName($this->getUniqueName('request_info_options'));
|
28 |
+
|
29 |
+
parent::__construct($api->getRepositoryUrl(), $pluginFile, $slug, $checkPeriod, $optionName, $muPluginFile);
|
30 |
+
}
|
31 |
+
|
32 |
+
public function requestInfo($unusedParameter = null) {
|
33 |
+
//We have to make several remote API requests to gather all the necessary info
|
34 |
+
//which can take a while on slow networks.
|
35 |
+
set_time_limit(60);
|
36 |
+
|
37 |
+
$api = $this->api;
|
38 |
+
|
39 |
+
$info = new Puc_v4_Plugin_Info();
|
40 |
+
$info->filename = $this->pluginFile;
|
41 |
+
$info->slug = $this->slug;
|
42 |
+
|
43 |
+
$this->setInfoFromHeader($this->getPluginHeader(), $info);
|
44 |
+
|
45 |
+
//Pick a branch or tag.
|
46 |
+
$updateSource = $api->chooseReference($this->branch);
|
47 |
+
if ( $updateSource ) {
|
48 |
+
$ref = $updateSource->name;
|
49 |
+
$info->version = $updateSource->version;
|
50 |
+
$info->last_updated = $updateSource->updated;
|
51 |
+
$info->download_url = $updateSource->downloadUrl;
|
52 |
+
|
53 |
+
if ( !empty($updateSource->changelog) ) {
|
54 |
+
$info->sections['changelog'] = $updateSource->changelog;
|
55 |
+
}
|
56 |
+
if ( isset($updateSource->downloadCount) ) {
|
57 |
+
$info->downloaded = $updateSource->downloadCount;
|
58 |
+
}
|
59 |
+
} else {
|
60 |
+
//There's probably a network problem or an authentication error.
|
61 |
+
return null;
|
62 |
+
}
|
63 |
+
|
64 |
+
//Get headers from the main plugin file in this branch/tag. Its "Version" header and other metadata
|
65 |
+
//are what the WordPress install will actually see after upgrading, so they take precedence over releases/tags.
|
66 |
+
$mainPluginFile = basename($this->pluginFile);
|
67 |
+
$remotePlugin = $api->getRemoteFile($mainPluginFile, $ref);
|
68 |
+
if ( !empty($remotePlugin) ) {
|
69 |
+
$remoteHeader = $this->getFileHeader($remotePlugin);
|
70 |
+
$this->setInfoFromHeader($remoteHeader, $info);
|
71 |
+
}
|
72 |
+
|
73 |
+
//Try parsing readme.txt. If it's formatted according to WordPress.org standards, it will contain
|
74 |
+
//a lot of useful information like the required/tested WP version, changelog, and so on.
|
75 |
+
if ( $this->readmeTxtExistsLocally() ) {
|
76 |
+
$this->setInfoFromRemoteReadme($ref, $info);
|
77 |
+
}
|
78 |
+
|
79 |
+
//The changelog might be in a separate file.
|
80 |
+
if ( empty($info->sections['changelog']) ) {
|
81 |
+
$info->sections['changelog'] = $api->getRemoteChangelog($ref, dirname($this->getAbsolutePath()));
|
82 |
+
if ( empty($info->sections['changelog']) ) {
|
83 |
+
$info->sections['changelog'] = __('There is no changelog available.', 'plugin-update-checker');
|
84 |
+
}
|
85 |
+
}
|
86 |
+
|
87 |
+
if ( empty($info->last_updated) ) {
|
88 |
+
//Fetch the latest commit that changed the tag or branch and use it as the "last_updated" date.
|
89 |
+
$latestCommitTime = $api->getLatestCommitTime($ref);
|
90 |
+
if ( $latestCommitTime !== null ) {
|
91 |
+
$info->last_updated = $latestCommitTime;
|
92 |
+
}
|
93 |
+
}
|
94 |
+
|
95 |
+
$info = apply_filters($this->getUniqueName('request_info_result'), $info, null);
|
96 |
+
return $info;
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Check if the currently installed version has a readme.txt file.
|
101 |
+
*
|
102 |
+
* @return bool
|
103 |
+
*/
|
104 |
+
protected function readmeTxtExistsLocally() {
|
105 |
+
$pluginDirectory = dirname($this->pluginAbsolutePath);
|
106 |
+
if ( empty($this->pluginAbsolutePath) || !is_dir($pluginDirectory) || ($pluginDirectory === '.') ) {
|
107 |
+
return false;
|
108 |
+
}
|
109 |
+
return is_file($pluginDirectory . '/readme.txt');
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Copy plugin metadata from a file header to a Plugin Info object.
|
114 |
+
*
|
115 |
+
* @param array $fileHeader
|
116 |
+
* @param Puc_v4_Plugin_Info $pluginInfo
|
117 |
+
*/
|
118 |
+
protected function setInfoFromHeader($fileHeader, $pluginInfo) {
|
119 |
+
$headerToPropertyMap = array(
|
120 |
+
'Version' => 'version',
|
121 |
+
'Name' => 'name',
|
122 |
+
'PluginURI' => 'homepage',
|
123 |
+
'Author' => 'author',
|
124 |
+
'AuthorName' => 'author',
|
125 |
+
'AuthorURI' => 'author_homepage',
|
126 |
+
|
127 |
+
'Requires WP' => 'requires',
|
128 |
+
'Tested WP' => 'tested',
|
129 |
+
'Requires at least' => 'requires',
|
130 |
+
'Tested up to' => 'tested',
|
131 |
+
);
|
132 |
+
foreach ($headerToPropertyMap as $headerName => $property) {
|
133 |
+
if ( isset($fileHeader[$headerName]) && !empty($fileHeader[$headerName]) ) {
|
134 |
+
$pluginInfo->$property = $fileHeader[$headerName];
|
135 |
+
}
|
136 |
+
}
|
137 |
+
|
138 |
+
if ( !empty($fileHeader['Description']) ) {
|
139 |
+
$pluginInfo->sections['description'] = $fileHeader['Description'];
|
140 |
+
}
|
141 |
+
}
|
142 |
+
|
143 |
+
/**
|
144 |
+
* Copy plugin metadata from the remote readme.txt file.
|
145 |
+
*
|
146 |
+
* @param string $ref GitHub tag or branch where to look for the readme.
|
147 |
+
* @param Puc_v4_Plugin_Info $pluginInfo
|
148 |
+
*/
|
149 |
+
protected function setInfoFromRemoteReadme($ref, $pluginInfo) {
|
150 |
+
$readme = $this->api->getRemoteReadme($ref);
|
151 |
+
if ( empty($readme) ) {
|
152 |
+
return;
|
153 |
+
}
|
154 |
+
|
155 |
+
if ( isset($readme['sections']) ) {
|
156 |
+
$pluginInfo->sections = array_merge($pluginInfo->sections, $readme['sections']);
|
157 |
+
}
|
158 |
+
if ( !empty($readme['tested_up_to']) ) {
|
159 |
+
$pluginInfo->tested = $readme['tested_up_to'];
|
160 |
+
}
|
161 |
+
if ( !empty($readme['requires_at_least']) ) {
|
162 |
+
$pluginInfo->requires = $readme['requires_at_least'];
|
163 |
+
}
|
164 |
+
|
165 |
+
if ( isset($readme['upgrade_notice'], $readme['upgrade_notice'][$pluginInfo->version]) ) {
|
166 |
+
$pluginInfo->upgrade_notice = $readme['upgrade_notice'][$pluginInfo->version];
|
167 |
+
}
|
168 |
+
}
|
169 |
+
|
170 |
+
public function setBranch($branch) {
|
171 |
+
$this->branch = $branch;
|
172 |
+
return $this;
|
173 |
+
}
|
174 |
+
|
175 |
+
public function setAuthentication($credentials) {
|
176 |
+
$this->api->setAuthentication($credentials);
|
177 |
+
return $this;
|
178 |
+
}
|
179 |
+
|
180 |
+
public function getUpdate() {
|
181 |
+
$update = parent::getUpdate();
|
182 |
+
|
183 |
+
if ( isset($update) && !empty($update->download_url) ) {
|
184 |
+
$update->download_url = $this->api->signDownloadUrl($update->download_url);
|
185 |
+
}
|
186 |
+
|
187 |
+
return $update;
|
188 |
+
}
|
189 |
+
|
190 |
+
public function onDisplayConfiguration($panel) {
|
191 |
+
parent::onDisplayConfiguration($panel);
|
192 |
+
$panel->row('Branch', $this->branch);
|
193 |
+
$panel->row('Authentication enabled', $this->api->isAuthenticationEnabled() ? 'Yes' : 'No');
|
194 |
+
$panel->row('API client', get_class($this->api));
|
195 |
+
}
|
196 |
+
}
|
197 |
+
|
198 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Vcs/Reference.php
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( !class_exists('Puc_v4_Vcs_Reference', false) ):
|
3 |
+
|
4 |
+
/**
|
5 |
+
* This class represents a VCS branch or tag. It's intended as a read only, short-lived container
|
6 |
+
* that only exists to provide a limited degree of type checking.
|
7 |
+
*
|
8 |
+
* @property string $name
|
9 |
+
* @property string|null version
|
10 |
+
* @property string $downloadUrl
|
11 |
+
* @property string $updated
|
12 |
+
*
|
13 |
+
* @property string|null $changelog
|
14 |
+
* @property int|null $downloadCount
|
15 |
+
*/
|
16 |
+
class Puc_v4_Vcs_Reference {
|
17 |
+
private $properties = array();
|
18 |
+
|
19 |
+
public function __construct($properties = array()) {
|
20 |
+
$this->properties = $properties;
|
21 |
+
}
|
22 |
+
|
23 |
+
/**
|
24 |
+
* @param string $name
|
25 |
+
* @return mixed|null
|
26 |
+
*/
|
27 |
+
function __get($name) {
|
28 |
+
return array_key_exists($name, $this->properties) ? $this->properties[$name] : null;
|
29 |
+
}
|
30 |
+
|
31 |
+
/**
|
32 |
+
* @param string $name
|
33 |
+
* @param mixed $value
|
34 |
+
*/
|
35 |
+
function __set($name, $value) {
|
36 |
+
$this->properties[$name] = $value;
|
37 |
+
}
|
38 |
+
|
39 |
+
/**
|
40 |
+
* @param string $name
|
41 |
+
* @return bool
|
42 |
+
*/
|
43 |
+
function __isset($name) {
|
44 |
+
return isset($this->properties[$name]);
|
45 |
+
}
|
46 |
+
|
47 |
+
}
|
48 |
+
|
49 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/Puc/v4/Vcs/ThemeUpdateChecker.php
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if ( !class_exists('Puc_v4_Vcs_ThemeUpdateChecker', false) ):
|
4 |
+
|
5 |
+
class Puc_v4_Vcs_ThemeUpdateChecker extends Puc_v4_Theme_UpdateChecker implements Puc_v4_Vcs_BaseChecker {
|
6 |
+
/**
|
7 |
+
* @var string The branch where to look for updates. Defaults to "master".
|
8 |
+
*/
|
9 |
+
protected $branch = 'master';
|
10 |
+
|
11 |
+
/**
|
12 |
+
* @var Puc_v4_Vcs_Api Repository API client.
|
13 |
+
*/
|
14 |
+
protected $api = null;
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Puc_v4_Vcs_ThemeUpdateChecker constructor.
|
18 |
+
*
|
19 |
+
* @param Puc_v4_Vcs_Api $api
|
20 |
+
* @param null $stylesheet
|
21 |
+
* @param null $customSlug
|
22 |
+
* @param int $checkPeriod
|
23 |
+
* @param string $optionName
|
24 |
+
*/
|
25 |
+
public function __construct($api, $stylesheet = null, $customSlug = null, $checkPeriod = 12, $optionName = '') {
|
26 |
+
$this->api = $api;
|
27 |
+
$this->api->setHttpFilterName($this->getUniqueName('request_update_options'));
|
28 |
+
|
29 |
+
parent::__construct($api->getRepositoryUrl(), $stylesheet, $customSlug, $checkPeriod, $optionName);
|
30 |
+
}
|
31 |
+
|
32 |
+
public function requestUpdate() {
|
33 |
+
$api = $this->api;
|
34 |
+
|
35 |
+
$update = new Puc_v4_Theme_Update();
|
36 |
+
$update->slug = $this->slug;
|
37 |
+
|
38 |
+
//Figure out which reference (tag or branch) we'll use to get the latest version of the theme.
|
39 |
+
$updateSource = $api->chooseReference($this->branch);
|
40 |
+
if ( $updateSource ) {
|
41 |
+
$ref = $updateSource->name;
|
42 |
+
$update->download_url = $updateSource->downloadUrl;
|
43 |
+
} else {
|
44 |
+
$ref = $this->branch;
|
45 |
+
}
|
46 |
+
|
47 |
+
//Get headers from the main stylesheet in this branch/tag. Its "Version" header and other metadata
|
48 |
+
//are what the WordPress install will actually see after upgrading, so they take precedence over releases/tags.
|
49 |
+
$remoteHeader = $this->getFileHeader($api->getRemoteFile('style.css', $ref));
|
50 |
+
$update->version = Puc_v4_Utils::findNotEmpty(array(
|
51 |
+
$remoteHeader['Version'],
|
52 |
+
Puc_v4_Utils::get($updateSource, 'version'),
|
53 |
+
));
|
54 |
+
|
55 |
+
//The details URL defaults to the Theme URI header or the repository URL.
|
56 |
+
$update->details_url = Puc_v4_Utils::findNotEmpty(array(
|
57 |
+
$remoteHeader['ThemeURI'],
|
58 |
+
$this->theme->get('ThemeURI'),
|
59 |
+
$this->metadataUrl,
|
60 |
+
));
|
61 |
+
|
62 |
+
if ( empty($update->version) ) {
|
63 |
+
//It looks like we didn't find a valid update after all.
|
64 |
+
$update = null;
|
65 |
+
}
|
66 |
+
|
67 |
+
$update = $this->filterUpdateResult($update);
|
68 |
+
return $update;
|
69 |
+
}
|
70 |
+
|
71 |
+
//FIXME: This is duplicated code. Both theme and plugin subclasses that use VCS share these methods.
|
72 |
+
|
73 |
+
public function setBranch($branch) {
|
74 |
+
$this->branch = $branch;
|
75 |
+
return $this;
|
76 |
+
}
|
77 |
+
|
78 |
+
public function setAuthentication($credentials) {
|
79 |
+
$this->api->setAuthentication($credentials);
|
80 |
+
return $this;
|
81 |
+
}
|
82 |
+
|
83 |
+
public function getUpdate() {
|
84 |
+
$update = parent::getUpdate();
|
85 |
+
|
86 |
+
if ( isset($update) && !empty($update->download_url) ) {
|
87 |
+
$update->download_url = $this->api->signDownloadUrl($update->download_url);
|
88 |
+
}
|
89 |
+
|
90 |
+
return $update;
|
91 |
+
}
|
92 |
+
|
93 |
+
public function onDisplayConfiguration($panel) {
|
94 |
+
parent::onDisplayConfiguration($panel);
|
95 |
+
$panel->row('Branch', $this->branch);
|
96 |
+
$panel->row('Authentication enabled', $this->api->isAuthenticationEnabled() ? 'Yes' : 'No');
|
97 |
+
$panel->row('API client', get_class($this->api));
|
98 |
+
}
|
99 |
+
}
|
100 |
+
|
101 |
+
endif;
|
vendor/yahnis-elsts/plugin-update-checker/README.md
ADDED
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Plugin Update Checker
|
2 |
+
=====================
|
3 |
+
|
4 |
+
This is a custom update checker library for WordPress plugins and themes. It lets you add automatic update notifications and one-click upgrades to your commercial plugins, private themes, and so on. All you need to do is put your plugin/theme details in a JSON file, place the file on your server, and pass the URL to the library. The library periodically checks the URL to see if there's a new version available and displays an update notification to the user if necessary.
|
5 |
+
|
6 |
+
From the users' perspective, it works just like with plugins and themes hosted on WordPress.org. The update checker uses the default upgrade UI that is familiar to most WordPress users.
|
7 |
+
|
8 |
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
9 |
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
10 |
+
**Table of Contents**
|
11 |
+
|
12 |
+
- [Getting Started](#getting-started)
|
13 |
+
- [Self-hosted Plugins and Themes](#self-hosted-plugins-and-themes)
|
14 |
+
- [How to Release an Update](#how-to-release-an-update)
|
15 |
+
- [Notes](#notes)
|
16 |
+
- [GitHub Integration](#github-integration)
|
17 |
+
- [How to Release an Update](#how-to-release-an-update-1)
|
18 |
+
- [Notes](#notes-1)
|
19 |
+
- [BitBucket Integration](#bitbucket-integration)
|
20 |
+
- [How to Release an Update](#how-to-release-an-update-2)
|
21 |
+
- [Resources](#resources)
|
22 |
+
|
23 |
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
24 |
+
|
25 |
+
Getting Started
|
26 |
+
---------------
|
27 |
+
|
28 |
+
### Self-hosted Plugins and Themes
|
29 |
+
|
30 |
+
1. Download [the latest release](https://github.com/YahnisElsts/plugin-update-checker/releases/latest) and copy the `plugin-update-checker` directory to your plugin or theme.
|
31 |
+
2. Go to the `examples` subdirectory and open the .json file that fits your project type. Replace the placeholder data with your plugin/theme details.
|
32 |
+
- Plugin example:
|
33 |
+
|
34 |
+
```json
|
35 |
+
{
|
36 |
+
"name" : "Plugin Name",
|
37 |
+
"version" : "2.0",
|
38 |
+
"download_url" : "http://example.com/plugin-name-2.0.zip",
|
39 |
+
"sections" : {
|
40 |
+
"description" : "Plugin description here. You can use HTML."
|
41 |
+
}
|
42 |
+
}
|
43 |
+
```
|
44 |
+
|
45 |
+
This is a minimal example that leaves out optional fields. See [this table](https://spreadsheets.google.com/pub?key=0AqP80E74YcUWdEdETXZLcXhjd2w0cHMwX2U1eDlWTHc&authkey=CK7h9toK&hl=en&single=true&gid=0&output=html) for a full list of supported fields and their descriptions.
|
46 |
+
- Theme example:
|
47 |
+
|
48 |
+
```json
|
49 |
+
{
|
50 |
+
"version": "2.0",
|
51 |
+
"details_url": "http://example.com/version-2.0-details.html",
|
52 |
+
"download_url": "http://example.com/example-theme-2.0.zip"
|
53 |
+
}
|
54 |
+
```
|
55 |
+
|
56 |
+
This is actually a complete example that shows all theme-related fields. `version` and `download_url` should be self-explanatory. The `details_url` key specifies the page that the user will see if they click the "View version 1.2.3 details" link in an update notification.
|
57 |
+
3. Upload the JSON file to a publicly accessible location.
|
58 |
+
4. Add the following code to the main plugin file or to the `functions.php` file:
|
59 |
+
|
60 |
+
```php
|
61 |
+
require 'path/to/plugin-update-checker/plugin-update-checker.php';
|
62 |
+
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
|
63 |
+
'http://example.com/path/to/details.json',
|
64 |
+
__FILE__,
|
65 |
+
'unique-plugin-or-theme-slug'
|
66 |
+
);
|
67 |
+
```
|
68 |
+
|
69 |
+
#### How to Release an Update
|
70 |
+
|
71 |
+
Change the `version` number in the JSON file and make sure that `download_url` points to the latest version. Update the other fields if necessary. Tip: You can use [wp-update-server](https://github.com/YahnisElsts/wp-update-server) to automate this process.
|
72 |
+
|
73 |
+
By default, the library will check the specified URL for changes every 12 hours. You can force it to check immediately by clicking the "Check Now" link on the "Plugins" page (it's next to the "Visit plugin site" link). Themes don't get a "check now" link, but you can also trigger an update check like this:
|
74 |
+
|
75 |
+
1. Install [Debug Bar](https://srd.wordpress.org/plugins/debug-bar/).
|
76 |
+
2. Click the "Debug" menu in the Admin Bar (a.k.a Toolbar).
|
77 |
+
3. Open the "PUC (your-slug)" panel.
|
78 |
+
4. Click the "Check Now" button.
|
79 |
+
|
80 |
+
#### Notes
|
81 |
+
- The second argument passed to `buildUpdateChecker` must be the absolute path to the main plugin file or any file in the theme directory. If you followed the "getting started" instructions, you can just use the `__FILE__` constant.
|
82 |
+
- The third argument - i.e. the slug - is optional but recommended. If it's omitted, the update checker will use the name of the main plugin file as the slug (e.g. `my-cool-plugin.php` → `my-cool-plugin`). This can lead to conflicts if your plugin has a generic file name like `plugin.php`.
|
83 |
+
|
84 |
+
This doesn't affect themes because PUC uses the theme directory name as the default slug. Still, if you're planning to use the slug in your own code - e.g. to filter updates or override update checker behaviour - it can be a good idea to set it explicitly.
|
85 |
+
|
86 |
+
### GitHub Integration
|
87 |
+
|
88 |
+
1. Download [the latest release](https://github.com/YahnisElsts/plugin-update-checker/releases/latest) and copy the `plugin-update-checker` directory to your plugin or theme.
|
89 |
+
2. Add the following code to the main plugin file or `functions.php`:
|
90 |
+
|
91 |
+
```php
|
92 |
+
require 'plugin-update-checker/plugin-update-checker.php';
|
93 |
+
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
|
94 |
+
'https://github.com/user-name/repo-name/',
|
95 |
+
__FILE__,
|
96 |
+
'unique-plugin-or-theme-slug'
|
97 |
+
);
|
98 |
+
|
99 |
+
//Optional: If you're using a private repository, specify the access token like this:
|
100 |
+
$myUpdateChecker->setAuthentication('your-token-here');
|
101 |
+
|
102 |
+
//Optional: Set the branch that contains the stable release.
|
103 |
+
$myUpdateChecker->setBranch('stable-branch-name');
|
104 |
+
```
|
105 |
+
3. Plugins only: Add a `readme.txt` file formatted according to the [WordPress.org plugin readme standard](https://wordpress.org/plugins/about/readme.txt) to your repository. The contents of this file will be shown when the user clicks the "View version 1.2.3 details" link.
|
106 |
+
|
107 |
+
#### How to Release an Update
|
108 |
+
|
109 |
+
This library supports a couple of different ways to release updates on GitHub. Pick the one that best fits your workflow.
|
110 |
+
|
111 |
+
- **GitHub releases**
|
112 |
+
|
113 |
+
Create a new release using the "Releases" feature on GitHub. The tag name and release title don't matter. The description is optional, but if you do provide one, it will be displayed when the user clicks the "View version x.y.z details" link on the "Plugins" page. Note that PUC ignores releases marked as "This is a pre-release".
|
114 |
+
|
115 |
+
- **Tags**
|
116 |
+
|
117 |
+
To release version 1.2.3, create a new Git tag named `v1.2.3` or `1.2.3`. That's it.
|
118 |
+
|
119 |
+
PUC doesn't require strict adherence to [SemVer](http://semver.org/). These are all valid tag names: `v1.2.3`, `v1.2-foo`, `1.2.3_rc1-ABC`, `1.2.3.4.5`. However, be warned that it's not smart enough to filter out alpha/beta/RC versions. If that's a problem, you might want to use GitHub releases or branches instead.
|
120 |
+
|
121 |
+
- **Stable branch**
|
122 |
+
|
123 |
+
Point the update checker at a stable, production-ready branch:
|
124 |
+
```php
|
125 |
+
$updateChecker->setBranch('branch-name');
|
126 |
+
```
|
127 |
+
PUC will periodically check the `Version` header in the main plugin file or `style.css` and display a notification if it's greater than the installed version.
|
128 |
+
|
129 |
+
Caveat: If you set the branch to `master` (the default), the update checker will look for recent releases and tags first. It'll only use the `master` branch if it doesn't find anything else suitable.
|
130 |
+
|
131 |
+
#### Notes
|
132 |
+
|
133 |
+
The library will pull update details from the following parts of a release/tag/branch:
|
134 |
+
|
135 |
+
- Version number
|
136 |
+
- The "Version" plugin header.
|
137 |
+
- The latest GitHub release or tag name.
|
138 |
+
- Changelog
|
139 |
+
- The "Changelog" section of `readme.txt`.
|
140 |
+
- One of the following files:
|
141 |
+
CHANGES.md, CHANGELOG.md, changes.md, changelog.md
|
142 |
+
- GitHub release notes.
|
143 |
+
- Required and tested WordPress versions
|
144 |
+
- The "Requires at least" and "Tested up to" fields in `readme.txt`.
|
145 |
+
- The following plugin headers:
|
146 |
+
`Required WP`, `Tested WP`, `Requires at least`, `Tested up to`
|
147 |
+
- "Last updated" timestamp
|
148 |
+
- The creation timestamp of the latest GitHub release.
|
149 |
+
- The latest commit in the selected tag or branch.
|
150 |
+
- Number of downloads
|
151 |
+
- The `download_count` statistic of the latest release.
|
152 |
+
- If you're not using GitHub releases, there will be no download stats.
|
153 |
+
- Other plugin details - author, homepage URL, description
|
154 |
+
- The "Description" section of `readme.txt`.
|
155 |
+
- Remote plugin headers (i.e. the latest version on GitHub).
|
156 |
+
- Local plugin headers (i.e. the currently installed version).
|
157 |
+
- Ratings, banners, screenshots
|
158 |
+
- Not supported.
|
159 |
+
|
160 |
+
### BitBucket Integration
|
161 |
+
|
162 |
+
1. Download [the latest release](https://github.com/YahnisElsts/plugin-update-checker/releases/latest) and copy the `plugin-update-checker` directory to your plugin or theme.
|
163 |
+
2. Add the following code to the main plugin file or `functions.php`:
|
164 |
+
|
165 |
+
```php
|
166 |
+
require 'plugin-update-checker/plugin-update-checker.php';
|
167 |
+
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
|
168 |
+
'https://bitbucket.org/user-name/repo-name',
|
169 |
+
__FILE__,
|
170 |
+
'unique-plugin-or-theme-slug'
|
171 |
+
);
|
172 |
+
|
173 |
+
//Optional: If you're using a private repository, create an OAuth consumer
|
174 |
+
//and set the authentication credentials like this:
|
175 |
+
$myUpdateChecker->setAuthentication(array(
|
176 |
+
'consumer_key' => '...',
|
177 |
+
'consumer_secret' => '...',
|
178 |
+
));
|
179 |
+
|
180 |
+
//Optional: Set the branch that contains the stable release.
|
181 |
+
$myUpdateChecker->setBranch('stable-branch-name');
|
182 |
+
```
|
183 |
+
3. Optional: Add a `readme.txt` file formatted according to the [WordPress.org plugin readme standard](https://wordpress.org/plugins/about/readme.txt) to your repository. For plugins, the contents of this file will be shown when the user clicks the "View version 1.2.3 details" link.
|
184 |
+
|
185 |
+
#### How to Release an Update
|
186 |
+
|
187 |
+
BitBucket doesn't have an equivalent to GitHub's releases, so the process is slightly different. You can use any of the following approaches:
|
188 |
+
|
189 |
+
- **`Stable tag` header**
|
190 |
+
|
191 |
+
This is the recommended approach if you're using tags to mark each version. Add a `readme.txt` file formatted according to the [WordPress.org plugin readme standard](https://wordpress.org/plugins/about/readme.txt) to your repository. Set the "stable tag" header to the tag that represents the latest release. Example:
|
192 |
+
```text
|
193 |
+
Stable tag: v1.2.3
|
194 |
+
```
|
195 |
+
The tag doesn't have to start with a "v" or follow any particular format. You can use any name you like as long as it's a valid Git tag.
|
196 |
+
|
197 |
+
Tip: If you explicitly set a stable branch, the update checker will look for a `readme.txt` in that branch. Otherwise it will only look at the `master` branch.
|
198 |
+
|
199 |
+
- **Tags**
|
200 |
+
|
201 |
+
You can skip the "stable tag" bit and just create a new Git tag named `v1.2.3` or `1.2.3`. The update checker will look at the most recent tags and pick the one that looks like the highest version number.
|
202 |
+
|
203 |
+
PUC doesn't require strict adherence to [SemVer](http://semver.org/). These are all valid tag names: `v1.2.3`, `v1.2-foo`, `1.2.3_rc1-ABC`, `1.2.3.4.5`. However, be warned that it's not smart enough to filter out alpha/beta/RC versions.
|
204 |
+
|
205 |
+
- **Stable branch**
|
206 |
+
|
207 |
+
Point the update checker at a stable, production-ready branch:
|
208 |
+
```php
|
209 |
+
$updateChecker->setBranch('branch-name');
|
210 |
+
```
|
211 |
+
PUC will periodically check the `Version` header in the main plugin file or `style.css` and display a notification if it's greater than the installed version. Caveat: If you set the branch to `master`, the update checker will still look for tags first.
|
212 |
+
|
213 |
+
Resources
|
214 |
+
---------
|
215 |
+
|
216 |
+
- [This blog post](http://w-shadow.com/blog/2010/09/02/automatic-updates-for-any-plugin/) has more information about the update checker API. *Slightly out of date.*
|
217 |
+
- [Debug Bar](https://wordpress.org/plugins/debug-bar/) - useful for testing and debugging the update checker.
|
218 |
+
- [Securing download links](http://w-shadow.com/blog/2013/03/19/plugin-updates-securing-download-links/) - a general overview.
|
219 |
+
- [A GUI for entering download credentials](http://open-tools.net/documentation/tutorial-automatic-updates.html#wordpress)
|
220 |
+
- [Theme Update Checker](http://w-shadow.com/blog/2011/06/02/automatic-updates-for-commercial-themes/) - an older, theme-only variant of this update checker.
|
vendor/yahnis-elsts/plugin-update-checker/composer.json
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "yahnis-elsts/plugin-update-checker",
|
3 |
+
"type": "library",
|
4 |
+
"description": "A custom update checker for WordPress plugins and themes. Useful if you can't host your plugin in the official WP repository but still want it to support automatic updates.",
|
5 |
+
"keywords": ["wordpress", "plugin updates", "automatic updates", "theme updates"],
|
6 |
+
"homepage": "https://github.com/YahnisElsts/plugin-update-checker/",
|
7 |
+
"license": "MIT",
|
8 |
+
"authors": [
|
9 |
+
{
|
10 |
+
"name": "Yahnis Elsts",
|
11 |
+
"email": "whiteshadow@w-shadow.com",
|
12 |
+
"homepage": "http://w-shadow.com/",
|
13 |
+
"role": "Developer"
|
14 |
+
}
|
15 |
+
],
|
16 |
+
"require": {
|
17 |
+
"php": ">=5.2.0"
|
18 |
+
}
|
19 |
+
}
|
vendor/yahnis-elsts/plugin-update-checker/css/puc-debug-bar.css
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.puc-debug-bar-panel-v4 pre {
|
2 |
+
margin-top: 0;
|
3 |
+
}
|
4 |
+
|
5 |
+
/* Style the debug data table to match "widefat" table style used by WordPress. */
|
6 |
+
table.puc-debug-data {
|
7 |
+
width: 100%;
|
8 |
+
clear: both;
|
9 |
+
margin: 0;
|
10 |
+
|
11 |
+
border-spacing: 0;
|
12 |
+
background-color: #f9f9f9;
|
13 |
+
|
14 |
+
border-radius: 3px;
|
15 |
+
border: 1px solid #dfdfdf;
|
16 |
+
border-collapse: separate;
|
17 |
+
}
|
18 |
+
|
19 |
+
table.puc-debug-data * {
|
20 |
+
word-wrap: break-word;
|
21 |
+
}
|
22 |
+
|
23 |
+
table.puc-debug-data th {
|
24 |
+
width: 11em;
|
25 |
+
padding: 7px 7px 8px;
|
26 |
+
text-align: left;
|
27 |
+
|
28 |
+
font-family: "Georgia", "Times New Roman", "Bitstream Charter", "Times", serif;
|
29 |
+
font-weight: 400;
|
30 |
+
font-size: 14px;
|
31 |
+
line-height: 1.3em;
|
32 |
+
text-shadow: rgba(255, 255, 255, 0.804) 0 1px 0;
|
33 |
+
}
|
34 |
+
|
35 |
+
table.puc-debug-data td, table.puc-debug-data th {
|
36 |
+
border-width: 1px 0;
|
37 |
+
border-style: solid;
|
38 |
+
|
39 |
+
border-top-color: #fff;
|
40 |
+
border-bottom-color: #dfdfdf;
|
41 |
+
|
42 |
+
text-transform: none;
|
43 |
+
}
|
44 |
+
|
45 |
+
table.puc-debug-data td {
|
46 |
+
color: #555;
|
47 |
+
font-size: 12px;
|
48 |
+
padding: 4px 7px 2px;
|
49 |
+
vertical-align: top;
|
50 |
+
}
|
51 |
+
|
52 |
+
.puc-ajax-response {
|
53 |
+
border: 1px solid #dfdfdf;
|
54 |
+
border-radius: 3px;
|
55 |
+
padding: 0.5em;
|
56 |
+
margin: 5px 0;
|
57 |
+
background-color: white;
|
58 |
+
}
|
59 |
+
|
60 |
+
.puc-ajax-nonce {
|
61 |
+
display: none;
|
62 |
+
}
|
vendor/yahnis-elsts/plugin-update-checker/examples/plugin.json
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "My Example Plugin",
|
3 |
+
"version": "2.0",
|
4 |
+
"download_url": "http://example.com/updates/example-plugin.zip",
|
5 |
+
|
6 |
+
"homepage": "http://example.com/",
|
7 |
+
"requires": "4.5",
|
8 |
+
"tested": "4.8",
|
9 |
+
"last_updated": "2017-01-01 16:17:00",
|
10 |
+
"upgrade_notice": "Here's why you should upgrade...",
|
11 |
+
|
12 |
+
"author": "Janis Elsts",
|
13 |
+
"author_homepage": "http://example.com/",
|
14 |
+
|
15 |
+
"sections": {
|
16 |
+
"description": "(Required) Plugin description. Basic HTML can be used in all sections.",
|
17 |
+
"installation": "(Recommended) Installation instructions.",
|
18 |
+
"changelog": "(Recommended) Changelog. <p>This section will be displayed by default when the user clicks 'View version x.y.z details'.</p>",
|
19 |
+
"custom_section": "This is a custom section labeled 'Custom Section'."
|
20 |
+
},
|
21 |
+
|
22 |
+
"banners": {
|
23 |
+
"low": "http://w-shadow.com/files/external-update-example/assets/banner-772x250.png",
|
24 |
+
"high": "http://w-shadow.com/files/external-update-example/assets/banner-1544x500.png"
|
25 |
+
},
|
26 |
+
|
27 |
+
"translations": [
|
28 |
+
{
|
29 |
+
"language": "fr_FR",
|
30 |
+
"version": "4.0",
|
31 |
+
"updated": "2016-04-22 23:22:42",
|
32 |
+
"package": "http://example.com/updates/translations/french-language-pack.zip"
|
33 |
+
},
|
34 |
+
{
|
35 |
+
"language": "de_DE",
|
36 |
+
"version": "5.0",
|
37 |
+
"updated": "2016-04-22 23:22:42",
|
38 |
+
"package": "http://example.com/updates/translations/german-language-pack.zip"
|
39 |
+
}
|
40 |
+
],
|
41 |
+
|
42 |
+
"rating": 90,
|
43 |
+
"num_ratings": 123,
|
44 |
+
|
45 |
+
"downloaded": 1234,
|
46 |
+
"active_installs": 12345
|
47 |
+
}
|
vendor/yahnis-elsts/plugin-update-checker/examples/theme.json
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"version": "2.0",
|
3 |
+
"details_url": "http://example.com/version-2.0-details.html",
|
4 |
+
"download_url": "http://example.com/example-theme-2.0.zip"
|
5 |
+
}
|
vendor/yahnis-elsts/plugin-update-checker/js/debug-bar.js
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
jQuery(function($) {
|
2 |
+
|
3 |
+
function runAjaxAction(button, action) {
|
4 |
+
button = $(button);
|
5 |
+
var panel = button.closest('.puc-debug-bar-panel-v4');
|
6 |
+
var responseBox = button.closest('td').find('.puc-ajax-response');
|
7 |
+
|
8 |
+
responseBox.text('Processing...').show();
|
9 |
+
$.post(
|
10 |
+
ajaxurl,
|
11 |
+
{
|
12 |
+
action : action,
|
13 |
+
uid : panel.data('uid'),
|
14 |
+
_wpnonce: panel.data('nonce')
|
15 |
+
},
|
16 |
+
function(data) {
|
17 |
+
responseBox.html(data);
|
18 |
+
},
|
19 |
+
'html'
|
20 |
+
);
|
21 |
+
}
|
22 |
+
|
23 |
+
$('.puc-debug-bar-panel-v4 input[name="puc-check-now-button"]').click(function() {
|
24 |
+
runAjaxAction(this, 'puc_v4_debug_check_now');
|
25 |
+
return false;
|
26 |
+
});
|
27 |
+
|
28 |
+
$('.puc-debug-bar-panel-v4 input[name="puc-request-info-button"]').click(function() {
|
29 |
+
runAjaxAction(this, 'puc_v4_debug_request_info');
|
30 |
+
return false;
|
31 |
+
});
|
32 |
+
|
33 |
+
|
34 |
+
// Debug Bar uses the panel class name as part of its link and container IDs. This means we can
|
35 |
+
// end up with multiple identical IDs if more than one plugin uses the update checker library.
|
36 |
+
// Fix it by replacing the class name with the plugin slug.
|
37 |
+
var panels = $('#debug-menu-targets').find('.puc-debug-bar-panel-v4');
|
38 |
+
panels.each(function() {
|
39 |
+
var panel = $(this);
|
40 |
+
var uid = panel.data('uid');
|
41 |
+
var target = panel.closest('.debug-menu-target');
|
42 |
+
|
43 |
+
//Change the panel wrapper ID.
|
44 |
+
target.attr('id', 'debug-menu-target-puc-' + uid);
|
45 |
+
|
46 |
+
//Change the menu link ID as well and point it at the new target ID.
|
47 |
+
$('#puc-debug-menu-link-' + uid)
|
48 |
+
.closest('.debug-menu-link')
|
49 |
+
.attr('id', 'debug-menu-link-puc-' + uid)
|
50 |
+
.attr('href', '#' + target.attr('id'));
|
51 |
+
});
|
52 |
+
});
|
vendor/yahnis-elsts/plugin-update-checker/languages/plugin-update-checker-de_DE.mo
ADDED
Binary file
|
vendor/yahnis-elsts/plugin-update-checker/languages/plugin-update-checker-de_DE.po
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
msgid ""
|
2 |
+
msgstr ""
|
3 |
+
"Project-Id-Version: plugin-update-checker\n"
|
4 |
+
"POT-Creation-Date: 2016-06-29 20:21+0100\n"
|
5 |
+
"PO-Revision-Date: 2016-06-29 20:23+0100\n"
|
6 |
+
"Last-Translator: Igor Lückel <info@igorlueckel.de>\n"
|
7 |
+
"Language-Team: \n"
|
8 |
+
"MIME-Version: 1.0\n"
|
9 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
+
"Content-Transfer-Encoding: 8bit\n"
|
11 |
+
"X-Generator: Poedit 1.8.1\n"
|
12 |
+
"X-Poedit-Basepath: ..\n"
|
13 |
+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
14 |
+
"X-Poedit-SourceCharset: UTF-8\n"
|
15 |
+
"X-Poedit-KeywordsList: __;_e\n"
|
16 |
+
"Language: de_DE\n"
|
17 |
+
"X-Poedit-SearchPath-0: .\n"
|
18 |
+
|
19 |
+
#: github-checker.php:137
|
20 |
+
msgid "There is no changelog available."
|
21 |
+
msgstr "Es ist keine Liste von Programmänderungen verfügbar."
|
22 |
+
|
23 |
+
#: plugin-update-checker.php:852
|
24 |
+
msgid "Check for updates"
|
25 |
+
msgstr "Nach Update suchen"
|
26 |
+
|
27 |
+
#: plugin-update-checker.php:896
|
28 |
+
msgid "This plugin is up to date."
|
29 |
+
msgstr "Das Plugin ist aktuell."
|
30 |
+
|
31 |
+
#: plugin-update-checker.php:898
|
32 |
+
msgid "A new version of this plugin is available."
|
33 |
+
msgstr "Es ist eine neue Version für das Plugin verfügbar."
|
34 |
+
|
35 |
+
#: plugin-update-checker.php:900
|
36 |
+
#, php-format
|
37 |
+
msgid "Unknown update checker status \"%s\""
|
38 |
+
msgstr "Unbekannter Update Status \"%s\""
|
vendor/yahnis-elsts/plugin-update-checker/languages/plugin-update-checker-fa_IR.mo
ADDED
Binary file
|
vendor/yahnis-elsts/plugin-update-checker/languages/plugin-update-checker-fa_IR.po
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
msgid ""
|
2 |
+
msgstr ""
|
3 |
+
"Project-Id-Version: plugin-update-checker\n"
|
4 |
+
"POT-Creation-Date: 2016-02-17 14:21+0100\n"
|
5 |
+
"PO-Revision-Date: 2016-10-28 14:30+0330\n"
|
6 |
+
"Last-Translator: studio RVOLA <hello@rvola.com>\n"
|
7 |
+
"Language-Team: Pro Style <info@prostyle.ir>\n"
|
8 |
+
"Language: fa_IR\n"
|
9 |
+
"MIME-Version: 1.0\n"
|
10 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
+
"Content-Transfer-Encoding: 8bit\n"
|
12 |
+
"X-Generator: Poedit 1.8.8\n"
|
13 |
+
"X-Poedit-Basepath: ..\n"
|
14 |
+
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
15 |
+
"X-Poedit-SourceCharset: UTF-8\n"
|
16 |
+
"X-Poedit-KeywordsList: __;_e\n"
|
17 |
+
"X-Poedit-SearchPath-0: .\n"
|
18 |
+
|
19 |
+
#: github-checker.php:120
|
20 |
+
msgid "There is no changelog available."
|
21 |
+
msgstr "شرحی برای تغییرات یافت نشد"
|
22 |
+
|
23 |
+
#: plugin-update-checker.php:637
|
24 |
+
msgid "Check for updates"
|
25 |
+
msgstr "بررسی برای بروزرسانی "
|
26 |
+
|
27 |
+
#: plugin-update-checker.php:681
|
28 |
+
msgid "This plugin is up to date."
|
29 |
+
msgstr "شما از آخرین نسخه استفاده میکنید . بهروز باشید"
|
30 |
+
|
31 |
+
#: plugin-update-checker.php:683
|
32 |
+
msgid "A new version of this plugin is available."
|
33 |
+
msgstr "نسخه جدیدی برای افزونه ارائه شده است ."
|
34 |
+
|
35 |
+
#: plugin-update-checker.php:685
|
36 |
+
#, php-format
|
37 |
+
msgid "Unknown update checker status \"%s\""
|
38 |
+
msgstr "وضعیت ناشناخته برای بروزرسانی \"%s\""
|
vendor/yahnis-elsts/plugin-update-checker/languages/plugin-update-checker-fr_FR.mo
ADDED
Binary file
|
vendor/yahnis-elsts/plugin-update-checker/languages/plugin-update-checker-fr_FR.po
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
msgid ""
|
2 |
+
msgstr ""
|
3 |
+
"Project-Id-Version: plugin-update-checker\n"
|
4 |
+
"POT-Creation-Date: 2016-02-17 14:21+0100\n"
|
5 |
+
"PO-Revision-Date: 2016-08-04 21:08+0200\n"
|
6 |
+
"Last-Translator: studio RVOLA <hello@rvola.com>\n"
|
7 |
+
"Language-Team: studio RVOLA <http://www.rvola.com>\n"
|
8 |
+
"Language: fr_FR\n"
|
9 |
+
"MIME-Version: 1.0\n"
|
10 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
+
"Content-Transfer-Encoding: 8bit\n"
|
12 |
+
"X-Generator: Poedit 1.8.8\n"
|
13 |
+
"X-Poedit-Basepath: ..\n"
|
14 |
+
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
15 |
+
"X-Poedit-SourceCharset: UTF-8\n"
|
16 |
+
"X-Poedit-KeywordsList: __;_e\n"
|
17 |
+
"X-Poedit-SearchPath-0: .\n"
|
18 |
+
|
19 |
+
#: github-checker.php:120
|
20 |
+
msgid "There is no changelog available."
|
21 |
+
msgstr "Il n’y a aucun journal de mise à jour disponible."
|
22 |
+
|
23 |
+
#: plugin-update-checker.php:637
|
24 |
+
msgid "Check for updates"
|
25 |
+
msgstr "Vérifier les mises à jour"
|
26 |
+
|
27 |
+
#: plugin-update-checker.php:681
|
28 |
+
msgid "This plugin is up to date."
|
29 |
+
msgstr "Cette extension est à jour."
|
30 |
+
|
31 |
+
#: plugin-update-checker.php:683
|
32 |
+
msgid "A new version of this plugin is available."
|
33 |
+
msgstr "Une nouvelle version de cette extension est disponible."
|
34 |
+
|
35 |
+
#: plugin-update-checker.php:685
|
36 |
+
#, php-format
|
37 |
+
msgid "Unknown update checker status \"%s\""
|
38 |
+
msgstr "Un problème inconnu est survenu \"%s\""
|
vendor/yahnis-elsts/plugin-update-checker/languages/plugin-update-checker-hu_HU.mo
ADDED
Binary file
|
vendor/yahnis-elsts/plugin-update-checker/languages/plugin-update-checker-hu_HU.po
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
msgid ""
|
2 |
+
msgstr ""
|
3 |
+
"Project-Id-Version: plugin-update-checker\n"
|
4 |
+
"POT-Creation-Date: 2016-01-11 21:23+0100\n"
|
5 |
+
"PO-Revision-Date: 2016-01-11 21:25+0100\n"
|
6 |
+
"Last-Translator: Tamás András Horváth <htomy92@gmail.com>\n"
|
7 |
+
"Language-Team: \n"
|
8 |
+
"Language: hu_HU\n"
|
9 |
+
"MIME-Version: 1.0\n"
|
10 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
+
"Content-Transfer-Encoding: 8bit\n"
|
12 |
+
"X-Generator: Poedit 1.8.6\n"
|
13 |
+
"X-Poedit-Basepath: ..\n"
|
14 |
+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
15 |
+
"X-Poedit-SourceCharset: UTF-8\n"
|
16 |
+
"X-Poedit-KeywordsList: __;_e\n"
|
17 |
+
"X-Poedit-SearchPath-0: .\n"
|
18 |
+
|
19 |
+
#: github-checker.php:137
|
20 |
+
msgid "There is no changelog available."
|
21 |
+
msgstr "Nem érhető el a changelog."
|
22 |
+
|
23 |
+
#: plugin-update-checker.php:852
|
24 |
+
msgid "Check for updates"
|
25 |
+
msgstr "Frissítés ellenőrzése"
|
26 |
+
|
27 |
+
#: plugin-update-checker.php:896
|
28 |
+
msgid "This plugin is up to date."
|
29 |
+
msgstr "Ez a plugin naprakész."
|
30 |
+
|
31 |
+
#: plugin-update-checker.php:898
|
32 |
+
msgid "A new version of this plugin is available."
|
33 |
+
msgstr "Új verzió érhető el a kiegészítőhöz"
|
34 |
+
|
35 |
+
#: plugin-update-checker.php:900
|
36 |
+
#, php-format
|
37 |
+
msgid "Unknown update checker status \"%s\""
|
38 |
+
msgstr "Ismeretlen a frissítés ellenőrző státusza \"%s\""
|
39 |
+
|
40 |
+
#~ msgid "Every %d hours"
|
41 |
+
#~ msgstr "Minden %d órában"
|
vendor/yahnis-elsts/plugin-update-checker/languages/plugin-update-checker-it_IT.mo
ADDED
Binary file
|
vendor/yahnis-elsts/plugin-update-checker/languages/plugin-update-checker-it_IT.po
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
msgid ""
|
2 |
+
msgstr ""
|
3 |
+
"Project-Id-Version: plugin-update-checker\n"
|
4 |
+
"POT-Creation-Date: 2016-06-29 20:21+0100\n"
|
5 |
+
"PO-Revision-Date: 2017-01-15 12:24+0100\n"
|
6 |
+
"Last-Translator: Igor Lückel <info@igorlueckel.de>\n"
|
7 |
+
"Language-Team: \n"
|
8 |
+
"MIME-Version: 1.0\n"
|
9 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
+
"Content-Transfer-Encoding: 8bit\n"
|
11 |
+
"X-Generator: Poedit 1.5.5\n"
|
12 |
+
"X-Poedit-Basepath: ..\n"
|
13 |
+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
14 |
+
"X-Poedit-SourceCharset: UTF-8\n"
|
15 |
+
"X-Poedit-KeywordsList: __;_e\n"
|
16 |
+
"Language: de_DE\n"
|
17 |
+
"X-Poedit-SearchPath-0: .\n"
|
18 |
+
|
19 |
+
#: github-checker.php:137
|
20 |
+
msgid "There is no changelog available."
|
21 |
+
msgstr "Non c'è alcuna sezione di aggiornamento disponibile"
|
22 |
+
|
23 |
+
#: plugin-update-checker.php:852
|
24 |
+
msgid "Check for updates"
|
25 |
+
msgstr "Verifica aggiornamenti"
|
26 |
+
|
27 |
+
#: plugin-update-checker.php:896
|
28 |
+
msgid "This plugin is up to date."
|
29 |
+
msgstr "Il plugin è aggiornato"
|
30 |
+
|
31 |
+
#: plugin-update-checker.php:898
|
32 |
+
msgid "A new version of this plugin is available."
|
33 |
+
msgstr "Una nuova versione del plugin è disponibile"
|
34 |
+
|
35 |
+
#: plugin-update-checker.php:900
|
36 |
+
#, php-format
|
37 |
+
msgid "Unknown update checker status \"%s\""
|
38 |
+
msgstr "Si è verificato un problema sconosciuto \"%s\""
|
vendor/yahnis-elsts/plugin-update-checker/languages/plugin-update-checker.pot
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#, fuzzy
|
2 |
+
msgid ""
|
3 |
+
msgstr ""
|
4 |
+
"Project-Id-Version: plugin-update-checker\n"
|
5 |
+
"POT-Creation-Date: 2016-01-11 21:22+0100\n"
|
6 |
+
"PO-Revision-Date: 2016-01-10 20:59+0100\n"
|
7 |
+
"Last-Translator: Tamás András Horváth <htomy92@gmail.com>\n"
|
8 |
+
"Language-Team: \n"
|
9 |
+
"Language: en_US\n"
|
10 |
+
"MIME-Version: 1.0\n"
|
11 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
12 |
+
"Content-Transfer-Encoding: 8bit\n"
|
13 |
+
"X-Generator: Poedit 1.8.6\n"
|
14 |
+
"X-Poedit-Basepath: ..\n"
|
15 |
+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
16 |
+
"X-Poedit-SourceCharset: UTF-8\n"
|
17 |
+
"X-Poedit-KeywordsList: __;_e\n"
|
18 |
+
"X-Poedit-SearchPath-0: .\n"
|
19 |
+
|
20 |
+
#: github-checker.php:137
|
21 |
+
msgid "There is no changelog available."
|
22 |
+
msgstr ""
|
23 |
+
|
24 |
+
#: plugin-update-checker.php:852
|
25 |
+
msgid "Check for updates"
|
26 |
+
msgstr ""
|
27 |
+
|
28 |
+
#: plugin-update-checker.php:896
|
29 |
+
msgid "This plugin is up to date."
|
30 |
+
msgstr ""
|
31 |
+
|
32 |
+
#: plugin-update-checker.php:898
|
33 |
+
msgid "A new version of this plugin is available."
|
34 |
+
msgstr ""
|
35 |
+
|
36 |
+
#: plugin-update-checker.php:900
|
37 |
+
#, php-format
|
38 |
+
msgid "Unknown update checker status \"%s\""
|
39 |
+
msgstr ""
|
vendor/yahnis-elsts/plugin-update-checker/license.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Copyright (c) 2014 Jānis Elsts
|
2 |
+
|
3 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4 |
+
|
5 |
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6 |
+
|
7 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
vendor/yahnis-elsts/plugin-update-checker/plugin-update-checker.php
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Plugin Update Checker Library 4.0.2
|
4 |
+
* http://w-shadow.com/
|
5 |
+
*
|
6 |
+
* Copyright 2017 Janis Elsts
|
7 |
+
* Released under the MIT license. See license.txt for details.
|
8 |
+
*/
|
9 |
+
|
10 |
+
require dirname(__FILE__) . '/Puc/v4/Autoloader.php';
|
11 |
+
new Puc_v4_Autoloader();
|
12 |
+
|
13 |
+
//Register classes defined in this file with the factory.
|
14 |
+
Puc_v4_Factory::addVersion('Plugin_UpdateChecker', 'Puc_v4_Plugin_UpdateChecker', '4.0');
|
15 |
+
Puc_v4_Factory::addVersion('Theme_UpdateChecker', 'Puc_v4_Theme_UpdateChecker', '4.0');
|
16 |
+
|
17 |
+
Puc_v4_Factory::addVersion('Vcs_PluginUpdateChecker', 'Puc_v4_Vcs_PluginUpdateChecker', '4.0');
|
18 |
+
Puc_v4_Factory::addVersion('Vcs_ThemeUpdateChecker', 'Puc_v4_Vcs_ThemeUpdateChecker', '4.0');
|
19 |
+
|
20 |
+
Puc_v4_Factory::addVersion('GitHubApi', 'Puc_v4_Vcs_GitHubApi', '4.0');
|
21 |
+
Puc_v4_Factory::addVersion('BitBucketApi', 'Puc_v4_Vcs_BitBucketApi', '4.0');
|
vendor/yahnis-elsts/plugin-update-checker/vendor/Parsedown.php
ADDED
@@ -0,0 +1,1538 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
#
|
4 |
+
#
|
5 |
+
# Parsedown
|
6 |
+
# http://parsedown.org
|
7 |
+
#
|
8 |
+
# (c) Emanuil Rusev
|
9 |
+
# http://erusev.com
|
10 |
+
#
|
11 |
+
# For the full license information, view the LICENSE file that was distributed
|
12 |
+
# with this source code.
|
13 |
+
#
|
14 |
+
#
|
15 |
+
|
16 |
+
class Parsedown
|
17 |
+
{
|
18 |
+
# ~
|
19 |
+
|
20 |
+
const version = '1.6.0';
|
21 |
+
|
22 |
+
# ~
|
23 |
+
|
24 |
+
function text($text)
|
25 |
+
{
|
26 |
+
# make sure no definitions are set
|
27 |
+
$this->DefinitionData = array();
|
28 |
+
|
29 |
+
# standardize line breaks
|
30 |
+
$text = str_replace(array("\r\n", "\r"), "\n", $text);
|
31 |
+
|
32 |
+
# remove surrounding line breaks
|
33 |
+
$text = trim($text, "\n");
|
34 |
+
|
35 |
+
# split text into lines
|
36 |
+
$lines = explode("\n", $text);
|
37 |
+
|
38 |
+
# iterate through lines to identify blocks
|
39 |
+
$markup = $this->lines($lines);
|
40 |
+
|
41 |
+
# trim line breaks
|
42 |
+
$markup = trim($markup, "\n");
|
43 |
+
|
44 |
+
return $markup;
|
45 |
+
}
|
46 |
+
|
47 |
+
#
|
48 |
+
# Setters
|
49 |
+
#
|
50 |
+
|
51 |
+
function setBreaksEnabled($breaksEnabled)
|
52 |
+
{
|
53 |
+
$this->breaksEnabled = $breaksEnabled;
|
54 |
+
|
55 |
+
return $this;
|
56 |
+
}
|
57 |
+
|
58 |
+
protected $breaksEnabled;
|
59 |
+
|
60 |
+
function setMarkupEscaped($markupEscaped)
|
61 |
+
{
|
62 |
+
$this->markupEscaped = $markupEscaped;
|
63 |
+
|
64 |
+
return $this;
|
65 |
+
}
|
66 |
+
|
67 |
+
protected $markupEscaped;
|
68 |
+
|
69 |
+
function setUrlsLinked($urlsLinked)
|
70 |
+
{
|
71 |
+
$this->urlsLinked = $urlsLinked;
|
72 |
+
|
73 |
+
return $this;
|
74 |
+
}
|
75 |
+
|
76 |
+
protected $urlsLinked = true;
|
77 |
+
|
78 |
+
#
|
79 |
+
# Lines
|
80 |
+
#
|
81 |
+
|
82 |
+
protected $BlockTypes = array(
|
83 |
+
'#' => array('Header'),
|
84 |
+
'*' => array('Rule', 'List'),
|
85 |
+
'+' => array('List'),
|
86 |
+
'-' => array('SetextHeader', 'Table', 'Rule', 'List'),
|
87 |
+
'0' => array('List'),
|
88 |
+
'1' => array('List'),
|
89 |
+
'2' => array('List'),
|
90 |
+
'3' => array('List'),
|
91 |
+
'4' => array('List'),
|
92 |
+
'5' => array('List'),
|
93 |
+
'6' => array('List'),
|
94 |
+
'7' => array('List'),
|
95 |
+
'8' => array('List'),
|
96 |
+
'9' => array('List'),
|
97 |
+
':' => array('Table'),
|
98 |
+
'<' => array('Comment', 'Markup'),
|
99 |
+
'=' => array('SetextHeader'),
|
100 |
+
'>' => array('Quote'),
|
101 |
+
'[' => array('Reference'),
|
102 |
+
'_' => array('Rule'),
|
103 |
+
'`' => array('FencedCode'),
|
104 |
+
'|' => array('Table'),
|
105 |
+
'~' => array('FencedCode'),
|
106 |
+
);
|
107 |
+
|
108 |
+
# ~
|
109 |
+
|
110 |
+
protected $unmarkedBlockTypes = array(
|
111 |
+
'Code',
|
112 |
+
);
|
113 |
+
|
114 |
+
#
|
115 |
+
# Blocks
|
116 |
+
#
|
117 |
+
|
118 |
+
protected function lines(array $lines)
|
119 |
+
{
|
120 |
+
$CurrentBlock = null;
|
121 |
+
|
122 |
+
foreach ($lines as $line)
|
123 |
+
{
|
124 |
+
if (chop($line) === '')
|
125 |
+
{
|
126 |
+
if (isset($CurrentBlock))
|
127 |
+
{
|
128 |
+
$CurrentBlock['interrupted'] = true;
|
129 |
+
}
|
130 |
+
|
131 |
+
continue;
|
132 |
+
}
|
133 |
+
|
134 |
+
if (strpos($line, "\t") !== false)
|
135 |
+
{
|
136 |
+
$parts = explode("\t", $line);
|
137 |
+
|
138 |
+
$line = $parts[0];
|
139 |
+
|
140 |
+
unset($parts[0]);
|
141 |
+
|
142 |
+
foreach ($parts as $part)
|
143 |
+
{
|
144 |
+
$shortage = 4 - mb_strlen($line, 'utf-8') % 4;
|
145 |
+
|
146 |
+
$line .= str_repeat(' ', $shortage);
|
147 |
+
$line .= $part;
|
148 |
+
}
|
149 |
+
}
|
150 |
+
|
151 |
+
$indent = 0;
|
152 |
+
|
153 |
+
while (isset($line[$indent]) and $line[$indent] === ' ')
|
154 |
+
{
|
155 |
+
$indent ++;
|
156 |
+
}
|
157 |
+
|
158 |
+
$text = $indent > 0 ? substr($line, $indent) : $line;
|
159 |
+
|
160 |
+
# ~
|
161 |
+
|
162 |
+
$Line = array('body' => $line, 'indent' => $indent, 'text' => $text);
|
163 |
+
|
164 |
+
# ~
|
165 |
+
|
166 |
+
if (isset($CurrentBlock['continuable']))
|
167 |
+
{
|
168 |
+
$Block = $this->{'block'.$CurrentBlock['type'].'Continue'}($Line, $CurrentBlock);
|
169 |
+
|
170 |
+
if (isset($Block))
|
171 |
+
{
|
172 |
+
$CurrentBlock = $Block;
|
173 |
+
|
174 |
+
continue;
|
175 |
+
}
|
176 |
+
else
|
177 |
+
{
|
178 |
+
if ($this->isBlockCompletable($CurrentBlock['type']))
|
179 |
+
{
|
180 |
+
$CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock);
|
181 |
+
}
|
182 |
+
}
|
183 |
+
}
|
184 |
+
|
185 |
+
# ~
|
186 |
+
|
187 |
+
$marker = $text[0];
|
188 |
+
|
189 |
+
# ~
|
190 |
+
|
191 |
+
$blockTypes = $this->unmarkedBlockTypes;
|
192 |
+
|
193 |
+
if (isset($this->BlockTypes[$marker]))
|
194 |
+
{
|
195 |
+
foreach ($this->BlockTypes[$marker] as $blockType)
|
196 |
+
{
|
197 |
+
$blockTypes []= $blockType;
|
198 |
+
}
|
199 |
+
}
|
200 |
+
|
201 |
+
#
|
202 |
+
# ~
|
203 |
+
|
204 |
+
foreach ($blockTypes as $blockType)
|
205 |
+
{
|
206 |
+
$Block = $this->{'block'.$blockType}($Line, $CurrentBlock);
|
207 |
+
|
208 |
+
if (isset($Block))
|
209 |
+
{
|
210 |
+
$Block['type'] = $blockType;
|
211 |
+
|
212 |
+
if ( ! isset($Block['identified']))
|
213 |
+
{
|
214 |
+
$Blocks []= $CurrentBlock;
|
215 |
+
|
216 |
+
$Block['identified'] = true;
|
217 |
+
}
|
218 |
+
|
219 |
+
if ($this->isBlockContinuable($blockType))
|
220 |
+
{
|
221 |
+
$Block['continuable'] = true;
|
222 |
+
}
|
223 |
+
|
224 |
+
$CurrentBlock = $Block;
|
225 |
+
|
226 |
+
continue 2;
|
227 |
+
}
|
228 |
+
}
|
229 |
+
|
230 |
+
# ~
|
231 |
+
|
232 |
+
if (isset($CurrentBlock) and ! isset($CurrentBlock['type']) and ! isset($CurrentBlock['interrupted']))
|
233 |
+
{
|
234 |
+
$CurrentBlock['element']['text'] .= "\n".$text;
|
235 |
+
}
|
236 |
+
else
|
237 |
+
{
|
238 |
+
$Blocks []= $CurrentBlock;
|
239 |
+
|
240 |
+
$CurrentBlock = $this->paragraph($Line);
|
241 |
+
|
242 |
+
$CurrentBlock['identified'] = true;
|
243 |
+
}
|
244 |
+
}
|
245 |
+
|
246 |
+
# ~
|
247 |
+
|
248 |
+
if (isset($CurrentBlock['continuable']) and $this->isBlockCompletable($CurrentBlock['type']))
|
249 |
+
{
|
250 |
+
$CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock);
|
251 |
+
}
|
252 |
+
|
253 |
+
# ~
|
254 |
+
|
255 |
+
$Blocks []= $CurrentBlock;
|
256 |
+
|
257 |
+
unset($Blocks[0]);
|
258 |
+
|
259 |
+
# ~
|
260 |
+
|
261 |
+
$markup = '';
|
262 |
+
|
263 |
+
foreach ($Blocks as $Block)
|
264 |
+
{
|
265 |
+
if (isset($Block['hidden']))
|
266 |
+
{
|
267 |
+
continue;
|
268 |
+
}
|
269 |
+
|
270 |
+
$markup .= "\n";
|
271 |
+
$markup .= isset($Block['markup']) ? $Block['markup'] : $this->element($Block['element']);
|
272 |
+
}
|
273 |
+
|
274 |
+
$markup .= "\n";
|
275 |
+
|
276 |
+
# ~
|
277 |
+
|
278 |
+
return $markup;
|
279 |
+
}
|
280 |
+
|
281 |
+
protected function isBlockContinuable($Type)
|
282 |
+
{
|
283 |
+
return method_exists($this, 'block'.$Type.'Continue');
|
284 |
+
}
|
285 |
+
|
286 |
+
protected function isBlockCompletable($Type)
|
287 |
+
{
|
288 |
+
return method_exists($this, 'block'.$Type.'Complete');
|
289 |
+
}
|
290 |
+
|
291 |
+
#
|
292 |
+
# Code
|
293 |
+
|
294 |
+
protected function blockCode($Line, $Block = null)
|
295 |
+
{
|
296 |
+
if (isset($Block) and ! isset($Block['type']) and ! isset($Block['interrupted']))
|
297 |
+
{
|
298 |
+
return;
|
299 |
+
}
|
300 |
+
|
301 |
+
if ($Line['indent'] >= 4)
|
302 |
+
{
|
303 |
+
$text = substr($Line['body'], 4);
|
304 |
+
|
305 |
+
$Block = array(
|
306 |
+
'element' => array(
|
307 |
+
'name' => 'pre',
|
308 |
+
'handler' => 'element',
|
309 |
+
'text' => array(
|
310 |
+
'name' => 'code',
|
311 |
+
'text' => $text,
|
312 |
+
),
|
313 |
+
),
|
314 |
+
);
|
315 |
+
|
316 |
+
return $Block;
|
317 |
+
}
|
318 |
+
}
|
319 |
+
|
320 |
+
protected function blockCodeContinue($Line, $Block)
|
321 |
+
{
|
322 |
+
if ($Line['indent'] >= 4)
|
323 |
+
{
|
324 |
+
if (isset($Block['interrupted']))
|
325 |
+
{
|
326 |
+
$Block['element']['text']['text'] .= "\n";
|
327 |
+
|
328 |
+
unset($Block['interrupted']);
|
329 |
+
}
|
330 |
+
|
331 |
+
$Block['element']['text']['text'] .= "\n";
|
332 |
+
|
333 |
+
$text = substr($Line['body'], 4);
|
334 |
+
|
335 |
+
$Block['element']['text']['text'] .= $text;
|
336 |
+
|
337 |
+
return $Block;
|
338 |
+
}
|
339 |
+
}
|
340 |
+
|
341 |
+
protected function blockCodeComplete($Block)
|
342 |
+
{
|
343 |
+
$text = $Block['element']['text']['text'];
|
344 |
+
|
345 |
+
$text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
|
346 |
+
|
347 |
+
$Block['element']['text']['text'] = $text;
|
348 |
+
|
349 |
+
return $Block;
|
350 |
+
}
|
351 |
+
|
352 |
+
#
|
353 |
+
# Comment
|
354 |
+
|
355 |
+
protected function blockComment($Line)
|
356 |
+
{
|
357 |
+
if ($this->markupEscaped)
|
358 |
+
{
|
359 |
+
return;
|
360 |
+
}
|
361 |
+
|
362 |
+
if (isset($Line['text'][3]) and $Line['text'][3] === '-' and $Line['text'][2] === '-' and $Line['text'][1] === '!')
|
363 |
+
{
|
364 |
+
$Block = array(
|
365 |
+
'markup' => $Line['body'],
|
366 |
+
);
|
367 |
+
|
368 |
+
if (preg_match('/-->$/', $Line['text']))
|
369 |
+
{
|
370 |
+
$Block['closed'] = true;
|
371 |
+
}
|
372 |
+
|
373 |
+
return $Block;
|
374 |
+
}
|
375 |
+
}
|
376 |
+
|
377 |
+
protected function blockCommentContinue($Line, array $Block)
|
378 |
+
{
|
379 |
+
if (isset($Block['closed']))
|
380 |
+
{
|
381 |
+
return;
|
382 |
+
}
|
383 |
+
|
384 |
+
$Block['markup'] .= "\n" . $Line['body'];
|
385 |
+
|
386 |
+
if (preg_match('/-->$/', $Line['text']))
|
387 |
+
{
|
388 |
+
$Block['closed'] = true;
|
389 |
+
}
|
390 |
+
|
391 |
+
return $Block;
|
392 |
+
}
|
393 |
+
|
394 |
+
#
|
395 |
+
# Fenced Code
|
396 |
+
|
397 |
+
protected function blockFencedCode($Line)
|
398 |
+
{
|
399 |
+
if (preg_match('/^['.$Line['text'][0].']{3,}[ ]*([\w-]+)?[ ]*$/', $Line['text'], $matches))
|
400 |
+
{
|
401 |
+
$Element = array(
|
402 |
+
'name' => 'code',
|
403 |
+
'text' => '',
|
404 |
+
);
|
405 |
+
|
406 |
+
if (isset($matches[1]))
|
407 |
+
{
|
408 |
+
$class = 'language-'.$matches[1];
|
409 |
+
|
410 |
+
$Element['attributes'] = array(
|
411 |
+
'class' => $class,
|
412 |
+
);
|
413 |
+
}
|
414 |
+
|
415 |
+
$Block = array(
|
416 |
+
'char' => $Line['text'][0],
|
417 |
+
'element' => array(
|
418 |
+
'name' => 'pre',
|
419 |
+
'handler' => 'element',
|
420 |
+
'text' => $Element,
|
421 |
+
),
|
422 |
+
);
|
423 |
+
|
424 |
+
return $Block;
|
425 |
+
}
|
426 |
+
}
|
427 |
+
|
428 |
+
protected function blockFencedCodeContinue($Line, $Block)
|
429 |
+
{
|
430 |
+
if (isset($Block['complete']))
|
431 |
+
{
|
432 |
+
return;
|
433 |
+
}
|
434 |
+
|
435 |
+
if (isset($Block['interrupted']))
|
436 |
+
{
|
437 |
+
$Block['element']['text']['text'] .= "\n";
|
438 |
+
|
439 |
+
unset($Block['interrupted']);
|
440 |
+
}
|
441 |
+
|
442 |
+
if (preg_match('/^'.$Block['char'].'{3,}[ ]*$/', $Line['text']))
|
443 |
+
{
|
444 |
+
$Block['element']['text']['text'] = substr($Block['element']['text']['text'], 1);
|
445 |
+
|
446 |
+
$Block['complete'] = true;
|
447 |
+
|
448 |
+
return $Block;
|
449 |
+
}
|
450 |
+
|
451 |
+
$Block['element']['text']['text'] .= "\n".$Line['body'];;
|
452 |
+
|
453 |
+
return $Block;
|
454 |
+
}
|
455 |
+
|
456 |
+
protected function blockFencedCodeComplete($Block)
|
457 |
+
{
|
458 |
+
$text = $Block['element']['text']['text'];
|
459 |
+
|
460 |
+
$text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
|
461 |
+
|
462 |
+
$Block['element']['text']['text'] = $text;
|
463 |
+
|
464 |
+
return $Block;
|
465 |
+
}
|
466 |
+
|
467 |
+
#
|
468 |
+
# Header
|
469 |
+
|
470 |
+
protected function blockHeader($Line)
|
471 |
+
{
|
472 |
+
if (isset($Line['text'][1]))
|
473 |
+
{
|
474 |
+
$level = 1;
|
475 |
+
|
476 |
+
while (isset($Line['text'][$level]) and $Line['text'][$level] === '#')
|
477 |
+
{
|
478 |
+
$level ++;
|
479 |
+
}
|
480 |
+
|
481 |
+
if ($level > 6)
|
482 |
+
{
|
483 |
+
return;
|
484 |
+
}
|
485 |
+
|
486 |
+
$text = trim($Line['text'], '# ');
|
487 |
+
|
488 |
+
$Block = array(
|
489 |
+
'element' => array(
|
490 |
+
'name' => 'h' . min(6, $level),
|
491 |
+
'text' => $text,
|
492 |
+
'handler' => 'line',
|
493 |
+
),
|
494 |
+
);
|
495 |
+
|
496 |
+
return $Block;
|
497 |
+
}
|
498 |
+
}
|
499 |
+
|
500 |
+
#
|
501 |
+
# List
|
502 |
+
|
503 |
+
protected function blockList($Line)
|
504 |
+
{
|
505 |
+
list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '[*+-]') : array('ol', '[0-9]+[.]');
|
506 |
+
|
507 |
+
if (preg_match('/^('.$pattern.'[ ]+)(.*)/', $Line['text'], $matches))
|
508 |
+
{
|
509 |
+
$Block = array(
|
510 |
+
'indent' => $Line['indent'],
|
511 |
+
'pattern' => $pattern,
|
512 |
+
'element' => array(
|
513 |
+
'name' => $name,
|
514 |
+
'handler' => 'elements',
|
515 |
+
),
|
516 |
+
);
|
517 |
+
|
518 |
+
$Block['li'] = array(
|
519 |
+
'name' => 'li',
|
520 |
+
'handler' => 'li',
|
521 |
+
'text' => array(
|
522 |
+
$matches[2],
|
523 |
+
),
|
524 |
+
);
|
525 |
+
|
526 |
+
$Block['element']['text'] []= & $Block['li'];
|
527 |
+
|
528 |
+
return $Block;
|
529 |
+
}
|
530 |
+
}
|
531 |
+
|
532 |
+
protected function blockListContinue($Line, array $Block)
|
533 |
+
{
|
534 |
+
if ($Block['indent'] === $Line['indent'] and preg_match('/^'.$Block['pattern'].'(?:[ ]+(.*)|$)/', $Line['text'], $matches))
|
535 |
+
{
|
536 |
+
if (isset($Block['interrupted']))
|
537 |
+
{
|
538 |
+
$Block['li']['text'] []= '';
|
539 |
+
|
540 |
+
unset($Block['interrupted']);
|
541 |
+
}
|
542 |
+
|
543 |
+
unset($Block['li']);
|
544 |
+
|
545 |
+
$text = isset($matches[1]) ? $matches[1] : '';
|
546 |
+
|
547 |
+
$Block['li'] = array(
|
548 |
+
'name' => 'li',
|
549 |
+
'handler' => 'li',
|
550 |
+
'text' => array(
|
551 |
+
$text,
|
552 |
+
),
|
553 |
+
);
|
554 |
+
|
555 |
+
$Block['element']['text'] []= & $Block['li'];
|
556 |
+
|
557 |
+
return $Block;
|
558 |
+
}
|
559 |
+
|
560 |
+
if ($Line['text'][0] === '[' and $this->blockReference($Line))
|
561 |
+
{
|
562 |
+
return $Block;
|
563 |
+
}
|
564 |
+
|
565 |
+
if ( ! isset($Block['interrupted']))
|
566 |
+
{
|
567 |
+
$text = preg_replace('/^[ ]{0,4}/', '', $Line['body']);
|
568 |
+
|
569 |
+
$Block['li']['text'] []= $text;
|
570 |
+
|
571 |
+
return $Block;
|
572 |
+
}
|
573 |
+
|
574 |
+
if ($Line['indent'] > 0)
|
575 |
+
{
|
576 |
+
$Block['li']['text'] []= '';
|
577 |
+
|
578 |
+
$text = preg_replace('/^[ ]{0,4}/', '', $Line['body']);
|
579 |
+
|
580 |
+
$Block['li']['text'] []= $text;
|
581 |
+
|
582 |
+
unset($Block['interrupted']);
|
583 |
+
|
584 |
+
return $Block;
|
585 |
+
}
|
586 |
+
}
|
587 |
+
|
588 |
+
#
|
589 |
+
# Quote
|
590 |
+
|
591 |
+
protected function blockQuote($Line)
|
592 |
+
{
|
593 |
+
if (preg_match('/^>[ ]?(.*)/', $Line['text'], $matches))
|
594 |
+
{
|
595 |
+
$Block = array(
|
596 |
+
'element' => array(
|
597 |
+
'name' => 'blockquote',
|
598 |
+
'handler' => 'lines',
|
599 |
+
'text' => (array) $matches[1],
|
600 |
+
),
|
601 |
+
);
|
602 |
+
|
603 |
+
return $Block;
|
604 |
+
}
|
605 |
+
}
|
606 |
+
|
607 |
+
protected function blockQuoteContinue($Line, array $Block)
|
608 |
+
{
|
609 |
+
if ($Line['text'][0] === '>' and preg_match('/^>[ ]?(.*)/', $Line['text'], $matches))
|
610 |
+
{
|
611 |
+
if (isset($Block['interrupted']))
|
612 |
+
{
|
613 |
+
$Block['element']['text'] []= '';
|
614 |
+
|
615 |
+
unset($Block['interrupted']);
|
616 |
+
}
|
617 |
+
|
618 |
+
$Block['element']['text'] []= $matches[1];
|
619 |
+
|
620 |
+
return $Block;
|
621 |
+
}
|
622 |
+
|
623 |
+
if ( ! isset($Block['interrupted']))
|
624 |
+
{
|
625 |
+
$Block['element']['text'] []= $Line['text'];
|
626 |
+
|
627 |
+
return $Block;
|
628 |
+
}
|
629 |
+
}
|
630 |
+
|
631 |
+
#
|
632 |
+
# Rule
|
633 |
+
|
634 |
+
protected function blockRule($Line)
|
635 |
+
{
|
636 |
+
if (preg_match('/^(['.$Line['text'][0].'])([ ]*\1){2,}[ ]*$/', $Line['text']))
|
637 |
+
{
|
638 |
+
$Block = array(
|
639 |
+
'element' => array(
|
640 |
+
'name' => 'hr'
|
641 |
+
),
|
642 |
+
);
|
643 |
+
|
644 |
+
return $Block;
|
645 |
+
}
|
646 |
+
}
|
647 |
+
|
648 |
+
#
|
649 |
+
# Setext
|
650 |
+
|
651 |
+
protected function blockSetextHeader($Line, array $Block = null)
|
652 |
+
{
|
653 |
+
if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted']))
|
654 |
+
{
|
655 |
+
return;
|
656 |
+
}
|
657 |
+
|
658 |
+
if (chop($Line['text'], $Line['text'][0]) === '')
|
659 |
+
{
|
660 |
+
$Block['element']['name'] = $Line['text'][0] === '=' ? 'h1' : 'h2';
|
661 |
+
|
662 |
+
return $Block;
|
663 |
+
}
|
664 |
+
}
|
665 |
+
|
666 |
+
#
|
667 |
+
# Markup
|
668 |
+
|
669 |
+
protected function blockMarkup($Line)
|
670 |
+
{
|
671 |
+
if ($this->markupEscaped)
|
672 |
+
{
|
673 |
+
return;
|
674 |
+
}
|
675 |
+
|
676 |
+
if (preg_match('/^<(\w*)(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*(\/)?>/', $Line['text'], $matches))
|
677 |
+
{
|
678 |
+
$element = strtolower($matches[1]);
|
679 |
+
|
680 |
+
if (in_array($element, $this->textLevelElements))
|
681 |
+
{
|
682 |
+
return;
|
683 |
+
}
|
684 |
+
|
685 |
+
$Block = array(
|
686 |
+
'name' => $matches[1],
|
687 |
+
'depth' => 0,
|
688 |
+
'markup' => $Line['text'],
|
689 |
+
);
|
690 |
+
|
691 |
+
$length = strlen($matches[0]);
|
692 |
+
|
693 |
+
$remainder = substr($Line['text'], $length);
|
694 |
+
|
695 |
+
if (trim($remainder) === '')
|
696 |
+
{
|
697 |
+
if (isset($matches[2]) or in_array($matches[1], $this->voidElements))
|
698 |
+
{
|
699 |
+
$Block['closed'] = true;
|
700 |
+
|
701 |
+
$Block['void'] = true;
|
702 |
+
}
|
703 |
+
}
|
704 |
+
else
|
705 |
+
{
|
706 |
+
if (isset($matches[2]) or in_array($matches[1], $this->voidElements))
|
707 |
+
{
|
708 |
+
return;
|
709 |
+
}
|
710 |
+
|
711 |
+
if (preg_match('/<\/'.$matches[1].'>[ ]*$/i', $remainder))
|
712 |
+
{
|
713 |
+
$Block['closed'] = true;
|
714 |
+
}
|
715 |
+
}
|
716 |
+
|
717 |
+
return $Block;
|
718 |
+
}
|
719 |
+
}
|
720 |
+
|
721 |
+
protected function blockMarkupContinue($Line, array $Block)
|
722 |
+
{
|
723 |
+
if (isset($Block['closed']))
|
724 |
+
{
|
725 |
+
return;
|
726 |
+
}
|
727 |
+
|
728 |
+
if (preg_match('/^<'.$Block['name'].'(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*>/i', $Line['text'])) # open
|
729 |
+
{
|
730 |
+
$Block['depth'] ++;
|
731 |
+
}
|
732 |
+
|
733 |
+
if (preg_match('/(.*?)<\/'.$Block['name'].'>[ ]*$/i', $Line['text'], $matches)) # close
|
734 |
+
{
|
735 |
+
if ($Block['depth'] > 0)
|
736 |
+
{
|
737 |
+
$Block['depth'] --;
|
738 |
+
}
|
739 |
+
else
|
740 |
+
{
|
741 |
+
$Block['closed'] = true;
|
742 |
+
}
|
743 |
+
}
|
744 |
+
|
745 |
+
if (isset($Block['interrupted']))
|
746 |
+
{
|
747 |
+
$Block['markup'] .= "\n";
|
748 |
+
|
749 |
+
unset($Block['interrupted']);
|
750 |
+
}
|
751 |
+
|
752 |
+
$Block['markup'] .= "\n".$Line['body'];
|
753 |
+
|
754 |
+
return $Block;
|
755 |
+
}
|
756 |
+
|
757 |
+
#
|
758 |
+
# Reference
|
759 |
+
|
760 |
+
protected function blockReference($Line)
|
761 |
+
{
|
762 |
+
if (preg_match('/^\[(.+?)\]:[ ]*<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*$/', $Line['text'], $matches))
|
763 |
+
{
|
764 |
+
$id = strtolower($matches[1]);
|
765 |
+
|
766 |
+
$Data = array(
|
767 |
+
'url' => $matches[2],
|
768 |
+
'title' => null,
|
769 |
+
);
|
770 |
+
|
771 |
+
if (isset($matches[3]))
|
772 |
+
{
|
773 |
+
$Data['title'] = $matches[3];
|
774 |
+
}
|
775 |
+
|
776 |
+
$this->DefinitionData['Reference'][$id] = $Data;
|
777 |
+
|
778 |
+
$Block = array(
|
779 |
+
'hidden' => true,
|
780 |
+
);
|
781 |
+
|
782 |
+
return $Block;
|
783 |
+
}
|
784 |
+
}
|
785 |
+
|
786 |
+
#
|
787 |
+
# Table
|
788 |
+
|
789 |
+
protected function blockTable($Line, array $Block = null)
|
790 |
+
{
|
791 |
+
if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted']))
|
792 |
+
{
|
793 |
+
return;
|
794 |
+
}
|
795 |
+
|
796 |
+
if (strpos($Block['element']['text'], '|') !== false and chop($Line['text'], ' -:|') === '')
|
797 |
+
{
|
798 |
+
$alignments = array();
|
799 |
+
|
800 |
+
$divider = $Line['text'];
|
801 |
+
|
802 |
+
$divider = trim($divider);
|
803 |
+
$divider = trim($divider, '|');
|
804 |
+
|
805 |
+
$dividerCells = explode('|', $divider);
|
806 |
+
|
807 |
+
foreach ($dividerCells as $dividerCell)
|
808 |
+
{
|
809 |
+
$dividerCell = trim($dividerCell);
|
810 |
+
|
811 |
+
if ($dividerCell === '')
|
812 |
+
{
|
813 |
+
continue;
|
814 |
+
}
|
815 |
+
|
816 |
+
$alignment = null;
|
817 |
+
|
818 |
+
if ($dividerCell[0] === ':')
|
819 |
+
{
|
820 |
+
$alignment = 'left';
|
821 |
+
}
|
822 |
+
|
823 |
+
if (substr($dividerCell, - 1) === ':')
|
824 |
+
{
|
825 |
+
$alignment = $alignment === 'left' ? 'center' : 'right';
|
826 |
+
}
|
827 |
+
|
828 |
+
$alignments []= $alignment;
|
829 |
+
}
|
830 |
+
|
831 |
+
# ~
|
832 |
+
|
833 |
+
$HeaderElements = array();
|
834 |
+
|
835 |
+
$header = $Block['element']['text'];
|
836 |
+
|
837 |
+
$header = trim($header);
|
838 |
+
$header = trim($header, '|');
|
839 |
+
|
840 |
+
$headerCells = explode('|', $header);
|
841 |
+
|
842 |
+
foreach ($headerCells as $index => $headerCell)
|
843 |
+
{
|
844 |
+
$headerCell = trim($headerCell);
|
845 |
+
|
846 |
+
$HeaderElement = array(
|
847 |
+
'name' => 'th',
|
848 |
+
'text' => $headerCell,
|
849 |
+
'handler' => 'line',
|
850 |
+
);
|
851 |
+
|
852 |
+
if (isset($alignments[$index]))
|
853 |
+
{
|
854 |
+
$alignment = $alignments[$index];
|
855 |
+
|
856 |
+
$HeaderElement['attributes'] = array(
|
857 |
+
'style' => 'text-align: '.$alignment.';',
|
858 |
+
);
|
859 |
+
}
|
860 |
+
|
861 |
+
$HeaderElements []= $HeaderElement;
|
862 |
+
}
|
863 |
+
|
864 |
+
# ~
|
865 |
+
|
866 |
+
$Block = array(
|
867 |
+
'alignments' => $alignments,
|
868 |
+
'identified' => true,
|
869 |
+
'element' => array(
|
870 |
+
'name' => 'table',
|
871 |
+
'handler' => 'elements',
|
872 |
+
),
|
873 |
+
);
|
874 |
+
|
875 |
+
$Block['element']['text'] []= array(
|
876 |
+
'name' => 'thead',
|
877 |
+
'handler' => 'elements',
|
878 |
+
);
|
879 |
+
|
880 |
+
$Block['element']['text'] []= array(
|
881 |
+
'name' => 'tbody',
|
882 |
+
'handler' => 'elements',
|
883 |
+
'text' => array(),
|
884 |
+
);
|
885 |
+
|
886 |
+
$Block['element']['text'][0]['text'] []= array(
|
887 |
+
'name' => 'tr',
|
888 |
+
'handler' => 'elements',
|
889 |
+
'text' => $HeaderElements,
|
890 |
+
);
|
891 |
+
|
892 |
+
return $Block;
|
893 |
+
}
|
894 |
+
}
|
895 |
+
|
896 |
+
protected function blockTableContinue($Line, array $Block)
|
897 |
+
{
|
898 |
+
if (isset($Block['interrupted']))
|
899 |
+
{
|
900 |
+
return;
|
901 |
+
}
|
902 |
+
|
903 |
+
if ($Line['text'][0] === '|' or strpos($Line['text'], '|'))
|
904 |
+
{
|
905 |
+
$Elements = array();
|
906 |
+
|
907 |
+
$row = $Line['text'];
|
908 |
+
|
909 |
+
$row = trim($row);
|
910 |
+
$row = trim($row, '|');
|
911 |
+
|
912 |
+
preg_match_all('/(?:(\\\\[|])|[^|`]|`[^`]+`|`)+/', $row, $matches);
|
913 |
+
|
914 |
+
foreach ($matches[0] as $index => $cell)
|
915 |
+
{
|
916 |
+
$cell = trim($cell);
|
917 |
+
|
918 |
+
$Element = array(
|
919 |
+
'name' => 'td',
|
920 |
+
'handler' => 'line',
|
921 |
+
'text' => $cell,
|
922 |
+
);
|
923 |
+
|
924 |
+
if (isset($Block['alignments'][$index]))
|
925 |
+
{
|
926 |
+
$Element['attributes'] = array(
|
927 |
+
'style' => 'text-align: '.$Block['alignments'][$index].';',
|
928 |
+
);
|
929 |
+
}
|
930 |
+
|
931 |
+
$Elements []= $Element;
|
932 |
+
}
|
933 |
+
|
934 |
+
$Element = array(
|
935 |
+
'name' => 'tr',
|
936 |
+
'handler' => 'elements',
|
937 |
+
'text' => $Elements,
|
938 |
+
);
|
939 |
+
|
940 |
+
$Block['element']['text'][1]['text'] []= $Element;
|
941 |
+
|
942 |
+
return $Block;
|
943 |
+
}
|
944 |
+
}
|
945 |
+
|
946 |
+
#
|
947 |
+
# ~
|
948 |
+
#
|
949 |
+
|
950 |
+
protected function paragraph($Line)
|
951 |
+
{
|
952 |
+
$Block = array(
|
953 |
+
'element' => array(
|
954 |
+
'name' => 'p',
|
955 |
+
'text' => $Line['text'],
|
956 |
+
'handler' => 'line',
|
957 |
+
),
|
958 |
+
);
|
959 |
+
|
960 |
+
return $Block;
|
961 |
+
}
|
962 |
+
|
963 |
+
#
|
964 |
+
# Inline Elements
|
965 |
+
#
|
966 |
+
|
967 |
+
protected $InlineTypes = array(
|
968 |
+
'"' => array('SpecialCharacter'),
|
969 |
+
'!' => array('Image'),
|
970 |
+
'&' => array('SpecialCharacter'),
|
971 |
+
'*' => array('Emphasis'),
|
972 |
+
':' => array('Url'),
|
973 |
+
'<' => array('UrlTag', 'EmailTag', 'Markup', 'SpecialCharacter'),
|
974 |
+
'>' => array('SpecialCharacter'),
|
975 |
+
'[' => array('Link'),
|
976 |
+
'_' => array('Emphasis'),
|
977 |
+
'`' => array('Code'),
|
978 |
+
'~' => array('Strikethrough'),
|
979 |
+
'\\' => array('EscapeSequence'),
|
980 |
+
);
|
981 |
+
|
982 |
+
# ~
|
983 |
+
|
984 |
+
protected $inlineMarkerList = '!"*_&[:<>`~\\';
|
985 |
+
|
986 |
+
#
|
987 |
+
# ~
|
988 |
+
#
|
989 |
+
|
990 |
+
public function line($text)
|
991 |
+
{
|
992 |
+
$markup = '';
|
993 |
+
|
994 |
+
# $excerpt is based on the first occurrence of a marker
|
995 |
+
|
996 |
+
while ($excerpt = strpbrk($text, $this->inlineMarkerList))
|
997 |
+
{
|
998 |
+
$marker = $excerpt[0];
|
999 |
+
|
1000 |
+
$markerPosition = strpos($text, $marker);
|
1001 |
+
|
1002 |
+
$Excerpt = array('text' => $excerpt, 'context' => $text);
|
1003 |
+
|
1004 |
+
foreach ($this->InlineTypes[$marker] as $inlineType)
|
1005 |
+
{
|
1006 |
+
$Inline = $this->{'inline'.$inlineType}($Excerpt);
|
1007 |
+
|
1008 |
+
if ( ! isset($Inline))
|
1009 |
+
{
|
1010 |
+
continue;
|
1011 |
+
}
|
1012 |
+
|
1013 |
+
# makes sure that the inline belongs to "our" marker
|
1014 |
+
|
1015 |
+
if (isset($Inline['position']) and $Inline['position'] > $markerPosition)
|
1016 |
+
{
|
1017 |
+
continue;
|
1018 |
+
}
|
1019 |
+
|
1020 |
+
# sets a default inline position
|
1021 |
+
|
1022 |
+
if ( ! isset($Inline['position']))
|
1023 |
+
{
|
1024 |
+
$Inline['position'] = $markerPosition;
|
1025 |
+
}
|
1026 |
+
|
1027 |
+
# the text that comes before the inline
|
1028 |
+
$unmarkedText = substr($text, 0, $Inline['position']);
|
1029 |
+
|
1030 |
+
# compile the unmarked text
|
1031 |
+
$markup .= $this->unmarkedText($unmarkedText);
|
1032 |
+
|
1033 |
+
# compile the inline
|
1034 |
+
$markup .= isset($Inline['markup']) ? $Inline['markup'] : $this->element($Inline['element']);
|
1035 |
+
|
1036 |
+
# remove the examined text
|
1037 |
+
$text = substr($text, $Inline['position'] + $Inline['extent']);
|
1038 |
+
|
1039 |
+
continue 2;
|
1040 |
+
}
|
1041 |
+
|
1042 |
+
# the marker does not belong to an inline
|
1043 |
+
|
1044 |
+
$unmarkedText = substr($text, 0, $markerPosition + 1);
|
1045 |
+
|
1046 |
+
$markup .= $this->unmarkedText($unmarkedText);
|
1047 |
+
|
1048 |
+
$text = substr($text, $markerPosition + 1);
|
1049 |
+
}
|
1050 |
+
|
1051 |
+
$markup .= $this->unmarkedText($text);
|
1052 |
+
|
1053 |
+
return $markup;
|
1054 |
+
}
|
1055 |
+
|
1056 |
+
#
|
1057 |
+
# ~
|
1058 |
+
#
|
1059 |
+
|
1060 |
+
protected function inlineCode($Excerpt)
|
1061 |
+
{
|
1062 |
+
$marker = $Excerpt['text'][0];
|
1063 |
+
|
1064 |
+
if (preg_match('/^('.$marker.'+)[ ]*(.+?)[ ]*(?<!'.$marker.')\1(?!'.$marker.')/s', $Excerpt['text'], $matches))
|
1065 |
+
{
|
1066 |
+
$text = $matches[2];
|
1067 |
+
$text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
|
1068 |
+
$text = preg_replace("/[ ]*\n/", ' ', $text);
|
1069 |
+
|
1070 |
+
return array(
|
1071 |
+
'extent' => strlen($matches[0]),
|
1072 |
+
'element' => array(
|
1073 |
+
'name' => 'code',
|
1074 |
+
'text' => $text,
|
1075 |
+
),
|
1076 |
+
);
|
1077 |
+
}
|
1078 |
+
}
|
1079 |
+
|
1080 |
+
protected function inlineEmailTag($Excerpt)
|
1081 |
+
{
|
1082 |
+
if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<((mailto:)?\S+?@\S+?)>/i', $Excerpt['text'], $matches))
|
1083 |
+
{
|
1084 |
+
$url = $matches[1];
|
1085 |
+
|
1086 |
+
if ( ! isset($matches[2]))
|
1087 |
+
{
|
1088 |
+
$url = 'mailto:' . $url;
|
1089 |
+
}
|
1090 |
+
|
1091 |
+
return array(
|
1092 |
+
'extent' => strlen($matches[0]),
|
1093 |
+
'element' => array(
|
1094 |
+
'name' => 'a',
|
1095 |
+
'text' => $matches[1],
|
1096 |
+
'attributes' => array(
|
1097 |
+
'href' => $url,
|
1098 |
+
),
|
1099 |
+
),
|
1100 |
+
);
|
1101 |
+
}
|
1102 |
+
}
|
1103 |
+
|
1104 |
+
protected function inlineEmphasis($Excerpt)
|
1105 |
+
{
|
1106 |
+
if ( ! isset($Excerpt['text'][1]))
|
1107 |
+
{
|
1108 |
+
return;
|
1109 |
+
}
|
1110 |
+
|
1111 |
+
$marker = $Excerpt['text'][0];
|
1112 |
+
|
1113 |
+
if ($Excerpt['text'][1] === $marker and preg_match($this->StrongRegex[$marker], $Excerpt['text'], $matches))
|
1114 |
+
{
|
1115 |
+
$emphasis = 'strong';
|
1116 |
+
}
|
1117 |
+
elseif (preg_match($this->EmRegex[$marker], $Excerpt['text'], $matches))
|
1118 |
+
{
|
1119 |
+
$emphasis = 'em';
|
1120 |
+
}
|
1121 |
+
else
|
1122 |
+
{
|
1123 |
+
return;
|
1124 |
+
}
|
1125 |
+
|
1126 |
+
return array(
|
1127 |
+
'extent' => strlen($matches[0]),
|
1128 |
+
'element' => array(
|
1129 |
+
'name' => $emphasis,
|
1130 |
+
'handler' => 'line',
|
1131 |
+
'text' => $matches[1],
|
1132 |
+
),
|
1133 |
+
);
|
1134 |
+
}
|
1135 |
+
|
1136 |
+
protected function inlineEscapeSequence($Excerpt)
|
1137 |
+
{
|
1138 |
+
if (isset($Excerpt['text'][1]) and in_array($Excerpt['text'][1], $this->specialCharacters))
|
1139 |
+
{
|
1140 |
+
return array(
|
1141 |
+
'markup' => $Excerpt['text'][1],
|
1142 |
+
'extent' => 2,
|
1143 |
+
);
|
1144 |
+
}
|
1145 |
+
}
|
1146 |
+
|
1147 |
+
protected function inlineImage($Excerpt)
|
1148 |
+
{
|
1149 |
+
if ( ! isset($Excerpt['text'][1]) or $Excerpt['text'][1] !== '[')
|
1150 |
+
{
|
1151 |
+
return;
|
1152 |
+
}
|
1153 |
+
|
1154 |
+
$Excerpt['text']= substr($Excerpt['text'], 1);
|
1155 |
+
|
1156 |
+
$Link = $this->inlineLink($Excerpt);
|
1157 |
+
|
1158 |
+
if ($Link === null)
|
1159 |
+
{
|
1160 |
+
return;
|
1161 |
+
}
|
1162 |
+
|
1163 |
+
$Inline = array(
|
1164 |
+
'extent' => $Link['extent'] + 1,
|
1165 |
+
'element' => array(
|
1166 |
+
'name' => 'img',
|
1167 |
+
'attributes' => array(
|
1168 |
+
'src' => $Link['element']['attributes']['href'],
|
1169 |
+
'alt' => $Link['element']['text'],
|
1170 |
+
),
|
1171 |
+
),
|
1172 |
+
);
|
1173 |
+
|
1174 |
+
$Inline['element']['attributes'] += $Link['element']['attributes'];
|
1175 |
+
|
1176 |
+
unset($Inline['element']['attributes']['href']);
|
1177 |
+
|
1178 |
+
return $Inline;
|
1179 |
+
}
|
1180 |
+
|
1181 |
+
protected function inlineLink($Excerpt)
|
1182 |
+
{
|
1183 |
+
$Element = array(
|
1184 |
+
'name' => 'a',
|
1185 |
+
'handler' => 'line',
|
1186 |
+
'text' => null,
|
1187 |
+
'attributes' => array(
|
1188 |
+
'href' => null,
|
1189 |
+
'title' => null,
|
1190 |
+
),
|
1191 |
+
);
|
1192 |
+
|
1193 |
+
$extent = 0;
|
1194 |
+
|
1195 |
+
$remainder = $Excerpt['text'];
|
1196 |
+
|
1197 |
+
if (preg_match('/\[((?:[^][]|(?R))*)\]/', $remainder, $matches))
|
1198 |
+
{
|
1199 |
+
$Element['text'] = $matches[1];
|
1200 |
+
|
1201 |
+
$extent += strlen($matches[0]);
|
1202 |
+
|
1203 |
+
$remainder = substr($remainder, $extent);
|
1204 |
+
}
|
1205 |
+
else
|
1206 |
+
{
|
1207 |
+
return;
|
1208 |
+
}
|
1209 |
+
|
1210 |
+
if (preg_match('/^[(]((?:[^ ()]|[(][^ )]+[)])+)(?:[ ]+("[^"]*"|\'[^\']*\'))?[)]/', $remainder, $matches))
|
1211 |
+
{
|
1212 |
+
$Element['attributes']['href'] = $matches[1];
|
1213 |
+
|
1214 |
+
if (isset($matches[2]))
|
1215 |
+
{
|
1216 |
+
$Element['attributes']['title'] = substr($matches[2], 1, - 1);
|
1217 |
+
}
|
1218 |
+
|
1219 |
+
$extent += strlen($matches[0]);
|
1220 |
+
}
|
1221 |
+
else
|
1222 |
+
{
|
1223 |
+
if (preg_match('/^\s*\[(.*?)\]/', $remainder, $matches))
|
1224 |
+
{
|
1225 |
+
$definition = strlen($matches[1]) ? $matches[1] : $Element['text'];
|
1226 |
+
$definition = strtolower($definition);
|
1227 |
+
|
1228 |
+
$extent += strlen($matches[0]);
|
1229 |
+
}
|
1230 |
+
else
|
1231 |
+
{
|
1232 |
+
$definition = strtolower($Element['text']);
|
1233 |
+
}
|
1234 |
+
|
1235 |
+
if ( ! isset($this->DefinitionData['Reference'][$definition]))
|
1236 |
+
{
|
1237 |
+
return;
|
1238 |
+
}
|
1239 |
+
|
1240 |
+
$Definition = $this->DefinitionData['Reference'][$definition];
|
1241 |
+
|
1242 |
+
$Element['attributes']['href'] = $Definition['url'];
|
1243 |
+
$Element['attributes']['title'] = $Definition['title'];
|
1244 |
+
}
|
1245 |
+
|
1246 |
+
$Element['attributes']['href'] = str_replace(array('&', '<'), array('&', '<'), $Element['attributes']['href']);
|
1247 |
+
|
1248 |
+
return array(
|
1249 |
+
'extent' => $extent,
|
1250 |
+
'element' => $Element,
|
1251 |
+
);
|
1252 |
+
}
|
1253 |
+
|
1254 |
+
protected function inlineMarkup($Excerpt)
|
1255 |
+
{
|
1256 |
+
if ($this->markupEscaped or strpos($Excerpt['text'], '>') === false)
|
1257 |
+
{
|
1258 |
+
return;
|
1259 |
+
}
|
1260 |
+
|
1261 |
+
if ($Excerpt['text'][1] === '/' and preg_match('/^<\/\w*[ ]*>/s', $Excerpt['text'], $matches))
|
1262 |
+
{
|
1263 |
+
return array(
|
1264 |
+
'markup' => $matches[0],
|
1265 |
+
'extent' => strlen($matches[0]),
|
1266 |
+
);
|
1267 |
+
}
|
1268 |
+
|
1269 |
+
if ($Excerpt['text'][1] === '!' and preg_match('/^<!---?[^>-](?:-?[^-])*-->/s', $Excerpt['text'], $matches))
|
1270 |
+
{
|
1271 |
+
return array(
|
1272 |
+
'markup' => $matches[0],
|
1273 |
+
'extent' => strlen($matches[0]),
|
1274 |
+
);
|
1275 |
+
}
|
1276 |
+
|
1277 |
+
if ($Excerpt['text'][1] !== ' ' and preg_match('/^<\w*(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*\/?>/s', $Excerpt['text'], $matches))
|
1278 |
+
{
|
1279 |
+
return array(
|
1280 |
+
'markup' => $matches[0],
|
1281 |
+
'extent' => strlen($matches[0]),
|
1282 |
+
);
|
1283 |
+
}
|
1284 |
+
}
|
1285 |
+
|
1286 |
+
protected function inlineSpecialCharacter($Excerpt)
|
1287 |
+
{
|
1288 |
+
if ($Excerpt['text'][0] === '&' and ! preg_match('/^&#?\w+;/', $Excerpt['text']))
|
1289 |
+
{
|
1290 |
+
return array(
|
1291 |
+
'markup' => '&',
|
1292 |
+
'extent' => 1,
|
1293 |
+
);
|
1294 |
+
}
|
1295 |
+
|
1296 |
+
$SpecialCharacter = array('>' => 'gt', '<' => 'lt', '"' => 'quot');
|
1297 |
+
|
1298 |
+
if (isset($SpecialCharacter[$Excerpt['text'][0]]))
|
1299 |
+
{
|
1300 |
+
return array(
|
1301 |
+
'markup' => '&'.$SpecialCharacter[$Excerpt['text'][0]].';',
|
1302 |
+
'extent' => 1,
|
1303 |
+
);
|
1304 |
+
}
|
1305 |
+
}
|
1306 |
+
|
1307 |
+
protected function inlineStrikethrough($Excerpt)
|
1308 |
+
{
|
1309 |
+
if ( ! isset($Excerpt['text'][1]))
|
1310 |
+
{
|
1311 |
+
return;
|
1312 |
+
}
|
1313 |
+
|
1314 |
+
if ($Excerpt['text'][1] === '~' and preg_match('/^~~(?=\S)(.+?)(?<=\S)~~/', $Excerpt['text'], $matches))
|
1315 |
+
{
|
1316 |
+
return array(
|
1317 |
+
'extent' => strlen($matches[0]),
|
1318 |
+
'element' => array(
|
1319 |
+
'name' => 'del',
|
1320 |
+
'text' => $matches[1],
|
1321 |
+
'handler' => 'line',
|
1322 |
+
),
|
1323 |
+
);
|
1324 |
+
}
|
1325 |
+
}
|
1326 |
+
|
1327 |
+
protected function inlineUrl($Excerpt)
|
1328 |
+
{
|
1329 |
+
if ($this->urlsLinked !== true or ! isset($Excerpt['text'][2]) or $Excerpt['text'][2] !== '/')
|
1330 |
+
{
|
1331 |
+
return;
|
1332 |
+
}
|
1333 |
+
|
1334 |
+
if (preg_match('/\bhttps?:[\/]{2}[^\s<]+\b\/*/ui', $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE))
|
1335 |
+
{
|
1336 |
+
$Inline = array(
|
1337 |
+
'extent' => strlen($matches[0][0]),
|
1338 |
+
'position' => $matches[0][1],
|
1339 |
+
'element' => array(
|
1340 |
+
'name' => 'a',
|
1341 |
+
'text' => $matches[0][0],
|
1342 |
+
'attributes' => array(
|
1343 |
+
'href' => $matches[0][0],
|
1344 |
+
),
|
1345 |
+
),
|
1346 |
+
);
|
1347 |
+
|
1348 |
+
return $Inline;
|
1349 |
+
}
|
1350 |
+
}
|
1351 |
+
|
1352 |
+
protected function inlineUrlTag($Excerpt)
|
1353 |
+
{
|
1354 |
+
if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<(\w+:\/{2}[^ >]+)>/i', $Excerpt['text'], $matches))
|
1355 |
+
{
|
1356 |
+
$url = str_replace(array('&', '<'), array('&', '<'), $matches[1]);
|
1357 |
+
|
1358 |
+
return array(
|
1359 |
+
'extent' => strlen($matches[0]),
|
1360 |
+
'element' => array(
|
1361 |
+
'name' => 'a',
|
1362 |
+
'text' => $url,
|
1363 |
+
'attributes' => array(
|
1364 |
+
'href' => $url,
|
1365 |
+
),
|
1366 |
+
),
|
1367 |
+
);
|
1368 |
+
}
|
1369 |
+
}
|
1370 |
+
|
1371 |
+
# ~
|
1372 |
+
|
1373 |
+
protected function unmarkedText($text)
|
1374 |
+
{
|
1375 |
+
if ($this->breaksEnabled)
|
1376 |
+
{
|
1377 |
+
$text = preg_replace('/[ ]*\n/', "<br />\n", $text);
|
1378 |
+
}
|
1379 |
+
else
|
1380 |
+
{
|
1381 |
+
$text = preg_replace('/(?:[ ][ ]+|[ ]*\\\\)\n/', "<br />\n", $text);
|
1382 |
+
$text = str_replace(" \n", "\n", $text);
|
1383 |
+
}
|
1384 |
+
|
1385 |
+
return $text;
|
1386 |
+
}
|
1387 |
+
|
1388 |
+
#
|
1389 |
+
# Handlers
|
1390 |
+
#
|
1391 |
+
|
1392 |
+
protected function element(array $Element)
|
1393 |
+
{
|
1394 |
+
$markup = '<'.$Element['name'];
|
1395 |
+
|
1396 |
+
if (isset($Element['attributes']))
|
1397 |
+
{
|
1398 |
+
foreach ($Element['attributes'] as $name => $value)
|
1399 |
+
{
|
1400 |
+
if ($value === null)
|
1401 |
+
{
|
1402 |
+
continue;
|
1403 |
+
}
|
1404 |
+
|
1405 |
+
$markup .= ' '.$name.'="'.$value.'"';
|
1406 |
+
}
|
1407 |
+
}
|
1408 |
+
|
1409 |
+
if (isset($Element['text']))
|
1410 |
+
{
|
1411 |
+
$markup .= '>';
|
1412 |
+
|
1413 |
+
if (isset($Element['handler']))
|
1414 |
+
{
|
1415 |
+
$markup .= $this->{$Element['handler']}($Element['text']);
|
1416 |
+
}
|
1417 |
+
else
|
1418 |
+
{
|
1419 |
+
$markup .= $Element['text'];
|
1420 |
+
}
|
1421 |
+
|
1422 |
+
$markup .= '</'.$Element['name'].'>';
|
1423 |
+
}
|
1424 |
+
else
|
1425 |
+
{
|
1426 |
+
$markup .= ' />';
|
1427 |
+
}
|
1428 |
+
|
1429 |
+
return $markup;
|
1430 |
+
}
|
1431 |
+
|
1432 |
+
protected function elements(array $Elements)
|
1433 |
+
{
|
1434 |
+
$markup = '';
|
1435 |
+
|
1436 |
+
foreach ($Elements as $Element)
|
1437 |
+
{
|
1438 |
+
$markup .= "\n" . $this->element($Element);
|
1439 |
+
}
|
1440 |
+
|
1441 |
+
$markup .= "\n";
|
1442 |
+
|
1443 |
+
return $markup;
|
1444 |
+
}
|
1445 |
+
|
1446 |
+
# ~
|
1447 |
+
|
1448 |
+
protected function li($lines)
|
1449 |
+
{
|
1450 |
+
$markup = $this->lines($lines);
|
1451 |
+
|
1452 |
+
$trimmedMarkup = trim($markup);
|
1453 |
+
|
1454 |
+
if ( ! in_array('', $lines) and substr($trimmedMarkup, 0, 3) === '<p>')
|
1455 |
+
{
|
1456 |
+
$markup = $trimmedMarkup;
|
1457 |
+
$markup = substr($markup, 3);
|
1458 |
+
|
1459 |
+
$position = strpos($markup, "</p>");
|
1460 |
+
|
1461 |
+
$markup = substr_replace($markup, '', $position, 4);
|
1462 |
+
}
|
1463 |
+
|
1464 |
+
return $markup;
|
1465 |
+
}
|
1466 |
+
|
1467 |
+
#
|
1468 |
+
# Deprecated Methods
|
1469 |
+
#
|
1470 |
+
|
1471 |
+
function parse($text)
|
1472 |
+
{
|
1473 |
+
$markup = $this->text($text);
|
1474 |
+
|
1475 |
+
return $markup;
|
1476 |
+
}
|
1477 |
+
|
1478 |
+
#
|
1479 |
+
# Static Methods
|
1480 |
+
#
|
1481 |
+
|
1482 |
+
static function instance($name = 'default')
|
1483 |
+
{
|
1484 |
+
if (isset(self::$instances[$name]))
|
1485 |
+
{
|
1486 |
+
return self::$instances[$name];
|
1487 |
+
}
|
1488 |
+
|
1489 |
+
$instance = new static();
|
1490 |
+
|
1491 |
+
self::$instances[$name] = $instance;
|
1492 |
+
|
1493 |
+
return $instance;
|
1494 |
+
}
|
1495 |
+
|
1496 |
+
private static $instances = array();
|
1497 |
+
|
1498 |
+
#
|
1499 |
+
# Fields
|
1500 |
+
#
|
1501 |
+
|
1502 |
+
protected $DefinitionData;
|
1503 |
+
|
1504 |
+
#
|
1505 |
+
# Read-Only
|
1506 |
+
|
1507 |
+
protected $specialCharacters = array(
|
1508 |
+
'\\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '>', '#', '+', '-', '.', '!', '|',
|
1509 |
+
);
|
1510 |
+
|
1511 |
+
protected $StrongRegex = array(
|
1512 |
+
'*' => '/^[*]{2}((?:\\\\\*|[^*]|[*][^*]*[*])+?)[*]{2}(?![*])/s',
|
1513 |
+
'_' => '/^__((?:\\\\_|[^_]|_[^_]*_)+?)__(?!_)/us',
|
1514 |
+
);
|
1515 |
+
|
1516 |
+
protected $EmRegex = array(
|
1517 |
+
'*' => '/^[*]((?:\\\\\*|[^*]|[*][*][^*]+?[*][*])+?)[*](?![*])/s',
|
1518 |
+
'_' => '/^_((?:\\\\_|[^_]|__[^_]*__)+?)_(?!_)\b/us',
|
1519 |
+
);
|
1520 |
+
|
1521 |
+
protected $regexHtmlAttribute = '[a-zA-Z_:][\w:.-]*(?:\s*=\s*(?:[^"\'=<>`\s]+|"[^"]*"|\'[^\']*\'))?';
|
1522 |
+
|
1523 |
+
protected $voidElements = array(
|
1524 |
+
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source',
|
1525 |
+
);
|
1526 |
+
|
1527 |
+
protected $textLevelElements = array(
|
1528 |
+
'a', 'br', 'bdo', 'abbr', 'blink', 'nextid', 'acronym', 'basefont',
|
1529 |
+
'b', 'em', 'big', 'cite', 'small', 'spacer', 'listing',
|
1530 |
+
'i', 'rp', 'del', 'code', 'strike', 'marquee',
|
1531 |
+
'q', 'rt', 'ins', 'font', 'strong',
|
1532 |
+
's', 'tt', 'sub', 'mark',
|
1533 |
+
'u', 'xm', 'sup', 'nobr',
|
1534 |
+
'var', 'ruby',
|
1535 |
+
'wbr', 'span',
|
1536 |
+
'time',
|
1537 |
+
);
|
1538 |
+
}
|
vendor/yahnis-elsts/plugin-update-checker/vendor/ParsedownLegacy.php
ADDED
@@ -0,0 +1,1535 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
#
|
4 |
+
#
|
5 |
+
# Parsedown
|
6 |
+
# http://parsedown.org
|
7 |
+
#
|
8 |
+
# (c) Emanuil Rusev
|
9 |
+
# http://erusev.com
|
10 |
+
#
|
11 |
+
# For the full license information, view the LICENSE file that was distributed
|
12 |
+
# with this source code.
|
13 |
+
#
|
14 |
+
#
|
15 |
+
|
16 |
+
class Parsedown
|
17 |
+
{
|
18 |
+
# ~
|
19 |
+
|
20 |
+
const version = '1.5.0';
|
21 |
+
|
22 |
+
# ~
|
23 |
+
|
24 |
+
function text($text)
|
25 |
+
{
|
26 |
+
# make sure no definitions are set
|
27 |
+
$this->DefinitionData = array();
|
28 |
+
|
29 |
+
# standardize line breaks
|
30 |
+
$text = str_replace(array("\r\n", "\r"), "\n", $text);
|
31 |
+
|
32 |
+
# remove surrounding line breaks
|
33 |
+
$text = trim($text, "\n");
|
34 |
+
|
35 |
+
# split text into lines
|
36 |
+
$lines = explode("\n", $text);
|
37 |
+
|
38 |
+
# iterate through lines to identify blocks
|
39 |
+
$markup = $this->lines($lines);
|
40 |
+
|
41 |
+
# trim line breaks
|
42 |
+
$markup = trim($markup, "\n");
|
43 |
+
|
44 |
+
return $markup;
|
45 |
+
}
|
46 |
+
|
47 |
+
#
|
48 |
+
# Setters
|
49 |
+
#
|
50 |
+
|
51 |
+
function setBreaksEnabled($breaksEnabled)
|
52 |
+
{
|
53 |
+
$this->breaksEnabled = $breaksEnabled;
|
54 |
+
|
55 |
+
return $this;
|
56 |
+
}
|
57 |
+
|
58 |
+
protected $breaksEnabled;
|
59 |
+
|
60 |
+
function setMarkupEscaped($markupEscaped)
|
61 |
+
{
|
62 |
+
$this->markupEscaped = $markupEscaped;
|
63 |
+
|
64 |
+
return $this;
|
65 |
+
}
|
66 |
+
|
67 |
+
protected $markupEscaped;
|
68 |
+
|
69 |
+
function setUrlsLinked($urlsLinked)
|
70 |
+
{
|
71 |
+
$this->urlsLinked = $urlsLinked;
|
72 |
+
|
73 |
+
return $this;
|
74 |
+
}
|
75 |
+
|
76 |
+
protected $urlsLinked = true;
|
77 |
+
|
78 |
+
#
|
79 |
+
# Lines
|
80 |
+
#
|
81 |
+
|
82 |
+
protected $BlockTypes = array(
|
83 |
+
'#' => array('Header'),
|
84 |
+
'*' => array('Rule', 'List'),
|
85 |
+
'+' => array('List'),
|
86 |
+
'-' => array('SetextHeader', 'Table', 'Rule', 'List'),
|
87 |
+
'0' => array('List'),
|
88 |
+
'1' => array('List'),
|
89 |
+
'2' => array('List'),
|
90 |
+
'3' => array('List'),
|
91 |
+
'4' => array('List'),
|
92 |
+
'5' => array('List'),
|
93 |
+
'6' => array('List'),
|
94 |
+
'7' => array('List'),
|
95 |
+
'8' => array('List'),
|
96 |
+
'9' => array('List'),
|
97 |
+
':' => array('Table'),
|
98 |
+
'<' => array('Comment', 'Markup'),
|
99 |
+
'=' => array('SetextHeader'),
|
100 |
+
'>' => array('Quote'),
|
101 |
+
'[' => array('Reference'),
|
102 |
+
'_' => array('Rule'),
|
103 |
+
'`' => array('FencedCode'),
|
104 |
+
'|' => array('Table'),
|
105 |
+
'~' => array('FencedCode'),
|
106 |
+
);
|
107 |
+
|
108 |
+
# ~
|
109 |
+
|
110 |
+
protected $DefinitionTypes = array(
|
111 |
+
'[' => array('Reference'),
|
112 |
+
);
|
113 |
+
|
114 |
+
# ~
|
115 |
+
|
116 |
+
protected $unmarkedBlockTypes = array(
|
117 |
+
'Code',
|
118 |
+
);
|
119 |
+
|
120 |
+
#
|
121 |
+
# Blocks
|
122 |
+
#
|
123 |
+
|
124 |
+
private function lines(array $lines)
|
125 |
+
{
|
126 |
+
$CurrentBlock = null;
|
127 |
+
|
128 |
+
foreach ($lines as $line)
|
129 |
+
{
|
130 |
+
if (chop($line) === '')
|
131 |
+
{
|
132 |
+
if (isset($CurrentBlock))
|
133 |
+
{
|
134 |
+
$CurrentBlock['interrupted'] = true;
|
135 |
+
}
|
136 |
+
|
137 |
+
continue;
|
138 |
+
}
|
139 |
+
|
140 |
+
if (strpos($line, "\t") !== false)
|
141 |
+
{
|
142 |
+
$parts = explode("\t", $line);
|
143 |
+
|
144 |
+
$line = $parts[0];
|
145 |
+
|
146 |
+
unset($parts[0]);
|
147 |
+
|
148 |
+
foreach ($parts as $part)
|
149 |
+
{
|
150 |
+
$shortage = 4 - mb_strlen($line, 'utf-8') % 4;
|
151 |
+
|
152 |
+
$line .= str_repeat(' ', $shortage);
|
153 |
+
$line .= $part;
|
154 |
+
}
|
155 |
+
}
|
156 |
+
|
157 |
+
$indent = 0;
|
158 |
+
|
159 |
+
while (isset($line[$indent]) and $line[$indent] === ' ')
|
160 |
+
{
|
161 |
+
$indent ++;
|
162 |
+
}
|
163 |
+
|
164 |
+
$text = $indent > 0 ? substr($line, $indent) : $line;
|
165 |
+
|
166 |
+
# ~
|
167 |
+
|
168 |
+
$Line = array('body' => $line, 'indent' => $indent, 'text' => $text);
|
169 |
+
|
170 |
+
# ~
|
171 |
+
|
172 |
+
if (isset($CurrentBlock['incomplete']))
|
173 |
+
{
|
174 |
+
$Block = $this->{'block'.$CurrentBlock['type'].'Continue'}($Line, $CurrentBlock);
|
175 |
+
|
176 |
+
if (isset($Block))
|
177 |
+
{
|
178 |
+
$CurrentBlock = $Block;
|
179 |
+
|
180 |
+
continue;
|
181 |
+
}
|
182 |
+
else
|
183 |
+
{
|
184 |
+
if (method_exists($this, 'block'.$CurrentBlock['type'].'Complete'))
|
185 |
+
{
|
186 |
+
$CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock);
|
187 |
+
}
|
188 |
+
|
189 |
+
unset($CurrentBlock['incomplete']);
|
190 |
+
}
|
191 |
+
}
|
192 |
+
|
193 |
+
# ~
|
194 |
+
|
195 |
+
$marker = $text[0];
|
196 |
+
|
197 |
+
# ~
|
198 |
+
|
199 |
+
$blockTypes = $this->unmarkedBlockTypes;
|
200 |
+
|
201 |
+
if (isset($this->BlockTypes[$marker]))
|
202 |
+
{
|
203 |
+
foreach ($this->BlockTypes[$marker] as $blockType)
|
204 |
+
{
|
205 |
+
$blockTypes []= $blockType;
|
206 |
+
}
|
207 |
+
}
|
208 |
+
|
209 |
+
#
|
210 |
+
# ~
|
211 |
+
|
212 |
+
foreach ($blockTypes as $blockType)
|
213 |
+
{
|
214 |
+
$Block = $this->{'block'.$blockType}($Line, $CurrentBlock);
|
215 |
+
|
216 |
+
if (isset($Block))
|
217 |
+
{
|
218 |
+
$Block['type'] = $blockType;
|
219 |
+
|
220 |
+
if ( ! isset($Block['identified']))
|
221 |
+
{
|
222 |
+
$Blocks []= $CurrentBlock;
|
223 |
+
|
224 |
+
$Block['identified'] = true;
|
225 |
+
}
|
226 |
+
|
227 |
+
if (method_exists($this, 'block'.$blockType.'Continue'))
|
228 |
+
{
|
229 |
+
$Block['incomplete'] = true;
|
230 |
+
}
|
231 |
+
|
232 |
+
$CurrentBlock = $Block;
|
233 |
+
|
234 |
+
continue 2;
|
235 |
+
}
|
236 |
+
}
|
237 |
+
|
238 |
+
# ~
|
239 |
+
|
240 |
+
if (isset($CurrentBlock) and ! isset($CurrentBlock['type']) and ! isset($CurrentBlock['interrupted']))
|
241 |
+
{
|
242 |
+
$CurrentBlock['element']['text'] .= "\n".$text;
|
243 |
+
}
|
244 |
+
else
|
245 |
+
{
|
246 |
+
$Blocks []= $CurrentBlock;
|
247 |
+
|
248 |
+
$CurrentBlock = $this->paragraph($Line);
|
249 |
+
|
250 |
+
$CurrentBlock['identified'] = true;
|
251 |
+
}
|
252 |
+
}
|
253 |
+
|
254 |
+
# ~
|
255 |
+
|
256 |
+
if (isset($CurrentBlock['incomplete']) and method_exists($this, 'block'.$CurrentBlock['type'].'Complete'))
|
257 |
+
{
|
258 |
+
$CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock);
|
259 |
+
}
|
260 |
+
|
261 |
+
# ~
|
262 |
+
|
263 |
+
$Blocks []= $CurrentBlock;
|
264 |
+
|
265 |
+
unset($Blocks[0]);
|
266 |
+
|
267 |
+
# ~
|
268 |
+
|
269 |
+
$markup = '';
|
270 |
+
|
271 |
+
foreach ($Blocks as $Block)
|
272 |
+
{
|
273 |
+
if (isset($Block['hidden']))
|
274 |
+
{
|
275 |
+
continue;
|
276 |
+
}
|
277 |
+
|
278 |
+
$markup .= "\n";
|
279 |
+
$markup .= isset($Block['markup']) ? $Block['markup'] : $this->element($Block['element']);
|
280 |
+
}
|
281 |
+
|
282 |
+
$markup .= "\n";
|
283 |
+
|
284 |
+
# ~
|
285 |
+
|
286 |
+
return $markup;
|
287 |
+
}
|
288 |
+
|
289 |
+
#
|
290 |
+
# Code
|
291 |
+
|
292 |
+
protected function blockCode($Line, $Block = null)
|
293 |
+
{
|
294 |
+
if (isset($Block) and ! isset($Block['type']) and ! isset($Block['interrupted']))
|
295 |
+
{
|
296 |
+
return;
|
297 |
+
}
|
298 |
+
|
299 |
+
if ($Line['indent'] >= 4)
|
300 |
+
{
|
301 |
+
$text = substr($Line['body'], 4);
|
302 |
+
|
303 |
+
$Block = array(
|
304 |
+
'element' => array(
|
305 |
+
'name' => 'pre',
|
306 |
+
'handler' => 'element',
|
307 |
+
'text' => array(
|
308 |
+
'name' => 'code',
|
309 |
+
'text' => $text,
|
310 |
+
),
|
311 |
+
),
|
312 |
+
);
|
313 |
+
|
314 |
+
return $Block;
|
315 |
+
}
|
316 |
+
}
|
317 |
+
|
318 |
+
protected function blockCodeContinue($Line, $Block)
|
319 |
+
{
|
320 |
+
if ($Line['indent'] >= 4)
|
321 |
+
{
|
322 |
+
if (isset($Block['interrupted']))
|
323 |
+
{
|
324 |
+
$Block['element']['text']['text'] .= "\n";
|
325 |
+
|
326 |
+
unset($Block['interrupted']);
|
327 |
+
}
|
328 |
+
|
329 |
+
$Block['element']['text']['text'] .= "\n";
|
330 |
+
|
331 |
+
$text = substr($Line['body'], 4);
|
332 |
+
|
333 |
+
$Block['element']['text']['text'] .= $text;
|
334 |
+
|
335 |
+
return $Block;
|
336 |
+
}
|
337 |
+
}
|
338 |
+
|
339 |
+
protected function blockCodeComplete($Block)
|
340 |
+
{
|
341 |
+
$text = $Block['element']['text']['text'];
|
342 |
+
|
343 |
+
$text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
|
344 |
+
|
345 |
+
$Block['element']['text']['text'] = $text;
|
346 |
+
|
347 |
+
return $Block;
|
348 |
+
}
|
349 |
+
|
350 |
+
#
|
351 |
+
# Comment
|
352 |
+
|
353 |
+
protected function blockComment($Line)
|
354 |
+
{
|
355 |
+
if ($this->markupEscaped)
|
356 |
+
{
|
357 |
+
return;
|
358 |
+
}
|
359 |
+
|
360 |
+
if (isset($Line['text'][3]) and $Line['text'][3] === '-' and $Line['text'][2] === '-' and $Line['text'][1] === '!')
|
361 |
+
{
|
362 |
+
$Block = array(
|
363 |
+
'markup' => $Line['body'],
|
364 |
+
);
|
365 |
+
|
366 |
+
if (preg_match('/-->$/', $Line['text']))
|
367 |
+
{
|
368 |
+
$Block['closed'] = true;
|
369 |
+
}
|
370 |
+
|
371 |
+
return $Block;
|
372 |
+
}
|
373 |
+
}
|
374 |
+
|
375 |
+
protected function blockCommentContinue($Line, array $Block)
|
376 |
+
{
|
377 |
+
if (isset($Block['closed']))
|
378 |
+
{
|
379 |
+
return;
|
380 |
+
}
|
381 |
+
|
382 |
+
$Block['markup'] .= "\n" . $Line['body'];
|
383 |
+
|
384 |
+
if (preg_match('/-->$/', $Line['text']))
|
385 |
+
{
|
386 |
+
$Block['closed'] = true;
|
387 |
+
}
|
388 |
+
|
389 |
+
return $Block;
|
390 |
+
}
|
391 |
+
|
392 |
+
#
|
393 |
+
# Fenced Code
|
394 |
+
|
395 |
+
protected function blockFencedCode($Line)
|
396 |
+
{
|
397 |
+
if (preg_match('/^(['.$Line['text'][0].']{3,})[ ]*([\w-]+)?[ ]*$/', $Line['text'], $matches))
|
398 |
+
{
|
399 |
+
$Element = array(
|
400 |
+
'name' => 'code',
|
401 |
+
'text' => '',
|
402 |
+
);
|
403 |
+
|
404 |
+
if (isset($matches[2]))
|
405 |
+
{
|
406 |
+
$class = 'language-'.$matches[2];
|
407 |
+
|
408 |
+
$Element['attributes'] = array(
|
409 |
+
'class' => $class,
|
410 |
+
);
|
411 |
+
}
|
412 |
+
|
413 |
+
$Block = array(
|
414 |
+
'char' => $Line['text'][0],
|
415 |
+
'element' => array(
|
416 |
+
'name' => 'pre',
|
417 |
+
'handler' => 'element',
|
418 |
+
'text' => $Element,
|
419 |
+
),
|
420 |
+
);
|
421 |
+
|
422 |
+
return $Block;
|
423 |
+
}
|
424 |
+
}
|
425 |
+
|
426 |
+
protected function blockFencedCodeContinue($Line, $Block)
|
427 |
+
{
|
428 |
+
if (isset($Block['complete']))
|
429 |
+
{
|
430 |
+
return;
|
431 |
+
}
|
432 |
+
|
433 |
+
if (isset($Block['interrupted']))
|
434 |
+
{
|
435 |
+
$Block['element']['text']['text'] .= "\n";
|
436 |
+
|
437 |
+
unset($Block['interrupted']);
|
438 |
+
}
|
439 |
+
|
440 |
+
if (preg_match('/^'.$Block['char'].'{3,}[ ]*$/', $Line['text']))
|
441 |
+
{
|
442 |
+
$Block['element']['text']['text'] = substr($Block['element']['text']['text'], 1);
|
443 |
+
|
444 |
+
$Block['complete'] = true;
|
445 |
+
|
446 |
+
return $Block;
|
447 |
+
}
|
448 |
+
|
449 |
+
$Block['element']['text']['text'] .= "\n".$Line['body'];;
|
450 |
+
|
451 |
+
return $Block;
|
452 |
+
}
|
453 |
+
|
454 |
+
protected function blockFencedCodeComplete($Block)
|
455 |
+
{
|
456 |
+
$text = $Block['element']['text']['text'];
|
457 |
+
|
458 |
+
$text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
|
459 |
+
|
460 |
+
$Block['element']['text']['text'] = $text;
|
461 |
+
|
462 |
+
return $Block;
|
463 |
+
}
|
464 |
+
|
465 |
+
#
|
466 |
+
# Header
|
467 |
+
|
468 |
+
protected function blockHeader($Line)
|
469 |
+
{
|
470 |
+
if (isset($Line['text'][1]))
|
471 |
+
{
|
472 |
+
$level = 1;
|
473 |
+
|
474 |
+
while (isset($Line['text'][$level]) and $Line['text'][$level] === '#')
|
475 |
+
{
|
476 |
+
$level ++;
|
477 |
+
}
|
478 |
+
|
479 |
+
if ($level > 6)
|
480 |
+
{
|
481 |
+
return;
|
482 |
+
}
|
483 |
+
|
484 |
+
$text = trim($Line['text'], '# ');
|
485 |
+
|
486 |
+
$Block = array(
|
487 |
+
'element' => array(
|
488 |
+
'name' => 'h' . min(6, $level),
|
489 |
+
'text' => $text,
|
490 |
+
'handler' => 'line',
|
491 |
+
),
|
492 |
+
);
|
493 |
+
|
494 |
+
return $Block;
|
495 |
+
}
|
496 |
+
}
|
497 |
+
|
498 |
+
#
|
499 |
+
# List
|
500 |
+
|
501 |
+
protected function blockList($Line)
|
502 |
+
{
|
503 |
+
list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '[*+-]') : array('ol', '[0-9]+[.]');
|
504 |
+
|
505 |
+
if (preg_match('/^('.$pattern.'[ ]+)(.*)/', $Line['text'], $matches))
|
506 |
+
{
|
507 |
+
$Block = array(
|
508 |
+
'indent' => $Line['indent'],
|
509 |
+
'pattern' => $pattern,
|
510 |
+
'element' => array(
|
511 |
+
'name' => $name,
|
512 |
+
'handler' => 'elements',
|
513 |
+
),
|
514 |
+
);
|
515 |
+
|
516 |
+
$Block['li'] = array(
|
517 |
+
'name' => 'li',
|
518 |
+
'handler' => 'li',
|
519 |
+
'text' => array(
|
520 |
+
$matches[2],
|
521 |
+
),
|
522 |
+
);
|
523 |
+
|
524 |
+
$Block['element']['text'] []= & $Block['li'];
|
525 |
+
|
526 |
+
return $Block;
|
527 |
+
}
|
528 |
+
}
|
529 |
+
|
530 |
+
protected function blockListContinue($Line, array $Block)
|
531 |
+
{
|
532 |
+
if ($Block['indent'] === $Line['indent'] and preg_match('/^'.$Block['pattern'].'(?:[ ]+(.*)|$)/', $Line['text'], $matches))
|
533 |
+
{
|
534 |
+
if (isset($Block['interrupted']))
|
535 |
+
{
|
536 |
+
$Block['li']['text'] []= '';
|
537 |
+
|
538 |
+
unset($Block['interrupted']);
|
539 |
+
}
|
540 |
+
|
541 |
+
unset($Block['li']);
|
542 |
+
|
543 |
+
$text = isset($matches[1]) ? $matches[1] : '';
|
544 |
+
|
545 |
+
$Block['li'] = array(
|
546 |
+
'name' => 'li',
|
547 |
+
'handler' => 'li',
|
548 |
+
'text' => array(
|
549 |
+
$text,
|
550 |
+
),
|
551 |
+
);
|
552 |
+
|
553 |
+
$Block['element']['text'] []= & $Block['li'];
|
554 |
+
|
555 |
+
return $Block;
|
556 |
+
}
|
557 |
+
|
558 |
+
if ($Line['text'][0] === '[' and $this->blockReference($Line))
|
559 |
+
{
|
560 |
+
return $Block;
|
561 |
+
}
|
562 |
+
|
563 |
+
if ( ! isset($Block['interrupted']))
|
564 |
+
{
|
565 |
+
$text = preg_replace('/^[ ]{0,4}/', '', $Line['body']);
|
566 |
+
|
567 |
+
$Block['li']['text'] []= $text;
|
568 |
+
|
569 |
+
return $Block;
|
570 |
+
}
|
571 |
+
|
572 |
+
if ($Line['indent'] > 0)
|
573 |
+
{
|
574 |
+
$Block['li']['text'] []= '';
|
575 |
+
|
576 |
+
$text = preg_replace('/^[ ]{0,4}/', '', $Line['body']);
|
577 |
+
|
578 |
+
$Block['li']['text'] []= $text;
|
579 |
+
|
580 |
+
unset($Block['interrupted']);
|
581 |
+
|
582 |
+
return $Block;
|
583 |
+
}
|
584 |
+
}
|
585 |
+
|
586 |
+
#
|
587 |
+
# Quote
|
588 |
+
|
589 |
+
protected function blockQuote($Line)
|
590 |
+
{
|
591 |
+
if (preg_match('/^>[ ]?(.*)/', $Line['text'], $matches))
|
592 |
+
{
|
593 |
+
$Block = array(
|
594 |
+
'element' => array(
|
595 |
+
'name' => 'blockquote',
|
596 |
+
'handler' => 'lines',
|
597 |
+
'text' => (array) $matches[1],
|
598 |
+
),
|
599 |
+
);
|
600 |
+
|
601 |
+
return $Block;
|
602 |
+
}
|
603 |
+
}
|
604 |
+
|
605 |
+
protected function blockQuoteContinue($Line, array $Block)
|
606 |
+
{
|
607 |
+
if ($Line['text'][0] === '>' and preg_match('/^>[ ]?(.*)/', $Line['text'], $matches))
|
608 |
+
{
|
609 |
+
if (isset($Block['interrupted']))
|
610 |
+
{
|
611 |
+
$Block['element']['text'] []= '';
|
612 |
+
|
613 |
+
unset($Block['interrupted']);
|
614 |
+
}
|
615 |
+
|
616 |
+
$Block['element']['text'] []= $matches[1];
|
617 |
+
|
618 |
+
return $Block;
|
619 |
+
}
|
620 |
+
|
621 |
+
if ( ! isset($Block['interrupted']))
|
622 |
+
{
|
623 |
+
$Block['element']['text'] []= $Line['text'];
|
624 |
+
|
625 |
+
return $Block;
|
626 |
+
}
|
627 |
+
}
|
628 |
+
|
629 |
+
#
|
630 |
+
# Rule
|
631 |
+
|
632 |
+
protected function blockRule($Line)
|
633 |
+
{
|
634 |
+
if (preg_match('/^(['.$Line['text'][0].'])([ ]*\1){2,}[ ]*$/', $Line['text']))
|
635 |
+
{
|
636 |
+
$Block = array(
|
637 |
+
'element' => array(
|
638 |
+
'name' => 'hr'
|
639 |
+
),
|
640 |
+
);
|
641 |
+
|
642 |
+
return $Block;
|
643 |
+
}
|
644 |
+
}
|
645 |
+
|
646 |
+
#
|
647 |
+
# Setext
|
648 |
+
|
649 |
+
protected function blockSetextHeader($Line, array $Block = null)
|
650 |
+
{
|
651 |
+
if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted']))
|
652 |
+
{
|
653 |
+
return;
|
654 |
+
}
|
655 |
+
|
656 |
+
if (chop($Line['text'], $Line['text'][0]) === '')
|
657 |
+
{
|
658 |
+
$Block['element']['name'] = $Line['text'][0] === '=' ? 'h1' : 'h2';
|
659 |
+
|
660 |
+
return $Block;
|
661 |
+
}
|
662 |
+
}
|
663 |
+
|
664 |
+
#
|
665 |
+
# Markup
|
666 |
+
|
667 |
+
protected function blockMarkup($Line)
|
668 |
+
{
|
669 |
+
if ($this->markupEscaped)
|
670 |
+
{
|
671 |
+
return;
|
672 |
+
}
|
673 |
+
|
674 |
+
if (preg_match('/^<(\w*)(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*(\/)?>/', $Line['text'], $matches))
|
675 |
+
{
|
676 |
+
if (in_array($matches[1], $this->textLevelElements))
|
677 |
+
{
|
678 |
+
return;
|
679 |
+
}
|
680 |
+
|
681 |
+
$Block = array(
|
682 |
+
'name' => $matches[1],
|
683 |
+
'depth' => 0,
|
684 |
+
'markup' => $Line['text'],
|
685 |
+
);
|
686 |
+
|
687 |
+
$length = strlen($matches[0]);
|
688 |
+
|
689 |
+
$remainder = substr($Line['text'], $length);
|
690 |
+
|
691 |
+
if (trim($remainder) === '')
|
692 |
+
{
|
693 |
+
if (isset($matches[2]) or in_array($matches[1], $this->voidElements))
|
694 |
+
{
|
695 |
+
$Block['closed'] = true;
|
696 |
+
|
697 |
+
$Block['void'] = true;
|
698 |
+
}
|
699 |
+
}
|
700 |
+
else
|
701 |
+
{
|
702 |
+
if (isset($matches[2]) or in_array($matches[1], $this->voidElements))
|
703 |
+
{
|
704 |
+
return;
|
705 |
+
}
|
706 |
+
|
707 |
+
if (preg_match('/<\/'.$matches[1].'>[ ]*$/i', $remainder))
|
708 |
+
{
|
709 |
+
$Block['closed'] = true;
|
710 |
+
}
|
711 |
+
}
|
712 |
+
|
713 |
+
return $Block;
|
714 |
+
}
|
715 |
+
}
|
716 |
+
|
717 |
+
protected function blockMarkupContinue($Line, array $Block)
|
718 |
+
{
|
719 |
+
if (isset($Block['closed']))
|
720 |
+
{
|
721 |
+
return;
|
722 |
+
}
|
723 |
+
|
724 |
+
if (preg_match('/^<'.$Block['name'].'(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*>/i', $Line['text'])) # open
|
725 |
+
{
|
726 |
+
$Block['depth'] ++;
|
727 |
+
}
|
728 |
+
|
729 |
+
if (preg_match('/(.*?)<\/'.$Block['name'].'>[ ]*$/i', $Line['text'], $matches)) # close
|
730 |
+
{
|
731 |
+
if ($Block['depth'] > 0)
|
732 |
+
{
|
733 |
+
$Block['depth'] --;
|
734 |
+
}
|
735 |
+
else
|
736 |
+
{
|
737 |
+
$Block['closed'] = true;
|
738 |
+
}
|
739 |
+
|
740 |
+
$Block['markup'] .= $matches[1];
|
741 |
+
}
|
742 |
+
|
743 |
+
if (isset($Block['interrupted']))
|
744 |
+
{
|
745 |
+
$Block['markup'] .= "\n";
|
746 |
+
|
747 |
+
unset($Block['interrupted']);
|
748 |
+
}
|
749 |
+
|
750 |
+
$Block['markup'] .= "\n".$Line['body'];
|
751 |
+
|
752 |
+
return $Block;
|
753 |
+
}
|
754 |
+
|
755 |
+
#
|
756 |
+
# Reference
|
757 |
+
|
758 |
+
protected function blockReference($Line)
|
759 |
+
{
|
760 |
+
if (preg_match('/^\[(.+?)\]:[ ]*<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*$/', $Line['text'], $matches))
|
761 |
+
{
|
762 |
+
$id = strtolower($matches[1]);
|
763 |
+
|
764 |
+
$Data = array(
|
765 |
+
'url' => $matches[2],
|
766 |
+
'title' => null,
|
767 |
+
);
|
768 |
+
|
769 |
+
if (isset($matches[3]))
|
770 |
+
{
|
771 |
+
$Data['title'] = $matches[3];
|
772 |
+
}
|
773 |
+
|
774 |
+
$this->DefinitionData['Reference'][$id] = $Data;
|
775 |
+
|
776 |
+
$Block = array(
|
777 |
+
'hidden' => true,
|
778 |
+
);
|
779 |
+
|
780 |
+
return $Block;
|
781 |
+
}
|
782 |
+
}
|
783 |
+
|
784 |
+
#
|
785 |
+
# Table
|
786 |
+
|
787 |
+
protected function blockTable($Line, array $Block = null)
|
788 |
+
{
|
789 |
+
if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted']))
|
790 |
+
{
|
791 |
+
return;
|
792 |
+
}
|
793 |
+
|
794 |
+
if (strpos($Block['element']['text'], '|') !== false and chop($Line['text'], ' -:|') === '')
|
795 |
+
{
|
796 |
+
$alignments = array();
|
797 |
+
|
798 |
+
$divider = $Line['text'];
|
799 |
+
|
800 |
+
$divider = trim($divider);
|
801 |
+
$divider = trim($divider, '|');
|
802 |
+
|
803 |
+
$dividerCells = explode('|', $divider);
|
804 |
+
|
805 |
+
foreach ($dividerCells as $dividerCell)
|
806 |
+
{
|
807 |
+
$dividerCell = trim($dividerCell);
|
808 |
+
|
809 |
+
if ($dividerCell === '')
|
810 |
+
{
|
811 |
+
continue;
|
812 |
+
}
|
813 |
+
|
814 |
+
$alignment = null;
|
815 |
+
|
816 |
+
if ($dividerCell[0] === ':')
|
817 |
+
{
|
818 |
+
$alignment = 'left';
|
819 |
+
}
|
820 |
+
|
821 |
+
if (substr($dividerCell, - 1) === ':')
|
822 |
+
{
|
823 |
+
$alignment = $alignment === 'left' ? 'center' : 'right';
|
824 |
+
}
|
825 |
+
|
826 |
+
$alignments []= $alignment;
|
827 |
+
}
|
828 |
+
|
829 |
+
# ~
|
830 |
+
|
831 |
+
$HeaderElements = array();
|
832 |
+
|
833 |
+
$header = $Block['element']['text'];
|
834 |
+
|
835 |
+
$header = trim($header);
|
836 |
+
$header = trim($header, '|');
|
837 |
+
|
838 |
+
$headerCells = explode('|', $header);
|
839 |
+
|
840 |
+
foreach ($headerCells as $index => $headerCell)
|
841 |
+
{
|
842 |
+
$headerCell = trim($headerCell);
|
843 |
+
|
844 |
+
$HeaderElement = array(
|
845 |
+
'name' => 'th',
|
846 |
+
'text' => $headerCell,
|
847 |
+
'handler' => 'line',
|
848 |
+
);
|
849 |
+
|
850 |
+
if (isset($alignments[$index]))
|
851 |
+
{
|
852 |
+
$alignment = $alignments[$index];
|
853 |
+
|
854 |
+
$HeaderElement['attributes'] = array(
|
855 |
+
'style' => 'text-align: '.$alignment.';',
|
856 |
+
);
|
857 |
+
}
|
858 |
+
|
859 |
+
$HeaderElements []= $HeaderElement;
|
860 |
+
}
|
861 |
+
|
862 |
+
# ~
|
863 |
+
|
864 |
+
$Block = array(
|
865 |
+
'alignments' => $alignments,
|
866 |
+
'identified' => true,
|
867 |
+
'element' => array(
|
868 |
+
'name' => 'table',
|
869 |
+
'handler' => 'elements',
|
870 |
+
),
|
871 |
+
);
|
872 |
+
|
873 |
+
$Block['element']['text'] []= array(
|
874 |
+
'name' => 'thead',
|
875 |
+
'handler' => 'elements',
|
876 |
+
);
|
877 |
+
|
878 |
+
$Block['element']['text'] []= array(
|
879 |
+
'name' => 'tbody',
|
880 |
+
'handler' => 'elements',
|
881 |
+
'text' => array(),
|
882 |
+
);
|
883 |
+
|
884 |
+
$Block['element']['text'][0]['text'] []= array(
|
885 |
+
'name' => 'tr',
|
886 |
+
'handler' => 'elements',
|
887 |
+
'text' => $HeaderElements,
|
888 |
+
);
|
889 |
+
|
890 |
+
return $Block;
|
891 |
+
}
|
892 |
+
}
|
893 |
+
|
894 |
+
protected function blockTableContinue($Line, array $Block)
|
895 |
+
{
|
896 |
+
if (isset($Block['interrupted']))
|
897 |
+
{
|
898 |
+
return;
|
899 |
+
}
|
900 |
+
|
901 |
+
if ($Line['text'][0] === '|' or strpos($Line['text'], '|'))
|
902 |
+
{
|
903 |
+
$Elements = array();
|
904 |
+
|
905 |
+
$row = $Line['text'];
|
906 |
+
|
907 |
+
$row = trim($row);
|
908 |
+
$row = trim($row, '|');
|
909 |
+
|
910 |
+
preg_match_all('/(?:(\\\\[|])|[^|`]|`[^`]+`|`)+/', $row, $matches);
|
911 |
+
|
912 |
+
foreach ($matches[0] as $index => $cell)
|
913 |
+
{
|
914 |
+
$cell = trim($cell);
|
915 |
+
|
916 |
+
$Element = array(
|
917 |
+
'name' => 'td',
|
918 |
+
'handler' => 'line',
|
919 |
+
'text' => $cell,
|
920 |
+
);
|
921 |
+
|
922 |
+
if (isset($Block['alignments'][$index]))
|
923 |
+
{
|
924 |
+
$Element['attributes'] = array(
|
925 |
+
'style' => 'text-align: '.$Block['alignments'][$index].';',
|
926 |
+
);
|
927 |
+
}
|
928 |
+
|
929 |
+
$Elements []= $Element;
|
930 |
+
}
|
931 |
+
|
932 |
+
$Element = array(
|
933 |
+
'name' => 'tr',
|
934 |
+
'handler' => 'elements',
|
935 |
+
'text' => $Elements,
|
936 |
+
);
|
937 |
+
|
938 |
+
$Block['element']['text'][1]['text'] []= $Element;
|
939 |
+
|
940 |
+
return $Block;
|
941 |
+
}
|
942 |
+
}
|
943 |
+
|
944 |
+
#
|
945 |
+
# ~
|
946 |
+
#
|
947 |
+
|
948 |
+
protected function paragraph($Line)
|
949 |
+
{
|
950 |
+
$Block = array(
|
951 |
+
'element' => array(
|
952 |
+
'name' => 'p',
|
953 |
+
'text' => $Line['text'],
|
954 |
+
'handler' => 'line',
|
955 |
+
),
|
956 |
+
);
|
957 |
+
|
958 |
+
return $Block;
|
959 |
+
}
|
960 |
+
|
961 |
+
#
|
962 |
+
# Inline Elements
|
963 |
+
#
|
964 |
+
|
965 |
+
protected $InlineTypes = array(
|
966 |
+
'"' => array('SpecialCharacter'),
|
967 |
+
'!' => array('Image'),
|
968 |
+
'&' => array('SpecialCharacter'),
|
969 |
+
'*' => array('Emphasis'),
|
970 |
+
':' => array('Url'),
|
971 |
+
'<' => array('UrlTag', 'EmailTag', 'Markup', 'SpecialCharacter'),
|
972 |
+
'>' => array('SpecialCharacter'),
|
973 |
+
'[' => array('Link'),
|
974 |
+
'_' => array('Emphasis'),
|
975 |
+
'`' => array('Code'),
|
976 |
+
'~' => array('Strikethrough'),
|
977 |
+
'\\' => array('EscapeSequence'),
|
978 |
+
);
|
979 |
+
|
980 |
+
# ~
|
981 |
+
|
982 |
+
protected $inlineMarkerList = '!"*_&[:<>`~\\';
|
983 |
+
|
984 |
+
#
|
985 |
+
# ~
|
986 |
+
#
|
987 |
+
|
988 |
+
public function line($text)
|
989 |
+
{
|
990 |
+
$markup = '';
|
991 |
+
|
992 |
+
$unexaminedText = $text;
|
993 |
+
|
994 |
+
$markerPosition = 0;
|
995 |
+
|
996 |
+
while ($excerpt = strpbrk($unexaminedText, $this->inlineMarkerList))
|
997 |
+
{
|
998 |
+
$marker = $excerpt[0];
|
999 |
+
|
1000 |
+
$markerPosition += strpos($unexaminedText, $marker);
|
1001 |
+
|
1002 |
+
$Excerpt = array('text' => $excerpt, 'context' => $text);
|
1003 |
+
|
1004 |
+
foreach ($this->InlineTypes[$marker] as $inlineType)
|
1005 |
+
{
|
1006 |
+
$Inline = $this->{'inline'.$inlineType}($Excerpt);
|
1007 |
+
|
1008 |
+
if ( ! isset($Inline))
|
1009 |
+
{
|
1010 |
+
continue;
|
1011 |
+
}
|
1012 |
+
|
1013 |
+
if (isset($Inline['position']) and $Inline['position'] > $markerPosition) # position is ahead of marker
|
1014 |
+
{
|
1015 |
+
continue;
|
1016 |
+
}
|
1017 |
+
|
1018 |
+
if ( ! isset($Inline['position']))
|
1019 |
+
{
|
1020 |
+
$Inline['position'] = $markerPosition;
|
1021 |
+
}
|
1022 |
+
|
1023 |
+
$unmarkedText = substr($text, 0, $Inline['position']);
|
1024 |
+
|
1025 |
+
$markup .= $this->unmarkedText($unmarkedText);
|
1026 |
+
|
1027 |
+
$markup .= isset($Inline['markup']) ? $Inline['markup'] : $this->element($Inline['element']);
|
1028 |
+
|
1029 |
+
$text = substr($text, $Inline['position'] + $Inline['extent']);
|
1030 |
+
|
1031 |
+
$unexaminedText = $text;
|
1032 |
+
|
1033 |
+
$markerPosition = 0;
|
1034 |
+
|
1035 |
+
continue 2;
|
1036 |
+
}
|
1037 |
+
|
1038 |
+
$unexaminedText = substr($excerpt, 1);
|
1039 |
+
|
1040 |
+
$markerPosition ++;
|
1041 |
+
}
|
1042 |
+
|
1043 |
+
$markup .= $this->unmarkedText($text);
|
1044 |
+
|
1045 |
+
return $markup;
|
1046 |
+
}
|
1047 |
+
|
1048 |
+
#
|
1049 |
+
# ~
|
1050 |
+
#
|
1051 |
+
|
1052 |
+
protected function inlineCode($Excerpt)
|
1053 |
+
{
|
1054 |
+
$marker = $Excerpt['text'][0];
|
1055 |
+
|
1056 |
+
if (preg_match('/^('.$marker.'+)[ ]*(.+?)[ ]*(?<!'.$marker.')\1(?!'.$marker.')/s', $Excerpt['text'], $matches))
|
1057 |
+
{
|
1058 |
+
$text = $matches[2];
|
1059 |
+
$text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
|
1060 |
+
$text = preg_replace("/[ ]*\n/", ' ', $text);
|
1061 |
+
|
1062 |
+
return array(
|
1063 |
+
'extent' => strlen($matches[0]),
|
1064 |
+
'element' => array(
|
1065 |
+
'name' => 'code',
|
1066 |
+
'text' => $text,
|
1067 |
+
),
|
1068 |
+
);
|
1069 |
+
}
|
1070 |
+
}
|
1071 |
+
|
1072 |
+
protected function inlineEmailTag($Excerpt)
|
1073 |
+
{
|
1074 |
+
if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<((mailto:)?\S+?@\S+?)>/i', $Excerpt['text'], $matches))
|
1075 |
+
{
|
1076 |
+
$url = $matches[1];
|
1077 |
+
|
1078 |
+
if ( ! isset($matches[2]))
|
1079 |
+
{
|
1080 |
+
$url = 'mailto:' . $url;
|
1081 |
+
}
|
1082 |
+
|
1083 |
+
return array(
|
1084 |
+
'extent' => strlen($matches[0]),
|
1085 |
+
'element' => array(
|
1086 |
+
'name' => 'a',
|
1087 |
+
'text' => $matches[1],
|
1088 |
+
'attributes' => array(
|
1089 |
+
'href' => $url,
|
1090 |
+
),
|
1091 |
+
),
|
1092 |
+
);
|
1093 |
+
}
|
1094 |
+
}
|
1095 |
+
|
1096 |
+
protected function inlineEmphasis($Excerpt)
|
1097 |
+
{
|
1098 |
+
if ( ! isset($Excerpt['text'][1]))
|
1099 |
+
{
|
1100 |
+
return;
|
1101 |
+
}
|
1102 |
+
|
1103 |
+
$marker = $Excerpt['text'][0];
|
1104 |
+
|
1105 |
+
if ($Excerpt['text'][1] === $marker and preg_match($this->StrongRegex[$marker], $Excerpt['text'], $matches))
|
1106 |
+
{
|
1107 |
+
$emphasis = 'strong';
|
1108 |
+
}
|
1109 |
+
elseif (preg_match($this->EmRegex[$marker], $Excerpt['text'], $matches))
|
1110 |
+
{
|
1111 |
+
$emphasis = 'em';
|
1112 |
+
}
|
1113 |
+
else
|
1114 |
+
{
|
1115 |
+
return;
|
1116 |
+
}
|
1117 |
+
|
1118 |
+
return array(
|
1119 |
+
'extent' => strlen($matches[0]),
|
1120 |
+
'element' => array(
|
1121 |
+
'name' => $emphasis,
|
1122 |
+
'handler' => 'line',
|
1123 |
+
'text' => $matches[1],
|
1124 |
+
),
|
1125 |
+
);
|
1126 |
+
}
|
1127 |
+
|
1128 |
+
protected function inlineEscapeSequence($Excerpt)
|
1129 |
+
{
|
1130 |
+
if (isset($Excerpt['text'][1]) and in_array($Excerpt['text'][1], $this->specialCharacters))
|
1131 |
+
{
|
1132 |
+
return array(
|
1133 |
+
'markup' => $Excerpt['text'][1],
|
1134 |
+
'extent' => 2,
|
1135 |
+
);
|
1136 |
+
}
|
1137 |
+
}
|
1138 |
+
|
1139 |
+
protected function inlineImage($Excerpt)
|
1140 |
+
{
|
1141 |
+
if ( ! isset($Excerpt['text'][1]) or $Excerpt['text'][1] !== '[')
|
1142 |
+
{
|
1143 |
+
return;
|
1144 |
+
}
|
1145 |
+
|
1146 |
+
$Excerpt['text']= substr($Excerpt['text'], 1);
|
1147 |
+
|
1148 |
+
$Link = $this->inlineLink($Excerpt);
|
1149 |
+
|
1150 |
+
if ($Link === null)
|
1151 |
+
{
|
1152 |
+
return;
|
1153 |
+
}
|
1154 |
+
|
1155 |
+
$Inline = array(
|
1156 |
+
'extent' => $Link['extent'] + 1,
|
1157 |
+
'element' => array(
|
1158 |
+
'name' => 'img',
|
1159 |
+
'attributes' => array(
|
1160 |
+
'src' => $Link['element']['attributes']['href'],
|
1161 |
+
'alt' => $Link['element']['text'],
|
1162 |
+
),
|
1163 |
+
),
|
1164 |
+
);
|
1165 |
+
|
1166 |
+
$Inline['element']['attributes'] += $Link['element']['attributes'];
|
1167 |
+
|
1168 |
+
unset($Inline['element']['attributes']['href']);
|
1169 |
+
|
1170 |
+
return $Inline;
|
1171 |
+
}
|
1172 |
+
|
1173 |
+
protected function inlineLink($Excerpt)
|
1174 |
+
{
|
1175 |
+
$Element = array(
|
1176 |
+
'name' => 'a',
|
1177 |
+
'handler' => 'line',
|
1178 |
+
'text' => null,
|
1179 |
+
'attributes' => array(
|
1180 |
+
'href' => null,
|
1181 |
+
'title' => null,
|
1182 |
+
),
|
1183 |
+
);
|
1184 |
+
|
1185 |
+
$extent = 0;
|
1186 |
+
|
1187 |
+
$remainder = $Excerpt['text'];
|
1188 |
+
|
1189 |
+
if (preg_match('/\[((?:[^][]|(?R))*)\]/', $remainder, $matches))
|
1190 |
+
{
|
1191 |
+
$Element['text'] = $matches[1];
|
1192 |
+
|
1193 |
+
$extent += strlen($matches[0]);
|
1194 |
+
|
1195 |
+
$remainder = substr($remainder, $extent);
|
1196 |
+
}
|
1197 |
+
else
|
1198 |
+
{
|
1199 |
+
return;
|
1200 |
+
}
|
1201 |
+
|
1202 |
+
if (preg_match('/^[(]((?:[^ (]|[(][^ )]+[)])+)(?:[ ]+("[^"]+"|\'[^\']+\'))?[)]/', $remainder, $matches))
|
1203 |
+
{
|
1204 |
+
$Element['attributes']['href'] = $matches[1];
|
1205 |
+
|
1206 |
+
if (isset($matches[2]))
|
1207 |
+
{
|
1208 |
+
$Element['attributes']['title'] = substr($matches[2], 1, - 1);
|
1209 |
+
}
|
1210 |
+
|
1211 |
+
$extent += strlen($matches[0]);
|
1212 |
+
}
|
1213 |
+
else
|
1214 |
+
{
|
1215 |
+
if (preg_match('/^\s*\[(.*?)\]/', $remainder, $matches))
|
1216 |
+
{
|
1217 |
+
$definition = $matches[1] ? $matches[1] : $Element['text'];
|
1218 |
+
$definition = strtolower($definition);
|
1219 |
+
|
1220 |
+
$extent += strlen($matches[0]);
|
1221 |
+
}
|
1222 |
+
else
|
1223 |
+
{
|
1224 |
+
$definition = strtolower($Element['text']);
|
1225 |
+
}
|
1226 |
+
|
1227 |
+
if ( ! isset($this->DefinitionData['Reference'][$definition]))
|
1228 |
+
{
|
1229 |
+
return;
|
1230 |
+
}
|
1231 |
+
|
1232 |
+
$Definition = $this->DefinitionData['Reference'][$definition];
|
1233 |
+
|
1234 |
+
$Element['attributes']['href'] = $Definition['url'];
|
1235 |
+
$Element['attributes']['title'] = $Definition['title'];
|
1236 |
+
}
|
1237 |
+
|
1238 |
+
$Element['attributes']['href'] = str_replace(array('&', '<'), array('&', '<'), $Element['attributes']['href']);
|
1239 |
+
|
1240 |
+
return array(
|
1241 |
+
'extent' => $extent,
|
1242 |
+
'element' => $Element,
|
1243 |
+
);
|
1244 |
+
}
|
1245 |
+
|
1246 |
+
protected function inlineMarkup($Excerpt)
|
1247 |
+
{
|
1248 |
+
if ($this->markupEscaped or strpos($Excerpt['text'], '>') === false)
|
1249 |
+
{
|
1250 |
+
return;
|
1251 |
+
}
|
1252 |
+
|
1253 |
+
if ($Excerpt['text'][1] === '/' and preg_match('/^<\/\w*[ ]*>/s', $Excerpt['text'], $matches))
|
1254 |
+
{
|
1255 |
+
return array(
|
1256 |
+
'markup' => $matches[0],
|
1257 |
+
'extent' => strlen($matches[0]),
|
1258 |
+
);
|
1259 |
+
}
|
1260 |
+
|
1261 |
+
if ($Excerpt['text'][1] === '!' and preg_match('/^<!---?[^>-](?:-?[^-])*-->/s', $Excerpt['text'], $matches))
|
1262 |
+
{
|
1263 |
+
return array(
|
1264 |
+
'markup' => $matches[0],
|
1265 |
+
'extent' => strlen($matches[0]),
|
1266 |
+
);
|
1267 |
+
}
|
1268 |
+
|
1269 |
+
if ($Excerpt['text'][1] !== ' ' and preg_match('/^<\w*(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*\/?>/s', $Excerpt['text'], $matches))
|
1270 |
+
{
|
1271 |
+
return array(
|
1272 |
+
'markup' => $matches[0],
|
1273 |
+
'extent' => strlen($matches[0]),
|
1274 |
+
);
|
1275 |
+
}
|
1276 |
+
}
|
1277 |
+
|
1278 |
+
protected function inlineSpecialCharacter($Excerpt)
|
1279 |
+
{
|
1280 |
+
if ($Excerpt['text'][0] === '&' and ! preg_match('/^&#?\w+;/', $Excerpt['text']))
|
1281 |
+
{
|
1282 |
+
return array(
|
1283 |
+
'markup' => '&',
|
1284 |
+
'extent' => 1,
|
1285 |
+
);
|
1286 |
+
}
|
1287 |
+
|
1288 |
+
$SpecialCharacter = array('>' => 'gt', '<' => 'lt', '"' => 'quot');
|
1289 |
+
|
1290 |
+
if (isset($SpecialCharacter[$Excerpt['text'][0]]))
|
1291 |
+
{
|
1292 |
+
return array(
|
1293 |
+
'markup' => '&'.$SpecialCharacter[$Excerpt['text'][0]].';',
|
1294 |
+
'extent' => 1,
|
1295 |
+
);
|
1296 |
+
}
|
1297 |
+
}
|
1298 |
+
|
1299 |
+
protected function inlineStrikethrough($Excerpt)
|
1300 |
+
{
|
1301 |
+
if ( ! isset($Excerpt['text'][1]))
|
1302 |
+
{
|
1303 |
+
return;
|
1304 |
+
}
|
1305 |
+
|
1306 |
+
if ($Excerpt['text'][1] === '~' and preg_match('/^~~(?=\S)(.+?)(?<=\S)~~/', $Excerpt['text'], $matches))
|
1307 |
+
{
|
1308 |
+
return array(
|
1309 |
+
'extent' => strlen($matches[0]),
|
1310 |
+
'element' => array(
|
1311 |
+
'name' => 'del',
|
1312 |
+
'text' => $matches[1],
|
1313 |
+
'handler' => 'line',
|
1314 |
+
),
|
1315 |
+
);
|
1316 |
+
}
|
1317 |
+
}
|
1318 |
+
|
1319 |
+
protected function inlineUrl($Excerpt)
|
1320 |
+
{
|
1321 |
+
if ($this->urlsLinked !== true or ! isset($Excerpt['text'][2]) or $Excerpt['text'][2] !== '/')
|
1322 |
+
{
|
1323 |
+
return;
|
1324 |
+
}
|
1325 |
+
|
1326 |
+
if (preg_match('/\bhttps?:[\/]{2}[^\s<]+\b\/*/ui', $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE))
|
1327 |
+
{
|
1328 |
+
$Inline = array(
|
1329 |
+
'extent' => strlen($matches[0][0]),
|
1330 |
+
'position' => $matches[0][1],
|
1331 |
+
'element' => array(
|
1332 |
+
'name' => 'a',
|
1333 |
+
'text' => $matches[0][0],
|
1334 |
+
'attributes' => array(
|
1335 |
+
'href' => $matches[0][0],
|
1336 |
+
),
|
1337 |
+
),
|
1338 |
+
);
|
1339 |
+
|
1340 |
+
return $Inline;
|
1341 |
+
}
|
1342 |
+
}
|
1343 |
+
|
1344 |
+
protected function inlineUrlTag($Excerpt)
|
1345 |
+
{
|
1346 |
+
if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<(\w+:\/{2}[^ >]+)>/i', $Excerpt['text'], $matches))
|
1347 |
+
{
|
1348 |
+
$url = str_replace(array('&', '<'), array('&', '<'), $matches[1]);
|
1349 |
+
|
1350 |
+
return array(
|
1351 |
+
'extent' => strlen($matches[0]),
|
1352 |
+
'element' => array(
|
1353 |
+
'name' => 'a',
|
1354 |
+
'text' => $url,
|
1355 |
+
'attributes' => array(
|
1356 |
+
'href' => $url,
|
1357 |
+
),
|
1358 |
+
),
|
1359 |
+
);
|
1360 |
+
}
|
1361 |
+
}
|
1362 |
+
|
1363 |
+
#
|
1364 |
+
# ~
|
1365 |
+
|
1366 |
+
protected $unmarkedInlineTypes = array("\n" => 'Break', '://' => 'Url');
|
1367 |
+
|
1368 |
+
# ~
|
1369 |
+
|
1370 |
+
protected function unmarkedText($text)
|
1371 |
+
{
|
1372 |
+
if ($this->breaksEnabled)
|
1373 |
+
{
|
1374 |
+
$text = preg_replace('/[ ]*\n/', "<br />\n", $text);
|
1375 |
+
}
|
1376 |
+
else
|
1377 |
+
{
|
1378 |
+
$text = preg_replace('/(?:[ ][ ]+|[ ]*\\\\)\n/', "<br />\n", $text);
|
1379 |
+
$text = str_replace(" \n", "\n", $text);
|
1380 |
+
}
|
1381 |
+
|
1382 |
+
return $text;
|
1383 |
+
}
|
1384 |
+
|
1385 |
+
#
|
1386 |
+
# Handlers
|
1387 |
+
#
|
1388 |
+
|
1389 |
+
protected function element(array $Element)
|
1390 |
+
{
|
1391 |
+
$markup = '<'.$Element['name'];
|
1392 |
+
|
1393 |
+
if (isset($Element['attributes']))
|
1394 |
+
{
|
1395 |
+
foreach ($Element['attributes'] as $name => $value)
|
1396 |
+
{
|
1397 |
+
if ($value === null)
|
1398 |
+
{
|
1399 |
+
continue;
|
1400 |
+
}
|
1401 |
+
|
1402 |
+
$markup .= ' '.$name.'="'.$value.'"';
|
1403 |
+
}
|
1404 |
+
}
|
1405 |
+
|
1406 |
+
if (isset($Element['text']))
|
1407 |
+
{
|
1408 |
+
$markup .= '>';
|
1409 |
+
|
1410 |
+
if (isset($Element['handler']))
|
1411 |
+
{
|
1412 |
+
$markup .= $this->$Element['handler']($Element['text']);
|
1413 |
+
}
|
1414 |
+
else
|
1415 |
+
{
|
1416 |
+
$markup .= $Element['text'];
|
1417 |
+
}
|
1418 |
+
|
1419 |
+
$markup .= '</'.$Element['name'].'>';
|
1420 |
+
}
|
1421 |
+
else
|
1422 |
+
{
|
1423 |
+
$markup .= ' />';
|
1424 |
+
}
|
1425 |
+
|
1426 |
+
return $markup;
|
1427 |
+
}
|
1428 |
+
|
1429 |
+
protected function elements(array $Elements)
|
1430 |
+
{
|
1431 |
+
$markup = '';
|
1432 |
+
|
1433 |
+
foreach ($Elements as $Element)
|
1434 |
+
{
|
1435 |
+
$markup .= "\n" . $this->element($Element);
|
1436 |
+
}
|
1437 |
+
|
1438 |
+
$markup .= "\n";
|
1439 |
+
|
1440 |
+
return $markup;
|
1441 |
+
}
|
1442 |
+
|
1443 |
+
# ~
|
1444 |
+
|
1445 |
+
protected function li($lines)
|
1446 |
+
{
|
1447 |
+
$markup = $this->lines($lines);
|
1448 |
+
|
1449 |
+
$trimmedMarkup = trim($markup);
|
1450 |
+
|
1451 |
+
if ( ! in_array('', $lines) and substr($trimmedMarkup, 0, 3) === '<p>')
|
1452 |
+
{
|
1453 |
+
$markup = $trimmedMarkup;
|
1454 |
+
$markup = substr($markup, 3);
|
1455 |
+
|
1456 |
+
$position = strpos($markup, "</p>");
|
1457 |
+
|
1458 |
+
$markup = substr_replace($markup, '', $position, 4);
|
1459 |
+
}
|
1460 |
+
|
1461 |
+
return $markup;
|
1462 |
+
}
|
1463 |
+
|
1464 |
+
#
|
1465 |
+
# Deprecated Methods
|
1466 |
+
#
|
1467 |
+
|
1468 |
+
function parse($text)
|
1469 |
+
{
|
1470 |
+
$markup = $this->text($text);
|
1471 |
+
|
1472 |
+
return $markup;
|
1473 |
+
}
|
1474 |
+
|
1475 |
+
#
|
1476 |
+
# Static Methods
|
1477 |
+
#
|
1478 |
+
|
1479 |
+
static function instance($name = 'default')
|
1480 |
+
{
|
1481 |
+
if (isset(self::$instances[$name]))
|
1482 |
+
{
|
1483 |
+
return self::$instances[$name];
|
1484 |
+
}
|
1485 |
+
|
1486 |
+
$instance = new self();
|
1487 |
+
|
1488 |
+
self::$instances[$name] = $instance;
|
1489 |
+
|
1490 |
+
return $instance;
|
1491 |
+
}
|
1492 |
+
|
1493 |
+
private static $instances = array();
|
1494 |
+
|
1495 |
+
#
|
1496 |
+
# Fields
|
1497 |
+
#
|
1498 |
+
|
1499 |
+
protected $DefinitionData;
|
1500 |
+
|
1501 |
+
#
|
1502 |
+
# Read-Only
|
1503 |
+
|
1504 |
+
protected $specialCharacters = array(
|
1505 |
+
'\\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '>', '#', '+', '-', '.', '!', '|',
|
1506 |
+
);
|
1507 |
+
|
1508 |
+
protected $StrongRegex = array(
|
1509 |
+
'*' => '/^[*]{2}((?:\\\\\*|[^*]|[*][^*]*[*])+?)[*]{2}(?![*])/s',
|
1510 |
+
'_' => '/^__((?:\\\\_|[^_]|_[^_]*_)+?)__(?!_)/us',
|
1511 |
+
);
|
1512 |
+
|
1513 |
+
protected $EmRegex = array(
|
1514 |
+
'*' => '/^[*]((?:\\\\\*|[^*]|[*][*][^*]+?[*][*])+?)[*](?![*])/s',
|
1515 |
+
'_' => '/^_((?:\\\\_|[^_]|__[^_]*__)+?)_(?!_)\b/us',
|
1516 |
+
);
|
1517 |
+
|
1518 |
+
protected $regexHtmlAttribute = '[a-zA-Z_:][\w:.-]*(?:\s*=\s*(?:[^"\'=<>`\s]+|"[^"]*"|\'[^\']*\'))?';
|
1519 |
+
|
1520 |
+
protected $voidElements = array(
|
1521 |
+
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source',
|
1522 |
+
);
|
1523 |
+
|
1524 |
+
protected $textLevelElements = array(
|
1525 |
+
'a', 'br', 'bdo', 'abbr', 'blink', 'nextid', 'acronym', 'basefont',
|
1526 |
+
'b', 'em', 'big', 'cite', 'small', 'spacer', 'listing',
|
1527 |
+
'i', 'rp', 'del', 'code', 'strike', 'marquee',
|
1528 |
+
'q', 'rt', 'ins', 'font', 'strong',
|
1529 |
+
's', 'tt', 'sub', 'mark',
|
1530 |
+
'u', 'xm', 'sup', 'nobr',
|
1531 |
+
'var', 'ruby',
|
1532 |
+
'wbr', 'span',
|
1533 |
+
'time',
|
1534 |
+
);
|
1535 |
+
}
|
vendor/yahnis-elsts/plugin-update-checker/vendor/readme-parser.php
ADDED
@@ -0,0 +1,334 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if ( !class_exists('PucReadmeParser', false) ):
|
4 |
+
|
5 |
+
/**
|
6 |
+
* This is a slightly modified version of github.com/markjaquith/WordPress-Plugin-Readme-Parser
|
7 |
+
* It uses Parsedown instead of the "Markdown Extra" parser.
|
8 |
+
*/
|
9 |
+
|
10 |
+
class PucReadmeParser {
|
11 |
+
|
12 |
+
function __construct() {
|
13 |
+
// This space intentionally blank
|
14 |
+
}
|
15 |
+
|
16 |
+
function parse_readme( $file ) {
|
17 |
+
$file_contents = @implode('', @file($file));
|
18 |
+
return $this->parse_readme_contents( $file_contents );
|
19 |
+
}
|
20 |
+
|
21 |
+
function parse_readme_contents( $file_contents ) {
|
22 |
+
$file_contents = str_replace(array("\r\n", "\r"), "\n", $file_contents);
|
23 |
+
$file_contents = trim($file_contents);
|
24 |
+
if ( 0 === strpos( $file_contents, "\xEF\xBB\xBF" ) )
|
25 |
+
$file_contents = substr( $file_contents, 3 );
|
26 |
+
|
27 |
+
// Markdown transformations
|
28 |
+
$file_contents = preg_replace( "|^###([^#]+)#*?\s*?\n|im", '=$1='."\n", $file_contents );
|
29 |
+
$file_contents = preg_replace( "|^##([^#]+)#*?\s*?\n|im", '==$1=='."\n", $file_contents );
|
30 |
+
$file_contents = preg_replace( "|^#([^#]+)#*?\s*?\n|im", '===$1==='."\n", $file_contents );
|
31 |
+
|
32 |
+
// === Plugin Name ===
|
33 |
+
// Must be the very first thing.
|
34 |
+
if ( !preg_match('|^===(.*)===|', $file_contents, $_name) )
|
35 |
+
return array(); // require a name
|
36 |
+
$name = trim($_name[1], '=');
|
37 |
+
$name = $this->sanitize_text( $name );
|
38 |
+
|
39 |
+
$file_contents = $this->chop_string( $file_contents, $_name[0] );
|
40 |
+
|
41 |
+
|
42 |
+
// Requires at least: 1.5
|
43 |
+
if ( preg_match('|Requires at least:(.*)|i', $file_contents, $_requires_at_least) )
|
44 |
+
$requires_at_least = $this->sanitize_text($_requires_at_least[1]);
|
45 |
+
else
|
46 |
+
$requires_at_least = NULL;
|
47 |
+
|
48 |
+
|
49 |
+
// Tested up to: 2.1
|
50 |
+
if ( preg_match('|Tested up to:(.*)|i', $file_contents, $_tested_up_to) )
|
51 |
+
$tested_up_to = $this->sanitize_text( $_tested_up_to[1] );
|
52 |
+
else
|
53 |
+
$tested_up_to = NULL;
|
54 |
+
|
55 |
+
|
56 |
+
// Stable tag: 10.4-ride-the-fire-eagle-danger-day
|
57 |
+
if ( preg_match('|Stable tag:(.*)|i', $file_contents, $_stable_tag) )
|
58 |
+
$stable_tag = $this->sanitize_text( $_stable_tag[1] );
|
59 |
+
else
|
60 |
+
$stable_tag = NULL; // we assume trunk, but don't set it here to tell the difference between specified trunk and default trunk
|
61 |
+
|
62 |
+
|
63 |
+
// Tags: some tag, another tag, we like tags
|
64 |
+
if ( preg_match('|Tags:(.*)|i', $file_contents, $_tags) ) {
|
65 |
+
$tags = preg_split('|,[\s]*?|', trim($_tags[1]));
|
66 |
+
foreach ( array_keys($tags) as $t )
|
67 |
+
$tags[$t] = $this->sanitize_text( $tags[$t] );
|
68 |
+
} else {
|
69 |
+
$tags = array();
|
70 |
+
}
|
71 |
+
|
72 |
+
|
73 |
+
// Contributors: markjaquith, mdawaffe, zefrank
|
74 |
+
$contributors = array();
|
75 |
+
if ( preg_match('|Contributors:(.*)|i', $file_contents, $_contributors) ) {
|
76 |
+
$temp_contributors = preg_split('|,[\s]*|', trim($_contributors[1]));
|
77 |
+
foreach ( array_keys($temp_contributors) as $c ) {
|
78 |
+
$tmp_sanitized = $this->user_sanitize( $temp_contributors[$c] );
|
79 |
+
if ( strlen(trim($tmp_sanitized)) > 0 )
|
80 |
+
$contributors[$c] = $tmp_sanitized;
|
81 |
+
unset($tmp_sanitized);
|
82 |
+
}
|
83 |
+
}
|
84 |
+
|
85 |
+
|
86 |
+
// Donate Link: URL
|
87 |
+
if ( preg_match('|Donate link:(.*)|i', $file_contents, $_donate_link) )
|
88 |
+
$donate_link = esc_url( $_donate_link[1] );
|
89 |
+
else
|
90 |
+
$donate_link = NULL;
|
91 |
+
|
92 |
+
|
93 |
+
// togs, conts, etc are optional and order shouldn't matter. So we chop them only after we've grabbed their values.
|
94 |
+
foreach ( array('tags', 'contributors', 'requires_at_least', 'tested_up_to', 'stable_tag', 'donate_link') as $chop ) {
|
95 |
+
if ( $$chop ) {
|
96 |
+
$_chop = '_' . $chop;
|
97 |
+
$file_contents = $this->chop_string( $file_contents, ${$_chop}[0] );
|
98 |
+
}
|
99 |
+
}
|
100 |
+
|
101 |
+
$file_contents = trim($file_contents);
|
102 |
+
|
103 |
+
|
104 |
+
// short-description fu
|
105 |
+
if ( !preg_match('/(^(.*?))^[\s]*=+?[\s]*.+?[\s]*=+?/ms', $file_contents, $_short_description) )
|
106 |
+
$_short_description = array( 1 => &$file_contents, 2 => &$file_contents );
|
107 |
+
$short_desc_filtered = $this->sanitize_text( $_short_description[2] );
|
108 |
+
$short_desc_length = strlen($short_desc_filtered);
|
109 |
+
$short_description = substr($short_desc_filtered, 0, 150);
|
110 |
+
if ( $short_desc_length > strlen($short_description) )
|
111 |
+
$truncated = true;
|
112 |
+
else
|
113 |
+
$truncated = false;
|
114 |
+
if ( $_short_description[1] )
|
115 |
+
$file_contents = $this->chop_string( $file_contents, $_short_description[1] ); // yes, the [1] is intentional
|
116 |
+
|
117 |
+
// == Section ==
|
118 |
+
// Break into sections
|
119 |
+
// $_sections[0] will be the title of the first section, $_sections[1] will be the content of the first section
|
120 |
+
// the array alternates from there: title2, content2, title3, content3... and so forth
|
121 |
+
$_sections = preg_split('/^[\s]*==[\s]*(.+?)[\s]*==/m', $file_contents, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
|
122 |
+
|
123 |
+
$sections = array();
|
124 |
+
for ( $i=1; $i <= count($_sections); $i +=2 ) {
|
125 |
+
$_sections[$i] = preg_replace('/(^[\s]*)=[\s]+(.+?)[\s]+=/m', '$1<h4>$2</h4>', $_sections[$i]);
|
126 |
+
$_sections[$i] = $this->filter_text( $_sections[$i], true );
|
127 |
+
$title = $this->sanitize_text( $_sections[$i-1] );
|
128 |
+
$sections[str_replace(' ', '_', strtolower($title))] = array('title' => $title, 'content' => $_sections[$i]);
|
129 |
+
}
|
130 |
+
|
131 |
+
|
132 |
+
// Special sections
|
133 |
+
// This is where we nab our special sections, so we can enforce their order and treat them differently, if needed
|
134 |
+
// upgrade_notice is not a section, but parse it like it is for now
|
135 |
+
$final_sections = array();
|
136 |
+
foreach ( array('description', 'installation', 'frequently_asked_questions', 'screenshots', 'changelog', 'change_log', 'upgrade_notice') as $special_section ) {
|
137 |
+
if ( isset($sections[$special_section]) ) {
|
138 |
+
$final_sections[$special_section] = $sections[$special_section]['content'];
|
139 |
+
unset($sections[$special_section]);
|
140 |
+
}
|
141 |
+
}
|
142 |
+
if ( isset($final_sections['change_log']) && empty($final_sections['changelog']) )
|
143 |
+
$final_sections['changelog'] = $final_sections['change_log'];
|
144 |
+
|
145 |
+
|
146 |
+
$final_screenshots = array();
|
147 |
+
if ( isset($final_sections['screenshots']) ) {
|
148 |
+
preg_match_all('|<li>(.*?)</li>|s', $final_sections['screenshots'], $screenshots, PREG_SET_ORDER);
|
149 |
+
if ( $screenshots ) {
|
150 |
+
foreach ( (array) $screenshots as $ss )
|
151 |
+
$final_screenshots[] = $ss[1];
|
152 |
+
}
|
153 |
+
}
|
154 |
+
|
155 |
+
// Parse the upgrade_notice section specially:
|
156 |
+
// 1.0 => blah, 1.1 => fnord
|
157 |
+
$upgrade_notice = array();
|
158 |
+
if ( isset($final_sections['upgrade_notice']) ) {
|
159 |
+
$split = preg_split( '#<h4>(.*?)</h4>#', $final_sections['upgrade_notice'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
|
160 |
+
for ( $i = 0; $i < count( $split ); $i += 2 )
|
161 |
+
$upgrade_notice[$this->sanitize_text( $split[$i] )] = substr( $this->sanitize_text( $split[$i + 1] ), 0, 300 );
|
162 |
+
unset( $final_sections['upgrade_notice'] );
|
163 |
+
}
|
164 |
+
|
165 |
+
// No description?
|
166 |
+
// No problem... we'll just fall back to the old style of description
|
167 |
+
// We'll even let you use markup this time!
|
168 |
+
$excerpt = false;
|
169 |
+
if ( !isset($final_sections['description']) ) {
|
170 |
+
$final_sections = array_merge(array('description' => $this->filter_text( $_short_description[2], true )), $final_sections);
|
171 |
+
$excerpt = true;
|
172 |
+
}
|
173 |
+
|
174 |
+
|
175 |
+
// dump the non-special sections into $remaining_content
|
176 |
+
// their order will be determined by their original order in the readme.txt
|
177 |
+
$remaining_content = '';
|
178 |
+
foreach ( $sections as $s_name => $s_data ) {
|
179 |
+
$remaining_content .= "\n<h3>{$s_data['title']}</h3>\n{$s_data['content']}";
|
180 |
+
}
|
181 |
+
$remaining_content = trim($remaining_content);
|
182 |
+
|
183 |
+
|
184 |
+
// All done!
|
185 |
+
// $r['tags'] and $r['contributors'] are simple arrays
|
186 |
+
// $r['sections'] is an array with named elements
|
187 |
+
$r = array(
|
188 |
+
'name' => $name,
|
189 |
+
'tags' => $tags,
|
190 |
+
'requires_at_least' => $requires_at_least,
|
191 |
+
'tested_up_to' => $tested_up_to,
|
192 |
+
'stable_tag' => $stable_tag,
|
193 |
+
'contributors' => $contributors,
|
194 |
+
'donate_link' => $donate_link,
|
195 |
+
'short_description' => $short_description,
|
196 |
+
'screenshots' => $final_screenshots,
|
197 |
+
'is_excerpt' => $excerpt,
|
198 |
+
'is_truncated' => $truncated,
|
199 |
+
'sections' => $final_sections,
|
200 |
+
'remaining_content' => $remaining_content,
|
201 |
+
'upgrade_notice' => $upgrade_notice
|
202 |
+
);
|
203 |
+
|
204 |
+
return $r;
|
205 |
+
}
|
206 |
+
|
207 |
+
function chop_string( $string, $chop ) { // chop a "prefix" from a string: Agressive! uses strstr not 0 === strpos
|
208 |
+
if ( $_string = strstr($string, $chop) ) {
|
209 |
+
$_string = substr($_string, strlen($chop));
|
210 |
+
return trim($_string);
|
211 |
+
} else {
|
212 |
+
return trim($string);
|
213 |
+
}
|
214 |
+
}
|
215 |
+
|
216 |
+
function user_sanitize( $text, $strict = false ) { // whitelisted chars
|
217 |
+
if ( function_exists('user_sanitize') ) // bbPress native
|
218 |
+
return user_sanitize( $text, $strict );
|
219 |
+
|
220 |
+
if ( $strict ) {
|
221 |
+
$text = preg_replace('/[^a-z0-9-]/i', '', $text);
|
222 |
+
$text = preg_replace('|-+|', '-', $text);
|
223 |
+
} else {
|
224 |
+
$text = preg_replace('/[^a-z0-9_-]/i', '', $text);
|
225 |
+
}
|
226 |
+
return $text;
|
227 |
+
}
|
228 |
+
|
229 |
+
function sanitize_text( $text ) { // not fancy
|
230 |
+
$text = strip_tags($text);
|
231 |
+
$text = esc_html($text);
|
232 |
+
$text = trim($text);
|
233 |
+
return $text;
|
234 |
+
}
|
235 |
+
|
236 |
+
function filter_text( $text, $markdown = false ) { // fancy, Markdown
|
237 |
+
$text = trim($text);
|
238 |
+
|
239 |
+
$text = call_user_func( array( __CLASS__, 'code_trick' ), $text, $markdown ); // A better parser than Markdown's for: backticks -> CODE
|
240 |
+
|
241 |
+
if ( $markdown ) { // Parse markdown.
|
242 |
+
if ( !class_exists('Parsedown', false) ) {
|
243 |
+
/** @noinspection PhpIncludeInspection */
|
244 |
+
require_once(dirname(__FILE__) . '/Parsedown' . (version_compare(PHP_VERSION, '5.3.0', '>=') ? '' : 'Legacy') . '.php');
|
245 |
+
}
|
246 |
+
$instance = Parsedown::instance();
|
247 |
+
$text = $instance->text($text);
|
248 |
+
}
|
249 |
+
|
250 |
+
$allowed = array(
|
251 |
+
'a' => array(
|
252 |
+
'href' => array(),
|
253 |
+
'title' => array(),
|
254 |
+
'rel' => array()),
|
255 |
+
'blockquote' => array('cite' => array()),
|
256 |
+
'br' => array(),
|
257 |
+
'p' => array(),
|
258 |
+
'code' => array(),
|
259 |
+
'pre' => array(),
|
260 |
+
'em' => array(),
|
261 |
+
'strong' => array(),
|
262 |
+
'ul' => array(),
|
263 |
+
'ol' => array(),
|
264 |
+
'li' => array(),
|
265 |
+
'h3' => array(),
|
266 |
+
'h4' => array()
|
267 |
+
);
|
268 |
+
|
269 |
+
$text = balanceTags($text);
|
270 |
+
|
271 |
+
$text = wp_kses( $text, $allowed );
|
272 |
+
$text = trim($text);
|
273 |
+
return $text;
|
274 |
+
}
|
275 |
+
|
276 |
+
function code_trick( $text, $markdown ) { // Don't use bbPress native function - it's incompatible with Markdown
|
277 |
+
// If doing markdown, first take any user formatted code blocks and turn them into backticks so that
|
278 |
+
// markdown will preserve things like underscores in code blocks
|
279 |
+
if ( $markdown )
|
280 |
+
$text = preg_replace_callback("!(<pre><code>|<code>)(.*?)(</code></pre>|</code>)!s", array( __CLASS__,'decodeit'), $text);
|
281 |
+
|
282 |
+
$text = str_replace(array("\r\n", "\r"), "\n", $text);
|
283 |
+
if ( !$markdown ) {
|
284 |
+
// This gets the "inline" code blocks, but can't be used with Markdown.
|
285 |
+
$text = preg_replace_callback("|(`)(.*?)`|", array( __CLASS__, 'encodeit'), $text);
|
286 |
+
// This gets the "block level" code blocks and converts them to PRE CODE
|
287 |
+
$text = preg_replace_callback("!(^|\n)`(.*?)`!s", array( __CLASS__, 'encodeit'), $text);
|
288 |
+
} else {
|
289 |
+
// Markdown can do inline code, we convert bbPress style block level code to Markdown style
|
290 |
+
$text = preg_replace_callback("!(^|\n)([ \t]*?)`(.*?)`!s", array( __CLASS__, 'indent'), $text);
|
291 |
+
}
|
292 |
+
return $text;
|
293 |
+
}
|
294 |
+
|
295 |
+
function indent( $matches ) {
|
296 |
+
$text = $matches[3];
|
297 |
+
$text = preg_replace('|^|m', $matches[2] . ' ', $text);
|
298 |
+
return $matches[1] . $text;
|
299 |
+
}
|
300 |
+
|
301 |
+
function encodeit( $matches ) {
|
302 |
+
if ( function_exists('encodeit') ) // bbPress native
|
303 |
+
return encodeit( $matches );
|
304 |
+
|
305 |
+
$text = trim($matches[2]);
|
306 |
+
$text = htmlspecialchars($text, ENT_QUOTES);
|
307 |
+
$text = str_replace(array("\r\n", "\r"), "\n", $text);
|
308 |
+
$text = preg_replace("|\n\n\n+|", "\n\n", $text);
|
309 |
+
$text = str_replace('&lt;', '<', $text);
|
310 |
+
$text = str_replace('&gt;', '>', $text);
|
311 |
+
$text = "<code>$text</code>";
|
312 |
+
if ( "`" != $matches[1] )
|
313 |
+
$text = "<pre>$text</pre>";
|
314 |
+
return $text;
|
315 |
+
}
|
316 |
+
|
317 |
+
function decodeit( $matches ) {
|
318 |
+
if ( function_exists('decodeit') ) // bbPress native
|
319 |
+
return decodeit( $matches );
|
320 |
+
|
321 |
+
$text = $matches[2];
|
322 |
+
$trans_table = array_flip(get_html_translation_table(HTML_ENTITIES));
|
323 |
+
$text = strtr($text, $trans_table);
|
324 |
+
$text = str_replace('<br />', '', $text);
|
325 |
+
$text = str_replace('&', '&', $text);
|
326 |
+
$text = str_replace(''', "'", $text);
|
327 |
+
if ( '<pre><code>' == $matches[1] )
|
328 |
+
$text = "\n$text\n";
|
329 |
+
return "`$text`";
|
330 |
+
}
|
331 |
+
|
332 |
+
} // end class
|
333 |
+
|
334 |
+
endif;
|
view/settings.php
CHANGED
@@ -30,9 +30,30 @@ if (is_string($data)) $data = json_decode($data, true);
|
|
30 |
</label>
|
31 |
</div>
|
32 |
<div class="col-md-6">
|
33 |
-
<input type="text" class="" name="license_key"
|
34 |
value="<?php if (isset($data['license_key'])) echo $data['license_key']; ?>"
|
35 |
placeholder="Your Unique License Key">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
</div>
|
37 |
</div>
|
38 |
<div class="row form-group">
|
@@ -175,4 +196,4 @@ if (is_string($data)) $data = json_decode($data, true);
|
|
175 |
<!-- Sidebar END -->
|
176 |
</form>
|
177 |
</div>
|
178 |
-
</div>
|
30 |
</label>
|
31 |
</div>
|
32 |
<div class="col-md-6">
|
33 |
+
<input type="text" class="" name="license_key" id="woo-disc-license-key"
|
34 |
value="<?php if (isset($data['license_key'])) echo $data['license_key']; ?>"
|
35 |
placeholder="Your Unique License Key">
|
36 |
+
<input type="button" id="woo-disc-license-check" value="Validate Key" class="button button-info">
|
37 |
+
<?php
|
38 |
+
$verifiedLicense = get_option('woo_discount_rules_verified_key', 0);
|
39 |
+
if (isset($data['license_key']) && $data['license_key'] != '') {
|
40 |
+
if ($verifiedLicense) {
|
41 |
+
?>
|
42 |
+
<span class="license-success">✔</span>
|
43 |
+
<?php
|
44 |
+
} else {
|
45 |
+
?>
|
46 |
+
<div class="license-failed notice-message error inline notice-error notice-alt">
|
47 |
+
License key seems to be Invalid. Please enter a valid license key
|
48 |
+
</div>
|
49 |
+
<?php
|
50 |
+
}
|
51 |
+
}
|
52 |
+
?>
|
53 |
+
<br>
|
54 |
+
<div id="woo-disc-license-check-msg">
|
55 |
+
|
56 |
+
</div>
|
57 |
</div>
|
58 |
</div>
|
59 |
<div class="row form-group">
|
196 |
<!-- Sidebar END -->
|
197 |
</form>
|
198 |
</div>
|
199 |
+
</div>
|
woo-discount-rules.php
CHANGED
@@ -5,7 +5,9 @@
|
|
5 |
* Description: Simple Discount Rules for WooCommerce.
|
6 |
* Author: Flycart Technologies LLP
|
7 |
* Author URI: https://www.flycart.org
|
8 |
-
* Version: 1.4.
|
|
|
|
|
9 |
* Requires at least: 4.6.1
|
10 |
*/
|
11 |
|
@@ -13,4 +15,4 @@ if (!defined('ABSPATH')) exit; // Exit if accessed directly
|
|
13 |
|
14 |
include_once('helper/activation-helper.php');
|
15 |
|
16 |
-
include_once('loader.php');
|
5 |
* Description: Simple Discount Rules for WooCommerce.
|
6 |
* Author: Flycart Technologies LLP
|
7 |
* Author URI: https://www.flycart.org
|
8 |
+
* Version: 1.4.8
|
9 |
+
* Slug: woo-discount-rules
|
10 |
+
* Text Domain: woo-discount-rules
|
11 |
* Requires at least: 4.6.1
|
12 |
*/
|
13 |
|
15 |
|
16 |
include_once('helper/activation-helper.php');
|
17 |
|
18 |
+
include_once('loader.php');
|