diff --git a/README.md b/README.md
index ffbafe0..c017c7b 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@ Displays download links and versions for latest BMLT Releases simply add [bmlt_v
[bmlt_versions]
**Attributes:** root_server, wordpress, drupal, basic, crouton, bread, yap, tabbed_map, meeting_map, list_locations, upcoming_meetings, contacts
-Adds ability to hide certain releases, default is to show all or 1.
+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 sort_by="name"] or [bmlt_versions sort_by="date"] defaults to date if not specified.
Ex. [bmlt_versions drupal="0"] would not display drupal link.
@@ -25,6 +25,9 @@ This section describes how to install the plugin and get it working.
# Changelog
+= 1.6.0 =
+* Added Sorting Option. [bmlt_versions sort_by="name"] or [bmlt_versions sort_by="date"] defaults to date if not specified.
+
= 1.5.0 =
* Added Temporary Closures
@@ -93,4 +96,4 @@ This section describes how to install the plugin and get it working.
= 1.0.0 =
-* Initial Release
\ No newline at end of file
+* Initial Release
diff --git a/bmlt-versions/bmlt-versions.php b/bmlt-versions/bmlt-versions.php
index eab5145..0ef7f8c 100644
--- a/bmlt-versions/bmlt-versions.php
+++ b/bmlt-versions/bmlt-versions.php
@@ -5,7 +5,7 @@
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.
Author: BMLT Authors
Author URI: https://bmlt.app
-Version: 1.5.0
+Version: 1.6.0
Install: Drop this directory into the "wp-content/plugins/" directory and activate it.
*/
/* Disallow direct access to the plugin file */
@@ -93,7 +93,8 @@ public function bmltVersionsSimpleFunc($atts = [])
'list_locations' => '1',
'upcoming_meetings' => '1',
'contacts' => '1',
- 'temporary_closures' => '1'
+ 'temporary_closures' => '1',
+ 'sort_by' => 'date'
),
$atts
);
@@ -111,6 +112,7 @@ public function bmltVersionsSimpleFunc($atts = [])
$upcoming_meetings = sanitize_text_field($argsSimple['upcoming_meetings']);
$contacts = sanitize_text_field($argsSimple['contacts']);
$temporary_closures = sanitize_text_field($argsSimple['temporary_closures']);
+ $sort_by = sanitize_text_field($argsSimple['sort_by']);
$rootServer_version = $this->githubLatestReleaseVersion('bmlt-root-server');
@@ -140,7 +142,8 @@ public function bmltVersionsFunc($atts = [])
'list_locations' => '1',
'upcoming_meetings' => '1',
'contacts' => '1',
- 'temporary_closures' => '1'
+ 'temporary_closures' => '1',
+ 'sort_by' => 'date'
),
$atts
);
@@ -158,186 +161,271 @@ public function bmltVersionsFunc($atts = [])
$upcoming_meetings = sanitize_text_field($args['upcoming_meetings']);
$contacts = sanitize_text_field($args['contacts']);
$temporary_closures = sanitize_text_field($args['temporary_closures']);
+ $sort_by = sanitize_text_field($args['sort_by']);
$content = '';
+ $releases = [];
if ($root_server) {
- $content .= '
';
- $content .= '
';
- $content .= '- ';
+ $root_server_content = '
';
+ $root_server_content .= '
';
+ $root_server_content .= '- ';
$rootServer_response = $this->githubLatestReleaseInfo('bmlt-root-server');
$rootServer_version = $this->githubLatestReleaseVersion($rootServer_response);
$rootServer_date = $this->githubLatestReleaseDate($rootServer_response);
- $content .= 'Root Server
';
- $content .= $this->githubReleaseDescription('bmlt-root-server') . '
';
- $content .= 'Latest Release : ' . $rootServer_date . '';
- $content .= ' ';
- $content .= '
';
- $content .= '
';
+ $rootServer_date_ver = $rootServer_version . ' (' . date("m-d-Y", strtotime($rootServer_date)) . ')';
+ $root_server_content .= 'Root Server
';
+ $root_server_content .= $this->githubReleaseDescription('bmlt-root-server') . '
';
+ $root_server_content .= 'Latest Release : ' . $rootServer_date_ver . '';
+ $root_server_content .= ' ';
+ $root_server_content .= '
';
+ $root_server_content .= '
';
+ $releases[0]['content'] = $root_server_content;
+ $releases[0]['name'] = "root-server";
+ $releases[0]['date'] = strtotime($rootServer_date);
+ $releases[0]['version'] = $rootServer_version;
}
if ($wordpress) {
- $content .= '';
- $content .= '
';
+ $wordpress_content .= '
';
+ $releases[1]['content'] = $wordpress_content;
+ $releases[1]['name'] = "wordpress-satellite-plugin";
+ $releases[1]['date'] = strtotime($wordpress_date);
+ $releases[1]['version'] = $wordpress_version;
}
if ($drupal) {
- $content .= '';
- $content .= '
';
+ $drupal_content .= '
';
+ $releases[2]['content'] = $drupal_content;
+ $releases[2]['name'] = "drupal";
+ $releases[2]['date'] = strtotime($drupal_date);
+ $releases[2]['version'] = $drupal_version;
}
if ($basic) {
- $content .= '';
- $content .= '
';
- $content .= '- ';
+ $basic_content = '
';
+ $basic_content .= '
';
+ $basic_content .= '- ';
$basic_response = $this->githubLatestReleaseInfo('bmlt-basic');
$basic_version = $this->githubLatestReleaseVersion($basic_response);
$basic_date = $this->githubLatestReleaseDate($basic_response);
- $content .= 'Basic Satellite
';
- $content .= $this->githubReleaseDescription('bmlt-basic') . '
';
- $content .= 'Latest Release : ' . $basic_date. '';
- $content .= ' ';
- $content .= '
';
- $content .= '
';
+ $basic_date_ver = $basic_version . ' (' . date("m-d-Y", strtotime($basic_date)) . ')';
+ $basic_content .= 'Basic Satellite
';
+ $basic_content .= $this->githubReleaseDescription('bmlt-basic') . '
';
+ $basic_content .= 'Latest Release : ' . $basic_date_ver. '';
+ $basic_content .= ' ';
+ $basic_content .= '
';
+ $basic_content .= '
';
+ $releases[3]['content'] = $basic_content;
+ $releases[3]['name'] = "basic";
+ $releases[3]['date'] = strtotime($basic_date);
+ $releases[3]['version'] = $basic_version;
}
if ($crouton) {
- $content .= '';
- $content .= '
';
+ $crouton_content .= '
';
+ $releases[4]['content'] = $crouton_content;
+ $releases[4]['name'] = "crouton";
+ $releases[4]['date'] = strtotime($crouton_date);
+ $releases[4]['version'] = $crouton_version;
}
if ($bread) {
- $content .= '';
- $content .= '
';
+ $bread_content = '';
+ $bread_content .= '
';
$bread_response = $this->githubLatestReleaseInfo('bread');
$bread_date = $this->githubLatestReleaseDate($bread_response);
- $content .= '- ';
- $content .= 'Bread (Meeting List Generator)
';
- $content .= $this->githubReleaseDescription('bread') . '
';
- $content .= 'Latest Release : ' .$bread_date. '';
- $content .= ' ';
- $content .= '
';
- $content .= '
';
+ $bread_version = $this->githubLatestReleaseVersion($bread_response);
+ $bread_date_ver = $bread_version . ' (' . date("m-d-Y", strtotime($bread_date)) . ')';
+ $bread_content .= '- ';
+ $bread_content .= 'Bread (Meeting List Generator)
';
+ $bread_content .= $this->githubReleaseDescription('bread') . '
';
+ $bread_content .= 'Latest Release : ' .$bread_date_ver. '';
+ $bread_content .= ' ';
+ $bread_content .= '
';
+ $bread_content .= '
';
+ $releases[5]['content'] = $bread_content;
+ $releases[5]['name'] = "bread";
+ $releases[5]['date'] = strtotime($bread_date);
+ $releases[5]['version'] = $bread_version;
}
if ($tabbed_map) {
- $content .= '';
- $content .= '
';
- $bmlt_tabbed_map_response = $this->githubLatestReleaseInfo('bmlt_tabbed_map');
- $bmlt_tabbed_map_date = $this->githubLatestReleaseDate($bmlt_tabbed_map_response);
- $content .= '- ';
- $content .= 'Tabbed Map
';
- $content .= $this->githubReleaseDescription('bmlt_tabbed_map') . '
';
- $content .= 'Latest Release : ' .$bmlt_tabbed_map_date. '';
- $content .= ' ';
- $content .= '
';
- $content .= '
';
+ $tabbed_map_content = '';
+ $tabbed_map_content .= '
';
+ $tabbed_map_response = $this->githubLatestReleaseInfo('bmlt_tabbed_map');
+ $tabbed_map_date = $this->githubLatestReleaseDate($tabbed_map_response);
+ $tabbed_map_version = $this->githubLatestReleaseVersion($tabbed_map_response);
+ $tabbed_map_date_ver = $tabbed_map_version . ' (' . date("m-d-Y", strtotime($tabbed_map_date)) . ')';
+ $tabbed_map_content .= '- ';
+ $tabbed_map_content .= 'Tabbed Map
';
+ $tabbed_map_content .= $this->githubReleaseDescription('bmlt_tabbed_map') . '
';
+ $tabbed_map_content .= 'Latest Release : ' .$tabbed_map_date_ver. '';
+ $tabbed_map_content .= ' ';
+ $tabbed_map_content .= '
';
+ $tabbed_map_content .= '
';
+ $releases[6]['content'] = $tabbed_map_content;
+ $releases[6]['name'] = "tabbed-map";
+ $releases[6]['date'] = strtotime($tabbed_map_date);
+ $releases[6]['version'] = $tabbed_map_version;
}
if ($meeting_map) {
- $content .= '';
- $content .= '
';
- $content .= '- ';
- $bmlt_meeting_response = $this->githubLatestReleaseInfo('bmlt-meeting-map');
- $bmlt_meeting_map_date = $this->githubLatestReleaseDate($bmlt_meeting_response);
- $content .= 'Meeting Map
';
- $content .= $this->githubReleaseDescription('bmlt-meeting-map') . '
';
- $content .= 'Latest Release : ' .$bmlt_meeting_map_date. '';
- $content .= ' ';
- $content .= '
';
- $content .= '
';
+ $meeting_map_content = '';
+ $meeting_map_content .= '
';
+ $meeting_map_content .= '- ';
+ $meeting_map_response = $this->githubLatestReleaseInfo('bmlt-meeting-map');
+ $meeting_map_date = $this->githubLatestReleaseDate($meeting_map_response);
+ $meeting_map_version = $this->githubLatestReleaseVersion($meeting_map_response);
+ $meeting_map_date_ver = $meeting_map_version . ' (' . date("m-d-Y", strtotime($meeting_map_date)) . ')';
+ $meeting_map_content .= 'Meeting Map
';
+ $meeting_map_content .= $this->githubReleaseDescription('bmlt-meeting-map') . '
';
+ $meeting_map_content .= 'Latest Release : ' .$meeting_map_date_ver. '';
+ $meeting_map_content .= ' ';
+ $meeting_map_content .= '
';
+ $meeting_map_content .= '
';
+ $releases[7]['content'] = $meeting_map_content;
+ $releases[7]['name'] = "meeting-map";
+ $releases[7]['date'] = strtotime($meeting_map_date);
+ $releases[7]['version'] = $meeting_map_version;
}
if ($list_locations) {
- $content .= '';
- $content .= '
';
+ $list_locations_content .= '
';
+ $releases[8]['content'] = $list_locations_content;
+ $releases[8]['name'] = "list-locations";
+ $releases[8]['date'] = strtotime($list_locations_date);
+ $releases[8]['version'] = $list_locations_version;
}
if ($upcoming_meetings) {
- $content .= '';
- $content .= '
';
+ $upcoming_meetings_content .= '
';
+ $releases[9]['content'] = $upcoming_meetings_content;
+ $releases[9]['name'] = "upcoming-meetings";
+ $releases[9]['date'] = strtotime($upcoming_meetings_date);
+ $releases[9]['version'] = $upcoming_meetings_version;
}
if ($contacts) {
- $content .= '';
- $content .= '
';
+ $contacts_content .= '
';
+ $releases[10]['content'] = $contacts_content;
+ $releases[10]['name'] = "contacts";
+ $releases[10]['date'] = strtotime($contacts_date);
+ $releases[10]['version'] = $contacts_version;
}
-
if ($temporary_closures) {
- $content .= '';
- $content .= '
';
- $content .= '- ';
+ $temporary_closures_content = '
';
+ $temporary_closures_content .= '
';
+ $temporary_closures_content .= '- ';
$temporary_closures_response = $this->githubLatestReleaseInfo('temporary-closures-bmlt');
+ $temporary_closures_date = $this->githubLatestReleaseDate($temporary_closures_response);
$temporary_closures_version = $this->githubLatestReleaseVersion($temporary_closures_response);
- $temporary_closures_release_date = $this->githubLatestReleaseDate($temporary_closures_response);
- $content .= 'Temporary Closures
';
- $content .= $this->githubReleaseDescription('temporary-closures-bmlt') . '
';
- $content .= 'Latest Release : ' . $temporary_closures_release_date. '';
- $content .= ' ';
- $content .= '
';
- $content .= '
';
+ $temporary_closures_date_ver = $temporary_closures_version . ' (' . date("m-d-Y", strtotime($temporary_closures_date)) . ')';
+ $temporary_closures_content .= 'Temporary Closures
';
+ $temporary_closures_content .= $this->githubReleaseDescription('temporary-closures-bmlt') . '
';
+ $temporary_closures_content .= 'Latest Release : ' . $temporary_closures_date_ver. '';
+ $temporary_closures_content .= ' ';
+ $temporary_closures_content .= '
';
+ $temporary_closures_content .= '
';
+ $releases[11]['content'] = $temporary_closures_content;
+ $releases[11]['name'] = "temporary-closures";
+ $releases[11]['date'] = strtotime($temporary_closures_date);
+ $releases[11]['version'] = $temporary_closures_version;
}
if ($yap) {
- $content .= '';
- $content .= '
';
- $content .= '- ';
+ $yap_content = '
';
+ $yap_content .= '
';
+ $yap_content .= '- ';
$yap_response = $this->githubLatestReleaseInfo('yap');
$yap_version = $this->githubLatestReleaseVersion($yap_response);
- $yap_release_date = $this->githubLatestReleaseDate($yap_response);
- $content .= 'Yap
';
- $content .= $this->githubReleaseDescription('yap') . '
';
- $content .= 'Latest Release : ' . $yap_release_date. '';
- $content .= ' ';
- $content .= '
';
- $content .= '
';
+ $yap_date = $this->githubLatestReleaseDate($yap_response);
+ $yap_date_ver = $yap_version . ' (' . date("m-d-Y", strtotime($yap_date)) . ')';
+ $yap_content .= 'Yap
';
+ $yap_content .= $this->githubReleaseDescription('yap') . '
';
+ $yap_content .= 'Latest Release : ' . $yap_date_ver. '';
+ $yap_content .= ' ';
+ $yap_content .= '
';
+ $yap_content .= '
';
+ $releases[12]['content'] = $yap_content;
+ $releases[12]['name'] = "yap";
+ $releases[12]['date'] = strtotime($yap_date);
+ $releases[12]['version'] = $yap_version;
+ }
+ if ($sort_by == "name") {
+ usort($releases, function ($a, $b) {
+ return strnatcasecmp($a['name'], $b['name']);
+ });
+ } else {
+ usort($releases, function ($a, $b) {
+ return strnatcasecmp($b['date'], $a['date']);
+ });
}
- return $content;
+ foreach ($releases as $release) {
+ echo $release['content'];
+ }
}
public function githubLatestReleaseInfo($repo)
@@ -349,8 +437,7 @@ public function githubLatestReleaseInfo($repo)
return 'Problem Connecting to Server!';
}
$body = wp_remote_retrieve_body($results);
- $result = json_decode($body, true);
- return $result;
+ return json_decode($body, true);
}
public function githubLatestReleaseVersion($result)
@@ -360,9 +447,7 @@ public function githubLatestReleaseVersion($result)
public function githubLatestReleaseDate($result)
{
- $releaseDate = date("m-d-Y", strtotime($result['published_at']));
- $versionDate = $result['tag_name'] . ' (' . $releaseDate . ')';
- return $versionDate;
+ return $result['published_at'];
}
public function githubReleaseDescription($repo)
@@ -376,8 +461,7 @@ public function githubReleaseDescription($repo)
$body = wp_remote_retrieve_body($results);
$result = json_decode($body, true);
$url = '~(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?$0', $result['description']);
- return $description;
+ return preg_replace($url, '$0', $result['description']);
}
public function get($url, $cookies = null)
diff --git a/bmlt-versions/readme.txt b/bmlt-versions/readme.txt
index 6ead5e1..5688cbe 100644
--- a/bmlt-versions/readme.txt
+++ b/bmlt-versions/readme.txt
@@ -3,7 +3,7 @@
Contributors: pjaudiomv, radius314
Tags: bmlt, meeting list
Tested up to: 5.3.2
-Stable tag: 1.5.0
+Stable tag: 1.6.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -15,7 +15,7 @@ SHORTCODE
[bmlt_versions]
**Attributes:** root_server, wordpress, drupal, basic, crouton, bread, yap, tabbed_map, meeting_map, list_locations, upcoming_meetings, contacts, temporary_closures
-Adds ability to hide certain releases, default is to show all or 1.
+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 sort_by="name"] or [bmlt_versions sort_by="date"] defaults to date if not specified.
Ex. [bmlt_versions drupal="0"] would not display drupal link.
@@ -35,6 +35,9 @@ This section describes how to install the plugin and get it working.
== Changelog ==
+= 1.6.0 =
+* Added Sorting Option. [bmlt_versions sort_by="name"] or [bmlt_versions sort_by="date"] defaults to date if not specified.
+
= 1.5.0 =
* Added Temporary Closures