* Finish task 29162,29163
This commit is contained in:
@@ -2495,6 +2495,90 @@ EOD;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Http response with header.
|
||||
*
|
||||
* @param string $url
|
||||
* @param string|array $data
|
||||
* @param array $options This is option and value pair, like CURLOPT_HEADER => true. Use curl_setopt function to set options.
|
||||
* @param array $headers Set request headers.
|
||||
* @static
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public static function httpWithHeader($url, $data = null, $options = array(), $headers = array())
|
||||
{
|
||||
global $lang, $app;
|
||||
if(!extension_loaded('curl')) return json_encode(array('result' => 'fail', 'message' => $lang->error->noCurlExt));
|
||||
|
||||
commonModel::$requestErrors = array();
|
||||
|
||||
if(!is_array($headers)) $headers = (array)$headers;
|
||||
$headers[] = "API-RemoteIP: " . zget($_SERVER, 'REMOTE_ADDR', '');
|
||||
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
|
||||
curl_setopt($curl, CURLOPT_USERAGENT, 'Sae T OAuth2 v0.1');
|
||||
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
|
||||
curl_setopt($curl, CURLOPT_ENCODING, "");
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||||
curl_setopt($curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||
curl_setopt($curl, CURLOPT_HEADER, true);
|
||||
curl_setopt($curl, CURLINFO_HEADER_OUT, TRUE);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
|
||||
if(!empty($data))
|
||||
{
|
||||
if(is_object($data)) $data = (array) $data;
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
}
|
||||
|
||||
if($options) curl_setopt_array($curl, $options);
|
||||
$response = curl_exec($curl);
|
||||
$errors = curl_error($curl);
|
||||
|
||||
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
|
||||
$headerString = substr($response, 0, $headerSize);
|
||||
$body = substr($response, $headerSize);
|
||||
|
||||
/* Parse header. */
|
||||
$header = explode("\n", $headerString);
|
||||
$newHeader = array();
|
||||
foreach($header as $item)
|
||||
{
|
||||
$field = explode(':', $item);
|
||||
if(count($field) < 2) continue;
|
||||
$headerkey = array_shift($field);
|
||||
$newHeader[$headerkey] = join('', $field);
|
||||
}
|
||||
curl_close($curl);
|
||||
|
||||
|
||||
$logFile = $app->getLogRoot() . 'saas.'. date('Ymd') . '.log.php';
|
||||
if(!file_exists($logFile)) file_put_contents($logFile, '<?php die(); ?' . '>');
|
||||
|
||||
$fh = @fopen($logFile, 'a');
|
||||
if($fh)
|
||||
{
|
||||
fwrite($fh, date('Ymd H:i:s') . ": " . $app->getURI() . "\n");
|
||||
fwrite($fh, "url: " . $url . "\n");
|
||||
if(!empty($data)) fwrite($fh, "data: " . print_r($data, true) . "\n");
|
||||
fwrite($fh, "results:" . print_r($response, true) . "\n");
|
||||
if(!empty($errors)) fwrite($fh, "errors: " . $errors . "\n");
|
||||
fclose($fh);
|
||||
}
|
||||
|
||||
if($errors) commonModel::$requestErrors[] = $errors;
|
||||
|
||||
return array('body' => $body, 'header' => $newHeader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Http.
|
||||
*
|
||||
|
||||
@@ -575,15 +575,27 @@ class gitlab extends control
|
||||
/**
|
||||
* Browse gitlab project.
|
||||
*
|
||||
* @param int $gitlabID
|
||||
* @param int $gitlabID
|
||||
* @param string $keyword
|
||||
* @param int $recTotal
|
||||
* @param int $recPerPage
|
||||
* @param int $pageID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function browseProject($gitlabID)
|
||||
public function browseProject($gitlabID, $keyword = '',$recTotal = 0, $recPerPage = 15, $pageID = 1)
|
||||
{
|
||||
|
||||
$this->app->loadClass('pager', $static = true);
|
||||
$pager = new pager($recTotal, $recPerPage, $pageID);
|
||||
|
||||
$result = $this->gitlab->apiGetProjects($gitlabID, $keyword, $pager);
|
||||
|
||||
$this->view->keyword = $keyword;
|
||||
$this->view->pager = $result['pager'];
|
||||
$this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browseProject;
|
||||
$this->view->gitlabID = $gitlabID;
|
||||
$this->view->gitlabProjectList = $this->gitlab->apiGetProjects($gitlabID);
|
||||
$this->view->gitlabProjectList = $result['projects'];
|
||||
$this->display();
|
||||
}
|
||||
|
||||
|
||||
20
module/gitlab/js/browseproject.js
Normal file
20
module/gitlab/js/browseproject.js
Normal file
@@ -0,0 +1,20 @@
|
||||
$(document).ready(function()
|
||||
{
|
||||
$('#projectSearch').click(function()
|
||||
{
|
||||
triggerSearch();
|
||||
});
|
||||
$('#keyword').keypress(function(event)
|
||||
{
|
||||
if(event.which == 13) triggerSearch();
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
function triggerSearch()
|
||||
{
|
||||
var keyword = $('#keyword').val();
|
||||
vars = vars.replace('%s', keyword);
|
||||
var link = createLink('gitlab', 'browseProject', 'gitlabID=' + gitlabID + '&' + vars);
|
||||
window.location.href = link;
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
$lang->gitlab = new stdclass;
|
||||
$lang->gitlab->common = 'GitLab';
|
||||
$lang->gitlab->browse = 'GitLab Browse';
|
||||
$lang->gitlab->search = 'Search';
|
||||
$lang->gitlab->create = 'Create GitLab';
|
||||
$lang->gitlab->edit = 'Edit GitLab';
|
||||
$lang->gitlab->view = 'View GitLab';
|
||||
@@ -20,6 +21,7 @@ $lang->gitlab->lastUpdate = 'Last Update';
|
||||
$lang->gitlab->confirmAddWebhook = 'Are you sure about creating Webhook?';
|
||||
$lang->gitlab->failCreateWebhook = 'Failed to create Webhook, please view the log';
|
||||
$lang->gitlab->manageProjectMembers = 'Manage project member';
|
||||
$lang->gitlab->placeholderSearch = 'Project name';
|
||||
|
||||
$lang->gitlab->browseAction = 'GitLab List';
|
||||
$lang->gitlab->deleteAction = 'Delete GitLab';
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
$lang->gitlab = new stdclass;
|
||||
$lang->gitlab->common = 'GitLab';
|
||||
$lang->gitlab->browse = '浏览GitLab';
|
||||
$lang->gitlab->search = '搜索';
|
||||
$lang->gitlab->create = '添加GitLab';
|
||||
$lang->gitlab->edit = '编辑GitLab';
|
||||
$lang->gitlab->view = '查看GitLab';
|
||||
@@ -20,6 +21,7 @@ $lang->gitlab->lastUpdate = '最后更新';
|
||||
$lang->gitlab->confirmAddWebhook = '您确定创建Webhook吗?';
|
||||
$lang->gitlab->failCreateWebhook = 'Webhook创建失败,请查看日志';
|
||||
$lang->gitlab->manageProjectMembers = '项目成员管理';
|
||||
$lang->gitlab->placeholderSearch = '请输入项目名称';
|
||||
|
||||
$lang->gitlab->browseAction = 'GitLab列表';
|
||||
$lang->gitlab->deleteAction = '删除GitLab';
|
||||
@@ -143,4 +145,4 @@ $lang->gitlab->group->manageMembers = '群组成员管
|
||||
$lang->gitlab->group->memberName = '账号';
|
||||
$lang->gitlab->group->memberAccessLevel = '角色权限';
|
||||
$lang->gitlab->group->memberExpiresAt = '过期时间';
|
||||
$lang->gitlab->group->repeatError = "群组成员不能重复添加";
|
||||
$lang->gitlab->group->repeatError = "群组成员不能重复添加";
|
||||
|
||||
@@ -572,11 +572,13 @@ class gitlabModel extends model
|
||||
/**
|
||||
* Get projects of one gitlab.
|
||||
*
|
||||
* @param int $gitlabID
|
||||
* @param int $gitlabID
|
||||
* @param string $keyword
|
||||
* @param object $pager
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function apiGetProjects($gitlabID)
|
||||
public function apiGetProjects($gitlabID, $keyword = '', $pager)
|
||||
{
|
||||
$gitlab = $this->getByID($gitlabID);
|
||||
if(!$gitlab) return array();
|
||||
@@ -584,15 +586,14 @@ class gitlabModel extends model
|
||||
$host = rtrim($gitlab->url, '/');
|
||||
$host .= '/api/v4/projects';
|
||||
|
||||
$allResults = array();
|
||||
for($page = 1; true; $page++)
|
||||
{
|
||||
$results = json_decode(commonModel::http($host . "?private_token={$gitlab->token}&simple=true&page={$page}&per_page=100"));
|
||||
if(!empty($results)) $allResults = array_merge($allResults, $results);
|
||||
if(count($results)<100 or $page > 10) break;
|
||||
}
|
||||
$result = commonModel::httpWithHeader($host . "?private_token={$gitlab->token}&simple=true&&per_page={$pager->recPerPage}&order_by=id&page={$pager->pageID}&search={$keyword}");
|
||||
|
||||
return $allResults;
|
||||
$header = $result['header'];
|
||||
$recTotal = $header['X-Total'];
|
||||
$recPerPage = $header['X-Per-Page'];
|
||||
$pager = pager::init($recTotal, $recPerPage, $pager->pageID);
|
||||
|
||||
return array('pager' => $pager, 'projects' => json_decode($result['body']));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,7 +11,18 @@
|
||||
*/
|
||||
?>
|
||||
<?php include '../../common/view/header.html.php';?>
|
||||
<?php js::set('vars', "keyword=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID=1")?>
|
||||
<?php js::set('gitlabID', $gitlabID)?>
|
||||
<div id="mainMenu" class="clearfix">
|
||||
<div id="sidebarHeader">
|
||||
<div class="title">所有模块</div>
|
||||
</div>
|
||||
<div class="btn-toolbar pull-left">
|
||||
<div>
|
||||
<?php echo html::input('keyword', $keyword, "class='form-control' placeholder='{$lang->gitlab->placeholderSearch}' style='display: inline-block;width:auto;margin:0 10px'");?>
|
||||
<a id="projectSearch" class="btn btn-primary"><?php echo $lang->gitlab->search?></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="btn-toolbar pull-right">
|
||||
<?php if(common::hasPriv('gitlab', 'createProject')) common::printLink('gitlab', 'createProject', "gitlabID=$gitlabID", "<i class='icon icon-plus'></i> " . $lang->gitlab->project->create, '', "class='btn btn-primary'");?>
|
||||
</div>
|
||||
@@ -58,6 +69,9 @@
|
||||
<?php endforeach;?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php if($gitlabProjectList):?>
|
||||
<div class='table-footer'><?php $pager->show('right', 'pagerjs');?></div>
|
||||
<?php endif;?>
|
||||
</form>
|
||||
</div>
|
||||
<?php endif;?>
|
||||
|
||||
Reference in New Issue
Block a user