function gmshc_options_page()
{
    $options = get_gmshc_options();
    if (isset($_POST['Restore_Default'])) {
        $options = get_gmshc_options(true);
    }
    ?>

	<div class="wrap">   
	
	<h2><?php 
    _e("Google Map Shortcode Settings", "google-map-sc");
    ?>
</h2>

	<?php 
    echo gmshc_plugin_menu();
    ?>
	
	<?php 
    if (isset($_POST['Submit'])) {
        $newoptions['width'] = isset($_POST['width']) ? $_POST['width'] : $options['width'];
        $newoptions['height'] = isset($_POST['height']) ? $_POST['height'] : $options['height'];
        $newoptions['margin'] = isset($_POST['margin']) ? $_POST['margin'] : $options['margin'];
        $newoptions['align'] = isset($_POST['align']) ? $_POST['align'] : $options['align'];
        $newoptions['zoom'] = isset($_POST['zoom']) ? $_POST['zoom'] : $options['zoom'];
        $newoptions['language'] = isset($_POST['language']) ? $_POST['language'] : $options['language'];
        $newoptions['type'] = isset($_POST['type']) ? $_POST['type'] : $options['type'];
        $newoptions['interval'] = isset($_POST['interval']) ? $_POST['interval'] : $options['interval'];
        $newoptions['focus'] = isset($_POST['focus']) ? $_POST['focus'] : "0";
        $newoptions['animate'] = isset($_POST['animate']) ? $_POST['animate'] : "false";
        $newoptions['focus_type'] = isset($_POST['focus_type']) ? $_POST['focus_type'] : "open";
        $newoptions['windowhtml'] = isset($_POST['windowhtml']) ? $_POST['windowhtml'] : $options['windowhtml'];
        $newoptions['default_icon'] = isset($_POST['default_icon']) ? $_POST['default_icon'] : $options['default_icon'];
        $newoptions['icons'] = $options['icons'];
        $newoptions['version'] = GMSHC_VERSION_CURRENT;
        if ($options != $newoptions) {
            $options = $newoptions;
            update_option('gmshc_op', $options);
        }
    }
    if (isset($_POST['Use_Default'])) {
        $options['windowhtml'] = gmshc_defaul_windowhtml();
        update_option('gmshc_op', $options);
    }
    $upload_icons = $options['icons'];
    if (isset($_POST['upload'])) {
        if ($_FILES['datafile']['error'] == 0) {
            $filename = $_FILES["datafile"]["name"];
            $upload = wp_upload_bits($filename, NULL, file_get_contents($_FILES["datafile"]["tmp_name"]));
            if (!empty($upload['error'])) {
                $errorString = sprintf(__('Could not write file %1$s (%2$s)', 'google-map-sc'), $filename, $upload['error']);
                echo "<div class='error'><p><strong>" . $errorString . "</strong></p></div>";
            } else {
                array_unshift($upload_icons, $upload['url']);
                $options['icons'] = $upload_icons;
                update_option('gmshc_op', $options);
            }
        } else {
            echo "<div class='error'><p><strong>" . __("Please upload a valid file", "google-map-sc") . "</strong></p></div>";
        }
    }
    $width = $options['width'];
    $height = $options['height'];
    $margin = $options['margin'];
    $align = $options['align'];
    $zoom = $options['zoom'];
    $language = $options['language'];
    $type = $options['type'];
    $interval = $options['interval'];
    $focus = $options['focus'];
    $animate = $options['animate'];
    $focus_type = $options['focus_type'];
    $windowhtml = $options['windowhtml'];
    $default_icon = $options['default_icon'];
    ?>
  
	
	<form method="POST" name="options" target="_self" enctype="multipart/form-data">
	
	<h3><?php 
    _e("Maps Default Configuration", "google-map-sc");
    ?>
</h3>
	
	<p><?php 
    _e("The shortcode attributes overwrites these options.", "google-map-sc");
    ?>
</p>
	
    <table width="80%" border="0" cellspacing="10" cellpadding="0">
      <tr>
        <td width="200" align="right" height="40"><strong><?php 
    _e("Width", "google-map-sc");
    ?>
</strong></td>
        <td><input name="width" type="text" size="6" value="<?php 
    echo $width;
    ?>
" /></td>
      </tr>
      <tr>
        <td align="right"><strong><?php 
    _e("Height", "google-map-sc");
    ?>
</strong></td>
        <td><input name="height" type="text" size="6" value="<?php 
    echo $height;
    ?>
" /></td>
      </tr>
      <tr>
        <td align="right"><strong><?php 
    _e("Margin", "google-map-sc");
    ?>
</strong></td>
        <td><input name="margin" type="text" size="6" value="<?php 
    echo $margin;
    ?>
" /></td>
      </tr>  
      <tr>
        <td align="right"><strong><?php 
    _e("Align", "google-map-sc");
    ?>
</strong></td>
        <td>
        	<input name="align" type="radio" value="left" <?php 
    echo $align == "left" ? "checked = 'checked'" : "";
    ?>
 /> <?php 
    _e("left", "google-map-sc");
    ?>
            <input name="align" type="radio" value="center" <?php 
    echo $align == "center" ? "checked = 'checked'" : "";
    ?>
 /> <?php 
    _e("center", "google-map-sc");
    ?>
            <input name="align" type="radio" value="right" <?php 
    echo $align == "right" ? "checked = 'checked'" : "";
    ?>
 /> <?php 
    _e("right", "google-map-sc");
    ?>
        
      </tr>          
      <tr>
        <td align="right"><strong><?php 
    _e("Zoom", "google-map-sc");
    ?>
</strong></td>
        <td>
        <select name="zoom" id="zoom">
            <?php 
    for ($i = 0; $i <= 20; $i++) {
        ?>
                <option value="<?php 
        echo $i;
        ?>
" <?php 
        echo $i == $zoom ? "selected" : "";
        ?>
 ><?php 
        echo $i;
        ?>
</option>
            <?php 
    }
    ?>
        </select>         
      </tr>  
      <tr>
        <td align="right"><strong><?php 
    _e("Maps Type", "google-map-sc");
    ?>
</strong></td>
        <td>
        	<select name="type">
        		<option value="ROADMAP" <?php 
    if ($type == "ROADMAP") {
        echo "selected";
    }
    ?>
><?php 
    _e("ROADMAP - Displays a normal street map", "google-map-sc");
    ?>
</option>
            	<option value="SATELLITE" <?php 
    if ($type == "SATELLITE") {
        echo "selected";
    }
    ?>
><?php 
    _e("SATELLITE - Displays satellite images", "google-map-sc");
    ?>
</option>
                <option value="TERRAIN" <?php 
    if ($type == "TERRAIN") {
        echo "selected";
    }
    ?>
><?php 
    _e("TERRAIN - Displays maps with physical features such as terrain and vegetation", "google-map-sc");
    ?>
</option>
                <option value="HYBRID" <?php 
    if ($type == "HYBRID") {
        echo "selected";
    }
    ?>
><?php 
    _e("HYBRID - Displays a transparent layer of major streets on satellite images", "google-map-sc");
    ?>
</option>
            </select>
        </td>        
      </tr>      
      <tr>
        <td align="right" valign="top"><strong><?php 
    _e("Select Language", "google-map-sc");
    ?>
</strong></td>
        <td>  
        <?php 
    $lang_array = array("ar" => __("ARABIC", "google-map-sc"), "eu" => __("BASQUE", "google-map-sc"), "bg" => __("BULGARIAN", "google-map-sc"), "bn" => __("BENGALI", "google-map-sc"), "ca" => __("CATALAN", "google-map-sc"), "cs" => __("CZECH", "google-map-sc"), "da" => __("DANISH", "google-map-sc"), "de" => __("GERMAN", "google-map-sc"), "el" => __("GREEK", "google-map-sc"), "en" => __("ENGLISH", "google-map-sc"), "en-AU" => __("ENGLISH (AUSTRALIAN)", "google-map-sc"), "en-GB" => __("ENGLISH (GREAT BRITAIN)", "google-map-sc"), "es" => __("SPANISH", "google-map-sc"), "eu" => __("BASQUE", "google-map-sc"), "fa" => __("FARSI", "google-map-sc"), "fi" => __("FINNISH", "google-map-sc"), "fil" => __("FILIPINO", "google-map-sc"), "fr" => __("FRENCH", "google-map-sc"), "gl" => __("GALICIAN", "google-map-sc"), "gu" => __("GUJARATI", "google-map-sc"), "hi" => __("HINDI", "google-map-sc"), "hr" => __("CROATIAN", "google-map-sc"), "hu" => __("HUNGARIAN", "google-map-sc"), "id" => __("INDONESIAN", "google-map-sc"), "it" => __("ITALIAN", "google-map-sc"), "iw" => __("HEBREW", "google-map-sc"), "ja" => __("JAPANESE", "google-map-sc"), "kn" => __("KANNADA", "google-map-sc"), "ko" => __("KOREAN", "google-map-sc"), "lt" => __("LITHUANIAN", "google-map-sc"), "lv" => __("LATVIAN", "google-map-sc"), "ml" => __("MALAYALAM", "google-map-sc"), "mr" => __("MARATHI", "google-map-sc"), "nl" => __("DUTCH", "google-map-sc"), "no" => __("NORWEGIAN", "google-map-sc"), "or" => __("ORIYA", "google-map-sc"), "pl" => __("POLISH", "google-map-sc"), "pt" => __("PORTUGUESE", "google-map-sc"), "pt-BR" => __("PORTUGUESE (BRAZIL)", "google-map-sc"), "pt-PT" => __("PORTUGUESE (PORTUGAL)", "google-map-sc"), "ro" => __("ROMANIAN", "google-map-sc"), "ru" => __("RUSSIAN", "google-map-sc"), "sk" => __("SLOVAK", "google-map-sc"), "sl" => __("SLOVENIAN", "google-map-sc"), "sr" => __("SERBIAN", "google-map-sc"), "sv" => __("SWEDISH", "google-map-sc"), "tl" => __("TAGALOG", "google-map-sc"), "ta" => __("TAMIL", "google-map-sc"), "te" => __("TELUGU", "google-map-sc"), "th" => __("THAI", "google-map-sc"), "tr" => __("TURKISH", "google-map-sc"), "uk" => __("UKRAINIAN", "google-map-sc"), "vi" => __("VIETNAMESE", "google-map-sc"), "zh-CN" => __("CHINESE (SIMPLIFIED)", "google-map-sc"), "zh-TW" => __("CHINESE (TRADITIONAL)", "google-map-sc"));
    ?>
 
        <select name="language" id="language">
            <?php 
    foreach ($lang_array as $lg => $lg_name) {
        ?>
                <option value="<?php 
        echo $lg;
        ?>
" <?php 
        echo $lg == $language ? "selected" : "";
        ?>
 ><?php 
        echo $lg_name;
        ?>
</option>
            <?php 
    }
    ?>
        </select>   
        </td>
      </tr>       
      <tr>
        <td align="right" valign="top"><strong><?php 
    _e("Circle", "google-map-sc");
    ?>
</strong></td>
        
        <td><input name="focus" type="checkbox" value="all" <?php 
    if ($focus == "all") {
        echo "checked = \"checked\"";
    }
    ?>
 /> <?php 
    _e(" Check if you want to focus all the map's points automatically with an interval of <br /><br />", "google-map-sc");
    ?>
<input name="interval" type="text" size="6" value="<?php 
    echo $interval;
    ?>
" /> <?php 
    _e("milliseconds.", "google-map-sc");
    ?>
</td>
      </tr>
      <tr>
        <td align="right" valign="top"> <strong><?php 
    _e("Focus Type", "google-map-sc");
    ?>
</strong></td>
        <td>
        <select name="focus_type" id="focus_type">
           <option value="open" <?php 
    echo $focus_type == "open" ? "selected" : "";
    ?>
 ><?php 
    _e("Open Markers", "google-map-sc");
    ?>
</option>
           <option value="center" <?php 
    echo $focus_type == "center" ? "selected" : "";
    ?>
 ><?php 
    _e("Center Markers", "google-map-sc");
    ?>
</option>
        </select>
        </td>        
      </tr>        
      <tr>
        <td align="right" valign="top"> <strong><?php 
    _e("Animation", "google-map-sc");
    ?>
</strong></td>
        <td><input name="animate" type="checkbox" value="true" <?php 
    if ($animate == "true") {
        echo "checked = \"checked\"";
    }
    ?>
 /> <?php 
    _e(" Check if you want to animate the markes.", "google-map-sc");
    ?>
</td>        
      </tr>        
    </table> 
         
    <p class="submit">
    <input type="submit" name="Submit" value="Update" class="button-primary" />
    </p>
    
    <h3 style="padding-top:30px; margin-top:30px; border-top:1px solid #CCCCCC;"><?php 
    _e("Markers", "google-map-sc");
    ?>
</h3>
      
    <table width="80%" border="0" cellspacing="10" cellpadding="0">             
      <tr>
        <td align="right" valign="top" colspan="2">

		<?php 
    gmshc_deploy_icons();
    ?>
		
        </td>
      </tr>
      <tr>
        <td align="left" valign="top" colspan="2">
            <?php 
    _e("To include new icons just specify the file location:", "google-map-sc");
    ?>
<br />
            <input type="file" name="datafile" size="40" /> <input type="submit" name="upload" value="Upload" class="button" />
        </td>
      </tr> 
    </table>
    
    <p class="submit">
    <input type="submit" name="Submit" value="Update" class="button-primary" />
    </p>
    
    <h3 style="padding-top:30px; margin-top:30px; border-top:1px solid #CCCCCC;"><?php 
    _e("Info Windows", "google-map-sc");
    ?>
</h3>
    
    <p><?php 
    _e("This is the html of the Info Window opened from the markers.", "google-map-sc");
    ?>
</p>

    <div id="gmshc_html">
        <div id="gmshc_previews">
            <p><strong><?php 
    _e("Previews", "google-map-sc");
    ?>
</strong></p> 
            <div id="gmshc_html_previews">       
            <?php 
    echo gmshc_defaul_windowhtml();
    ?>
            </div>
        </div>
        <div id="gmshc_html_cont">
            <p><strong><?php 
    _e("Custom Html", "google-map-sc");
    ?>
</strong></p>
            <textarea name="windowhtml" cols="60" rows="12" id="windowhtml">
            <?php 
    if (empty($windowhtml)) {
        echo gmshc_defaul_windowhtml();
    } else {
        echo str_replace("\\", "", $windowhtml);
    }
    ?>
            </textarea>
        </div>        
    </div>
    
    <p><?php 
    _e("The following tags can be used.", "google-map-sc");
    ?>
</p>    
    <table width="80%" border="0" cellspacing="10" cellpadding="0">
      <tr>
        <td width="60" align="right"><strong>%title%</strong></td>
        <td><?php 
    _e("Custom title of the point", "google-map-sc");
    ?>
</td>
      </tr>
      <tr>
         <td align="right"><strong>%link%</strong></td>
        <td><?php 
    _e("Permanet Link of the post where the point is attached", "google-map-sc");
    ?>
</td>
      </tr>
      <tr>
        <td align="right"><strong>%thubnail%</strong></td>
        <td><?php 
    _e("Thubnail attached to the point", "google-map-sc");
    ?>
</td>
      </tr>
      <tr>
        <td align="right"><strong>%description%</strong></td>
        <td><?php 
    _e("Description of the point", "google-map-sc");
    ?>
</td>
      </tr>      
      <tr>
        <td align="right"><strong>%excerpt%</strong></td>
        <td><?php 
    _e("Excerpt of the post where the point is attached", "google-map-sc");
    ?>
</td>
      </tr>  
      <tr>
        <td align="right"><strong>%address%</strong></td>
        <td><?php 
    _e("The address of this point", "google-map-sc");
    ?>
</td>
      </tr>
      <tr>
        <td align="right"><strong>%open_map%</strong></td>
        <td><?php 
    _e("Open this point on Google Map", "google-map-sc");
    ?>
</td>
      </tr> 
      <tr>
        <td align="right"><strong>%width%</strong></td>
        <td><?php 
    _e("Info Html width", "google-map-sc");
    ?>
</td>
      </tr>           
    </table>


    <p class="submit">
    <input type="submit" name="Submit" value="Update" class="button-primary" /><input type="submit" name="Restore_Default" value="<?php 
    _e("Restore Default", "google-map-sc");
    ?>
" class="button" />
    </p>
    </form>
    
    <?php 
    echo gmshc_plugin_menu();
    ?>
    
    </div>


<?php 
}
Пример #2
0
/**
 * Get the point from geocoding from address or latitude,longitude
 * http://code.google.com/apis/maps/documentation/geocoding/
 */
function gmshc_point($address, $ltlg)
{
    $formatted_address = "";
    $point = "";
    $response = false;
    if (!empty($ltlg)) {
        $query = $ltlg;
        $type = "latlng";
    } else {
        if (!empty($address)) {
            $find = array("\n", "\r", " ");
            $replace = array("", "", "+");
            $address = str_replace($find, $replace, $address);
            $query = $address;
            $type = "address";
        } else {
            return false;
        }
    }
    $options = get_gmshc_options();
    $api_url = "http://maps.googleapis.com/maps/api/geocode/json?" . $type . "=" . urlencode($query) . "&sensor=false&language=" . $options['language'];
    $json_answ = @file_get_contents($api_url);
    if (empty($json_answ)) {
        if (function_exists('curl_init')) {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $api_url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            $json_answ = curl_exec($ch);
            curl_close($ch);
        } else {
            echo "<div class='error'><p>" . __("The Point can't be added, <strong>php_curl.dll</strong> is not installed on your server and <strong>allow_url_fopen</strong> is disabled.") . "</p></div>";
            return false;
        }
    }
    $answ_arr = json_decode($json_answ, true);
    if (isset($answ_arr["status"]) && $answ_arr["status"] == "OK") {
        $formatted_address = gmshc_clean_string($answ_arr["results"]["0"]["formatted_address"]);
        $point = $answ_arr["results"]["0"]["geometry"]["location"]["lat"] . "," . $answ_arr["results"]["0"]["geometry"]["location"]["lng"];
        if (!empty($point) && !empty($formatted_address)) {
            $response = array('point' => $point, 'address' => $formatted_address);
        }
        return $response;
    } else {
        return false;
    }
}