Initial commit.

This commit is contained in:
tim
2013-05-17 23:38:44 +02:00
commit 7fc40728f5
1334 changed files with 164883 additions and 0 deletions
+81
View File
@@ -0,0 +1,81 @@
<?
require_once("../session.lib.php");
$added = FALSE;
if (!isset($_SESSION['editor'])) {
header("Location: https://xxx.org.za/publish/login");
return;
} else if (isset($_POST['adduser'])) {
require_once('../open_db.lib.php');
open_db('open');
$table = "editors";
$username = $db->real_escape_string($_POST['username']);
$password = crypt($_POST['password']);
$email = $db->real_escape_string($_POST['email']);
$query = "INSERT INTO $table SET".
"`username` = '".$username."', ".
"`password` = '".$password."', ".
"`email` = '".$email."'; ";
if ($result = $db->query($query)) {
$added = TRUE;
$is_admin = TRUE;
}
open_db('close');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" value="text/html; charset=UTF-8" />
<title>x.x.x: add editor</title>
<link rel="shortcut icon" href="/favicon.png">
<link rel="icon" href="/favicon.png">
<link rel='stylesheet' type='text/css' href='/style.css'>
<link rel='stylesheet' type='text/css' href='/publish/style.css'>
<link rel="alternate" type="application/rss+xml" title="xxx.org.za RSS feed" href="/feed" />
</head>
<? flush(); ?>
<body>
<div id="container">
<!-- Include siderbar here -->
<? include_once('../sidebar.inc.php'); ?>
<!-- Continue with main page stuff -->
<div id="main">
<div id="maintext">
<H1>add editor</H1>
<? if ($added) { ?>
<p>Added editor <?= $username ?></p>
<? } else { ?>
<form action="https://xxx.org.za<?= $_SERVER['REQUEST_URI'] ?>" method="post">
<label for="username">Username: </label>
<input type="text" id="username" name="username" />
<br class="clear" />
<label for="password">Password: </label>
<input type="password" id="password" name="password" />
<br class="clear" />
<label for="email">Email: </label>
<input type="text" id="email" name="email" />
<br class="clear" />
<div class="submission">
<button type="submit" id="adduser" name="adduser" value="1">Add editor</button>
</div>
</form>
<? } ?>
</div> <!-- maintext -->
</div> <!-- main -->
</div> <!-- container -->
<!-- Include bottom bar here -->
<? include('../bottombar.inc.php'); ?>
<!-- Finis -->
</body>
</html>
+35
View File
@@ -0,0 +1,35 @@
<?
// Default to the queue.
if (!isset($_REQUEST['queue']))
$queue = TRUE;
else
$queue = get_queue();
$num_stories = 15;
if (!get_id() && (get_count() > 1))
echo sort_options("/publish/edit");
if ($queue) { ?>
<p>To view already-posted articles, <a href="edit?queue=0">click here</a>.</p>
<? } else { ?>
<p>To view articles in the queue, <a href="edit?queue=1">click here</a>.</p>
<div class="input" style="text-align: justify">
<form action="" method="get">
<input name="search" type="text" class="input" id="search" maxlength="40" value="<?= $_GET['search'] ?>" />
<input name="queue" type="hidden" value="0" />
<button type="submit" id="choose" name="action" value="choose" class="inputbutton">Search</button>
</form>
</div>
<? }
echo display_stories();
?>
</div> <!-- maintext -->
</div> <!-- main -->
</div> <!-- container -->
<? include_once('../bottombar.inc.php'); ?>
</body>
</html>
+128
View File
@@ -0,0 +1,128 @@
<?
require_once("../session.lib.php");
if (!isset($_SESSION['editor'])) {
$is_admin = FALSE;
header("Location: https://xxx.org.za/publish/login");
return;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<title>x.x.x [edit]</title>
<link rel="icon" href="/favicon.png" />
<link rel="shortcut icon" href="/favicon.png" />
<link rel="stylesheet" type="text/css" href="/style.css" />
<link rel='stylesheet' type='text/css' href='/publish/style.css' />
<link rel="alternate" type="application/rss+xml" title="xxx.org.za RSS feed" href="/feed" />
<? include_once('./tinymce_init.inc.php'); ?>
</script>
</head>
<?
flush();
require_once("../get_data.lib.php");
open_db('open');
require_once("../navigation.lib.php");
require_once('./post.lib.php');
$editable = TRUE;
$id = get_id();
?>
<body>
<div id='container'>
<!-- Include siderbar here -->
<? include_once('../sidebar.inc.php'); ?>
<!-- Continue with main page stuff -->
<div id='main'>
<div id='maintext'>
<H1>edit</H1>
<?
/* Authenticated admin user allowed to: check the queue
edit article on the queue
optionally preview
post article to database
--------------------------
choose existing article
edit existing article
optionally preview
update article in database
--------------------------
write new article
preview (required)
post article to database
--------------------------
Ordinary web users can: write article
preview (required)
submit to the queue
*/
$action = NULL;
if (isset($_POST['action'])) {
$action = strtolower($_POST['action']);
// We can trigger only choose and edit via GET variables.
} else if (isset($_GET['action'])) {
if ($_GET['action'] == 'choose') {
$action = 'choose';
} else if ($_GET['action'] == 'edit') {
$action = 'edit';
}
}
if (!isset($action) && $id) {
$action = 'edit';
}
switch ($action) {
case 'submit': // to queue
case 'save': // resave to queue
case 'post': // to database
if (validate_data() && count($validate) === 0) {
$id = save_data($id);
echo display_stories();
} else {
$action = 'preview';
include('./preview.inc.php');
}
break;
case 'edit': // edit the chosen story
// admin only.
include('./modify.inc.php');
break;
case 'preview': // preview before posting
validate_data();
include('./preview.inc.php');
break;
case 'delete': // edit the chosen story
// admin only.
echo delete_story($id);
break;
case 'choose': // choose a story to edit
default:
// admin only: either from queue
// or from database
include('./choose.inc.php'); // need queue select!
break;
}
?>
</div>
</div>
</div>
<!-- Include bottom bar here -->
<? include_once('../bottombar.inc.php'); ?>
<? open_db('close'); ?>
<!-- Finis -->
</body>
</html>
+95
View File
@@ -0,0 +1,95 @@
<? require_once("../session.lib.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<title>x.x.x [add]</title>
<link rel="icon" href="/favicon.png" />
<link rel="shortcut icon" href="/favicon.png" />
<link rel="stylesheet" type="text/css" href="/style.css" />
<link rel='stylesheet' type='text/css' href='/publish/style.css' />
<link rel="alternate" type="application/rss+xml" title="xxx.org.za RSS feed" href="/feed" />
<? include_once('tinymce_init.inc.php'); ?>
</head>
<?
flush();
require_once("../get_data.lib.php");
open_db('open');
require_once("../navigation.lib.php");
require_once("./post.lib.php");
$editable = TRUE;
?>
<body>
<div id='container'>
<!-- Include siderbar here -->
<? include_once('../sidebar.inc.php'); ?>
<!-- Continue with main page stuff -->
<div id='main'>
<div id='maintext'>
<h1>submit</h1>
<?
/* Authenticated admin user allowed to: check the queue
edit article on the queue
optionally preview
post article to database
--------------------------
choose existing article
edit existing article
optionally preview
update article in database
--------------------------
write new article
preview (required)
post article to database
--------------------------
Ordinary web users can: write article
preview (required)
submit to the queue
*/
if (isset($_POST['action']))
$action = strtolower($_POST['action']);
else
$action = NULL;
switch ($action) {
case 'post': // post to database
case 'save': // post to queue
case 'submit': // post to queue
if (validate_data() && count($validate) === 0) {
$id = save_data();
echo display_stories($id);
} else {
$action = 'preview';
include('./preview.inc.php');
}
break;
case 'preview': // preview before posting
validate_data();
include('./preview.inc.php');
break;
default: // write a new article
include('./write.inc.php');
break;
}
?>
</div>
</div>
</div>
<!-- Include bottom bar here -->
<? include_once('../bottombar.inc.php'); ?>
<? open_db('close'); ?>
<!-- Finis -->
</body>
</html>
+103
View File
@@ -0,0 +1,103 @@
<?
require_once("../session.lib.php");
$denied = NULL;
$is_admin = NULL;
if (isset($_SESSION['editor'])) {
header("Location: http://xxx.org.za/publish/edit");
} else if (isset($_POST['login'])) {
include_once('../open_db.lib.php');
$table = "editors";
open_db('open');
$username = $db->real_escape_string($_POST['username']);
$query = "SELECT * FROM $table WHERE ".
"username LIKE '".$username."' ".
"LIMIT 1;";
$getid = $db->query($query) or die("Query failed: ".$db->error());
$row = $getid->fetch_assoc();
if (isset($row)) $stored_password = $row['password'];
else $denied = TRUE;
$getid->close();
open_db('close');
$compare_password = $_POST['password'];
if (crypt($compare_password, $stored_password) != $stored_password) {
$denied = TRUE;
} else {
$_SESSION['editor'] = $username;
// Keep user logged in with cookie, if they request it
if (isset($_POST['remember'])) {
create_persistent_login($username);
}
if (isset($_SESSION['referrer'])) {
$url = $_SERVER['HTTPS'] ? "https://" : "http://";
$url .= $_SERVER['HTTP_HOST'];
$url .= $_SESSION['referrer'];
unset($_SESSION['referrer']);
header("Location: $url");
return;
} else {
header("Location: http://xxx.org.za/publish/edit");
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" value="text/html; charset=UTF-8" />
<title>x.x.x: login</title>
<link rel="shortcut icon" href="/favicon.png">
<link rel="icon" href="/favicon.png">
<link rel='stylesheet' type='text/css' href='/style.css'>
<link rel='stylesheet' type='text/css' href='/publish/style.css'>
<link rel="alternate" type="application/rss+xml" title="xxx.org.za RSS feed" href="/feed" />
</head>
<? flush(); ?>
<body>
<div id="container">
<!-- Include siderbar here -->
<? include_once('../sidebar.inc.php'); ?>
<!-- Continue with main page stuff -->
<div id="main">
<div id="maintext">
<H1>editor login</H1>
<?
if ($denied)
echo "<p><strong>Access denied. Please try again.</strong></p>\n";
?>
<form action="<? echo "https://xxx.org.za".$_SERVER['REQUEST_URI']; ?>" method="post">
<label for="username">Username: </label>
<input type="text" id="username" name="username" />
<br class="clear" />
<label for="password">Password: </label>
<input type="password" id="password" name="password" />
<br class="clear" />
<label for="remember">Remember me:</label>
<input type="checkbox" id="remember" name="remember" checked />
<br class="clear" />
<div class="submission">
<button type="submit" id="login" name="login" value="1">Login</button>
</div>
</form>
</div> <!-- maintext -->
</div> <!-- main -->
</div> <!-- container -->
<!-- Include bottom bar here -->
<? include('../bottombar.inc.php'); ?>
<!-- Finis -->
</body>
</html>
+24
View File
@@ -0,0 +1,24 @@
<?
require_once("../session.lib.php");
if (isset($_SESSION['editor'])) {
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-42000, '/');
}
session_destroy();
}
delete_persistent_login();
if (isset($_SESSION['referrer'])) {
$url = $_SERVER['HTTPS'] ? "https://" : "http://";
$url .= $_SERVER['HTTP_HOST'];
$url .= $_SESSION['referrer'];
unset($_SESSION['referrer']);
if (preg_match("/logout(\.php)?$/i", $url)) {
$url = "/";
}
header("Location: $url");
return;
} else {
header("Location: /");
return;
}
?>
+7
View File
@@ -0,0 +1,7 @@
<?
echo display_stories();
echo "<br /><br />\n";
include('./write.inc.php');
?>
+253
View File
@@ -0,0 +1,253 @@
<?
require_once('../open_db.lib.php');
require_once('../get_data.lib.php');
function save_data($id = NULL) {
global $db, $is_admin, $queue, $action;
$queue = get_queue();
// Are we posting a story from the queue?
if ($queue && $action == 'post')
$move = TRUE;
else
$move = FALSE;
$table = which_table($move, $action);
// extract POST variables (running through stripslashes)
$result = get_post_data(TRUE);
// assign their keys and values to the symbol table
extract($result[0], EXTR_OVERWRITE);
// Process data...
$story = sanitise($story);
// Add the date if it's not got one
if (!$date)
$date = gmdate("Y-m-d H:i:s");
// Verify image
if ($move && isset($uploaded) && $uploaded === $id) {
// Special case - transfer image from queue table
$query = "SELECT img, mime FROM queue WHERE id = $id;";
if ($getimg = $db->query($query)) {
$row = $getimg->fetch_assoc();
$img = $row['img'];
$mime = $row['mime'];
$getimg->close();
} else {
die("Error in query: $db->error");
}
} else {
$image_file = save_uploaded_file();
if ($image_file) {
$img = fread(fopen($image_file, "r"), filesize($image_file));
$mime = get_mimetype($image_file);
}
}
if (is_numeric($id) && !$move)
$query = "UPDATE $table SET";
else
$query = "INSERT INTO $table SET";
$query .= " `title` = '".$db->real_escape_string($title)."'"
.", `author` = '".$db->real_escape_string($author)."'"
.", `email` = '".$db->real_escape_string($email)."'"
.", `editor` = '".$db->real_escape_string($editor)."'";
if ($is_admin && isset($comments)) {
$query .= ", `comments` = '".$db->real_escape_string($comments)."'";
}
if ($hidden) {
$query .= ", `hidden` = TRUE";
} else {
$query .= ", `hidden` = FALSE";
}
if ($remove_img && $story) {
$query .= ", `story` = '".$db->real_escape_string($story)."'";
$query .= ", `mime` = NULL";
$query .= ", `img` = NULL";
} else if (isset($img)) {
$query .= ", `mime` = '".$db->real_escape_string($mime)."'";
$query .= ", `img` = '".$db->real_escape_string($img)."'";
$query .= ", `story` = ''";
} else {
$query .= ", `story` = '".$db->real_escape_string($story)."'";
}
if (!is_numeric($id) || $move)
$query .= ", `date` = '".$db->real_escape_string($date)."'";
if (is_numeric($id) && !$move)
$query .= " WHERE `id` = '".$id."' LIMIT 1;";
else
$query .= ";";
//echo $query;
$result = $db->query($query) or die("Query failed: ".$db->error);
if (is_numeric($id) && $move) {
$queue_id = $id;
}
// Get the (new) ID if we don't already have it.
if (!is_numeric($id) || $move) {
$query = "SELECT LAST_INSERT_ID();";
$getid = $db->query($query) or die("Query failed: ".$db->error());
$row = $getid->fetch_row();
$id = $row[0];
}
// Delete the article in the queue if pushing live
if ($move && $queue_id) {
delete_story($queue_id, $move);
$queue = FALSE;
}
// Allow unprivileged user to view image on queue
if (!$is_admin && $action == 'submit')
$_SESSION['allow_queue_image'] = $id;
// Prune filesystem
if ($image_file)
prune_images($image_file);
// email admin if added to the queue
if ($action == 'submit')
send_email($title, $author, $story);
return $id;
}
function delete_story($id, $move = FALSE) {
global $db, $is_admin, $queue;
$queue = get_queue();
$table = which_table($move, 'delete');
$query = "DELETE FROM $table WHERE `id` = '".$id."' LIMIT 1;";
//echo $query;
$result = $db->query($query)or die("Query failed : ".$db->error());
if (!$move)
$message = 'Article has been deleted.';
return $message;
}
function get_mimetype($image_file) {
$upload = getimagesize($image_file);
$mimetype = $upload['mime'];
return $mimetype;
}
function save_uploaded_file() {
// Save uploaded file to new, temporary location
if (is_uploaded_file($_FILES['upload']['tmp_name'])) {
$tmp_file = $_FILES['upload']['tmp_name'];
$new_file = $_SERVER['DOCUMENT_ROOT'] . "/graphics" . $tmp_file;
$end_dir = dirname($new_file);
if (!is_dir($end_dir))
mkdir($end_dir, "0644", 1);
$image_file = $new_file;
move_uploaded_file($tmp_file, $image_file);
// File has already been uploaded, get location
} else if (isset($_POST['uploaded']) &&
is_file($_SERVER['DOCUMENT_ROOT'] . $_POST['uploaded'])) {
$image_file = realpath($_SERVER['DOCUMENT_ROOT'] . $_POST['uploaded']);
}
if (isset($image_file)) {
return $image_file;
} else {
return FALSE;
}
}
function prune_images($image_file) {
// Delete image from filesystem, and cleanup anything older than $age
$age = '86400'; // a day old
$cleanup_dir = dirname($image_file);
unlink($image_file);
if ( $dir_handle = @opendir($cleanup_dir) ) {
if($dir_handle=='.' || $dir_handle=='..') continue;
while ($cleanup_file = readdir ($dir_handle)) {
$cleanup_file = $cleanup_dir . "/". $cleanup_file;
if (@filemtime($cleanup_file) < (time() - $age)) {
@unlink($cleanup_file);
}
}
closedir($dir_handle);
}
}
/*
* Validate data
*
* Updates the global $validate array, with the key as the element name, and the value set to the error message.
*
*/
$validate = array();
function validate_data() {
global $validate;
// extract POST variables (running through stripslashes)
$result = get_post_data(TRUE);
// assign their keys and values to the symbol table
extract($result[0], EXTR_OVERWRITE);
if (!$author) {
$validate['author'] = "You have not submitted an author.";
}
if (!$title) {
$validate['title'] = "You have not submitted a title.";
}
if ($remove_img && !$story) {
$validate['story'] = "You've tried to remove an image without replacing it with text.";
}
// 0 == no error; 4 == no file; all others are errors.
if ($_FILES['upload']['error'] > 0 &&
$_FILES['upload']['error'] !== 4) {
$validate['upload'] = 'There was an error uploading the file ('.$_FILES['upload']['error'].')';
} else if ($_FILES['upload']['tmp_name']) {
$upload = getimagesize($_FILES['upload']['tmp_name']);
if (!$upload)
$validate['upload'] = htmlspecialchars($_FILES['upload']['name']) .
" wasn't an image file. Please go back.";
}
return TRUE;
}
function sanitise($story) {
if ($story) {
// No Javascript please!
$story = preg_replace("#<script[^>]*?>.*?</script>#si", "", $story);
// No comments please!
$story = preg_replace("#<!--.*?-->#si", "", $story);
// Replace number ranges with n-dashes
$stort = preg_replace("#(\d)-+(\d)#si", "$1&ndash;$2", $story);
// Replace " -- " and "--" with m-dashes
$story = preg_replace("#(\s?)--(\s?)#si", "$1&mdash;$2", $story);
// Replace ellipses
$story = preg_replace("#(\w|\p{P}|>)\. ?\. ?\.(\s|\p{P})#si", "$1&hellip;$2", $story);
// External processing
include_once('../lib/smartypants.inc.php');
$story = SmartyPants($story);
#include_once('../lib/convert_entities.inc.php');
#$story = html_entity_decode_full($story); // Convert named entities to numeric entities
// Won't worry about HTML Purifier yet
}
return $story;
}
function send_email($title, $author, $story) {
include_once('../lib/convert_entities.inc.php');
$to = 'editor@xxx.org.za';
$subject = "New submission: $title";
$headers = 'From: x.x.x Queue <editor@xxx.org.za>'."\r\n";
$message = "Please review the queue. $author has sent the following new submission:\n\n";
if ($story)
$message .= wordwrap(preg_replace("#(<br.?/?>|</p>)#", "\n", strip_tags(stripslashes(html_entity_decode_full($story)))));
else
$message .= "<Submission is an image. Review on the site.>";
$message .= "\n\nhttp://xxx.org.za/publish/edit";
mb_send_mail($to, $subject, $message, $headers);
}
+36
View File
@@ -0,0 +1,36 @@
<?
$result = get_post_data(TRUE, TRUE);
extract($result[0], EXTR_OVERWRITE);
if (isset($_POST['recaptcha_challenge_field']) && isset($_POST['recaptcha_response_field'])) {
include_once('../lib/recaptchalib.inc.php');
$privatekey = config('RECAPTCHA_SECRET');
$resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
$validate['captcha'] = 'The words you typed in the captcha were not correct. Please try again.';
include('./write.inc.php');
return;
}
}
echo '<p>Please review your submission. Once you\'ve finished, please click "Submit" at the bottom of the page, or click "Preview" to check it again.</p>';
if (is_uploaded_file($_FILES['upload']['tmp_name']) && !isset($validate['upload'])) {
$tmp_file = $_FILES['upload']['tmp_name'];
$upload = getimagesize($tmp_file);
$new_file = $_SERVER['DOCUMENT_ROOT'] . "/graphics" . $tmp_file;
move_uploaded_file($tmp_file, $new_file);
$file_src = "/graphics" .$tmp_file;
} else if (isset($uploaded) && is_file($_SERVER['DOCUMENT_ROOT'] . $uploaded) && !$remove_img) {
$file_src = $uploaded;
}
echo display_stories();
echo "<br /><br />\n";
include('./write.inc.php');
return;
?>
+160
View File
@@ -0,0 +1,160 @@
#title, #author, #email, #comments, #story, #username, #password, #remember, #recaptcha_response_field {
border: 1px dashed #006633;
display: block;
width: 250px;
float: left;
margin-bottom: 5px;
margin-top: 5px;
padding-left: 2px;
}
input#remember {
margin-left: -2px;
margin-top: 7px;
}
#story {
width: 400px;
height: 200px;
}
#htmloptions {
display: block;
float: left;
width: auto;
border: 1px solid #006633;
}
.submission {
margin-top: 10px;
margin-left: 120px;
}
#preview, #submit, #delete, #login, #adduser {
border: 1px dashed #006633;
background-color: #FFFFFF;
font-weight: bold;
margin-right: 5px;
}
#hidden {
display: block;
float: left;
margin: 5px 0;
}
label {
display: block;
float: left;
margin-bottom: 5px;
margin-top: 5px;
text-align: right;
width: 100px;
padding-right: 20px;
}
br.clear {
clear: both;
}
.note {
float: left;
text-align: justify;
font-size: 8pt;
margin-top: 5px;
margin-bottom: 5px;
margin-left: 100px;
padding-left: 20px;
}
.textarea .note {
margin-left: -20px;
}
.in-note {
text-align: justify;
font-size: 8pt;
margin-top: 5px;
margin-bottom: 5px;
}
.remove img {
padding: 5px;
padding-left: 10px;
float: right;
}
div.textarea {
margin-left: 120px;
}
.tab {
display: block;
float: left;
margin-bottom: 5px;
margin-top: 5px;
text-align: right;
width: 100px;
padding-top: 3px;
padding-bottom: 3px;
padding-right: 20px;
background-color: #006633;
clear: left;
color: white;
cursor: pointer;
}
#uploadparent {
width: 300px;
height: 150px;
padding: 10px;
border: 1px dashed #006633;
}
/* WordCount */
.counter {
display: block;
float: left;
margin-bottom: 5px;
margin-top: 5px;
text-align: right;
width: 100px;
padding-right: 20px;
clear: left;
font-size: 8pt;
}
.yes {
font-weight: bold;
}
.no {
color: red;
}
.required {
color: red;
position: relative;
top: 0.6em;
font-family: Times New Roman, serif;
}
ul.error-box {
border: 2px dotted red;
padding: 10px 30px;
}
fieldset.mi_group_prevacct ul.error-box {
border: 0;
margin: 0;
padding: 4px 0 0 6px;
color: red;
}
ul.error-box li {
margin: 4px 15px;
font-weight: bold;
}
#captcha #recaptcha_image {
margin-left: 120px;
border: 1px dotted #006633;
}
#captcha .icons {
position:relative;
top:0.6em;
}
+22
View File
@@ -0,0 +1,22 @@
<script type="text/javascript" src="/publish/utilities.js"></script>
<script type="text/javascript" src="/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
mode : "textareas",
theme : "advanced",
skin : "xxx",
width : "400",
height : "300",
auto_reset_designmode : true,
gecko_spellcheck : true,
content_css : "/style.css",
theme_advanced_buttons1 : "bold,italic,|,justifyleft,justifycenter,justifyright,justifyfull,|,blockquote,|,outdent,indent,|,link,unlink,|,charmap,iespell,|,code,cleanup",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "bottom",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "",
handle_event_callback : "mceWordCount",
oninit : "mceWordCount"
});
</script>
+124
View File
@@ -0,0 +1,124 @@
// GLOBAL
var tinyMCEstate = true;
function showHide(show) {
if (show == 'text') {
var hide = 'upload';
} else if (show == 'upload') {
var hide = 'text';
} else {
return false;
}
if (show == 'text') {
document.getElementById(hide+'parent').style.display = "none";
document.getElementById(show+'parent').style.display = "block";
document.getElementById('wordcounter').style.display = "block";
if (!tinyMCEstate && tinyMCE) {
// Toggling breaks getContent if the inital state is toggled off.
//tinyMCE.execCommand('mceToggleEditor',false,'text');
tinyMCEstate = true;
}
tinyMCE.execCommand('mceFocus',false,'text');
} else if (show == 'upload') {
if (tinyMCEstate && tinyMCE) {
// Toggling breaks getContent if the inital state is toggled off.
//tinyMCE.execCommand('mceToggleEditor',false,'text');
tinyMCEstate = false;
}
document.getElementById('wordcounter').style.display = "none";
document.getElementById(hide+'parent').style.display = "none";
document.getElementById(show+'parent').style.display = "block";
}
return true;
}
// GLOBAL
var is_delete = 0;
function do_delete() {
if (confirm('Are you certain you wish to delete this post?')) {
is_delete = 1;
return true;
} else
return false;
}
function review() {
var title = document.getElementById('title');
var author = document.getElementById('author');
var email = document.getElementById('email');
var upload = document.getElementById('upload');
var uploaded = document.getElementById('uploaded');
var remove_img = document.getElementById('remove_img');
var txtcnt = wc(tinyMCE.get('story').getContent());
if (is_delete) return true;
if (!title.value) {
alert("Please add a title to your submission; one makes everything much prettier.");
return false;
} if (!author.value) {
alert("You haven't added an author. You can use a pseudonym if you like.");
return false;
} if (!email.value) {
if (!confirm("You haven't added an email address.\n\nThis will not be published. It will only be used by editors if we need to contact you.\n\nClick 'cancel' if you would like to go back and add one now."))
return false;
} if ((txtcnt == 0) && (upload.value == '') && ((!remove_img || remove_img.value == 1) || (!uploaded || uploaded.value == ''))) {
alert("You haven't submitted anything (not even a picture!).");
return false;
} else if ((txtcnt != '100') && (upload.value == '') && ((!remove_img || remove_img.value == 1) || (!uploaded || uploaded.value == ''))) {
if (!confirm("Your submission doesn't appear to be 100 words long. I'll continue anyway, but you may want to review."))
return false;
}
return true;
}
// GLOBAL
if (document.images) {
trashcan_img = new Image(16,22);
trashcan_img.src="/graphics/trashcan-open.png";
}
function toggle_remove() {
var virtual_checkbox = document.getElementById('remove_img');
var img = document.getElementById('remove_img_icon');
if(virtual_checkbox.value == 0) {
virtual_checkbox.value=1;
img.src='/graphics/trashcan-open.png'
img.title = 'Image is marked for removal.';
} else {
virtual_checkbox.value=0;
img.src='/graphics/trashcan.png'
img.title = 'Image has been restored; it will not be removed.';
}
}
function mceWordCount (e) {
if (e && e.type != 'keyup')
return true;
var txt = tinyMCE.get('story').getContent();
var wordcounter = document.getElementById("wordcounter");
var cnt = wc(txt);
var words = (cnt == 1) ? "&nbsp;word" : "&nbsp;words";
if (wordcounter) {
wordcounter.innerHTML = cnt + words;
wordcounter.className = "counter";
if (cnt == 100) wordcounter.className += " yes";
if (cnt > 100) wordcounter.className += " no";
}
return true;
}
function wc (txt) {
txt = txt.replace(/(<br( \/)?>)/ig," "); // replace ending <br>s with spaces
txt = txt.replace(/(<([^>]+)>)/ig,""); //strip HTML
txt = txt.replace(/(\s?[a-zA-Z0-9]+)\s?(?:&.dash;\s?|-(?:-+\s?|\s))([a-zA-Z0-9]+)/g,"$1 $2"); //strip mdashes
txt = txt.replace(/\s[^a-zA-Z0-9]+\s/g," "); //strip punctuation
txt = txt.replace(/\s*((\S+\s*)*)/, "$1"); //ltrim
txt = txt.replace(/((\s*\S+)*)\s*/, "$1"); //rtrim
txt = txt.replace(/(&nbsp;)/g, " "); //TinyMCE newlines leave spaces behind
txt = txt.replace(/(^\s+|\s+$)/, " "); // Remove trailing spaces
if (txt.match(/^ *$/))
return 0;
var cnt = txt.split(/\s+/g);
return cnt.length;
}
+176
View File
@@ -0,0 +1,176 @@
<?
$id = get_id();
$search = get_search_args();
if ($action == 'preview')
$result = get_post_data(TRUE, TRUE);
else if ($action && is_numeric($id))
$result = get_query($id);
if (isset($result) && is_array($result))
extract($result[0], EXTR_OVERWRITE);
// Print any validation error messages
if (count($validate) !== 0) {
echo '<ul class="error-box">Please correct the following errors:';
foreach ($validate as $validate_key=>$validate_value) {
echo '<li>'.$validate_value.'</li>';
}
echo '</ul>';
}
?>
<form method="post" enctype="multipart/form-data" onsubmit="return review()" action="">
<div>
<label<?= isset($validate['title']) ? ' class="red"' : '' ?> for="title">Title:</label>
<input type="text" id="title" name="title" maxlength="150" value="<?= isset($title) ? $title : '' ?>" />
<span class="required">&nbsp;*</span>
<br class="clear" />
</div>
<div>
<label<?= isset($validate['author']) ? ' class="red"' : '' ?> for="author">Author:</label>
<input type="text" name="author" id="author" value="<?= isset($author) ? $author : '' ?>" maxlength="150" />
<span class="required">&nbsp;*</span>
<br class="clear" />
</div>
<div>
<label<?= isset($validate['email']) ? ' class="red"' : '' ?> for="email">Email address:</label>
<input type="text" name="email" id="email" maxlength="150" value="<?= isset($email) ? $email : ''?>" />
<br class="clear" />
<div class="note">(An email address where editors can reach the author.)</div>
<br class="clear" />
</div>
<div class="tab<?= isset($validate['story']) ? ' red' : '' ?>" onclick="showHide('text');">Text:</div>
<div class="tab<?= isset($validate['upload']) ? ' red' : '' ?>" onclick="showHide('upload');">Image:</div>
<div id="wordcounter" class="counter" style="display: none;">0 words</div>
<div class="textarea">
<div id="textparent">
<textarea name="story" id="story" rows="20" cols="50">
<?
echo (isset($story) ? $story : '')
?>
</textarea>
<br class="clear" />
<div class="note">(To get line-breaks&mdash;as in poetry&mdash;instead of paragraph breaks, hit shift-enter instead of enter.)</div>
</div>
<div class="upload" id="uploadparent" style="display: none;">
<?
if (isset($file_src) || isset($img)) {
if (isset($file_src)) {
echo ' <input type="hidden" id="uploaded" name="uploaded" value="'.$file_src.'" />';
} else {
echo ' <input type="hidden" id="uploaded" name="uploaded" value="'.$id.'" />';
}
echo ' <div class="in-note">If you are happy with the image above, click Submit. Otherwise, upload a new image:</div>';
} else {
echo ' <div class="in-note">You may upload an image of 100,000 pixels instead of text:</div>';
}
?>
<br class="clear" />
<input type="file" name="upload" id="upload" />
<br class="clear" />
<?
if (isset($file_src) || isset($img)) {
echo ' <div>';
echo ' <div class="remove">';
echo ' <input id="remove_img" name="remove_img" type="hidden" value="0" />';
echo ' <a href="javascript:toggle_remove()">';
echo ' <img id="remove_img_icon" src="/graphics/trashcan.png" border="0" title="Mark photo for deletion." /></a>';
echo ' </div>';
echo ' <div class="in-note">If you wish to remove the image altogether, and replace it with text, click the bin icon: <br />';
echo ' (Click it again to restore the image.)</div>';
echo ' </div>';
}
?>
</div>
<br class="clear" />
</div>
<? if ($is_admin) { ?>
<div>
<label<? isset($validate['comments']) ? ' class="red"' : '' ?> for="comments">Comments:</label>
<input type="text" name="comments" id="comments" maxlength="150" value="<?= isset($comments) ? $comments : '' ?>" />
<br class="clear" />
</div>
<input type="hidden" id="editor" name="editor" value="<?= $username ?>" />
<? } else { ?>
<input type="hidden" id="editor" name="editor" value="original author" />
<? } ?>
<div style="display: none;">
<input type="hidden" id="date" name="date" value="<?= isset($date) ? $date : '' ?>" />
<input type="hidden" id="id" name="id" value="<?= isset($id) ? $id : '' ?>" />
</div>
<?
if (!$is_admin && (($action == "") || isset($validate['captcha']))) {
echo '<div><br class="clear" /></div>';
include('../lib/recaptchalib.inc.php');
echo '<script type="text/javascript"> var RecaptchaOptions = { theme : "custom", custom_theme_widget : "captcha" }; </script>';
echo '<div id="captcha" style="display: none;">';
echo '<div id="recaptcha_image"></div>';
$redo_cap_class = isset($validate['captcha']) ? 'class="no" ' : '';
echo '<label '.$redo_cap_class.'for="recaptcha_response_field">Type the two words:</label>';
echo '<input type="text" name="recaptcha_response_field" id="recaptcha_response_field" maxlength="150" value="" />';
echo '<span class="required">&nbsp;*</span>';
$publickey = config('RECAPTCHA_SITE_KEY');
echo recaptcha_get_html($publickey);
echo '<span class="icons">';
echo '<a href="javascript:Recaptcha.reload()">';
echo '<img src="/graphics/recaptcha-refresh.png" alt="Refresh CAPTCHA" title="Refresh CAPTCHA" /></a>';
echo '<span class="recaptcha_only_if_image"><a href="javascript:Recaptcha.switch_type(\'audio\')">';
echo '<img src="/graphics/recaptcha-audio.png" alt="Get audio CAPTCHA" title="Audio version" /></a></span>';
echo '<span class="recaptcha_only_if_audio"><a href="javascript:Recaptcha.switch_type(\'image\')">';
echo '<img src="/graphics/recaptcha-text.png" alt="Get image CAPTCHA" title="Image version" /></a></span>';
echo '<a href="javascript:Recaptcha.showhelp()">';
echo '<img src="/graphics/recaptcha-help.png" alt="CAPTCHA help" title="Help" /></a>';
echo '</span>';
echo '<br class="clear" />';
echo '</div>';
}
if ($is_admin) {
$checked = isset($hidden) && !empty($hidden) ? ' checked' : '';
echo '<div>';
echo '<label'.(isset($validate['hidden']) ? ' class="red"' : '').' for="hidden">Hidden:</label>';
echo '<input type="checkbox" name="hidden" id="hidden"'.$checked.' />';
echo '<br class="clear" />';
echo '</div>';
}
?>
<div class="submission">
<?
if (isset($queue) && $is_admin) {
echo '<button type="submit" id="preview" name="action" value="save">Save in queue</button>';
} else {
echo '<button type="submit" id="preview" name="action" value="preview">Preview</button>';
}
if ((count($validate) === 0 && $action == "preview") || ($is_admin && !$action)){
$submit_text = $is_admin ? "Submit to queue" : "Submit";
echo '<button type="submit" id="submit" name="action" value="submit">'.$submit_text.'</button>';
}
if (($id || $action == "edit") || $is_admin) {
echo '<button type="submit" id="submit" name="action" value="post">Post!</button>';
if ($id && $is_admin)
echo '<button type="submit" onclick="javascript:return do_delete();" id="delete" name="action" value="delete">Delete</button>';
}
?>
</div>
</form>
<?
echo '<script type="text/javascript">'."\n";
if (isset($file_src) || isset($img) || isset($validate['upload'])) {
echo " showHide('upload')\n";
} else {
echo " var wordcounter = document.getElementById('wordcounter');\n";
echo " wordcounter.style.display = 'block';\n";
}
echo "</script>\n";
?>