I am trying to add CKeditor to this script. It works fine when I add openwysiwyg to it. but i just cant seem to get ckeditor to work. I added this to the head
<head><script src="/ckeditor/ckeditor.js"></script> </head>
and this to ---> echo " <script>CKEDITOR.replace( \'HtmlEditor3\' );</script>
the body. i get this Parse error: syntax error, unexpected on line 285
<?php
// *************************************** //
// CHIP //
// //
// *************************************** //
define('ADMIN_PASS', 'password');
$upload_folder = "./images/";
$max_size = 200000;
$database = './news_db.php';
$admin_password = isset($_COOKIE['admin_password']) ? $_COOKIE['admin_password'] : '';
if (empty($admin_password))
{
if (isset($_POST['admin_password']))
{
$admin_password = md5($_POST['admin_password']);
if ($admin_password == md5(ADMIN_PASS))
{
setcookie('admin_password', $admin_password);
}
}
}
(is_writable($database)) ? include($database): die ($database . ' is not writable or does not exist! Please read the manual for more details.');
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
$index = isset($_REQUEST['index']) ? $_REQUEST['index'] : -1;
$is_admin = ($admin_password == md5(ADMIN_PASS));
$is_modified = false;
$count = sizeof($news);
if ($action == 'logout')
{
setcookie('admin_password', '');
unset($_COOKIE['admin_password'], $admin_password);
header("Location: ".basename(__FILE__));
exit;
}
else
if ($action == 'save')
{
$text = get_magic_quotes_gpc() ? trim($_POST['text']) : addslashes(trim($_POST['text']));
$text = str_replace("\\'", "'", $text);
if ($index >= 0 && $index < $count)
{
$news[$index] = $text;
}
else
{
$news[$count] = $text;
$count++;
}
$is_modified = true;
}
else
if ($action == 'movedown')
{
if ($index > 0 && $index < $count)
{
$temp = $news[$index-1];
$news[$index-1] = $news[$index];
$news[$index] = $temp;
$is_modified = true;
}
else
{
header('Location: '.basename(__FILE__));
exit;
}
}
else
if ($action == 'moveup')
{
if ($index >= 0 && $index < ($count-1))
{
$temp = $news[$index+1];
$news[$index+1] = $news[$index];
$news[$index] = $temp;
$is_modified = true;
}
else
{
header('Location: '.basename(__FILE__));
exit;
}
}
else
if ($action == 'delete')
{
$count--;
for ($i=$index; $i < $count; $i++)
{
$news[$i] = $news[$i+1];
}
$is_modified = true;
}
if ($is_modified && $is_admin)
{
$content = "<?php\r\n";
for ($i=0; $i < $count; $i++)
{
$content .= '$news['.$i.'] = '."'".$news[$i]."';\r\n";
}
$content .= "?>";
$content = str_replace('\"', '"', $content);
$file = fopen($database, "wb");
fputs($file, $content);
fclose($file);
header('Location: '.basename(__FILE__));
exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script src="/ckeditor/ckeditor.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>News Writer</title>
<style type="text/css">
<!--
body
{
font-size: 11px;
font-family: Verdana;
font-weight: normal;
text-decoration: none;
color: #212121;
}
-->
</style>
</head>
<body bgcolor="#F7F6F3" style="margin:0px 0px 0px 0px">
<?php
if ($action == 'admin')
{
echo "<center>\n";
echo "Administrator login<br>\n";
echo "<form method=\"post\" action=\"" .basename(__FILE__) . "\">\n";
echo "<input type=\"password\" name=\"admin_password\" size=\"20\" />\n";
echo "<input type=\"submit\" value=\"Login\" name=\"submit\" />\n";
echo "</form>\n";
echo "</center>\n";
}
else
if ($action == 'image')
{
if ($is_admin)
{
echo "<center>\n";
echo "Upload image<br>\n";
echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"" .basename(__FILE__) . "\">\n";
echo "<input type=\"hidden\" name=\"action\" value=\"upload\" />\n";
echo "Image filename: <input type=\"file\" name=\"filename\"><br>\n";
echo "<input type=\"submit\" value=\"Upload\">\n";
echo "</form>\n";
echo "<a href=\"" .basename(__FILE__). "\">Back to overview</a>\n";
echo "</center>\n";
}
}
else
if ($action == 'imagelist')
{
if ($is_admin)
{
$ext_to_show = array("gif","jpg","jpeg","jpe","pjpeg");
$files_to_show = array();
if ($handle = opendir($upload_folder))
{
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != ".." && is_file($upload_folder.$file))
{
$ext = (pathinfo($upload_folder.$file));
if(in_array(strtolower($ext['extension']), $ext_to_show))
{
$files_to_show[] = $file;
}
}
}
closedir($handle);
}
if(empty($files_to_show))
{
echo "No files to show.";
}
else
{
sort($files_to_show);
foreach ($files_to_show as $file)
{
echo '<br><img src="'.$upload_folder.$file.'"alt="" align="middle" border="0" style="width:120px;height:90px;">'."\n";
echo '<input type="text" size="30" value="'.$upload_folder.$file.'"><br>'."\n";
}
}
echo "</body></html>";
exit;
}
}
else
if ($action == 'upload')
{
echo "<center>\n";
if (isset($_FILES['filename']))
{
$name = $_FILES['filename']['name'];
$type = $_FILES['filename']['type'];
$tmp_name = $_FILES['filename']['tmp_name'];
$error = $_FILES['filename']['error'];
$size = $_FILES['filename']['size'];
switch ($error)
{
case 0:
if ($type == 'image/gif' || $type == 'image/jpeg' || $type == 'image/pjpeg')
{
if ($size <= $max_size)
{
if (!file_exists($upload_folder. $name))
{
if (move_uploaded_file($tmp_name, $upload_folder. $name))
{
echo "Image succesfully uploaded!<br><br>\n";
echo "Filename:<br>". $upload_folder. $name. "<br>\n";
}
else
{
echo "Error: Upload failed, please verify the folder's permissions.\n";
}
}
else
{
echo "Error: The image already exists.\n";
}
}
else
{
echo "Error: The image is too big.\n";
}
}
else
{
echo "Error: Wrong file type, please only use jpg or gif images.\n";
}
break;
case 1:
echo "Error: The uploaded file exceeds the 'upload_max_filesize' directive.\n";
break;
case 2:
echo "Error: The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.\n";
break;
case 3:
echo "Error: The uploaded file was only partially uploaded.\n";
break;
case 4:
echo "Error: No file was uploaded.\n";
break;
case 6:
echo "Error: Missing a temporary folder.\n";
break;
case 7:
echo "Error: Failed to write file to disk.\n";
break;
case 8:
echo "Error: File upload stopped by extension.\n";
break;
}
}
else
{
echo "Error: No filename specified!<br>\n";
}
echo "<a href=\"" .basename(__FILE__). "\"><br><br>Back to overview</a>\n";
echo "</center>\n";
exit;
}
else
if ($action == 'edit' || $action == 'new')
{
if ($is_admin)
{
$text = ($index >= 0) ? $news[$index] : '';
echo "<form action=\"" .basename(__FILE__) . "\" method=\"POST\">\n";
echo "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"4\" border=\"0\">\n";
echo "<tr>\n";
echo "<td>\n";
echo " <textarea id=\"HtmlEditor3\" style=\"width:100%;height:250\" name=\"text\">".$text."</textarea>\n";
echo " <script>CKEDITOR.replace( \'HtmlEditor3\' );</script>
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td align=left>\n";
echo " <input type=\"hidden\" name=\"action\" value=\"save\" />\n";
echo " <input type=\"hidden\" name=\"index\" value=\"" . $index . "\" />\n";
echo " <input type=\"submit\" value=\"Save\" />\n";
echo " <input type=\"button\" value=\"Back to overview\" onclick=\"window.location='" .basename(__FILE__) . "'\" />\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</form>\n";
}
}
else
{
if ($is_admin)
{
echo "<a href=\"".basename(__FILE__)."?action=new\">Create new item</a> ";
echo "<a href=\"".basename(__FILE__)."?action=image\">Upload image</a> ";
echo "<a href=\"".basename(__FILE__)."?action=imagelist\" onClick=\"window.open('','img_list','scrollbars=yes, resizable=yes, width=400, height=300')\" target=\"img_list\">Image List</a> ";
echo "<a href=\"".basename(__FILE__)."?action=logout\">Logout</a><br><br>\n";
}
if ($count > 0)
{
for ($i=$count-1; $i >= 0; $i--)
{
echo $news[$i];
echo "<br>";
echo "<br>\n";
if ($is_admin)
{
echo "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n";
echo "<tr>\n";
echo "<td>\n";
echo " <table cellpadding=\"0\" cellspacing=\"4\" border=\"0\">\n";
echo " <tr>\n";
echo " <td>\n";
echo " <form action=\"" .basename(__FILE__) . "\">\n";
echo " <input type=\"hidden\" name=\"action\" value=\"edit\" />\n";
echo " <input type=\"hidden\" name=\"index\" value=\"" . $i . "\" />\n";
echo " <input type=\"submit\" value=\"Edit\" />\n";
echo " </form>\n";
echo " </td>\n";
echo " <td>\n";
echo " <form action=\"" .basename(__FILE__) . "\" onSubmit=\"return confirm('Delete item?')\">\n";
echo " <input type=\"hidden\" name=\"action\" value=\"delete\" />\n";
echo " <input type=\"hidden\" name=\"index\" value=\"" . $i . "\" />\n";
echo " <input type=\"submit\" value=\"Delete\" />\n";
echo " </form>\n";
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
echo "</td>\n";
echo "<td>\n";
echo " <table align=\"right\" cellpadding=\"0\" cellspacing=\"4\" border=\"0\">\n";
echo " <tr>\n";
echo " <td>\n";
echo " <form action=\"" .basename(__FILE__) . "\">\n";
echo " <input type=\"hidden\" name=\"action\" value=\"moveup\" />\n";
echo " <input type=\"hidden\" name=\"index\" value=\"" . $i . "\" />\n";
echo " <input type=\"submit\" value=\"Move Up\" />\n";
echo " </form>\n";
echo " </td>\n";
echo " <td>\n";
echo " <form action=\"" .basename(__FILE__) . "\">\n";
echo " <input type=\"hidden\" name=\"action\" value=\"movedown\" />\n";
echo " <input type=\"hidden\" name=\"index\" value=\"" . $i . "\" />\n";
echo " <input type=\"submit\" value=\"Move Down\" />\n";
echo " </form>\n";
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
}
echo "<hr>\n";
}
}
else
{
echo "No news<br><br>";
}
if (!$is_admin)
{
echo "<a href=\"".basename(__FILE__)."?action=admin\">Admin login</a>";
}
}
?>
</body>
</html>