From 7c7685bee74397f9df6f78584385cfdb4bbeaf3c Mon Sep 17 00:00:00 2001 From: Tilman Kranz Date: Mon, 29 Nov 2021 05:50:47 +0100 Subject: [PATCH 1/5] consolidate format_commit_stats --- linuxfoo-gitlab.php | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/linuxfoo-gitlab.php b/linuxfoo-gitlab.php index 85b603c..fb31146 100644 --- a/linuxfoo-gitlab.php +++ b/linuxfoo-gitlab.php @@ -48,40 +48,28 @@ class LinuxfooGitlab { } static function format_commit($atts, $commit) { - $out = ''; - preg_match('/^....-..-../', $commit->committed_date, $m); $date = $m[0]; $title = htmlspecialchars($commit->title, ENT_NOQUOTES|ENT_HTML5|ENT_SUBSTITUTE, 'UTF-8', FALSE); - $out .= + return $date.' '. __('by', 'linuxfoo-gitlab').' '.$commit->author_name. ': '. ''.$commit->short_id.' '.$title; - - return $out; } static function format_commit_stats($atts, $commits_count, $branch) { - $out = ''; - - if($commits_count==0) { - $out .= - __('No commits', 'linuxfoo-gitlab'). - (is_null($branch) ? '' : ' '.__('in branch', 'linuxfoo-gitlab').' "'.$branch.'"'). - (is_null($atts['since']) ? '' : ' '.('since '.$atts['since'].' ago')).'.'; - } - else { - $out .= - /* 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']) ? '' : ' '.self::format_since($atts['since'])).':'; - } - - return $out; + return + ( + ($commits_count==0) + ? __('No commits', 'linuxfoo-gitlab') + /* 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']) ? '' : ' '.self::format_since($atts['since'])).':'; } static function commits_list($atts, $project_url) { From 6efb5ccf18c05dec37dee2d4954705b15992bad9 Mon Sep 17 00:00:00 2001 From: Tilman Kranz Date: Mon, 29 Nov 2021 19:56:05 +0100 Subject: [PATCH 2/5] modify tag structure to avoid p and ul elements --- linuxfoo-gitlab.php | 30 +++++++++++++++--------------- styles.css | 10 +++++++--- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/linuxfoo-gitlab.php b/linuxfoo-gitlab.php index fb31146..03cf0b0 100644 --- a/linuxfoo-gitlab.php +++ b/linuxfoo-gitlab.php @@ -132,13 +132,13 @@ class LinuxfooGitlab { ''; if($commits_count>0) { - $out .= ''; + $out .= ''; } } } @@ -171,32 +171,32 @@ class LinuxfooGitlab { else { 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 .= ''; } } } @@ -212,7 +212,7 @@ class LinuxfooGitlab { static function show_project($atts, $content, $tag) { global $post; - $out = '
'; + $out = ''; if( is_null($atts['url']) || @@ -255,7 +255,7 @@ class LinuxfooGitlab { } } - $out .= '
'; + $out .= ''; return $out; } diff --git a/styles.css b/styles.css index 229f784..1dec3c9 100644 --- a/styles.css +++ b/styles.css @@ -1,13 +1,17 @@ .linuxfoo_gitlab { + display: block; border: 1px dashed #8a8a8a; border-radius: .5em; padding: .25em .5em; } -.linuxfoo_gitlab .commits { +.linuxfoo_gitlab .commits, .linuxfoo_gitlab .releases { + display: block; margin: .25em 0 .25em 0; } -.linuxfoo_gitlab .releases { - margin: .25em 0 .25em 0; +.linuxfoo_gitlab .commit, .linuxfoo_gitlab .release { + display: list-item; + list-style-type: square; + margin: 0 0 0 1em; } .linuxfoo_gitlab .project_header { display: block; From 4b7b8d4a13ded86e6d45e4914e333ce7ba060166 Mon Sep 17 00:00:00 2001 From: Tilman Kranz Date: Tue, 30 Nov 2021 01:48:11 +0100 Subject: [PATCH 3/5] project_header formatting --- linuxfoo-gitlab.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/linuxfoo-gitlab.php b/linuxfoo-gitlab.php index 03cf0b0..44e0a02 100644 --- a/linuxfoo-gitlab.php +++ b/linuxfoo-gitlab.php @@ -28,6 +28,14 @@ class LinuxfooGitlab { ''; } + static function project_header($atts, $project) { + return + ''. + __('Gitlab project', 'linuxfoo-gitlab').' '. + ''.$project->name.''. + ''; + } + static function format_since($since) { preg_match('/^([0-9]+)\s+(.*)$/', $since, $m); $num = $m[1]; @@ -243,12 +251,7 @@ class LinuxfooGitlab { $out .= self::error('Project information not readable.'); } else { - $out .= - ''. - __('Gitlab project', 'linuxfoo-gitlab').' '. - ''.$project->name.''. - ''; - + $out .= self::project_header($atts, $project); $out .= self::commits_list($atts, $project_url); $out .= self::releases_list($atts, $project_url); } From f6abb63a22a681cec23e1b1712c4e16770817c47 Mon Sep 17 00:00:00 2001 From: Tilman Kranz Date: Sat, 1 Jan 2022 08:08:04 +0100 Subject: [PATCH 4/5] add option author="none" --- README.md | 1 + lang/linuxfoo-gitlab-de_DE.po | 4 ++-- lang/linuxfoo-gitlab.pot | 2 +- linuxfoo-gitlab.php | 18 +++++++++++------- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 6614b18..f12a2ed 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ The following optional attributes modify the behavior of the list of commits: * `max=NUM`: Optional; `NUM`: Positive integer; list not more than `NUM` commits (example: `5`). * `ref_name=STRING`: Optional: list only commit from branch or reference name `STRING` (examples: `main`, `v1.1`). * `default_branch`: Optional; if set, list only commits from the project's default branch. +* `author="none"`: Optional; do not print names of authors in the commit list. ## Author and License diff --git a/lang/linuxfoo-gitlab-de_DE.po b/lang/linuxfoo-gitlab-de_DE.po index 9d39fe0..d993d55 100644 --- a/lang/linuxfoo-gitlab-de_DE.po +++ b/lang/linuxfoo-gitlab-de_DE.po @@ -22,8 +22,8 @@ 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 commits=\"all\" since=\"3 month\" max=5 releases=\"latest\"] for a list of at most 5 commits to that project that were made since at most 3 months ago, followed by alink to the latest release of the project (if any). To disable the list of commits, set commits=\"none\". To generate a list of all releases, set releases=\"all\". To disable the list of releases, omit the \"releases\" attribute or set releases=\"none\"." -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]. Um die Liste der Commits zu deaktivieren: commits=\"none\". Um eine Liste von Releases hinzuzufügen: releases=\"all\". Um nur die neueste Release anzuzeigen: releases=\"latest\"." +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 commits=\"all\" since=\"3 month\" max=5 releases=\"latest\"] for a list of at most 5 commits to that project that were made since at most 3 months ago, followed by alink to the latest release of the project (if any). To disable the list of commits, set commits=\"none\". To disable printing the author name of a commit, set author=\"none\". To generate a list of all releases, set releases=\"all\". To disable the list of releases, omit the \"releases\" attribute or set releases=\"none\"." +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]. Um die Liste der Commits zu deaktivieren: commits=\"none\". Um die Ausgabe der Autor-Namens pro Commit zu deaktivieren: author=\"none\". Um eine Liste von Releases hinzuzufügen: releases=\"all\". Um nur die neueste Release anzuzeigen: releases=\"latest\"." #. Author of the plugin msgid "Tilman Kranz" diff --git a/lang/linuxfoo-gitlab.pot b/lang/linuxfoo-gitlab.pot index 810ea64..53ef2a9 100644 --- a/lang/linuxfoo-gitlab.pot +++ b/lang/linuxfoo-gitlab.pot @@ -23,7 +23,7 @@ msgid "http://tk-sls.de/ref/gitlab-list-commits" 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 commits=\"all\" since=\"3 month\" max=5 releases=\"latest\"] for a list of at most 5 commits to that project that were made since at most 3 months ago, followed by alink to the latest release of the project (if any). To disable the list of commits, set commits=\"none\". To generate a list of all releases, set releases=\"all\". To disable the list of releases, omit the \"releases\" attribute or set releases=\"none\"." +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 commits=\"all\" since=\"3 month\" max=5 releases=\"latest\"] for a list of at most 5 commits to that project that were made since at most 3 months ago, followed by alink to the latest release of the project (if any). To disable the list of commits, set commits=\"none\". To disable printing the author name of a commit, set author=\"none\". To generate a list of all releases, set releases=\"all\". To disable the list of releases, omit the \"releases\" attribute or set releases=\"none\"." msgstr "" #. Author of the plugin diff --git a/linuxfoo-gitlab.php b/linuxfoo-gitlab.php index 44e0a02..599b302 100644 --- a/linuxfoo-gitlab.php +++ b/linuxfoo-gitlab.php @@ -3,7 +3,7 @@ /* 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 commits="all" since="3 month" max=5 releases="latest"] for a list of at most 5 commits to that project that were made since at most 3 months ago, followed by alink to the latest release of the project (if any). To disable the list of commits, set commits="none". To generate a list of all releases, set releases="all". To disable the list of releases, omit the "releases" attribute or set releases="none". +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 commits="all" since="3 month" max=5 releases="latest"] for a list of at most 5 commits to that project that were made since at most 3 months ago, followed by alink to the latest release of the project (if any). To disable the list of commits, set commits="none". To disable printing the author name of a commit, set author="none". To generate a list of all releases, set releases="all". To disable the list of releases, omit the "releases" attribute or set releases="none". Author: Tilman Kranz Version: 1.4 Author URI: https://tk-sls.de @@ -57,15 +57,19 @@ class LinuxfooGitlab { static function format_commit($atts, $commit) { preg_match('/^....-..-../', $commit->committed_date, $m); - $date = $m[0]; - $title = htmlspecialchars($commit->title, ENT_NOQUOTES|ENT_HTML5|ENT_SUBSTITUTE, 'UTF-8', FALSE); + $result = $m[0].' '; - return - $date.' '. - __('by', 'linuxfoo-gitlab').' '.$commit->author_name. + if($atts['author']==null || $atts['author']!='none') + $result .= + __('by', 'linuxfoo-gitlab').' '.$commit->author_name; + + $result .= ': '. - ''.$commit->short_id.' '.$title; + ''.$commit->short_id.' '. + htmlspecialchars($commit->title, ENT_NOQUOTES|ENT_HTML5|ENT_SUBSTITUTE, 'UTF-8', FALSE); + + return $result; } static function format_commit_stats($atts, $commits_count, $branch) { From fb5d9a8f52eb2c14e1b112730978c85683517ca4 Mon Sep 17 00:00:00 2001 From: Tilman Kranz Date: Sun, 28 Aug 2022 13:02:39 +0200 Subject: [PATCH 5/5] tab vs space cleanup --- linuxfoo-gitlab.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/linuxfoo-gitlab.php b/linuxfoo-gitlab.php index 599b302..0e87b76 100644 --- a/linuxfoo-gitlab.php +++ b/linuxfoo-gitlab.php @@ -10,18 +10,18 @@ Author URI: https://tk-sls.de */ class LinuxfooGitlab { - public function __construct() { - } + 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.4' ); + wp_enqueue_style('linuxfoo_gitlab_css', plugins_url('styles.css', __FILE__ ), '', '1.4' ); } - static function error ( $msg ) { + static function error ( $msg ) { return ''. $msg. @@ -84,7 +84,7 @@ class LinuxfooGitlab { (is_null($atts['since']) ? '' : ' '.self::format_since($atts['since'])).':'; } - static function commits_list($atts, $project_url) { + static function commits_list($atts, $project_url) { $since = null; if($atts['commits']=='none') { @@ -158,7 +158,7 @@ class LinuxfooGitlab { return $out; } - static function releases_list($atts, $project_url) { + static function releases_list($atts, $project_url) { $out = ''; if(is_null($atts['releases']) || $atts['releases']=='none') { @@ -217,12 +217,12 @@ class LinuxfooGitlab { return $out; } - static function list_commits($atts, $content, $tag) { + static function list_commits($atts, $content, $tag) { return self::show_project($atts, $content, $tag); } - static function show_project($atts, $content, $tag) { - global $post; + static function show_project($atts, $content, $tag) { + global $post; $out = '';