<?php
/**
* Documents the file following
* @package googlemapsForWP
* @author webcat
*/
//#################################################################
if (preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
die('You are not allowed to call this page directly.');
}
//#################################################################
if (!class_exists('googlemapsForWPAdminPage')) {
/**
* googlemapsForWP Admin Page
* The class provides access to
*/
class googlemapsForWPAdminPage {
protected $googlemapsForWPMaps;
function __construct() {
add_action('wp_ajax_locationFinder', array($this, 'locationFinder'));
include_once googlemapsForWP::pluginDir() . DIRECTORY_SEPARATOR . 'business' . DIRECTORY_SEPARATOR . 'googlemapsForWPMaps.php';
try{
$this->googlemapsForWPMaps = new googlemapsForWPMaps();
}catch(Exception $e){}
}
public function locationFinder(){
try{
if (!file_exists(googlemapsForWP::pluginDir() . DIRECTORY_SEPARATOR . 'business' . DIRECTORY_SEPARATOR . 'geocodes.php')) {
throw new Exception('Cannot find the required files');
} else {
require_once(googlemapsForWP::pluginDir() . DIRECTORY_SEPARATOR . 'business' . DIRECTORY_SEPARATOR . 'geocodes.php');
$codes = new gmfwpGeoCodes();
die($codes->getCodes($_POST['location']));
}
}catch(Exception $e){
die("error");
}
}
/**
* Adds a menu page and item in the wordpress dashboard sidebar for display readme, acess submenus, feedback form for evaluation
*
*/
public function add_menu() {
//add_submenu_page($f,'page', 'googlemapsForWP Admin', 9, __FILE__,array($this,'output') ) ;
add_submenu_page('tools.php', 'googlemapsForWP Admin', 'googlemapsForWP', 'administrator', 'googlemapsForWPAdmin.php', array($this, 'output'));
add_action('admin_head', array($this, 'addHeadLinks'), 12);
add_action('media_buttons', array($this, 'add_maps_select'), 11);
add_action('admin_head', array($this, 'add_button_js'));
//add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function )
}
/**
* Adds javascript to update posts with selected shortcode
* Thanks to Kevin Chard for the tidy bit of shortcode code
* @author Kevin Chard
* @link http://wpsnipp.com/index.php/functions-php/update-automatically-create-media_buttons-for-shortcode-selection/
*/
function add_button_js() { {
echo '<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#map_select").change(function() {
send_to_editor(jQuery("#map_select :selected").val());
return false;
});
});
</script>';
}
}
/**
* Adds a shortcode selection to the WP editor
* Thanks to Kevin Chard for the tidy bit of shortcode code
* @author Kevin Chard
* @link http://wpsnipp.com/index.php/functions-php/update-automatically-create-media_buttons-for-shortcode-selection/
*/
function add_maps_select() {
$maps = $this->googlemapsForWPMaps->getMaps();
echo '<select id="map_select"><option>Shortcode</option>';
foreach ($maps as $key => $val) {
if (!in_array($key, $exclude)) {
$shortcodes_list .= '<option value="'.$this->create_shortcode($val['id']).'">' . $val['mapname'] . " = " . $this->create_shortcode($val['id']) . '</option>';
}
}
echo $shortcodes_list;
echo '</select>';
}
function create_shortcode($mapid) {
$code = htmlentities("[getmap mapnumber='" . $mapid . "']");
return $code;
}
/**
* Creates the page output. Includes logic for selecting <br /> the correct screen
* @uses googlemapsForWPMaps
*
*/
private function install(){
try {
if (!file_exists(googlemapsForWP::pluginDir() . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'mapdata.php')) {
throw new Exception('Cannot find the required files');
} else {
require_once(googlemapsForWP::pluginDir() . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'mapdata.php');
}
$d = new googlemapsForWPDB();
$d->install();
} catch (Exception $e) {
die($e->getMessage());
}
}
private function uninstall(){
try {
if (!file_exists(googlemapsForWP::pluginDir() . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'mapdata.php')) {
throw new Exception('Cannot find the required files');
} else {
require_once(googlemapsForWP::pluginDir() . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'mapdata.php');
}
$d = new googlemapsForWPDB();
$d->uninstall();
} catch (Exception $e) {
die($e->getMessage());
}
}
function output() {
$heading = "Google Maps for WP Control Panel";
$credits = googlemapsForWP::$googlemapsForWPCredits;
$version = googlemapsForWP::$googlemapsForWPVersion;
$tmpdir = googlemapsForWP::pluginDir() . DIRECTORY_SEPARATOR . 'output' . DIRECTORY_SEPARATOR;
if($this->googlemapsForWPMaps->installed()){
$status="uninstall";
$command="Remove Database";
$advice="Before uninstalling plugin remove plugin database tables. Non-revertable!";
$installed=true;
}else{
$status="install";
$command="Setup Database";
$advice="Before using the plugin click the button to setup your database";
$installed=false;
}
if(isset($_POST['install'])){
$this->install();
$status="uninstall";
$command="Remove Database";
$advice="Before uninstalling plugin remove plugin database tables. Non-revertable!";
$installed=true;
$maps = $this->googlemapsForWPMaps->getMaps();
unset($_POST);
include_once $tmpdir . 'googlemapsForWPadminscreen.tpl';
return;
}
if(isset($_POST['uninstall'])){
$this->uninstall();
$status="install";
$command="Setup Database";
$advice="Before using the plugin click the button to setup your database";
$installed=false;
$maps = $this->googlemapsForWPMaps->getMaps();
unset($_POST);
include_once $tmpdir . 'googlemapsForWPadminscreen.tpl';
return;
}
if (isset($_POST['deletemap'])) {
$mapid = $_POST['deletemapid'];
$this->googlemapsForWPMaps->deleteMap($mapid);
$maps = $this->googlemapsForWPMaps->getMaps();
$map = $this->googlemapsForWPMaps->getMap($mapid);
include_once $tmpdir . 'googlemapsForWPadminscreen.tpl';
return;
}
if (isset($_POST['deleteflagid'])) {
$map = null;
$flagid = $_POST['deleteflagid'];
$mapid = $_POST['map'];
$this->googlemapsForWPMaps->deleteFlag($flagid);
$map = $this->googlemapsForWPMaps->getMap($mapid);
if (!$map == false) {
$flags = $this->googlemapsForWPMaps->getFlags($mapid);
include_once $tmpdir . 'googlemapsForWPviewmapscreen.tpl';
return;
} else {
$status = $this->googlemapsForWPMaps->getStatus();
include_once $tmpdir . 'googlemapsForWPerrorscreen.tpl';
return;
}
}
if (isset($_POST['addmap']) || isset($_POST['editmap'])) {
if (isset($_POST['editmap'])) {
$mapid = $_POST['editmapid'];
$map = $this->googlemapsForWPMaps->getMap(intval($mapid));
if (!$map == false) {
include_once $tmpdir . 'googlemapsForWPviewmapscreen.tpl';
return;
} else {
$status = $this->googlemapsForWPMaps->getStatus();
include_once $tmpdir . 'googlemapsForWPerrorscreen.tpl';
return;
}
} else {
include_once $tmpdir . 'googlemapsForWPaddmapscreen.tpl';
return;
}
} else {
if (isset($_POST['viewmap'])) {
$mapid = $_POST['viewmapid'];
$map = $this->googlemapsForWPMaps->getMap(intval($mapid));
if (!$map == false) {
$flags = $this->googlemapsForWPMaps->getFlags($mapid);
include_once $tmpdir . 'googlemapsForWPviewmapscreen.tpl';
} else {
$status = $this->googlemapsForWPMaps->getStatus();
include_once $tmpdir . 'googlemapsForWPerrorscreen.tpl';
return;
}
} else {
if (isset($_POST['newflag'])) {
$map = null;
$mapid = $_POST['newflag'];
$map = $this->googlemapsForWPMaps->getMap(intval($mapid));
$args = array('longitude' => $_POST['longitude'], 'latitude' => $_POST['latitude'], 'map' => $mapid, 'type' => 'flag', 'size' => $_POST['flagsize'], 'colour' => $_POST['flagcolour'], 'note' => $_POST['flagnote']);
$isadded = $this->googlemapsForWPMaps->addFlag($args);
if ($isadded && !$map == false) {
$map->addFlags($this->googlemapsForWPMaps->getFlags($mapid));
include_once $tmpdir . 'googlemapsForWPviewmapscreen.tpl';
return;
} else {
$status = $this->googlemapsForWPMaps->getStatus();
include_once $tmpdir . 'googlemapsForWPerrorscreen.tpl';
return;
}
} else {
if (isset($_POST['savenew']) && $_POST['savenew'] == 'true') {
$mapname = $_POST['mapname'];
$mapdescription = $_POST['mapdescription'];
$long = $_POST['longitude'];
$lat = $_POST['latitude'];
$zoom = $_POST['zoom'];
$width = $_POST['sizewidth'];
$height = $_POST['sizeheight'];
$type = $_POST['type'];
$format = $_POST['format'];
$map = null;
$maps = $this->googlemapsForWPMaps->getMaps();
if (!empty($maps)) {
foreach ($maps as $value) {
if ($value['mapname'] == $mapname) {
$mapname = $mapname . "-1";
}
}
}
$map = $this->googlemapsForWPMaps->addMap(array('mapname' => $mapname, 'mapdescription' => $mapdescription, 'longitude' => $long, 'latitude' => $lat, 'zoom' => $zoom, 'sizewidth' => $width, 'sizeheight' => $height, 'type' => $type, 'format' => $format, 'sensor' => 'false'));
if (!$map == false) {
$heading = "Add and Delete Flags";
include_once $tmpdir . 'googlemapsForWPviewmapscreen.tpl';
return;
} else {
$status = $this->googlemapsForWPMaps->getStatus();
include_once $tmpdir . 'googlemapsForWPerrorscreen.tpl';
return;
}
} else {
$maps = $this->googlemapsForWPMaps->getMaps();
include_once $tmpdir . 'googlemapsForWPadminscreen.tpl';
return;
}
}
}
}
unset($maps);
}
/*
*
* Adds js and stylesheet to header
*/
function addHeadLinks() {
echo '<link rel="stylesheet" type="text/css" href="' . googlemapsForWP::pluginURL() . 'googlemapsForWPstyles.css" />';
echo '<script type="text/javascript" src="' . googlemapsForWP::pluginURL() . 'js/googlemapsForWP.js" ></script>';
}
}
}
?>