diff --git a/module/extension/config.php b/module/extension/config.php new file mode 100644 index 0000000000..ae6636b0c8 --- /dev/null +++ b/module/extension/config.php @@ -0,0 +1,2 @@ +extension->apiRoot = 'http://www.zentao.net/extension-'; diff --git a/module/extension/control.php b/module/extension/control.php index 89cccd5283..bf471d3a92 100644 --- a/module/extension/control.php +++ b/module/extension/control.php @@ -22,19 +22,60 @@ class extension extends control { $this->view->header->title = $this->lang->extension->browse; $this->view->position[] = $this->lang->extension->browse; + $this->view->tab = $type; $this->display(); } - public function download() + /** + * Obtain an extension from the community. + * + * @param string $type + * @param string $param + * @access public + * @return void + */ + public function obtain($type = 'byDownloads', $param = '', $recTotal = 0, $recPerPage = 10, $pageID = 1) { + /* Init vars. */ + $type = strtolower($type); + $moduleID = $type == 'bymodule' ? (int)$param : 0; + $extensions = array(); + $pager = null; + + /* Get results from the api. */ + $results = $this->extension->getExtensionsByAPI($type, $param, $recTotal, $recPerPage, $pageID); + if($results) + { + $this->app->loadClass('pager', $static = true); + $pager = new pager($results->dbPager->recTotal, $results->dbPager->recPerPage, $results->dbPager->pageID); + $extensions = $results->extensions; + } + + $this->view->moduleTree = $this->extension->getModulesByAPI(); + $this->view->extensions = $extensions; + $this->view->pager = $pager; + $this->view->tab = 'obtain'; + $this->view->type = $type; + $this->view->moduleID = $moduleID; + $this->display(); } - public function upload() + /** + * Install a extension + * + * @param int $downLink + * @access public + * @return void + */ + public function install($extension, $downLink = '') { - } + if($downLink) $this->extension->download($extension, helper::safe64Decode($downLink)); - public function install($extension) - { + $packgeFile = $this->extension->getPackageFile($extension); + if(!file_exists($packgeFile)) die(js::error('not found')); + + $this->extension->install($extension); + echo 'installed'; } public function uninstall() diff --git a/module/extension/css/obtain.css b/module/extension/css/obtain.css new file mode 100644 index 0000000000..a68e3f9d4f --- /dev/null +++ b/module/extension/css/obtain.css @@ -0,0 +1,2 @@ +.active a {color:blue; font-weight:bold;} +.button-c {padding:4px 6px} diff --git a/module/extension/lang/zh-cn.php b/module/extension/lang/zh-cn.php index e418f572ad..671118a862 100644 --- a/module/extension/lang/zh-cn.php +++ b/module/extension/lang/zh-cn.php @@ -12,19 +12,32 @@ $lang->extension->common = '插件管理'; $lang->extension->browse = '浏览插件'; $lang->extension->install = '安装插件'; +$lang->extension->installAB = '安装'; $lang->extension->uninstall = '卸载插件'; $lang->extension->activate = '激活插件'; $lang->extension->deactivate= '禁用插件'; +$lang->extension->obtain = '获得插件'; $lang->extension->download = '下载插件'; +$lang->extension->downloadAB= '下载'; $lang->extension->upload = '上传插件'; $lang->extension->installed = '已安装'; $lang->extension->deactivated = '已禁用'; $lang->extension->available = '可安装'; -$lang->extension->name = '插件名称'; -$lang->extension->version = '插件版本'; -$lang->extension->author = '插件作者'; -$lang->extension->license = '授权协议'; -$lang->extension->desc = '插件描述'; -$lang->extension->site = '官方网站'; +$lang->extension->id = '编号'; +$lang->extension->name = '名称'; +$lang->extension->version = '版本'; +$lang->extension->author = '作者'; +$lang->extension->license = '授权'; +$lang->extension->desc = '描述'; +$lang->extension->site = '官方网站'; +$lang->extension->addedTime = '添加时间'; +$lang->extension->updatedTime = '更新时间'; +$lang->extension->downloads = '下载'; + +$lang->extension->byDownloads = '最多下载'; +$lang->extension->byAddedTime = '最新添加'; +$lang->extension->byUpdatedTime = '最近更新'; +$lang->extension->bySearch = '搜索'; +$lang->extension->byCategory = '分类浏览'; diff --git a/module/extension/model.php b/module/extension/model.php index e3fcf683e6..b338e4b4af 100644 --- a/module/extension/model.php +++ b/module/extension/model.php @@ -11,6 +11,157 @@ */ class extensionModel extends model { + /** + * The api agent(use snoopy). + * + * @var object + * @access public + */ + public $agent; + + /** + * The api root. + * + * @var string + * @access public + */ + public $apiRoot; + + /** + * The construct function. + * + * @access public + * @return void + */ + public function __construct() + { + parent::__construct(); + $this->setAgent(); + $this->setApiRoot(); + } + + /** + * Set the api agent. + * + * @access public + * @return void + */ + public function setAgent() + { + $this->agent = $this->app->loadClass('snoopy'); + } + + /** + * Set the apiRoot. + * + * @access public + * @return void + */ + public function setApiRoot() + { + $this->apiRoot = $this->config->extension->apiRoot; + } + + /** + * Fetch data from an api. + * + * @param string $url + * @access public + * @return mixed + */ + public function fetchAPI($url) + { + $this->agent->fetch($url); + $result = json_decode($this->agent->results); + if(!isset($result->status)) return false; + if($result->status != 'success') return false; + if(isset($result->data) and md5($result->data) != $result->md5) return false; + if(isset($result->data)) return json_decode($result->data); + } + + /** + * Get extension modules from the api. + * + * @access public + * @return void + */ + public function getModulesByAPI() + { + $requestType = $this->config->requestType; + $webRoot = helper::safe64Encode($this->config->webRoot); + $apiURL = $this->apiRoot . 'apiGetmodules-' . $requestType . '-' . $webRoot . '.json'; + $data = $this->fetchAPI($apiURL); + if(isset($data->modules)) return $data->modules; + return false; + } + + /** + * Get extensions by some condition. + * + * @param string $type + * @param mixe d $param + * @access public + * @return void + */ + public function getExtensionsByAPI($type, $param) + { + $apiURL = $this->apiRoot . 'apiGetExtensions-' . $type . '-' . $param . '.json'; + $data = $this->fetchAPI($apiURL); + if(isset($data->extensions)) return $data; + return false; + } + + /** + * Get the full path of the zip file of a extension. + * + * @param string $extension + * @access public + * @return string + */ + public function getPackageFile($extension) + { + return $this->app->getTmpRoot() . 'extension/' . $extension . '.zip'; + } + + /** + * Install an extension. + * + * @param string $extension + * @access public + * @return void + */ + public function install($extension) + { + $packageFile = $this->getPackageFile($extension); + + /* Extract the zip file. */ + $this->app->loadClass('pclzip', true); + $zip = new pclzip($packageFile); + $zip->extract(PCLZIP_OPT_PATH, 'ext'); + + /* Copy to the destination. */ + $this->xcopy("ext/$extension/module", $this->app->getAppRoot() . 'module'); + $this->xcopy("ext/$extension/www", $this->app->getAppRoot() . 'www'); + $this->xcopy("ext/$extension/bin", $this->app->getAppRoot() . 'bin'); + $this->xcopy("ext/$extension/config", $this->app->getAppRoot() . 'config'); + $this->xcopy("ext/$extension/lib", $this->app->getAppRoot() . 'bli'); + } + + /** + * Download an extension. + * + * @param string $extension + * @param string $downLink + * @access public + * @return void + */ + public function download($extension, $downLink) + { + $packageFile = $this->getPackageFile($extension); + $this->agent->fetch($downLink); + file_put_contents($packageFile, $this->agent->results); + } + /** * Copy a directory from an directory to another directory. * diff --git a/module/extension/view/browse.html.php b/module/extension/view/browse.html.php index 2ed245517f..cd3b962368 100644 --- a/module/extension/view/browse.html.php +++ b/module/extension/view/browse.html.php @@ -10,18 +10,7 @@ * @link http://www.zentao.net */ ?> - - -
| extension->version;?> | extension->author;?> | extension->desc;?> | +操作 |
|---|---|---|---|
| extension->name;?> | +extension->version;?> | +extension->author;?> | +extension->desc;?> | +
|
+ extension->obtain;?>
+
+ " . html::a(inlink('obtain', 'type=byDownloads'), $lang->extension->byDownloads) . '
+ '; + echo "" . html::a(inlink('obtain', 'type=byAddedTime'), $lang->extension->byAddedTime) . ' '; + echo "" . html::a(inlink('obtain', 'type=byUpdatedTime'), $lang->extension->byUpdatedTime) . ' '; + ?> + extension->bySearch;?>
+
+
+
+ extension->byCategory;?>
+
+
+
+ |
+ + |
+
|
+ |||||||||||||||||||||