function pg_array_parse($text, &$output, $limit = false, $offset = 1) { if (false === $limit) { $limit = strlen($text) - 1; $output = array(); } if ('{}' != $text) { do { if ('{' != $text[$offset]) { preg_match("/(\\{?\"([^\"\\\\]|\\\\.)*\"|[^,{}]+)+([,}]+)/", $text, $match, 0, $offset); $offset += strlen($match[0]); $output[] = '"' != $match[1][0] ? $match[1] : stripcslashes(substr($match[1], 1, -1)); if ('},' == $match[3]) { return $offset; } } else { $offset = pg_array_parse($text, $output[], $limit, $offset + 1); } } while ($limit > $offset); } return $output; }
$desc = "<p>" . $row["desc"] . "</p><a href=\"http://commons.wikipedia.org/wiki/" . htmlspecialchars($row["page"]) . "?uselang=ru\" target=_blank><img src=\"" . htmlspecialchars(furl(str_replace(" ", "_", str_replace("File:", "", $row["page"])))) . "\" /></a><br><font style='font-size: 9px'>" . $links . "</font>"; return $desc; } while ($row = pg_fetch_assoc($res)) { $pm = $doc->addChild("Placemark"); $pm->addChild("name"); $pm->name = "<a href=\"http://commons.wikimedia.org/\"><img src=\"img/commons-mini.png\" width=\"20\" height=\"27\" border=\"0\"></a> Wikimedia Commons"; $pm->addChild("description"); $links = "<a href=\"http://commons.wikimedia.org/w/index.php?title=" . urlencode($row["page"]) . "&action=edit\" target=\"_blank\">Править</a>"; $links .= " <a href=\"wpc-up.php?title=" . urlencode($row["page"]) . "\" target=\"_blank\">Обновить</a>"; if ($row["cnt"] < 2) { $pm->{'description'} = row2desc($row); } elseif ($row["cnt"] < 17) { $es = array(); $pages = ""; pg_array_parse($row["pages"], $pages); foreach ($pages as $p) { $es[] = "'" . pg_escape_string($p) . "'"; } $q = "SELECT page,\"desc\",ST_X(point) AS lon,ST_Y(point) AS lat FROM wpc_img WHERE page IN (" . implode(",", $es) . ") LIMIT 16"; $qres = pg_query($q); $desc = null; $i = 1; while ($qrow = pg_fetch_assoc($qres)) { $display = "block"; if ($desc) { $display = "none"; } $bar = "<br><a href='#' onclick='wpcprev(event);return false;'>«</a> {$i}/" . $row["cnt"] . " <a href='#' onclick='wpcnext(event);return false;'>»</a>"; $desc .= "<div style='display: {$display}'>" . row2desc($qrow) . $bar . "</div>"; $i++;