ci #6
2 changed files with 105 additions and 91 deletions
27
.gitea/workflows/lint.yml
Normal file
27
.gitea/workflows/lint.yml
Normal file
|
@ -0,0 +1,27 @@
|
|||
name: lint
|
||||
run-name: lint is launched by ${{ github.actor }}
|
||||
on: [push]
|
||||
jobs:
|
||||
check:
|
||||
runs-on: ubuntu-latest
|
||||
name: lint
|
||||
steps:
|
||||
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
|
||||
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!"
|
||||
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v4
|
||||
- name: Install linters using Composer
|
||||
run: |
|
||||
export COMPOSER_HOME=/tmp
|
||||
echo "{}" > composer.json
|
||||
composer config --no-interaction allow-plugins.bamarni/composer-bin-plugin true
|
||||
composer require --dev bamarni/composer-bin-plugin
|
||||
composer bin phplint require --dev overtrue/phplint
|
||||
composer require --dev friendsofphp/php-cs-fixer
|
||||
- name: Lint
|
||||
run: vendor/bin/phplint --no-cache --no-progress --exclude=vendor --verbose
|
||||
- name: PHP CS Fixer
|
||||
run: vendor/bin/php-cs-fixer fix --dry-run --verbose --diff .
|
||||
- run: echo "🍏 This job's status is ${{ job.status }}."
|
||||
|
169
shaargem.php
169
shaargem.php
|
@ -24,7 +24,7 @@ const EXT_TRANSLATION_DOMAIN = 'shaargem';
|
|||
*/
|
||||
function shaargem_t($text, $nText = '', $nb = 1)
|
||||
{
|
||||
return t($text, $nText, $nb, EXT_TRANSLATION_DOMAIN);
|
||||
return t($text, $nText, $nb, EXT_TRANSLATION_DOMAIN);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,15 +60,15 @@ function shaargem_init($conf)
|
|||
*/
|
||||
function hook_shaargem_render_editlink($data)
|
||||
{
|
||||
// fetch title only for gemini:// iris
|
||||
if(isset($data['link']['url'])) {
|
||||
if(strstr($data['link']['url'],"gemini://")) {
|
||||
if ($data['link']['title'] == '') {
|
||||
$data['link']['title'] = fetch_iri_title($data['link']['url']);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
// fetch title only for gemini:// iris
|
||||
if(isset($data['link']['url'])) {
|
||||
if(strstr($data['link']['url'], "gemini://")) {
|
||||
if ($data['link']['title'] == '') {
|
||||
$data['link']['title'] = fetch_iri_title($data['link']['url']);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,15 +83,14 @@ function hook_shaargem_render_editlink($data)
|
|||
*/
|
||||
function hook_shaargem_save_link($data)
|
||||
{
|
||||
// ugly hack to get scheme
|
||||
if(isset($_POST['lf_url'])) {
|
||||
if(strstr($_POST['lf_url'],"gemini://"))
|
||||
{
|
||||
$new_url = str_replace("http://","gemini://",$data['url']);
|
||||
$data['url'] = $new_url;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
// ugly hack to get scheme
|
||||
if(isset($_POST['lf_url'])) {
|
||||
if(strstr($_POST['lf_url'], "gemini://")) {
|
||||
$new_url = str_replace("http://", "gemini://", $data['url']);
|
||||
$data['url'] = $new_url;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,10 +111,10 @@ function hook_shaargem_save_link($data)
|
|||
*/
|
||||
function hook_shaargem_render_linklist($data)
|
||||
{
|
||||
foreach ($data['links'] as &$value) {
|
||||
$value['description'] = preg_replace(',gemini://([\d\w\.\+\-@\:%._\~#=/]+),','<a href="gemini://\1">gemini://\1</a>',$value['description']);
|
||||
}
|
||||
return $data;
|
||||
foreach ($data['links'] as &$value) {
|
||||
$value['description'] = preg_replace(',gemini://([\d\w\.\+\-@\:%._\~#=/]+),', '<a href="gemini://\1">gemini://\1</a>', $value['description']);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -123,8 +122,8 @@ function hook_shaargem_render_linklist($data)
|
|||
*/
|
||||
function shaargem_dummy_translation()
|
||||
{
|
||||
// meta
|
||||
shaargem_t('Provides Gemini protocol support.');
|
||||
// meta
|
||||
shaargem_t('Provides Gemini protocol support.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -132,74 +131,62 @@ function shaargem_dummy_translation()
|
|||
*/
|
||||
function fetch_iri_title($iri)
|
||||
{
|
||||
$ret = preg_match(",gemini://([\d\w\.\+\-@\:%._\~#=]+)/?,", $iri ,$domain);
|
||||
static $redirect_counter = 0;
|
||||
if ($ret)
|
||||
{
|
||||
$stream_context = stream_context_create([ 'ssl' => [
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false,
|
||||
'allow_self_signed' => true,
|
||||
'verify_depth' => 0 ]]);
|
||||
$ret = preg_match(",gemini://([\d\w\.\+\-@\:%._\~#=]+)/?,", $iri, $domain);
|
||||
static $redirect_counter = 0;
|
||||
if ($ret) {
|
||||
$stream_context = stream_context_create([ 'ssl' => [
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false,
|
||||
'allow_self_signed' => true,
|
||||
'verify_depth' => 0 ]]);
|
||||
|
||||
$fp = stream_socket_client("tls://".$domain[1].":1965", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $stream_context);
|
||||
$fp = stream_socket_client("tls://".$domain[1].":1965", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $stream_context);
|
||||
|
||||
if (!$fp) {
|
||||
error_log("[shaargem] $errstr ($errno)");
|
||||
} else {
|
||||
fwrite($fp, $iri."\r\n");
|
||||
$header = fgets($fp);
|
||||
$ret = preg_match(",^(\d\d) (.*)\r\n$,", $header, $headers);
|
||||
$status = $headers[1];
|
||||
$meta = $headers[2];
|
||||
$max_redirects = 10;
|
||||
if (!$fp) {
|
||||
error_log("[shaargem] $errstr ($errno)");
|
||||
} else {
|
||||
fwrite($fp, $iri."\r\n");
|
||||
$header = fgets($fp);
|
||||
$ret = preg_match(",^(\d\d) (.*)\r\n$,", $header, $headers);
|
||||
$status = $headers[1];
|
||||
$meta = $headers[2];
|
||||
$max_redirects = 10;
|
||||
|
||||
error_log("[shaargem] status:".$status.", meta:".$meta);
|
||||
error_log("[shaargem] status:".$status.", meta:".$meta);
|
||||
|
||||
// status 1x cannot be handled by shaarli, but input field can be used as title
|
||||
if ($status[0] == 1)
|
||||
{
|
||||
return $meta;
|
||||
}
|
||||
// status 2x ok
|
||||
elseif ($status[0] == 2)
|
||||
{
|
||||
$nblines = 1;
|
||||
while($line = fgets($fp)) {
|
||||
$ret = preg_match(",# (.*),",$line,$title);
|
||||
if ($title[0] or $nblines > 100 ) {
|
||||
break;
|
||||
}
|
||||
$nblines++;
|
||||
}
|
||||
}
|
||||
// status 3x redirect
|
||||
elseif ($status[0] == 3 and $redirect_counter < $max_redirects)
|
||||
{
|
||||
$redirect_counter++;
|
||||
error_log("[shaargem] ".shaargem_t("Redirecting to")." ".$meta." (".$redirect_counter."/".$max_redirects.")");
|
||||
$title[1] = fetch_iri_title($meta);
|
||||
}
|
||||
// 4x 5x 6x are error statuses, should find a better way to display that
|
||||
elseif ($status[0] == 4)
|
||||
{
|
||||
return shaargem_t('Error').' '.$status.' ('.shaargem_t('TEMPORARY FAILURE').'): '.$meta;
|
||||
}
|
||||
elseif ($status[0] == 5)
|
||||
{
|
||||
return shaargem_t('Error').' '.$status.' ('.shaargem_t('PERMANENT FAILURE').'): '.$meta;
|
||||
}
|
||||
elseif ($status[0] == 6)
|
||||
{
|
||||
return shaargem_t('Error').' '.$status.' ('.shaargem_t('CLIENT CERTIFICATE REQUIRED').'): '.$meta;
|
||||
}
|
||||
else
|
||||
{
|
||||
return shaargem_t('Invalid response').': '.$header;
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
return $title[1];
|
||||
}
|
||||
// status 1x cannot be handled by shaarli, but input field can be used as title
|
||||
if ($status[0] == 1) {
|
||||
return $meta;
|
||||
}
|
||||
// status 2x ok
|
||||
elseif ($status[0] == 2) {
|
||||
$nblines = 1;
|
||||
while($line = fgets($fp)) {
|
||||
$ret = preg_match(",# (.*),", $line, $title);
|
||||
if ($title[0] or $nblines > 100) {
|
||||
break;
|
||||
}
|
||||
$nblines++;
|
||||
}
|
||||
}
|
||||
// status 3x redirect
|
||||
elseif ($status[0] == 3 and $redirect_counter < $max_redirects) {
|
||||
$redirect_counter++;
|
||||
error_log("[shaargem] ".shaargem_t("Redirecting to")." ".$meta." (".$redirect_counter."/".$max_redirects.")");
|
||||
$title[1] = fetch_iri_title($meta);
|
||||
}
|
||||
// 4x 5x 6x are error statuses, should find a better way to display that
|
||||
elseif ($status[0] == 4) {
|
||||
return shaargem_t('Error').' '.$status.' ('.shaargem_t('TEMPORARY FAILURE').'): '.$meta;
|
||||
} elseif ($status[0] == 5) {
|
||||
return shaargem_t('Error').' '.$status.' ('.shaargem_t('PERMANENT FAILURE').'): '.$meta;
|
||||
} elseif ($status[0] == 6) {
|
||||
return shaargem_t('Error').' '.$status.' ('.shaargem_t('CLIENT CERTIFICATE REQUIRED').'): '.$meta;
|
||||
} else {
|
||||
return shaargem_t('Invalid response').': '.$header;
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
return $title[1];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue