From f980b021f1f1df132c4599cb4c1fb127a1ae289a Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 22 Mar 2022 20:42:48 +0800 Subject: + album --- admin.php | 4 +- admin_add_album.php | 64 +++++++++++++++++ admin_albums.php | 51 ++++++++++++++ admin_header.php | 4 +- admin_modify_music.php | 78 +++++++++++++++++++++ admin_new_album.php | 21 ++++++ admin_new_music.php | 5 ++ admin_paginate.php | 2 - admin_tags.php | 57 ++++++++++++++++ admin_template.php | 14 +++- admin_uber.php | 37 ++++++++++ cover/1647698450_764_15683538526.jpg | Bin 0 -> 8794 bytes music.php | 129 ++++++++++++++++++++++++++++++++++- music/1647697408_705_Erika.mp3 | Bin 0 -> 2013165 bytes music/1647698175_317_Erika.mp3 | Bin 0 -> 2013165 bytes music/1647698450_399_Erika.mp3 | Bin 0 -> 2013165 bytes res/admin.css | 44 +++++++++++- res/dachai.png | Bin 320027 -> 6793 bytes res/pause_cover.png | Bin 539 -> 539 bytes res/play_cover.png | Bin 749 -> 757 bytes res/styles.css | 2 +- sql/musik.sql | 74 ++++++++++++++++++++ template.php | 6 ++ uber.php | 37 ---------- utils.php | 4 ++ 25 files changed, 584 insertions(+), 49 deletions(-) create mode 100644 admin_add_album.php create mode 100644 admin_albums.php create mode 100644 admin_modify_music.php create mode 100644 admin_new_album.php create mode 100644 admin_tags.php create mode 100644 admin_uber.php create mode 100644 cover/1647698450_764_15683538526.jpg create mode 100644 music/1647697408_705_Erika.mp3 create mode 100644 music/1647698175_317_Erika.mp3 create mode 100644 music/1647698450_399_Erika.mp3 create mode 100644 sql/musik.sql delete mode 100644 uber.php diff --git a/admin.php b/admin.php index d0adc6a..9feea13 100644 --- a/admin.php +++ b/admin.php @@ -48,9 +48,9 @@ form .text { Music - Albums + Albums - Tags + Tags
diff --git a/admin_add_album.php b/admin_add_album.php new file mode 100644 index 0000000..022ba27 --- /dev/null +++ b/admin_add_album.php @@ -0,0 +1,64 @@ + + + + + + + + + +
+ + + + + + + +

Add Album

+ +
+
+ +
+
+
+ +
+
+
+ + +
+
+ +
+
+ +
+ +
+ + + + \ No newline at end of file diff --git a/admin_albums.php b/admin_albums.php new file mode 100644 index 0000000..8858f76 --- /dev/null +++ b/admin_albums.php @@ -0,0 +1,51 @@ + + + + + + + + + +
+ + + + + + + + + +
+ + + new album +
+
+ + + +
+ + + \ No newline at end of file diff --git a/admin_header.php b/admin_header.php index d877ef3..9cd27bd 100644 --- a/admin_header.php +++ b/admin_header.php @@ -26,8 +26,8 @@ Site Main Music - Albums - Tags + Albums + Tags
diff --git a/admin_modify_music.php b/admin_modify_music.php new file mode 100644 index 0000000..141db72 --- /dev/null +++ b/admin_modify_music.php @@ -0,0 +1,78 @@ + + + + + + + + + +
+ + + + + + + + + +

Music (Iduid;?>)

+ +
+ +
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+ +
+
+
+ +
+
+ +
+ +
+ + + + \ No newline at end of file diff --git a/admin_new_album.php b/admin_new_album.php new file mode 100644 index 0000000..aed04d6 --- /dev/null +++ b/admin_new_album.php @@ -0,0 +1,21 @@ + + + + + + \ No newline at end of file diff --git a/admin_new_music.php b/admin_new_music.php index ceb761e..d084450 100644 --- a/admin_new_music.php +++ b/admin_new_music.php @@ -5,7 +5,12 @@ -
\ No newline at end of file diff --git a/admin_tags.php b/admin_tags.php new file mode 100644 index 0000000..ce76dba --- /dev/null +++ b/admin_tags.php @@ -0,0 +1,57 @@ + + + + + + + + + +
+ + + + + + + + + +
+ +
+
+ + 0){ + foreach($arr as $tag){ + html_admin_tag($tag); + } + } + ?> + +
+ + + \ No newline at end of file diff --git a/admin_template.php b/admin_template.php index b745e44..efbd0bd 100644 --- a/admin_template.php +++ b/admin_template.php @@ -8,12 +8,22 @@ function html_admin_music($music) { echo ''; echo ''; echo ''; - echo 'Delete'; - echo 'Modify'; + echo 'Delete'; + echo 'Modify'; echo '
'; echo '
'; } +function html_admin_tag($tag) { + echo '
'; + echo '
'; + echo ' ' . $tag->name . ''; + echo ' X'; + echo '
'; + echo '
'; + echo '
'; +} + function html_admin_paginate_link($url, $pagei) { echo '' . ($pagei + 1) . ''; } diff --git a/admin_uber.php b/admin_uber.php new file mode 100644 index 0000000..ac34286 --- /dev/null +++ b/admin_uber.php @@ -0,0 +1,37 @@ + \ No newline at end of file diff --git a/cover/1647698450_764_15683538526.jpg b/cover/1647698450_764_15683538526.jpg new file mode 100644 index 0000000..b647dba Binary files /dev/null and b/cover/1647698450_764_15683538526.jpg differ diff --git a/music.php b/music.php index 797f48a..6903fc3 100644 --- a/music.php +++ b/music.php @@ -2,6 +2,7 @@ require_once 'config.php'; require_once 'connect.php'; +require_once 'utils.php'; class Tag { @@ -13,6 +14,9 @@ class Album { public $uid; public $name; + public $cover; + public $description; + public $array_music_ids; // 包含的音乐id(考虑到效率,这里不存为music结构) } class Music @@ -296,6 +300,70 @@ function get_last_id() { } } +function delete_music($music_id) { + $sql = "DELETE FROM ". Config::$tb_music . " WHERE id=" . $music_id; + echo $sql; + execute_sql($sql); + $sql = "DELETE FROM " . Config::$tb_music_tag . " WHERE music_id=" . $music_id; + execute_sql($sql); + $sql = "DELETE FROM " . Config::$tb_album_music . " WHERE music_id=" . $music_id; + execute_sql($sql); + + redirect('admin_music.php'); +} + +function delete_tag($tag_id) { + $sql = "DELETE FROM " . Config::$tb_tags . " WHERE id=" . $tag_id; + execute_sql($sql); + $sql = "DELETE FROM " . Config::$tb_music_tag . " WHERE tag_id=" . $tag_id; + execute_sql($sql); + + redirect('admin_tags.php'); +} + +function delete_album($album_id) { + $sql = "DELETE FROM " . Config::$tb_album . " WHERE id=" . $album_id; + execute_sql($sql); + $sql = "DELETE FROM " . Config::$tb_album_music . " WHERE album_id=" . $album_id; + execute_sql($sql); + + redirect('admin_albums.php'); +} + +// 返回描述music tag的字符串 +function get_music_tag_string($music) { + if($music->array_tags == null || count($music->array_tags) == 0){ + return ""; + } + $tag_str = $music->array_tags[0]->name; + for($i = 1; $i < count($music->array_tags); $i++) { + $tag_str = $tag_str . ',' . $music->array_tags[$i]->name; + } + return $tag_str; +} + +// 返回描述music所属专辑的id字符串 +function get_music_albums_id_string($music) { + if($music->array_albums == null || count($music->array_albums) == 0){ + return ""; + } + $album_str = $music->array_albums[0]->uid; + for($i = 1; $i < count($music->array_albums); $i++) { + $album_str = $album_str . ',' . $music->array_albums[$i]->uid; + } + return $album_str; +} + +function delete_music_tag($music) { + $sql = "DELETE FROM " . Config::$tb_music_tag . " WHERE music_id=" . $music->uid; + execute_sql($sql); +} + +function delete_music_album($music) { + $sql = "DELETE FROM " . Config::$tb_album_music . " WHERE music_id=" . $music->uid; + execute_sql($sql); +} + // 提交上来的表单中构建music function get_music_from_post() { @@ -311,8 +379,9 @@ function get_music_from_post() return null; $music->path = $res_music[1]; } - else // 必须有音乐文件 + else // 必须有音乐文件 { + echo 'Music file is essential.'; return null; } @@ -361,6 +430,10 @@ function get_music_from_post() $music->uid = -1; // 未插入数据库 + if($_POST["mid"] != null) { + $music->uid = $_POST["mid"]; + } + //println($music); return $music; @@ -392,15 +465,67 @@ function write_music_to_db($music) { foreach($music->array_albums as $album){ add_unique_music_album($id, $album->uid); } - } else // 更新 { + $sql = "UPDATE " . Config::$tb_music . " SET " . + "path='" . $music->path ."'," . + "title='" . $music->title ."'," . + "cover='" . $music->cover ."'," . + "project='" . $music->project ."'" . + " WHERE id=" . $music->uid; + //println($sql); + execute_sql($sql); + + delete_music_tag($music); + delete_music_album($music); + $id = $music->uid; + foreach($music->array_tags as $tag){ + add_unique_music_tag($id, $tag->uid); + } + foreach($music->array_albums as $album){ + add_unique_music_album($id, $album->uid); + } } +} + +function get_album_from_post() { + $album = new Album; + + $cover_image = $_FILES["coverImage"]; + + if(is_upload_notempty($cover_image)) { + $res_cover = upload_file(Config::$cover_upload_dir, $cover_image); + if($res_cover[0] == 0) + return null; + $album->cover = $res_cover[1]; + } + + if($_POST["music_list"] != null && $_POST["music_list"] != "") + $music_ids = explode(',', $_POST["music_list"]); + + $album->array_music_ids = array(); + if($music_ids != null && count($music_ids) > 0) { + foreach($music_ids as $music_id){ + array_push($album->array_music_ids, $music_id); + } + } + + $album->title = html_escape_string($_POST["title"]); + $album->description = html_escape_string($_POST["description"]); + + $album->uid = -1; // 未插入数据库 + + if($_POST["aid"] != null) { + $album->uid = $_POST["aid"]; + } + + // println($album); + return $album; } ?> \ No newline at end of file diff --git a/music/1647697408_705_Erika.mp3 b/music/1647697408_705_Erika.mp3 new file mode 100644 index 0000000..e893114 Binary files /dev/null and b/music/1647697408_705_Erika.mp3 differ diff --git a/music/1647698175_317_Erika.mp3 b/music/1647698175_317_Erika.mp3 new file mode 100644 index 0000000..e893114 Binary files /dev/null and b/music/1647698175_317_Erika.mp3 differ diff --git a/music/1647698450_399_Erika.mp3 b/music/1647698450_399_Erika.mp3 new file mode 100644 index 0000000..e893114 Binary files /dev/null and b/music/1647698450_399_Erika.mp3 differ diff --git a/res/admin.css b/res/admin.css index beca966..d185acf 100644 --- a/res/admin.css +++ b/res/admin.css @@ -111,6 +111,7 @@ body{ width: 100%; position: absolute; bottom: 0; + left: 0; } #admin-paginate a { @@ -122,7 +123,7 @@ body{ text-align: center; line-height: 30px; float:left; - margin-right: 5px; + /*margin-right: 5px;*/ } #admin-paginate a:hover{ @@ -139,3 +140,44 @@ body{ display: block; } +#admin_tags{ + margin: 10px 0; +} + +.admin_tag { + display:inline-block; + height: 20px; + padding: 2px 5px; + box-sizing: border-box; + background: rgb(219, 219, 219); + border: 0px solid; + border-radius: 4px; + float:left; + margin-right: 10px; +} + +.admin_tag:hover { + background-color: black; + color:white; +} + +.admin_tag:hover a{ + color:white; +} + +.admin_tag a { + font-size: 12px; + text-decoration: none; + display: block; + float: left; +} + +.admin-tag-name{ + color:black; +} + +.admin-del-tag { + margin-left: 10px; + color:red; + font-weight: bold; +} diff --git a/res/dachai.png b/res/dachai.png index d30f86d..1db55b9 100644 Binary files a/res/dachai.png and b/res/dachai.png differ diff --git a/res/pause_cover.png b/res/pause_cover.png index ebf3288..db1ba4d 100644 Binary files a/res/pause_cover.png and b/res/pause_cover.png differ diff --git a/res/play_cover.png b/res/play_cover.png index c7f8ca6..bc74085 100644 Binary files a/res/play_cover.png and b/res/play_cover.png differ diff --git a/res/styles.css b/res/styles.css index 6ddcc6e..e1318a0 100644 --- a/res/styles.css +++ b/res/styles.css @@ -234,7 +234,7 @@ body{ text-align: center; line-height: 30px; float:left; - margin-right: 5px; + /*margin-right: 5px;*/ } #paginate a:hover{ diff --git a/sql/musik.sql b/sql/musik.sql new file mode 100644 index 0000000..8d4233b --- /dev/null +++ b/sql/musik.sql @@ -0,0 +1,74 @@ +/* +Navicat MySQL Data Transfer + +Source Server : wod +Source Server Version : 50722 +Source Host : localhost:3306 +Source Database : musik + +Target Server Type : MYSQL +Target Server Version : 50722 +File Encoding : 65001 + +Date: 2022-03-21 02:36:02 +*/ + +SET FOREIGN_KEY_CHECKS=0; + +-- ---------------------------- +-- Table structure for album +-- ---------------------------- +DROP TABLE IF EXISTS `album`; +CREATE TABLE `album` ( + `id` int(32) unsigned NOT NULL AUTO_INCREMENT, + `name` text NOT NULL, + `description` text, + `cover` text, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; + +-- ---------------------------- +-- Table structure for album_music +-- ---------------------------- +DROP TABLE IF EXISTS `album_music`; +CREATE TABLE `album_music` ( + `id` int(32) unsigned NOT NULL AUTO_INCREMENT, + `music_id` int(32) NOT NULL, + `album_id` int(32) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8; + +-- ---------------------------- +-- Table structure for music +-- ---------------------------- +DROP TABLE IF EXISTS `music`; +CREATE TABLE `music` ( + `id` int(32) unsigned NOT NULL AUTO_INCREMENT, + `path` text NOT NULL, + `title` text, + `time` int(128) NOT NULL, + `cover` text, + `project` text, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8; + +-- ---------------------------- +-- Table structure for music_tag +-- ---------------------------- +DROP TABLE IF EXISTS `music_tag`; +CREATE TABLE `music_tag` ( + `id` int(32) unsigned NOT NULL AUTO_INCREMENT, + `music_id` int(32) DEFAULT NULL, + `tag_id` int(32) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8; + +-- ---------------------------- +-- Table structure for tags +-- ---------------------------- +DROP TABLE IF EXISTS `tags`; +CREATE TABLE `tags` ( + `id` int(32) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(128) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8; diff --git a/template.php b/template.php index 726bdfe..eb38b54 100644 --- a/template.php +++ b/template.php @@ -1,5 +1,6 @@ + ' ; + if(isLogin()){ + echo ''; + echo '
'; + } + echo ''; echo '
'; diff --git a/uber.php b/uber.php deleted file mode 100644 index fee329d..0000000 --- a/uber.php +++ /dev/null @@ -1,37 +0,0 @@ - \ No newline at end of file diff --git a/utils.php b/utils.php index 8a7824b..60dd29a 100644 --- a/utils.php +++ b/utils.php @@ -25,5 +25,9 @@ function html_escape_string($str) { return $str; } +function redirect($url){ + header('Location: '.$url); +} + ?> -- cgit v1.1-26-g67d0