]*>(.*?)<\/title>/is', $header, $match)) { $title = trim($match[1]); } else { $title = $fname; } $shapeindex[$fname] = $title; fclose($fh); } $json = json_encode($shapeindex, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); file_put_contents($shapeindexfile, $json); return $shapeindex; } function get_shapeindex() { global $g_doc_basepath; $shapeindex = []; $shapeindexfile = $g_doc_basepath . '/shapeindex.json'; if (!file_exists($shapeindexfile)) { $shapeindex = create_shapeindex($shapeindexfile); } else { // check if shapeindex needs refresh (older than one day) if (time() - filemtime($shapeindexfile) > 86400) { $shapeindex = create_shapeindex($shapeindexfile); } else { // read svg metadata from existing file $json = file_get_contents($shapeindexfile); $shapeindex = json_decode($json, true); if (json_last_error() !== JSON_ERROR_NONE) { // some kind of error: just recreate $shapeindex = create_shapeindex($shapeindexfile); } } } return $shapeindex; } function svg_create_box($cx, $cy, $w, $h, $fg, $bg) { }