index.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. $location = isset($_GET['location']) ? $_GET['location'] : '02135';
  3. //get xml from google api
  4. $ch = curl_init();
  5. curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/ig/api?weather='. $location);
  6. curl_setopt($ch, CURLOPT_HEADER, 0);
  7. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  8. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  9. $result = curl_exec($ch);
  10. curl_close($ch);
  11. //parse xml (thx KomunitasWeb.com for pointers)
  12. $xml = simplexml_load_string($result);
  13. $information = $xml->xpath("/xml_api_reply/weather/forecast_information");
  14. $current = $xml->xpath("/xml_api_reply/weather/current_conditions");
  15. $forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");
  16. ?>
  17. <!DOCTYPE html>
  18. <html>
  19. <head>
  20. <meta charset="utf-8">
  21. <meta name="viewport" content="width=device-width, initial-scale=1">
  22. <title>jQuery Mobile Framework - Weather for <?php echo $information[0]->city['data']; ?></title>
  23. <link rel="stylesheet" href="../../jquery.mobile-1.0.1.min.css" />
  24. <script src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
  25. <script src="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.js"></script>
  26. <style>
  27. .current { text-align: left; }
  28. h1 { font-size: 1.3em; text-align: center; }
  29. .ui-listview img { left: auto; margin: 10px; position: absolute; right: 10px; }
  30. .current { position: relative; }
  31. .current img { float: left; margin: 5px 10px 0 0; }
  32. .current p { font-weight: bold; font-size: 1.1em; margin-left: 20px; }
  33. .ui-mobile label { position: absolute; left: -9999px; }
  34. .ui-input-search, .min-width-480px .ui-input-search { margin: 5px auto; width: auto; float: none; display: block; }
  35. </style>
  36. <script>
  37. $('div').live('pagecreate',function(){
  38. $('.ui-listview img').removeClass('ui-corner-bl');
  39. });
  40. </script>
  41. </head>
  42. <body>
  43. <div data-role="page" data-theme="a">
  44. <form action="" method="get" class="ui-body ui-body-a ">
  45. <label for="location">Change zip code:</label>
  46. <input type="search" name="location" id="location" value="<?php echo$location; ?>" placeholder="zip code..." data-theme="a" />
  47. <input type="submit" data-role="nojs" value="submit" />
  48. </form>
  49. <div data-role="content">
  50. <h1>Currently in <?=$information[0]->city['data']; ?>:</h1>
  51. <div class="current ui-body ui-bar-a ui-corner-all">
  52. <img src="<?php echo 'http://www.google.com' . $current[0]->icon['data']?>" alt="weather">
  53. <p class="condition">
  54. <?php echo $current[0]->temp_f['data']; ?>&deg; F,
  55. <?php echo $current[0]->condition['data']; ?>
  56. </p>
  57. </div>
  58. <ul data-role="listview" data-inset="true" data-theme="a">
  59. <li data-role="list-divider">This week's forecast</li>
  60. <?php foreach ($forecast_list as $forecast) : ?>
  61. <li>
  62. <img src="<?php echo 'http://www.google.com' . $forecast->icon['data']; ?>">
  63. <h3><?php echo $forecast->day_of_week['data']; ?></h3>
  64. <p>
  65. <?php echo $forecast->low['data']; ?>&deg; F - <?php echo $forecast->high['data']; ?>&deg; F,
  66. <?php echo $forecast->condition['data']; ?>
  67. </p>
  68. </li>
  69. <?php endforeach; ?>
  70. </ul>
  71. </div>
  72. </div>
  73. </body>
  74. </html>