-
Notifications
You must be signed in to change notification settings - Fork 18
/
index.php
executable file
·1611 lines (1393 loc) · 53.7 KB
/
index.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
//MarkNote 轻量级云记事本系统
//功能:
// 1. 以文件或数据库的方式保存记事本
// 2. 支持MarkDown(即时预览+优化的textarea)和纯文本两种格式的记事本
// 3. 可以给记事本设置密码
// 4. 可生成记事本的二维码,以方便手机用户
// 5. 可将记事本下载到本地
// 6. 可以将Markdown记事本一键生成网页
// 7. 支持伪静态(https://233333.net/记事本名),仅限apache,默认开启,若环境不支持请关闭
// 8. 支持使用任意英文和数字作为ID
//=== 选项 =============================
define('MD5_SALT', 'faowifankjsnvlaiuwef2480rasdlkvj'); //加密记事本密码时, 所使用的盐, 请一定要修改为自己设置的
define('MARK_DOWN_TYPE', '<<<-- MarkDown Type Note -->>>'); //Markdown 格式的标记
define('NOTE_CONFIG_FILE', 'NoteConfig.php'); //MarkNote的配置文件(自动生成)
define('NOTE_DATA', 'NoteData/'); //MarkNote的数据目录(自动生成)
define('NOTE_PASSWD_FILE', NOTE_DATA . 'passwd.data'); //MarkNote的密码存储文件(自动生成)
$rewrite_create_htaccess_file = true; //是否创建.htaccess文件以尝试实现伪静态
//======================================
$rewrite_use_better_url = true; //是否使用伪静态后的URL(如 https://note.domain/记事本名 ),若环境不支持伪静态则不要开启
function show_error_exit($output,$show_return=true){
//输出错误信息并终止
echo '<!DOCTYPE html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>body{font-family: "文泉驛正黑","Microsoft yahei UI","Microsoft yahei","微软雅黑","Lato",Helvetica,Arial,sans-serif !important;}button{border: 0;background: #3498DB;color: #fff;font-size: 16px;padding:5px 10px;box-shadow: 0px 1px 3px rgba(100, 100, 100, 0.3);}</style><title>MarkNote</title></head>';
echo '<body style="background-color:#eee;margin:50px auto;width:800px;">';
echo '<div style="padding:20px;margin:0;color:#555;background:#fff;border:0;box-shadow:0px 2px 6px rgba(100, 100, 100, 0.3);">';
echo '<p style="margin:0 0 5px 0;">'.$output.'</p>';
if($show_return) echo '<br/><button onclick="history.go(-1)">< 返回</button>';
echo '</div>';
echo '</body></html>';
exit();
}
//显示输入密码框并终止
function show_input_passwd(){?>
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title>输入密码</title>
<style type="text/css">
body{
background:#eee;width:500px;margin:20px auto 20px auto;
}
#input-passwd{
font-size:14px;width:400px;padding:10px;margin:0;font-size:14px;color:#555;background:#fff;border:0;box-shadow:0px 2px 6px rgba(100, 100, 100, 0.3);
}
#input-submit{
font-size:14px;padding:9px 20px;color:#555;background:#fff;border:0;box-shadow:0px 2px 6px rgba(100, 100, 100, 0.3);cursor:pointer;
}
@media screen and (max-width: 500px){
body{
width:100%;
padding: 20px;
margin: 0;
}
form{
width:100%;
}
#input-passwd{
width: 70%;
}
#input-submit{
width: 20%;
}
}
</style>
</head>
<body>
<h3 style="font-weight:400;">此记事本有密码, 请输入密码以继续访问</h3>
<form action="<?php echo_note_url(); ?>" method="post">
<input id="input-passwd" type="password" name="GiveYouPasswd" placeholder="密码" style=""/>
<input id="input-submit" type="submit" value="提交" style="" />
</form>
</body>
</html>
<?php
exit();
}
function echo_note_url(){
global $rewrite_use_better_url, $noteId;
echo ($rewrite_use_better_url ? '' : '?n=') . $noteId;
}
function reLocation($url){
global $rewrite_use_better_url;
header("Location: ". ($rewrite_use_better_url ? '' : '?n=') . $url);
exit();
}
function encrypt_pass($noteId, $password){
return md5(MD5_SALT . $noteId . 'MyNote' . $password . 'Let-It-More-Lang');
}
// -----程序从这里开始-----
// error_reporting(0); //不显示所以错误提升
// ini_set("display_errors", "On"); //显示所以错误提升
// error_reporting(E_ALL);
//判断是否是第一次使用
if( !file_exists(NOTE_CONFIG_FILE) ){
if( !isset($_POST['mode']) ){
show_error_exit('
<h1 style="font-weight:100;margin:0;"">请选择记事本的存储方式</h1>
<br/>
<h2 style="font-weight:100;margin:0 0 5px 0;border-bottom:solid 2px #ddd;">使用文件方式</h3>
<p style="margin: 5px 0;">点击确定以使用文件方式存储,并自动生成所需文件</p>
<form action="" method="post">
<input type="hidden" name="mode" value="file">
<button>确定,使用文件方式</button>
</form>
<br/>
<br/>
<h2 style="font-weight:100;margin:0 0 5px 0;border-bottom:solid 2px #ddd;">使用MySQL方式</h3>
<p style="margin: 5px 0;">填写数据库连接信息,并点击确定以使用MySQL方式存储</p>
<form action="" method="post">
<input type="hidden" name="mode" value="sql">
<div style="margin-bottom:5px"><span style="width:400px;display:inline-block;">数据库主机</span> <input type="text" name="sql_host" placeholder="Host" value="localhost" /></div>
<div style="margin-bottom:5px"><span style="width:400px;display:inline-block;">数据库用户</span> <input type="text" name="sql_user" placeholder="User" value="root" /></div>
<div style="margin-bottom:5px"><span style="width:400px;display:inline-block;">密码</span> <input type="text" name="sql_passwd" placeholder="Password" /></div>
<div style="margin-bottom:5px"><span style="width:400px;display:inline-block;">数据库名</span> <input type="text" name="sql_name" placeholder="Database Name" value="marknote" /></div>
<div style="margin-bottom:5px"><span style="width:400px;display:inline-block;">使用的数据库表(自动创建,一般不必修改)</span> <input type="text" name="sql_table" placeholder="Database Table Name" value="note_data"/></div>
<button>确定,使用MySQL方式</button>
</form>
',false);
}else{
if( $_POST['mode']=='sql' ){
$use_sql=true;
$sql_host=$_POST['sql_host'];
$sql_user=$_POST['sql_user'];
$sql_passwd=$_POST['sql_passwd'];
$sql_name=$_POST['sql_name'];
$sql_table=$_POST['sql_table'];
}else{
$use_sql=false;
}
if( !$use_sql ){
if( !file_exists(NOTE_DATA) ){
mkdir(NOTE_DATA);
if( !file_exists(NOTE_DATA)){
show_error_exit('服务器端错误:无法创建文件,请检查文件系统权限');
}
touch(NOTE_DATA . 'index.html');
touch(NOTE_PASSWD_FILE);
}else if( !is_dir(NOTE_DATA) ){
show_error_exit('服务器端错误:错误的数据目录类型.');
}
}else{
$notesql = mysqli_connect($sql_host, $sql_user, $sql_passwd, $sql_name);
if(!$notesql) show_error_exit("服务器端错误:无法连接数据库,请修正数据库连接信息或使用文件存储方式");
if( !mysqli_query($notesql,"SELECT * FROM ".$sql_table) ){
$is_ok = mysqli_query($notesql,"CREATE TABLE ".$sql_table." (
num int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(num),
ID tinytext,
passwd tinytext,
content longtext
)");
if(!$is_ok) show_error_exit("服务器端错误:无法创建数据库表,请修正数据库连接信息或使用文件存储方式");
}
}
//创建伪静态
if( !file_exists(".htaccess") && $rewrite_create_htaccess_file ){
$htaccess_file_content =
"### MarkNote RewriteRule start
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)$ index.php?n=$1
RewriteRule ^([a-zA-Z0-9]+).html$ index.php?n=$1&html=yes
</IfModule>
### MarkNote RewriteRule end
";
file_put_contents('.htaccess', $htaccess_file_content);
}
if( !$use_sql ){
$to_config_file=
'<?php
$use_sql=false;
?>
';
}else{
$to_config_file=
'<?php
$use_sql=true;
$sql_host="'.$sql_host.'";
$sql_user="'.$sql_user.'";
$sql_passwd="'.$sql_passwd.'";
$sql_name="'.$sql_name.'";
$sql_table="'.$sql_table.'";
?>
';
}
file_put_contents(NOTE_CONFIG_FILE, $to_config_file);
header("Location: ");
}
}else{
require NOTE_CONFIG_FILE;
}
if($use_sql){
$notesql = mysqli_connect($sql_host, $sql_user, $sql_passwd, $sql_name);
if(!$notesql) show_error_exit('无法连接数据库');
}
$noteId = @$_GET['n'];
$noteTitle = '新建';
$JavaScript = '';//用于保存需要在页面中输出的 javascript 代码, 以修正在文档开头输出 <script> 标签的问题
$passwd = false;//代表当前的Note是否有密码
$note_content_to_show = '';//记事本的默认内容
//开始处理记事本
if( $noteId == '' ){
//如果访问主页
$url = '';
$isNew = @$_GET['new'] === 'yes';
if( $isNew !== true && isset($_COOKIE['myNote']) && @$_POST['force_home'] != 'yes'){
//如果是已保存cookie的老用户,并不是强制到主页(通过笔记本页的返回主页按钮).则取出记事本ID,并跳转根据ID跳转到笔记本页
$url = $_COOKIE['myNote'];
}else{
$page_type = 'home'; //设置是主页标记为真(在最后生成页面时作判断用)
if( $isNew ){
//以当前的时间(带毫秒)再加上随机数生成唯一的(理论上) noteId
$url = md5(microtime(1) . mt_rand());
}
}
if($url !== ''){
reLocation($url);
}
}else{
//如果指定了ID
if( !preg_match('/^[A-Za-z0-9]+$/', $noteId) || strlen($noteId) < 3 || strlen($noteId) > 200){
//如果ID不符合规范
show_error_exit("错误:输入的ID不合法");
}
$noteTitle = $noteId;
setcookie("myNote", $noteId, time()+31536000000);
//判断是否已有笔记本
if( !$use_sql ){
$this_ID_have_note = file_exists(NOTE_DATA . $noteId);
}else{
$sql_return = mysqli_query($notesql,"SELECT ID, content FROM ".$sql_table." WHERE ID='". $noteId ."'");
$the_content = mysqli_fetch_array($sql_return);
$this_ID_have_note = isset($the_content['ID']) && $the_content['ID'];
}
if( $this_ID_have_note ){
//如果ID已有笔记
$page_type = 'text_note';
//处理输入的密码
if( isset($_POST['GiveYouPasswd']) ){
//如果输入了密码
setcookie("myNodePasswdFor". $noteId, $_POST['GiveYouPasswd'], time()+3600);
reLocation($noteId);
}
$realpasswd = '';
//检查是这个ID是否有密码
if( !$use_sql ){
//打开密码文件
$passwd_file = fopen(NOTE_PASSWD_FILE, 'r');
//读取密码文件
while( !feof($passwd_file) ){
//读取一行
$passwd_file_this_line = fgets($passwd_file);
//把这行分为两段
$this_line_array = explode(" ", $passwd_file_this_line);
if( $this_line_array[0] === $noteId ){
//如果这个ID有密码并在这一行中
//有密码标记为真
$passwd = true;
$realpasswd = $this_line_array[1];
//找到密码后, 不再往后找了
break;
}
}
fclose($passwd_file);
}else{
$sql_return = mysqli_query($notesql, "SELECT passwd FROM ".$sql_table." WHERE ID='". $noteId ."'");
$the_passwd = mysqli_fetch_array($sql_return);
if( isset($the_passwd['passwd']) && $the_passwd['passwd'] ){
//有密码标记为真
$passwd = true;
$realpasswd = $the_passwd['passwd'];
}
}
//当前的 note 有密码标记
if($passwd){
//从Cookie获取密码
$password = @$_COOKIE['myNodePasswdFor'.$noteId];
//密码不正确或者未输入, 则显示密码输入框
if( encrypt_pass($noteId, $password) !== trim($realpasswd) ) {
show_input_passwd();
}
//当前 note 有密码时, 才处理 删除密码的逻辑, 否则 不处理, 因为没有密码, 不需要删除密码
if( isset($_POST['delete_passwd']) ){
if( !$use_sql ){
$passwd_file = fopen(NOTE_PASSWD_FILE, 'a+');
//读取密码文件
while( !feof($passwd_file) ){
//读取一行
$passwd_file_this_line = fgets($passwd_file);
//把这行分为两段
$this_line_array = explode(" ",$passwd_file_this_line);
if( $this_line_array[0] === $noteId ){
//如果这个ID有密码并在这一行中
$passwd_file_content = file_get_contents(NOTE_PASSWD_FILE);
$passwd_file_content_part_1 = substr($passwd_file_content,0,ftell($passwd_file)-strlen($passwd_file_this_line) );
$passwd_file_content_part_2 = substr($passwd_file_content,ftell($passwd_file));
file_put_contents(NOTE_PASSWD_FILE, $passwd_file_content_part_1.$passwd_file_content_part_2);
//有密码标记为假
$passwd = false;
break;
}
}
//关闭文件
fclose($passwd_file);
}else{
mysqli_query($notesql,"UPDATE ".$sql_table." SET passwd = '' WHERE ID = '".$noteId."'");
//有密码标记为假
$passwd = false;
}
//密码删除成功
if($passwd === false){
//删除Cookie
setcookie("myNodePasswdFor".$noteId, '', time()-1);
//提示信息
$JavaScript = "alert('密码已删除');";
}
}
}else{
//没有密码时, 才处理 设置密码的逻辑, 否则单独多次提交设置密码逻辑, 在使用 文件模式时, 会导致文件里同一 noteId 出现多条密码的情况
if( isset($_POST['the_set_passwd']) ){
//如果要设置密码
$password = $_POST['the_set_passwd'];
//密码长度至少 6 位
if(strlen($password) > 5){
$mpass = encrypt_pass($noteId, $password);
if( !$use_sql ){
//打开密码文件
$passwd_file = fopen(NOTE_PASSWD_FILE, 'a+');
//写入密码信息
fputs($passwd_file, $noteId.' '.$mpass);
fputs($passwd_file, "\n");
fclose($passwd_file);
}else{
mysqli_query($notesql,"UPDATE ".$sql_table." SET passwd = '". $mpass ."' WHERE ID = '".$noteId."'");
}
//设置Cookie
setcookie("myNodePasswdFor".$noteId, $password, time()+3600);
//提示信息
$JavaScript = "alert('密码已设置');";
//有密码标记为真
$passwd = true;
}
}
}
if( isset($_POST['the_set_id']) ){
$new_id = $_POST['the_set_id'];
if( !preg_match('/^[A-Za-z0-9]+$/', $new_id) || strlen($new_id) < 3 || strlen($new_id) > 200){
//如果ID不符合规范
show_error_exit("错误:输入的ID不合法");
}
//判断是否已有笔记本
if( !$use_sql ){
$this_ID_have_note = file_exists(NOTE_DATA . $new_id);
}else{
$sql_return = mysqli_query($notesql,"SELECT ID, content FROM ".$sql_table." WHERE ID='". $new_id ."'");
$the_content = mysqli_fetch_array($sql_return);
$this_ID_have_note = isset($the_content['ID']) && $the_content['ID'];
}
if($this_ID_have_note){
show_error_exit("错误:输入的ID已存在");
}
if( !$use_sql ){
rename(NOTE_DATA.$noteId,NOTE_DATA.$new_id);
}else{
mysqli_query($notesql,"UPDATE ".$sql_table." SET ID = '".$new_id."' WHERE ID = '".$noteId."'");
}
reLocation($new_id);
}
if(
isset($_POST['the_note']) && //有POST过来的 记事本 内容
(
isset($_POST['save']) || @$_POST['ajax_save'] === 'yes'
)
){
$to_save_raw = $_POST['the_note'];
if( @$_POST['note_type'] == 'md_note' ){
$to_save_raw = MARK_DOWN_TYPE . $to_save_raw;
}
if( !$use_sql ){
file_put_contents(NOTE_DATA . $noteId, $to_save_raw);
}else{
$to_save_tmp = $to_save_raw;
$to_save_tmp = str_replace("&", "&",$to_save_tmp);
$to_save_tmp = str_replace("'", "'",$to_save_tmp);
$to_save_tmp = str_replace("\"", "*",$to_save_tmp);
$to_save_tmp = str_replace("=", "=",$to_save_tmp);
$to_save_tmp = str_replace("?", "?",$to_save_tmp);
mysqli_query($notesql,"UPDATE ".$sql_table." SET content = '".$to_save_tmp."' WHERE ID = '".$noteId."'");
}
if(@$_POST['ajax_save'] === 'yes'){
echo "ok";
//使用ajax时无需再输出HTML,任务已完成,终止执行.
exit();
}
}
if( !$use_sql ){
$note_content_to_show = file_get_contents(NOTE_DATA . $noteId);
}else{
//直接使用上面查询出来的结果, 不再重新查询
$note_content_to_show = $the_content['content'];
$note_content_to_show = str_replace("&", "&",$note_content_to_show);
$note_content_to_show = str_replace("'", "'",$note_content_to_show);
$note_content_to_show = str_replace("*", "\"",$note_content_to_show);
$note_content_to_show = str_replace("=", "=",$note_content_to_show);
$note_content_to_show = str_replace("?", "?",$note_content_to_show);
}
//如果内容里包含 MarkDown 的特定标记, 则自动将标记移除
if( strpos($note_content_to_show, MARK_DOWN_TYPE) === 0 ){
$page_type = 'md_note';
$note_content_to_show = substr($note_content_to_show, strlen(MARK_DOWN_TYPE));
}
if( @$_GET['html'] === 'yes' ){
$page_type = 'html';
}
}else{
//如果是新记事本
$page_type = 'select_note_type';//默认值
if( isset($_POST['type']) ){
$IsMd = $_POST['type'] === 'md';//是否为新建 MarkDown 格式的记事本
$note_content_to_show = $IsMd ? (MARK_DOWN_TYPE . '#MarkDown格式记事本
- - -
在**右侧**编辑记事本,会在**左侧**显示效果。') : '';
//创建新新文件
if( !$use_sql ){
$note_file = NOTE_DATA . $noteId;
if( $IsMd ){
file_put_contents($note_file, $note_content_to_show);
}else{
touch($note_file);
}
}else{
mysqli_query($notesql, "INSERT INTO ".$sql_table." (ID, passwd, content) VALUES ('".$noteId."','','".$note_content_to_show."')");
}
$passwd = false;
$page_type = $IsMd ? 'md_note' : 'text_note';
//因为MarkDown格式的内容开头有特写的标记,所以此处要将它移除
if($IsMd){
$note_content_to_show = substr($note_content_to_show, strlen(MARK_DOWN_TYPE));
}
}
}
//下载时的 文件名
$filename = '记事本-' . $noteId . '.' . (( $page_type == 'md_note' ) ? 'md' : 'txt');
}
?>
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title>记事本 › <?php echo $noteTitle; ?></title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAABWVBMVEVhVTVSSjVORzROSDRQSTVfVDVcUTVLRTRHQTRHQjRIQzRZUDVgVDVPSDRMRjRdUjXIojrGoTvFoDvHojv8yD37yT37yD37yD32xT72xT71xT71xT7QsVPOsVTOsFTPsVPwwULvwkLvwULvwkLRsVLPsVPPsVPQsVPqvkXpv0XpvkXpvkXWtFDVtFDUs1DVtFDguUrgukrfuUrfuUrfuUrVtFDUtFDUtFDrv0TrwETqv0Tqv0T6xzz6yDz5vDv3rDr6yDz6xzz6xzz6xzxLRDRLRTTFmTrFjznFoTvFoDr6vjz4rjv7yT37yD30uz3yqzz2xT71xT7NqFPLm1LOsFTuuEHsqD/vwkLvwULOqFLMm1HPsVPotUTmpkPpv0XpvkXTq0/Snk7UtFDUs1DesEndokjfukrfuUresErcokjfuUvTq1DRnU7UtFHptUPop0LrwETqv0T////ZQ5XYAAAAAWJLR0QAiAUdSAAAAAlwSFlzAAAN1wAADdcBQiibeAAAAAd0SU1FB98FCA0SEE9zUCEAAAA2SURBVBjTY+BEAwwYAqKi7qLIAFNAUNBdEBlg1yIGBXi0iCEABbbg14JkB0QLlOPo6OgkKgoAn/UWJhIEn78AAAAASUVORK5CYII=" type="image/x-icon" rel="icon" />
<script src="https://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script>
<?php if ( $page_type == 'html' ) : ?>
<script src="https://cdn.bootcss.com/markdown.js/0.5.0/markdown.min.js"></script>
<script src="https://cdn.bootcss.com/prism/0.0.1/prism.min.js"></script>
<link href="https://cdn.bootcss.com/prism/0.0.1/prism.min.css" rel="stylesheet">
<script src="//cdn.bootcss.com/mathjax/2.5.3/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<style type="text/css">
body{
font-size: 16px;
font-family: Microsoft Yahei,Hiragino Sans GB,WenQuanYi Micro Hei,sans-serif !important;
line-height: 27px;
background: #eee;
width: 1100px;
margin: 0px auto 10px auto;
color: #34495E;
}
h1{
color: #3498db;
font-size: 30px;
}
a{
color: #3498DB;
text-decoration: none;
}
img{
max-width: 100%;
}
#html-box{
box-shadow: 0px 2px 6px rgba(100, 100, 100, 0.3);
background-color: #fff;
padding: 20px;
margin: 50px 0;
}
#html-box p{
margin: 5px 0 15px 0;
}
#html-box h2{
border-bottom:solid 2px #ddd;
margin-bottom: 5px;
padding-bottom: 2px;
}
#html-box blockquote{
border-left: 5px solid #ccc;
padding: 5px 0 1px 10px;
margin: 16px 0;
background-color: #F2F2F5;
}
#html-box pre{
margin: 5px 0;
padding: 5px;
background-color: #F2F2F5;
font-family: "Menlo","Liberation Mono","Consolas","DejaVu Sans Mono","Ubuntu Mono","Courier New","andale mono","lucida console",monospace !important;
}
#html-box pre code{
background-color: #F2F2F5;
overflow: auto;
}
#html-box hr{
border: 1px solid #888;
}
#html-box code{
line-height: 16px;
background-color: #ddd;
padding: 2px 5px;
margin: 0px 2px;
font-family: "Menlo","Liberation Mono","Consolas","DejaVu Sans Mono","Ubuntu Mono","Courier New","andale mono","lucida console",monospace !important;
}
#note-md-show .MathJax_Display,#note-md-show .MathJax_Preview .MJXc-math{
padding: 10px 0;
background-color: #F2F2F5;
display: block;
}
#note-md-show .MathJax_Preview span{
font-size: 16px !important;
}
:focus {
border: none;
outline: 0;
}
::selection {
background:#3498DB;
color:#fff;
}
::-moz-selection {
background:#3498DB;
color:#fff;
}
::-webkit-selection {
background:#3498DB;
color:#fff;
}
/* 设置滚动条的样式 */
::-webkit-scrollbar {
width: 10px;
}
/* 滚动槽 */
::-webkit-scrollbar-track {
background-color: #eee;
}
/* 滚动条滑块 */
::-webkit-scrollbar-thumb {
background: rgba(0,0,0,0.1);
}
::-webkit-scrollbar-thumb:hover {
background: rgba(0,0,0,0.3);
}
h1,h2,h3,h4,h4,h5,h6{
font-weight:100;
margin: 0;
}
@media screen and (max-width: 1140px){
body{
margin: 0 20px 0 20px;
width: auto;
}
}
</style>
<div id="html-box"><?php echo htmlentities($note_content_to_show); ?></div>
<script type="text/javascript">
document.getElementById("html-box").innerHTML = markdown.toHTML($("#html-box").text());
$("#html-box a").attr("target","_blank");
codes=$("#html-box pre code");
langs={"[html code]":"language-markup","[javascript code]":"language-javascript","[js code]":"language-javascript","[css code]":"language-css",
"[python code]":"language-python","[php code]":"language-php","[perl code]":"language-perl",
"[c code]":"language-c","[c++ code]":"language-cpp","[c# code]":"language-csharp",
"[java code]":"language-java","[go code]":"language-go","[ruby code]":"language-ruby",
"[markdown code]":"language-markdown","[less code]":"language-less","[ini code]":"language-ini"
}
for(var x=0;x<codes.length;x++){
first_line=codes[x].innerHTML.split('\n',1)[0];
first_line_lower=first_line.toLowerCase()
codes[x].className="language-markup";
var l='';
for(l in langs){
if(first_line_lower==l){
codes[x].innerHTML=codes[x].innerHTML.split(first_line+'\n',2)[1];
codes[x].className=langs[l];
}
}
}
Prism.highlightAll();
</script>
<?php exit(); endif; ?>
<script type="text/javascript">
var is_passwd_set_show = false;
var is_need_save = false;
var is_pic_loaded = false;
$(document).ready(function(){
$("#note-btns-save-form").hide();
$("#note-btns-save-ajax").show();
$("#note-btns-save-ajax").css({"background-color":"#ccc","cursor":"default","padding":"9px 20px"}).html("已保存");
$('#note-btns-setpasswd-form-btn').click(function(){
if(($('#note-btns-setpasswd-form-input').val()+'').length < 6){
alert('请输入密码, 长度至少六位!');
return false;
}
});
var winh=window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight;
var winw=window.innerWidth
|| document.documentElement.clientWidth
|| document.body.clientWidth;
$("#note-main-form-div").height(winh-135);
<?php if ( $page_type == 'md_note' ) : ?>
if(winw<=1140){
var box_width = winw-60;
}else{
var box_width = $("#note-main-form-div").width();
}
var edit_width = box_width / 2;
$("#note-md-show").height(winh-145).width( box_width - edit_width - 35 );
$("#note-md-edit").height(winh-145).width(edit_width).css("margin-left",box_width - edit_width - 10);
$("#note-md-move").height(winh-135).css("left",winw - (winw - box_width)/2 - edit_width - 20);
MathJax.Hub.Config({
showProcessingMessages: false
});
<?php endif; ?>
});
<?php
if($JavaScript !== ''){
echo $JavaScript;
}?>
window.onresize = function () {
var winh=window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight;
var winw=window.innerWidth
|| document.documentElement.clientWidth
|| document.body.clientWidth;
if( is_passwd_set_show ){
$("#note-main-form-div").height(winh-192);
}else{
$("#note-main-form-div").height(winh-135);
}
$("#note-btns-setpasswd-form-input").width($("#note-btns-passwdset-form").width()-110);
<?php if ( $page_type == 'md_note' ) : ?>
if(winw<=1140){
var box_width = winw-60;
}else{
var box_width = $("#note-main-form-div").width();
}
var edit_width = box_width / 2;
if( is_passwd_set_show ){
$("#note-md-show").height(winh-202).width( box_width - edit_width - 35 );
$("#note-md-edit").height(winh-202).width(edit_width).css("margin-left",box_width - edit_width - 10);
$("#note-md-move").height(winh-192).css("left",winw - (winw - box_width)/2 - edit_width - 20);
}else{
$("#note-md-show").height(winh-145).width( box_width - edit_width - 35 );
$("#note-md-edit").height(winh-145).width(edit_width).css("margin-left",box_width - edit_width - 10);
$("#note-md-move").height(winh-135).css("left",winw - (winw - box_width)/2 - edit_width - 20);
}
<?php endif; ?>
}
function psaawd_set_display(){
if( !is_passwd_set_show ){
$('#note-btns-passwdset-form').slideDown(500);
$('#note-main-form-div').animate({height:'-=57px'},500);
$("#note-btns-setpasswd-form-input").width($("#note-btns-passwdset-form").width()-110);
is_passwd_set_show = true;
<?php if ( $page_type == 'md_note' ) : ?>
$("#note-md-edit").animate({height:'-=57px'},500);
$("#note-md-show").animate({height:'-=57px'},500);
$("#note-md-move").animate({height:'-=57px'},500);
<?php endif; ?>
}else{
$('#note-btns-passwdset-form').slideUp(500);
$('#note-main-form-div').animate({height:'+=57px'},500);
is_passwd_set_show = false;
<?php if ( $page_type == 'md_note' ) : ?>
$("#note-md-edit").animate({height:'+=57px'},500);
$("#note-md-show").animate({height:'+=57px'},500);
$("#note-md-move").animate({height:'+=57px'},500);
<?php endif; ?>
}
}
function id_set_display(){
if( !is_passwd_set_show ){
$('#note-btns-idset-form').slideDown(500);
$('#note-main-form-div').animate({height:'-=57px'},500);
$("#note-btns-setid-form-input").width($("#note-btns-idset-form").width()-110);
is_passwd_set_show = true;
<?php if ( $page_type == 'md_note' ) : ?>
$("#note-md-edit").animate({height:'-=57px'},500);
$("#note-md-show").animate({height:'-=57px'},500);
$("#note-md-move").animate({height:'-=57px'},500);
<?php endif; ?>
}else{
$('#note-btns-idset-form').slideUp(500);
$('#note-main-form-div').animate({height:'+=57px'},500);
is_passwd_set_show = false;
<?php if ( $page_type == 'md_note' ) : ?>
$("#note-md-edit").animate({height:'+=57px'},500);
$("#note-md-show").animate({height:'+=57px'},500);
$("#note-md-move").animate({height:'+=57px'},500);
<?php endif; ?>
}
}
function ajax_save(){
if( is_need_save ){
$("#note-btns-save-ajax").css({"background-color":"#ccc","cursor":"wait","padding":"9px 20px"}).html("正在保存");
$.post("<?php echo_note_url(); ?>",
{
ajax_save:"yes",
the_note:$("textarea").val(),
note_type:"<?php echo $page_type ?>"
},
function(data,status){
$("#note-btns-save-ajax").css({"background-color":"#ccc","cursor":"default","padding":"9px 20px"}).html("已保存");
is_need_save = false;
});
}
}
function note_change(){
$("#note-btns-save-ajax").css({"background-color":"#3498DB","cursor":"pointer","padding":"9px 20px"}).html("保存");
is_need_save = true;
}
function other_dev_show(){
$('#note-otherdev-background-div').fadeIn();
if(!is_pic_loaded){
$('#note-otherdev-img-add').after("<img alt='Loading...' src='https://qr.liantu.com/api.php?m=0&fg=222222&w=240&text=<?php echo 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>'>");
is_pic_loaded = true;
}
}
function download_note(){
$('#download-a').attr({
"download" : "<?php echo $filename; ?>",
"href" : "data:text/plain,"+$("textarea").val().replace(/\n/g,"%0a").replace(/\#/g,"%23")
});
document.getElementById("download-a").click();
}
window.onbeforeunload = onbeforeunload_handler;
function onbeforeunload_handler(){
if(is_need_save){
var warning="您的记事本还没有保存,请确认您是否真的要离开。";
return warning;
}
}
$(document).keydown(function(e){
if( e.ctrlKey && e.which == 83 ){
ajax_save();
return false;
}
});
<?php if ( $page_type == 'md_note' || $page_type == 'text_note' ) : ?>
(function($, undefined) {
$.fn.getCursorPosition = function() {
var el = $(this).get(0);
var pos = 0;
if ('selectionStart' in el) {
pos = el.selectionStart;
} else if ('selection' in document) {
el.focus();
var Sel = document.selection.createRange();
var SelLength = document.selection.createRange().text.length;
Sel.moveStart('character', -el.value.length);
pos = Sel.text.length - SelLength;
}
return pos;
}
})(jQuery);
var is_focus = true;
$(document).ready(function(){
the_textarea = $('textarea');
the_textarea.focus(function(){is_focus=true;});
the_textarea.blur(function(){is_focus=false;});
});
$(document).keydown(function(e){
the_textarea = $('textarea');
if(is_focus){
if( e.which == 9 ){
var cursor_pos = the_textarea.getCursorPosition();
the_textarea.val(the_textarea.val().slice(0,cursor_pos)+'\t'+the_textarea.val().slice(cursor_pos));
<?php if ( $page_type == 'md_note' ) : ?>
document.getElementById("note-md-edit").focus();
document.getElementById("note-md-edit").setSelectionRange(cursor_pos+1,cursor_pos+1);
<?php else : ?>
document.getElementById("note-text-edit").focus();
document.getElementById("note-text-edit").setSelectionRange(cursor_pos+1,cursor_pos+1);
<?php endif; ?>
return false;
}
if( e.which == 13 ){
var cursor_pos = the_textarea.getCursorPosition();
var notelines = the_textarea.val().slice(0,cursor_pos).split('\n');
var listline = notelines[notelines.length-1];
var ntab = 0,nsp = 0;
while(listline[ntab]=='\t'){
ntab+=1;
}
while( listline[nsp]==' ' && listline[nsp+1]==' ' && listline[nsp+2]==' ' && listline[nsp+3]==' '){
nsp+=4;
}
the_textarea.val(the_textarea.val().slice(0,cursor_pos)+'\n'+the_textarea.val().slice(cursor_pos));
for (i=ntab; i>0; i--){
the_textarea.val(the_textarea.val().slice(0,cursor_pos+1)+'\t'+the_textarea.val().slice(cursor_pos+1));
}
for (i=nsp; i>0; i--){
the_textarea.val(the_textarea.val().slice(0,cursor_pos+1)+' '+the_textarea.val().slice(cursor_pos+1));
}
<?php if ( $page_type == 'md_note' ) : ?>
document.getElementById("note-md-edit").focus();
document.getElementById("note-md-edit").setSelectionRange(cursor_pos+ntab+nsp+1,cursor_pos+ntab+nsp+1);
<?php else : ?>
document.getElementById("note-text-edit").focus();
document.getElementById("note-text-edit").setSelectionRange(cursor_pos+ntab+nsp+1,cursor_pos+ntab+nsp+1);
<?php endif; ?>
return false;
}
}
});
<?php endif; ?>
</script>
<style type="text/css">
/***** 全局 *****/
body{
color: #555;
font-size: 14px;
font-family: Microsoft Yahei,Hiragino Sans GB,WenQuanYi Micro Hei,sans-serif !important;
line-height: 27px;
background: #eee;
width: 1200px;
margin: 0px auto 10px auto;
}
a,input,button{
outline: none !important;
-webkit-appearance:none;
border-radius: 0;
font-family: '文泉驛正黑','Microsoft yahei UI','Microsoft yahei','微软雅黑',"Lato",Helvetica,Arial,sans-serif !important;
}
.btn::-moz-focus-inner,input::-moz-focus-inner{
border-color:transparent!important;
}
:focus {
border: none;
outline: 0;
}
::selection {
background:#3498DB;
color:#fff;
}
::-moz-selection {
background:#3498DB;
color:#fff;
}
::-webkit-selection {
background:#3498DB;
color:#fff;
}
/* 设置滚动条的样式 */
::-webkit-scrollbar {
width: 10px;
}
/* 滚动槽 */
::-webkit-scrollbar-track {
background-color: #eee;
}
/* 滚动条滑块 */
::-webkit-scrollbar-thumb {
background: rgba(0,0,0,0.1);