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 .= ''; + $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 .= ''; + $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 .= '
'; + $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 .= ''; - $content .= '
'; + $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 .= '
'; + $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 .= ''; + $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 .= ''; + $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