"PHP" / Говнокод #4853 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
<!-- saved from url=(0014)about:internet -->
<?php
define('WEATHER_FILE_3_DAYS', '/meteoparse/weather.xml');
define('WEATHER_URL_3_DAYS', 'http://pogoda.by/xml2/xml-kstati.by.php');
define('BASE_PATH', $_SERVER['DOCUMENT_ROOT']);
define('DAYS_COUNT', 3);
 
require_once('include/weather_tools.php');
 
if (date('d.m.Y.h', filectime(BASE_PATH . WEATHER_FILE_3_DAYS)) != date('d.m.Y.h')) {
        copy(WEATHER_URL_3_DAYS, BASE_PATH . WEATHER_FILE_3_DAYS);      
}
        $file = file_get_contents ('weather.xml');
        $xmlWeather = simplexml_load_string($file);
        $aXmlForecasts = $xmlWeather->xpath('/pogoda/CITY/FORECAST');
        
$aWeather = array();
$curDay = 0;
 
foreach($aXmlForecasts as $xmlForecast) {
        $attrs = $xmlForecast->attributes();
        $date = $attrs->day . '-' .
                $attrs->month . '-' .
                $attrs->year;
        $hour = strval($attrs->hour);
        if (!array_key_exists($date, $aWeather)) {
                $curDay++;
                if ($curDay > DAYS_COUNT) break;
                $aWeather[$date] = array();
        }
        if (!array_key_exists($hour, $aWeather[$date])) {
                $aWeather[$date][$hour] = array();
        }
        foreach($xmlForecast as $property => $values) {
                $aWeather[$date][$hour][$property] = '';
                $valuesAttr = $values->attributes();
                foreach($valuesAttr as $value) {
                        $aWeather[$date][$hour][$property] .= strval($value);
                }                               
        }
        
}
foreach($aWeather as $dateKey => $date) {
        foreach ($date as $hourKey => $hour) {
                $aWeather[$dateKey][$hourKey]['DAYTIME'] = getDayTime($hourKey);
                $aWeather[$dateKey][$hourKey]['PHENOMENA'] = getPhenomeaUrl($hour['PHENOMENA']);
                $aWeather[$dateKey][$hourKey]['WIND'] = getWind($hour['WIND']);
        }
}
?>
                <td colspan="<?php echo count($aWeather); ?>">
                        <?php foreach ($aWeather as $date => $hours) : ?>                       
                        <table id="<?php echo 'table' . $date; ?>" class="hide">
                                <tr class="attrs">
                                        <th></th>
                                        <th></th>
                                        <th>Давление</th>
                                        <th>t, °С</th>
                                        <th>Ветер</th>
                                </tr>
                                <?php foreach($hours as $hour => $properties) : ?>
                                <tr>
                                        <td><?php echo $properties['DAYTIME']; ?></td>
                                        <td><img src="<?php echo $properties['PHENOMENA']; ?>" /></td>
                                        <td class="param"><?php echo $properties['PRESSURE']; ?> гПа </td>
                                        <td class="param1"><?php echo $properties['TEMPERATURE']; ?> °C</td>
                                        <td class="param"><?php echo $properties['WIND']; ?> &nbsp(м/с)</td>
                                </tr>
                                <?php endforeach; ?>
                        </table>
                        <?php endforeach; ?>
                </td>
        </tr>
        </table>
        </div>
        <script type="text/javascript">
                var weatherBox = document.getElementById('weatherBox');
                weatherBox.getElementsByTagName('table')[0].getElementsByTagName('table')[0].className = "show";
        </script>

#4837 Продолжение.

Запостил: qbasic qbasic, (Updated )

Комментарии (6) RSS

  • http://pogoda.by/315/xml.html
    Владельцам сайтов, желающих размещать погоду в формате XML, рекомендуется связаться с администрацией сайта.
    можно не связываться. ок.
    Ответить
  • А это не наш говнокод, это kstati.by говнокод - они писали.
    skif, pogoda.by
    Ответить
    • как говорил один офицер РККА: "это - отмазка, и ты сам это понимаешь"
      Ответить
  • Нашел, откуда ноги растут. Это совместный проект kstati.by и нашего нового сотрудника 🙂 На pogoda.by использоваться не будет 🙂
    Ответить

Добавить комментарий

Где здесь C++, guest?!

    А не использовать ли нам bbcode?


    8