<?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('googleMapsForWPDataCheck')){
/**
* googlemapsForWP maps
* The class provides access to
*/
class googleMapsForWPDataCheck {
protected $errorsArr;
function __construct(){
//$this->errorsArr=array();
}
function getErrors(){
if(is_array($this->errorsArr)){
return implode("", $this->errorsArr);
}else{return "no error";}
}
function matchLat($v){
$reg="/^[-]?(([9][0]\.[0]{1,7}|([1-9]\.[0-9]{1,7})|([1-8][0-9]\.[0-9]{1,7})))$/";
if(preg_match($reg, $v)){
return true;
}return false;
}
function matchLong($v){
$reg="/^[-]?((180\.[0]{1,7})|(1([0-7][0-9])\.[0-9]{1,7})|([1-9][0-9]\.[0-9]{1,7})|([1-9]\.[0-9]{1,7}))$/";
if(preg_match($reg, $v)){
return true;
}return false;
}
}
}
if (!class_exists('googleMapsForWPDataFlagCheck')){
/**
* googlemapsForWP maps
* The class provides access to
*/
class googleMapsForWPDataFlagCheck extends googleMapsForWPDataCheck {
function __construct(){}
function checkFlag($args){
$return = true;
//longitude' => ,'latitude'=>,'map'=>,'type'=>'flag','size'=>,'colour'=>,'note'=>
$coloursArr= array('black', 'brown', 'green', 'purple', 'yellow', 'blue', 'gray', 'orange', 'red', 'white');
foreach($args as $key => $value){
$errortxt="The ".$key." you entered was invalid: ".$value;
switch ($key) {
case 'latitude':
if(!$this->matchLat($value)) {$this->errorsArr['latitude']=$errortxt;$return=false;}
break;
case 'longitude':
if(!$this->matchLong($value)) {$this->errorsArr['longitude']=$errortxt;$return=false;}
break;
case 'colour':
if(array_search($value, $coloursArr)===false) {$this->errorsArr['colour']=$errortxt;$return=false;}
break;
case 'size':
if(!$value=='small' && !$value=='mid' && !$value == 'tiny') {$this->errorsArr['size']=$errortxt;$return=false;}
break;
}
}
return $return;
}
}
}
if (!class_exists('googleMapsForWPDataMapCheck')){
/**
* googlemapsForWP maps
* The class provides access to
*/
class googleMapsForWPDataMapCheck extends googleMapsForWPDataCheck{
function __construct(){
}
function checkSize($size){
$reg="/^([1-9][0-9]|[1-5]([0-9]{2})|[6]([0-3][0-9])|([6][4][0]))$/";
if(preg_match($reg, $size)){
return true;
}
return false;
}
function checkText($v,$l){
if(sizeof($v)< 3 && sizeof($v)>$l){return false;}
$reg="/(([A-Z]|[a-z])\b)+/";
if(!preg_match($reg, $v)){return false;}
return true;
}
function checkMap($args){
//$mapname,$mapdescription,$long,$lat,$zoom,$width,$height,$type,$format
$return = true;
foreach($args as $key => $value){
$errortxt="The ".$key." you entered was invalid: ".$value;
switch ($key) {
case 'mapname':
if(!$this->checkText($value,25)) {$this->errorsArr['mapname']=$errortxt;$return=false;}
break;
case 'mapdescription':
if(!$this->checkText($value,300)) {$this->errorsArr['mapdescription']=$errortxt;$return=false;}
break;
case 'longitude':
if(!$this->matchLong($value)) {$this->errorsArr['longitude']=$errortxt;$return=false;}
break;
case 'latitude':
if(!$this->matchLat($value)) {$this->errorsArr['latitude']=$errortxt;$return=false;}
break;
case 'zoom':
if(intval($value)>21 || intval($value)<1) {$this->errorsArr['zoom']=$errortxt;$return=false;}
break;
case 'sizewidth':
if(!$this->checkSize($value)) {$this->errorsArr['sizewidth']=$errortxt;$return=false;}
break;
case 'sizeheight':
if(!$this->checkSize($value)) {$this->errorsArr['sizeheight']=$errortxt;$return=false;}
break;
case 'type':
if(!$value=='roadmap' && !$value=='satellite' && !$value == 'terrain') {$this->errorsArr['type']=$errortxt;$return=false;}
break;
case 'format':
if(!$value=='png32' && !$value=='png8' && !$value == 'jpg') {$this->errorsArr['format']=$errortxt;$return=false;}
break;
}
}
return $return;
}
}
}
if (!class_exists('gmfwpLocationCheck')){
class gmfwpLocationCheck{
function checkAddress($postcode){
$regexUK="/^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) {0,1}[0-9][A-Za-z]{2})$/";
$regexUS='/\d{5}(-\d{4})?/';
$regexCa='/^([A-Z]{1}[0-9]{1}){3}$/';
if(preg_match($regexUK, $postcode)||preg_match($regexUS, $postcode)||preg_match($regexCa, $postcode)){
return true;
}
else{return false;}
}
}
}
?>