| 1 |
lars |
1 |
<?
|
|
|
2 |
|
|
|
3 |
//abitwhizzy.php - whizzywig web page editor, demonstrating whizzywig.js
|
|
|
4 |
//Copyright © 2005, John Goodman - john.goodman(at)unverse.net *date 061204
|
|
|
5 |
//This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. A copy of the GNU General Public License can be obtained at: http://www.gnu.org/licenses/gpl.html
|
|
|
6 |
|
|
|
7 |
if (!isset($_SERVER))
|
|
|
8 |
{
|
|
|
9 |
$_GET = &$HTTP_GET_VARS;
|
|
|
10 |
$_POST = &$HTTP_POST_VARS;
|
|
|
11 |
$_ENV = &$HTTP_ENV_VARS;
|
|
|
12 |
$_SERVER = &$HTTP_SERVER_VARS;
|
|
|
13 |
$_COOKIE = &$HTTP_COOKIE_VARS;
|
|
|
14 |
$_REQUEST = array_merge($_GET, $_POST, $_COOKIE);
|
|
|
15 |
}
|
|
|
16 |
$f = $_REQUEST['f'];
|
|
|
17 |
$t = $_REQUEST['t'];
|
|
|
18 |
|
|
|
19 |
//CONFIGURE HERE ====================================================================
|
|
|
20 |
if (!$password) $password= ""; //can leave password as "" if you are using .htaccess to protect abitwhizzy
|
|
|
21 |
if (!$whizzywig) $whizzywig = "whizzery/whizzywig.js"; //path to whizzywig.js required
|
|
|
22 |
if (!$cssFile) $cssFile= "whizzery/simple.css"; //choose your stylesheet, or set to ""
|
|
|
23 |
if (!$buttonPath) $buttonPath = "whizzery/buttons/"; //toolbar images live here. "" for text buttons
|
|
|
24 |
if (!$imageBrowse) $imageBrowse = "whizzery/whizzypic.php"; // "" for no image browser
|
|
|
25 |
if (!$linkBrowse) $linkBrowse = "whizzery/whizzylink.php"; // "" for no link browser
|
|
|
26 |
if (!$toolbar) $toolbar = "formatblock bold italic color bullet number image link table clean html"; //try "all" if you need more
|
|
|
27 |
if (!$editarea) $editarea = "width:100%; height:550px";
|
|
|
28 |
if (!$xhtml) $xhtml = ""; //path to xhtml converter, or set to "" for HTML 4.01. Use appropriate header in $top.
|
|
|
29 |
if (!$extensions) $extensions = "/(html|htm)$/"; //file extensions to consider for edit (in the brackets|to separate)
|
|
|
30 |
//LEAVE THESE
|
|
|
31 |
if ($xhtml) $doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
|
32 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
33 |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
|
|
|
34 |
else $doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
|
35 |
<html>';
|
|
|
36 |
//HTML TEMPLATE: Use these 2 variables ($top and $tail) to wrap the generated HTML in your own template.
|
|
|
37 |
if (!$top) $top = "$doctype\n<head>\n<title>$t</title>\n<link rel='stylesheet' type='text/css' href='$cssFile' >\n</head>\n<body>";
|
|
|
38 |
if (!$tail) $tail = "<form style='float:right' action='".$_SERVER['SCRIPT_NAME']."'><input type='hidden' name='f' value='$f'><input type='submit' style='font-size:xx-small' value='Edit'></form></body>\n</html>";
|
|
|
39 |
//END CONFIG ========================================================================
|
|
|
40 |
if (preg_match("#^\.|\.\.\/|^\/#",$f)) die ("Not allowed!");
|
|
|
41 |
if ($_REQUEST['save']) { //write page and go there
|
|
|
42 |
if ($_REQUEST['p'] != $password) die ("<h1>Wrong password: not saved.</h1>Click the Back button to try again. ");
|
|
|
43 |
$edited = $_REQUEST['edited'];
|
|
|
44 |
if ($f == "top.shtml" || $f == "tail.shtml") $html = stripslashes($edited);
|
|
|
45 |
else {
|
|
|
46 |
$html = $top."<!--#include virtual='top.shtml'-->";
|
|
|
47 |
$html .= stripslashes($edited);
|
|
|
48 |
$html .= "<!--#include virtual='tail.shtml'-->".$tail;
|
|
|
49 |
}
|
|
|
50 |
$fsave = fopen($f, 'w'); //save the edited file
|
|
|
51 |
fwrite($fsave, $html);
|
|
|
52 |
fclose($fsave);
|
|
|
53 |
header("Location: $f");
|
|
|
54 |
} else if (file_exists($f)) {
|
|
|
55 |
$fedit = fopen($f, 'r'); //open the file for edit
|
|
|
56 |
$content = fread($fedit, filesize($f));
|
|
|
57 |
$start = strpos($content,"<!--#include virtual='top.shtml'-->") ? "/.*<!--#include virtual='top.shtml'-->/" : "|.*<body[^>]*>|iU";
|
|
|
58 |
$stop = strpos($content,"<!--#include virtual='tail.shtml'-->") ? "/<!--#include virtual='tail.shtml'-->.*/" : "|</body>.*$|iU";
|
|
|
59 |
$content = preg_replace($start,'',$content);
|
|
|
60 |
$content = preg_replace($stop,'',$content);
|
|
|
61 |
fclose($fedit);
|
|
|
62 |
preg_match('|<title>(.*)</title>|i',$content, $match);
|
|
|
63 |
$t = $match[1]; //grab the title
|
|
|
64 |
} //now show form
|
|
|
65 |
//===================================================================================
|
|
|
66 |
?>
|
|
|
67 |
<html>
|
|
|
68 |
<head>
|
|
|
69 |
<title>aBitWhizzy: the Whizzywig page editor v7</title>
|
|
|
70 |
<script language="JavaScript" type="text/javascript" src="<?= $whizzywig ?>"></script>
|
|
|
71 |
<? if ($xhtml) echo '<script language="JavaScript" type="text/javascript" src="'.$xhtml.'>"></script>'; ?>
|
|
|
72 |
<script language="JavaScript" type="text/javascript">
|
|
|
73 |
function insistF() { //check filename given before save
|
|
|
74 |
if (document.getElementById("f").value == "") {
|
|
|
75 |
alert("Please supply a filename");
|
|
|
76 |
document.getElementById("f").style.backgroundColor="yellow";
|
|
|
77 |
document.getElementById("f").focus();
|
|
|
78 |
return false;
|
|
|
79 |
}else return true;
|
|
|
80 |
}
|
|
|
81 |
</script>
|
|
|
82 |
<meta name="robots" content="noindex,nofollow">
|
|
|
83 |
</head>
|
|
|
84 |
<body>
|
|
|
85 |
<form name="Whizzy" action="<? $_SERVER['SCRIPT_NAME']; ?>" method="post" onsubmit="return insistF()">
|
|
|
86 |
<label for="f">Filename: </label><input name="f" id="f" type="text" value="<?=$f;?>">
|
|
|
87 |
<select onchange="document.getElementById('f').value=this.options[this.selectedIndex].value;" style="vertical-align:middle">
|
|
|
88 |
<option value="">or choose:</option>
|
|
|
89 |
<?
|
|
|
90 |
$dir = opendir('./');
|
|
|
91 |
while ($fil = readdir($dir)){
|
|
|
92 |
$files[] = $fil;
|
|
|
93 |
}
|
|
|
94 |
closedir($dir);
|
|
|
95 |
sort($files);
|
|
|
96 |
foreach ($files as $fil){
|
|
|
97 |
if (preg_match($extensions,$fil)){
|
|
|
98 |
echo "<option value='$fil'>$fil</option>\n"; //it's a potential link
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
?>
|
|
|
102 |
</select>
|
|
|
103 |
<input type="submit" name="open" value="Open">
|
|
|
104 |
<label for="t">Title: </label><input id="t" name="t" type="text" size="30" value="<?=$t;?>">
|
|
|
105 |
<? if ($password) { ?>
|
|
|
106 |
<br><label for="p">Password: </label><input id="p" name="p" type="password" size="8" onkeypress="document.getElementById('save').style.display='inline'">
|
|
|
107 |
<input type="submit" name="save" id="save" value="Save" style="display:none">
|
|
|
108 |
<? } else echo '<input type="submit" name="save" value="Save">'; ?>
|
|
|
109 |
<textarea name="edited" id="edited" rows="25" cols="70" style="<?=$editarea;?>">
|
|
|
110 |
<?=$content;?>
|
|
|
111 |
</textarea>
|
|
|
112 |
<script language="JavaScript" type="text/javascript">
|
|
|
113 |
buttonPath = "<?=$buttonPath;?>";
|
|
|
114 |
cssFile = "<?=$cssFile;?>"
|
|
|
115 |
imageBrowse = "<?=$imageBrowse;?>";
|
|
|
116 |
linkBrowse = "<?=$linkBrowse;?>";
|
|
|
117 |
makeWhizzyWig("edited", "<?=$toolbar;?>");
|
|
|
118 |
</script>
|
|
|
119 |
</form>
|
|
|
120 |
<p style="font-size:xx-small">
|
|
|
121 |
<a href="http://www.unverse.net/abitwhizzy">aBitWhizzy</a>:
|
|
|
122 |
More about this free editor from <a href="http://www.unverse.net">unverse.net</a>
|
|
|
123 |
</p>
|
|
|
124 |
</body>
|
|
|
125 |
</html>
|