forked from Automattic/WordPress-Plugin-Readme-Parser
-
Notifications
You must be signed in to change notification settings - Fork 1
/
validator.php
222 lines (182 loc) · 5.86 KB
/
validator.php
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?php
require('parse-readme.php');
function validate_readme($r) {
$warnings = array();
$fatal_errors = array();
$notes = array();
// fatal errors
if ( !$r['name'] )
$fatal_errors[] = 'No plugin name detected. Plugin names look like: <code>=== Plugin Name ===</code>';
// warnings
if ( !$r['requires_at_least'] )
$warnings[] = '<code>Requires at least</code> is missing';
if ( !$r['tested_up_to'] )
$warnings[] = '<code>Tested up to</code> is missing';
if ( !$r['stable_tag'] )
$warnings[] = '<code>Stable tag</code> is missing. Hint: If you treat <code>/trunk/</code> as stable, put <code>Stable tag: trunk</code>';
if ( !count($r['contributors']) )
$warnings[] = 'No <code>Contributors</code> listed';
if ( !count($r['tags']) )
$warnings[] = 'No <code>Tags</code> specified';
if ( $r['is_excerpt'] )
$warnings[] = 'No <code>== Description ==</code> section was found... your short description section will be used instead';
if ( $r['is_truncated'] )
$warnings[] = 'Your short description exceeds the 150 character limit';
// notes
if ( !$r['sections']['installation'] )
$notes[] = 'No <code>== Installation ==</code> section was found';
if ( !$r['sections']['frequently_asked_questions'] )
$notes[] = 'No <code>== Frequently Asked Questions ==</code> section was found';
if ( !$r['sections']['changelog'] )
$notes[] = 'No <code>== Changelog ==</code> section was found';
if ( !$r['upgrade_notice'] )
$notes[] = 'No <code>== Upgrade Notice ==</code> section was found';
if ( !$r['sections']['screenshots'] )
$notes[] = 'No <code>== Screenshots ==</code> section was found';
if ( !$r['donate_link'] )
$notes[] = 'No donate link was found';
readme_validator_head('Readme Validator Results');
// print those errors, warnings, and notes
if ( $fatal_errors ) {
echo "<div class='fatal error'><p>Fatal Error:</p>\n<ul class='fatal error'>\n";
foreach ( $fatal_errors as $e )
echo "<li>$e</li>\n";
echo "</ul>\n</div>";
return; // no point staying
}
if ( $warnings ) {
echo "<div class='warning error'><p>Warnings:</p>\n<ul class='warning error'>\n";
foreach ( $warnings as $e )
echo "<li>$e</li>\n";
echo "</ul>\n</div>";
}
if ( $notes ) {
echo "<div class='note error'><p>Notes:</p>\n<ul class='note error'>\n";
foreach ( $notes as $e )
echo "<li>$e</li>\n";
echo "</ul>\n</div>";
}
if ( !$notes && !$warnings && !$fatal_errors )
echo "<div class='success'><p>Your <code>readme.txt</code> rocks. Seriously. Flying colors.</p></div>\n";
else
echo "<a href='#re-edit'>Re-Edit your Readme File</a>\n";
// Show the data, as interpreted
?>
<hr />
<h1><?php echo $r['name']; ?></h1>
<p><em><?php echo $r['short_description']; ?></em></p>
<hr />
<p>
<strong>Contributors:</strong> <?php echo implode(', ', $r['contributors']); ?><br />
<strong>Donate link:</strong> <?php echo $r['donate_link']; ?><br />
<strong>Tags:</strong> <?php echo implode(', ', $r['tags']);?><br />
<strong>Requires at least:</strong> <?php echo $r['requires_at_least']; ?><br />
<strong>Tested up to:</strong> <?php echo $r['tested_up_to']; ?><br />
<strong>Stable tag:</strong> <?php echo $r['stable_tag']; ?>
</p>
<hr />
<?php foreach ( $r['sections'] as $title => $section ) : ?>
<h3><?php echo ucwords(str_replace('_', ' ', $title)); ?></h3>
<?php echo function_exists( 'apply_filters' ) ? apply_filters( 'validator_section', $section ) : $section; ?>
<hr />
<?php endforeach; ?>
<h3>Upgrade Notice</h3>
<dl>
<?php foreach ( $r['upgrade_notice'] as $version => $notice ) : ?>
<dt><?php echo $version; ?></dt>
<dd><?php echo $notice; ?></dd>
<?php endforeach; ?>
</dl>
<?php echo $r['remaining_content'];
echo "\n<hr />\n\n";
echo "<h2 id='re-edit'>Re-Edit your Readme File</h2>\n";
}
function readme_validator_head($title) { ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title><?php echo $title; ?></title>
</head>
<style type="text/css">
<!--
body {
font-family: Lucida Grande, Verdana, sans-serif;
}
code {
font-size: 1.3em
}
div.success {
background: #0f0;
width: 50%;
margin: 0 auto;
padding: 1px 10px;
border: 3px solid #0d0;
}
div.error {
padding: 1px 10px;
margin: 30px auto;
}
div.error p {
font-weight: bold;
}
div.error ul {
list-style: square;
}
div.fatal {
background: #faa;
border: 3px solid #d00;
}
div.warning {
background: #f60;
border: 3px solid #e40;
}
div.note {
background: #5cf;
border: 3px solid #3ad;
}
-->
</style>
<body>
<?php
}
$readme_contents = '';
$url = '';
if ( $_POST['url'] ) {
$url = wp_kses_no_null( stripslashes($_POST['readme_url']) );
$url = clean_url( $url );
if ( strtolower(substr($url, -10, 10)) != 'readme.txt') {
readme_validator_head('Validator Error!');
die('URL must end in <code>readme.txt</code>!');
}
if ( !$readme_contents = file_get_contents($url) ) {
readme_validator_head('Validator Error!');
die('Invalid readme.txt URL');
}
$r = new Automattic_Readme;
$readme = $r->parse_readme_contents($readme_contents);
validate_readme($readme);
} elseif ( $_POST['text'] ) {
$readme_contents = stripslashes($_POST['readme_contents']);
$r = new Automattic_Readme;
$readme = $r->parse_readme_contents($readme_contents);
validate_readme($readme);
} else {
readme_validator_head('WordPress/BBPress Plugin readme.txt Validator');
?>
<p>Enter the URL to your <code>readme.txt</code>:</p>
<form method="post" action="">
<input type="hidden" name="url" value="1" />
<p>http://<input type="text" name="readme_url" size="70" /> <input type="submit" value="Validate!" /></p>
</form>
<p>... or paste your <code>readme.txt</code> here:</p>
<?php
}
?>
<form method="post" action="">
<input type="hidden" name="text" value="1" />
<textarea rows="20" cols="100" name="readme_contents"><?php echo wp_specialchars( $readme_contents ); ?></textarea>
<p><input type="submit" value="Validate!" /></p>
</form>
</body>
</html>