-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
donwa
committed
Mar 27, 2018
1 parent
e1b54e2
commit 103b9c1
Showing
11 changed files
with
943 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
class admin{ | ||
function install_set(){ | ||
if ($_SERVER['REQUEST_METHOD'] == 'GET') { | ||
return view::load('install_set')->with('client_id',config('client_id')) | ||
->with('client_secret',config('client_secret')) | ||
->with('redirect_uri',config('redirect_uri')); | ||
} | ||
if(empty($_POST['client_id']) || empty($_POST['client_secret']) || empty($_POST['redirect_uri'])){ | ||
return view::load('install_set')->with('error','参数不能为空') | ||
->with('client_id',config('client_id')) | ||
->with('client_secret',config('client_secret')) | ||
->with('redirect_uri',config('redirect_uri')); | ||
} | ||
config('client_id',$_POST['client_id']); | ||
config('client_secret',$_POST['client_secret']); | ||
config('redirect_uri',$_POST['redirect_uri']); | ||
view::direct('?/install/auth'); | ||
} | ||
|
||
function install_auth(){ | ||
$authorize_url = onedrive::authorize_url(); | ||
if ($_SERVER['REQUEST_METHOD'] == 'GET') { | ||
return view::load('install_auth')->with('authorize_url',$authorize_url); | ||
} | ||
|
||
if(empty($_POST['code'])){ | ||
return view::load('install_auth')->with('authorize_url',$authorize_url) | ||
->with('error','参数不能为空'); | ||
} | ||
|
||
list($tmp, $code) = explode("code=",$_POST['code']); | ||
$code = empty($code)?$tmp:$code; | ||
$data = onedrive::authorize($code); | ||
if(empty($data['access_token'])){ | ||
return view::load('install_auth')->with('authorize_url',$authorize_url) | ||
->with('error','认证失败'); | ||
} | ||
|
||
$app_url = onedrive::get_app_url($data['access_token']); | ||
if(empty($app_url)){ | ||
return view::load('install_auth')->with('authorize_url',$authorize_url) | ||
->with('error','获取app url 失败'); | ||
} | ||
|
||
config('refresh_token', $data['refresh_token']); | ||
config('app_url', $app_url); | ||
|
||
view::direct('/'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
class one{ | ||
function index(){ | ||
if(substr($_SERVER['REQUEST_URI'],-1) != '/'){ | ||
return $this->download($_GET['path']); | ||
} | ||
$path = str_replace('//','/', '/'.$_GET['path'].'/'); | ||
$dir = onedrive::dir($path); | ||
view::load('list')->with('path',$path)->with('items', $dir['value'])->show(); | ||
} | ||
|
||
function download($path){ | ||
$item = onedrive::file($path); | ||
$downloadurl = $item["@content.downloadUrl"]; | ||
if(!empty($downloadurl)){ | ||
header('Location: '.$downloadurl); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
require 'init.php'; | ||
define('CONTROLLER_PATH', ROOT . 'controller/'); | ||
|
||
onedrive::$client_id = config('client_id'); | ||
onedrive::$client_secret = config('client_secret'); | ||
onedrive::$redirect_uri = config('redirect_uri'); | ||
onedrive::$app_url = config('app_url'); | ||
|
||
|
||
|
||
if( empty(onedrive::$app_url) ){ | ||
route::any('/install','admin@install_set'); | ||
route::any('/install/auth','admin@install_auth'); | ||
if((route::$runed) == false){ | ||
view::direct('?/install'); | ||
} | ||
} | ||
|
||
//route::get('/downloads/','one@index'); | ||
route::get('{path:#all}','one@index'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
error_reporting(E_ALL & ~E_NOTICE); | ||
date_default_timezone_set('PRC'); | ||
define('TIME', microtime(true)); | ||
define('ROOT', str_replace("\\", "/", dirname(__FILE__)) . '/'); | ||
|
||
//__autoload方法 | ||
function i_autoload($className) { | ||
if (is_int(strripos($className, '..'))) { | ||
return; | ||
} | ||
|
||
$file = ROOT . 'lib/' . $className . '.php'; | ||
if (file_exists($file)) { | ||
include $file; | ||
} | ||
} | ||
spl_autoload_register('i_autoload'); | ||
|
||
/** | ||
* config('name'); | ||
* config('name@file'); | ||
* config('@file'); | ||
*/ | ||
!defined('CONFIG_PATH') && define('CONFIG_PATH', ROOT . 'config/'); | ||
function config($key) { | ||
static $configs = array(); | ||
list($key, $file) = explode('@', $key, 2); | ||
$file = empty($file) ? 'base' : $file; | ||
|
||
$file_name = CONFIG_PATH . $file . '.php'; | ||
//读取配置 | ||
if (empty($configs[$file]) AND file_exists($file_name)) { | ||
$configs[$file] = @include $file_name; | ||
} | ||
|
||
if (func_num_args() === 2) { | ||
$value = func_get_arg(1); | ||
//写入配置 | ||
if (!empty($key)) { | ||
$configs[$file] = (array) $configs[$file]; | ||
if (is_null($value)) { | ||
unset($configs[$file][$key]); | ||
} else { | ||
$configs[$file][$key] = $value; | ||
} | ||
|
||
} else { | ||
if (is_null($value)) { | ||
return unlink($file_name); | ||
} else { | ||
$configs[$file] = $value; | ||
} | ||
|
||
} | ||
file_put_contents($file_name, "<?php return " . var_export($configs[$file], true) . ";", LOCK_EX); | ||
} else { | ||
//返回结果 | ||
if (!empty($key)) { | ||
return $configs[$file][$key]; | ||
} | ||
|
||
return $configs[$file]; | ||
} | ||
} | ||
|
||
/** | ||
* config('name'); | ||
* config('name@file'); | ||
* config('@file'); | ||
*/ | ||
!defined('CACHE_PATH') && define('CACHE_PATH', ROOT . 'cache/'); | ||
function cache($key, $value = null, $time = 86400) { | ||
$file = CACHE_PATH . md5($key) . '.php'; | ||
if (is_null($value)) { | ||
$cache = @include $file; | ||
if ($cache['time'] > TIME) { | ||
return $cache['data']; | ||
} else { | ||
@unlink($file); | ||
} | ||
} else { | ||
file_put_contents($file, "<?php return " . var_export(array('data' => $value, 'time' => TIME + $time), true) . ";", LOCK_EX); | ||
return $value; | ||
} | ||
} | ||
|
||
|
||
if (!function_exists('db')) { | ||
function db($table) { | ||
return db::table($table); | ||
} | ||
} | ||
|
||
if (!function_exists('view')) { | ||
function view($file, $set = null) { | ||
return view::load($file, $set = null); | ||
} | ||
} | ||
|
||
if (!function_exists('_')) { | ||
function _($str) { | ||
return htmlspecialchars($str); | ||
} | ||
} |
Oops, something went wrong.