123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- <?php
- // +----------------------------------------------------------------------
- // | 应用公共文件
- // +----------------------------------------------------------------------
- // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | Author:
- // +----------------------------------------------------------------------
- use \think\facade\Db;
- error_reporting(0);
- /**
- * @return mixed
- * 获取站点信息
- */
- if (!function_exists('site_name')) {
- function site_name()
- {
- return Db::name('config')->where('code', 'site_name')
- ->value('value');
- }
- }
- if (!function_exists('site_logo')) {
- function site_logo()
- {
- return Db::name('config')->where('code', 'site_logo')
- ->value('value');
- }
- }
- //获取配置信息
- if (!function_exists('getConfigByCode')) {
- function getConfigByCode($code)
- {
- return Db::name('config')->where('code', $code)
- ->value('value');
- }
- }
- /*
- * 百度编辑器内容 多个编辑器单独引入js,重复会导致出错
- */
- if (!function_exists('build_ueditor_js')) {
- function build_ueditor_js(){
- /* 配置界面语言 */
- switch (config('default_lang')) {
- case 'zh-cn':
- $lang = '/static/plugins/ueditor/lang/zh-cn/zh-cn.js';
- break;
- case 'en-us':
- $lang = '/static/plugins/ueditor/lang/en/en.js';
- break;
- default:
- $lang = '/static/plugins/ueditor/lang/zh-cn/zh-cn.js';
- break;
- }
- return $include_js = '<script type="text/javascript" charset="utf-8" src="/static/plugins/ueditor/ueditor.config.js"></script> <script type="text/javascript" charset="utf-8" src="/static/plugins/ueditor/ueditor.all.min.js""> </script><script type="text/javascript" charset="utf-8" src="' . $lang . '"></script>';
- }
- }
- if (!function_exists('build_ueditor')) {
- function build_ueditor($params = array())
- {
- $name = isset($params['name']) ? $params['name'] : null;
- $theme = isset($params['theme']) ? $params['theme'] : 'normal';
- $content = isset($params['content']) ? $params['content'] : null;
- //http://fex.baidu.com/ueditor/#start-toolbar
- /* 指定使用哪种主题 */
- $themes = array(
- 'normal' => "[
- 'fullscreen', 'source', '|', 'undo', 'redo', '|',
- 'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
- 'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
- 'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
- 'directionalityltr', 'directionalityrtl', 'indent', '|',
- 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
- 'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
- 'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe', 'insertcode', 'webapp', 'pagebreak', 'template', 'background', '|',
- 'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
- 'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
- 'print', 'preview', 'searchreplace', 'drafts', 'help'
- ]", 'simple' => " ['fullscreen', 'source', 'undo', 'redo', 'bold']",
- );
- switch ($theme) {
- case 'simple':
- $theme_config = $themes['simple'];
- break;
- case 'normal':
- $theme_config = $themes['normal'];
- break;
- default:
- $theme_config = $themes['normal'];
- break;
- }
- if(!isset($params['type']) || (isset($params['type']) && $params['type']==0) ){
- $include_js = build_ueditor_js();
- }elseif($params['type']==1 ){
- $include_js = '';
- }
- $content = json_encode($content);
- $str = <<<EOT
- $include_js
- <script type="text/javascript">
- var ue_{$name} = UE.getEditor('{$name}',{
- toolbars:[{$theme_config}],
- });
- if($content){
- ue_{$name}.ready(function() {
- this.setContent($content);
- })
- }
-
- </script>
- EOT;
- return $str;
- }
- }
- if (!function_exists('p')) {
- function p($var, $die = 0) {
- print_r($var);
- $die && die();
- }
- }
- if (!function_exists('isMobile')) {
- function isMobile()
- {
- if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])) {
- return true;
- }
- if (isset ($_SERVER['HTTP_VIA'])) {
- return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
- }
- if (isset ($_SERVER['HTTP_USER_AGENT'])) {
- $clientkeywords = array('nokia',
- 'sony',
- 'ericsson',
- 'mot',
- 'samsung',
- 'htc',
- 'sgh',
- 'lg',
- 'sharp',
- 'sie-',
- 'philips',
- 'panasonic',
- 'alcatel',
- 'lenovo',
- 'iphone',
- 'ipod',
- 'blackberry',
- 'meizu',
- 'android',
- 'netfront',
- 'symbian',
- 'ucweb',
- 'windowsce',
- 'palm',
- 'operamini',
- 'operamobi',
- 'openwave',
- 'nexusone',
- 'cldc',
- 'midp',
- 'wap',
- 'mobile'
- );
- if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
- return true;
- }
- }
- if (isset ($_SERVER['HTTP_ACCEPT'])) {
- if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {
- return true;
- }
- }
- return false;
- }
- }
- if (!function_exists("json_result")){
- /** 返回接送 接口
- * @param int $code
- * @param string $msg
- * @param $data
- */
- function json_result($code=200,$msg="",$data=""){
- $dat["code"]=$code;
- $dat["msg"]=$msg;
- $dat["data"]=$data;
- $json=json_encode($dat);
- echo $json;exit();
- }
- }
- /**
- * 生成操作按钮
- * @param array $operate 操作按钮数组
- */
- if (!function_exists("showOperate")){
- function showOperate($operate = [])
- {
- if(empty($operate)){
- return '';
- }
- $option = <<<EOT
- <div class="btn-group">
- <button class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
- 操作 <span class="caret"></span>
- </button>
- <ul class="dropdown-menu">
- EOT;
- foreach($operate as $key=>$vo){
- $option .= '<li><a href="'.$vo.'">'.$key.'</a></li>';
- }
- $option .= '</ul></div>';
- return $option;
- }
- }
- if (!function_exists("time2string")){
- function time2string($second){
- $day = floor($second/(3600*24));
- $second = $second%(3600*24);//除去整天之后剩余的时间
- $hour = floor($second/3600);
- $second = $second%3600;//除去整小时之后剩余的时间
- $minute = floor($second/60);
- $second = $second%60;//除去整分钟之后剩余的时间
- //返回字符串
- return $day.'天'.$hour.'小时';
- }
- }
- if (!function_exists("is_admin")){
- function is_admin(){
- $session= \think\facade\Session::get("admin");
- $admin=$session->toArray();
- if ($admin["project"]){
- return $admin["project"];
- }else{
- return false;
- }
- }
- }
- // 成绩转换 成数字
- if (!function_exists("achievement_switch")){
- function achievement_switch($name){
- $age=0;
- switch ($name){
- case "A":$age=4;break;
- case "a":$age=4;break;
- case "B":$age=3;break;
- case "b":$age=3;break;
- case "C":$age=2;break;
- case "c":$age=2;break;
- case "D":$age=1;break;
- case "d":$age=1;break;
- case "F":$age=0;break;
- case "f":$age=0;break;
- }
- return $age;
- }
- }
- // 成绩转换成 单词
- if (!function_exists("achievement_change")){
- function achievement_change($name){
- $age="F";
- switch ($name){
- case 4: $age="A";break;
- case 3: $age="B";break;
- case 2: $age="C";break;
- case 1: $age="D";break;
- case 0: $age="F";break;
- case -1: $age="录入中";break;
- }
- return $age;
- }
- }
- // 等级换算
- if (!function_exists("star_deng")){
- function star_deng($name){
- $age="初出茅庐";
- switch ($name){
- case 0: $age="初出茅庐";break;
- case 1: $age="心令神会";break;
- case 2: $age="出类拔萃";break;
- case 3: $age="名列前茅";break;
- case 4: $age="百里挑一";break;
- }
- return $age;
- }
- }
- // 升星标准
- if (!function_exists("star_class")){
- function star_class($name){
- $age=0;
- if ($name>=3.4){
- $age=5;
- }elseif ($name>=2.8&&$name<3.4){
- $age=4;
- }elseif ($name>=2.2&&$name<2.8){
- $age=3;
- }elseif ($name>=1.6&&$name<2.2){
- $age=2;
- }elseif ($name>=1&&$name<1.5){
- $age=1;
- }
- return $age;
- }
- }
- // 专业等级
- if (!function_exists("major_levels")){
- function major_levels($num,$subject_id){
- $where[]=["max",">=",$num];
- $where[]=["subject_id","=",$subject_id];
- $type=Db::name("major_level")->order("type asc")->where($where)->find();
- if (!$type){
- if ($num>0){
- return 4;
- }else{
- return 0;
- }
- }
- return $type["type"];
- }
- }
- function sortArr($arrays,$sort_key,$sort_order=SORT_ASC,$sort_type=SORT_NUMERIC ){
- $key_arrays =array();
- if(is_array($arrays)){
- foreach ($arrays as $array){
- if(is_array($array)){
- $key_arrays[] = $array[$sort_key];
- }else{
- return false;
- }
- }
- }else{
- return false;
- }
- array_multisort($key_arrays,$sort_order,$sort_type,$arrays);
- return $arrays;
- }
|