From fd444dea19d430b89a5024a04a8a04e0069fc1b5 Mon Sep 17 00:00:00 2001 From: zero Date: Tue, 24 Aug 2010 05:01:32 +0000 Subject: [PATCH] git-svn-id: http://xe-core.googlecode.com/svn/sandbox@7642 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- modules/syndication/a | 9 -- .../syndication.admin.controller.php | 93 +++++++++++++++++++ modules/syndication/syndication.class.php | 35 +++++++ .../syndication/syndication.controller.php | 36 ++++++- modules/syndication/syndication.model.php | 42 +++++++-- 5 files changed, 193 insertions(+), 22 deletions(-) delete mode 100644 modules/syndication/a diff --git a/modules/syndication/a b/modules/syndication/a deleted file mode 100644 index 166bf1df0..000000000 --- a/modules/syndication/a +++ /dev/null @@ -1,9 +0,0 @@ -rm -rf ./.svn -rm -rf ./schemas/.svn -rm -rf ./lang/.svn -rm -rf ./tpl/js/.svn -rm -rf ./tpl/filter/.svn -rm -rf ./tpl/.svn -rm -rf ./tpl/css/.svn -rm -rf ./queries/.svn -rm -rf ./conf/.svn diff --git a/modules/syndication/syndication.admin.controller.php b/modules/syndication/syndication.admin.controller.php index 97b8a9bf4..c086d8760 100644 --- a/modules/syndication/syndication.admin.controller.php +++ b/modules/syndication/syndication.admin.controller.php @@ -36,5 +36,98 @@ $this->setMessage('success_applied'); } + + 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'); + + $oModuleModel = &getModel('module'); + + $config = $oModuleModel->getModuleConfig('syndication'); + $site_url = preg_replace('/^(http|https):\/\//i','',$config->site_url); + + $method = 'getSyndicationStatus' . ucfirst(strtolower($target_service)); + if(!method_exists(&$this, $method)) return new Object(-1,'msg_syndication_status_not_support'); + + $output = call_user_func(array(&$this,$method),$site_url); + if(!$output->toBool()) return $output; + + $this->add('result_status',$output->get('result_status')); + } + + 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->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); + } + + 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); + + } + + 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; + } } ?> diff --git a/modules/syndication/syndication.class.php b/modules/syndication/syndication.class.php index f30c45959..c311a9c6e 100644 --- a/modules/syndication/syndication.class.php +++ b/modules/syndication/syndication.class.php @@ -18,19 +18,54 @@ 'Naver' => 'http://syndication.openapi.naver.com/ping/', ); + var $statuses = array( + 'Naver' => 'http://syndication.openapi.naver.com/status/?site=%s', + ); + function moduleInstall() { $oModuleController = &getController('module'); $oModuleController->insertTrigger('document.insertDocument', 'syndication', 'controller', 'triggerInsertDocument', 'after'); $oModuleController->insertTrigger('document.updateDocument', 'syndication', 'controller', 'triggerUpdateDocument', 'after'); $oModuleController->insertTrigger('document.deleteDocument', 'syndication', 'controller', 'triggerDeleteDocument', 'after'); $oModuleController->insertTrigger('module.deleteModule', 'syndication', 'controller', 'triggerDeleteModule', 'after'); + + $oModuleController->insertTrigger('document.moveDocumentToTrash', 'syndication', 'controller', 'triggerMoveDocumentToTrash', 'after'); + $oModuleController->insertTrigger('document.restoreTrash', 'syndication', 'controller', 'triggerRestoreTrash', 'after'); + + $oAddonAdminModel = &getAdminModel('addon'); + if($oAddonAdminModel->getAddonInfoXml('catpcha')){ + $oAddonAdminController = &addonAdminController::getInstance(); + $oAddonAdminController->doActivate('catpcha'); + $oAddonAdminController->makeCacheFile(); + } } function checkUpdate() { + $oModuleModel = &getModel('module'); + if(!$oModuleModel->getTrigger('document.moveDocumentToTrash', 'syndication', 'controller', 'triggerMoveDocumentToTrash', 'after')) return true; + if(!$oModuleModel->getTrigger('document.restoreTrash', 'syndication', 'controller', 'triggerRestoreTrash', 'after')) return true; + return false; } function moduleUpdate() { + $oModuleModel = &getModel('module'); + $oModuleController = &getController('module'); + + if(!$oModuleModel->getTrigger('document.moveDocumentToTrash', 'syndication', 'controller', 'triggerMoveDocumentToTrash', 'after')){ + $oModuleController->insertTrigger('document.moveDocumentToTrash', 'syndication', 'controller', 'triggerMoveDocumentToTrash', 'after'); + } + if(!$oModuleModel->getTrigger('document.restoreTrash', 'syndication', 'controller', 'triggerRestoreTrash', 'after')){ + $oModuleController->insertTrigger('document.restoreTrash', 'syndication', 'controller', 'triggerRestoreTrash', 'after'); + } + + $oAddonAdminModel = &getAdminModel('addon'); + if($oAddonAdminModel->getAddonInfoXml('catpcha')){ + $oAddonAdminController = &addonAdminController::getInstance(); + $oAddonAdminController->doActivate('catpcha'); + $oAddonAdminController->makeCacheFile(); + } + } function recompileCache() { diff --git a/modules/syndication/syndication.controller.php b/modules/syndication/syndication.controller.php index 700822eaf..900429178 100644 --- a/modules/syndication/syndication.controller.php +++ b/modules/syndication/syndication.controller.php @@ -49,8 +49,6 @@ $this->insertLog($obj->module_srl, $obj->document_srl, $obj->title, $obj->content); - $config = $oModuleModel->getModuleConfig('syndication'); - $id = $oSyndicationModel->getID('channel', $obj->module_srl); $this->ping($id, 'deleted'); @@ -68,14 +66,42 @@ $output = executeQuery('syndication.getExceptModule', $obj); if($output->data->count) return new Object(); - $config = $oModuleModel->getModuleConfig('syndication'); - $id = $oSyndicationModel->getID('site', $obj->module_srl); $this->ping($id, 'deleted'); return new Object(); } - + + function triggerMoveDocumentToTrash(&$obj) { + $document_srl = $obj->document_srl; + $module_srl = $obj->module_srl; + + $oSyndicationModel = &getModel('syndication'); + $oModuleModel = &getModel('module'); + + if($oSyndicationModel->isExceptedModules($module_srl)) return new Object(); + + $id = $oSyndicationModel->getID('channel', $module_srl); + $this->ping($id, 'deleted'); + + return new Object(); + } + + function triggerRestoreTrash(&$obj) { + $document_srl = $obj->document_srl; + $module_srl = $obj->module_srl; + + $oSyndicationModel = &getModel('syndication'); + $oModuleModel = &getModel('module'); + + if($oSyndicationModel->isExceptedModules($module_srl)) return new Object(); + + $id = $oSyndicationModel->getID('article', $module_srl.'-'.$document_srl); + $this->ping($id, 'article'); + + return new Object(); + } + function insertLog($module_srl, $document_srl, $title = null, $summary = null) { $args->module_srl = $module_srl; $args->document_srl = $document_srl; diff --git a/modules/syndication/syndication.model.php b/modules/syndication/syndication.model.php index 238941753..e7ca15ebf 100644 --- a/modules/syndication/syndication.model.php +++ b/modules/syndication/syndication.model.php @@ -72,18 +72,21 @@ function getSyndicationList() { $oModuleModel = &getModel('module'); $config = $oModuleModel->getModuleConfig('syndication'); + if(!$config->year || !$config->site_url) return new Object(-1,'msg_check_syndication_config'); $id = Context::get('id'); $type = Context::get('type'); $page = Context::get('page'); if(!$id || !$type) return new Object(-1,'msg_invalid_request'); - preg_match('/^tag:([^,]+),([0-9]+):([^:]+):(.*)$/i',$id,$match); + if(!preg_match('/^tag:([^,]+),([0-9]+):(site|channel|article)(.*)$/i',$id,$matches)) return new Object(-1,'msg_invalid_request'); + + $url = $matches[1]; + $year = $matches[2]; + $target = $matches[3]; + $id = $matches[4]; + if($id && $id{0}==':') $id = substr($id, 1); - $url = $match[1]; - $year = $match[2]; - $target = $match[3]; - $id = $match[4]; if($id && strpos($id,'-')!==false) list($module_srl, $document_srl) = explode('-',$id); elseif($id) $module_srl = $id; if(!$url || !$year || !$target) return new Object(-1,'msg_invalid_request'); @@ -113,7 +116,6 @@ if(!$error) { Context::set('target', $target); Context::set('type', $type); - switch($target) { case 'site' : $site_info->id = $this->getID('site'); @@ -174,14 +176,19 @@ break; } break; + + case 'article': + Context::set('article', $this->getArticle($document_srl)); + $this->setTemplateFile('include.articles'); + break; } } else { Context::set('message', $error); $this->setTemplateFile('error'); } - Context::setResponseMethod('XML'); $this->setTemplatePath($this->module_path.'tpl'); + Context::setResponseMethod('XMLRPC'); } function getChannels() { @@ -213,6 +220,25 @@ return $list; } + function getArticle($document_srl) { + if($this->site_url==null) $this->init(); + + $oDocumentModel = &getModel('document'); + $oDocument = $oDocumentModel->getDocument($document_srl,false,false); + if(!$oDocument->isExists()) return; + + $val = $oDocument->getObjectVars(); + + $val->id = $this->getID('article', $val->module_srl.'-'.$val->document_srl); + $val->updated = date("Y-m-d\\TH:i:s", ztime($val->last_update)).$GLOBALS['_time_zone']; + $val->alternative_href = getFullSiteUrl($this->site_url, '', 'document_srl', $val->document_srl); + $val->channel_alternative_href = $this->getChannelAlternativeHref($val->module_srl); + $val->channel_id = $this->getID('channel', $val->module_srl.'-'.$val->document_srl); + if(!$val->nick_name) $val->nick_name = $val->user_name; + + return $val; + } + function getArticles($module_srl = null, $page=1, $startTime = null, $endTime = null, $type = null, $id = null) { if($this->site_url==null) $this->init(); @@ -289,7 +315,7 @@ function getID($type, $target_id = null) { if($this->site_url==null) $this->init(); - return sprintf('tag:%s,%d:%s:%s', $this->site_url, $this->year, $type, $target_id); + return sprintf('tag:%s,%d:%s', $this->site_url, $this->year, $type) . ($target_id?':'.$target_id:''); } function getChannelAlternativeHref($module_srl) {