Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
WangNingkai committed Sep 29, 2018
0 parents commit d37f364
Show file tree
Hide file tree
Showing 112 changed files with 13,572 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_size = 2
47 changes: 47 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

GRAPH_CLIENT_ID=
GRAPH_CLIENT_SECRET=
GRAPH_REDIRECT_URI=
GRAPH_AUTHORITY_URL=https://login.microsoftonline.com/common
GRAPH_AUTHORIZE_ENDPOINT=/oauth2/v2.0/authorize
GRAPH_TOKEN_ENDPOINT=/oauth2/v2.0/token
GRAPH_SCOPES="openid profile user.read files.readwrite.all offline_access"
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* text=auto
*.css linguist-vendored
*.scss linguist-vendored
*.js linguist-vendored
CHANGELOG.md export-ignore
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/node_modules
/public/hot
/public/storage
/storage/*.key
/vendor
/.idea
/.vscode
/.vagrant
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
.env
.phpunit.result.cache
46 changes: 46 additions & 0 deletions app/Console/Commands/ResetPassword.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;

class ResetPassword extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'reset:password';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Reset Password';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
*/
public function handle()
{
$password = str_random(8);
DB::table('parameters')->where('name','password')->update(['value' => $password]);
Artisan::call('cache:clear');
$this->info('重置密码成功,新密码:'.$password);
}
}
42 changes: 42 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
];

/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly();
}

/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');

require base_path('routes/console.php');
}
}
51 changes: 51 additions & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];

/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];

/**
* Report or log an exception.
*
* @param \Exception $exception
* @return void
*/
public function report(Exception $exception)
{
parent::report($exception);
}

/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
return parent::render($request, $exception);
}
}
167 changes: 167 additions & 0 deletions app/Helpers/Tool.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?php

namespace App\Helpers;

use App\Models\Parameter;
use HyperDown\Parser;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Session;

class Tool
{
/**
* 操作成功或者失败的提示
* @param string $message
* @param bool $success
*/
public static function showMessage($message = '成功', $success = true)
{
$alertType = $success ? 'success' : 'danger';
Session::put('alertMessage', $message);
Session::put('alertType', $alertType);
}

/**
*文件大小转换
* @param string $size 原始大小
* @return string 转换大小
*/
public static function convertSize($size)
{
$units = array(' B', ' KB', ' MB', ' GB', ' TB');
for ($i = 0; $size >= 1024 && $i < 4; $i++) $size /= 1024;
return @round($size, 2).$units[$i];
}

/**
* 获取包屑导航栏路径
* @param $key
* @param $pathArr
* @return string
*/
public static function getUrl($key,$pathArr)
{
$pathArr = array_slice($pathArr,0,$key);
$url= '';
foreach ($pathArr as $param) {
$url .= '-'.$param;
}
return trim($url,'-');
}

/**
* 获取上一级 Url
* @param $pathArr
* @return string
*/
public static function getParentUrl($pathArr)
{
array_pop($pathArr);
if (count($pathArr) == 0)
{
return '';
}
$url= '';
foreach ($pathArr as $param) {
$url .= '-'.$param;
}
return trim($url,'-');
}

/**
* 字符串截取,支持中文和其他编码
*
* @param string $str 需要转换的字符串
* @param integer $start 开始位置
* @param string $length 截取长度
* @param boolean $suffix 截断显示字符
* @param string $charset 编码格式
* @return string
*/
public static function subStr($str, $start, $length, $suffix = true, $charset = "utf-8")
{
$slice = mb_substr($str, $start, $length, $charset);
$omit = mb_strlen($str) >= $length ? '...' : '';
return $suffix ? $slice . $omit : $slice;
}

/**
* markdown 转 html
*
* @param string $markdown
* @return array
*/
public static function markdown2Html($markdown)
{
preg_match_all('/&lt;iframe.*iframe&gt;/', $markdown, $iframe);
// 如果有 i_frame 则先替换为临时字符串
if (!empty($iframe[0])) {
$tmp = [];
// 组合临时字符串
foreach ($iframe[0] as $k => $v) {
$tmp[] = '【iframe' . $k . '';
}
// 替换临时字符串
$markdown = str_replace($iframe[0], $tmp, $markdown);
// 转义 i_frame
$replace = array_map(function ($v) {
return htmlspecialchars_decode($v);
}, $iframe[0]);
}
// markdown转html
$parser = new Parser();
$html = $parser->makeHtml($markdown);
$html = str_replace('<code class="', '<code class="lang-', $html);
// 将临时字符串替换为 i_frame
if (!empty($iframe[0])) {
$html = str_replace($tmp, $replace, $html);
}
return $html;
}

/**
* 读取配置
* @param string $key
* @param string $default
* @return mixed|string
*/
public static function config($key = '',$default = '')
{
// 读取配置缓存
$config = Cache::remember('config', 1440, function () {
return Parameter::query()->pluck('value', 'name')->toArray();
});
return $key ? ($config[$key] ?: $default) : $config;
}

/**
* 获取文件图片
* @param $ext
* @return string
*/
public static function getExtIcon($ext)
{
$patterns = [
'stream'=>['fa-file-text-o',['txt','log']],
'image' => ['fa-file-image-o',['bmp','jpg','jpeg','png','gif']],
'video' => ['fa-file-video-o',['mkv','mp4']],
'audio' => ['fa-file-audio-o',['mp3']],
'code' => ['fa-file-code-o',['html','htm', 'css', 'go','java','js','json','txt','sh','md']],
'doc' => ['fa-file-word-o',['csv','doc','docx','odp','ods','odt','pot','potm','potx','pps','ppsx','ppsxm','ppt','pptm','pptx','rtf','xls','xlsx']],
'pdf' => ['fa-file-pdf-o',['pdf']],
'zip' => ['fa-file-archive-o',['zip','7z','rar','bz','gz']],
'android' => ['fa-android',['apk']],
'exe' => ['fa-windows',['exe','msi']],
];
$icon = '';
foreach ($patterns as $key => $suffix) {
if(in_array($ext,$suffix[1])){
$icon = $patterns[$key][0];
break;
} else {
$icon = 'fa-file-text-o';
}
}
return $icon;
}
}
Loading

0 comments on commit d37f364

Please sign in to comment.