+ add the feature of obtain extensions from community.
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
$config->extension->apiRoot = 'http://www.zentao.net/extension-';
|
||||
@@ -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()
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
.active a {color:blue; font-weight:bold;}
|
||||
.button-c {padding:4px 6px}
|
||||
@@ -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 = '分类浏览';
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -10,18 +10,7 @@
|
||||
* @link http://www.zentao.net
|
||||
*/
|
||||
?>
|
||||
<?php include '../../common/view/header.html.php';?>
|
||||
<?php include '../../common/view/tablesorter.html.php';?>
|
||||
<div id='featurebar'>
|
||||
<?php
|
||||
echo '<span id="installed">' . html::a(inlink('browse', "type=installed"), $lang->extension->installed) . '</span>';
|
||||
echo '<span id="deactivated">'. html::a(inlink('browse', "type=deactivated"), $lang->extension->deactivated) . '</span>';
|
||||
echo '<span id="available">' . html::a(inlink('browse', "type=available"), $lang->extension->available ) . '</span>';
|
||||
echo '<span id="download">' . html::a(inlink('download'), $lang->extension->download) . '</span>';
|
||||
echo '<span id="upload" >' . html::a(inlink('upload'), $lang->extension->upload) . '</span>';
|
||||
?>
|
||||
<script>$('#<?php echo $type;?>').addClass('active')</script>
|
||||
</div>
|
||||
<?php include 'header.html.php';?>
|
||||
<table class='table-1 tablesorter'>
|
||||
<thead>
|
||||
<tr class='colhead'>
|
||||
@@ -29,7 +18,16 @@
|
||||
<th><?php echo $lang->extension->version;?></th>
|
||||
<th><?php echo $lang->extension->author;?></th>
|
||||
<th><?php echo $lang->extension->desc;?></th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr >
|
||||
<td><?php echo $lang->extension->name;?></td>
|
||||
<td><?php echo $lang->extension->version;?></td>
|
||||
<td><?php echo $lang->extension->author;?></td>
|
||||
<td><?php echo $lang->extension->desc;?></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php include '../../common/view/footer.html.php';?>
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php include '../../common/view/header.html.php';?>
|
||||
<?php include '../../common/view/tablesorter.html.php';?>
|
||||
<div id='featurebar'>
|
||||
<?php
|
||||
echo '<span id="installed">' . html::a(inlink('browse', "type=installed"), $lang->extension->installed) . '</span>';
|
||||
echo '<span id="deactivated">'. html::a(inlink('browse', "type=deactivated"), $lang->extension->deactivated) . '</span>';
|
||||
echo '<span id="available">' . html::a(inlink('browse', "type=available"), $lang->extension->available ) . '</span>';
|
||||
echo '<span id="obtain"> ' . html::a(inlink('obtain'), $lang->extension->obtain) . '</span>';
|
||||
echo '<span id="upload" >' . html::a(inlink('upload'), $lang->extension->upload) . '</span>';
|
||||
?>
|
||||
<script>$('#<?php echo $tab;?>').addClass('active')</script>
|
||||
</div>
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* The obtain view file of extension module of ZenTaoPMS.
|
||||
*
|
||||
* @copyright Copyright 2009-2011 QingDao Nature Easy Soft Network Technology Co,LTD (www.cnezsoft.com)
|
||||
* @license LGPL (http://www.gnu.org/licenses/lgpl.html)
|
||||
* @author Chunsheng Wang <chunsheng@cnezsoft.com>
|
||||
* @package extension
|
||||
* @version $Id$
|
||||
* @link http://www.zentao.net
|
||||
*/
|
||||
?>
|
||||
<?php include 'header.html.php';?>
|
||||
<?php include '../../common/view/treeview.html.php';?>
|
||||
<table class='cont-lt1'>
|
||||
<tr valign='top'>
|
||||
<td class='side'>
|
||||
<div class='box-title'><?php echo $lang->extension->obtain;?></div>
|
||||
<div class='box-content a-center'>
|
||||
<?php
|
||||
echo "<span id='bydownloads'>" . html::a(inlink('obtain', 'type=byDownloads'), $lang->extension->byDownloads) . '</span><br />';
|
||||
echo "<span id='byaddedtime'>" . html::a(inlink('obtain', 'type=byAddedTime'), $lang->extension->byAddedTime) . '</span><br />';
|
||||
echo "<span id='byupdatedtime'>" . html::a(inlink('obtain', 'type=byUpdatedTime'), $lang->extension->byUpdatedTime) . '</span><br />';
|
||||
?>
|
||||
</div>
|
||||
<div class='box-title'><?php echo $lang->extension->bySearch;?></div>
|
||||
<div class='box-content a-center'>
|
||||
<form method='post'>
|
||||
<?php
|
||||
echo html::input('key', '', "class='text-1'") . html::submitButton($lang->extension->bySearch);
|
||||
?>
|
||||
</form>
|
||||
</div>
|
||||
<div class='box-title'><?php echo $lang->extension->byCategory;?></div>
|
||||
<div class='box-content' id='tree'>
|
||||
<?php echo $moduleTree;?>
|
||||
</div>
|
||||
</td>
|
||||
<td class='divider'></td>
|
||||
<td>
|
||||
<table class='table-1 tablesorter'>
|
||||
<thead>
|
||||
<tr class='colhead'>
|
||||
<th class='w-id'><?php echo $lang->extension->id;?></th>
|
||||
<th class='w-150px'><?php echo $lang->extension->name;?></th>
|
||||
<th class='w-50px'><?php echo $lang->extension->version;?></th>
|
||||
<th><?php echo $lang->extension->desc;?></th>
|
||||
<th><?php echo $lang->extension->author;?></th>
|
||||
<th class='w-id'><?php echo $lang->extension->downloads;?></th>
|
||||
<th class='w-100px'>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach($extensions as $extension):?>
|
||||
<tr class='a-center'>
|
||||
<td class='strong'><?php echo $extension->id;?></td>
|
||||
<td class='a-left'><?php echo $extension->name;?></td>
|
||||
<td><?php echo $extension->version;?></td>
|
||||
<td class='a-left'><?php echo $extension->desc;?></td>
|
||||
<td><?php echo $extension->author;?></td>
|
||||
<td><?php echo $extension->downloads;?></td>
|
||||
<td>
|
||||
<?php
|
||||
echo html::linkButton($lang->extension->installAB, inlink('install', "extension=$extension->code&downLink=" . helper::safe64Encode($extension->downLink)));
|
||||
echo html::linkButton($lang->extension->downloadAB, $extension->downLink);
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach;?>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr><td class='a-right' colspan='7'><?php if($pager) $pager->show();?></td></tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<script>
|
||||
$('#<?php echo $type;?>').addClass('active')
|
||||
$('#module<?php echo $moduleID;?>').addClass('active')
|
||||
</script>
|
||||
<?php include '../../common/view/footer.html.php';?>
|
||||
Reference in New Issue
Block a user