Exemplo n.º 1
0
/**
 * Converts longitude (in degrees) into tile X coordinate of the tile 
 * (for elliptic Mercator projection) containing the specified point 
 * at a specified level of zoom.
 *
 * @param float $longitude Longitude of the point, in degrees.</param>
 * @param int $zoom Level of detail, from 0 (the whole map as single tile)
 * to 23 (highest detail).
 * 
 * @return int The tile X coordinate.
 */
function lon_to_tile_x($longitude, $zoom)
{
    $longitude = clip($longitude, -180, 180);
    $x = ($longitude + 180) / 360;
    $size_in_tiles = 1 << $zoom;
    return min((int) ($x * $size_in_tiles), $size_in_tiles - 1);
}
function wp_syntax_highlight($match)
{
    global $wp_syntax_matches;
    // print_r($wp_syntax_matches[0][0]);
    $c = $wp_syntax_matches[0][0];
    // $c = implode('\n',$wp_syntax_matches);
    $i = intval($match[1]);
    $match = $wp_syntax_matches[$i];
    $language = strtolower(trim($match[1]));
    // $line = trim($match[2]);
    $line = trim(1);
    $escaped = trim($match[3]);
    $code = wp_syntax_code_trim($match[4]);
    if ($escaped == "true") {
        $code = htmlspecialchars_decode($code);
    }
    $geshi = new GeSHi($code, $language);
    $geshi->enable_keyword_links(false);
    do_action_ref_array('wp_syntax_init_geshi', array(&$geshi));
    $output = "\n<div class=\"wp_syntax\">";
    if ($line) {
        $output .= "<table><tr><td class=\"line_numbers\">";
        $output .= wp_syntax_line_numbers($code, $line);
        $output .= "</td><td class=\"code\">";
        $output .= $geshi->parse_code();
        $clean = $wp_syntax_matches[0][0];
        // Suck out Entire Pre tag
        $clean = preg_replace('/^[ \\t]*[\\r\\n]+/m', '', $clean);
        // Remove empty lines
        $clean = implode("\n", array_slice(explode("\n", $clean), 1));
        // chop off top line (pre tag)
        $clean = urlencode($clean);
        $clean = str_replace(array('%3C%2Fpre%3E', '%0D%0A%0D%0A%0D%0A'), "", $clean);
        // remote end pre tag
        $output .= "</td></tr></table>" . clip($clean);
        $string = preg_replace("/<img[^>]+\\>/i", "", $string);
    } else {
        $output .= "<div class=\"code\">";
        $output .= $geshi->parse_code();
        $output .= "</div>";
    }
    return $output .= "</div>\n";
    return $output;
}