diff --git a/lang/linuxfoo-gitlab-de_DE.po b/lang/linuxfoo-gitlab-de_DE.po index b696844..524b928 100644 --- a/lang/linuxfoo-gitlab-de_DE.po +++ b/lang/linuxfoo-gitlab-de_DE.po @@ -96,3 +96,27 @@ msgstr "im Branch" #: linuxfoo-gitlab.php:146 msgid "Last %d commits" msgstr "Letzte %d Commits" + +#: linuxfoo-gitlab.php:172 +msgid "Invalid value for parameter \"releases\"." +msgstr "Unzulässiger Wert für Parameter \"releases\"." + +#: linuxfoo-gitlab.php:179 +msgid "Releases URL not reachable." +msgstr "Releases-URL nicht erreichbar." + +#: linuxfoo-gitlab.php:185 +msgid "Releases information not readable." +msgstr "Releases-Information nicht lesbar." + +#: linuxfoo-gitlab.php:189 +msgid "This project has currently no releases." +msgstr "Dieses Projekt hat derzeit keine Releases." + +#: linuxfoo-gitlab.php:194 +msgid "Latest release" +msgstr "Neueste Release" + +#: linuxfoo-gitlab.php:201 +msgid "Releases" +msgstr "Releases" diff --git a/lang/linuxfoo-gitlab.pot b/lang/linuxfoo-gitlab.pot index d37e670..13f8001 100644 --- a/lang/linuxfoo-gitlab.pot +++ b/lang/linuxfoo-gitlab.pot @@ -9,7 +9,7 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"POT-Creation-Date: 2021-11-27T12:01:58+01:00\n" +"POT-Creation-Date: 2021-11-27T16:45:29+01:00\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "X-Generator: WP-CLI 2.5.0\n" "X-Domain: linuxfoo-gitlab\n" @@ -51,49 +51,73 @@ msgstr "" msgid "since %d %s ago" msgstr "" -#: linuxfoo-gitlab.php:59 +#: linuxfoo-gitlab.php:63 msgid "Required parameter missing." msgstr "" -#: linuxfoo-gitlab.php:62 -#: linuxfoo-gitlab.php:68 +#: linuxfoo-gitlab.php:66 +#: linuxfoo-gitlab.php:72 msgid "Invalid value for parameter \"project_id\"." msgstr "" -#: linuxfoo-gitlab.php:65 +#: linuxfoo-gitlab.php:69 msgid "Invalid value for parameter \"url\"." msgstr "" -#: linuxfoo-gitlab.php:75 +#: linuxfoo-gitlab.php:79 msgid "Project URL not reachable." msgstr "" -#: linuxfoo-gitlab.php:86 +#: linuxfoo-gitlab.php:90 msgid "Gitlab project" msgstr "" -#: linuxfoo-gitlab.php:93 +#: linuxfoo-gitlab.php:97 msgid "Invalid value for parameter \"since\"." msgstr "" -#: linuxfoo-gitlab.php:115 +#: linuxfoo-gitlab.php:119 msgid "Commits URL not reachable." msgstr "" -#: linuxfoo-gitlab.php:121 +#: linuxfoo-gitlab.php:125 msgid "Commits information not readable." msgstr "" -#: linuxfoo-gitlab.php:132 +#: linuxfoo-gitlab.php:136 msgid "No commits" msgstr "" -#: linuxfoo-gitlab.php:133 -#: linuxfoo-gitlab.php:147 +#: linuxfoo-gitlab.php:137 +#: linuxfoo-gitlab.php:151 msgid "in branch" msgstr "" #. translators: %d: maximum number of commits displayed -#: linuxfoo-gitlab.php:146 +#: linuxfoo-gitlab.php:150 msgid "Last %d commits" msgstr "" + +#: linuxfoo-gitlab.php:172 +msgid "Invalid value for parameter \"releases\"." +msgstr "" + +#: linuxfoo-gitlab.php:179 +msgid "Releases URL not reachable." +msgstr "" + +#: linuxfoo-gitlab.php:185 +msgid "Releases information not readable." +msgstr "" + +#: linuxfoo-gitlab.php:189 +msgid "This project has currently no releases." +msgstr "" + +#: linuxfoo-gitlab.php:194 +msgid "Latest release" +msgstr "" + +#: linuxfoo-gitlab.php:201 +msgid "Releases" +msgstr "" diff --git a/linuxfoo-gitlab.php b/linuxfoo-gitlab.php index 2261dda..251ec75 100644 --- a/linuxfoo-gitlab.php +++ b/linuxfoo-gitlab.php @@ -50,6 +50,10 @@ class LinuxfooGitlab { } static function list_commits($atts, $content, $tag) { + return self::show_project($atts, $content, $tag); + } + + static function show_project($atts, $content, $tag) { global $post; if( @@ -117,7 +121,7 @@ class LinuxfooGitlab { $commits = json_decode($commits_json); - if(is_null($project)) { + if(is_null($commits)) { return self::error(__('Commits information not readable.', 'linuxfoo-gitlab')); } @@ -162,6 +166,53 @@ class LinuxfooGitlab { } $out .= ''; + + if(!is_null($atts['releases'])) { + if(!preg_match('/^(all|latest)$/', $atts['releases'])) { + return self::error(__('Invalid value for parameter "releases".', 'linuxfoo-gitlab')); + } + + $releases_url = $project_url.'/releases?'; + $releases_json = file_get_contents($releases_url); + + if(is_null($releases_json)) { + return self::error(__('Releases URL not reachable.', 'linuxfoo-gitlab')); + } + + $releases = json_decode($releases_json); + + if(is_null($releases)) { + return self::error(__('Releases information not readable.', 'linuxfoo-gitlab')); + } + + if(count($releases)==0) { + $out .= '

'.__('This project has currently no releases.', 'linuxfoo-gitlab').'

'; + } + elseif($atts['releases']=='latest') { + $out .= + '

'. + __('Latest release', 'linuxfoo-gitlab').': '. + ''.$releases[0]->name.''. + '

'; + } + elseif($atts['releases']=='all') { + $out .= + '

'. + __('Releases', 'linuxfoo-gitlab').': '. + '

'. + ''; + } + } + $out .= ''; return $out; @@ -171,4 +222,5 @@ class LinuxfooGitlab { add_action('plugins_loaded', 'LinuxfooGitlab::load_textdomain'); add_action('wp_enqueue_scripts', 'LinuxfooGitlab::css' ); add_shortcode('gitlab-list-commits', 'LinuxfooGitlab::list_commits'); +add_shortcode('gitlab-show-project', 'LinuxfooGitlab::show_project'); diff --git a/styles.css b/styles.css index cf8bdcd..229f784 100644 --- a/styles.css +++ b/styles.css @@ -6,6 +6,9 @@ .linuxfoo_gitlab .commits { margin: .25em 0 .25em 0; } +.linuxfoo_gitlab .releases { + margin: .25em 0 .25em 0; +} .linuxfoo_gitlab .project_header { display: block; }