그누보드5 정식버전

This commit is contained in:
chicpro
2014-06-09 14:48:44 +09:00
parent 0243dabe20
commit 7983affa68
1174 changed files with 136960 additions and 0 deletions

View File

@ -0,0 +1,137 @@
<?php
/**
* @class SyndicationArticle
* @author sol (ngleader@gmail.com)
* @brief Syndication Article 데이타 클래스
**/
class SyndicationArticle extends SyndicationObject
{
var $node = array('id','author','category','title','content','published','updated','link_alternative','link_channel','link_channel_alternative');
/**
* @brief URI Tag
**/
function setId($id)
{
$this->id = $id;
}
/**
* @brief Author name
**/
function setName($name)
{
$this->name = $name;
}
/**
* @brief Author email
**/
function setEmail($email)
{
$this->email = $email;
}
/**
* @brief Author homepage or blog
**/
function setUrl($url)
{
$this->url = $url;
}
/**
* @brief category or tag of content
**/
function setCategory($category)
{
$this->category = $category;
}
/**
* @brief Title of content
**/
function setTitle($title)
{
$this->title = $title;
}
/**
* @brief content
**/
function setContent($content)
{
$this->content = $content;
}
/**
* @brief Syndication Content Type으로 blog 경우'blog', 일반사이트 경우 'web'
**/
function setType($type='web')
{
$this->type = $type;
}
/**
* @brief Syndication Ping Url
**/
function setLinkSelf($link_self)
{
$this->link_self = $link_self;
}
/**
* @brief Channel Syndication Ping Url
**/
function setLinkChannel($link_channel)
{
$this->link_channel = $link_channel;
}
/**
* @brief Article(게시물) 접근 Url
**/
function setLinkAlternative($link_alternative)
{
$this->link_alternative = $link_alternative;
}
/**
* @brief Channel(게시판) 접근 Url
**/
function setLinkChannelAlternative($link_channel_alternative)
{
$this->link_channel_alternative = $link_channel_alternative;
}
/**
* @brief published time
* 'YYYYMMDDHHIISS' type
**/
function setPublished($published)
{
$this->published = $published;
}
/**
* @brief update time
* 'YYYYMMDDHHIISS' type
**/
function setUpdated($updated)
{
$this->updated = $updated;
}
function __toString()
{
$str = '';
foreach($this->node as $node){
$str .= $this->get($node);
}
return $str;
}
}
?>

View File

@ -0,0 +1,98 @@
<?php
/**
* @class SyndicationChannel
* @author sol (ngleader@gmail.com)
* @brief Syndication Channel(게시판) 데이타 클래스
**/
class SyndicationChannel extends SyndicationObject
{
var $node = array('id','title','type','summary','updated','link_rss','link_alternative','link_self','link_next_in_thread');
/**
* @brief URI Tag
**/
function setId($id)
{
$this->id = $id;
}
/**
* @brief Title of Channel
**/
function setTitle($title)
{
$this->title = $title;
}
/**
* @brief Type of Channel, web or blog
* blog 일경우 setLinkRss()를 등록해야 함
**/
function setType($type='web')
{
$this->type = $type;
}
/**
* @brief Summary of Channel
**/
function setSummary($summary)
{
$this->summary = $summary;
}
/**
* @brief Syndication Ping Url
**/
function setLinkSelf($link_self)
{
$this->link_self = $link_self;
}
/**
* @brief Channel(게시판) 접근 Url
**/
function setLinkAlternative($link_alternative)
{
$this->link_alternative = $link_alternative;
}
/**
* @brief Channel RSS Url (type이 blog면 필수)
**/
function setLinkRss($link_rss)
{
$this->link_rss = $link_rss;
}
/**
* @brief 다음 페이지 Url
**/
function setNextPage($obj)
{
if(!$obj) return;
if($obj['page']>0) $this->link_next_in_thread = $this->link_self . '&page='. $obj['page'];
}
/**
* @brief update time
* 'YYYYMMDDHHIISS' type
**/
function setUpdated($updated)
{
$this->updated = $updated;
}
function __toString()
{
$str = '';
foreach($this->node as $node){
$str .= $this->get($node);
}
return $str;
}
}
?>

View File

@ -0,0 +1,65 @@
<?php
/**
* @class SyndicationDeleted
* @author sol (ngleader@gmail.com)
* @brief Syndication Delete(Article) 데이타 클래스
**/
class SyndicationDeleted extends SyndicationObject
{
var $node = array('id','title','deleted','updated','link_alternative');
/**
* @brief URI Tag
**/
function setId($id)
{
$this->id = $id;
}
/**
* @brief Title of content
**/
function setTitle($title)
{
$this->title = $title;
}
/**
* @brief update time
* 'YYYYMMDDHHIISS' type
**/
function setUpdated($updated)
{
$this->updated = $updated;
}
/**
* @brief deleted time
* 'YYYYMMDDHHIISS' type
**/
function setDeleted($deleted)
{
$this->deleted = $deleted;
}
/**
* @brief Article(게시물) 접근 Url
**/
function setLinkAlternative($link_alternative)
{
$this->link_alternative = $link_alternative;
}
function __toString()
{
$str = '';
foreach($this->node as $node){
$str .= $this->get($node);
}
return $str;
}
}
?>

View File

@ -0,0 +1,346 @@
<?php
/**
* @class SyndicationHandler
* @author sol (ngleader@gmail.com)
* @brief Syndication 데이타 출력 핸들러
**/
class SyndicationHandler
{
var $param; // GET value
var $type; // 출력 내용 : article, deleted, channel, site
var $target; // 출력 대상 : article, channel, site
var $target_channel_id; // 출력 대상 channel(게시판) 번호 또는 유닉한 문자열
var $target_content_id; // 출력 대상 article(게시물) 번호 또는 유닉한 문자열
var $register_function = array();
function &getInstance()
{
if(!$GLOBALS['__SyndicationHandler__'])
{
$GLOBALS['__SyndicationHandler__'] = new SyndicationHandler();
}
return $GLOBALS['__SyndicationHandler__'];
}
/**
* @brief initialization.
**/
function SyndicationHandler()
{
}
/**
* @brief register function
* site_info
* article_list
* deleted_list
* channel_list
* article_next_page
* deleted_next_page
* channel_next_page
**/
function checkRegisteredFunctions()
{
$ids = array('site_info','article_list','deleted_list','channel_list','article_next_page','deleted_next_page','channel_next_page');
if(count($this->register_function) != count($ids)) return false;
foreach($this->register_function as $id => $func)
{
if(!in_array($id, $ids) || !is_callable($func))
{
return false;
}
}
return true;
}
function registerFunction($id, $func)
{
$this->register_function[$id] = $func;
}
function callFunction($id)
{
if(!isset($this->register_function[$id]) || !is_callable($this->register_function[$id])) return false;
return call_user_func($this->register_function[$id], $this->param);
}
/**
* @brief set GET Value.
**/
function setArgument($args=null)
{
if(!$args) $args = $_GET;
$obj = new stdClass;
$obj->id = $args['id'];
if($args['start-time']) $obj->start_time = SyndicationHandler::getDate($args['start-time']);
if($args['end-time']) $obj->end_time = SyndicationHandler::getDate($args['end-time']);
$obj->max_entry = $args['max_entry'];
if(!$obj->max_entry) $obj->max_entry = 100;
$obj->page = $args['page'];
if(!$obj->page) $obj->page = 1;
$obj->type = $args['type'];
// for getting all article on mysql 3.X, 4.0.X
if($args['channel_id']) $obj->channel_id = $args['channel_id'];
$this->param = $obj;
$this->parseTag();
}
/**
* @brief parsing id value(Tag URI)
**/
function parseTag()
{
// tag:domain,{YYYY}:site:
// tag:domain,{YYYY}:channel:{channel_id}
// tag:domain,{YYYY}:article:{channel_id}-{$article_id}
if(!preg_match('/^tag:([^,]+),([0-9]+):(site|channel|article)(.*)$/i',$this->param->id,$matches)) return;
$this->target = $matches[3];
$id = $matches[4];
if($id && $id{0}==':') $id = substr($id, 1);
switch($this->target)
{
case 'site':
break;
case 'channel':
if(!$id)
{
$this->target = $this->target_channel_id = $this->target_content_id = null;
return;
}
$this->target_channel_id = $id;
break;
case 'article':
if($id && strpos($id,'-')!==false)
{
list($this->target_channel_id, $this->target_content_id) = explode('-',$id);
if(!$this->target_content_id)
{
$this->target = $this->target_channel_id = $this->target_content_id = null;
return;
}
}
else
{
$this->target = $this->target_channel_id = $this->target_content_id = null;
return;
}
break;
}
if($this->target_channel_id) $this->param->target_channel_id = $this->target_channel_id;
if($this->target_content_id) $this->param->target_content_id = $this->target_content_id;
}
/**
* @brief xml for Syndication Server
**/
function getXML()
{
if(!$this->checkRegisteredFunctions()) return '';
switch($this->target)
{
// in site
case 'site':
// get Site info
$oSite = $this->callFunction('site_info');
if(!$oSite) return '';
$list_xml = '';
if(in_array($this->param->type,array('article','deleted','channel')))
{
$list = $this->callFunction($this->param->type . '_list');
if(!$list) $list = array();
$obj = $this->callFunction($this->param->type . '_next_page');
if($obj) $oSite->setNextPage($obj);
foreach($list as $oObject)
{
$list_xml .= $oObject->wrapEntry($oObject->__toString());
}
$xml = $oSite->__toString();
$xml = $oSite->wrapFeed($xml . $list_xml);
}
else
{
$xml = $oSite->__toString();
$xml = $oSite->wrapEntry($xml . $list_xml, true);
}
break;
// in channel
case 'channel':
// get Channel info
$oChannelList = $this->callFunction('channel_list');
if(!is_array($oChannelList) || count($oChannelList)==0) return '';
$oChannel = $oChannelList[0];
$list_xml = '';
if($this->target_channel_id && in_array($this->param->type,array('article','deleted')))
{
$list = $this->callFunction($this->param->type . '_list');
if(is_array($list) && count($list))
{
$obj = $this->callFunction($this->param->type . '_next_page');
if($obj) $oChannel->setNextPage($obj);
foreach($list as $oObject)
{
$list_xml .= $oObject->wrapEntry($oObject->__toString());
}
}
$xml = $oChannel->__toString();
$xml = $oChannel->wrapFeed($xml . $list_xml);
}
else
{
$xml = $oChannel->__toString();
$xml = $oChannel->wrapEntry($xml . $list_xml, true);
}
break;
// article info
case 'article':
if(in_array($this->param->type,array('article','deleted')))
{
$list = $this->callFunction($this->param->type . '_list');
}
if(!is_array($list) || count($list)==0) return '';
$oObject = $list[0];
$xml = $oObject->__toString();
$xml = $oObject->wrapEntry($xml, true);
break;
}
if(!$GLOBALS['syndi_from_encoding']) $GLOBALS['syndi_from_encoding'] = 'utf-8';
if($xml && strtolower($GLOBALS['syndi_from_encoding']) != 'utf-8' && function_exists('iconv'))
{
$xml = iconv($GLOBALS['syndi_from_encoding'], 'utf-8//IGNORE', $xml);
}
return $xml;
}
/**
* @brief Tag URI
**/
function getTag($type, $channel_id=null, $article_id=null)
{
$tag = sprintf('tag:%s,%s:%s'
,$GLOBALS['syndi_tag_domain']
,$GLOBALS['syndi_tag_year']
,$type);
if($type=='channel' && $channel_id)
{
$tag .= ':' . $channel_id;
}
else if($type=='article' && $channel_id && $article_id)
{
$tag .= ':' .$channel_id .'-' . $article_id;
}
return $tag;
}
/**
* @brief Timestamp 로 YYYYMMDDHHIISS 변환
**/
function getDate($timestamp)
{
$time = strtotime($timestamp);
if($time == -1) $time = SyndicationHandler::ztime(str_replace(array('-','T',':'),'',$timestamp));
return date('YmdHis', $time);
}
/**
* @brief YYYYMMDDHHIISS에서 Timestamp로 변환
**/
function getTimestamp($date)
{
$time = mktime(substr($date,8,2),substr($date,10,2),substr($date,12,2),substr($date,4,2),substr($date,6,2),substr($date,0,4));
$timestamp = date("Y-m-d\\TH:i:s", $time). $GLOBALS['syndi_time_zone'];
return $timestamp;
}
function ztime($str)
{
if(!$str) return;
$hour = (int)substr($str,8,2);
$min = (int)substr($str,10,2);
$sec = (int)substr($str,12,2);
$year = (int)substr($str,0,4);
$month = (int)substr($str,4,2);
$day = (int)substr($str,6,2);
if(strlen($str) <= 8)
{
$gap = 0;
}
else
{
$gap = SyndicationHandler::zgap();
}
return mktime($hour, $min, $sec, $month?$month:1, $day?$day:1, $year)+$gap;
}
function zgap()
{
$time_zone = $GLOBALS['syndi_time_zone'];
if($time_zone < 0) $to = -1; else $to = 1;
$t_hour = substr($time_zone, 1, 2) * $to;
$t_min = substr($time_zone, 3, 2) * $to;
$server_time_zone = date("O");
if($server_time_zone < 0) $so = -1; else $so = 1;
$c_hour = substr($server_time_zone, 1, 2) * $so;
$c_min = substr($server_time_zone, 3, 2) * $so;
$g_min = $t_min - $c_min;
$g_hour = $t_hour - $c_hour;
$gap = $g_min*60 + $g_hour*60*60;
return $gap;
}
function error($msg)
{
echo $msg;
exit;
}
}
?>

View File

@ -0,0 +1,104 @@
<?php
/**
* @class SyndicationObject
* @author sol (ngleader@gmail.com)
* @brief Syndication 데이타 타입의 상위 클래스
**/
class SyndicationObject
{
var $id;
var $title;
var $content;
var $summary;
var $author;
var $name;
var $email;
var $url;
var $published;
var $updated;
var $deleted;
var $type;
var $link_self;
var $link_alternative;
var $link_rss;
var $link_channel;
var $link_channel_alternative;
var $link_next_in_thread;
function SyndicationXml()
{
}
function get($node_name)
{
$node = array('id','author','name','email','url','title','type','summary','content','published','deleted','updated','link_rss','link_alternative','link_self','link_channel','link_channel_alternative','link_next_in_thread');
if(!in_array($node_name, $node)) return '';
if($node_name == 'author')
{
$str = "<author>\n";
$str .= $this->get('name');
$str .= $this->get('email');
$str .= $this->get('url');
$str .= "</author>\n";
return $str;
}
$value = $this->{$node_name};
if(!$value) return '';
if(strpos($node_name,'link_')!==false)
{
$type = str_replace('_','-',substr($node_name, strlen('link_')));
return "<link rel=\"".$type."\" href=\"".htmlspecialchars($value)."\" />\n";
}
if(in_array($node_name,array('published','deleted','updated')))
{
$value = $this->_getTime($value);
}
return sprintf("<%s>%s</%s>\n", $node_name, htmlspecialchars($value) ,$node_name);
}
function _getTime($time)
{
return SyndicationHandler::getTimestamp($time);
}
function wrapFeed($str)
{
$return = '<?xml version="1.0" encoding="utf-8"?>';
$return .= "\n";
$return .= '<feed xmlns="http://www.w3.org/2005/Atom">';
$return .= "\n";
$return .= $str;
$return .= "</feed>";
return $return;
}
function wrapEntry($str, $xml_info=false)
{
if($xml_info)
{
$return = '<?xml version="1.0" encoding="utf-8"?>';
$return .= "\n";
$return .= '<entry xmlns="http://www.w3.org/2005/Atom">';
$return .= "\n";
}
else
{
$return .= "<entry>\n";
}
$return .= $str;
$return .= "</entry>\n";
return $return;
}
}
?>

View File

@ -0,0 +1,105 @@
<?php
/**
* @class SyndicationPing
* @author sol (ngleader@gmail.com)
* @brief Syndication Ping Request 클래스
**/
class SyndicationPing
{
// Ping Server
var $ping_host = 'syndication.openapi.naver.com';
var $client;
var $type = 'article';
var $id;
var $start_time;
var $end_time;
var $max_entry;
var $page;
function setId($id)
{
$this->id = $id;
}
function setType($type)
{
$this->type = $type;
}
function setStartTime($start_time)
{
if($start_time)
{
$this->start_time = $this->_convertTime($start_time);
}
}
function setEndTime($end_time)
{
if($end_time)
{
$this->end_time = $this->_convertTime($end_time);
}
}
function _convertTime($time)
{
return str_replace('+','%2b',$time);
}
function setMaxEntry($max_entry)
{
if($max_entry > 0 && $max_entry <= 10000)
{
$this->max_entry = $max_entry;
}
}
function setPage($page)
{
if($page > 0 && $page <= 10000)
{
$this->page = $page;
}
}
function getBody()
{
$str = $GLOBALS['syndi_echo_url'];
$str .= '?id=' . $this->id;
$str .= '&type=' . $this->type;
if($this->start_time && $this->end_time)
{
$str .= '&start_time=' . $this->start_time;
$str .= '&end_time=' . $this->end_time;
}
if($this->max_entry) $str .= '&max_entry=' . $this->max_entry;
if($this->page) $str .= '&page=' . $this->page;
return 'link='.urlencode($str);
}
function request()
{
$body = $this->getBody();
if(!$body) return false;
$header = "POST /ping/ HTTP/1.0\r\n".
"User-Agent: request\r\n".
"Host: " . $this->ping_host . "\r\n".
"Content-Type: application/x-www-form-urlencoded\r\n".
"Content-Length: ". strlen($body) ."\r\n".
"\r\n".
$body;
$fp = @fsockopen($this->ping_host, '80', $errno, $errstr, 5);
if(!$fp) return false;
fputs($fp, $header);
fclose($fp);
return true;
}
}
?>

View File

@ -0,0 +1,74 @@
<?php
/**
* @class SyndicationSite
* @author sol (ngleader@gmail.com)
* @brief Syndication Site 정보 클래스
**/
class SyndicationSite extends SyndicationObject
{
var $node = array('id','title','link_self','link_alternative','link_next_in_thread','updated');
/**
* @brief URI Tag
**/
function setId($id)
{
$this->id = $id;
}
/**
* @brief Title of Site
**/
function setTitle($title)
{
$this->title = $title;
}
/**
* @brief Syndication Ping Url
**/
function setLinkSelf($link_self)
{
$this->link_self = $link_self;
}
/**
* @brief 접근 Url
**/
function setLinkAlternative($link_alternative)
{
$this->link_alternative = $link_alternative;
}
/**
* @brief 다음 페이지 Url
**/
function setNextPage($obj)
{
if(!$obj) return;
if($obj['page']>0) $this->link_next_in_thread = $this->link_self . '&page='. $obj['page'];
if($obj['channel_id']) $this->link_next_in_thread .= '&channel_id='. $obj['channel_id'];
}
/**
* @brief update time
* 'YYYYMMDDHHIISS' type
**/
function setUpdated($updated)
{
$this->updated = $updated;
}
function __toString()
{
$str = '';
foreach($this->node as $node){
$str .= $this->get($node);
}
return $str;
}
}
?>

View File

@ -0,0 +1,77 @@
<?php
/**
* @class SyndicationStatus
* @author sol (ngleader@gmail.com)
* @brief Syndication 상태 정보 클래스
**/
class SyndicationStatus
{
// Status Server
var $status_host = 'syndication.openapi.naver.com';
var $site;
function setSite($site)
{
$this->site = $site;
}
function request()
{
if(!$this->site) return false;
$header = "GET /status/?site=".$this->site." HTTP/1.0\r\n".
"Host: " . $this->status_host . "\r\n\r\n";
$fp = @fsockopen($this->status_host, '80', $errno, $errstr);
if(!$fp) return false;
$output = '';
fputs($fp, $header);
while(!feof($fp)){
$output .= fgets($fp, 1024);
}
fclose($fp);
$output = substr($output, strpos($output, "\r\n\r\n")+4);
return $this->_parse($output);
}
function _parse($data)
{
preg_match_all('@\<([a-z_0-9=\" ]+)\>([^\<]+)\</@', $data, $matches);
if(!$matches[2]) return false;
$output = array('article'=>array());
for($i=0,$c=count($matches[0]);$i<$c;$i++){
if(strpos($matches[1][$i], 'date="')!==false){
$date = substr($matches[1][$i],14,8);
$output['article'][$date] = $matches[2][$i];
}else{
$output[$matches[1][$i]] = $matches[2][$i];
}
}
return $output;
}
}
/*
$oStatus = new SyndicationStatus;
$oStatus->setSite('domain.com');
$output = $oStatus->request();
$output data fields
error : 0이 아닌 경우 에러
message : 에러 메세지
site_url : site url
site_name : site name
first_update : Syndication 서버에 처음 등록된 시간
last_update : Syndication 서버에 최근 갱신 시간
status : site 상태
visit_ok_count : ping 연속 성공 횟수
visit_fail_count : ping 실패 횟수
*/
?>