Skip to content

Commit 04612c5

Browse files
committed
Add crumb
1 parent 5115459 commit 04612c5

3 files changed

Lines changed: 90 additions & 94 deletions

File tree

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Displays download links and versions for latest BMLT Releases simply add [bmlt_v
55
SHORTCODE
66
[bmlt_versions]
77

8-
**Attributes:** server, wordpress, drupal, basic, crouton, bread, yap, tabbed_map, meeting_map, list_locations, upcoming_meetings, contacts, temporary_closures, workflow
8+
**Attributes:** server, wordpress, drupal, basic, crouton, crumb, crumb_drupal, crumb_joomla, bread, yap, tabbed_map, meeting_map, list_locations, upcoming_meetings, contacts, temporary_closures, workflow
99
Adds ability to hide certain releases, default for most is to show all or 1. sort_by allows you to sort by name or date, defaults to date. [bmlt_versions sort_by="name"] or [bmlt_versions sort_by="date"] defaults to date if not specified.
1010

1111
Ex. [bmlt_versions drupal="0"] would not display drupal link.
@@ -14,7 +14,7 @@ Ex. [bmlt_versions drupal="0"] would not display drupal link.
1414
[bmlt_versions_simple]
1515

1616
This is just a more concise and simple display but allows you to add documentation links in dashboard settings.
17-
**Attributes:** server, crouton, bread, yap, workflow
17+
**Attributes:** server, crouton, crumb, bread, yap, workflow
1818
Adds ability to hide certain releases, default is to show all or 1. sort_by allows you to sort by name or date, defaults to date. [bmlt_versions_simple sort_by="name"] or [bmlt_versions_simple sort_by="date"] defaults to date if not specified.
1919

2020
Ex. [bmlt_versions_simple drupal="0"] would not display drupal link.
@@ -32,6 +32,11 @@ This section describes how to install the plugin and get it working.
3232

3333
# Changelog
3434

35+
= 1.9.0 =
36+
* Added Crumb plugin support (WordPress, Drupal, and Joomla variants).
37+
* Fixed duplicated entry in [bmlt_versions_simple] output.
38+
* Cleaned up settings registration, sort comparators, and API error handling.
39+
3540
= 1.8.1 =
3641
* Better handling for bad API keys.
3742

bmlt-versions.php

Lines changed: 75 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Description: A simple content generator to display the versions and links of the various BMLT components. Add [bmlt_versions] to a page or a post to generate the list.
77
Author: bmlt-enabled
88
Author URI: https://bmlt.app
9-
Version: 1.8.2
9+
Version: 1.9.0
1010
Install: Drop this directory into the "wp-content/plugins/" directory and activate it.
1111
*/
1212
/* Disallow direct access to the plugin file */
@@ -44,74 +44,65 @@ public function enqueueFrontendFiles()
4444

4545
public function bmltVersionsRegisterSettings()
4646
{
47-
$options = [
48-
'serverDoc' => 'Server Documentation Link',
49-
'croutonDoc' => 'Crouton Documentation Link',
50-
'yapDoc' => 'Yap Documentation Link',
51-
'breadDoc' => 'Bread Documentation Link',
52-
'bmltVersionsGithubApiKey' => 'Github API Key.',
53-
'workflowDoc' => 'BMLT Workflow Documentation Link'
54-
];
47+
add_option('bmltVersionsGithubApiKey', '');
48+
register_setting('bmltVersionsOptionGroup', 'bmltVersionsGithubApiKey');
5549

56-
foreach ($options as $key => $value) {
57-
add_option($key, $value);
58-
register_setting('bmltVersionsOptionGroup', $key, 'bmltVersionsCallback');
50+
foreach ($this->docOptions() as $key => $field) {
51+
add_option($key, $field['default']);
52+
register_setting('bmltVersionsOptionGroup', $key);
5953
}
6054
}
6155

56+
private function docOptions()
57+
{
58+
return [
59+
'serverDoc' => ['label' => 'Server Documentation', 'default' => ''],
60+
'croutonDoc' => ['label' => 'Crouton Documentation', 'default' => ''],
61+
'crumbDoc' => ['label' => 'Crumb Documentation', 'default' => 'https://crumb.bmlt.app/'],
62+
'yapDoc' => ['label' => 'Yap Documentation', 'default' => ''],
63+
'breadDoc' => ['label' => 'Bread Documentation', 'default' => ''],
64+
'workflowDoc' => ['label' => 'BMLT Workflow Documentation', 'default' => ''],
65+
];
66+
}
67+
6268
public function bmltVersionsOptionsPage()
6369
{
6470
add_options_page('BMLT Versions', 'BMLT Versions', 'manage_options', 'bmlt-versions', [$this, 'bmltVersionsAdminOptionsPage']);
6571
}
6672
public function bmltVersionsAdminOptionsPage()
6773
{
74+
$rows = ['bmltVersionsGithubApiKey' => 'GitHub API Token'];
75+
foreach ($this->docOptions() as $key => $field) {
76+
$rows[$key] = $field['label'];
77+
}
6878
?>
6979
<div>
7080
<h2>BMLT Versions</h2>
7181
<p>You must activate a GitHub personal access token to use this plugin. Instructions can be found here <a href="https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token">https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token</a>.</p>
7282
<p>Links for documentation are optional and only configured for [bmlt_versions_simple]. You can find all the documentations pages here <a href="https://bmlt.app">https://bmlt.app</a>. If inputs are left blank, "View Documentation" link will not display on the front end</p>
7383
<form method="post" action="options.php">
74-
<?php settings_fields('bmltVersionsOptionGroup'); ?>
84+
<?php settings_fields('bmltVersionsOptionGroup'); ?>
7585
<table>
76-
<tr valign="top">
77-
<th scope="row"><label for="bmltVersionsGithubApiKey">GitHub API Token</label></th>
78-
<td><input type="text" id="bmltVersionsGithubApiKey" name="bmltVersionsGithubApiKey" value="<?php echo get_option('bmltVersionsGithubApiKey'); ?>" /></td>
79-
</tr>
80-
<tr valign="top">
81-
<th scope="row"><label for="serverDoc">Server Documentation</label></th>
82-
<td><input type="text" id="serverDoc" name="serverDoc" value="<?php echo get_option('serverDoc'); ?>" /></td>
83-
</tr>
84-
<tr valign="top">
85-
<th scope="row"><label for="croutonDoc">Crouton Documentation</label></th>
86-
<td><input type="text" id="croutonDoc" name="croutonDoc" value="<?php echo get_option('croutonDoc'); ?>" /></td>
87-
</tr>
88-
<tr valign="top">
89-
<th scope="row"><label for="yapDoc">Yap Documentation</label></th>
90-
<td><input type="text" id="yapDoc" name="yapDoc" value="<?php echo get_option('yapDoc'); ?>" /></td>
91-
</tr>
92-
<tr valign="top">
93-
<th scope="row"><label for="breadDoc">Bread Documentation</label></th>
94-
<td><input type="text" id="breadDoc" name="breadDoc" value="<?php echo get_option('breadDoc'); ?>" /></td>
95-
</tr>
96-
<tr valign="top">
97-
<th scope="row"><label for="workflowDoc">BMLT Workflow Documentation</label></th>
98-
<td><input type="text" id="workflowDoc" name="workflowDoc" value="<?php echo get_option('workflowDoc'); ?>" /></td>
99-
</tr>
100-
86+
<?php foreach ($rows as $key => $label) : ?>
87+
<tr valign="top">
88+
<th scope="row"><label for="<?php echo esc_attr($key); ?>"><?php echo esc_html($label); ?></label></th>
89+
<td><input type="text" id="<?php echo esc_attr($key); ?>" name="<?php echo esc_attr($key); ?>" value="<?php echo esc_attr(get_option($key)); ?>" /></td>
90+
</tr>
91+
<?php endforeach; ?>
10192
</table>
102-
<?php submit_button(); ?>
93+
<?php submit_button(); ?>
10394
</form>
10495
</div>
10596
<?php
10697
}
10798

10899
public function bmltVersionsSimpleFunc($atts = [])
109100
{
110-
$content = '';
111101
$args = shortcode_atts(
112102
[
113103
'server' => '1',
114104
'crouton' => '1',
105+
'crumb' => '1',
115106
'bread' => '1',
116107
'yap' => '1',
117108
'workflow' => '1',
@@ -135,6 +126,13 @@ public function bmltVersionsSimpleFunc($atts = [])
135126
'download_url' => 'https://wordpress.org/plugins/crouton/',
136127
'github_url' => 'https://github.com/bmlt-enabled/crouton'
137128
],
129+
'crumb' => [
130+
'github_name' => 'crumb',
131+
'display_name' => 'Crumb',
132+
'docs_option_name' => 'crumbDoc',
133+
'download_url' => 'https://wordpress.org/plugins/crumb/',
134+
'github_url' => 'https://github.com/bmlt-enabled/crumb'
135+
],
138136
'bread' => [
139137
'github_name' => 'bread',
140138
'display_name' => 'Bread',
@@ -163,34 +161,29 @@ public function bmltVersionsSimpleFunc($atts = [])
163161
foreach ($products as $key => $product) {
164162
if ($args[$key]) {
165163
$response = $this->githubLatestReleaseInfo($product['github_name']);
166-
$version = $this->githubLatestReleaseVersion($response);
167-
$date = $this->githubLatestReleaseDate($response);
164+
$version = $response['tag_name'] ?? '';
165+
$date = $response['published_at'] ?? '';
168166
$docs = get_option($product['docs_option_name']);
169167

170-
$content = $this->generateSimpleHtmlContent($product, $version, $date, $docs);
171168
$releases[] = [
172-
'content' => $content,
169+
'content' => $this->generateSimpleHtmlContent($product, $version, $date, $docs),
173170
'name' => $product['display_name'],
174171
'date' => strtotime($date),
175-
'version' => $version
176172
];
177173
}
178174
}
179175

180-
if ($args['sort_by'] == "name") {
181-
usort($releases, function ($a, $b) {
182-
return strnatcasecmp($a['name'], $b['name']);
183-
});
184-
} else {
185-
usort($releases, function ($a, $b) {
186-
return strnatcasecmp($b['date'], $a['date']);
187-
});
188-
}
176+
usort($releases, function ($a, $b) use ($args) {
177+
return $args['sort_by'] === 'name'
178+
? strnatcasecmp($a['name'], $b['name'])
179+
: $b['date'] <=> $a['date'];
180+
});
181+
182+
$output = '';
189183
foreach ($releases as $release) {
190-
$content .= $release['content'];
184+
$output .= $release['content'];
191185
}
192-
193-
return $content;
186+
return $output;
194187
}
195188

196189
private function generateSimpleHtmlContent($product, $version, $date, $docs)
@@ -219,6 +212,9 @@ public function bmltVersionsFunc($atts = [])
219212
'drupal' => '0',
220213
'basic' => '0',
221214
'crouton' => '1',
215+
'crumb' => '1',
216+
'crumb_drupal' => '0',
217+
'crumb_joomla' => '0',
222218
'bread' => '1',
223219
'workflow' => '1',
224220
'yap' => '1',
@@ -243,6 +239,9 @@ public function bmltVersionsFunc($atts = [])
243239
'drupal' => ['display_name' => 'Drupal Satellite', 'name' => 'bmlt-drupal', 'source' => 'drupal'],
244240
'basic' => ['display_name' => 'Basic Satellite', 'name' => 'bmlt-basic', 'source' => 'github'],
245241
'crouton' => ['display_name' => 'Crouton', 'name' => 'crouton', 'source' => 'wordpress'],
242+
'crumb' => ['display_name' => 'Crumb', 'name' => 'crumb', 'source' => 'wordpress'],
243+
'crumb_drupal' => ['display_name' => 'Crumb Drupal', 'name' => 'crumb-drupal', 'source' => 'drupal'],
244+
'crumb_joomla' => ['display_name' => 'Crumb Joomla', 'name' => 'crumb-joomla', 'source' => 'joomla'],
246245
'bread' => ['display_name' => 'Bread', 'name' => 'bread', 'source' => 'wordpress'],
247246
'workflow' => ['display_name' => 'Workflow', 'name' => 'bmlt-workflow', 'source' => 'wordpress'],
248247
'tabbed_map' => ['display_name' => 'Tabbed Map', 'name' => 'bmlt-tabbed-map', 'gh_name' => 'bmlt_tabbed_map', 'source' => 'wordpress'],
@@ -258,14 +257,15 @@ public function bmltVersionsFunc($atts = [])
258257
foreach ($repositories as $key => $repo) {
259258
if ($args[$key]) {
260259
$response = $this->githubLatestReleaseInfo($repo['gh_name'] ?? $repo['name']);
261-
$version = $this->githubLatestReleaseVersion($response);
262-
$date = $this->githubLatestReleaseDate($response);
260+
$version = $response['tag_name'] ?? '';
261+
$date = $response['published_at'] ?? '';
263262
$description = $this->githubReleaseDescription($repo['gh_name'] ?? $repo['name']);
264263
$formattedDate = date("m-d-Y", strtotime($date));
265264

266265
$downloadURL = '';
267266
switch ($repo['source']) {
268267
case 'drupal':
268+
case 'joomla':
269269
case 'github':
270270
$downloadURL = "https://github.com/bmlt-enabled/{$repo['name']}/releases/{$version}";
271271
break;
@@ -282,55 +282,41 @@ public function bmltVersionsFunc($atts = [])
282282
$content .= "Latest Release : <strong><a href=\"{$downloadURL}\" id=\"bmlt_versions_release\">{$version} ({$formattedDate})</a></strong>";
283283
$content .= "</li></ul></div>";
284284

285-
$releases[] = ['content' => $content, 'name' => $repo['name'], 'date' => strtotime($date), 'version' => $version];
285+
$releases[] = ['content' => $content, 'name' => $repo['name'], 'date' => strtotime($date)];
286286
}
287287
}
288288

289-
$sortKey = ($args['sort_by'] == 'name') ? 'name' : 'date';
290-
usort($releases, function ($a, $b) use ($sortKey) {
291-
return ($sortKey == 'date') ? strnatcasecmp($b[$sortKey], $a[$sortKey]) : strnatcasecmp($a[$sortKey], $b[$sortKey]);
289+
usort($releases, function ($a, $b) use ($args) {
290+
return $args['sort_by'] === 'name'
291+
? strnatcasecmp($a['name'], $b['name'])
292+
: $b['date'] <=> $a['date'];
292293
});
293-
$rel = '';
294+
295+
$output = '';
294296
foreach ($releases as $release) {
295-
$rel .= $release['content'];
297+
$output .= $release['content'];
296298
}
297-
return $rel;
299+
return $output;
298300
}
299301

300302
public function githubLatestReleaseInfo($repo)
301303
{
302304
$results = $this->get("https://api.github.com/repos/bmlt-enabled/$repo/releases/latest");
303-
$httpcode = wp_remote_retrieve_response_code($results);
304-
$response_message = wp_remote_retrieve_response_message($results);
305-
if ($httpcode != 200 && $httpcode != 302 && $httpcode != 304 && !empty($response_message)) {
306-
return 'Problem Connecting to Server!';
305+
if (!in_array(wp_remote_retrieve_response_code($results), [200, 302, 304], true)) {
306+
return [];
307307
}
308-
$body = wp_remote_retrieve_body($results);
309-
return json_decode($body, true);
310-
}
311-
312-
public function githubLatestReleaseVersion($result)
313-
{
314-
return $result['tag_name'] ?? '';
315-
}
316-
317-
public function githubLatestReleaseDate($result)
318-
{
319-
return $result['published_at'] ?? '';
308+
return json_decode(wp_remote_retrieve_body($results), true) ?? [];
320309
}
321310

322311
public function githubReleaseDescription($repo)
323312
{
324313
$results = $this->get("https://api.github.com/repos/bmlt-enabled/$repo");
325-
$httpcode = wp_remote_retrieve_response_code($results);
326-
$response_message = wp_remote_retrieve_response_message($results);
327-
if ($httpcode != 200 && $httpcode != 302 && $httpcode != 304 && !empty($response_message)) {
328-
return 'Problem Connecting to Server!';
314+
if (!in_array(wp_remote_retrieve_response_code($results), [200, 302, 304], true)) {
315+
return '';
329316
}
330-
$body = wp_remote_retrieve_body($results);
331-
$result = json_decode($body, true);
317+
$description = json_decode(wp_remote_retrieve_body($results), true)['description'] ?? '';
332318
$url = '~(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i';
333-
return preg_replace($url, '<a href="$0" target="_blank" title="$0">$0</a>', $result['description']);
319+
return preg_replace($url, '<a href="$0" target="_blank" title="$0">$0</a>', $description);
334320
}
335321

336322
public function get($url, $cookies = null)

readme.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Contributors: pjaudiomv, GarrettWeinberg, tempsaint, dgershman
44
Tags: bmlt, meeting list
55
Tested up to: 6.8
6-
Stable tag: 1.8.2
6+
Stable tag: 1.9.0
77
License: GPLv2 or later
88
License URI: http://www.gnu.org/licenses/gpl-2.0.html
99

@@ -14,7 +14,7 @@ Displays download links and versions for latest BMLT Releases simply add [bmlt_v
1414
SHORTCODE
1515
[bmlt_versions]
1616

17-
**Attributes:** server, wordpress, drupal, basic, crouton, bread, yap, tabbed_map, meeting_map, list_locations, upcoming_meetings, contacts, temporary_closures, workflow
17+
**Attributes:** server, wordpress, drupal, basic, crouton, crumb, crumb_drupal, crumb_joomla, bread, yap, tabbed_map, meeting_map, list_locations, upcoming_meetings, contacts, temporary_closures, workflow
1818
Adds ability to hide certain releases, default for most is to show all or 1. sort_by allows you to sort by name or date, defaults to date. [bmlt_versions sort_by="name"] or [bmlt_versions sort_by="date"] defaults to date if not specified.
1919

2020
Ex. [bmlt_versions drupal="0"] would not display drupal link.
@@ -23,7 +23,7 @@ Ex. [bmlt_versions drupal="0"] would not display drupal link.
2323
[bmlt_versions_simple]
2424

2525
This is just a more concise and simple display but allows you to add documentation links in dashboard settings.
26-
**Attributes:** server, crouton, bread, yap, workflow
26+
**Attributes:** server, crouton, crumb, bread, yap, workflow
2727
Adds ability to hide certain releases, default is to show all or 1. sort_by allows you to sort by name or date, defaults to date. [bmlt_versions_simple sort_by="name"] or [bmlt_versions_simple sort_by="date"] defaults to date if not specified.
2828

2929
Ex. [bmlt_versions_simple drupal="0"] would not display drupal link.
@@ -45,6 +45,11 @@ This section describes how to install the plugin and get it working.
4545

4646
== Changelog ==
4747

48+
= 1.9.0 =
49+
* Added Crumb plugin support (WordPress, Drupal, and Joomla variants).
50+
* Fixed duplicated entry in [bmlt_versions_simple] output.
51+
* Cleaned up settings registration, sort comparators, and API error handling.
52+
4853
= 1.8.2 =
4954
* Rename server.
5055

0 commit comments

Comments
 (0)