-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.php
218 lines (164 loc) · 6.25 KB
/
edit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
session_start();
function h($s){
return htmlspecialchars($s, ENT_QUOTES, 'utf-8');
}
if(!isset($_SESSION['id'])){
header('Location: ./login_form.php');
exit();
}
//ファイルがあるなら編集
$file_title = "";
$file_content = "";
$file_id = "";
if(isset($_GET["u"]) && isset($_GET["fid"])){
$file_id = $_GET["fid"];
$user = $_GET["u"];
if(!preg_match("/^[0-9A-Za-z]+$/", $user)){
exit();
}
$lines = file("./search/".$user.".csv");
foreach($lines as $line){
$data = explode('($split)',$line);
if(count($data) == 3){
if($data[1] === $file_id){
$file_title = $data[0];
break;
}
}
}
if($file_title === ""){
echo("404 Not found :(");
exit();
}
$file_lines = file("./data/".$file_id.".md");
foreach($file_lines as $line){
$file_content .= $line;
}
}else{
//なかったら新規作成
$file_title = "";
$file_content = "";
}
if(!isset($_SESSION["csrf_token"])){
// ランダムな英数字を生成し、それをcsrf_tokenにする
$str = '1234567890abcdefghijklmnopqrstuvwxyz';
$csrf_token = substr(str_shuffle($str), 0, 10);
$_SESSION["csrf_token"] = $csrf_token;
}else{
$csrf_token = $_SESSION["csrf_token"];
}
?>
<html>
<head>
<meta charset="UTF-8">
<title>easeLp - editor</title>
<link rel="stylesheet" href="./css/style.css">
<link rel="stylesheet" href="./css/edit.css">
<link rel="stylesheet" href="./css/modal.css">
<link rel="stylesheet" href="./css/load_anime.css">
<link rel="preconnect" href="https://rsms.me/">
<link rel="stylesheet" href="https://rsms.me/inter/inter.css">
<link rel="preconnect" href="https://fonts.googleapis.com/">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Quicksand:300,400,500,700">
<link rel="icon" type="image/svg+xml" href="./logo.svg" />
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/a11y-dark.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
</head>
<body>
<header>
<?php include("./header.php"); ?>
</header>
<div class="editor_contents">
<input id="title_input" type="text" placeholder="here title.">
<div class="edit_preview">
<div id="edit_box">
<div class="edit_head">
<div class="title">
<span style="font-size:1.3vw;">markdown</span>
<img class="menu" src="./img/code.svg" onclick="add_md('code')">
<img class="menu" src="./img/color.svg" onclick="add_md('color')">
<span class="menu" id="image_upload_back">
<form method="post" enctype="multipart/form-data" id="up_form">
<input type="file" name="file1" accept=".jpg, .png, .gif, .bmp, .svg" class="menu" id="image_upload">
<input type="submit" style="display:none;" id="submit_image">
</form>
</span>
<img class="menu" src="./img/link.svg" onclick="add_md('link')">
<span class="menu" onclick="add_md('h2')">h2</span>
<span class="menu" onclick="add_md('h1')">h1</span>
<span id="save_btn" class="save_btn" href="./save.php">save</span>
<span id="delete_btn" href="./delete.php">delete</span>
</div>
</div>
<textarea id="editor_main"></textarea>
</div>
<div id="preview_box">
<div class="edit_head">
<div class="title">
<span style="font-size:1.3vw;">html preview</span>
<span class="menu" style="margin-right:1em;">help</span>
</div>
</div>
<div id="preview_html"></div>
</div>
</div>
</div>
</div>
<div id="saved_window">
saved!
</div>
<div id="save_error_window">
save error
</div>
<a id="gpt_help_button" href="#modal">
<div id="gpt_help_svg">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"></path>
</svg>
</div>
</a>
<div class="modal" id="modal">
<a href="#!" class="overlay"></a>
<div class="modal-wrapper">
<div class="modal-contents">
<a href="#!" class="modal-close">✕</a>
<div class="modal-content">
<div id="overlay_black"></div>
<h2>Chat-GPT writing assistant</h2>
<br><br>
Please write in bullet points what you want to write in the document.<br>
<textarea id="gpt_write_inp" rows="8"></textarea>
<br><br>
<div class="btn" onclick="gpt_write_send();" style="font-size:1.2em;">Generate</div>
<br><br>
words: <input id="word_num" type="number" value="50">
<br>
<br>
copy and paste this to your editor.
<textarea id="gpt_write_out" rows="8"></textarea>
<br><br>
<div id="assist_load_box">
<div class="spinner-box-as">
<div class="pulse-container">
<div class="pulse-bubble-as pulse-bubble-1"></div>
<div class="pulse-bubble-as pulse-bubble-2"></div>
<div class="pulse-bubble-as pulse-bubble-3"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script>
const get_file_id = <?php echo('"'.h($file_id).'"'); ?>;
const file_content = <?php echo('`'.h(str_replace('`','\`',$file_content)).'`'); ?>;
const file_title = <?php echo('"'.h($file_title).'"'); ?>;
const csrf_token = <?php echo('"'.$csrf_token.'"') ?>
</script>
<script src="./js/editor.js"></script>
</body>
</html>