This commit is contained in:
parent
2fa417de10
commit
1372755830
1 changed files with 78 additions and 91 deletions
31
shaargem.php
31
shaargem.php
|
@ -85,8 +85,7 @@ function hook_shaargem_save_link($data)
|
|||
{
|
||||
// ugly hack to get scheme
|
||||
if(isset($_POST['lf_url'])) {
|
||||
if(strstr($_POST['lf_url'],"gemini://"))
|
||||
{
|
||||
if(strstr($_POST['lf_url'], "gemini://")) {
|
||||
$new_url = str_replace("http://", "gemini://", $data['url']);
|
||||
$data['url'] = $new_url;
|
||||
}
|
||||
|
@ -134,8 +133,7 @@ function fetch_iri_title($iri)
|
|||
{
|
||||
$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,13 +155,11 @@ 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);
|
||||
|
@ -174,27 +170,19 @@ function fetch_iri_title($iri)
|
|||
}
|
||||
}
|
||||
// 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];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue