SHARE
TWEET

top10 gasoline prices in Riga.

a guest Jan 19th, 2012 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $site=@$_POST['name'];
  3. if (!isset($site)) {$site="e95";}
  4. if($site=="e95"){$site="http://www.gudriem.lv/degviela?lng=lv&ci=&st=&co=&t=&fc=&o=1";}
  5. elseif($site=="e98"){$site="http://www.gudriem.lv/degviela?lng=lv&ci=&st=&co=&t=&fc=&o=5";}
  6. elseif($site=="dd"){$site="http://www.gudriem.lv/degviela?lng=lv&ci=&st=&co=&t=&fc=&o=9";}
  7. else {$site="http://www.gudriem.lv/degviela?lng=lv&ci=&st=&co=&t=&fc=&o=1";}
  8. ?>
  9. <html xmlns="http://www.w3.org/1999/xhtml">
  10.  
  11. <head>
  12. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  13. <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
  14. <style type="text/css">
  15.       html { height: 100% }
  16.       body { height: 100%; margin: 0; padding: 0 }
  17.       #map_canvas { height: 100%; top:0px}
  18.      
  19.       #menu {
  20.         position: fixed;
  21.         _position:absolute;
  22.         _top:expression(eval(document.body.scrollTop));
  23.         left:80px;
  24.         top:0px;
  25.     background-color: #ffffff }
  26.     </style>
  27.  
  28.    
  29.     <script type="text/javascript" src="//maps.googleapis.com/maps/api/js?sensor=false"></script>
  30.     </script>
  31. </head>
  32. <?php
  33.  
  34. //this lib kicks donkeys AKA rocks
  35. //http://simplehtmldom.sourceforge.net/
  36. include_once('simple_html_dom.php');
  37. //////////////////////////////////////
  38.  
  39. //$html= file_get_html('http://www.gudriem.lv/degviela?lng=lv&ci=&st=&co=&t=&fc=&o=1');
  40. $html= file_get_html($site);
  41.  
  42. $v = $html->find('table[id=tresult]');
  43.  
  44.  
  45.  
  46.         foreach($v[0]->find('script,a') as $e) {
  47.                 $e->outertext= '';
  48.                 }
  49.                
  50. //        foreach($v[0]->find('img')as $e){
  51. //          $e->outertext=;
  52.                
  53. //        }
  54.         foreach ($v[0]->find('span') as $e){
  55.                 $e->outertext= "<span>".$e->plaintext."</span>" ;
  56.                 }
  57.                
  58.  
  59.         foreach($v[0]->find('div[class=tooltip_small]') as $e) {
  60.                 $e->style= '';
  61.                 }
  62.                
  63.        
  64.  
  65.  
  66.       //echo $v[0];
  67.  
  68.         $w = $v[0]->find('tr');
  69.        
  70.  
  71. ?>
  72.  
  73. <body onload="initialize()">
  74.     <div id="map_canvas" style="width:100%; height:100%"></div>
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81. <?php  
  82. $i=0;
  83. $j=0;
  84.      
  85.         foreach ($w as $e){
  86.                 $adress= $e->find('span');
  87.                 $adreses= explode(",",$adress[0]->plaintext);
  88.                
  89.                 $allPrices=$e->find('td[class=price]');
  90.                
  91.                 $nosaukums=$e->find('img');
  92.                
  93.                 //$nosaukums=$nosaukums[0]->alt;
  94.                
  95.                
  96.                
  97.                 foreach ($adreses as $adrese){
  98.                         $adrese=str_replace("Adreses","",$adrese);
  99.                        
  100.                         $allStations[$i][0]=trim($adrese);
  101.                         $allStations[$i][1]=trim($allPrices[0]->plaintext);
  102.                         $allStations[$i][1]=str_replace("-","'nav'",$allStations[$i][1]);
  103.                         $allStations[$i][2]=trim($allPrices[1]->plaintext);
  104.                         $allStations[$i][2]=str_replace("-","'nav'",$allStations[$i][2]);
  105.                         $allStations[$i][3]=trim($allPrices[2]->plaintext);
  106.                         $allStations[$i][3]=str_replace("-","'nav'",$allStations[$i][3]);
  107.                         $allStations[$i][4]=trim($nosaukums[0]->alt);
  108.                         $i++;
  109.                 }
  110.         }
  111. ?>
  112.  
  113.  
  114. <script type="text/javascript">
  115.  
  116. ////////////////////////////
  117. //defining global variables
  118. ////////////////////////////
  119.   var geocoder;
  120.   var map;
  121.   var marker = new Array(); //where markers are stored
  122.   var bounds; //for extending when populates markers
  123.  
  124.  
  125.  
  126.  
  127.   function initialize() {
  128.   // creating objects
  129.     geocoder = new google.maps.Geocoder();  //initialize uses codeAddress function and thus codeAddress can access geocoder object
  130.         bounds= new google.maps.LatLngBounds(); //the same with bounds.
  131.         infowindow = new google.maps.InfoWindow({content: "holding..."}); //and with infoWindow.
  132.        
  133.     //var latlng = new google.maps.LatLng(); //setting default latlng for map, maybe not necessary.
  134.     var myOptions = {           //setting default options
  135.       zoom: 11,
  136.       mapTypeId: google.maps.MapTypeId.ROADMAP
  137.     }
  138.     map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); //creating The Map.
  139.  
  140.         <?php
  141.         $i=0;
  142.         array_shift($allStations);      //first element in array is kinda empty (in my case)
  143.         foreach ($allStations as $adrese) { //this php part populates function codeAddress with previously fetched information
  144.                 if ($i<10)      {
  145.                         echo "codeAddress(\"".$adrese[0].", RÄ«ga, Latvija\",$i,$adrese[1],$adrese[2],$adrese[3],'$adrese[4]');\n";
  146.                        
  147.                         }
  148.                 $i++;
  149.         }
  150.         ?>
  151. }
  152. //this is where initialize ends. As it uses function codeAddress - so here it is:
  153.  
  154.   function codeAddress(address,markerNr,e95,e98,dd,nosaukums) {  
  155.     geocoder.geocode( { 'address': address}, function(results, status) {//the address has been passed as street name and number and
  156.       if (status == google.maps.GeocoderStatus.OK) {                            //it should be geocoded through geocoder.
  157.             marker[markerNr] = new google.maps.Marker({                                 //the array with marker objects has been created.
  158.                   <?php //this part chooses correct icon type
  159.                  
  160.                   if ($site=="http://www.gudriem.lv/degviela?lng=lv&ci=&st=&co=&t=&fc=&o=1"){echo "icon: 'icons/gas95_";}
  161.                   elseif($site=="http://www.gudriem.lv/degviela?lng=lv&ci=&st=&co=&t=&fc=&o=5"){echo "icon: 'icons/gas98_";}
  162.                   elseif($site=="http://www.gudriem.lv/degviela?lng=lv&ci=&st=&co=&t=&fc=&o=9"){echo"icon: 'icons/gasdd_";}
  163.                   else{echo"icon: 'icons/gas95',";}
  164.                   ?>'+markerNr+'.png',
  165.            map: map,
  166.             position: results[0].geometry.location,     //where to put the marker
  167.             title: nosaukums+" (" + address + "); 95`ais - " + e95 + " LVL/l; 98`ais - " + e98 + " LVL/l; dÄ«zelis - " + dd + " LVL/l."
  168.         });    
  169.                
  170.                 google.maps.event.addListener(marker[markerNr], 'click', function() { //each marker must listen for click and if clicked it should fire a infowindow with custom content
  171.                 infowindow.setContent("<h2>"+nosaukums+"</h2> (" + address + "); <br/><b>E95</b> - " + e95 + " LVL/l;<br/> <b>E98</b> - " + e98 + " LVL/l; <br/><b>Petrol</b> - " + dd + " LVL/l.");
  172.                 infowindow.open(map,marker[markerNr]);
  173.                 });
  174.                                
  175.                 bounds.extend(marker[markerNr].position);               //and all the time when markers has been populated, the bounds are extending and
  176.                 map.fitBounds(bounds);                                                  //finally the map is centered
  177.            
  178.      } else {
  179.        alert("Geocode was not successful for the following reason: " + status);
  180.      }
  181.    });
  182.  }
  183.        
  184.          
  185.    </script>
  186.        
  187. <div id="menu">
  188. <form action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" method="post" name="formasName">
  189.  
  190. <select name="name" onChange="document.forms['formasName'].submit()">
  191. <option>
  192.       select gas type
  193. </option>
  194. <option>
  195.       e95
  196. </option>
  197. <option>
  198.       e98
  199. </option>
  200. <option>
  201.       dd
  202. </option>
  203. </select>
  204. </form>
  205.  </div>
  206. </body>
  207. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top