Skip to content

Commit

Permalink
#3 Naver Syndication API v2 대응, version 4.0.0-beta.1
Browse files Browse the repository at this point in the history
  • Loading branch information
akasima committed Jul 11, 2014
1 parent 1b61219 commit 727ba98
Show file tree
Hide file tree
Showing 19 changed files with 335 additions and 219 deletions.
4 changes: 2 additions & 2 deletions conf/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<description xml:lang="ko">검색서비스업체와 직접 통신을 통해 컨텐츠를 잘 검색되도록 하는 Syndication 규약을 따라 정보를 주고받는 모듈</description>
<description xml:lang="zh-TW">검색서비스업체와 직접 통신을 통해 컨텐츠를 잘 검색되도록 하는 Syndication 규약을 따라 정보를 주고받는 모듈</description>
<description xml:lang="tr">검색서비스업체와 직접 통신을 통해 컨텐츠를 잘 검색되도록 하는 Syndication 규약을 따라 정보를 주고받는 모듈</description>
<version>3.1.0-beta.2</version>
<date>2014-01-09</date>
<version>4.0.0-beta.1</version>
<date>2014-07-11</date>
<category>interlock</category>

<author email_address="developers@xpressengine.com" link="http://xpressengine.com/">
Expand Down
5 changes: 2 additions & 3 deletions conf/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
<actions>
<action name="getSyndicationList" type="model" />
<action name="dispSyndicationAdminConfig" type="view" admin_index="true" />
<action name="procSyndicationAdminInsertService" type="controller" ruleset="insertService" />
<action name="procSyndicationAdminCheckSitePingResult" type="controller" />
<action name="procSyndicationAdminCheckApiStatus" type="controller" />
<action name="procSyndicationAdminInsertConfig" type="controller" ruleset="insertService" />
<action name="procSyndicationAdminCheckPingResult" type="controller" />
</actions>
</module>
28 changes: 27 additions & 1 deletion lang/lang.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
<value xml:lang="zh-TW"><![CDATA[供稿服務]]></value>
<value xml:lang="tr"><![CDATA[İçerik Paylaşım Hizmeti]]></value>
</item>
<item name="naver_syndication_token">
<value xml:lang="ko"><![CDATA[NAVER 신디케이션 Token]]></value>
<value xml:lang="en"><![CDATA[NAVER Syndication Token]]></value>
<value xml:lang="jp"><![CDATA[NAVER シンディケーション Token]]></value>
<value xml:lang="zh-TW"><![CDATA[NAVER 聯合供搞 Token]]></value>
<value xml:lang="tr"><![CDATA[NAVER İçerik Paylaşımı Token]]></value>
</item>
<item name="about_syndication_service">
<value xml:lang="ko"><![CDATA[신디케이션 표준 규약에 맞춰 신디케이션 서비스를 제공하는 곳입니다.<br/>[적용하기] 버튼을 선택하시면 선택 또는 해제된 서비스에 Ping 을 통해서 결과를 통보하게 됩니다]]></value>
<value xml:lang="en"><![CDATA[Syndication Service provides syndication services according to a standard protocol.<br/>You will get Ping result from the selected (deselected) services if you apply.]]></value>
Expand All @@ -32,12 +39,24 @@
<value xml:lang="jp"><![CDATA[サイトアドレス]]></value>
<value xml:lang="zh-TW"><![CDATA[供稿網址]]></value>
</item>
<item name="my_syndication_password">
<value xml:lang="ko"><![CDATA[신디케이션 비밀번호]]></value>
<value xml:lang="en"><![CDATA[Syndication Password]]></value>
<value xml:lang="jp"><![CDATA[シンジケーションパスワード]]></value>
<value xml:lang="zh-TW"><![CDATA[聚合密碼]]></value>
</item>
<item name="about_my_syndication_url">
<value xml:lang="ko"><![CDATA[신디케이션 정보를 제공할때 사용되는 사이트의 주소를 입력해주세요. 이 주소는 대표 주소를 이용해주시고 가능한 바꾸시지 않는 것이 좋습니다]]></value>
<value xml:lang="en"><![CDATA[Please enter the URL which will be used when providing syndication information. It is recommended to use representative URL and keep it as long as you can.]]></value>
<value xml:lang="jp"><![CDATA[シンディケーション情報を提供するときに使用されるサイトのアドレスを入力してください。このアドレスは、代表アドレスを利用し、できれば変更しないでください。]]></value>
<value xml:lang="tr"><![CDATA[Lütfen sendikasyon bilgilerini sağlarken kullanılacak URLyi girin. Temsili bir URLyi mümkün olduğu sürece kullanmak daha uygun olabilir.]]></value>
</item>
<item name="about_my_syndication_password">
<value xml:lang="ko"><![CDATA[신디케이션 비밀번호를 설정하여 허용되지 않은 곳에서의 접근을 차단합니다.]]></value>
<value xml:lang="en"><![CDATA[Set syndication password for block access where not allowed.]]></value>
<value xml:lang="jp"><![CDATA[許可されていないブロックアクセスのための設定シンジケーションパスワード。]]></value>
<value xml:lang="zh-TW"><![CDATA[銀團設置密碼的地方不允許的訪問。]]></value>
</item>
<item name="except_module">
<value xml:lang="ko"><![CDATA[제외시킬 모듈]]></value>
<value xml:lang="en"><![CDATA[Modules to exclude]]></value>
Expand All @@ -57,6 +76,13 @@
<value xml:lang="zh-TW"><![CDATA[請輸入網站網址]]></value>
<value xml:lang="tr"><![CDATA[Lütfen URL girişi yapın]]></value>
</item>
<item name="msg_syndication_token_is_null">
<value xml:lang="ko"><![CDATA[신디케이션 Token을 입력해주세요]]></value>
<value xml:lang="en"><![CDATA[Please enter Syndication Token.]]></value>
<value xml:lang="jp"><![CDATA[シンジケートTokenを入力してください]]></value>
<value xml:lang="zh-TW"><![CDATA[請輸入辛迪加令牌]]></value>
<value xml:lang="tr"><![CDATA[Sendikasyon Token'ı girin.]]></value>
</item>
<item name="success_applied">
<value xml:lang="ko"><![CDATA[적용되었습니다]]></value>
<value xml:lang="en"><![CDATA[Successfully Applied]]></value>
Expand Down Expand Up @@ -134,4 +160,4 @@
<value xml:lang="jp"><![CDATA[同期化状態]]></value>
<value xml:lang="tr"><![CDATA[Eş zamanlama statüleri]]></value>
</item>
</lang>
</lang>
9 changes: 9 additions & 0 deletions queries/deleteLog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<query id="deleteLog" action="delete">
<tables>
<table name="syndication_logs" />
</tables>
<conditions>
<condition operation="equal" column="module_srl" var="module_srl" filter="number" />
<condition operation="equal" column="document_srl" var="document_srl" filter="number" pipe="and" />
</conditions>
</query>
2 changes: 1 addition & 1 deletion queries/getDeletedList.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<condition operation="less" column="regdate" var="end_date" filter="number" pipe="and" />
</conditions>
<navigation>
<index var="sort_index" default="log_srl" order="asc" />
<index var="sort_index" default="log_srl" order="desc" />
<list_count var="list_count" default="100" />
<page_count var="page_count" default="10" />
<page var="page" default="1" />
Expand Down
1 change: 1 addition & 0 deletions ruleset/insertService.xml → ruleset/insertConfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
</customrules>
<fields>
<field name="site_url" required="true" />
<field name="syndication_token" required="true" />
</fields>
</ruleset>
117 changes: 27 additions & 90 deletions syndication.admin.controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,26 @@

class syndicationAdminController extends syndication {

function init() {
function init()
{
}

function procSyndicationAdminInsertService() {
function procSyndicationAdminInsertConfig()
{
$oModuleController = getController('module');
$oSyndicationController = getController('syndication');
$oSyndicationModel = getModel('syndication');

$config = new stdClass;
$config->target_services = explode('|@|',Context::get('target_services'));
$config->site_url = preg_replace('/\/+$/is','',Context::get('site_url'));
$config->year = Context::get('year');
$config->syndication_token = Context::get('syndication_token');
$config->syndication_password = Context::get('syndication_password');

if(!$config->site_url) return new Object(-1,'msg_site_url_is_null');
if(!$config->syndication_token) return new Object(-1,'msg_syndication_token_is_null');

$oModuleController->insertModuleConfig('syndication',$config);
$oSyndicationController->ping($oSyndicationModel->getID('site'), 'site');
$oModuleController->updateModuleConfig('syndication',$config);

$except_module = Context::get('except_module');
$output = executeQuery('syndication.deleteExceptModules');
Expand All @@ -42,102 +46,35 @@ function procSyndicationAdminInsertService() {
$this->setMessage('success_applied');
if(!in_array(Context::getRequestMethod(),array('XMLRPC','JSON'))) {
$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispSyndicationAdminConfig');
header('location:'.$returnUrl);
$this->setRedirectUrl($returnUrl);
return;
}
}

function procSyndicationAdminCheckSitePingResult(){
$site_url = trim(Context::get('site_url'));
if(!$site_url) return new Object(-1,'msg_invalid_request');

$oSyndicationModel = getModel('syndication');

$id = $oSyndicationModel->getID('site');
if(substr($site_url,-1)!='/') $site_url .= '/';
$site_ping = sprintf('http://%s?module=syndication&act=getSyndicationList&id=%s&type=site', $site_url, $id);

$headers = array();
$headers['Connection'] = 'TE, close';
$headers['User-Agent'] = 'Mozilla/4.0 (compatible; NaverBot/1.0; http://help.naver.com/customer_webtxt_02.jsp)';

$xml = FileHandler::getRemoteResource($site_ping, null, 3, 'GET', '', $headers);
if(!$xml) return new Object(-1, 'msg_ping_test_error');

$oXmlParser = new XmlParser();
$oXml = $oXmlParser->parse($xml);

if(!$oXml || !is_object($oXml) || !$oXml->entry || !$oXml->entry->id || !$oXml->entry->title) {
$this->setMessage('msg_ping_test_error');
$this->add('ping_result',$xml);
}else{
$this->setMessage('msg_success_ping_test');
}
}

function procSyndicationAdminCheckApiStatus(){
$target_service = Context::get('target_service');
if(!$target_service) return new Object(-1,'msg_invalid_request');

$status_url = trim($this->statuses[$target_service]);
if(!$status_url) return new Object(-1,'msg_syndication_status_not_support');

function procSyndicationAdminCheckPingResult()
{
$oModuleModel = getModel('module');

$config = $oModuleModel->getModuleConfig('syndication');
$site_url = preg_replace('/^(http|https):\/\//i','',$config->site_url);
$oSyndicationController = getController('syndication');
$oSyndicationModel= getModel('syndication');

$method = 'getSyndicationStatus' . ucfirst(strtolower($target_service));
if(!method_exists($this, $method)) return new Object(-1,'msg_syndication_status_not_support');
$module_config = $oModuleModel->getModuleConfig('syndication');

$output = call_user_func(array(&$this,$method),$site_url);
if(!$output->toBool()) return $output;
$site_url = trim(Context::get('site_url'));
if(!$module_config->site_url) return new Object(-1,'msg_site_url_is_null');
if(!$module_config->syndication_token) return new Object(-1,'msg_syndication_token_is_null');

$this->add('result_status',$output->get('result_status'));
}
$id = $oSyndicationModel->getID('site');

function getSyndicationStatusNaver($site_url){
$status_url = trim($this->statuses['Naver']);

$xml = FileHandler::getRemoteResource(sprintf($status_url,$site_url), null, 3, 'GET', 'application/xml');
$oXmlParser = new XmlParser();
$oXml = $oXmlParser->parse($xml);
$oStatus = $oXml->syndication_status;

if($oStatus->error->body != 0) return new Object(-1,$oStatus->message->body);

$result = new stdClass;
$result->site_name = $oStatus->site_name->body;
$result->first_update = $oStatus->first_update->body;
$result->last_update = $oStatus->last_update->body;
$result->visit_ok_count = $oStatus->visit_ok_count->body;
$result->visit_fail_count = $oStatus->visit_fail_count->body;
$result->status = $oStatus->status->body;

if(!$oStatus->sync || !$oStatus->sync->article){
$oArticleList = array();
}else{
$oArticleList = $oStatus->sync->article;
if(!is_array($oArticleList)) $oArticleList = array($oArticleList);
// site_url 정보와 token 정보를 이용해서 ping 전송 테스트
if($oSyndicationController->ping($id, 'site')===FALSE)
{
$this->setError(-1);
$this->setMessage($oSyndicationController->ping_message);
}

if(count($oArticleList)>0){
$article_count = array();
foreach($oArticleList as $article){
$article_count[$article->attrs->date] = $article->body;
}

$result->article_count = $article_count;
$result->max_article_count = max($result->article_count);

else
{
$this->setMessage('msg_success_ping_test');
}

Context::set('result', $result);
$oTemplateHandler = &TemplateHandler::getInstance();
$html = $oTemplateHandler->compile($this->module_path.'tpl', 'naver_result');

$output = new Object();
$output->add('result_status', $html);
return $output;
}
}
29 changes: 12 additions & 17 deletions syndication.admin.view.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,36 @@
**/
class syndicationAdminView extends syndication
{
function init() {
function init()
{
}

public function dispSyndicationAdminConfig()
{
$oModuleModel = getModel('module');

$module_config = $oModuleModel->getModuleConfig('syndication');
if(!$module_config->target_services)
{
$module_config->target_services = array();
}

foreach($this->services as $key => $val)
{
unset($obj);
$obj = new stdClass;
$obj->service = $key;
$obj->ping = $val;
$obj->selected = in_array($key, $module_config->target_services)?true:false;
$services[] = $obj;
}
Context::set('services', $services);

if(!$module_config->site_url)
{
$module_config->site_url = Context::getDefaultUrl()?Context::getDefaultUrl():getFullUrl();
}
Context::set('site_url', preg_replace('/^(http|https):\/\//i','',$module_config->site_url));

if(!$module_config->year)
{
$module_config->year = date("Y");
}

if(!isset($module_config->syndication_password))
{
$module_config->syndication_password = uniqid();
}

Context::set('site_url', preg_replace('/^(http|https):\/\//i','',$module_config->site_url));
Context::set('year', $module_config->year);
Context::set('syndication_token', $module_config->syndication_token);
Context::set('syndication_password', $module_config->syndication_password);


$output = executeQueryArray('syndication.getExceptModules');
$except_module_list = array();
Expand Down
Loading

0 comments on commit 727ba98

Please sign in to comment.