-
Notifications
You must be signed in to change notification settings - Fork 0
/
editor.php
147 lines (129 loc) · 3.9 KB
/
editor.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
<?php
$lang_code="en";
$blog_title="bare minimum blog";
$blog_one_liner="barebone very minimal php blog";
$contact="https://github.com/dansdrivers";
$email="uremail@email.com";
$homepage="../";
$news_link="http://news.google.com";
$twitter="https://www.twitter.com";
$summary_length=300;
?>
<html>
<head>
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="../index.css">
<link rel="shortcut icon" type="image/x-icon" href="../favicon.ico">
<link rel="top" title="<?=$blog_title;?>" href="index.php">
<meta name="robots" content="noindex, nofollow">
<title>
<?=$blog_title;?> Editor
</title>
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
<script>tinymce.init({ selector:'textarea' });</script>
<style type="text/css">
@import "../index.css";
</style>
</head>
<body>
<h1>Create and edit blog entries</h1>
<p>This is a very simple blog machine. On the first line, choose
"Formats -> Headings -> Heading 1" - the text will
become the title of your blog post.</p>
<?php
function getTextBetweenTags($string, $tagname)
{
$pattern = "/<$tagname ?.*>(.*)<\/$tagname>/";
preg_match($pattern, $string, $matches);
return $matches[1];
}
$title='';
if(isset($_POST["entry"])){
$title = str_replace(" ","_",'.'.getTextBetweenTags($_POST["entry"],"h1"));
//echo $title;
}
if(!(empty($_POST["btnVal"]))){
if($_POST["btnVal"] == "New"){
if(file_exists(date("dmY")."$title.blog")){
unlink(date("dmY")."$title.blog");
} else {
$logFile = fopen("../log", "a");
fwrite($logFile, "Error deleting old blog."."\n");
fclose($logFile);
}
}
if($_POST["btnVal"] == "Save" && !(empty($_POST["entry"]))){
$toWrite = $_POST["entry"];
$file = fopen(date("dmY")."$title.blog", "w+");
fwrite($file, $toWrite);
fclose($file);
unlink(date("dmY").".blog");
}
}
if(!(empty($_POST["entry"]))){
$tarea = $_POST["entry"];
} elseif(file_exists(date("dmY")."$title.blog")){
$tarea = file_get_contents(date("dmY")."$title.blog");
} elseif($_POST["btnVal"] == "Edit" && !(empty($_POST["entryname"] ) ) ){
$tarea = file_get_contents($_POST["entryname"]);
} else {
$tarea = "";
}
?>
<script type="text/javascript">
function insert(ins,entry) {
if(ins == "a"){
var tmp = prompt("URL?","");
entry.value+='<a href='+tmp+'>';
}
if(ins == "h"){
var tmp = prompt("Size? 1-6","");
entry.value+='<h'+tmp+'>';
}else{
entry.value+='<'+ins+'>';
}
entry.focus();
if(ins.indexOf("/")!=-1){
end++;
}else{
start++;
}
}
var start = 0;
var end = 0;
</script>
<form method="post" action="index.php">
<input type="submit" value="New" name="btnVal" onclick="entry.value='';"/>
<input type="submit" value="Save" name="btnVal"/>
<textarea name="entry" style="height:400px"><?php echo $tarea; ?></textarea>
</form>
<h2>Manage blog entries</h2>
<?php
if(!(empty($_POST["btnVal"]))){
if($_POST["btnVal"] == "Delete"){
if(isset($_POST["entryname"])){
unlink($_POST["entryname"]);
}
}
}
$entryDir = opendir("./");
$entrys = array();
while (false !== ($file = readdir($entryDir))) {
$lastname = substr(strrchr($file, "."), 1);
if($lastname == "blog" && $lastname != "php" && $file != "." && $file != ".."){
$entrys[filemtime("$file")] = $file;
}
}
krsort($entrys);
foreach($entrys as $entry){
echo '<form method="post" action="index.php">';
echo '<input type="hidden" name="entryname" value="'.$entry.'"/>';
$exploded = explode(".",$entry);
$name_string = str_replace("_"," ",$exploded[1]);
echo "$name_string <input type=\"submit\" name=\"btnVal\" value=\"Delete\"/>";
echo "<input type=\"submit\" name=\"btnVal\" value=\"Edit\"/>";
echo "</form>";
}
?>
</body>
</html>