IT/웹툴즈

오픈캐스트 위젯(?) PHP소스 공개

k2man 2009. 4. 21. 17:39
반응형

웹툴즈에서 몇 가지를 만들어 봤는데요… 트래픽 부담도 있고 해서, 필요하신 분들은 직접 설치해서 쓰시라고 소스를 공개합니다.

PHP가 어려우신 분께서는 아래의 삽입코드는 그대로 이용하셔도 무방합니다. 좀 더 다양한 기능 (통계분석, 이웃관리, 랜덤, 이웃랜덤 등)을 이용하시려면 웹툴즈 홈페이지에서 회원 가입 후 이용하셔야 합니다. (DB와 연결되는 부분이라 어쩔 수 없네요.)

간단히 HTML로만 이루어진 소스는 며칠 전에 공개했으니, 그 것을 이용하시면 됩니다.

RSS로 구독을 원하시면 며칠 전 공개한 RSS구독 PHP소스를 이용하시면 됩니다.

아래 코드는 웹툴즈에서 제공하고 있는 부분 중 회원가입이 필요하진 않은 부분만 추린 소스입니다.

삽입코드

<iframe name='opencastframe' id='opencastframe' src='http://opencast.netne.net/embed.php?opencast_id=KK244&opencast_index=3&is_header=1&is_footer=1&is_feed=1&opencast_feed=opencast.netne.net/feed.php?id=KK244' width='475 height='336' border='0' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' allowtransparency='true'></iframe>

옵션 설명

http://opencast.netne.net/embed.php embed.php의 도메인을 포함한 전체 경로
opencast_id=KK244 필수, 오픈캐스트의 캐스트 채널 아이디
opencast_index=3 생략하면 최신 발행, 발행번호
is_header=1 상단에 캐스트 채널 보일지 여부, 0 또는 생략하면 안보임
is_footer=1 하단에 구독링크 보일지 여부, 0 또는 생략하면 안보임
is_feed=1 하단에 rss 구독링크 보일지 여부, 0 또는 생략하면 안보임, is_footer=1 일 때만 보임
opencast_feed= feed링크에 연결할 주소, 블로그 RSS링크로 바꿔도 됨. 앞서 공개한 RSS PHP파일 경로를 이용. http://를 붙이지 말 것.

만약 is_feed=1 인데, opencast_feed를 생략하면 기본 RSS주소로 링크됩니다. 기본 링크 주소를 바꾸시려면 embed.php의 13번 줄을 변경하시면 됩니다.

view.php

오픈캐스트의 캐스트보드 부분만을 가져오는 IFRAME 소스

view.php?opencast_id=KK244 또는
view.php?opencast_id=KK244&opencast_index=3 형태로 불러오면, 캐스트보드만 가져옴.

캐스트보드만 보여주기 원하면 이 소스만 이용하면 됨.

<?php
// GET변수 가져옴
$opencast_id = $_GET['opencast_id'];
$opencast_index = $_GET['opencast_index'];

$opencast_url = "http://opencast.naver.com/" . $opencast_id;

if ($opencast_index)
$opencast_url .= "/" . $opencast_index;
?>

<body topmargin="0" leftmargin="0" style="background-color:transparent">
<div style="position:absolute; width:475; height:275; left:-263px; top:-127px;">
<iframe name='opencast' id='opencast' src='<?=$opencast_url?>' width='738' height='402' border='0' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' allowtransparency='true'></iframe>
</div>
</body>

embed.php

상단 제목과 하단 구독링크를 만들기 위해서 확장한 것임.

파란색으로 된 줄은 자신의 홈페이지 등으로 링크해서 쓰세요 .

3개의 이미지 파일이 필요합니다. 각 이미지는 embed.php이 있는 디렉토리 하단에 images 디렉토리를 만들어서 업로드 합니다.

<?php
// GET변수 가져옴
$opencast_id = $_GET['opencast_id'];
$opencast_index = $_GET['opencast_index'];
$is_header = $_GET['is_header'];
$is_footer = $_GET['is_footer'];
$opencast_feed = $_GET['opencast_feed'];
$is_feed = $_GET['is_feed'];

$opencast_url = "http://opencast.naver.com/" . $opencast_id;

if ($is_feed && !$opencast_feed)
$opencast_feed = "opencast.netne.net/feed.php?id=" . $opencast_id;

$fp = fopen($opencast_url,"r");
$content = "";
while( !feof($fp) ){
$buffer = fgets($fp,4096);
$content .= $buffer;
}
fclose($fp);

preg_match("/<h1>.*<\/h1>/", $content, $matches);

echo "<p>";
if( $matches[0] == ""){
$ch_link = "";
} else {
$ch_link = $matches[0];
$ch_link = str_replace("a href=\"/", "a target=\"_blank\" href=\"http://opencast.naver.com/", $ch_link);
}

$footer_top = 318;
if (!$is_header)
$footer_top -= 37;
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style>
a:link    {color:#666;text-decoration:none;}
a:visited {color:#666;text-decoration:none;}
a:active  {color:#333;text-decoration:none;}
a:hover  {color:#333;text-decoration:none;}

#chlink { width:100%; height:32px; background:url(images/cast_logo.gif) no-repeat 0 9px; background-color:#272e3c; }
<?php if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) { ?>
#chlink h1 { font-size: 12px; float:left; padding:9px 9px 0 27px; color:#fff; }
<?php } else { ?>
#chlink h1 { font-size: 12px; float:left; padding:2px 9px 0 27px; color:#fff; }
<?php } ?>
#chlink h1 span { position:relative; top:-1px;  margin-right:1px; padding-right:3px; font-size:11px; color:#01939c; font-family:Tahoma, sans-serif;}
#chlink h1 a { color:#fff; }

#chrssicon { position:absolute; width:100%; height:24px; background-color:#f0f0f0; font-size: 11px; font-family:Dotum; float:left; padding:4px 0 0 8px; color:#333333; left:0px; top:<?=$footer_top-6?>px;}
#chrsslink { position:absolute; width:120px; height:24px; font-size: 11px; color:#333333; font-family:Dotum; top:<?=$footer_top?>px; left:28px;}
#chrssicon2 { position:absolute; width:20px; height:24px; background-color:#f0f0f0; font-size: 11px; font-family:Dotum; float:left; padding:4px 0 0 8px; color:#333333; left:110px; top:<?=$footer_top-6?>px;}
#chrsslink2 { position:absolute; width:120px; height:24px; font-size: 11px; color:#333333; font-family:Dotum; top:<?=$footer_top?>px; left:137px;}
#chrssicon3 { position:absolute; width:20px; height:24px; background-color:#f0f0f0; font-size: 11px; font-family:Dotum; float:left; padding:4px 0 0 8px; color:#333333; left:183px; top:<?=$footer_top-6?>px;}
#chrsslink3 { position:absolute; width:120px; height:24px; font-size: 11px; color:#333333; font-family:Dotum; top:<?=$footer_top?>px; left:210px;}
#webtools { position:absolute; width:120px; height:24px; font-size: 10px; color:#333333; font-family:Tahoma, sans-serif; top:10px; left:<?php if($is_right) echo "450px;"; else echo "410px;"; ?> }
#webtools a { color:#666; }
#chhelp { position:absolute; width:220px; height:24px; font-size: 11px; color:#999999; font-family:Dotum; top:<?=$footer_top?>px; left:270px;}

#blank1 { padding:5px 0 0 0; }
</style>
</head>
<body topmargin="0" leftmargin="0" style="background-color:transparent">
<?php if ($is_header) { ?>
<div id="chlink"><?=$ch_link?></div>
<div id="webtools"><a href="http://webtools.kr" target="_blank">WEBTOOLS</a></div>
<div id="blank1"></div>
<?php } ?>
<iframe name='opencast' id='opencast' src='http://opencast.netne.net/view.php?opencast_id=<?=$opencast_id ?>&opencast_index=<?=$opencast_index?>' width='475' height='275' border='0' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' allowtransparency='true'></iframe>
<?php if ($is_footer) { ?>
<div id="chrssicon"><img src="images/cast_link1.gif"></div>
<div id="chrsslink"><a href="<?=$opencast_url?>?action=subscribe" target="_blank">네이버에서 구독</a></div>
<?php if ($is_feed == 1) { // 피드출력 옵션이 체크된 경우만 RSS링크 출력 ?>
<div id="chrssicon2"><img src="images/cast_link2.gif"></div>
<div id="chrsslink2"><a href="http://www.hanrss.com/add_sub.qst?url=http://<?=$opencast_feed?>" target="_blank">HanRSS</a></div>
<div id="chrssicon3"><img src="images/cast_link2.gif"></div>
<div id="chrsslink3"><a href="http://<?=$opencast_feed?>" target="_blank">RSS</a></div>
<?php } ?>
<div id="chhelp">마우스를 올려놓고 휠을 사용해 보세요.</div>
<?php } ?>
</body>
</html>

반응형