1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-01 20:30:39 +02:00

Bugtracker #4716 - submit news tidy up - mostly thanks to whoisrich

This commit is contained in:
e107steved
2009-04-21 21:26:59 +00:00
parent 53037acb47
commit b8da62d09a
2 changed files with 183 additions and 154 deletions

View File

@@ -4,17 +4,17 @@
| e107 website system - Language File. | e107 website system - Language File.
| |
| $Source: /cvs_backup/e107_0.8/e107_languages/English/lan_submitnews.php,v $ | $Source: /cvs_backup/e107_0.8/e107_languages/English/lan_submitnews.php,v $
| $Revision: 1.2 $ | $Revision: 1.3 $
| $Date: 2007-04-12 23:04:51 $ | $Date: 2009-04-21 21:26:59 $
| $Author: e107coders $ | $Author: e107steved $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
define("PAGE_NAME", "Submit News"); define("PAGE_NAME", "Submit News");
define("LAN_7", "Username: "); define("LAN_7", "Name: ");
define("LAN_62", "Subject: "); define("LAN_62", "News Title: ");
define("LAN_112", "Email Address: "); define("LAN_112", "Email Address: ");
define("LAN_133", "Thank you"); define("LAN_133", "Thank you");
define("LAN_134", "Your item has been submitted and will be reviewed by one of the site administrators in due course."); define("LAN_134", "Your item has been submitted for review by one of the site administrators.");
define("LAN_135", "News Item: "); define("LAN_135", "News Item: ");
define("LAN_136", "Submit News Item"); define("LAN_136", "Submit News Item");
define("NWSLAN_6", "Category"); define("NWSLAN_6", "Category");
@@ -28,5 +28,6 @@ define("SUBNEWSLAN_3", "Your attachment must be either a jpg, gif or png file");
define("SUBNEWSLAN_4", "File too Large"); define("SUBNEWSLAN_4", "File too Large");
define("SUBNEWSLAN_5", "Image File"); define("SUBNEWSLAN_5", "Image File");
define("SUBNEWSLAN_6", "(jpg, gif or png)"); define("SUBNEWSLAN_6", "(jpg, gif or png)");
define('SUBNEWSLAN_7', 'You must give your name and email address');
?> ?>

View File

@@ -11,21 +11,21 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/submitnews.php,v $ | $Source: /cvs_backup/e107_0.8/submitnews.php,v $
| $Revision: 1.8 $ | $Revision: 1.9 $
| $Date: 2009-01-22 01:58:29 $ | $Date: 2009-04-21 21:26:59 $
| $Author: mcfly_e107 $ | $Author: e107steved $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
require_once("class2.php"); require_once("class2.php");
$e_wysiwyg = varsettrue($pref['subnews_htmlarea']) ? "submitnews_item" : "";
$e_wysiwyg = varsettrue($pref['subnews_htmlarea']) ? 'e107_submitnews_item' : '';
require_once(HEADERF); require_once(HEADERF);
if (!isset($pref['subnews_class'])) if (!isset($pref['subnews_class']))
{ {
$pref['subnews_class'] = "0"; $pref['subnews_class'] = '0';
} }
if (!check_class($pref['subnews_class'])) if (!check_class($pref['subnews_class']))
{ {
$ns->tablerender(NWSLAN_12, NWSLAN_11); $ns->tablerender(NWSLAN_12, NWSLAN_11);
@@ -33,114 +33,134 @@ if (!check_class($pref['subnews_class']))
exit; exit;
} }
$author_name = $tp->toDB($_POST['author_name']); if (isset($_POST['submitnews_submit']) && $_POST['submitnews_title'] && $_POST['submitnews_item'])
$author_email = $tp->toDB(check_email($_POST['author_email']));
if (isset($_POST['submit']))
{ {
$user = (USER ? USERNAME : $author_name); $ip = $e107->getip();
$email = (USER ? USEREMAIL : $author_email); $fp = new floodprotect;
if ($fp->flood("submitnews", "submitnews_datestamp") == FALSE)
if ($user && $email)
{ {
$ip = $e107->getip(); header("location:".e_BASE."index.php");
$fp = new floodprotect; exit;
if ($fp->flood("submitnews", "submitnews_datestamp") == false) }
$submitnews_user = (USER ? USERNAME : trim($tp->toDB($_POST['submitnews_name'])));
$submitnews_email = (USER ? USEREMAIL : trim(check_email($tp->toDB($_POST['submitnews_email']))));
$submitnews_title = $tp->toDB($_POST['submitnews_title']);
$submitnews_item = $tp->toDB($_POST['submitnews_item']);
$submitnews_item = str_replace("src="e107_images", "src="".SITEURL."e107_images", $submitnews_item);
$submitnews_file = "";
$submitnews_error = FALSE;
if (!$submitnews_user || !$submitnews_email)
{
$message = SUBNEWSLAN_7;
$submitnews_error = TRUE;
}
// ==== Process File Upload ====
if ($_FILES['file_userfile'] && $pref['subnews_attach'] && $pref['upload_enabled'] && check_class($pref['upload_class']) && FILE_UPLOADS)
{
require_once(e_HANDLER."upload_handler.php");
$uploaded = file_upload(e_IMAGE . "newspost_images/");
$filename = $uploaded[0]['name'];
$filetype = $uploaded[0]['type'];
$filesize = $uploaded[0]['size'];
$fileext = substr(strrchr($filename, "."), 1);
if ($filename && $fileext != "jpg" && $fileext != "gif" && $fileext != "png")
{ {
header("location:" . e_BASE . "index.php"); $message = SUBNEWSLAN_3;
exit; $submitnews_error = TRUE;
} }
$itemtitle = $tp->toDB($_POST['itemtitle']);
$item = $tp->toDB($_POST['e107_submitnews_item']); if (!$pref['upload_maxfilesize'])
$item = str_replace("src="e107_images", "src="" . SITEURL . "e107_images", $item);
// Process File Upload =================================================
if ($_FILES['file_userfile'] && $pref['subnews_attach'] && $pref['upload_enabled'] && check_class($pref['upload_class']) && FILE_UPLOADS)
{ {
require_once(e_HANDLER . "upload_handler.php"); $pref['upload_maxfilesize'] = ini_get('upload_max_filesize') * 1048576;
$uploaded = file_upload(e_IMAGE . "newspost_images/"); }
$file = $uploaded[0]['name'];
$filetype = $uploaded[0]['type']; if ($filesize > $pref['upload_maxfilesize'])
$filesize = $uploaded[0]['size']; {
$fileext = substr(strrchr($file, "."), 1); $message = SUBNEWSLAN_4;
$submitnews_error = TRUE;
if (!$pref['upload_maxfilesize']) }
if ($filename && !$submitnews_error)
{
$today = getdate();
$submitnews_file = USERID."_".$today[0]."_".str_replace(" ", "_", substr($submitnews_title, 0, 6)).".".$fileext;
if ($pref['subnews_resize'])
{ {
$pref['upload_maxfilesize'] = ini_get('upload_max_filesize') * 1048576; require_once(e_HANDLER."resize_handler.php");
}
if (!resize_image(e_IMAGE."newspost_images/".$filename, e_IMAGE."newspost_images/".$submitnews_file, $pref['subnews_resize']))
if ($uploaded && $fileext != "jpg" && $fileext != "gif" && $fileext != "png")
{
$message = SUBNEWSLAN_3;
$error = true;
}
if ($filesize > $pref['upload_maxfilesize'])
{
$message = SUBNEWSLAN_4;
$error = true;
}
if (!$error)
{
// $numberoffiles = count($uploaded);
$today = getdate();
$newname = USERID . "_" . $today[0] . "_" . str_replace(" ", "_", substr($itemtitle, 0, 6)) . "." . $fileext;
if ($file && $pref['subnews_resize'])
{ {
require_once(e_HANDLER . "resize_handler.php"); rename(e_IMAGE."newspost_images/".$filename, e_IMAGE."newspost_images/".$submitnews_file);
$rezwidth = $pref['subnews_resize'];
if (!resize_image(e_IMAGE . "newspost_images/" . $file, e_IMAGE . "newspost_images/" . $newname, $rezwidth))
{
rename(e_IMAGE . "newspost_images/" . $file, e_IMAGE . "newspost_images/" . $newname);
}
} elseif ($file)
{
rename(e_IMAGE . "newspost_images/" . $file, e_IMAGE . "newspost_images/" . $newname);
} }
} }
} elseif ($filename)
if ($error == false)
{
if (!file_exists(e_IMAGE . "newspost_images/" . $newname))
{ {
$newname = ""; rename(e_IMAGE."newspost_images/".$filename, e_IMAGE."newspost_images/".$submitnews_file);
} }
$sql->db_Insert("submitnews", "0, '$user', '$email', '$itemtitle', '".intval($_POST['cat_id'])."','$item', '" . time() . "', '$ip', '0', '$newname' ");
$edata_sn = array("user" => $user, "email" => $email, "itemtitle" => $itemtitle, "catid" => intval($_POST['cat_id']), "item" => $item, "ip" => $ip, "newname" => $newname);
$e_event->trigger("subnews", $edata_sn);
$ns->tablerender(LAN_133, "<div style='text-align:center'>" . LAN_134 . "</div>");
require_once(FOOTERF);
exit;
} }
else
if ($filename && !file_exists(e_IMAGE."newspost_images/".$submitnews_file))
{ {
require_once(e_HANDLER . "message_handler.php"); $submitnews_file = "";
message_handler("P_ALERT", $message);
} }
} }
if ($submitnews_error == FALSE)
{
$sql->db_Insert("submitnews", "0, '$submitnews_user', '$submitnews_email', '$submitnews_title', '".intval($_POST['cat_id'])."', '$submitnews_item', '".time()."', '$ip', '0', '$submitnews_file' ");
$edata_sn = array("user" => $submitnews_user, "email" => $submitnews_email, "itemtitle" => $submitnews_title, "catid" => intval($_POST['cat_id']), "item" => $submitnews_item, "ip" => $ip, "newname" => $submitnews_file);
$e_event->trigger("subnews", $edata_sn);
$ns->tablerender(LAN_133, "<div style='text-align:center'>".LAN_134."</div>");
require_once(FOOTERF);
exit;
}
else
{
require_once(e_HANDLER."message_handler.php");
message_handler("P_ALERT", $message);
}
} }
if (!defined("USER_WIDTH")){ define("USER_WIDTH","width:95%"); } if (!defined("USER_WIDTH")) { define("USER_WIDTH","width:95%"); }
$text = "<div style='text-align:center'> $text = "
<form id='dataform' method='post' action='" . e_SELF . "' enctype='multipart/form-data' onsubmit='return frmVerify()'>\n <div style='text-align:center'>
<table style='".USER_WIDTH."' class='fborder'>"; <form id='dataform' method='post' action='".e_SELF."' enctype='multipart/form-data' onsubmit='return frmVerify()'>
if (!USER) <table style='".USER_WIDTH."' class='fborder'>";
{
$text .= "<tr>\n<td style='width:20%' class='forumheader3'>" . LAN_7 . "</td>\n<td style='width:80%' class='forumheader3'>\n<input class='tbox' type='text' name='author_name' size='60' value='$author_name' maxlength='100' />\n</td>\n</tr>\n<tr>\n<td style='width:20%' class='forumheader3'>" . LAN_112 . "</td>\n<td style='width:80%' class='forumheader3'>\n<input class='tbox' type='text' name='author_email' size='60' value='$author_email' maxlength='100' />\n</td>\n</tr>";
}
if (!empty($pref['news_subheader'])) if (!empty($pref['news_subheader']))
{ {
$text .= " <tr> $text .= "
<td colspan='2' class='forumheader3'>" . $tp->toHTML($pref['news_subheader'], TRUE,'TITLE') . "</td> <tr>
</tr>"; <td colspan='2' class='forumheader3'>".$tp->toHTML($pref['news_subheader'], TRUE, "TITLE")."<br /></td>
</tr>";
} }
$text .= " <tr> if (!USER)
<td style='width:20%' class='forumheader3'>" . NWSLAN_6 . ": </td> {
<td style='width:80%' class='forumheader3'>"; $text .= "
<tr>
<td style='width:20%' class='forumheader3'>".LAN_7."</td>
<td style='width:80%' class='forumheader3'>
<input class='tbox' type='text' name='submitnews_name' size='60' value='".$tp->toHTML($submitnews_user,FALSE,'USER_TITLE')."' maxlength='100' />
</td>
</tr>
<tr>
<td style='width:20%' class='forumheader3'>".LAN_112."</td>
<td style='width:80%' class='forumheader3'>
<input class='tbox' type='text' name='submitnews_email' size='60' value='".$tp->toHTML($submitnews_email, FALSE, 'LINKTEXT')."' maxlength='100' />
</td>
</tr>";
}
$text .= "
<tr>
<td style='width:20%' class='forumheader3'>".NWSLAN_6.": </td>
<td style='width:80%' class='forumheader3'>";
if (!$sql->db_Select("news_category")) if (!$sql->db_Select("news_category"))
{ {
$text .= NWSLAN_10; $text .= NWSLAN_10;
@@ -148,89 +168,97 @@ if (!$sql->db_Select("news_category"))
else else
{ {
$text .= " $text .= "
<select name='cat_id' class='tbox'>"; <select name='submitnews_category' class='tbox'>";
while (list($cat_id, $cat_name, $cat_icon) = $sql->db_Fetch(MYSQL_NUM)) while (list($cat_id, $cat_name, $cat_icon) = $sql->db_Fetch(MYSQL_NUM))
{ {
$sel = ($_POST['cat_id'] == $cat_id) ? "selected='selected'" : ""; $sel = ($_POST['submitnews_category'] == $cat_id) ? "selected='selected'" : "";
$text .= "<option value='{$cat_id}' {$sel}>" . $tp->toHTML($cat_name,FALSE,"defs") . "</option>"; $text .= "<option value='{$cat_id}' {$sel}>".$tp->toHTML($cat_name, FALSE, "defs")."</option>";
} }
$text .= "</select>"; $text .= "</select>";
} }
$text .= "</td>
</tr><tr>
<td style='width:20%' class='forumheader3'>" . LAN_62 . "</td>
<td style='width:80%' class='forumheader3'>
<input class='tbox' type='text' id='itemtitle' name='itemtitle' size='60' value='{$itemtitle}' maxlength='200' style='width:90%' />
</td>
</tr>";
$text .= "
</td>
</tr>
<tr>
<td style='width:20%' class='forumheader3'>".LAN_62."</td>
<td style='width:80%' class='forumheader3'>
<input class='tbox' type='text' id='submitnews_title' name='submitnews_title' size='60' value='".$tp->toHTML($_POST['submitnews_title'],TRUE,'USER_TITLE')."' maxlength='200' style='width:90%' />
</td>
</tr>";
if (e_WYSIWYG) if (e_WYSIWYG)
{ {
$insertjs = "rows='25' "; $insertjs = "rows='25'";
} }
else else
{ {
require_once(e_HANDLER."ren_help.php"); require_once(e_HANDLER."ren_help.php");
$insertjs = "rows='15' onselect='storeCaret(this);' onclick='storeCaret(this);' onkeyup='storeCaret(this);'"; $insertjs = "rows='15' onselect='storeCaret(this);' onclick='storeCaret(this);' onkeyup='storeCaret(this);'";
} }
$text .= " $text .= "
<tr> <tr>
<td style='width:20%' class='forumheader3'>" . LAN_135 . "</td> <td style='width:20%' class='forumheader3'>".LAN_135."</td>
<td style='width:80%' class='forumheader3'> <td style='width:80%' class='forumheader3'>
<textarea class='tbox' id='e107_submitnews_item' name='e107_submitnews_item' cols='80' style='max-width:95%' {$insertjs}></textarea><br />"; <textarea class='tbox' id='submitnews_item' name='submitnews_item' cols='80' style='max-width:95%' {$insertjs}>".$tp->toHTML($_POST['submitnews_item'],TRUE,'USER_BODY')."</textarea><br />";
if (!e_WYSIWYG) if (!e_WYSIWYG)
{ {
$text .= display_help("helpb","submitnews"); $text .= display_help("helpb","submitnews");
}
$text .= " </td>
</tr>\n";
if ($pref['subnews_attach'] && $pref['upload_enabled'] && check_class($pref['upload_class']) && FILE_UPLOADS)
{
$text .= "
<tr>
<td style='width:20%' class='forumheader3'>" . SUBNEWSLAN_5 . "<br /><span class='smalltext'>" . SUBNEWSLAN_6 . "</span></td>
<td style='width:80%' class='forumheader3'>
<input class='tbox' type='file' name='file_userfile[]' style='width:90%' />
</td>
</tr>\n";
} }
$text .= " $text .= "
<tr> </td>
<td colspan='2' style='text-align:center' class='forumheader'> </tr>";
<input class='button' type='submit' name='submit' value='" . LAN_136 . "' />
</td> if ($pref['subnews_attach'] && $pref['upload_enabled'] && check_class($pref['upload_class']) && FILE_UPLOADS)
</tr> {
</table> $text .= "
</form> <tr>
<td style='width:20%' class='forumheader3'>".SUBNEWSLAN_5."<br /><span class='smalltext'>".SUBNEWSLAN_6."</span></td>
<td style='width:80%' class='forumheader3'>
<input class='tbox' type='file' name='file_userfile[]' style='width:90%' />
</td>
</tr>";
}
$text .= "
<tr>
<td colspan='2' style='text-align:center' class='forumheader'>
<input class='button' type='submit' name='submitnews_submit' value='".LAN_136."' />
</td>
</tr>
</table>
</form>
</div>"; </div>";
$ns->tablerender(LAN_136, $text); $ns->tablerender(LAN_136, $text);
require_once(FOOTERF); require_once(FOOTERF);
function headerjs() function headerjs()
{ {
$adder = ''; $adder = "";
if (e_WYSIWYG) $adder = 'triggerSave();'; if (e_WYSIWYG) $adder = 'tinyMCE.triggerSave();';
$script = "<script type=\"text/javascript\"> $script = "
function frmVerify() <script type=\"text/javascript\">
{ function frmVerify()
{$adder} {
if(document.getElementById('itemtitle').value == \"\") {$adder}
{ if(document.getElementById('submitnews_title').value == \"\")
alert('" . SUBNEWSLAN_1 . "'); {
return false; alert('".SUBNEWSLAN_1."');
} return false;
if(document.getElementById('e107_submitnews_item').value == \"\") }
{
alert('" . SUBNEWSLAN_2 . "'); if(document.getElementById('submitnews_item').value == \"\")
return false; {
} alert('".SUBNEWSLAN_2."');
} return false;
</script>"; }
return $script; }
</script>";
return $script;
} }
?> ?>