From: Chuck Scott Date: Tue, 13 Dec 2016 18:36:36 +0000 (-0500) Subject: Initial test version of NearMe feature add-on X-Git-Tag: v0.1.0^2~2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=70e988cc773766f812f9b197804e12f49ffedf03;p=WP-Plugins%2Fglm-member-db-nearme.git Initial test version of NearMe feature add-on --- diff --git a/models/admin/ajax/getPOI.php b/models/admin/ajax/getPOI.php new file mode 100644 index 0000000..5146114 --- /dev/null +++ b/models/admin/ajax/getPOI.php @@ -0,0 +1,276 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + + +// Load Members Data Class +require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMembers.php'; + +/* + * This class exports the currently selected members list + * to a printable HTML file, to a CSV file, or otherwise. + */ +class GlmMembersAdmin_ajax_getPOI extends GlmDataMembers +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + + /* + * Constructor + * + * This contructor sets up this model. At this time that only includes + * storing away the WordPress data object. + * + * @return object Class object + * + */ + public function __construct ($wpdb, $config) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + parent::__construct(false, false); + + } + + /* + * Perform Model Action + * + * This modelAction takes an AJAX request to bump a member detail page views + * counter in the database for the current day, week and month and updates + * the database accordingly. + * + * This model action does not return, it simply does it's work then calls die(); + * + * @param $actionData + * + * Echos JSON string as response and does not return + */ + public function modelAction ($actionData = false) + { + + $ret = false; + $poiAreas = false; // False means to search anywhere + + // Get any search string + $searchText = html_entity_decode( filter_input(INPUT_GET, 'searchText', FILTER_SANITIZE_STRING), ENT_QUOTES | ENT_XML1); + + $request = filter_input(INPUT_GET, 'request', FILTER_SANITIZE_STRING); + + // Get the target LAT/LON area + $latMax = filter_input(INPUT_GET, 'latMax', FILTER_VALIDATE_FLOAT); + $latMin = filter_input(INPUT_GET, 'latMin', FILTER_VALIDATE_FLOAT); + $lonMax = filter_input(INPUT_GET, 'lonMax', FILTER_VALIDATE_FLOAT); + $lonMin = filter_input(INPUT_GET, 'lonMin', FILTER_VALIDATE_FLOAT); + + + // If this is not an "anywhere" search, then build the lat/lon areas + switch($request) { + + case 'onMap'; + + // Check for good LAT/LON data + if ($latMax && $latMin && $lonMax && $lonMin) { + + // Get the previous target LAT/LON area + $lastLatMax = filter_input(INPUT_GET, 'lastLatMax', FILTER_VALIDATE_FLOAT); + $lastLatMin = filter_input(INPUT_GET, 'lastLatMin', FILTER_VALIDATE_FLOAT); + $lastLonMax = filter_input(INPUT_GET, 'lastLonMax', FILTER_VALIDATE_FLOAT); + $lastLonMin = filter_input(INPUT_GET, 'lastLonMin', FILTER_VALIDATE_FLOAT); + + // If this is the first load, request all POIs within map bounds + if ($lastLatMax == false) { + + // Add entire map as area to update + $poiAreas[] = array( + 'area' => 'Entire Map', + 'latMax' => $latMax, + 'latMin' => $latMin, + 'lonMax' => $lonMax, + 'lonMin' => $lonMin + ); + + // Otherwise request only those POIs in the new map areas + } else { + + // Check for good last LAT/LON data + if ($lastLatMax && $lastLatMin && $lastLonMax && $lastLonMin) { + + // Check if there's new area at the top of the map + if ($latMax > $lastLatMax) { + $poiAreas[] = array( + 'area' => 'New at top', + 'latMax' => $latMax, + 'latMin' => $lastLatMax, + 'lonMax' => $lonMax, + 'lonMin' => $lonMin + ); + } + + // Check if there's new area at the bottom of the map + if ($latMin < $lastLatMin) { + $poiAreas[] = array( + 'area' => 'New at bottom', + 'latMax' => $lastLatMin, + 'latMin' => $latMin, + 'lonMax' => $lonMax, + 'lonMin' => $lonMin + ); + } + + // Check if there's new area at the left of the map + if ($lonMin < $lastLonMin) { + $poiAreas[] = array( + 'area' => 'New at left', + 'latMax' => $latMax, + 'latMin' => $latMin, + 'lonMax' => $lastLonMin, + 'lonMin' => $lonMin + ); + } + + // Check if there's new area at the right of the map + if ($lonMax > $lastLonMax) { + $poiAreas[] = array( + 'area' => 'New at right', + 'latMax' => $latMax, + 'latMin' => $latMin, + 'lonMax' => $lonMax, + 'lonMin' => $lastLonMax + ); + } + + } + + } + + } + + break; + + case 'anywhere': + break; + + default: + $request = 'onMap'; + break; + + } + + /* + * Get map items + * + * (NOTE that while this is for a front-end feature, that feature gets + * data via AJAX, which is processed by the admin controller.) + * + * The array supplied is in the following standardized format. This format is + * used for all generic map items aggregated from multiple sources. + * + * 'request' What type of request is being made - Request only + * 'filter' A string filter to use to limit results - Request only + * 'area' A set of lat/lon areas to get results for (if request = 'onMap') - Request only + * If false then get all results without regard as to where they are. + * 'sources' An array of source information for what type of item and which add-on - Each source adds one entry here + * 'mapItems' Array of new map items to return to NearMe - Each source adds one or more map items here + * + * array( + * 'request' => {'onMap', 'anywhere'} + * 'filter' => {some search string} + * 'area' => array( + * // First area to search + * array( + * 'latMax' => {lat at North end of area}, + * 'latMin' => {lat at South end of area}, + * 'lonMax' => {lon at East end of area}, + * 'lonMin' => {lon at West end of area} + * ), + * // Second area to search + * array( + * 'latMax' => {lat at North end of area}, + * 'latMin' => {lat at South end of area}, + * 'lonMax' => {lon at East end of area}, + * 'lonMin' => {lon at West end of area} + * ), + * // Additional areas + * ), + * 'sources' = array( + * {addOn Slug} => array( + * 'addOn' => {addOn Slug}, + * 'type' => {Name to use for the source - Needs to match the 'type' element in map items added by the addOn ) + * ), + * // Additional sources + * ), + * 'mapItems' => array( + * array( + * 'type' => {type of item, i.e. 'member', 'event', ...}, + * 'id' => {ID of item for reference}, + * 'lat' => {Latitude}, + * 'lon' => {Longitude}, + * 'name' => {Name of item}, + * 'loc_name' => {Name of Location}, + * 'addr1' => {Address line 1 of location}, + * 'addr2' => {Address line 2 of location}, + * 'city' => {City of location}, + * 'state' => {State code of location}, + * 'zip' => {Postal Code of location}, + * 'phone' => {Contact phone number}, + * 'email' => {Contact E-Mail address}, + * 'url' => {URL of item}, + * 'region' => {Region name, if available}, + * 'categories' => {array of categories - i.e. array( 0 = array( id => {id}, name => {name}), ... ) + * 'descr' => {Description}, + * 'short_descr' => {Short Description}, + * 'detail_page' => {URL of detail page, if available}, + * 'dates' => {Text stating date, dates, or date range}, + * 'times' => {Text stating time, times, or time range} + * ) + * ) + * ) + */ + $poiData = apply_filters( + 'glm-hook-list-map-items-by-latlon', + array( + 'request' => $request, + 'filter' => $searchText, + 'area' => $poiAreas, + 'sources' => array(), + 'mapItems' => array() + ) + ); + + header('Content-type:application/json;charset=utf-8', true); + echo json_encode($poiData); + + wp_die(); + + } + +} diff --git a/models/front/nearme/index.php b/models/front/nearme/index.php new file mode 100644 index 0000000..00b6def --- /dev/null +++ b/models/front/nearme/index.php @@ -0,0 +1,195 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + +/* + * This class performs the work for displaying members packages. + */ +class GlmMembersFront_nearme_index +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + + /* + * Constructor + * + * This contructor sets up this model. At this time that only includes + * storing away the WordPress data object. + * + * @return object Class object + * + */ + public function __construct ($wpdb, $config) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + // Enqueue the Marker Clusterer Script + wp_register_script( + 'glm-members-admin-google-maps-marker-clusterer', + GLM_MEMBERS_PLUGIN_URL . 'js/googleMapsMarkerClusterer/markerclustererplus.js', + array( + 'jquery' + ), + GLM_MEMBERS_PLUGIN_VERSION + ); + wp_enqueue_script('glm-members-admin-google-maps-marker-clusterer', false, array('jquery'), false, true); + + } + + /* + * Perform Model Action + * + * This method does the work for this model and returns any resulting data + * + * @return array Status and data array + * + * 'status' + * + * True if successfull and false if there was a fatal failure. + * + * 'menuItemRedirect' + * + * If not false, provides a menu item the controller should + * execute after this one. Normally if this is used, there would also be a + * modelRedirect value supplied as well. + * + * 'modelRedirect' + * + * If not false, provides an action the controller should execute after + * this one. + * + * 'view' + * + * A suggested view name that the contoller should use instead of the + * default view for this model or false to indicate that the default view + * should be used. + * + * 'data' + * + * Data that the model is returning for use in merging with the view to + * produce output. + * + */ + public function modelAction ($actionData = false) + { + + $status = true; + $pointsOfInterest = array(); + $havePOI = false; // Have Points of Interest + + // Set default map center + $mapCenterLat = $this->config['settings']['maps_default_lat']; + $mapCenterLon = $this->config['settings']['maps_default_lon']; + + // Set default reference location + $refLat = $mapCenterLat; + $refLon = $mapCenterLon; + + // Set default map zoom + $mapZoom = 14; // Need to add this to management ****** + + // Check for user cookie - Cookie will be set by ajax request from map so we can save the last user map status - Overides defaults + if (isset($_COOKIE) && isset($_COOKIE[GLM_MEMBERS_NEARME_PLUGIN_SLUG])) { + $cookie = $_COOKIE[GLM_MEMBERS_NEARME_PLUGIN_SLUG]; + $mapCenterLat = $cookie['mapCenterLat']; + $mapCenterLon = $cookie['mapCenterLon']; + $refLat = $cookie['refLat']; + $refLon = $cookie['refLon']; + $mapZoom = $cookie['mapZoom']; + } + + // Check for specified map center, reference location, and zoom - Overides cookies and defaults + $mapCenterLat = $this->checkMapRequest('mapCenterLat', $mapCenterLat); + $mapCenterLon = $this->checkMapRequest('mapCenterLon', $mapCenterLon); + $refLat = $this->checkMapRequest('refLat', $refLat); + $refLon = $this->checkMapRequest('refLon', $refLon); + $mapZoom = $this->checkMapRequest('mapZoom', $mapZoom); + + $view = 'index.html'; + + // Compile template data + $templateData = array( + 'siteBaseUrl' => GLM_MEMBERS_SITE_BASE_URL, + 'pointsOfInterest' => $pointsOfInterest, + 'havePOI' => $havePOI, + 'mapCenterLat' => $mapCenterLat, + 'mapCenterLon' => $mapCenterLon, + 'refLat' => $refLat, + 'refLon' => $refLon, + 'mapZoom' => $mapZoom + ); + + // Return status, suggested view, and data to controller - also return any modified settings + return array( + 'status' => $status, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => 'front/nearme/'.$view, + 'data' => $templateData + ); + + } + + /* + * Check for a submitted value for map defaults + * + * @param $param string Name of the request parameter + * @param $default float/integer Default value to return if none was sumbitted + * + * @return float/integer Value to use + */ + private function checkMapRequest ($param, $default) + { + // If there's no request array, return default + if (!isset($_REQUEST)) { + return $default; + } + + // If the request parameter doesn't exist, return default + if (!isset($_REQUEST[$param])) { + return $default; + } + + // If it's not a valid number, return default + $val = ($_REQUEST[$param] - 0); + if ($val == 0) { + return $default; + } + + // Return the parameter value + return $val; + + } + + +} + +?> \ No newline at end of file diff --git a/setup/shortcodes.php b/setup/shortcodes.php index 2206529..3403201 100644 --- a/setup/shortcodes.php +++ b/setup/shortcodes.php @@ -48,7 +48,7 @@ * The following is an explanation of this array. * * array( - * '{shortcode-slug} => array( + * '{shortcode-slug}' => array( * 'plugin' => '{plugin (add-on) slug}', // Identifies which plugin is providing the short-code * 'menu' => '{menu name}', // Menu name in this context is simply where to find the action * 'action' => '{shortcode action name}, // Action used to execute this shortcode @@ -62,6 +62,7 @@ * * Shortcode descriptions sample * + * ShortcodeAttributeDescription * * [glm-members-sample-shortcode] *   @@ -87,7 +88,24 @@ */ $glmMembersNearMeShortcodes = array( + 'glm-members-nearme' => array( + 'plugin' => GLM_MEMBERS_NEARME_PLUGIN_SLUG, // Identifies which plugin is providing the short-code + 'menu' => 'nearme', // Menu name in this context is simply where to find the action + 'action' => 'index', // Action used to execute this shortcode + 'table' => false, // Database table where default attribute values are stored + 'attributes' => array( // An array of all shortcode attributes (options) + ) + ) ); -$glmMembersNearMeShortcodesDescription = ''; +$glmMembersNearMeShortcodesDescription = ' + ShortcodeAttributeDescription + + [glm-members-nearme] +   + + Displays the NearMe search map and associated information. + + +'; diff --git a/setup/validActions.php b/setup/validActions.php index 9e4eee3..05af50d 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -59,8 +59,14 @@ $glmMembersNearMeAddOnValidActions = array( 'adminActions' => array( + 'ajax' => array( + 'getPOI' => GLM_MEMBERS_NEARME_PLUGIN_SLUG + ) ), 'frontActions' => array( + 'nearme' => array( + 'index' => GLM_MEMBERS_NEARME_PLUGIN_SLUG + ) ) ); diff --git a/views/front/footer.html b/views/front/footer.html new file mode 100644 index 0000000..75ce31a --- /dev/null +++ b/views/front/footer.html @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/views/front/nearme/header.html b/views/front/nearme/header.html new file mode 100644 index 0000000..4eaacea --- /dev/null +++ b/views/front/nearme/header.html @@ -0,0 +1,3 @@ +
+
+ \ No newline at end of file diff --git a/views/front/nearme/index.html b/views/front/nearme/index.html new file mode 100644 index 0000000..a296762 --- /dev/null +++ b/views/front/nearme/index.html @@ -0,0 +1,871 @@ +{include file='front/nearme/header.html'} + + + + +
+ Display only items matching this text:     + + Search All Areas + +
+ +

+ +
+ My Location: + Follow Me + Manual Map Selection +    + Set My Location Here  + Return to My Location  + Back to previous map location  + Loading ... +
+
(map loads here)
+
+ Show:   +
+
+ My Location (drag to change) + + Clustered locations - Click to view: + + + + + + +
+
+
+

My Favorites

+
+ +
+
+ +
+ { name } - Click for more +
+ + + +{include file='front/footer.html'} \ No newline at end of file