- Code: Select all
<?php
//Installation:
//Open inc/show.news.php and change this:
//$output = str_replace('{author}', $user_name[$row['author']], $output);
//to this:
//$output = str_replace('{author}', (isset($user_name[$row['author']]) ? $user_name[$row['author']] : $row['author']) , $output);
//Config maximum unapproved
$max_unapproved = 50;
///////////////////////////
//Config XFields
$show_xfields = false;
///////////////////////////
//Config categories
$config_categories = '1,2,3';
///////////////////////////
//Config captcha
$use_captcha = false; //true or false
$path_to_captcha = './plugins/captcha/';
//Config bbcode
$bbcode = true;
if($use_captcha){
@include $path_to_captcha.'php-captcha.inc.php';
}
?>
<link rel="stylesheet" type="text/css" href="skins/default.css">
<script type="text/javascript">
function check_fields(){
if (document.guest.short_story.value == ""){
document.guest.short_story.focus();
alert ("The short story can't be blank.");
return false;
}
return true;
}
function insertext(open, close, area){
if(area=="short"){msgfield = document.guest.short_story}
else if(area=="full"){msgfield = document.guest.full_story}
// IE support
if (document.selection && document.selection.createRange){
msgfield.focus();
sel = document.selection.createRange();
sel.text = open + sel.text + close;
msgfield.focus();
}
// Moz support
else if (msgfield.selectionStart || msgfield.selectionStart == "0"){
var startPos = msgfield.selectionStart;
var endPos = msgfield.selectionEnd;
msgfield.value = msgfield.value.substring(0, startPos) + open + msgfield.value.substring(startPos, endPos) + close + msgfield.value.substring(endPos, msgfield.value.length);
msgfield.selectionStart = msgfield.selectionEnd = endPos + open.length + close.length;
msgfield.focus();
}
// Fallback support for other browsers
else {
msgfield.value += open + close;
msgfield.focus();
}
return;
}
</script>
<?
include 'head.php';
if($_POST['dosend'] == "yes"){
$unapproved = count($sql->select(array('table' => 'news', 'where' => array('hidden = 1'))));
if($unapproved > $max_unapproved) echo "Sorry, we have enough unapproved stories.";
if ($use_captcha and !PhpCaptcha::Validate($_POST['code'])) {
echo("<div style=\"text-align: center;\">Please enter the numbers from the image.<br /><a href=\"javascript:history.go(-1)\">go back</a></div>");
}
else{
$added_time = (time() + $config_date_adjust * 60);
if (!$title){
$title = substr($short_story, 0, 10).'...';
}
$id = $sql->last_insert_id('news', '', 'id') + 1;
if ($cat){
foreach ($cat as $k => $v){
$category_tmp[] = $k;
}
$category = join(',', $category_tmp);
}
$mod == 'addnews';
$sql->insert(array(
'table' => 'news',
'values' => array(
'date' => $added_time,
'author' => ($_POST['name'] ? $_POST['name'] : 'guest'),
'title' => replace_news('add', $title),
'short' => strlen(replace_news('add', $short_story)),
'full' => strlen(replace_news('add', $full_story)),
'avatar' => $avatar,
'category' => $category,
'url' => namespace2(totranslit($title)),
'hidden' => true
)
));
$sql->insert(array(
'table' => 'story',
'values' => array(
'post_id' => $id,
'short' => replace_news('add', $short_story),
'full' => replace_news('add', $full_story)
)
));
if($show_xfields){
call_xfields_Save();
}
mail("josh@runsleepdesign.com", "New guest news", "There's a new guest news", "From:noreply@runsleepdesign.com");
echo "Thank you for submitting your story.<br />";
echo "The admin will publish it after approval.";
}
}
else{
?>
<form action="" name="guest" method="post" onsubmit="return check_fields()">
<table>
<tr><td>Author:</td><td><input size="20" type="text" name="name"></td></tr>
<tr><td>Title:</td><td><input size="60" type="text" name="title"></td></tr>
<?
echo '<tr><td>Category:</td><td>'.get_categories($config_categories).'</td></tr>';
?>
<tr><td>Short story:</td><td><?=$bbcode ? insertTag('short') : ''; ?><textarea name="short_story"></textarea></td></tr>
<!--Browse for image-->
<tr><td>Add a picture:</td><td><input name="avatar" type="file" class="text_calendar" value="" size="32" /></td></tr>
<!--Browse for image-->
<?
if($show_xfields){
echo "<tr><td>XFields:</td><td>";
echo admins_xfields();
echo "</td></tr>";
}
if($use_captcha){
?>
<tr><td>Enter this code in the field below.<br /><img src="<?=$path_to_captcha; ?>/captcha.php?width=144" width="144" alt="Security Image"/><br /><input type="text" size="10" name="code" maxlength="6" />
<?
}
?>
<tr><td align="center" colspan="2"><input type="submit" value="Submit story"></td></tr>
<input type="hidden" name="dosend" value="yes">
</table>
</form>
<?
}
function get_categories($selection){
global $sql;
$category = '<select name="category">';
foreach($single_cats = explode(",", $selection) as $id){
foreach ($sql->select(array('table' => 'categories', 'where' => array("id = $id"))) as $row){
$category .= '<option value="'.$id.'">'.$row['name'].'</option>';
}
}
$category .= '</select>';
return $category;
}
function namespace2($str){
global $sql;
foreach ($sql->select(array('table' => 'news')) as $row){
if (@preg_match("/$str([0-9]+)?/i", $row['url'])){
$result[] = $row['id'];
}
}
$count = count($result);
$count++;
return totranslit($str.(($count and $count != 1) ? ' '.$count : ''));
}
?>
