Compare commits

...

15 Commits
main ... main

Author SHA1 Message Date
root 3596243319 correct json pat to commit message 2023-09-23 16:00:11 +02:00
root fccb7dd511 correct message formatting 2023-09-23 15:58:57 +02:00
root 19f52bfb1c correct class names 2023-09-23 15:56:40 +02:00
root 0a9093c72d correct shortcode 2023-09-23 15:54:07 +02:00
root 707ee80e4e correct class name 2023-09-23 15:50:53 +02:00
root a820f609be update project documentation 2023-09-23 15:40:13 +02:00
root b0313b3f7c update description and usage instructions (German translation) 2023-09-23 15:31:53 +02:00
root 8b15a3162b update description and usage instructions 2023-09-23 15:30:19 +02:00
root bebd5f2551 update description and usage instructions 2023-09-23 15:28:05 +02:00
root 7642f91b18 port from gitlab to gitea (done, untested)
Done: port to gitea API; Broken: filter commits since date
2023-09-23 15:26:08 +02:00
root 18f7d56fcd port from gitlab to gitea (WIP)
Done fix wording and gettext domain references
ToDo port API calls
2023-09-23 14:36:46 +02:00
root 590f35c0a0 correct base url of example gitea 2023-09-23 14:32:25 +02:00
root e2fde7594d rename file, update translations and code references 2023-09-23 14:31:41 +02:00
root 845e3cf083 rename file, update translations and code references 2023-09-23 14:28:23 +02:00
root 7e141853a4 rename plugin file 2023-09-23 14:25:34 +02:00
5 changed files with 119 additions and 136 deletions

View File

@ -1,37 +1,38 @@
# linuxfoo-gitlab
# linuxfoo-gitea
## Summary
Embed a list of the most recent commits to a Gitlab project. Information is retrieved from a specified Gitlab instance's public REST API.
Embed a list of the most recent commits to a Gitea project. Information is retrieved from a specified Gitea instance's public REST API.
## Shortcode `gitlab-show-project`
## Shortcode `gitea-show-project`
### Examples
Add the following shortcode for a list of at most 5 commits to that project that were made since at most 3 months ago:
Add the following shortcode for a list of at most 5 commits to that project:
```
[gitlab-show-project url="https://tk-sls.de/gitlab" project_id=42 since="3 months" max=5]
[gitea-show-project url="https://tk-sls.de/git" project_owner=tk-sls.de project_repo=linuxfoo-gitea max=5]
```
Add the following shortcode for a list of at most 3 commits followed by a link to the latest release:
```
[gitlab-show-project url="https://tk-sls.de/gitlab" project_id=42 max=3 releases="latest"]
[gitea-show-project url="https://tk-sls.de/git" project_owner=tk-sls.de project_repo=linuxfoo-gitea max=3 releases="latest"]
```
Add the following shortcode to just link to the Gitlab project, without a list of commits or releases:
```
[gitlab-show-project url="https://tk-sls.de/gitlab" project_id=42 commit="none" releases="none"]
[gitea-show-project url="https://tk-sls.de/git" project_owner=tk-sls.de project_repo=linuxfoo-gitea commit="none" releases="none"]
```
### Attributes
The following attributes are mandatory:
* `url="STRING"`: Base URL of Gitlab instance (example: `https://tk-sls.de/gitlab`).
* `project_id=NUM`: ; `NUM`: Positive Integer, valid project ID in Gitlab specified by `url` (example: `42`).
* `url="STRING"`: Base URL of Git instance (example: `https://tk-sls.de/git`).
* `project_owner=STRING`: ; `STRING`: User or organisation owning the repository in Gitea (examples: `tilman`, `tk-sls.de`).
* `project_repo=STRING`: ; `STRING`: Name of repository in Gitea (examples: `tilman`, `tk-sls.de`).
The following optional attributes enable or disable additional project information:
@ -40,7 +41,6 @@ The following optional attributes enable or disable additional project informati
The following optional attributes modify the behavior of the list of commits:
* `since="NUM UNIT"`: Optional; `NUM`: Positive integer; `UNIT`: `days`, `months`, `years`; exclude commits older than specified time interval (example: `3 months`).
* `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.
@ -48,5 +48,5 @@ The following optional attributes modify the behavior of the list of commits:
## Author and License
* Copyleft 2021 Tilman Kranz <[t.kranz@tk-sls.de](mailto:t.kranz@tk-sls.de)>
* Copyleft 2023 Tilman Kranz <[t.kranz@tk-sls.de](mailto:t.kranz@tk-sls.de)>
* License: MIT License [https://opensource.org/licenses/MIT](https://opensource.org/licenses/MIT)

View File

@ -1,9 +1,9 @@
# Copyright (C) 2021 Tilman Kranz
# This file is distributed under the same license as the Gitlab REST API Shortcodes plugin.
# This file is distributed under the same license as the Gitea REST API Shortcodes plugin.
msgid ""
msgstr ""
"Project-Id-Version: Gitlab REST API Shortcodes 1.2\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/linuxfoo-gitlab\n"
"Project-Id-Version: Gitea REST API Shortcodes 1.2\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/linuxfoo-gitea\n"
"Last-Translator: Tilman Kranz <t.kranz@tk-sls.de>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@ -11,19 +11,19 @@ msgstr ""
"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"
"X-Domain: linuxfoo-gitea\n"
#. Plugin Name of the plugin
msgid "Gitlab REST API Shortcodes"
msgstr "Gitlab REST API Shortcodes"
msgid "Gitea REST API Shortcodes"
msgstr "Gitea 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"
msgid "http://tk-sls.de/ref/gitea-list-commits"
msgstr "http://tk-sls.de/ref/gitea-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 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\"."
msgid "Summary: Embed list of most recent commits to a Gitea project from a Gitea instance's public REST API. Example: Add [gitea-list-commits url=https://tk-sls.de/git/ project_owner=tk-sls.de project_repo=linuxfoo-gitea commits=\"all\" max=5 releases=\"latest\"] for a list of at most the 5 latest commits to that project, followed by a link 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 Gitea-Projektes ein, die mit Gitea REST API abgerufen wird. Beispiel: Füge folgenden Shortcode zu einem Artikel hinzu, um die letzten 5 Commits anzuzeigen: [gitea-list-commits url=https://tk-sls.de/git/ project_owner=tk-sls.de project_repo=linuxfoo-gitea 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"
@ -33,87 +33,87 @@ msgstr "Tilman Kranz"
msgid "https://tk-sls.de"
msgstr "https://tk-sls.de"
#: linuxfoo-gitlab.php:39
#: linuxfoo-gitea.php:39
msgid "days"
msgstr "Tagen"
#: linuxfoo-gitlab.php:42
#: linuxfoo-gitea.php:42
msgid "months"
msgstr "Monaten"
#: linuxfoo-gitlab.php:45
#: linuxfoo-gitea.php:45
msgid "years"
msgstr "Jahren"
#. translators: %d: count, %s unit of time interval
#: linuxfoo-gitlab.php:49
#: linuxfoo-gigiteatlab.php:49
msgid "since %d %s ago"
msgstr "seit %d %s"
#: linuxfoo-gitlab.php:57
#: linuxfoo-gitea.php:57
msgid "Invalid value for parameter \"commits\"."
msgstr "Unzulässiger Wert für Parameter \"commits\"."
#: linuxfoo-gitlab.php:59
#: linuxfoo-gitea.php:59
msgid "Required parameter missing."
msgstr "Notwendiger Parameter fehlt"
#: linuxfoo-gitlab.php:62
#: linuxfoo-gitlab.php:68
#: linuxfoo-gitea.php:62
#: linuxfoo-gitea.php:68
msgid "Invalid value for parameter \"project_id\"."
msgstr "Unzulässiger Wert für Parameter \"project_id\"."
#: linuxfoo-gitlab.php:65
#: linuxfoo-gitea.php:65
msgid "Invalid value for parameter \"url\"."
msgstr "Unzulässiger Wert für Parameter \"url\"."
#: linuxfoo-gitlab.php:75
#: linuxfoo-gitea.php:75
msgid "Project URL not reachable."
msgstr "Gitlab-Projekt-URL nicht erreichbar."
#: linuxfoo-gitlab.php:86
#: linuxfoo-gitea.php:86
msgid "Gitlab project"
msgstr "Gitlab-Projekt"
#: linuxfoo-gitlab.php:93
#: linuxfoo-gitea.php:93
msgid "Invalid value for parameter \"since\"."
msgstr "Unzulässiger Wert für Parameter \"since\"."
#: linuxfoo-gitlab.php:115
#: linuxfoo-gitea.php:115
msgid "Commits URL not reachable."
msgstr "Gitlab-Commits-URL nicht erreichbar."
#: linuxfoo-gitlab.php:121
#: linuxfoo-gitea.php:121
msgid "Commits information not readable."
msgstr "Commit-Information nicht lesbar."
#: linuxfoo-gitlab.php:132
#: linuxfoo-gitea.php:132
msgid "No commits"
msgstr "Keine aktuellen Commits"
#: linuxfoo-gitlab.php:133
#: linuxfoo-gitlab.php:147
#: linuxfoo-gitea.php:133
#: linuxfoo-gitea.php:147
msgid "in branch"
msgstr "im Branch"
#. translators: %d: maximum number of commits displayed
#: linuxfoo-gitlab.php:146
#: linuxfoo-gitea.php:146
msgid "Last %d commits"
msgstr "Letzte %d Commits"
#: linuxfoo-gitlab.php:172
#: linuxfoo-gitea.php:172
msgid "Invalid value for parameter \"releases\"."
msgstr "Unzulässiger Wert für Parameter \"releases\"."
#: linuxfoo-gitlab.php:179
#: linuxfoo-gitea.php:179
msgid "Releases URL not reachable."
msgstr "Releases-URL nicht erreichbar."
#: linuxfoo-gitlab.php:185
#: linuxfoo-gitea.php:185
msgid "Releases information not readable."
msgstr "Releases-Information nicht lesbar."
#: linuxfoo-gitlab.php:189
#: linuxfoo-gitea.php:189
msgid "This project has currently no releases."
msgstr "Dieses Projekt hat derzeit keine Releases."

View File

@ -2,8 +2,8 @@
# 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.2\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/linuxfoo-gitlab\n"
"Project-Id-Version: Gitea REST API Shortcodes 1.2\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/linuxfoo-gitea\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
@ -15,15 +15,15 @@ msgstr ""
"X-Domain: linuxfoo-gitlab\n"
#. Plugin Name of the plugin
msgid "Gitlab REST API Shortcodes"
msgid "Gitea REST API Shortcodes"
msgstr ""
#. Plugin URI of the plugin
msgid "http://tk-sls.de/ref/gitlab-list-commits"
msgid "http://tk-sls.de/ref/gitea-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 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\"."
msgid "Summary: Embed list of most recent commits to a Gitea project from a Gitea instance's public REST API. Example: Add [gitea-list-commits url=https://tk-sls.de/git/ project_owner=tk-sls.de project_repo=linuxfoo-gitea commits=\"all\" max=5 releases=\"latest\"] for a list of at most the 5 latest commits to that project, followed by a link 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
@ -34,87 +34,87 @@ msgstr ""
msgid "https://tk-sls.de"
msgstr ""
#: linuxfoo-gitlab.php:37
#: linuxfoo-gitea.php:37
msgid "days"
msgstr ""
#: linuxfoo-gitlab.php:40
#: linuxfoo-gitea.php:40
msgid "months"
msgstr ""
#: linuxfoo-gitlab.php:43
#: linuxfoo-gitea.php:43
msgid "years"
msgstr ""
#. translators: %d: count, %s unit of time interval
#: linuxfoo-gitlab.php:47
#: linuxfoo-gitea.php:47
msgid "since %d %s ago"
msgstr ""
#: linuxfoo-gitlab.php:57
#: linuxfoo-gitea.php:57
msgid "Invalid value for parameter \"commits\"."
msgstr ""
#: linuxfoo-gitlab.php:61
#: linuxfoo-gitea.php:61
msgid "Invalid value for parameter \"since\"."
msgstr ""
#: linuxfoo-gitlab.php:91
#: linuxfoo-gitea.php:91
msgid "Commits URL not reachable."
msgstr ""
#: linuxfoo-gitlab.php:97
#: linuxfoo-gitea.php:97
msgid "Commits information not readable."
msgstr ""
#: linuxfoo-gitlab.php:108
#: linuxfoo-gitea.php:108
msgid "No commits"
msgstr ""
#: linuxfoo-gitlab.php:109
#: linuxfoo-gitlab.php:118
#: linuxfoo-gitea.php:109
#: linuxfoo-gitea.php:118
msgid "in branch"
msgstr ""
#. translators: %d: maximum number of commits displayed
#: linuxfoo-gitlab.php:117
#: linuxfoo-gitea.php:117
msgid "Last %d commits"
msgstr ""
#: linuxfoo-gitlab.php:150
#: linuxfoo-gitea.php:150
msgid "Invalid value for parameter \"releases\"."
msgstr ""
#: linuxfoo-gitlab.php:157
#: linuxfoo-gitea.php:157
msgid "Releases URL not reachable."
msgstr ""
#: linuxfoo-gitlab.php:163
#: linuxfoo-gitea.php:163
msgid "Releases information not readable."
msgstr ""
#: linuxfoo-gitlab.php:169
#: linuxfoo-gitea.php:169
msgid "This project has currently no releases."
msgstr ""
#: linuxfoo-gitlab.php:175
#: linuxfoo-gitea.php:175
msgid "Latest release"
msgstr ""
#: linuxfoo-gitlab.php:182
#: linuxfoo-gitea.php:182
msgid "Releases"
msgstr ""
#: linuxfoo-gitlab.php:215
#: linuxfoo-gitea.php:215
msgid "Required parameter missing."
msgstr ""
#: linuxfoo-gitlab.php:218
#: linuxfoo-gitlab.php:224
#: linuxfoo-gitea.php:218
#: linuxfoo-gitea.php:224
msgid "Invalid value for parameter \"project_id\"."
msgstr ""
#: linuxfoo-gitlab.php:221
#: linuxfoo-gitea.php:221
msgid "Invalid value for parameter \"url\"."
msgstr ""

View File

@ -1,24 +1,24 @@
<?php
/*
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 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".
Plugin Name: Gitea REST API Shortcodes
Plugin URI: http://tk-sls.de/ref/gitea-list-commits
Description: Summary: Embed list of most recent commits to a Gitea project from a Gitea instance's public REST API. Example: Add [gitea-list-commits url=https://tk-sls.de/git/ project_owner=tk-sls.de project_repo=linuxfoo-gitea commits="all" max=5 releases="latest"] for a list of at most the 5 latest commits to that project, followed by a link 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
*/
class LinuxfooGitlab {
class LinuxfooGitea {
public function __construct() {
}
static function load_textdomain() {
load_plugin_textdomain('linuxfoo-gitlab', false, dirname(plugin_basename(__FILE__)).'/lang');
load_plugin_textdomain('linuxfoo-gitea', 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_gitea_css', plugins_url('styles.css', __FILE__ ), '', '1.4' );
}
static function error ( $msg ) {
@ -31,8 +31,8 @@ class LinuxfooGitlab {
static function project_header($atts, $project) {
return
'<span class="project_header">'.
__('Gitlab project', 'linuxfoo-gitlab').' '.
'<a href="'.$project->web_url.'">'.$project->name.'</a>'.
__('Gitea project', 'linuxfoo-gitea').' '.
'<a href="'.$project->html_url.'">'.$project->name.'</a>'.
'</span>';
}
@ -42,17 +42,17 @@ class LinuxfooGitlab {
$unit = $m[2];
if($unit=='days') {
$unit = __('days', 'linuxfoo-gitlab');
$unit = __('days', 'linuxfoo-gitea');
}
elseif($unit=='months') {
$unit = __('months', 'linuxfoo-gitlab');
$unit = __('months', 'linuxfoo-gitea');
}
elseif($unit=='years') {
$unit = __('years', 'linuxfoo-gitlab');
$unit = __('years', 'linuxfoo-gitea');
}
/* translators: %d: count, %s unit of time interval*/
return sprintf(__('since %d %s ago', 'linuxfoo-gitlab'), $num, $unit);
return sprintf(__('since %d %s ago', 'linuxfoo-gitea'), $num, $unit);
}
static function format_commit($atts, $commit) {
@ -62,12 +62,12 @@ class LinuxfooGitlab {
if($atts['author']==null || $atts['author']!='none')
$result .=
__('by', 'linuxfoo-gitlab').' '.$commit->author_name;
__('by', 'linuxfoo-gitea').' '.$commit->commit->author->name;
$result .=
': '.
'<a href="'.$commit->web_url.'">'.$commit->short_id.'</a> '.
htmlspecialchars($commit->title, ENT_NOQUOTES|ENT_HTML5|ENT_SUBSTITUTE, 'UTF-8', FALSE);
'<a href="'.$commit->html_url.'">'.substr($commit->sha, 0, 8).'</a> '.
htmlspecialchars(preg_replace('/\n.*/', '', $commit->commit->message), ENT_NOQUOTES|ENT_HTML5|ENT_SUBSTITUTE, 'UTF-8', FALSE);
return $result;
}
@ -76,11 +76,11 @@ class LinuxfooGitlab {
return
(
($commits_count==0)
? __('No commits', 'linuxfoo-gitlab')
? __('No commits', 'linuxfoo-gitea')
/* translators: %d: maximum number of commits displayed */
: sprintf(__('Last %d commits', 'linuxfoo-gitlab'), $commits_count)
: sprintf(__('Last %d commits', 'linuxfoo-gitea'), $commits_count)
).
(is_null($branch) ? '' : ' '.__('in branch', 'linuxfoo-gitlab').' "'.$branch.'"').
(is_null($branch) ? '' : ' '.__('in branch', 'linuxfoo-gitea').' "'.$branch.'"').
(is_null($atts['since']) ? '' : ' '.self::format_since($atts['since'])).':';
}
@ -91,31 +91,19 @@ class LinuxfooGitlab {
return '';
}
elseif(!is_null($atts['commits']) && $atts['commits']!='all') {
return self::error(__('Invalid value for parameter "commits".', 'linuxfoo-gitlab'));
}
elseif(!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'));
}
else {
$since = date(DATE_ISO8601, strtotime('-'.$atts['since']));
}
return self::error(__('Invalid value for parameter "commits".', 'linuxfoo-gitea'));
}
$out = '';
$commits_url = $project_url.'/repository/commits?';
if(!is_null($since)) {
$commits_url .= '&since='.$since;
}
$commits_url = $project_url.'/commits?stat=false&verification=false&files=false';
if(!is_null($atts['ref_name'])) {
$commits_url .= '&ref_name='.$atts['ref_name'];
$commits_url .= '&sha='.$atts['ref_name'];
$branch = $atts['ref_name'];
}
elseif(!is_null($atts['default_branch'])) {
$commits_url .= '&ref_name='.$project->default_branch;
elseif(!is_null($project->default_branch)) {
$commits_url .= '&sha='.$project->default_branch;
$branch = $project->default_branch;
}
else {
@ -125,13 +113,13 @@ class LinuxfooGitlab {
$commits_json = file_get_contents($commits_url);
if(is_null($commits_json)) {
$out .= self::error(__('Commits URL not reachable.', 'linuxfoo-gitlab'));
$out .= self::error(__('Commits URL not reachable.', 'linuxfoo-gitea'));
}
else {
$commits = json_decode($commits_json);
if(is_null($commits)) {
$out .= self::error(__('Commits information not readable.', 'linuxfoo-gitlab'));
$out .= self::error(__('Commits information not readable.', 'linuxfoo-gitea'));
}
else {
$commits_count = count($commits);
@ -165,46 +153,46 @@ class LinuxfooGitlab {
$out .= '';
}
elseif(!preg_match('/^(all|latest)$/', $atts['releases'])) {
$out .= self::error(__('Invalid value for parameter "releases".', 'linuxfoo-gitlab'));
$out .= self::error(__('Invalid value for parameter "releases".', 'linuxfoo-gitea'));
}
else {
$releases_url = $project_url.'/releases?';
$releases_json = file_get_contents($releases_url);
if(is_null($releases_json)) {
$out .= self::error(__('Releases URL not reachable.', 'linuxfoo-gitlab'));
$out .= self::error(__('Releases URL not reachable.', 'linuxfoo-gitea'));
}
else {
$releases = json_decode($releases_json);
if(is_null($releases)) {
$out .= self::error(__('Releases information not readable.', 'linuxfoo-gitlab'));
$out .= self::error(__('Releases information not readable.', 'linuxfoo-gitea'));
}
else {
if(count($releases)==0) {
$out .=
'<span class="releases">'.
__('This project has currently no releases.', 'linuxfoo-gitlab').
__('This project has currently no releases.', 'linuxfoo-gitea').
'</span>';
}
elseif($atts['releases']=='latest') {
$out .=
'<span class="releases">'.
__('Latest release', 'linuxfoo-gitlab').': '.
'<a href="'.$releases[0]->_links->self.'">'.$releases[0]->name.'</a>'.
__('Latest release', 'linuxfoo-gitea').': '.
'<a href="'.$releases[0]->html_url.'">'.$releases[0]->name.'</a>'.
'</span>';
}
elseif($atts['releases']=='all') {
$out .=
'<span class="releases">'.
__('Releases', 'linuxfoo-gitlab').': '.
__('Releases', 'linuxfoo-gitea').': '.
'</span>'.
'<span class="releases" role="list">';
foreach($releases as $release) {
$out .=
'<span class="release">'.
'<a href="'.$release->_links->self.'">'.$release->name.'</a>'.
'<a href="'.$release->html_url.'">'.$release->name.'</a>'.
'</span>';
}
@ -224,29 +212,24 @@ class LinuxfooGitlab {
static function show_project($atts, $content, $tag) {
global $post;
$out = '<span class="linuxfoo_gitlab">';
$out = '<span class="linuxfoo_gitea">';
if(
is_null($atts['url']) ||
is_null($atts['project_id'])
is_null($atts['project_owner']) ||
is_null($atts['project_repo'])
) {
$out .= self::error(__('Required parameter missing.', 'linuxfoo-gitlab'));
}
elseif(!preg_match('/^[1-9][0-9]*$/', $atts['project_id'])) {
$out .= self::error(__('Invalid value for parameter "project_id".', 'linuxfoo-gitlab'));
$out .= self::error(__('Required parameter missing.', 'linuxfoo-gitea'));
}
elseif(!filter_var($atts['url'], FILTER_VALIDATE_URL)) {
$out .= self::error(__('Invalid value for parameter "url".', 'linuxfoo-gitlab'));
}
elseif(!preg_match('/^[1-9][0-9]*$/', $atts['project_id'])) {
$out .= self::error(__('Invalid value for parameter "project_id".', 'linuxfoo-gitlab'));
$out .= self::error(__('Invalid value for parameter "url".', 'linuxfoo-gitea'));
}
else {
$project_url = $atts['url'].'/api/v4/projects/'.$atts['project_id'];
$project_url = $atts['url'].'/api/v1/repos/'.$atts['project_owner'].'/'.$atts['project_repo'];
$project_json = file_get_contents($project_url);
if(is_null($project_json)) {
$out .= self::error(__('Project URL not reachable.', 'linuxfoo-gitlab'));
$out .= self::error(__('Project URL not reachable.', 'linuxfoo-gitea'));
}
else {
$project = json_decode($project_json);
@ -268,7 +251,7 @@ 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');
add_action('plugins_loaded', 'LinuxfooGitea::load_textdomain');
add_action('wp_enqueue_scripts', 'LinuxfooGitea::css' );
add_shortcode('gitea-list-commits', 'LinuxfooGitea::list_commits');
add_shortcode('gitea-show-project', 'LinuxfooGitea::show_project');

View File

@ -1,21 +1,21 @@
.linuxfoo_gitlab {
.linuxfoo_gitea {
display: block;
border: 1px dashed #8a8a8a;
border-radius: .5em;
padding: .25em .5em;
}
.linuxfoo_gitlab .commits, .linuxfoo_gitlab .releases {
.linuxfoo_gitea .commits, .linuxfoo_gitlab .releases {
display: block;
margin: .25em 0 .25em 0;
}
.linuxfoo_gitlab .commit, .linuxfoo_gitlab .release {
.linuxfoo_gitea .commit, .linuxfoo_gitlab .release {
display: list-item;
list-style-type: square;
margin: 0 0 0 1em;
}
.linuxfoo_gitlab .project_header {
.linuxfoo_gitea .project_header {
display: block;
}
.linuxfoo_gitlab .stats {
.linuxfoo_gitea .stats {
font-size: smaller;
}