git-svn-id: http://xe-core.googlecode.com/svn/trunk@261 201d5d3c-b55e-5fd7-737f-ddc643e51545

This commit is contained in:
zero 2007-03-06 01:21:27 +00:00
parent c1622a7c2f
commit 31bfa47594
14 changed files with 232 additions and 52 deletions

View file

@ -13,6 +13,7 @@
class Context { class Context {
var $request_method = 'GET'; ///< @brief GET/POST/XMLRPC 중 어떤 방식으로 요청이 왔는지에 대한 값이 세팅. GET/POST/XML 3가지가 있음 var $request_method = 'GET'; ///< @brief GET/POST/XMLRPC 중 어떤 방식으로 요청이 왔는지에 대한 값이 세팅. GET/POST/XML 3가지가 있음
var $response_method = ''; ///< @brief HTML/XMLRPC 중 어떤 방식으로 결과를 출력할지 결정. (강제 지정전까지는 request_method를 따름)
var $context = NULL; ///< @brief request parameter 및 각종 환경 변수등을 정리하여 담을 변수 var $context = NULL; ///< @brief request parameter 및 각종 환경 변수등을 정리하여 담을 변수
@ -287,6 +288,38 @@
} }
} }
/**
* @brief response method를 강제로 지정 (기본으로는 request method를 이용함)
*
* method의 종류에는 HTML/ TEXT/ XMLRPC가 있음
**/
function setResponseMethod($method = "HTML") {
$oContext = &Context::getInstance();
return $oContext->_setResponseMethod($method);
}
function _setResponseMethod($method = "HTML") {
$this->response_method = $method;
}
/**
* @brief response method 값을 return
*
* method의 종류에는 HTML/ TEXT/ XMLRPC가 있음
* 별도로 response method를 지정하지 않았다면 request method로 판단하여 결과 return
**/
function getResponseMethod() {
$oContext = &Context::getInstance();
return $oContext->_getResponseMethod();
}
function _getResponseMethod() {
if($this->response_method) return $this->response_method;
if($this->_getRequestMethod()=="XMLRPC") return "XMLRPC";
return "HTML";
}
/** /**
* @brief request method가 어떤것인지 판단하여 저장 (GET/POST/XMLRPC) * @brief request method가 어떤것인지 판단하여 저장 (GET/POST/XMLRPC)
**/ **/

View file

@ -26,7 +26,7 @@
$content = $this->getContent($oModule); $content = $this->getContent($oModule);
// 요청방식에 따라 출력을 별도로 // 요청방식에 따라 출력을 별도로
if(Context::getRequestMethod()!="XMLRPC") { if(Context::getResponseMethod()!="XMLRPC") {
Context::set('content', $content); Context::set('content', $content);
// content 래핑 (common/tpl/default.html) // content 래핑 (common/tpl/default.html)
@ -119,6 +119,7 @@
$buff .= "\n- Request/ Response info\n"; $buff .= "\n- Request/ Response info\n";
$buff .= sprintf("\tRequest URI \t\t\t: %s:%s%s%s%s\n", $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'], $_SERVER['PHP_SELF'], $_SERVER['QUERY_STRING']?'?':'', $_SERVER['QUERY_STRING']); $buff .= sprintf("\tRequest URI \t\t\t: %s:%s%s%s%s\n", $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'], $_SERVER['PHP_SELF'], $_SERVER['QUERY_STRING']?'?':'', $_SERVER['QUERY_STRING']);
$buff .= sprintf("\tRequest method \t\t\t: %s\n", $_SERVER['REQUEST_METHOD']); $buff .= sprintf("\tRequest method \t\t\t: %s\n", $_SERVER['REQUEST_METHOD']);
$buff .= sprintf("\tResponse method \t\t: %s\n", Context::getResponseMethod());
$buff .= sprintf("\tResponse contents size\t\t: %d byte\n", $this->getContentSize()); $buff .= sprintf("\tResponse contents size\t\t: %d byte\n", $this->getContentSize());
if($GLOBALS['__db_queries__']) { if($GLOBALS['__db_queries__']) {
$buff .= "\n- DB Queries\n"; $buff .= "\n- DB Queries\n";
@ -140,7 +141,7 @@
* @brief RequestMethod에 맞춰 헤더 출력 * @brief RequestMethod에 맞춰 헤더 출력
***/ ***/
function _printHeader() { function _printHeader() {
if(Context::getRequestMethod() == 'XMLRPC') return $this->_printXMLHeader(); if(Context::getResponseMethod() == 'XMLRPC') return $this->_printXMLHeader();
else return $this->_printHTMLHeader(); else return $this->_printHTMLHeader();
} }

View file

@ -380,9 +380,13 @@
$info->link = sprintf("%s?mid=%s", Context::getRequestUri(), Context::get('mid')); $info->link = sprintf("%s?mid=%s", Context::getRequestUri(), Context::get('mid'));
$info->total_count = $output->total_count; $info->total_count = $output->total_count;
// 출력하고 끝내기 // RSS 모듈을 불러서 출력할 내용을 지정
$oRssView = &getView('rss'); $oRssView = &getView('rss');
$oRssView->dispRss($info, $document_list); $oRssView->dispRss($info, $document_list);
// RSS 모듈의 tempate을 가져옴
$this->setTemplatePath($oRssView->getTemplatePath());
$this->setTemplateFile($oRssView->getTemplateFile());
} }
/** /**

View file

@ -14,7 +14,7 @@
} }
/** /**
* @brief 스팸필터 설정 * @brief 설정
**/ **/
function procInsertConfig() { function procInsertConfig() {
// 기본 정보를 받음 // 기본 정보를 받음

View file

@ -15,7 +15,7 @@
} }
/** /**
* @brief 애드온 목록을 보여줌 * @brief 설정
**/ **/
function dispConfig() { function dispConfig() {
// 설정 정보를 받아옴 (module model 객체를 이용) // 설정 정보를 받아옴 (module model 객체를 이용)

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<module>
<grants />
<actions>
<action name="dispConfig" type="view" admin_index="true" standalone="true" />
<action name="procInsertConfig" type="controller" standalone="true" />
</actions>
</module>

View file

@ -0,0 +1,18 @@
<?php
/**
* @file : modules/rss/lang/ko.lang.php
* @author : zero <zero@nzeo.com>
* @desc : 한국어 언어팩 (기본적인 내용만 수록)
**/
// 일반 단어들
$lang->rss_disable = "RSS 끄기";
$lang->rss_type = "출력할 RSS 형식";
// 설명문
$lang->about_rss_disable = "체크하시면 RSS 출력을 하지 않습니다";
$lang->about_rss_type = "출력하실 RSS 형식을 지정하실 수 있습니다";
// 에러 메세지들
$lang->msg_rss_is_disabled = "RSS 기능이 잠겨 있습니다";
?>

View file

@ -7,7 +7,10 @@
class rss extends ModuleObject { class rss extends ModuleObject {
var $rss_type = "rss2.0"; var $default_rss_type = "rss20";
var $rss_types = array(
"rss20" => "rss2.0"
);
} }
?> ?>

View file

@ -0,0 +1,34 @@
<?php
/**
* @class rssController
* @author zero (zero@nzeo.com)
* @brief rss module의 view class
*
* RSS 2.0형식으로 문서 출력
*
**/
class rssController extends rss {
/**
* @brief 초기화
**/
function init() {
}
/**
* @brief 설정
**/
function procInsertConfig() {
// 기본 정보를 받음
$args = Context::gets('rss_disable', 'rss_type');
if($args->rss_disable!='Y') $args->rss_disable = 'N';
if(!$args->rss_type) $args->rss_type = "rss20";
// module Controller 객체 생성하여 입력
$oModuleController = &getController('module');
$output = $oModuleController->insertModuleConfig('rss',$args);
return $output;
}
}
?>

View file

@ -3,7 +3,6 @@
* @class rssView * @class rssView
* @author zero (zero@nzeo.com) * @author zero (zero@nzeo.com)
* @brief rss module의 view class * @brief rss module의 view class
* @todo 다양한 형식의 format 제어 기능 추가
* *
* RSS 2.0형식으로 문서 출력 * RSS 2.0형식으로 문서 출력
* *
@ -17,40 +16,38 @@
function init() { function init() {
} }
function dispRss($info, $content, $type="rss2.0") { /**
switch($type) { * @brief 설정
case "rss2.0" : **/
$this->dispRss20($info, $content); function dispConfig() {
break; // 설정 정보를 받아옴 (module model 객체를 이용)
} $oModuleModel = &getModel('module');
$config = $oModuleModel->getModuleConfig('rss');
Context::set('config',$config);
Context::set('rss_types',$this->rss_types);
exit(); // 템플릿 파일 지정
$this->setTemplatePath($this->module_path.'tpl.admin/');
$this->setTemplateFile('index');
} }
/** /**
* @brief content를 받아서 rss 형식으로 출력 * @brief RSS 출력
**/ **/
function dispRss20($info, $content) { function dispRss($info, $content) {
header("Content-Type: text/xml; charset=UTF-8"); // 설정 정보를 받아옴 (module model 객체를 이용)
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); $oModuleModel = &getModel('module');
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); $config = $oModuleModel->getModuleConfig('rss');
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false); // RSS 비활성화 되었는지 체크하여 비활성화시 에러 출력
header("Pragma: no-cache"); if($config->rss_disable=='Y') return $this->dispError();
print '<?xml version="1.0" encoding="utf-8" ?>'."\n";
print "<!-- // RSS2.0 -->\n"; // RSS 출력 형식을 체크
$rss_type = $config->rss_type;
if(!$this->rss_types->{$rss_type}) $rss_type = $this->default_rss_type;
?><rss version="2.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/">
<channel>
<title><![CDATA[<?=$info->title?>]]></title>
<link><![CDATA[<?=$info->link?>]]></link>
<description><![CDATA[<?=$info->description?>]]></description>
<language><?=$info->language?></language>
<pubDate><?=$info->date?></pubDate>
<totalCount><?=$info->total_count?></totalCount>
<?
if(count($content)) { if(count($content)) {
foreach($content as $item) { foreach($content as $key => $item) {
$year = substr($item->regdate,0,4); $year = substr($item->regdate,0,4);
$month = substr($item->regdate,4,2); $month = substr($item->regdate,4,2);
$day = substr($item->regdate,6,2); $day = substr($item->regdate,6,2);
@ -59,26 +56,41 @@
$sec = substr($item->regdate,12,2); $sec = substr($item->regdate,12,2);
$time = mktime($hour,$min,$sec,$month,$day,$year); $time = mktime($hour,$min,$sec,$month,$day,$year);
$title = $item->title; $item->author = $item->user_name;
$author = $item->user_name; $item->link = sprintf("%s?document_srl=%d", Context::getRequestUri(), $item->document_srl);
$link = sprintf("%s?document_srl=%d", Context::getRequestUri(), $item->document_srl); $item->description = $item->content;
$description = $item->content; $item->date = gmdate("D, d M Y H:i:s", $time);
$date = gmdate("D, d M Y H:i:s", $time); $content[$key] = $item;
?>
<item>
<title><![CDATA[<?=$title?>]]></title>
<author><![CDATA[<?=$author?>]]></author>
<link><![CDATA[<?=$link?>]]></link>
<description><![CDATA[<?=$description?>]]></description>
<pubDate><?=$date?></pubDate>
</item>
<?
} }
} }
?>
</channel> // RSS 출력물에서 사용될 변수 세팅
</rss> Context::set('info', $info);
<? Context::set('content', $content);
// 결과 출력을 XMLRPC로 강제 지정
Context::setResponseMethod("XMLRPC");
// 템플릿 파일 지정
$this->setTemplatePath($this->module_path.'tpl/');
$this->setTemplateFile($rss_type);
}
/**
* @brief 에러 출력
**/
function dispError() {
// 결과 출력을 XMLRPC로 강제 지정
Context::setResponseMethod("XMLRPC");
// 출력 메세지 작성
Context::set('error', -1);
Context::set('message', Context::getLang('msg_rss_is_disabled') );
// 템플릿 파일 지정
$this->setTemplatePath($this->module_path.'tpl.admin/');
$this->setTemplateFile("error");
} }
} }
?> ?>

View file

@ -0,0 +1,6 @@
{'<?xml version="1.0" encoding="utf-8" ?>'}
<response>
<error>{$error}</error>
<message><![CDATA[{$message}]]></message>
</response>

View file

@ -0,0 +1,7 @@
<filter name="insert_config" module="rss" act="procInsertConfig" confirm_msg_code="confirm_submit">
<form />
<response>
<tag name="error" />
<tag name="message" />
</response>
</filter>

View file

@ -0,0 +1,32 @@
<!--%import("filter/insert_config.xml")-->
<form action="./" method="get" onsubmit="return procFilter(this, insert_config)">
<table border="1">
<tr>
<th rowspan="2">{$lang->rss_disable}</th>
<td><input type="checkbox" name="rss_disable" value="Y" <!--@if($config->rss_disable=="Y")-->checked="true"<!--@end--> />
</tr>
<tr>
<td>{$lang->about_rss_disable}</td>
</tr>
<tr>
<th rowspan="2">{$lang->rss_type}</th>
<td>
<select name="rss_type">
<!--@foreach($rss_types as $key => $val)-->
<option value="{$key}" <!--@if($key==$config->rss_type)-->selected="true"<!--@end-->>{$val}</option>
<!--@end-->
</select>
</td>
</tr>
<tr>
<td>{$lang->about_rss_type}</td>
</tr>
<tr>
<td colspan="2">
<input type="button" value="{$lang->cmd_cancel}" onclick="location.href='{@getUrl('act','')}'" />
<input type="submit" value="{$lang->cmd_registration}" accesskey="s" />
</td>
</tr>
</table>
</form>

View file

@ -0,0 +1,22 @@
{'<?xml version="1.0" encoding="utf-8" ?>'}
<!-- // RSS2.0 -->
<rss version="2.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/">
<channel>
<title><![CDATA[{$info->title}]]></title>
<link><![CDATA[{$info->link}]]></link>
<description><![CDATA[{$info->description}]]></description>
<language>{$info->language}</language>
<pubDate>{$info->date}</pubDate>
<totalCount>{$info->total_count}</totalCount>
<!--@foreach($content as $item)-->
<item>
<title><![CDATA[{$item->title}]]></title>
<author><![CDATA[{$item->author}]]></author>
<link><![CDATA[{$item->link}]]></link>
<description><![CDATA[{$item->description}]]></description>
<pubDate>{$item->date}</pubDate>
</item>
<!--@end-->
</channel>
</rss>