-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwppvc
More file actions
125 lines (108 loc) · 5.51 KB
/
wppvc
File metadata and controls
125 lines (108 loc) · 5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env php
<?php
/**
* Program: WP Plugin Version Checker (Markdown output supported)
* File: wppvc
* Version: 1.0.2
* Description: This program fetches the information of WordPress plugins installed on a server and displays them in a Markdown format. It checks for updates and provides detailed information about each plugin in a clear and easy-to-read format.
* Author: Ishizaka Takehiko
* Copyright: © 2023 Ishizaka Takehiko. All Rights Reserved.
* License: GNU General Public License v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Idea 1: This program could be extended to automatically update the plugins if they are out of date.
* Idea 2: The program could be modified to send email notifications when a plugin update is available.
*/
// error_reporting(E_ALL);
// ini_set('display_errors', '1');
// Check for -h, -u, and -v flags
$options = getopt("huv");
if (isset($options['h'])) {
echo "Usage: script.php [-h] [-u] [-v]\n";
echo " -h Show help information\n";
echo " -u Perform version check and update check\n";
echo " -v Display the plug in information in Markdown in a form like form like WP Plugin List.\n";
exit(0);
}
// If -u flag is not set and -v flag is not set, behave like -v
if (!isset($options['u']) && !isset($options['v'])) {
$options['v'] = true;
}
// Execute `wp plugin list` and get the result
exec('wp plugin list --format=json --fields=name,status,update,version,update_version,update_package,update_id,title,description,file', $output, $return_var);
// If the command fails, print an error and exit
if ($return_var !== 0) {
echo "Error: Unable to execute `wp plugin list`.\n";
exit(1);
}
// Join the output lines and decode the JSON into an array
$plugins = json_decode(implode("\n", $output), true);
// If the decoding fails, print an error and exit
if ($plugins === null) {
echo "Error: Unable to decode the output of `wp plugin list`.\n";
exit(1);
}
if (isset($options['v'])) {
echo "| No. | name | status | update | version | 備考 |\n";
echo "| --- | ---- | ------ | ------ | ------- | ---- |\n";
$counter = 1;
foreach ($plugins as $plugin) {
echo "| {$counter} | {$plugin['name']} | {$plugin['status']} | {$plugin['update']} | {$plugin['version']} | ー |\n";
$counter++;
}
} else {
echo "| No. | 更新対象 | name | status | update | version | 最新Ver | WP Tested | PHP ver | Plugin HomePage | WP公式URL | 備考 |\n";
echo "| --- | -------- | ---- | ------ | ------ | ------- | ------- | --------- | -------- | -------------- | ---------- | ---- |\n";
$counter = 1;
foreach ($plugins as $plugin) {
// Specific exception for 'hello' plugin
$pluginName = $plugin['name'] === 'hello' && $plugin['title'] === 'Hello Dolly' ? 'hello-dolly' : $plugin['name'];
// Fetch plugin details from WordPress API
$contextOptions = [
"ssl" => [
"verify_peer" => false,
"verify_peer_name" => false,
],
];
$context = stream_context_create($contextOptions);
$response = @file_get_contents("https://api.wordpress.org/plugins/info/1.0/{$pluginName}.json", false, $context);
// If the API request fails, print the plugin info without an error message and continue with the next plugin
if ($response === false) {
echo "| {$counter} | ー | {$plugin['name']} | {$plugin['status']} | {$plugin['update']} | {$plugin['version']} | ー | ー | ー | ー | 公式なし | ー |\n";
$counter++;
continue;
}
// Decode the JSON response into an associative array
$pluginDetails = json_decode($response, true);
// If the decoding fails or the plugin is not found, print the plugin info without an error message and continue with the next plugin
if ($pluginDetails === null || isset($pluginDetails['error'])) {
echo "| {$counter} | ー | {$plugin['name']} | {$plugin['status']} | {$plugin['update']} | {$plugin['version']} | ー | ー | ー | ー | 公式なし | ー |\n";
$counter++;
continue;
}
// Compare current version with latest version
$updateTarget = version_compare($plugin['version'], $pluginDetails['version'], '<') ? 'レ' : ' ー ';
// Prepare the output line
$line = "| {$counter} | {$updateTarget} | {$plugin['name']} | {$plugin['status']} | {$plugin['update']} | {$plugin['version']} | ";
$line .= "{$pluginDetails['version']} | {$pluginDetails['tested']} | {$pluginDetails['requires_php']} | ";
$line .= "[{$pluginDetails['name']}]({$pluginDetails['homepage']}) | ";
$line .= "[LINK](https://wordpress.org/plugins/{$pluginDetails['slug']}/) | ー |\n";
// Print the line
echo $line;
$counter++;
}
}