일반페이지에서 그누보드 스킨의 기능 적용하기
관련링크
본문
예를 들어 https://sir.kr/g5_skin/19250?page=4 (페이지 참조)
그누보드 설치되지 않은 페이지에서 예로 아이프래임<iframe ... >을 이용해 날씨정보를 가져오려면 어떻게 해야 할까요? 도움 주시면 감사하겠습니다.
답변 5
아래 소스를 복사해서 weather.php 파일 만드시고
거기에 style.css 파일과 map_sub3.png 파일 같이 올리신 후에
weather.php 실행해보세요.
<link rel="stylesheet" href="./style.css">
<?php
// 많이 사용하는 경우 openweathermap.org 에서 api 키 발급
$g5['weather_key']='ceb339a4c742fc7a9c33dd51a0bdc68c';
$cache_file= "./weather_cache.php";
$arr_week=array('일','월','화','수','목','금','토');
$arr_info=array(
1=>"맑음"
,2=>"다소흐림"
,3=>"흐림"
,4=>"많이흐림"
,9=>"소나기"
,10=>"비"
,11=>"천둥번개"
,13=>"눈"
,50=>"안개");
//30분에 한번씩 갱신함
if (is_file($cache_file) && time()-filemtime($cache_file)<30*60) {
$arr_data=unserialize(file_get_contents($cache_file));
}
else {
$arr=explode("\n","
서해,125.853029,37.271484
서울,126.975148,37.560961
춘천,127.165517,37.832336
강릉,128.896103,37.755562
울릉,130.839601,37.506399
충남,126.670660,36.658832
충북,127.489267,36.635409
경북,128.750000,36.333328
전남,126.460730,34.816223
전북,127.106533,35.820364
경남,128.250000,35.250000
제주,126.521942,33.509720
");
$g5['arr_city']=array();
foreach($arr as $str) {
$arr2=explode(',',trim($str));
if ($arr2[1]) $g5['arr_city'][$arr2[0]]=array('lon'=>$arr2[1],'lat'=>$arr2[2]);
}
$arr_data=array();
foreach($g5['arr_city'] as $city=>$arr) {
$lat=$arr['lat'];
$lon=$arr['lon'];
$url="http://api.openweathermap.org/data/2.5/weather?lat=$lat&lon=$lon&units=metric&APPID=".$g5['weather_key'];
$w = curl_init($url);
$weather_options = array(
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true
);
curl_setopt_array($w, $weather_options);
$a = curl_exec($w);
curl_close($w);
if (!isset($a) || ! $a) continue;
$weather=json_decode($a,true);
$arr_data[]=array(
'temp'=>intval($weather['main']['temp'])
,'icon'=>$weather['weather'][0]['icon']
);
$arr_data['datetime']=date("Y-m-d H:i",$weather['dt']);
}
file_put_contents($cache_file,serialize($arr_data));
}
?>
<div id='ar_weather'>
<div class='map'>
<?php for($i=0;$i<12;$i++) { ?>
<div class="zone area<?php echo ($i+1)?>" title="<?php echo $arr_info[intval($arr_data[$i]['icon'])]?>">
<img src="//openweathermap.org/img/w/<?php echo $arr_data[$i]['icon']?>.png"><BR>
<?php echo $arr_data[$i]['temp']?>
</div>
<?php } ?>
</div>
<div class='info'>
<?php echo substr($arr_data['datetime'],5)?> (<?php echo $arr_week[date(w,$arr_data['datetime'])]?>) 발표
</div>
</div>
와우~ eyekiss 선생님 감사합니다. 한번 적용해 보고 감사의 댓글 다시 올리겠습니다. (꾸벅^^)
도움 주셔서 참으로 감사합니다.
이왕 이렇게 알려 주셨으니 여기도 한 번 살펴주셨으면 더욱 감사하겠습니다.
기존 데이터와 날씨정보가 동일한데요... 제가 헤깔려서요.
날짜는 맞는데 요일이 현재 일요일인데 ---> '목요일'로 출력 됩니다.
예: 04-15 13:00 (목) 발표
어느부분 수정하면 되는지 알려 주시면 더욱 감사하게씁니다.
좋은 컨텐츠 올려 주셔서 감사한데 이렇게 상세하게 알려 주시니 더욱 감사합니다.
오늘 하루 즐거운 일 가득하세요 (꾸벅^^)
답변 채택하였습니다. 감사합니다~~^^ (최고세요)
답변을 작성하시기 전에 로그인 해주세요.