diff --git a/lang/linuxfoo-gitlab-de_DE.po b/lang/linuxfoo-gitlab-de_DE.po index ba1dc7b..b696844 100644 --- a/lang/linuxfoo-gitlab-de_DE.po +++ b/lang/linuxfoo-gitlab-de_DE.po @@ -2,15 +2,14 @@ # This file is distributed under the same license as the Gitlab REST API Shortcodes plugin. msgid "" msgstr "" -"Project-Id-Version: Gitlab REST API Shortcodes 1.1\n" -"Report-Msgid-Bugs-To: https://tk-sls.de/ref/linuxfoo-gitlab\n" +"Project-Id-Version: Gitlab REST API Shortcodes 1.2\n" +"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/linuxfoo-gitlab\n" "Last-Translator: Tilman Kranz \n" -"Language: de\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"POT-Creation-Date: 2021-11-27T03:05:12+01:00\n" -"PO-Revision-Date: 2021-11-27 00:00+0100\n" +"POT-Creation-Date: 2021-11-27T11:51:10+01:00\n" +"PO-Revision-Date: 2021-11-27T11:51:10+01:00\n" "X-Generator: WP-CLI 2.5.0\n" "X-Domain: linuxfoo-gitlab\n" @@ -18,35 +17,82 @@ msgstr "" msgid "Gitlab REST API Shortcodes" msgstr "Gitlab REST API Shortcodes" +#. Plugin URI of the plugin +msgid "http://tk-sls.de/ref/gitlab-list-commits" +msgstr "http://tk-sls.de/ref/gitlab-list-commits" + #. Description of the plugin -msgid "

Summary: Embed list of most recent commits to a Gitlab project from a Gitlab instance's public REST API.

Example: Add [gitlab-list-commits url=https://tk-sls.de/gitlab project_id=42 since=\"3 month\" max=5] for a list of at most 5 commits to that project that were made since at most 3 months ago.

The attributes \"url\" and \"project_id\" are mandatory.

The attributes \"since\" and \"max\" are optional (beware, the default is an unlimited list of commits).

Other optional attributes:

" -msgstr "

Zusammenfassung: Lies Liste neuester Commits eines Projekts aus einem Projekt in einer Gitlab-Instanz via v4 REST API.

Beispiel: [gitlab-list-commits url=https://tk-sls.de/gitlab project_id=42 since=\"3 month\" max=5] Liste bis zu 5 Commits (Neueste zuerst) aus den letzten 3 Monaten.

Attribute \"url\" und \"project_id\" sind Pflichtangaben.

Attribute \"since\" und \"max\" sind optional (Achtung, Standardverhalten ist unlimitiertes Auflisten).

Weitere optionale Attribute:

" +msgid "Summary: Embed list of most recent commits to a Gitlab project from a Gitlab instance's public REST API. Example: Add [gitlab-list-commits url=https://tk-sls.de/gitlab project_id=42 since=\"3 month\" max=5] for a list of at most 5 commits to that project that were made since at most 3 months ago." +msgstr "Zusammenfassung: Bette Liste der neuesten Commits eines Gitlab-Projektes ein, die mit Gitlabs REST API abgerufen wird. Beispiel: Füge folgenden Shortcode zu einem Artikel hinzu, um die letzten 5 Commits anzuzeigen, die nicht älter als 3 Monate sind: [gitlab-list-commits url=https://tk-sls.de/gitlab project_id=42 since=\"3 month\" max=5]" -#: linuxfoo-gitlab.php:36 +#. Author of the plugin +msgid "Tilman Kranz" +msgstr "Tilman Kranz" + +#. Author URI of the plugin +msgid "https://tk-sls.de" +msgstr "https://tk-sls.de" + +#: linuxfoo-gitlab.php:39 +msgid "days" +msgstr "Tagen" + +#: linuxfoo-gitlab.php:42 +msgid "months" +msgstr "Monaten" + +#: linuxfoo-gitlab.php:45 +msgid "years" +msgstr "Jahren" + +#. translators: %d: count, %s unit of time interval +#: linuxfoo-gitlab.php:49 +msgid "since %d %s ago" +msgstr "seit %d %s" + +#: linuxfoo-gitlab.php:59 msgid "Required parameter missing." -msgstr "Benötigter Parameter fehlt." +msgstr "Notwendiger Parameter fehlt" -#: linuxfoo-gitlab.php:43 +#: linuxfoo-gitlab.php:62 +#: linuxfoo-gitlab.php:68 +msgid "Invalid value for parameter \"project_id\"." +msgstr "Unzulässiger Wert für Parameter \"project_id\"." + +#: linuxfoo-gitlab.php:65 +msgid "Invalid value for parameter \"url\"." +msgstr "Unzulässiger Wert für Parameter \"url\"." + +#: linuxfoo-gitlab.php:75 msgid "Project URL not reachable." -msgstr "Projekt-URL nicht erreichbar." +msgstr "Gitlab-Projekt-URL nicht erreichbar." -#: linuxfoo-gitlab.php:79 +#: linuxfoo-gitlab.php:86 +msgid "Gitlab project" +msgstr "Gitlab-Projekt" + +#: linuxfoo-gitlab.php:93 +msgid "Invalid value for parameter \"since\"." +msgstr "Unzulässiger Wert für Parameter \"since\"." + +#: linuxfoo-gitlab.php:115 msgid "Commits URL not reachable." -msgstr "Commits-URL nicht erreichbar." +msgstr "Gitlab-Commits-URL nicht erreichbar." -#: linuxfoo-gitlab.php:85 +#: linuxfoo-gitlab.php:121 msgid "Commits information not readable." -msgstr "Commit-Information nicht verfügbar." +msgstr "Commit-Information nicht lesbar." -#: linuxfoo-gitlab.php:96 +#: linuxfoo-gitlab.php:132 msgid "No commits" -msgstr "Keine Commits" +msgstr "Keine aktuellen Commits" -#: linuxfoo-gitlab.php:97 -#: linuxfoo-gitlab.php:110 +#: linuxfoo-gitlab.php:133 +#: linuxfoo-gitlab.php:147 msgid "in branch" -msgstr "in Branch" +msgstr "im Branch" -#: linuxfoo-gitlab.php:109 +#. translators: %d: maximum number of commits displayed +#: linuxfoo-gitlab.php:146 msgid "Last %d commits" msgstr "Letzte %d Commits" diff --git a/lang/linuxfoo-gitlab.pot b/lang/linuxfoo-gitlab.pot index fb32698..d37e670 100644 --- a/lang/linuxfoo-gitlab.pot +++ b/lang/linuxfoo-gitlab.pot @@ -2,14 +2,15 @@ # This file is distributed under the same license as the Gitlab REST API Shortcodes plugin. msgid "" msgstr "" -"Project-Id-Version: Gitlab REST API Shortcodes 1.1\n" +"Project-Id-Version: Gitlab REST API Shortcodes 1.2\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/linuxfoo-gitlab\n" -"Last-Translator: Tilman Kranz \n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"POT-Creation-Date: 2021-11-27T03:05:12+01:00\n" -"PO-Revision-Date: 2021-11-27 00:00+0100\n" +"POT-Creation-Date: 2021-11-27T12:01:58+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" @@ -17,35 +18,82 @@ msgstr "" msgid "Gitlab REST API Shortcodes" msgstr "" -#. Description of the plugin -msgid "

Summary: Embed list of most recent commits to a Gitlab project from a Gitlab instance's public REST API.

Example: Add [gitlab-list-commits url=https://tk-sls.de/gitlab project_id=42 since=\"3 month\" max=5] for a list of at most 5 commits to that project that were made since at most 3 months ago.

The attributes \"url\" and \"project_id\" are mandatory.

The attributes \"since\" and \"max\" are optional (beware, the default is an unlimited list of commits).

Other optional attributes:

  • ref_name=STRING: List only commit from branch or reference name STRING.
  • default_branch: If set, list only commits from the project's default branch.
" +#. Plugin URI of the plugin +msgid "http://tk-sls.de/ref/gitlab-list-commits" msgstr "" -#: linuxfoo-gitlab.php:36 +#. Description of the plugin +msgid "Summary: Embed list of most recent commits to a Gitlab project from a Gitlab instance's public REST API. Example: Add [gitlab-list-commits url=https://tk-sls.de/gitlab project_id=42 since=\"3 month\" max=5] for a list of at most 5 commits to that project that were made since at most 3 months ago." +msgstr "" + +#. Author of the plugin +msgid "Tilman Kranz" +msgstr "" + +#. Author URI of the plugin +msgid "https://tk-sls.de" +msgstr "" + +#: linuxfoo-gitlab.php:39 +msgid "days" +msgstr "" + +#: linuxfoo-gitlab.php:42 +msgid "months" +msgstr "" + +#: linuxfoo-gitlab.php:45 +msgid "years" +msgstr "" + +#. translators: %d: count, %s unit of time interval +#: linuxfoo-gitlab.php:49 +msgid "since %d %s ago" +msgstr "" + +#: linuxfoo-gitlab.php:59 msgid "Required parameter missing." msgstr "" -#: linuxfoo-gitlab.php:43 +#: linuxfoo-gitlab.php:62 +#: linuxfoo-gitlab.php:68 +msgid "Invalid value for parameter \"project_id\"." +msgstr "" + +#: linuxfoo-gitlab.php:65 +msgid "Invalid value for parameter \"url\"." +msgstr "" + +#: linuxfoo-gitlab.php:75 msgid "Project URL not reachable." msgstr "" -#: linuxfoo-gitlab.php:79 +#: linuxfoo-gitlab.php:86 +msgid "Gitlab project" +msgstr "" + +#: linuxfoo-gitlab.php:93 +msgid "Invalid value for parameter \"since\"." +msgstr "" + +#: linuxfoo-gitlab.php:115 msgid "Commits URL not reachable." msgstr "" -#: linuxfoo-gitlab.php:85 +#: linuxfoo-gitlab.php:121 msgid "Commits information not readable." msgstr "" -#: linuxfoo-gitlab.php:96 +#: linuxfoo-gitlab.php:132 msgid "No commits" msgstr "" -#: linuxfoo-gitlab.php:97 -#: linuxfoo-gitlab.php:110 +#: linuxfoo-gitlab.php:133 +#: linuxfoo-gitlab.php:147 msgid "in branch" msgstr "" -#: linuxfoo-gitlab.php:109 +#. translators: %d: maximum number of commits displayed +#: linuxfoo-gitlab.php:146 msgid "Last %d commits" msgstr "" diff --git a/linuxfoo-gitlab.php b/linuxfoo-gitlab.php index 174338c..50bdab6 100644 --- a/linuxfoo-gitlab.php +++ b/linuxfoo-gitlab.php @@ -3,9 +3,9 @@ /* Plugin Name: Gitlab REST API Shortcodes Plugin URI: http://tk-sls.de/ref/gitlab-list-commits -Description:

Summary: Embed list of most recent commits to a Gitlab project from a Gitlab instance's public REST API.

Example: Add [gitlab-list-commits url=https://tk-sls.de/gitlab project_id=42 since="3 month" max=5] for a list of at most 5 commits to that project that were made since at most 3 months ago.

The attributes "url" and "project_id" are mandatory.

The attributes "since" and "max" are optional (beware, the default is an unlimited list of commits).

Other optional attributes:

  • ref_name=STRING: List only commit from branch or reference name STRING.
  • default_branch: If set, list only commits from the project's default branch.
+Description: Summary: Embed list of most recent commits to a Gitlab project from a Gitlab instance's public REST API. Example: Add [gitlab-list-commits url=https://tk-sls.de/gitlab project_id=42 since="3 month" max=5] for a list of at most 5 commits to that project that were made since at most 3 months ago. Author: Tilman Kranz -Version: 1.1 +Version: 1.2 Author URI: https://tk-sls.de */ @@ -13,8 +13,12 @@ class LinuxfooGitlab { public function __construct() { } + static function load_textdomain() { + load_plugin_textdomain('linuxfoo-gitlab', false, dirname(plugin_basename(__FILE__)).'/lang'); + } + static function css() { - wp_enqueue_style('linuxfoo_gitlab_css', plugins_url('styles.css', __FILE__ ), '', '1.1' ); + wp_enqueue_style('linuxfoo_gitlab_css', plugins_url('styles.css', __FILE__ ), '', '1.2' ); } static function error ( $msg ) { @@ -26,6 +30,25 @@ class LinuxfooGitlab { ''; } + static function format_since($since) { + preg_match('/^([0-9]+)\s+(.*)$/', $since, $m); + $num = $m[1]; + $unit = $m[2]; + + if($unit=='days') { + $unit = __('days', 'linuxfoo-gitlab'); + } + elseif($unit=='months') { + $unit = __('months', 'linuxfoo-gitlab'); + } + elseif($unit=='years') { + $unit = __('years', 'linuxfoo-gitlab'); + } + + /* translators: %d: count, %s unit of time interval*/ + return sprintf(__('since %d %s ago', 'linuxfoo-gitlab'), $num, $unit); + } + static function list_commits($atts, $content, $tag) { global $post; @@ -35,6 +58,15 @@ class LinuxfooGitlab { ) { return self::error(__('Required parameter missing.', 'linuxfoo-gitlab')); } + elseif(!preg_match('/^[1-9][0-9]*$/', $atts['project_id'])) { + return self::error(__('Invalid value for parameter "project_id".', 'linuxfoo-gitlab')); + } + elseif(!filter_var($atts['url'], FILTER_VALIDATE_URL)) { + return self::error(__('Invalid value for parameter "url".', 'linuxfoo-gitlab')); + } + elseif(!preg_match('/^[1-9][0-9]*$/', $atts['project_id'])) { + return self::error(__('Invalid value for parameter "project_id".', 'linuxfoo-gitlab')); + } $project_url = $atts['url'].'/api/v4/projects/'.$atts['project_id']; $project_json = file_get_contents($project_url); @@ -51,12 +83,16 @@ class LinuxfooGitlab { $project_header = ''. - 'Gitlab project'.' '.$project->name.''. + __('Gitlab project', 'linuxfoo-gitlab').' '.$project->name.''. ''; $commits_url = $project_url.'/repository/commits?'; if(!is_null($atts['since'])) { + if(!preg_match('/^[1-9][0-9]*\s+(days|months|years)$/', $atts['since'])) { + return self::error(__('Invalid value for parameter "since".', 'linuxfoo-gitlab')); + } + $since = date(DATE_ISO8601, strtotime('-'.$atts['since'])); $commits_url .= '&since='.$since; } @@ -95,7 +131,7 @@ class LinuxfooGitlab { ''. __('No commits', 'linuxfoo-gitlab'). (is_null($branch) ? '' : ' '.__('in branch', 'linuxfoo-gitlab').' "'.$branch.'"'). - (is_null($atts['since']) ? '' : ' since '.$atts['since'].' ago').'.'. + (is_null($atts['since']) ? '' : ' '.('since '.$atts['since'].' ago')).'.'. ''. ''; } @@ -106,9 +142,10 @@ class LinuxfooGitlab { '
'. $project_header. ''. + /* translators: %d: maximum number of commits displayed */ sprintf(__('Last %d commits', 'linuxfoo-gitlab'), $commits_count). (is_null($branch) ? '' : ' '.__('in branch', 'linuxfoo-gitlab').' "'.$branch.'"'). - (is_null($atts['since']) ? '' : ' since '.$atts['since'].' ago').':'. + (is_null($atts['since']) ? '' : ' '.self::format_since($atts['since'])).':'. ''. '
    '; @@ -130,10 +167,6 @@ class LinuxfooGitlab { return $out; } - - static function load_textdomain() { - load_plugin_textdomain('linuxfoo-gitlab', false, dirname(plugin_basename(__FILE__)).'/lang'); - } } add_action('plugins_loaded', 'LinuxfooGitlab::load_textdomain');