Created
November 21, 2019 20:16
-
-
Save vimes1984/604a15a169969a51730765fcba2caba0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* OIFN extended | |
* | |
* integrates google map into a location based buddypress | |
* | |
* @package oifn-extended | |
* @author Christopher James Chruchill <[email protected]> | |
* @license GPL-2.0+ | |
* @link http://buildawebdoctor.com | |
* @copyright 5-7-2014 BAWD | |
* | |
* @wordpress-plugin | |
* Plugin Name: OIFN extended | |
* Plugin URI: http://buildawebdoctor.com | |
* Description: integrates google map into a location based buddypress | |
* Version: 1.0.0 | |
* Author: Christopher James Chruchill | |
* Author URI: http://buildawebdoctor.com | |
* Text Domain: oifn-extended-locale | |
* License: GPL-2.0+ | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt | |
* Domain Path: /lang | |
*/ | |
// If this file is called directly, abort. | |
if (!defined("WPINC")) { | |
die; | |
} | |
/*GET plugin options*/ | |
$PluginOptsArray = get_option( 'ofin_options' ); | |
$geturl = $PluginOptsArray['redircturl']; | |
//var_dump($geturl); | |
require_once(plugin_dir_path(__FILE__) . "OIFNExtended.php"); | |
// Register hooks that are fired when the plugin is activated, deactivated, and uninstalled, respectively. | |
register_activation_hook(__FILE__, array("OIFNExtended", "activate")); | |
register_deactivation_hook(__FILE__, array("OIFNExtended", "deactivate")); | |
OIFNExtended::get_instance(); | |
/*Add a filter to filter the redirect url for login*/ | |
add_filter("login_redirect","bpdev_redirect_profile_edit",100,3); | |
function bpdev_redirect_profile_edit($redirect_to_calculated,$redirect_url_specified,$user){ | |
/*if no redirect was specified,let us think ,user wants to be in wp-dashboard*/ | |
if(empty($redirect_to_calculated)) | |
$redirect_to_calculated=admin_url(); | |
/*if the user is not site admin,redirect to his/her profile*/ | |
if(!is_super_admin($user->ID) && function_exists('bp_core_get_user_domain') ){ | |
global $PluginOptsArray, $geturl; | |
$getuserprofileurl = bp_core_get_user_domain($user->ID ); | |
$combinethem = $getuserprofileurl . $geturl; | |
return $combinethem; | |
} | |
else{ | |
return $redirect_to_calculated; /*if site admin or not logged in,do not do anything much*/ | |
} | |
} | |
/*end redirect login*/ | |
/******************************************************************************************************************** | |
| | | |
| Start profile page edits this will drive me mad i know it!! | | |
| | | |
| | | |
********************************************************************************************************************/ | |
//check postcode | |
function validate_character_count( $result, $value, $form, $field, $locale ) { | |
//$validator = new Zend_Validate_PostCode($locale); | |
$regex = '/[a-z][0-9][a-z][- ]?[0-9][a-z][0-9]$/i'; | |
if(!preg_match($regex, $value)) { | |
$result['is_valid'] = false; | |
$result['message'] = sprintf( $this->_args['validation_message'], $this->_args['min_chars'] ); | |
} | |
return $result; | |
} | |
function valid_postcode ($data) { | |
global $bp; | |
if(isset($_POST['field_23'])){ | |
$postcodecheck = $_POST['field_23']; | |
$regex = '/[a-z][0-9][a-z][- ]?[0-9][a-z][0-9]$/i'; | |
if(!preg_match($regex, $postcodecheck)) { | |
bp_core_add_message( __( 'That Postal code is invalid. Check the formatting and try again.', 'buddypress' ), 'error' ); | |
wp_redirect( $bp->loggedin_user->domain . 'profile/edit/group/2/' ); | |
exit(); | |
}elseif ($postcodecheck == '') { | |
bp_core_add_message( __( 'You need to fill out the Postal Code.', 'buddypress' ), 'error' ); | |
wp_redirect( $bp->loggedin_user->domain . 'profile/edit/group/2/' ); | |
exit(); | |
} | |
} | |
return $data; | |
} | |
add_action( 'xprofile_data_before_save', 'valid_postcode'); | |
function addprovince($data){ | |
global $current_user; | |
get_currentuserinfo(); | |
$newAddress = 'Ontario'; | |
//var_dump(xprofile_get_field_data( 'Province' ,bp_get_member_user_id())); | |
xprofile_set_field_data('Province', $current_user->id, $newAddress); | |
} | |
//add_action( 'xprofile_screen_edit_profile', 'addprovince'); | |
/******************************************** | |
| PUT buddypress data into table 'makers' | | |
| Now this function is spagetti Junction, | | |
| I'll comment my way through it | | |
| hope all makes sense | | |
********************************************/ | |
//add_action( 'xprofile_data_after_save', 'write_to_user', 99999); | |
function write_to_user(){ | |
bp_core_add_message( __( 'Once you have completed your changes log out by choosing the LOG OUT menu item at the top right of the black bar above.', 'buddypress' ), 'success' ); | |
//wp_redirect( $bp->loggedin_user->domain . 'profile/edit/group/2/' ); | |
} | |
function updatedb($data){ | |
//Global varibales | |
global $wpdb; | |
//Grab our userid We'll need this for later | |
$user_ID = get_current_user_id(); | |
if ( ! is_admin() ) { | |
//this is to check if this user has a DB entry or not... | |
$result = $wpdb->get_results ("SELECT id FROM markers WHERE userID = '".$user_ID."'"); | |
/********************************* | |
|ok let's geoencode! the address | | |
**********************************/ | |
//this checks the buinesss name field and post code, to make sure we have that | |
/* | |
echo "<pre>"; | |
var_dump($_POST['field_23']); | |
echo "</pre>"; | |
die(); | |
*/ | |
if(isset($_POST['field_23']) && $_POST['field_23'] != '' && isset($_POST['field_15']) && $_POST['field_15'] != ''){ | |
//OK here we grab the $_POST fields the var names describe what each is... | |
$organaddress = $_POST['field_15']; | |
$street = $_POST['field_21']; | |
$postcode = $_POST['field_23']; | |
$combineaddress = $organaddress . ', ' . $street . ', Ontario, ' . $postcode; | |
//urlenocde the combined address | |
$Address = urlencode($combineaddress); | |
//Ask google to convert to LAT/LNG for us this can be flaky at times... | |
//Poss ask to move to a paid service? | |
//this is more precise but it's being removed due to mul;tiple users at one address... | |
//$request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$Address."&sensor=true"; | |
$request_url = "http://maps.googleapis.com/maps/api/geocode/xml?components=postal_code:".$postcode."&sensor=true"; | |
//ask the URL | |
$xml = simplexml_load_file($request_url); | |
//set the satus | |
$status = $xml->status; | |
//If the status checks out we nip into here | |
// LIKE A THEIF IN THE NIGHT! | |
if ($status=="OK") { | |
/************************************************************ | |
// Ok sparky we made it this far // | |
// as Yazz would say "the only way is up!! BABABYYY " // | |
// Good god the eighties where bad.. // | |
************************************************************/ | |
//these two do as they say grab lat/lng from that xml we loaded earlier! | |
$Lat = $xml->result->geometry->location->lat; | |
$Lon = $xml->result->geometry->location->lng; | |
//Yet another if/else maybe this should be a while or a catch? | |
if(isset($_POST['field_13']) && $_POST['field_13'] != ''){ | |
$jsontype = $_POST['field_2']; | |
$name = mysql_real_escape_string( $_POST['field_13']); | |
$description = mysql_real_escape_string( $_POST['field_27']); | |
//$county = mysql_real_escape_string( $_POST['field_65']); NOT IN USE | |
// and the last if else this checks wether the results | |
// var we delcared right at the begining are larger than 0 if they are | |
// we UPDATE if not we create a brand spanking new table! | |
// Either way we save the results to the KML file | |
if (count ($result) > 0) { | |
$udpate = $wpdb->query ("UPDATE markers SET name = '" . $name . "', address = '". $combineaddress ."', county = '". $county ."', type = '". $jsontype ."', description = '". $description ."', lat = '". $Lat ."', lng = '". $Lon ."' WHERE userID = '".$user_ID."'"); | |
} else { | |
$insertarray = array( | |
'userID' => $user_ID, | |
'name' => $name, | |
'address' => $combineaddress, | |
'description' => $description, | |
'lat' => $Lat{0}, | |
'lng' => $Lon{0}, | |
'type' => $jsontype, | |
'county' => $county | |
); | |
$insert = $wpdb->replace('markers', $insertarray ); | |
} | |
} | |
}else{ | |
//if the status doesn't check out we drop to here... | |
// :'( it also makes us sad... | |
// this is a flaky un sure way to do this but it's what we have currently! | |
bp_core_add_message( __( 'The geolocation service is currently unavailable, please try again. Note edited fields may be lost - please check. If, after several attempts, you still encounter this message, exit and revisit this page, re-edit and re-save your profile.', 'buddypress' ), 'error' ); | |
wp_redirect( $bp->loggedin_user->domain . 'profile/edit/group/2/' ); | |
//exit(); | |
} | |
}else{ | |
//Drop to here if no Organizqation name is set | |
/*bp_core_add_message( __( 'You must have a Organization name, if you are a indivual use your First & Last name.', 'buddypress' ), 'error' ); | |
wp_redirect( $bp->loggedin_user->domain . 'profile/edit/group/2/' ); | |
exit();*/ | |
} | |
} | |
} | |
function deletemarkers($user_id){ | |
global $wpdb; | |
$wpdb->query($wpdb->prepare("DELETE FROM `ccdeathm_mort`.`markers` WHERE `markers`.`userID` = %d", $user_id)); | |
// Selects all the rows in the markers table. | |
$result_kml = $wpdb->get_results( 'SELECT * FROM markers'); | |
if (!$result_kml){ | |
return; | |
} | |
// Creates the Document. | |
$dom = new DOMDocument('1.0', 'UTF-8'); | |
// Creates the root KML element and appends it to the root document. | |
$node = $dom->createElementNS('http://earth.google.com/kml/2.1', 'kml'); | |
$parNode = $dom->appendChild($node); | |
// Creates a KML Document element and append it to the KML element. | |
$dnode = $dom->createElement('Document'); | |
$docNode = $parNode->appendChild($dnode); | |
// Creates the six Style elements,for the profile type, and append the elements to the Document element. | |
$IndividualStyleNode = $dom->createElement('Style'); | |
$IndividualStyleNode->setAttribute('id', 'IndividualStyle'); | |
$IndividualIconstyleNode = $dom->createElement('IconStyle'); | |
$IndividualIconstyleNode->setAttribute('id', 'IndividualIcon'); | |
$IndividualIconNode = $dom->createElement('Icon'); | |
$IndividualHref = $dom->createElement('href', plugins_url(). '/OIFNExtended/kml/pins/individ.png'); | |
$IndividualIconNode->appendChild($IndividualHref); | |
$IndividualIconstyleNode->appendChild($IndividualIconNode); | |
$IndividualStyleNode->appendChild($IndividualIconstyleNode); | |
$docNode->appendChild($IndividualStyleNode); | |
$OrganisationStyleNode = $dom->createElement('Style'); | |
$OrganisationStyleNode->setAttribute('id', 'CooperativeStyle'); | |
$OrganisationIconstyleNode = $dom->createElement('IconStyle'); | |
$OrganisationIconstyleNode->setAttribute('id', 'OrganizationIcon'); | |
$OrganisationIconNode = $dom->createElement('Icon'); | |
$OrganisationHref = $dom->createElement('href', plugins_url(). '/OIFNExtended/kml/pins/organ.png'); | |
$OrganisationIconNode->appendChild($OrganisationHref); | |
$OrganisationIconstyleNode->appendChild($OrganisationIconNode); | |
$OrganisationStyleNode->appendChild($OrganisationIconstyleNode); | |
$docNode->appendChild($OrganisationStyleNode); | |
$NetworkStyleNode = $dom->createElement('Style'); | |
$NetworkStyleNode->setAttribute('id', 'Community of Practice/NetworkStyle'); | |
$NetworkIconstyleNode = $dom->createElement('IconStyle'); | |
$NetworkIconstyleNode->setAttribute('id', 'NetworkIcon'); | |
$NetworkIconNode = $dom->createElement('Icon'); | |
$NetworkHref = $dom->createElement('href', plugins_url(). '/OIFNExtended/kml/pins/comm.png'); | |
$NetworkIconNode->appendChild($NetworkHref); | |
$NetworkIconstyleNode->appendChild($NetworkIconNode); | |
$NetworkStyleNode->appendChild($NetworkIconstyleNode); | |
$docNode->appendChild($NetworkStyleNode); | |
$TrainingStyleNode = $dom->createElement('Style'); | |
$TrainingStyleNode->setAttribute('id', 'EducationalStyle'); | |
$TrainingIconstyleNode = $dom->createElement('IconStyle'); | |
$TrainingIconstyleNode->setAttribute('id', 'TrainingIcon'); | |
$TrainingIconNode = $dom->createElement('Icon'); | |
$TrainingHref = $dom->createElement('href', plugins_url(). '/OIFNExtended/kml/pins/training.png'); | |
$TrainingIconNode->appendChild($TrainingHref); | |
$TrainingIconstyleNode->appendChild($TrainingIconNode); | |
$TrainingStyleNode->appendChild($TrainingIconstyleNode); | |
$docNode->appendChild($TrainingStyleNode); | |
$OfficeStyleNode = $dom->createElement('Style'); | |
$OfficeStyleNode->setAttribute('id', 'DSO OfficeStyle'); | |
$OfficeIconstyleNode = $dom->createElement('IconStyle'); | |
$OfficeIconstyleNode->setAttribute('id', 'OfficeIcon'); | |
$OfficeIconNode = $dom->createElement('Icon'); | |
$OfficeHref = $dom->createElement('href', plugins_url(). '/OIFNExtended/kml/pins/dso.png'); | |
$OfficeIconNode->appendChild($OfficeHref); | |
$OfficeIconstyleNode->appendChild($OfficeIconNode); | |
$OfficeStyleNode->appendChild($OfficeIconstyleNode); | |
$docNode->appendChild($OfficeStyleNode); | |
$IndividualtrainStyleNode = $dom->createElement('Style'); | |
$IndividualtrainStyleNode->setAttribute('id', 'Individual Training EntityStyle'); | |
$IndividualtrainIconstyleNode = $dom->createElement('IconStyle'); | |
$IndividualtrainIconstyleNode->setAttribute('id', 'IndividualtrainIcon'); | |
$IndividualtrainIconNode = $dom->createElement('Icon'); | |
$IndividualtrainHref = $dom->createElement('href', 'http://maps.google.com/mapfiles/kml/shapes/target.png'); | |
$IndividualtrainIconNode->appendChild($IndividualtrainHref); | |
$IndividualtrainIconstyleNode->appendChild($IndividualtrainIconNode); | |
$IndividualtrainStyleNode->appendChild($IndividualtrainIconstyleNode); | |
$docNode->appendChild($IndividualtrainStyleNode); | |
$OrganisationtrainStyleNode = $dom->createElement('Style'); | |
$OrganisationtrainStyleNode->setAttribute('id', 'Organization Training EntityStyle'); | |
$OrganisationtrainIconstyleNode = $dom->createElement('IconStyle'); | |
$OrganisationtrainIconstyleNode->setAttribute('id', 'OrganizationtrainIcon'); | |
$OrganisationtrainIconNode = $dom->createElement('Icon'); | |
$OrganisationtrainHref = $dom->createElement('href', 'http://maps.google.com/mapfiles/kml/pal2/icon63.png'); | |
$OrganisationtrainIconNode->appendChild($OrganisationtrainHref); | |
$OrganisationtrainIconstyleNode->appendChild($OrganisationtrainIconNode); | |
$OrganisationtrainStyleNode->appendChild($OrganisationtrainIconstyleNode); | |
$docNode->appendChild($OrganisationtrainStyleNode); | |
// Iterates through the MySQL results, creating one Placemark for each row. | |
if ($result_kml = $wpdb->get_results( 'SELECT * FROM markers')) { | |
foreach ($result_kml as $key => $value) { | |
$buistype = $value->type; | |
// Creates a Placemark and append it to the Document. | |
$node = $dom->createElement('Placemark'); | |
$placeNode = $docNode->appendChild($node); | |
// Creates an id attribute and assign it the value of id column. | |
$placeNode->setAttribute('id', 'placemark' . $value->userID); | |
// Create name, and description elements and assigns them the values of the name and address columns from the results. | |
$nameNode = $dom->createElement('name',htmlspecialchars($value->name)); | |
$placeNode->appendChild($nameNode); | |
$descNode = $dom->createElement('description', htmlspecialchars($value->description) . ' <span class="all_hide">' . $buistype . ' all ' . $value->county .' ' . $value->name . '</span>' ); | |
$placeNode->appendChild($descNode); | |
$styleUrl = $dom->createElement('styleUrl', '#' . $buistype . 'Style'); | |
$placeNode->appendChild($styleUrl); | |
// Creates a Point element. | |
$pointNode = $dom->createElement('Point'); | |
$placeNode->appendChild($pointNode); | |
// Creates a coordinates element and gives it the value of the lng and lat columns from the results. | |
$coorStr = $value->lng. ',' . $value->lat; | |
$coorNode = $dom->createElement('coordinates', $coorStr); | |
$pointNode->appendChild($coorNode); | |
} | |
} | |
$kmlOutput = $dom->saveXML(); | |
$locationtosave = realpath(dirname(__FILE__)) . '/kml/kmlOutput.kml'; | |
$dom->save($locationtosave); | |
// header('Content-type: application/vnd.google-earth.kml+xml'); | |
} | |
add_action( 'xprofile_data_after_save', 'updatedb'); | |
add_action( 'delete_user', 'deletemarkers' ); | |
function saveKML(){ | |
global $wpdb; | |
$users_array = array(); | |
// Selects all the rows in the markers table. | |
$result_kml = $wpdb->get_results( 'SELECT * FROM markers'); | |
$current_users = get_users(); | |
foreach($current_users as $user => $value){ | |
$users_array[] = $value->data->ID; | |
} | |
foreach ($result_kml as $$result_kml_key => $value) { | |
if(!in_array($value->userID, $users_array)){ | |
$wpdb->query($wpdb->prepare("DELETE FROM `ccdeathm_mort`.`markers` WHERE `markers`.`userID` = %d", $value->userID)); | |
} | |
} | |
if (!$result_kml){ | |
return; | |
} | |
// Creates the Document. | |
$dom = new DOMDocument('1.0', 'UTF-8'); | |
// Creates the root KML element and appends it to the root document. | |
$node = $dom->createElementNS('http://earth.google.com/kml/2.1', 'kml'); | |
$parNode = $dom->appendChild($node); | |
// Creates a KML Document element and append it to the KML element. | |
$dnode = $dom->createElement('Document'); | |
$docNode = $parNode->appendChild($dnode); | |
// Creates the six Style elements,for the profile type, and append the elements to the Document element. | |
$IndividualStyleNode = $dom->createElement('Style'); | |
$IndividualStyleNode->setAttribute('id', 'IndividualStyle'); | |
$IndividualIconstyleNode = $dom->createElement('IconStyle'); | |
$IndividualIconstyleNode->setAttribute('id', 'IndividualIcon'); | |
$IndividualIconNode = $dom->createElement('Icon'); | |
$IndividualHref = $dom->createElement('href', plugins_url(). '/OIFNExtended/kml/pins/individ.png'); | |
$IndividualIconNode->appendChild($IndividualHref); | |
$IndividualIconstyleNode->appendChild($IndividualIconNode); | |
$IndividualStyleNode->appendChild($IndividualIconstyleNode); | |
$docNode->appendChild($IndividualStyleNode); | |
$OrganisationStyleNode = $dom->createElement('Style'); | |
$OrganisationStyleNode->setAttribute('id', 'CooperativeStyle'); | |
$OrganisationIconstyleNode = $dom->createElement('IconStyle'); | |
$OrganisationIconstyleNode->setAttribute('id', 'OrganizationIcon'); | |
$OrganisationIconNode = $dom->createElement('Icon'); | |
$OrganisationHref = $dom->createElement('href', plugins_url(). '/OIFNExtended/kml/pins/organ.png'); | |
$OrganisationIconNode->appendChild($OrganisationHref); | |
$OrganisationIconstyleNode->appendChild($OrganisationIconNode); | |
$OrganisationStyleNode->appendChild($OrganisationIconstyleNode); | |
$docNode->appendChild($OrganisationStyleNode); | |
$NetworkStyleNode = $dom->createElement('Style'); | |
$NetworkStyleNode->setAttribute('id', 'Community of Practice/NetworkStyle'); | |
$NetworkIconstyleNode = $dom->createElement('IconStyle'); | |
$NetworkIconstyleNode->setAttribute('id', 'NetworkIcon'); | |
$NetworkIconNode = $dom->createElement('Icon'); | |
$NetworkHref = $dom->createElement('href', plugins_url(). '/OIFNExtended/kml/pins/comm.png'); | |
$NetworkIconNode->appendChild($NetworkHref); | |
$NetworkIconstyleNode->appendChild($NetworkIconNode); | |
$NetworkStyleNode->appendChild($NetworkIconstyleNode); | |
$docNode->appendChild($NetworkStyleNode); | |
$TrainingStyleNode = $dom->createElement('Style'); | |
$TrainingStyleNode->setAttribute('id', 'EducationalStyle'); | |
$TrainingIconstyleNode = $dom->createElement('IconStyle'); | |
$TrainingIconstyleNode->setAttribute('id', 'TrainingIcon'); | |
$TrainingIconNode = $dom->createElement('Icon'); | |
$TrainingHref = $dom->createElement('href', plugins_url(). '/OIFNExtended/kml/pins/training.png'); | |
$TrainingIconNode->appendChild($TrainingHref); | |
$TrainingIconstyleNode->appendChild($TrainingIconNode); | |
$TrainingStyleNode->appendChild($TrainingIconstyleNode); | |
$docNode->appendChild($TrainingStyleNode); | |
$OfficeStyleNode = $dom->createElement('Style'); | |
$OfficeStyleNode->setAttribute('id', 'DSO OfficeStyle'); | |
$OfficeIconstyleNode = $dom->createElement('IconStyle'); | |
$OfficeIconstyleNode->setAttribute('id', 'OfficeIcon'); | |
$OfficeIconNode = $dom->createElement('Icon'); | |
$OfficeHref = $dom->createElement('href', plugins_url(). '/OIFNExtended/kml/pins/dso.png'); | |
$OfficeIconNode->appendChild($OfficeHref); | |
$OfficeIconstyleNode->appendChild($OfficeIconNode); | |
$OfficeStyleNode->appendChild($OfficeIconstyleNode); | |
$docNode->appendChild($OfficeStyleNode); | |
$IndividualtrainStyleNode = $dom->createElement('Style'); | |
$IndividualtrainStyleNode->setAttribute('id', 'Individual Training EntityStyle'); | |
$IndividualtrainIconstyleNode = $dom->createElement('IconStyle'); | |
$IndividualtrainIconstyleNode->setAttribute('id', 'IndividualtrainIcon'); | |
$IndividualtrainIconNode = $dom->createElement('Icon'); | |
$IndividualtrainHref = $dom->createElement('href', 'http://maps.google.com/mapfiles/kml/shapes/target.png'); | |
$IndividualtrainIconNode->appendChild($IndividualtrainHref); | |
$IndividualtrainIconstyleNode->appendChild($IndividualtrainIconNode); | |
$IndividualtrainStyleNode->appendChild($IndividualtrainIconstyleNode); | |
$docNode->appendChild($IndividualtrainStyleNode); | |
$OrganisationtrainStyleNode = $dom->createElement('Style'); | |
$OrganisationtrainStyleNode->setAttribute('id', 'Organization Training EntityStyle'); | |
$OrganisationtrainIconstyleNode = $dom->createElement('IconStyle'); | |
$OrganisationtrainIconstyleNode->setAttribute('id', 'OrganizationtrainIcon'); | |
$OrganisationtrainIconNode = $dom->createElement('Icon'); | |
$OrganisationtrainHref = $dom->createElement('href', 'http://maps.google.com/mapfiles/kml/pal2/icon63.png'); | |
$OrganisationtrainIconNode->appendChild($OrganisationtrainHref); | |
$OrganisationtrainIconstyleNode->appendChild($OrganisationtrainIconNode); | |
$OrganisationtrainStyleNode->appendChild($OrganisationtrainIconstyleNode); | |
$docNode->appendChild($OrganisationtrainStyleNode); | |
// Iterates through the MySQL results, creating one Placemark for each row. | |
if ($result_kml = $wpdb->get_results( 'SELECT * FROM markers')) { | |
foreach ($result_kml as $key => $value) { | |
$buistype = $value->type; | |
/* | |
echo "<pre>"; | |
var_dump($value->description); | |
var_dump($value->name); | |
echo "</pre>"; | |
die(); | |
*/ | |
// Creates a Placemark and append it to the Document. | |
$node = $dom->createElement('Placemark'); | |
$placeNode = $docNode->appendChild($node); | |
// Creates an id attribute and assign it the value of id column. | |
$placeNode->setAttribute('id', 'placemark' . $value->userID); | |
// Create name, and description elements and assigns them the values of the name and address columns from the results. | |
$nameNode = $dom->createElement('name',htmlspecialchars($value->name)); | |
$placeNode->appendChild($nameNode); | |
$descNode = $dom->createElement('description', htmlspecialchars($value->description) . ' <span class="all_hide">' . htmlspecialchars( $buistype ) . ' all ' . htmlspecialchars( $value->county ) .' ' . htmlspecialchars( $value->name ) . '</span>' ); | |
$placeNode->appendChild($descNode); | |
$styleUrl = $dom->createElement('styleUrl', '#' . $buistype . 'Style'); | |
$placeNode->appendChild($styleUrl); | |
// Creates a Point element. | |
$pointNode = $dom->createElement('Point'); | |
$placeNode->appendChild($pointNode); | |
// Creates a coordinates element and gives it the value of the lng and lat columns from the results. | |
$coorStr = $value->lng. ',' . $value->lat; | |
$coorNode = $dom->createElement('coordinates', $coorStr); | |
$pointNode->appendChild($coorNode); | |
} | |
} | |
$kmlOutput = $dom->saveXML(); | |
$locationtosave = realpath(dirname(__FILE__)) . '/kml/kmlOutput.kml'; | |
$dom->save($locationtosave); | |
// header('Content-type: application/vnd.google-earth.kml+xml'); | |
} | |
add_action( 'xprofile_data_after_save', 'saveKML',-9999); | |
function provincecheck ($data) { | |
global $bp; | |
if(isset($_POST['field_22'])){ | |
$postcodecheck = $_POST['field_22']; | |
if($postcodecheck != 'Ontario') { | |
bp_core_add_message( __( 'The Province must be Ontario. Check the formatting and try again.', 'buddypress' ), 'error' ); | |
wp_redirect( $bp->loggedin_user->domain . 'profile/edit/group/2/' ); | |
exit(); | |
}elseif ($postcodecheck == '') { | |
bp_core_add_message( __( 'The Province field must be Ontario.', 'buddypress' ), 'error' ); | |
wp_redirect( $bp->loggedin_user->domain . 'profile/edit/group/2/' ); | |
exit(); | |
} | |
} | |
return $data; | |
} | |
//add_action( 'xprofile_data_before_save', 'provincecheck'); | |
/* | |
Login page | |
*/ | |
//check for diclaimer cookie if it's set to disagree redirect user to disclaimer page | |
add_action('init','custom_login'); | |
function custom_login(){ | |
global $pagenow; | |
$disclaimercook = $_COOKIE['disclaimer']; | |
if( 'wp-login.php' == $pagenow && $_GET['action']!="logout" && $disclaimercook == 'disagree') { | |
wp_redirect('/notacceptdiclaimer/'); | |
exit(); | |
} | |
} | |
//login page styling | |
function my_login_stylesheet() { | |
wp_enqueue_style( 'custom-login', plugins_url( 'css' , __FILE__ ) . '/style-login.css' ); | |
wp_enqueue_script( 'custom-login', plugins_url( 'js' , __FILE__ ) . '/style-login.js', array("jquery") ); | |
} | |
add_action( 'login_enqueue_scripts', 'my_login_stylesheet' ); | |
function bp_get_displayed_user_nav_new() { | |
global $bp; | |
foreach ( (array) $bp->bp_nav as $user_nav_item ) { | |
if ( empty( $user_nav_item['show_for_displayed_user'] ) && !bp_is_my_profile() ) | |
continue; | |
$selected = ''; | |
if ( bp_is_current_component( $user_nav_item['slug'] ) ) { | |
$selected = ' class="current selected rs_skip topnav"'; | |
}else{ | |
$selected = ' class="topnav rs_skip"'; | |
} | |
if ( bp_loggedin_user_domain() ) { | |
$link = str_replace( bp_loggedin_user_domain(), bp_displayed_user_domain(), $user_nav_item['link'] ); | |
} else { | |
$link = trailingslashit( bp_displayed_user_domain() . $user_nav_item['link'] ); | |
} | |
if($user_nav_item['name'] === 'Profile'){ | |
$user_nav_item['name'] = 'Listing'; | |
} | |
echo '<li id="' . $user_nav_item['css_id'] . '-personal-li" ' . $selected . ' >'; | |
echo '<a href="' . $link . '" class=" rs_skip" id="user-' . $user_nav_item['css_id'] . '" > ' . $user_nav_item['name'] . '</a>'; | |
echo "<ul class='subnavnav'>"; | |
bp_get_options_nav_new($user_nav_item['slug']); | |
echo "</ul>"; | |
echo "</li>"; | |
//echo '<li ><a >' . $user_nav_item['name'] . '<ul id="subsubnav">'. bp_get_options_nav_new($user_nav_item['slug']) .'<ul></a> </li>'; | |
} | |
} | |
function bp_get_options_nav_new($the_index) { | |
global $bp; | |
// If we are looking at a member profile, then the we can use the current component as an | |
// index. Otherwise we need to use the component's root_slug | |
/* | |
$component_index = !empty( $bp->displayed_user ) ? bp_current_component() : bp_get_root_slug( bp_current_component() ); | |
if ( !bp_is_single_item() ) { | |
if ( !isset( $bp->bp_options_nav[$component_index] ) || count( $bp->bp_options_nav[$component_index] ) < 1 ) { | |
return false; | |
} else { | |
$the_index = $component_index; | |
} | |
} else { | |
if ( !isset( $bp->bp_options_nav[bp_current_item()] ) || count( $bp->bp_options_nav[bp_current_item()] ) < 1 ) { | |
return false; | |
} else { | |
$the_index = bp_current_item(); | |
} | |
} | |
*/ | |
// Loop through each navigation item | |
foreach ( (array) $bp->bp_options_nav[$the_index] as $subnav_item ) { | |
if ( !$subnav_item['user_has_access'] ) | |
continue; | |
// If the current action or an action variable matches the nav item id, then add a highlight CSS class. | |
if ( $subnav_item['slug'] == bp_current_action() ) { | |
$selected = ' class="current selected"'; | |
} else { | |
$selected = ''; | |
} | |
// List type depends on our current component | |
$list_type = bp_is_group() ? 'groups' : 'personal'; | |
// echo out the final list item | |
echo '<li id="' . $subnav_item['css_id'] . '-' . $list_type . '-li" ' . $selected . '><a id="' . $subnav_item['css_id'] . '" href="' . $subnav_item['link'] . '">' . $subnav_item['name'] . '</a></li>'; | |
} | |
} | |
function bp_get_displayed_user_nav_new_readspeak() { | |
global $bp; | |
foreach ( (array) $bp->bp_nav as $user_nav_item ) { | |
if ( empty( $user_nav_item['show_for_displayed_user'] ) && !bp_is_my_profile() ) | |
continue; | |
$selected = ''; | |
if ( bp_is_current_component( $user_nav_item['slug'] ) ) { | |
$selected = ' class="current selected"'; | |
$link = $user_nav_item['link']; | |
} | |
} | |
$urlconstruct = $bp; | |
var_dump( $urlconstruct ); | |
//echo $link; | |
} | |
/******************************************************************************************************************** | |
| | | |
| END PROFILE PAGE EDITS | | |
| | | |
| | | |
********************************************************************************************************************/ | |
/******************************************************************************************************************** | |
| | | |
| Dump hooks very very usefull for debugging Since Buddypress is a bit of a bugger when it comes to priorities! | | |
| | | |
| | | |
********************************************************************************************************************/ | |
function dump_hook( $tag, $hook ) { | |
ksort($hook); | |
echo "<pre>\t$tag<br>"; | |
foreach( $hook as $priority => $functions ) { | |
echo $priority; | |
foreach( $functions as $function ) | |
if( $function['function'] != 'list_hook_details' ) { | |
echo "\t"; | |
if( is_string( $function['function'] ) ) | |
echo $function['function']; | |
elseif( is_string( $function['function'][0] ) ) | |
echo $function['function'][0] . ' -> ' . $function['function'][1]; | |
elseif( is_object( $function['function'][0] ) ) | |
echo "(object) " . get_class( $function['function'][0] ) . ' -> ' . $function['function'][1]; | |
else | |
print_r($function); | |
echo ' (' . $function['accepted_args'] . ') <br>'; | |
} | |
} | |
echo '</pre>'; | |
} | |
function list_hooks( $filter = false ){ | |
global $wp_filter; | |
$hooks = $wp_filter; | |
ksort( $hooks ); | |
foreach( $hooks as $tag => $hook ) | |
if ( false === $filter || false !== strpos( $tag, $filter ) ) | |
dump_hook($tag, $hook); | |
} | |
function list_hook_details( $input = NULL ) { | |
global $wp_filter; | |
$tag = current_filter(); | |
if( isset( $wp_filter[$tag] ) ) | |
dump_hook( $tag, $wp_filter[$tag] ); | |
return $input; | |
} | |
function list_live_hooks( $hook = false ) { | |
if ( false === $hook ) | |
$hook = 'all'; | |
add_action( $hook, 'list_hook_details', -1 ); | |
} | |
function getusers(){ | |
global $wpdb; | |
$data_kml = $wpdb->get_results( 'SELECT * FROM wp_bp_xprofile_data'); | |
$result_kml = array(); | |
foreach ($data_kml as $row) { | |
if ($row->field_id == '1') { | |
$arrayindex = 'user_id'; | |
} | |
elseif ($row->field_id == '2') { | |
$arrayindex = 'Organtype'; | |
} | |
elseif ($row->field_id == '14') { | |
$arrayindex = 'PhoneOne'; | |
} | |
elseif ($row->field_id == '15') { | |
$arrayindex = 'addyLineOne'; | |
} | |
elseif ($row->field_id == '21') { | |
$arrayindex = 'addyLine2'; | |
} | |
elseif ($row->field_id == '22') { | |
$arrayindex = 'Province'; | |
} | |
elseif ($row->field_id == '23') { | |
$arrayindex = 'pcode'; | |
} | |
elseif ($row->field_id == '24') { | |
$arrayindex = 'email'; | |
} | |
elseif ($row->field_id == '265') { | |
$arrayindex = 'branch'; | |
} | |
elseif ($row->field_id == '25') { | |
$arrayindex = 'website'; | |
} | |
elseif ($row->field_id == '26') { | |
$arrayindex = 'profilephoto'; | |
} | |
elseif ($row->field_id == '27') { | |
$arrayindex = 'desc'; | |
} | |
elseif ($row->field_id == '13') { | |
$arrayindex = 'Organisation'; | |
} | |
elseif ($row->field_id == '32') { | |
$arrayindex = 'ContactFirst'; | |
} | |
elseif ($row->field_id == '33') { | |
$arrayindex = 'Contactlast'; | |
} | |
elseif ($row->field_id == '34') { | |
$arrayindex = 'phoneTwo'; | |
} | |
elseif ($row->field_id == '65') { | |
$arrayindex = 'county'; | |
} | |
elseif($row->field_id == '138'){ | |
$arrayindex = 'region'; | |
} | |
elseif($row->field_id == '226'){ | |
$arrayindex = 'coveragearea'; | |
} | |
elseif($row->field_id == '166'){ | |
$arrayindex = 'faconename'; | |
} | |
elseif($row->field_id == '159'){ | |
$arrayindex = 'faconedesc'; | |
} | |
elseif($row->field_id == '160'){ | |
$arrayindex = 'faconeimg'; | |
} | |
elseif($row->field_id == '448'){ | |
$arrayindex = 'faconecreds'; | |
} | |
elseif($row->field_id == '473'){ | |
$arrayindex = 'faconetitle'; | |
} | |
elseif($row->field_id == '479'){ | |
$arrayindex = 'faconeinformal'; | |
} | |
elseif($row->field_id == '502'){ | |
$arrayindex = 'faconeformal'; | |
} | |
elseif($row->field_id == '167'){ | |
$arrayindex = 'factwoname'; | |
} | |
elseif($row->field_id == '171'){ | |
$arrayindex = 'factwodesc'; | |
} | |
elseif($row->field_id == '161'){ | |
$arrayindex = 'factwoimg'; | |
} | |
elseif($row->field_id == '463'){ | |
$arrayindex = 'factwocreds'; | |
} | |
elseif($row->field_id == '472'){ | |
$arrayindex = 'factwotitle'; | |
} | |
elseif($row->field_id == '484'){ | |
$arrayindex = 'factwoinformal'; | |
} | |
elseif($row->field_id == '501'){ | |
$arrayindex = 'factwoformal'; | |
} | |
elseif($row->field_id == '168'){ | |
$arrayindex = 'facthreename'; | |
} | |
elseif($row->field_id == '175'){ | |
$arrayindex = 'facthreedesc'; | |
} | |
elseif($row->field_id == '165'){ | |
$arrayindex = 'facthreeimg'; | |
} | |
elseif($row->field_id == '455'){ | |
$arrayindex = 'facthreecreds'; | |
} | |
elseif($row->field_id == '471'){ | |
$arrayindex = 'facthreetitle'; | |
} | |
elseif($row->field_id == '483'){ | |
$arrayindex = 'facthreeinformal'; | |
} | |
elseif($row->field_id == '500'){ | |
$arrayindex = 'facthreeformal'; | |
} | |
elseif($row->field_id == '170'){ | |
$arrayindex = 'facfourname'; | |
} | |
elseif($row->field_id == '174'){ | |
$arrayindex = 'facfourdesc'; | |
} | |
elseif($row->field_id == '162'){ | |
$arrayindex = 'facfourimg'; | |
} | |
elseif($row->field_id == '456'){ | |
$arrayindex = 'facfourcreds'; | |
} | |
elseif($row->field_id == '470'){ | |
$arrayindex = 'facfourtitle'; | |
} | |
elseif($row->field_id == '482'){ | |
$arrayindex = 'facfourinformal'; | |
} | |
elseif($row->field_id == '499'){ | |
$arrayindex = 'facfourformal'; | |
} | |
elseif($row->field_id == '169'){ | |
$arrayindex = 'facfivename'; | |
} | |
elseif($row->field_id == '172'){ | |
$arrayindex = 'facfivedesc'; | |
} | |
elseif($row->field_id == '163'){ | |
$arrayindex = 'facfiveimg'; | |
} | |
elseif($row->field_id == '461'){ | |
$arrayindex = 'facfivecreds'; | |
} | |
elseif($row->field_id == '469'){ | |
$arrayindex = 'facfivetitle'; | |
} | |
elseif($row->field_id == '481'){ | |
$arrayindex = 'facfiveinformal'; | |
} | |
elseif($row->field_id == '498'){ | |
$arrayindex = 'facfiveformal'; | |
} | |
elseif($row->field_id == '375'){ | |
$arrayindex = 'facsixname'; | |
} | |
elseif($row->field_id == '173'){ | |
$arrayindex = 'facsixdesc'; | |
} | |
elseif($row->field_id == '164'){ | |
$arrayindex = 'facsiximg'; | |
} | |
elseif($row->field_id == '460'){ | |
$arrayindex = 'facsixcreds'; | |
} | |
elseif($row->field_id == '468'){ | |
$arrayindex = 'facsixtitle'; | |
} | |
elseif($row->field_id == '487'){ | |
$arrayindex = 'facsixinformal'; | |
} | |
elseif($row->field_id == '497'){ | |
$arrayindex = 'facsixformal'; | |
} | |
elseif($row->field_id == '378'){ | |
$arrayindex = 'facsevenname'; | |
} | |
elseif($row->field_id == '376'){ | |
$arrayindex = 'facsevendesc'; | |
} | |
elseif($row->field_id == '377'){ | |
$arrayindex = 'facsevenimg'; | |
} | |
elseif($row->field_id == '459'){ | |
$arrayindex = 'facsevencreds'; | |
} | |
elseif($row->field_id == '467'){ | |
$arrayindex = 'facseventitle'; | |
} | |
elseif($row->field_id == '486'){ | |
$arrayindex = 'facseveninformal'; | |
} | |
elseif($row->field_id == '496'){ | |
$arrayindex = 'facsevenformal'; | |
} | |
elseif($row->field_id == '381'){ | |
$arrayindex = 'faceightname'; | |
} | |
elseif($row->field_id == '379'){ | |
$arrayindex = 'faceightdesc'; | |
} | |
elseif($row->field_id == '380'){ | |
$arrayindex = 'faceightimg'; | |
} | |
elseif($row->field_id == '457'){ | |
$arrayindex = 'faceightcreds'; | |
} | |
elseif($row->field_id == '474'){ | |
$arrayindex = 'faceighttitle'; | |
} | |
elseif($row->field_id == '485'){ | |
$arrayindex = 'faceightinformal'; | |
} | |
elseif($row->field_id == '503'){ | |
$arrayindex = 'faceightformal'; | |
} | |
elseif($row->field_id == '384'){ | |
$arrayindex = 'facninename'; | |
} | |
elseif($row->field_id == '382'){ | |
$arrayindex = 'facninedesc'; | |
} | |
elseif($row->field_id == '383'){ | |
$arrayindex = 'facnineimg'; | |
} | |
elseif($row->field_id == '458'){ | |
$arrayindex = 'facninecreds'; | |
} | |
elseif($row->field_id == '477'){ | |
$arrayindex = 'facninetitle'; | |
} | |
elseif($row->field_id == '480'){ | |
$arrayindex = 'facnineinformal'; | |
} | |
elseif($row->field_id == '493'){ | |
$arrayindex = 'facnineformal'; | |
} | |
elseif($row->field_id == '387'){ | |
$arrayindex = 'factenname'; | |
} | |
elseif($row->field_id == '385'){ | |
$arrayindex = 'factendesc'; | |
} | |
elseif($row->field_id == '386'){ | |
$arrayindex = 'factenimg'; | |
} | |
elseif($row->field_id == '454'){ | |
$arrayindex = 'factencreds'; | |
} | |
elseif($row->field_id == '476'){ | |
$arrayindex = 'factentitle'; | |
} | |
elseif($row->field_id == '490'){ | |
$arrayindex = 'facteninformal'; | |
} | |
elseif($row->field_id == '495'){ | |
$arrayindex = 'factenformal'; | |
} | |
elseif($row->field_id == '390'){ | |
$arrayindex = 'facelevenname'; | |
} | |
elseif($row->field_id == '388'){ | |
$arrayindex = 'facelevendesc'; | |
} | |
elseif($row->field_id == '389'){ | |
$arrayindex = 'facelevenimg'; | |
} | |
elseif($row->field_id == '464'){ | |
$arrayindex = 'facelevencreds'; | |
} | |
elseif($row->field_id == '475'){ | |
$arrayindex = 'faceleventitle'; | |
} | |
elseif($row->field_id == '488'){ | |
$arrayindex = 'faceleveninformal'; | |
} | |
elseif($row->field_id == '494'){ | |
$arrayindex = 'facelevenformal'; | |
} | |
elseif($row->field_id == '391'){ | |
$arrayindex = 'factwelvename'; | |
} | |
elseif($row->field_id == '391'){ | |
$arrayindex = 'factwelvedesc'; | |
} | |
elseif($row->field_id == '392'){ | |
$arrayindex = 'factwelveimg'; | |
} | |
elseif($row->field_id == '465'){ | |
$arrayindex = 'factwelvecreds'; | |
} | |
elseif($row->field_id == '478'){ | |
$arrayindex = 'factwelvetitle'; | |
} | |
elseif($row->field_id == '489'){ | |
$arrayindex = 'factwelveinformal'; | |
} | |
elseif($row->field_id == '491'){ | |
$arrayindex = 'factwelveformal'; | |
} | |
elseif($row->field_id == '137'){ | |
$arrayindex = 'town'; | |
} | |
else{ | |
$arrayindex = $row->field_id; | |
} | |
if($row->value === "admin"){ | |
}else{ | |
$result_kml[$row->user_id][$arrayindex] = $row->value; | |
$result_kml[$row->user_id]['id'] = $row->user_id; | |
$result_kml[$row->user_id]['all']= 'all'; | |
if($result_kml[$row->user_id]['desc']){ | |
$result_kml[$row->user_id]['desc'] = stripslashes ( $result_kml[$row->user_id]['desc'] ); | |
} | |
} | |
} | |
$jsonit = json_encode($result_kml); | |
return $jsonit; | |
} | |
function getmarkers(){ | |
global $wpdb; | |
$datamarkers = $wpdb->get_results( 'SELECT * FROM markers'); | |
$jsonmarkers = json_encode($datamarkers); | |
return $jsonmarkers; | |
} | |
function dumpitall(){ | |
echo "<pre>"; | |
var_dump( current_filter() ); | |
echo "</pre>"; | |
} | |
/*add_action( 'all', 'dumpitall' );*/ | |
/******************************************************************************************************************** | |
| | | |
| END DEBUGGING | | |
| | | |
| | | |
********************************************************************************************************************/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment