diff --git a/module/admin/control.php b/module/admin/control.php index 2a38dac0ef..97238f0cfe 100755 --- a/module/admin/control.php +++ b/module/admin/control.php @@ -53,23 +53,52 @@ class admin extends control $this->loadModel('misc'); - $hasInternet = $this->admin->checkInternet(); - $clientLang = $this->app->getClientLang(); - $langNotCN = common::checkNotCN(); - $dateUsed = $this->admin->genDateUsed(); + $clientLang = $this->app->getClientLang(); + $langNotCN = common::checkNotCN(); + $dateUsed = $this->admin->genDateUsed(); + + $zentaoData = $this->admin->getZentaoData(); + $hasInternet = $zentaoData->hasData; $this->view->title = $this->lang->admin->common; $this->view->position[] = $this->lang->admin->index; - $this->view->plugins = $this->admin->getExtensionsByAPI('plugin', $langNotCN ? 5 : 6, $hasInternet); - $this->view->patches = $this->admin->getExtensionsByAPI('patch', 5, $hasInternet); + $this->view->plugins = $zentaoData->plugins; + $this->view->patches = $zentaoData->patches; $this->view->dateUsed = $dateUsed; $this->view->hasInternet = $hasInternet; - $this->view->dynamics = ($hasInternet and !$langNotCN) ? $this->admin->getDynamicsByAPI(3) : array(); - $this->view->publicClass = ($hasInternet and !$langNotCN) ? $this->admin->getPublicClassByAPI(3) : array(); + $this->view->dynamics = $zentaoData->news; + $this->view->publicClass = $zentaoData->publicclass; $this->view->langNotCN = $langNotCN; $this->display(); } + /** + * Get zentao.net data by api. + * + * @access public + * @return void + */ + public function ajaxSetZentaoData() + { + $hasInternet = $this->admin->checkInternet(); + + if($hasInternet) + { + $nextWeek = date('Y-m-d', strtotime('-7 days')); + $zentaoData = $this->loadModel('block')->getZentaoData($nextWeek); + + if(empty($zentaoData)) + { + $this->admin->setExtensionsByAPI('plugin', 6); + $this->admin->setExtensionsByAPI('patch', 5); + $this->admin->setDynamicsByAPI(3); + $this->admin->setPublicClassByAPI(3); + } + } + + return $this->send(array('result' => 'success')); + } + /** * Ignore notice of register and bind. * diff --git a/module/admin/js/index.js b/module/admin/js/index.js index f97411945c..fed2be7c68 100644 --- a/module/admin/js/index.js +++ b/module/admin/js/index.js @@ -10,4 +10,6 @@ $(function() { window.open($(this).data('link')); }); + + if(!hasInternet) $.get(createLink('admin', 'ajaxSetZentaoData')); }); diff --git a/module/admin/model.php b/module/admin/model.php index a85a8f49a6..faa37c44d4 100755 --- a/module/admin/model.php +++ b/module/admin/model.php @@ -506,7 +506,7 @@ class adminModel extends model } /** - * Get extensions from zentao.net. + * Set extensions from zentao.net. * * @param string $type plugin|patch * @param int $limit @@ -514,44 +514,22 @@ class adminModel extends model * @access public * @return array */ - public function getExtensionsByAPI($type = 'plugin', $limit = 6, $hasInternet = true) + public function setExtensionsByAPI($type = 'plugin', $limit = 5) { - if($hasInternet) + $searchType = $type == 'plugin' ? 'byModule,offcial' : 'byModule'; + $param = $type == 'plugin' ? '' : 'MTIxOA=='; + $extensions = $this->loadModel('extension')->getExtensionsByAPI($searchType, $param, 0, $limit); + $extensions = isset($extensions->extensions) ? (array)$extensions->extensions : array(); + $plugins = array(); + foreach($extensions as $extension) { - $searchType = $type == 'plugin' ? 'byModule,offcial' : 'byModule'; - $param = $type == 'plugin' ? '' : 'MTIxOA=='; - $extensions = $this->loadModel('extension')->getExtensionsByAPI($searchType, $param, 0, $limit); - $extensions = isset($extensions->extensions) ? (array)$extensions->extensions : array(); - $plugins = array(); - foreach($extensions as $extension) - { - if($type == 'patch' and !isset($extension->compatibleRelease)) continue; + if($type == 'patch' and !isset($extension->compatibleRelease)) continue; - $extension->viewLink = str_replace(array('info', 'client'), '', $extension->viewLink); - $plugins[] = $extension; - } - } - else - { - if($this->config->edition == 'open') - { - $plugins = array( - $this->config->admin->plugins[27], - $this->config->admin->plugins[26], - $this->config->admin->plugins[30] - ); - } - else - { - $plugins = array( - $this->config->admin->plugins[198], - $this->config->admin->plugins[194], - $this->config->admin->plugins[203] - ); - } + $extension->viewLink = str_replace(array('info', 'client'), '', $extension->viewLink); + $plugins[] = $extension; } - return $plugins; + return $this->loadModel('block')->setZentaoData($type, $plugins); } /** @@ -575,13 +553,13 @@ class adminModel extends model } /** - * Get public class from zentao.net. + * Set public class from zentao.net. * * @param int $limit * @access public - * @return array + * @return void */ - public function getPublicClassByAPI($limit = 2) + public function setPublicClassByAPI($limit = 3) { $apiURL = $this->config->admin->videoAPIURL; $data = $this->fetchAPI($apiURL); @@ -599,24 +577,25 @@ class adminModel extends model $publicClass[$index]->viewLink = $this->config->admin->apiRoot . '/publicclass/' . ($course->alias ? "{$course->alias}-" : '') . "{$course->id}.html"; $index ++; } - return $publicClass; + + return $this->loadModel('block')->setZentaoData('publicclass', $publicClass); } /** - * Get dynamics by API. + * Set dynamics by API. * * @param int $limit * @access public - * @return array + * @return void */ - public function getDynamicsByAPI($limit = 2) + public function setDynamicsByAPI($limit = 2) { $apiURL = $this->config->admin->downloadAPIURL; $data = $this->fetchAPI($apiURL); $articles = $data->articles; - $index = 1; - $downloads = array(); + $index = 1; + $news = array(); foreach($articles as $article) { if($index > $limit) break; @@ -625,14 +604,15 @@ class adminModel extends model if(!isset($this->lang->admin->$tagKey)) break; if(!preg_match("/{$this->lang->admin->$tagKey}\d/", $article->title)) continue; - $downloads[$index] = new stdClass(); - $downloads[$index]->id = $article->id; - $downloads[$index]->title = $article->title; - $downloads[$index]->addedDate = $article->addedDate; - $downloads[$index]->link = $this->config->admin->apiRoot . "/download/{$article->alias}-{$article->id}.html"; + $news[$index] = new stdClass(); + $news[$index]->id = $article->id; + $news[$index]->title = $article->title; + $news[$index]->addedDate = $article->addedDate; + $news[$index]->link = $this->config->admin->apiRoot . "/download/{$article->alias}-{$article->id}.html"; $index ++; } - return $downloads; + + return $this->loadModel('block')->setZentaoData('news', $news); } /** @@ -643,11 +623,11 @@ class adminModel extends model */ public function checkInternet() { - $timeoutMS = 400; - $curl = curl_init(); + $timeout = 3; + $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $this->config->admin->apiSite); - curl_setopt($curl, CURLOPT_TIMEOUT_MS, $timeoutMS); - curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, $timeoutMS); + curl_setopt($curl, CURLOPT_TIMEOUT, $timeout); + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); @@ -674,4 +654,58 @@ class adminModel extends model return helper::getDateInterval($firstUseDate); } + + /** + * Get zentao.net data. + * + * @access public + * @return object + */ + public function getZentaoData() + { + $zentaoData = $this->loadModel('block')->getZentaoData(); + + $data = new stdclass(); + $data->hasData = true; + + $news = array(); + $publicclass = array(); + $plugins = array(); + $patches = array(); + if(empty($zentaoData)) + { + $data->hasData = false; + if($this->config->edition == 'open') + { + $plugins = array( + $this->config->admin->plugins[27], + $this->config->admin->plugins[26], + $this->config->admin->plugins[30] + ); + } + else + { + $plugins = array( + $this->config->admin->plugins[198], + $this->config->admin->plugins[194], + $this->config->admin->plugins[203] + ); + } + } + else + { + $news = json_decode($zentaoData['news']); + $publicclass = json_decode($zentaoData['publicclass']); + $plugins = json_decode($zentaoData['plugin']); + $patches = json_decode($zentaoData['patch']); + if(common::checkNotCN()) array_pop($plugins); + } + + $data->news = $news; + $data->publicclass = $publicclass; + $data->plugins = $plugins; + $data->patches = $patches; + + return $data; + } } diff --git a/module/block/model.php b/module/block/model.php index 383315585e..fcb3d99bab 100644 --- a/module/block/model.php +++ b/module/block/model.php @@ -1072,4 +1072,43 @@ class blockModel extends model { return $this->dao->select('count(estimate) as estimate')->from(TABLE_STORY)->where('id')->in($storyID)->fetch('estimate'); } + + /** + * Get zentao.net data. + * + * @param string $minTime + * @access public + * @return array + */ + public function getZentaoData($minTime = '') + { + return $this->dao->select('type,params')->from(TABLE_BLOCK) + ->where('account')->eq('system') + ->andWhere('vision')->eq('rnd') + ->andWhere('module')->eq('zentao') + ->beginIF($minTime)->andWhere('source')->ge($minTime)->fi() + ->andWhere('type')->in('plugin,patch,publicclass,news') + ->fetchPairs('type'); + } + + /** + * Set zentao data. + * + * @param string $type + * @param string $params + * @access public + * @return void + */ + public function setZentaoData($type = 'patch', $params = '') + { + $data = new stdclass(); + $data->account = 'system'; + $data->vision = 'rnd'; + $data->module = 'zentao'; + $data->type = $type; + $data->source = date('Y-m-d'); + $data->params = json_encode($params); + + $this->dao->replace(TABLE_BLOCK)->data($data)->exec(); + } } diff --git a/module/index/js/index.js b/module/index/js/index.js index 86ab05c19c..591c1b3753 100644 --- a/module/index/js/index.js +++ b/module/index/js/index.js @@ -891,6 +891,9 @@ $(function() { $('#globalSearchInput').click(); }); + + /* Update patch, plugin, news, publicclass from zetao.net. */ + if(isAdminUser) $.get(createLink('admin', 'ajaxSetZentaoData')); }); /* Change the search object according to the module and method. */ diff --git a/module/index/view/index.html.php b/module/index/view/index.html.php index be9093fc00..bb74a7d06c 100644 --- a/module/index/view/index.html.php +++ b/module/index/view/index.html.php @@ -21,6 +21,7 @@ js::set('appsMenuItems', commonModel::getMainNavList($app->rawModule)); js::set('defaultOpen', (isset($open) and !empty($open)) ? $open : ''); js::set('manualText', $lang->manual); js::set('manualUrl', ((!empty($config->isINT)) ? $config->manualUrl['int'] : $config->manualUrl['home']) . '&theme=' . $_COOKIE['theme']); +js::set('isAdminUser', $this->app->user->admin); ?>