Răsfoiți Sursa

优化了代码

unknown-o 4 ani în urmă
părinte
comite
8906e58cdd
10 a modificat fișierele cu 136 adăugiri și 142 ștergeri
  1. 1 1
      api/admin.php
  2. 1 1
      api/submit.php
  3. 2 2
      config.php
  4. 5 3
      includes/footer.php
  5. 30 22
      includes/function.php
  6. 5 4
      includes/header.php
  7. 2 3
      index.php
  8. 5 4
      pages/about.php
  9. 85 86
      pages/card.php
  10. 0 16
      pages/more.php

+ 1 - 1
api/admin.php

@@ -5,7 +5,7 @@ include('../includes/function.php');
 switch ($_POST['mode']) {
     case "login":
         if ($_POST['username'] == $ADMIN_USER && $_POST['password'] == $ADMIN_PASS) {
-            setcookie("loveway_token", md5($ADMIN_USER . $ADMIN_PASS . 'KAGAMINE WORLD!' . date('Y-m-d', time())), time()+3600,'/');
+            setcookie("loveway_token", md5($ADMIN_USER . $ADMIN_PASS . 'KAGAMINE WORLD!' . date('Y-m-d', time())), time() + 3600, '/');
             exit('{"code":1,"msg":"success"}');
         } else {
             exit('{"code":-1,"msg":"username or password error"}');

+ 1 - 1
api/submit.php

@@ -17,7 +17,7 @@ if ($timestamp - time() > 5 || time() - $timestamp > 5) {
     exit('{"code":-5,"msg":"提交失败!请检查您的系统时间!"}');
 }
 
-$all = 'Kagamine Yes!'.strval($contact) . $confessor . $ta . $image .$introduction . $content . strval($timestamp);
+$all = 'Kagamine Yes!' . strval($contact) . $confessor . $ta . $image . $introduction . $content . strval($timestamp);
 if (md5($all) != $_POST['key']) {
     exit('{"code":-5,"msg":"出现了一个未知错误!请联系管理员!"}');
 }

+ 2 - 2
config.php

@@ -1,5 +1,5 @@
 <?php
-//V1.2.6版本
+//V1.2.8版本
 
 //数据库地址
 $DB_HOST="127.0.0.1";
@@ -20,4 +20,4 @@ $REWRITE=false;
 当前只支持nginx,apache规则的话...实在不会写,热心的童鞋可以帮忙写一下啊(谢谢各位大佬了)
 
 */
-?>
+?>

+ 5 - 3
includes/footer.php

@@ -1,7 +1,9 @@
 </div>
 <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/mdui.min.js"></script>
 <script>
-    $(document).pjax('a', '#pjax-container',{'timeout':false})
+    $(document).pjax('a', '#pjax-container', {
+        'timeout': false
+    })
     $("#isLoading").hide()
     var inst = new mdui.Drawer('#main-drawer');
     $(document).on('pjax:send', function() {
@@ -35,8 +37,8 @@
         return mobile_flag;
     }
 
-    function getNowURL(){
-        return window.location.protocol+'//'+window.location.host
+    function getNowURL() {
+        return window.location.protocol + '//' + window.location.host
     }
 
     $(function() {

+ 30 - 22
includes/function.php

@@ -1,5 +1,6 @@
 <?php
-function pdoConnect(){
+function pdoConnect()
+{
     return new PDO('mysql:host=' . $GLOBALS['DB_HOST'] . ';dbname=' . $GLOBALS['DB_NAME'], $GLOBALS['DB_USER'], $GLOBALS['DB_PASS']);
 }
 
@@ -9,34 +10,36 @@ function get_http_type()
     return $http_type;
 }
 
-function titleChange(){
-    $title='';
+function titleChange()
+{
+    $title = '';
     if (!empty(getInfo($_GET['page']))) $title = getInfo($_GET['page']) . ' - ';
     $title = $title . getInfo('title');
-    return '<script>$(document).attr("title","'.$title.'");</script>';
+    return '<script>$(document).attr("title","' . $title . '");</script>';
 }
 
-function listActive($pageName){
-    ?>
+function listActive($pageName)
+{
+?>
     <script>
-    pageArr = ['homePage', 'submitPage', 'morePage', 'aboutPage'];
-    for (let i = 0; i < pageArr.length; i++) {
-        if ($("#" + pageArr[i]).hasClass("mdui-list-item-active")) {
-            $("#" + pageArr[i]).removeClass("mdui-list-item-active");
+        pageArr = ['homePage', 'submitPage', 'morePage', 'aboutPage'];
+        for (let i = 0; i < pageArr.length; i++) {
+            if ($("#" + pageArr[i]).hasClass("mdui-list-item-active")) {
+                $("#" + pageArr[i]).removeClass("mdui-list-item-active");
+            }
         }
-    }
-    $("#<?php echo $pageName;?>Page").addClass("mdui-list-item-active");
+        $("#<?php echo $pageName; ?>Page").addClass("mdui-list-item-active");
     </script>
-    <?php
+<?php
 }
 
 function getInfo($name)
 {
-    try{
+    try {
         $pdo = pdoConnect();
         $stmt = $pdo->prepare("select * from loveway_config where name = ?");
-        $stmt->bindValue(1,$name);
-        if($stmt->execute()){
+        $stmt->bindValue(1, $name);
+        if ($stmt->execute()) {
             $rows = $stmt->fetchAll();
             return $rows[0]['value'];
         } else {
@@ -48,11 +51,16 @@ function getInfo($name)
     }
 }
 
-function hideSomethings(){
-    echo "<script>";
-    echo "$('#appbar').css('display','none');";
-    echo "$('#main-drawer').css('display','none');";
-    echo "setTimeout(function(){inst.close();},50);";
-    echo "</script>";
+function hideSomethings()
+{
+?>
+    <script>
+        $('#appbar').css('display', 'none');
+        $('#main-drawer').css('display', 'none');
+        setTimeout(function() {
+            inst.close();
+        }, 50);
+    </script>
+<?php
 }
 ?>

+ 5 - 4
includes/header.php

@@ -1,4 +1,4 @@
-<?php 
+<?php
 error_reporting(0);
 ?>
 <!DOCTYPE html>
@@ -7,11 +7,12 @@ error_reporting(0);
 <head>
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5">
-    <title><?php $subPageName=$_GET['page']; if (!empty(getInfo($subPageName))) echo getInfo($subPageName) . ' - ';
+    <title><?php $subPageName = $_GET['page'];
+            if (!empty(getInfo($subPageName))) echo getInfo($subPageName) . ' - ';
             echo $siteTitle ?></title>
     <meta name="keywords" content="<?php echo getInfo('keywords') ?>">
     <meta name="description" content="<?php echo getInfo('description') ?>">
-    <link rel="stylesheet" href="https://static.llilii.cn/css/other/background.css"/>
+    <link rel="stylesheet" href="https://static.llilii.cn/css/other/background.css" />
     <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/mdui.min.css" />
     <script src="https://static.llilii.cn/libs/jquery/3.5.1/jquery.min.js"></script>
     <script src="https://static.llilii.cn/libs/pjax/jquery.pjax.js"></script>
@@ -36,7 +37,7 @@ error_reporting(0);
 <body class="mdui-drawer-body-left mdui-bottom-nav-fixed mdui-appbar-with-toolbar mdui-theme-primary-pink mdui-theme-accent-pink mdui-theme-layout-auto mdui-loaded">
     <header id="appbar" class="mdui-appbar mdui-appbar-fixed">
         <audio src="<?php echo getInfo('audio') ?>" loop autoplay>
-            您的浏览器不支持 audio 标签。
+            抱歉...您的浏览器暂不支持audio标签哦!
         </audio>
         <div class="mdui-progress" id="isLoading">
             <div class="mdui-progress-indeterminate"></div>

+ 2 - 3
index.php

@@ -23,7 +23,7 @@ if (empty($QueryArr)) {
     $QueryArr = $_GET;
 }
 $templateMode = empty($QueryArr['_pjax']);
-$siteTitle=getInfo('title');
+$siteTitle = getInfo('title');
 switch ($pageName) {
     case "":
         include('./pages/homepage.php');
@@ -53,9 +53,8 @@ switch ($pageName) {
         }
         break;
     default:
-        $templateMode=false;
+        $templateMode = false;
         include('./pages/404.php');
-
 }
 echo titleChange();
 if ($templateMode) {

+ 5 - 4
pages/about.php

@@ -14,10 +14,11 @@ if ($templateMode) {
     </div>
     <div class="mdui-card-content">
         <div class="mdui-typo">
-        <?php echo getInfo('about_content')?>
-        <br><br><div class="mdui-divider"></div><br>
-        程序版本:V1.2.6<br />
-        作者博客:<a href="https://www.wunote.cn" class="text-decoration: none;">吴先森的笔记</a><br />作者邮箱:[email protected]<br>
+            <?php echo getInfo('about_content') ?>
+            <br><br>
+            <div class="mdui-divider"></div><br>
+            程序版本:V1.2.8<br />
+            作者博客:<a href="https://www.wunote.cn" class="text-decoration: none;">吴先森的笔记</a><br />作者邮箱:[email protected]<br>
         </div>
     </div>
 </div>

+ 85 - 86
pages/card.php

@@ -1,70 +1,69 @@
+<script>
+    function RandomNumBoth(Min, Max) {
+        var Range = Max - Min;
+        var Rand = Math.random();
+        var num = Min + Math.round(Rand * Range);
+        return num;
+    }
 
-    <script>
-        function RandomNumBoth(Min, Max) {
-            var Range = Max - Min;
-            var Rand = Math.random();
-            var num = Min + Math.round(Rand * Range);
-            return num;
-        }
-
-        function randomImage() {
-            var img = event.srcElement;
-            img.onerror = null;
-            var xhr = new XMLHttpRequest();
-            xhr.onreadystatechange = function() {
-                switch (xhr.readyState) {
-                    case 4:
-                        if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304) {
-                            imgURL = 'https://img.llilii.cn/kagamine/' + JSON.parse(xhr.responseText)['file_name'][RandomNumBoth(0, JSON.parse(xhr.responseText)['file_num'])];
-                            img.src = imgURL;
-                        }
-                        break;
-                }
+    function randomImage() {
+        var img = event.srcElement;
+        img.onerror = null;
+        var xhr = new XMLHttpRequest();
+        xhr.onreadystatechange = function() {
+            switch (xhr.readyState) {
+                case 4:
+                    if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304) {
+                        imgURL = 'https://img.llilii.cn/kagamine/' + JSON.parse(xhr.responseText)['file_name'][RandomNumBoth(0, JSON.parse(xhr.responseText)['file_num'])];
+                        img.src = imgURL;
+                    }
+                    break;
             }
-            xhr.open('get', 'https://static.llilii.cn/json/img_list.json');
-            xhr.send(null);
         }
+        xhr.open('get', 'https://static.llilii.cn/json/img_list.json');
+        xhr.send(null);
+    }
 
-        document.getElementById('pjax-container').style='max-width: 400px;';
-    </script>
+    document.getElementById('pjax-container').style = 'max-width: 400px;';
+</script>
 
-    <?php
-    try {
-        $pdo = pdoConnect();
-        $stmt = $pdo->prepare("select * from loveway_data where id = ?");
-        $stmt->bindValue(1, $cardID);
-        if ($stmt->execute()) {
-            $rows = $stmt->fetchAll();
-            $row = $rows[0];
-    ?>
-            <div class="mdui-card mdui-hoverable" style="border-radius: 16px;">
-                <div class="mdui-card-header">
-                    <img class="mdui-card-header-avatar" src="https://q1.qlogo.cn/g?b=qq&s=640&nk=<?php echo $row['contact']; ?>" />
-                    <div class="mdui-card-header-title"><?php echo $row['confessor']; ?></div>
-                    <div class="mdui-card-header-subtitle"><?php echo $row['time']; ?></div>
-                </div>
-                <div class="mdui-card-media">
-                    <?php
-                    if (!empty($row['image'])) {
-                    ?>
-                        <img style="max-height: 1000px" onerror="randomImage()" src="<?php echo $row['image']; ?>" />
-                    <?php
-                    } else {
-                    ?>
-                        <div class="mdui-divider"></div>
-                    <?php } ?>
-                </div>
-                <div class="mdui-card-primary">
-                    <div class="mdui-card-primary-title">To <?php echo $row['to_who']; ?></div>
-                    <div class="mdui-card-primary-subtitle">
-                        <?php echo $row['introduction']; ?>
-                    </div>
-                </div>
-                <div class="mdui-card-content">
-                    <?php echo $row['content']; ?>
+<?php
+try {
+    $pdo = pdoConnect();
+    $stmt = $pdo->prepare("select * from loveway_data where id = ?");
+    $stmt->bindValue(1, $cardID);
+    if ($stmt->execute()) {
+        $rows = $stmt->fetchAll();
+        $row = $rows[0];
+?>
+        <div class="mdui-card mdui-hoverable" style="border-radius: 16px;">
+            <div class="mdui-card-header">
+                <img class="mdui-card-header-avatar" src="https://q1.qlogo.cn/g?b=qq&s=640&nk=<?php echo $row['contact']; ?>" />
+                <div class="mdui-card-header-title"><?php echo $row['confessor']; ?></div>
+                <div class="mdui-card-header-subtitle"><?php echo $row['time']; ?></div>
+            </div>
+            <div class="mdui-card-media">
+                <?php
+                if (!empty($row['image'])) {
+                ?>
+                    <img style="max-height: 1000px" onerror="randomImage()" src="<?php echo $row['image']; ?>" />
+                <?php
+                } else {
+                ?>
+                    <div class="mdui-divider"></div>
+                <?php } ?>
+            </div>
+            <div class="mdui-card-primary">
+                <div class="mdui-card-primary-title">To <?php echo $row['to_who']; ?></div>
+                <div class="mdui-card-primary-subtitle">
+                    <?php echo $row['introduction']; ?>
                 </div>
-                <div class="mdui-card-actions">
-                    <a class="copy mdui-btn mdui-btn-icon mdui-float-right" href="javascript:void(0);" data-clipboard-text="
+            </div>
+            <div class="mdui-card-content">
+                <?php echo $row['content']; ?>
+            </div>
+            <div class="mdui-card-actions">
+                <a class="copy mdui-btn mdui-btn-icon mdui-float-right" href="javascript:void(0);" data-clipboard-text="
                             <?php
                             echo get_http_type() . $_SERVER['SERVER_NAME'];
                             if ($REWRITE) {
@@ -74,36 +73,36 @@
                             }
                             ?>
                             "><i class="mdui-icon material-icons">share</i></a>
-                    </a>
-                </div>
+                </a>
             </div>
+        </div>
 
-    <?php
-        } else {
-            return 'database connection failed';
-        }
-    } catch (Exception $e) {
+<?php
+    } else {
         return 'database connection failed';
     }
-    ?>
+} catch (Exception $e) {
+    return 'database connection failed';
+}
+?>
 
-    <div id="background">
-        <div class="bg-image" style="background: url('//img.llilii.cn/kagamine/p3/32639516_p2.jpg') no-repeat center center; display: block;"></div>
-    </div>
-    <script>
-        $(function() {
-            var clipboard = new ClipboardJS('.copy');
-            clipboard.on('success', function(e) {
-                mdui.snackbar({
-                    message: '复制表白卡片地址成功!',
-                    position: 'right-top'
-                });
+<div id="background">
+    <div class="bg-image" style="background: url('//img.llilii.cn/kagamine/p3/32639516_p2.jpg') no-repeat center center; display: block;"></div>
+</div>
+<script>
+    $(function() {
+        var clipboard = new ClipboardJS('.copy');
+        clipboard.on('success', function(e) {
+            mdui.snackbar({
+                message: '复制表白卡片地址成功!',
+                position: 'right-top'
             });
-            clipboard.on('error', function(e) {
-                mdui.snackbar({
-                    message: '复制表白卡片地址失败!请尝试手动复制!',
-                    position: 'right-top'
-                });
+        });
+        clipboard.on('error', function(e) {
+            mdui.snackbar({
+                message: '复制表白卡片地址失败!请尝试手动复制!',
+                position: 'right-top'
             });
         });
-    </script>
+    });
+</script>

+ 0 - 16
pages/more.php

@@ -5,31 +5,15 @@ if ($templateMode) {
 ?>
 <br /><br />
 <div class="mdui-card mdui-hoverable" style="border-radius: 16px">
-    <!-- 卡片头部,包含头像、标题、副标题 -->
-
-    <!-- 卡片的媒体内容,可以包含图片、视频等媒体内容,以及标题、副标题 -->
     <div class="mdui-card-media">
         <img style="max-height: 1000px" src="https://static.llilii.cn/images/kagamine/78688114_p0.png" />
     </div>
-
-    <!-- 卡片的标题和副标题 -->
     <div class="mdui-card-primary">
         <div class="mdui-card-primary-title"><?php echo getInfo('more') ?></div>
         <div class="mdui-card-primary-subtitle">哇!终于等到你来看这个页面!</div>
     </div>
-
-    <!-- 卡片的内容 -->
     <div class="mdui-card-content">
         <?php echo getInfo('more_content') ?>
     </div>
-    <!--
-        <div class="mdui-card-actions">
-          <button class="mdui-btn mdui-btn-icon mdui-float-right">
-            <i class="mdui-icon material-icons">share</i>
-          </button>
-          <button class="mdui-btn mdui-btn-icon mdui-float-right">
-            <i class="mdui-icon material-icons">more</i>
-          </button>
-        </div>-->
 </div>
 <br /><br />