find first title within 100 lines

This commit is contained in:
n 2021-02-27 19:39:00 +01:00
parent 4459a95b40
commit cf916f6b8b
Signed by: n
GPG key ID: E96086FC951DAE30

View file

@ -77,11 +77,20 @@ function hook_shaargem_render_editlink($data)
error_log("$errstr ($errno)"); error_log("$errstr ($errno)");
} else { } else {
fwrite($fp, $data['link']['url']."\r\n"); fwrite($fp, $data['link']['url']."\r\n");
$header = fgets($fp,1024); $header = fgets($fp);
error_log("header:".$header); error_log("header:".$header);
if (strstr($header, "20 text/gemini")) if (strstr($header, "20 text/gemini"))
{ {
$data['link']['title'] = substr(fgets($fp,1024),2,-1); $nblines = 1;
while($line = fgets($fp)) {
$ret = preg_match(",# (.*),",$line,$title);
if ($title[0] or $nblines > 100 ) {
error_log($nblines);
break;
}
$nblines++;
}
$data['link']['title'] = $title[1];
} }
else else
{ {