Skip to content

Commit

Permalink
Merge pull request #1 from gongwalker/master
Browse files Browse the repository at this point in the history
merge
  • Loading branch information
sailoryoung committed Aug 19, 2015
2 parents 494fd5f + 1c00df5 commit 6e98341
Show file tree
Hide file tree
Showing 11 changed files with 262 additions and 62 deletions.
8 changes: 6 additions & 2 deletions MinPHP/core/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
'session'=>array(
'prefix' => 'api_',
),
//cookie配置
'cookie' => array(
'navbar' => 'API_NAVBAR_STATUS',
),
//版本信息
'version'=>array(
'no' => 'v1.0', //版本号
'time' => '2015-07-06 18:24', //版本时间
'no' => 'v1.1', //版本号
'time' => '2015-08-19 00:40', //版本时间
)

);
55 changes: 22 additions & 33 deletions MinPHP/core/function.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,43 +132,32 @@ function I($val){

//网站基础路径baseUrl
function baseUrl(){
$currentPath = $_SERVER['PHP_SELF'];
$currentPath = $_SERVER['SCRIPT_NAME'];
$pathInfo = pathinfo($currentPath);
$hostName = $_SERVER['HTTP_HOST'];
$protocol = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,5))=='https://' ? 'https://' : 'http://';
return $protocol.$hostName.$pathInfo['dirname']."/";
}

//下载html
function downfile($fileName){
$fileName = '路径+实际文件名';
//文件的类型
header('Content-type: application/pdf');
//下载显示的名字
header('Content-Disposition: attachment; filename="保存时的文件名.pdf"');
readfile("$fileName");
exit();
/**
* @dec 下载文件 指定了content参数,下载该参数的内容
* @access public
* @param string $showname 下载显示的文件名
* @param string $content 下载的内容
* @param integer $expire 下载内容浏览器缓存时间
* @return void
*/
function download($showname='',$content='',$expire=180) {
$type = "application/octet-stream";
//发送Http Header信息 开始下载
header("Pragma: public");
header("Cache-control: max-age=".$expire);
//header('Cache-Control: no-store, no-cache, must-revalidate');
header("Expires: " . gmdate("D, d M Y H:i:s",time()+$expire) . "GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s",time()) . "GMT");
header("Content-Disposition: attachment; filename=".$showname);
header("Content-type: ".$type);
header('Content-Encoding: none');
header("Content-Transfer-Encoding: binary" );
die($content);
}

/**
* @dec 下载文件 指定了content参数,下载该参数的内容
* @access public
* @param string $showname 下载显示的文件名
* @param string $content 下载的内容
* @param integer $expire 下载内容浏览器缓存时间
* @return void
*/
function download($showname='',$content='',$expire=180) {
$type = "application/octet-stream";
//发送Http Header信息 开始下载
header("Pragma: public");
header("Cache-control: max-age=".$expire);
//header('Cache-Control: no-store, no-cache, must-revalidate');
header("Expires: " . gmdate("D, d M Y H:i:s",time()+$expire) . "GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s",time()) . "GMT");
header("Content-Disposition: attachment; filename=".$showname);
header("Content-type: ".$type);
header('Content-Encoding: none');
header("Content-Transfer-Encoding: binary" );
die($content);
}
117 changes: 117 additions & 0 deletions MinPHP/res/jquery.cookie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*!
* jQuery Cookie Plugin v1.4.1
* https://github.com/carhartl/jquery-cookie
*
* Copyright 2013 Klaus Hartl
* Released under the MIT license
*/
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// CommonJS
factory(require('jquery'));
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {

var pluses = /\+/g;

function encode(s) {
return config.raw ? s : encodeURIComponent(s);
}

function decode(s) {
return config.raw ? s : decodeURIComponent(s);
}

function stringifyCookieValue(value) {
return encode(config.json ? JSON.stringify(value) : String(value));
}

function parseCookieValue(s) {
if (s.indexOf('"') === 0) {
// This is a quoted cookie as according to RFC2068, unescape...
s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
}

try {
// Replace server-side written pluses with spaces.
// If we can't decode the cookie, ignore it, it's unusable.
// If we can't parse the cookie, ignore it, it's unusable.
s = decodeURIComponent(s.replace(pluses, ' '));
return config.json ? JSON.parse(s) : s;
} catch(e) {}
}

function read(s, converter) {
var value = config.raw ? s : parseCookieValue(s);
return $.isFunction(converter) ? converter(value) : value;
}

var config = $.cookie = function (key, value, options) {

// Write

if (value !== undefined && !$.isFunction(value)) {
options = $.extend({}, config.defaults, options);

if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setTime(+t + days * 864e+5);
}

return (document.cookie = [
encode(key), '=', stringifyCookieValue(value),
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
options.path ? '; path=' + options.path : '',
options.domain ? '; domain=' + options.domain : '',
options.secure ? '; secure' : ''
].join(''));
}

// Read

var result = key ? undefined : {};

// To prevent the for loop in the first place assign an empty array
// in case there are no cookies at all. Also prevents odd result when
// calling $.cookie().
var cookies = document.cookie ? document.cookie.split('; ') : [];

for (var i = 0, l = cookies.length; i < l; i++) {
var parts = cookies[i].split('=');
var name = decode(parts.shift());
var cookie = parts.join('=');

if (key && key === name) {
// If second argument (value) is a function it's a converter...
result = read(cookie, value);
break;
}

// Prevent storing a cookie that we couldn't decode.
if (!key && (cookie = read(cookie)) !== undefined) {
result[name] = cookie;
}
}

return result;
};

config.defaults = {};

$.removeCookie = function (key, options) {
if ($.cookie(key) === undefined) {
return false;
}

// Must not alter options, thus extending a fresh object...
$.cookie(key, '', $.extend({}, options, { expires: -1 }));
return !$.cookie(key);
};

}));
39 changes: 30 additions & 9 deletions MinPHP/run/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,35 @@
$filename = $filename['cname'].$version.'.html';
//要抓取的接口分类url
$url = BASEURL.U(array('act'=>'api','tag'=>$tag));
//分类详情页的内容
$content = file_get_contents($url);
// 如果file_get_contents函数不能用就用curl方式获取
function file_get_contents_fixed($url)
{

switch (true) {
case function_exists('file_get_contents'):
$res = file_get_contents($url);
break;
case function_exists('curl_init'):
$ch = curl_init();
$timeout = 10; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL,$url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$res = curl_exec($ch);
break;
default :
exit('导出不可用,请确保可用file_get_contents函数或CURL扩展,');
}
return $res;
}
//分类详情页的内容
$content = file_get_contents_fixed($url);
//========js与css静态文件替换start=======================================
//css文件替换--start
$pattern = '/<link href="(.+?\.css)" rel="stylesheet">/is';
function getCssFileContent($matches){
$filepath = BASEURL.ltrim($matches[1],'./');
$content = file_get_contents($filepath);
$content = file_get_contents_fixed($filepath);
return "<style>".$content."</style>";
}
$content = preg_replace_callback($pattern,'getCssFileContent',$content);
Expand All @@ -28,26 +48,27 @@ function getCssFileContent($matches){
$pattern = '/<script src="(.+?\.js)"><\/script>/is';
function getJSFileContent($matches){
$filepath = BASEURL.ltrim($matches[1],'./');
$content = file_get_contents($filepath);
$content = file_get_contents_fixed($filepath);
return "<script>".$content."</script>";
}
$content = preg_replace_callback($pattern,'getJSFileContent',$content);
//js文件替换--end
//========js与css静态文件替换end=======================================

//=======页面锚点连接替换start=======================================
$pattern = '/<a href=".+?act=api&tag=\d#(\w+).+?">(.+?)<\/a>/is';
//=======页面锚点连接替换start=========================================
$pattern = '/href=".+?tag=\d#(\w+)"/i';
function changeLink($matches){
return "<a href='#{$matches[1]}'>$matches[2]</a>";
return "href=#{$matches[1]}";
}
$content = preg_replace_callback($pattern,'changeLink',$content);
//=======页面锚点连接替换end=========================================
$tag = C('version->no');
$headhtml=<<<START
<!--
=======================================================================
导出时间:{$version}
=======================================================================
此文档由API Manager 导出
此文档由API Manager {$tag} 导出
=======================================================================
github : https://github.com/gongwalker/ApiManager.git
=======================================================================
Expand All @@ -66,4 +87,4 @@ function changeLink($matches){
END;
$content=$headhtml.$content.$appendhtml;
download($filename,$content);
exit;
exit;
11 changes: 10 additions & 1 deletion MinPHP/run/hello.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
<!--欢迎页-->
<!--info start-->
<div style="font-size:18px;">
<span style="font-size:26px;" class="glyphicon glyphicon-grain" aria-hidden="true"></span> 欢迎使用接口管理工具 <?php echo C('version->no').'';?>
<div class="info" style="font-size:14px;">
<span style="font-size:30px;" class="glyphicon glyphicon-grain" aria-hidden="true"></span> <span style="font-size:16px;">欢迎使用接口管理工具 <?php echo C('version->no').'';?></span><br>
<pre class="info" style="margin:10px 34px 10px 34px">
什么是接口文档管理工具?
&nbsp;&nbsp;&nbsp;&nbsp;是一个在线API文档系统;其致力于快速解决团队内部接口文档的编写、维护、存档,和减少团队协作开发的沟通成本。
</pre>
</div>
<div style="font-size:12px;position:absolute;bottom:0;right:20px;height:20px;text-align:right;">
路人庚 | qq : 309581329 | github : <a target="_blank" href="https://github.com/gongwalker/ApiManager.git">https://github.com/gongwalker/ApiManager.git</a>
</div>
</div>
<!--欢迎页 end-->
37 changes: 30 additions & 7 deletions MinPHP/run/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,19 +302,21 @@ function del(obj){
<script>
function add(){
var $html ='<tr>' +
'<td class="form-group has-error" ><input type="text" class="form-control has-error" name="p[name][]" placeholder="参数名" required="required"></td>' +
'<td class="form-group has-error" >' +
'<input type="text" class="form-control has-error" name="p[name][]" placeholder="参数名" required="required"></td>' +
'<td>' +
'<select class="form-control" name="p[type][]">' +
'<option value="Y">Y</option> <option value="N">N</option>' +
'</select >' +
'<select class="form-control" name="p[type][]">' +
'<option value="Y">Y</option> <option value="N">N</option>' +
'</select >' +
'</td>' +
'<td>' +
'<input type="text" class="form-control" name="p[default][]" placeholder="缺省值"></td>' +
'<input type="text" class="form-control" name="p[default][]" placeholder="缺省值">' +
'</td>' +
'<td>' +
'<textarea name="p[des][]" rows="1" class="form-control" placeholder="描述"></textarea>' +
'<textarea name="p[des][]" rows="1" class="form-control" placeholder="描述"></textarea>' +
'</td>' +
'<td>' +
'<button type="button" class="btn btn-danger" onclick="del(this)">删除</button>' +
'<button type="button" class="btn btn-danger" onclick="del(this)">删除</button>' +
'</td>' +
'</tr >';
$('#parameter').append($html);
Expand Down Expand Up @@ -398,6 +400,11 @@ function del(obj){
<?php } ?>
</div>
<!--接口详细列表end-->
<!--接口详情返回顶部按钮start-->
<div id="gotop" onclick="goTop()" style="z-index:999999;font-size:18px;display:none;color:#e6e6e6;cursor:pointer;width:42px;height:42px;border:#ddd 1px solid;line-height:42px;text-align:center;background:rgba(91,192,222, 0.8);position:fixed;right:20px;bottom:200px;border-radius:50%;box-shadow: 0px 0px 0px 1px #cccccc;">
T
</div>
<!--接口详情返回顶部按钮end-->
<?php } ?>
<?php } else{ ?>
<div style="font-size:16px;">
Expand All @@ -421,6 +428,22 @@ function deleteApi(apiId,divId){
function editApi(gourl){
window.location.href=gourl;
}

//返回顶部
function goTop(){
$('#mainwindow').animate(
{ scrollTop: '0px' }, 200
);
}

//检测滚动条,显示返回顶部按钮
document.getElementById('mainwindow').onscroll = function () {
if(document.getElementById('mainwindow').scrollTop > 100){
document.getElementById('gotop').style.display='block';
}else{
document.getElementById('gotop').style.display='none';
}
};
</script>
<?php } ?>
<!--接口详情列表与接口管理end-->
5 changes: 3 additions & 2 deletions MinPHP/run/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<div class="container-fluid" style="background:white;height:100%;">
<div class="row" style="height:100%;">
<!--左侧导航start-->
<div class="col-md-3" style="position:relative;background:#f5f5f5;padding:10px;height:100%;border-right:#ddd 1px solid;overflow-y:auto">
<div id="navbar" class="col-md-3" style="position:relative;background:#f5f5f5;padding:10px;height:100%;border-right:#ddd 1px solid;overflow-y:auto;<?php if($_COOKIE[C('cookie->navbar')]==1){?>display:none<?php }?>">
<div style="height:50px;font-size:30px;line-height:50px;">
<a class="home" style="color:#000000;text-shadow:1px 0px 1px #666;text-decoration: none" href="<?php echo U()?>">
<span class="glyphicon glyphicon-random" aria-hidden="true" style="width:40px;"></span>&nbsp;
Expand All @@ -31,7 +31,7 @@
?>
</div>
<!--左侧导航end-->
<div class="col-md-9" style="height:100%;background:white;margin:0px;overflow-y:auto;padding:0px;">
<div id="mainwindow" <?php if($_COOKIE[C('cookie->navbar')]==1){?>class="col-md-12"<?php }else{?>class="col-md-9" <?php }?> style="height:100%;background:white;margin:0px;overflow-y:auto;padding:0px;">
<!--顶部导航start-->
<div class="textshadow" style="font-size:16px;widht:100%;height:60px;line-height:60px;padding:0 16px 0 16px;;border-bottom:#ddd 1px solid">
<span> <a class="home" href="<?php echo U() ?>">Home</a><?php echo $menu;?></span>
Expand Down Expand Up @@ -64,6 +64,7 @@
</div>
</div>
<script src="./MinPHP/res/jquery.min.js"></script>
<script src="./MinPHP/res/jquery.cookie.js"></script>
<script src="./MinPHP/res/bootstrap-3.3.4-dist/js/bootstrap.min.js"></script>
</body>
</html>
Loading

0 comments on commit 6e98341

Please sign in to comment.