PHP Coding Standards fixes
All checks were successful
lint / lint (push) Successful in 15s

This commit is contained in:
n 2024-02-11 22:04:20 +01:00
parent 2fa417de10
commit 1372755830
Signed by: n
GPG key ID: 510227DD6C502CE3

View file

@ -62,7 +62,7 @@ function hook_shaargem_render_editlink($data)
{
// fetch title only for gemini:// iris
if(isset($data['link']['url'])) {
if(strstr($data['link']['url'],"gemini://")) {
if(strstr($data['link']['url'], "gemini://")) {
if ($data['link']['title'] == '') {
$data['link']['title'] = fetch_iri_title($data['link']['url']);
}
@ -85,9 +85,8 @@ 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']);
if(strstr($_POST['lf_url'], "gemini://")) {
$new_url = str_replace("http://", "gemini://", $data['url']);
$data['url'] = $new_url;
}
}
@ -113,7 +112,7 @@ 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']);
$value['description'] = preg_replace(',gemini://([\d\w\.\+\-@\:%._\~#=/]+),', '<a href="gemini://\1">gemini://\1</a>', $value['description']);
}
return $data;
}
@ -132,10 +131,9 @@ function shaargem_dummy_translation()
*/
function fetch_iri_title($iri)
{
$ret = preg_match(",gemini://([\d\w\.\+\-@\:%._\~#=]+)/?,", $iri ,$domain);
$ret = preg_match(",gemini://([\d\w\.\+\-@\:%._\~#=]+)/?,", $iri, $domain);
static $redirect_counter = 0;
if ($ret)
{
if ($ret) {
$stream_context = stream_context_create([ 'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
@ -157,44 +155,34 @@ function fetch_iri_title($iri)
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)
{
if ($status[0] == 1) {
return $meta;
}
// status 2x ok
elseif ($status[0] == 2)
{
elseif ($status[0] == 2) {
$nblines = 1;
while($line = fgets($fp)) {
$ret = preg_match(",# (.*),",$line,$title);
if ($title[0] or $nblines > 100 ) {
$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)
{
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)
{
elseif ($status[0] == 4) {
return shaargem_t('Error').' '.$status.' ('.shaargem_t('TEMPORARY FAILURE').'): '.$meta;
}
elseif ($status[0] == 5)
{
} elseif ($status[0] == 5) {
return shaargem_t('Error').' '.$status.' ('.shaargem_t('PERMANENT FAILURE').'): '.$meta;
}
elseif ($status[0] == 6)
{
} elseif ($status[0] == 6) {
return shaargem_t('Error').' '.$status.' ('.shaargem_t('CLIENT CERTIFICATE REQUIRED').'): '.$meta;
}
else
{
} else {
return shaargem_t('Invalid response').': '.$header;
}
fclose($fp);
@ -202,4 +190,3 @@ function fetch_iri_title($iri)
return $title[1];
}
}