Advertisement
developerjustin

Untitled

Feb 7th, 2014
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.78 KB | None | 0 0
  1. <?php /* Template Name: Beer Finder Template */ get_header(); ?>
  2.  
  3.     <?php
  4.    
  5.         $lat = $_GET['lat'];
  6.         $lon = $_GET['lon'];
  7.    
  8.     ?>
  9.  
  10.  
  11.    
  12.     <!-- section -->
  13.     <section role="main" class="main finder">
  14.     <div id="finder-map"></div>
  15.  
  16.         <!-- article -->
  17.         <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  18.        
  19.             <h1><?php the_title(); ?></h1> 
  20.            
  21.            
  22.             <div id="gmap-container">
  23.             <p class="content">Even our year round beers can be elusive at times, so use this guide to help you find any and all of our beers that are out there.</p>          
  24.                 <div id="filter-container">
  25.                     <!--<span class="filter-title">Filter:</span>-->
  26.                     <div class="form-container">
  27.                         <button class="finderbutton findmargin" id="all" type="button">All Beers</button>                  
  28.                         <div class="distance drop findmargin">
  29.                             <h4>Distance</h4>                          
  30.                             <ul class="distance">
  31.                                 <li><input class="filter-input" type="checkbox" name="20" id="release-year"><label for="release-year"><span></span>Within 20 Miles</label></li>
  32.                                 <li><input class="filter-input" type="checkbox" name="50" id="release-migrational"><label for="release-migrational"><span></span>20-50 Miles</label></li>
  33.                                 <li><input class="filter-input" type="checkbox" name="100" id="release-spasmodic"><label for="release-spasmodic"><span></span>50-100 Miles</label></li>
  34.                             </ul>  
  35.                             <span>+</span>                                                 
  36.                         </div>
  37.                         <div class="beer drop findmargin">
  38.                             <h4>Category</h4>
  39.                             <ul class="beer">
  40.                                 <li><input class="filter-input" type="checkbox" name="Year Round" id="release-year"><label for="release-year"><span></span>Year Round</label></li>
  41.                                 <li><input class="filter-input" type="checkbox" name="Migrational" id="release-migrational"><label for="release-migrational"><span></span>Migrational Release</label></li>
  42.                                 <li><input class="filter-input" type="checkbox" name="Spasmodic" id="release-spasmodic"><label for="release-spasmodic"><span></span>Spasmodic Release</label></li>
  43.                                 <li><input class="filter-input" type="checkbox" name="Elusive Reclusive" id="release-elusive"><label for="release-elusive"><span></span>Elusive Reclusive</label></li>
  44.                             </ul>
  45.                             <span>+</span>                                                     
  46.                         </div>                     
  47.                         <div class="zip">
  48.                             <input type="tel" name="zip" class="zip findmargin" onfocus="if (this.value==this.defaultValue) this.value = ''"onblur="if (this.value=='') this.value = this.defaultValue" value="Zip">                           
  49.                         </div> 
  50.                         <button class="finderbutton findmargin" id="gps" type="button">Use My Location</button>                                                                    
  51.                         <button class="finderbutton findmargin" id="findit" type="button">Find The Beer</button>                                               
  52.                     </div>
  53.                    
  54.                 </div> 
  55.                 <div id="controls"></div>
  56.                 <div id="gmap-inner">
  57.                     <div id="gmap"></div>
  58.                 </div>
  59.                 <p class="content">Keep in mind that this map represents a list of accounts that have purchased our beer in the last 30 days, not necessarily who is pouring our beer at any given time. If you are specifically hunting a certain Swamp Head beer, always call the bar or restaurant first.</p>
  60.                                
  61.             </div>         
  62.             <script src="http://maps.google.com/maps/api/js?sensor=false&libraries=geometry&v=3.7"></script>
  63.             <script src="/wp-content/themes/swamphead/js/maplace.min.js"></script> 
  64.             <script src="http://jquery-ui-map.googlecode.com/svn/trunk/ui/min/jquery.ui.map.full.min.js"></script>
  65.             <?php      
  66.                 //Grab all beers at all retailers
  67.                 if($lat!=""){
  68.                     $jsonData = file_get_contents("http://digitalrelativity.org/BeerMappr/API/GetLocationByLatLon.aspx?clientid=SWAMP&lat=".$lat."&lon=".$lon."&dist=100");                                                                            
  69.                 }  
  70.                 else{
  71.                     $jsonData = file_get_contents("http://digitalrelativity.org/BeerMappr/API/GetLocationByLatLon.aspx?clientid=SWAMP&lat=29.6249388&lon=-82.388749&dist=10000");                                                                              
  72.                 }
  73.             ?>
  74.             <script type="text/javascript">
  75.            
  76.                 var maplace = new Maplace();                                               
  77.                            
  78.                 var sampleArray = [];
  79.                 var firstRun = console.log(<?php echo $jsonData; ?>);
  80.                 var json = <?php echo $jsonData; ?>;
  81.                 var lat = "";
  82.                 var lon = "";              
  83.                
  84.                 for (var i = 0, length = json.locations.length; i < length; i++)
  85.                 {
  86.                     var data = json.locations[i];
  87.                     var latLng = new google.maps.LatLng(data.lat, data.lng);   
  88.                    
  89.                                    
  90.                     //console.log("HTML: "+data.description);                      
  91.                     var html = jQuery.parseHTML(data.description);
  92.                     var fullBeer = $(html).find("li").text();  
  93.                     var beerName = fullBeer.substr(0, fullBeer.indexOf(" - "));
  94.                     var fullCat = fullBeer.substr(fullBeer.indexOf("-") + 1);
  95.                     var pack = fullCat.substring(fullCat.lastIndexOf(" ")+1);
  96.                     var release = fullCat.replace(pack,"");
  97.                     var cleanRelease = release.split(' ').join('');
  98.  
  99.                     console.log("Beer Release: *"+cleanRelease+"*");   
  100.                                                        
  101.  
  102.                     sampleArray.push({
  103.                         lat: data.lat,
  104.                         lon: data.lng,
  105.                         release: cleanRelease,
  106.                         title: data.title,
  107.                         html: data.description,
  108.                         icon: 'http://swamp.digitalrelativity.me/wp-content/themes/swamphead/img/Pin'+cleanRelease+'.png'                          
  109.                     });                                                        
  110.                 }
  111.        
  112.                 maplace.Load({
  113.                     show_markers: true,
  114.                     type:'marker',
  115.                     generate_controls: false,                      
  116.                     locations: sampleArray
  117.                 });
  118.                            
  119.                 console.log("Found "+json.count+" beers.");                        
  120.                 console.log("Displayed "+sampleArray.length+" beers.");
  121.  
  122.                
  123.                 $('.filter-input').click(function(e)
  124.                 {
  125.                     var visibility = $('#findit').css( "visibility" );
  126.                     if(visibility=="hidden"){
  127.                         if(document.querySelectorAll('.filter-input:checked').length!=0){
  128.                             $('#findit').css( "visibility" ,"visible");
  129.                         }
  130.                     }
  131.                     else{
  132.                         if(document.querySelectorAll('.filter-input:checked').length==0)
  133.                         {
  134.                             $('#findit').css( "visibility" ,"hidden");
  135.                         }                      
  136.                     }
  137.                 });
  138.                 $('input.zip').change(function(e)
  139.                 {
  140.                     var length = $(this).val().length;
  141.                    
  142.                     if(length>4){
  143.                         $('#findit').css( "visibility" ,"visible");
  144.                     }
  145.                     if(length<5 && document.querySelectorAll('.filter-input:checked').length==0){
  146.                         $('#findit').css( "visibility" ,"hidden");
  147.                     }
  148.                 });                        
  149.                
  150.                 $('#gps').click(function(e)
  151.                 {
  152.                     navigator.geolocation.getCurrentPosition(GetLocation);
  153.                     $('#filter-container *').prop('disabled', true);
  154.                    
  155.                     function GetLocation(location)
  156.                     {
  157.                         lat = location.coords.latitude;
  158.                         lon = location.coords.longitude;
  159.                         $.getJSON("http://maps.googleapis.com/maps/api/geocode/json?latlng="+location.coords.latitude+","+location.coords.longitude+"&sensor=false",null,
  160.                         function(data) {
  161.                             var zip = data['results'][0]['address_components'][7]['long_name'];
  162.                             console.log("GPS Zip: "+zip);
  163.                             $('input.zip').val(zip);
  164.                             $('input.zip').trigger('change');
  165.                             $('#filter-container *').prop('disabled', false);
  166.                         });                    
  167.                     }
  168.                 });                            
  169.  
  170.                 $('#findit').click(function(e)
  171.                 {
  172.                     e.preventDefault();
  173.                    
  174.                     $('#filter-container *').prop('disabled', true);
  175.                                    
  176.                     //Distance
  177.                     if(document.querySelectorAll('.distance .filter-input:checked').length!=0){
  178.                         var dist = document.querySelectorAll('.distance .filter-input:checked')[0].name;
  179.                     }
  180.                     else{
  181.                         var dist = 10000;                      
  182.                     }  
  183.                     //Category
  184.                     if(document.querySelectorAll('.beer .filter-input:checked').length!=0){
  185.                         var name = document.querySelectorAll('.beer .filter-input:checked')[0].name;
  186.                                                
  187.                         try
  188.                         {
  189.                         //Run some code here
  190.                         if(document.querySelectorAll('.beer .filter-input:checked')[1]!=""){
  191.                             name = name+","+document.querySelectorAll('.beer .filter-input:checked')[1].name;
  192.                         }
  193.                         }
  194.                         catch(err)
  195.                         {
  196.                         //Handle errors here
  197.                         }
  198.                         try
  199.                         {
  200.                         //Run some code here
  201.                         if(document.querySelectorAll('.beer .filter-input:checked')[2]!=""){
  202.                             name = name+","+document.querySelectorAll('.beer .filter-input:checked')[2].name;
  203.                         }
  204.                         }
  205.                         catch(err)
  206.                         {
  207.                         //Handle errors here
  208.                         }
  209.                         try
  210.                         {
  211.                         //Run some code here
  212.                         if(document.querySelectorAll('.beer .filter-input:checked')[3]!=""){
  213.                             name = name+","+document.querySelectorAll('.beer .filter-input:checked')[3].name;
  214.                         }
  215.                         }
  216.                         catch(err)
  217.                         {
  218.                         //Handle errors here
  219.                         }                      
  220.                                                
  221.                     }
  222.                     else{
  223.                         var name = null;                       
  224.                     }                  
  225.                     //Zip                                  
  226.                     var zip = $('input.zip').val();                        
  227.                     if(zip=="Zip"){
  228.                         zip="32608";
  229.                     }
  230.                                                                        
  231.                     FilterLocations({
  232.                         dist:dist,
  233.                         name: name,
  234.                         zip: zip
  235.                     });
  236.                 });
  237.                
  238.                 $('#all').click(function(e)
  239.                 {
  240.                     e.preventDefault();
  241.                     $('#filter-container *').prop('disabled', true);
  242.                     FilterLocations({
  243.                         dist:100000,
  244.                         zip: 32608
  245.                     });
  246.                 });            
  247.  
  248.                 function FilterLocations(args)
  249.                 {
  250.                     console.log("Argument object: "+JSON.stringify(args));
  251.                     jQuery.getJSON('http://digitalrelativity.org/BeerMappr/API/GetLocationByZipcode.aspx', {
  252.                         city: args.city,
  253.                         dist: args.dist,
  254.                         name: args.name,
  255.                         zip: args.zip,
  256.                         clientid: 'SWAMP'
  257.                         },
  258.                     function(data)
  259.                     {
  260.                        
  261.                         console.log("Parameter City: *"+args.city+"*");
  262.                         console.log("Parameter Distance: *"+args.dist+"*");
  263.                         console.log("Parameter Lat: *"+args.lat+"*");
  264.                         console.log("Parameter Lon: *"+args.lon+"*");
  265.                         console.log("Parameter Zip: *"+args.zip+"*");
  266.                         console.log("Parameter Name: *"+args.name+"*");
  267.                         console.log("Count: *"+data.count+"*");
  268.                        
  269.                         var sampleArray = [];
  270.                         var json = data;
  271.                        
  272.                         for (var i = 0, length = json.locations.length; i < length; i++)
  273.                         {
  274.                             var data = json.locations[i];
  275.                             var latLng = new google.maps.LatLng(data.lat, data.lng);   
  276.                        
  277.                             var html = jQuery.parseHTML(data.description);
  278.                             var fullBeer = $(html).find("li").text();  
  279.                             var beerName = fullBeer.substr(0, fullBeer.indexOf(" - "));
  280.                             var fullCat = fullBeer.substr(fullBeer.indexOf("-") + 1);
  281.                             var pack = fullCat.substring(fullCat.lastIndexOf(" ")+1);
  282.                             var release = fullCat.replace(pack,"");
  283.                             var cleanRelease = release.split(' ').join('');
  284.  
  285.                             sampleArray.push({
  286.                                 lat: data.lat,
  287.                                 lon: data.lng,
  288.                                 release: cleanRelease,
  289.                                 title: data.title,
  290.                                 html: data.description,
  291.                                 icon: 'http://swamp.digitalrelativity.me/wp-content/themes/swamphead/img/Pin'+cleanRelease+'.png'                          
  292.                             });                                                        
  293.                         }
  294.                        
  295.                         maplace.Load({
  296.                             show_markers: true,
  297.                             type:'marker',
  298.                             generate_controls: false,                      
  299.                             locations: sampleArray
  300.                         });
  301.                                
  302.                         console.log("Found "+json.count+" beers.");                        
  303.                         console.log("Displayed "+sampleArray.length+" beers.");
  304.                         $('#filter-container *').prop('disabled', false);  
  305.                        
  306.                     });
  307.                 }
  308.  
  309.             </script>
  310.             <?php edit_post_link(); ?>
  311.            
  312.         </article>
  313.         <!-- /article -->
  314.  
  315.     </section>
  316.     <!-- /section -->
  317.    
  318. <?php //get_sidebar(); ?>
  319.  
  320. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement