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

SubmitNews code cleanup. Admin can now set minimum dimensions for attached images.

This commit is contained in:
Cameron
2016-03-16 19:54:10 -07:00
parent 1202c72390
commit 7846015f85
4 changed files with 354 additions and 213 deletions

View File

@@ -508,17 +508,23 @@ echo getAlert();
return ' return '
<div id="uiModal" class="modal hide fade" tabindex="-1" role="dialog" aria-hidden="true"> <div id="uiModal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-caption">&nbsp;</h4> <h4 class="modal-caption">&nbsp;</h4>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<p>Loading…</p> <p>Loading…</p>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<a href="#" data-dismiss="modal" class="btn btn-primary">Close</a> <a href="#" data-dismiss="modal" class="btn btn-primary">Close</a>
</div> </div>
</div>
</div>
</div>'; </div>';
} }

View File

@@ -835,6 +835,7 @@ class news_admin_ui extends e_admin_ui
$temp['nbr_cols'] = intval($_POST['nbr_cols']); $temp['nbr_cols'] = intval($_POST['nbr_cols']);
$temp['subnews_attach'] = intval($_POST['subnews_attach']); $temp['subnews_attach'] = intval($_POST['subnews_attach']);
$temp['subnews_resize'] = intval($_POST['subnews_resize']); $temp['subnews_resize'] = intval($_POST['subnews_resize']);
$temp['subnews_attach_minsize'] = e107::getParser()->filter($_POST['subnews_attach_minsize']);
$temp['subnews_class'] = intval($_POST['subnews_class']); $temp['subnews_class'] = intval($_POST['subnews_class']);
$temp['subnews_htmlarea'] = intval($_POST['subnews_htmlarea']); $temp['subnews_htmlarea'] = intval($_POST['subnews_htmlarea']);
$temp['news_subheader'] = e107::getParser()->toDB($_POST['news_subheader']); $temp['news_subheader'] = e107::getParser()->toDB($_POST['news_subheader']);
@@ -1083,7 +1084,7 @@ class news_admin_ui extends e_admin_ui
$text = " $text = "
<form method='post' action='".e_SELF."?pref' id='core-newspost-settings-form'>"; <form method='post' action='".e_REQUEST_URI."' id='core-newspost-settings-form'>";
$tab1 = " $tab1 = "
@@ -1164,6 +1165,28 @@ class news_admin_ui extends e_admin_ui
</tr> </tr>
"; ";
$imageSizes = array(
'400×300' => '400x300',
'640×480' => '640x480',
'800×600' => '800x600',
'1024×768' => '1024x768',
'1600x1200' => '2 MP (1600×1200)',
'2272x1704' => '4 MP (2272×1704)',
'2816x2112' => '6 MP (2816×2112)',
'3264x2448' => '8 MP (3264×2448)',
// 10 MP (3648×2736)
// 12 MP (4096×3072)
);
$tab2 = "<table class='table adminform'> $tab2 = "<table class='table adminform'>
<colgroup> <colgroup>
<col class='col-label' /> <col class='col-label' />
@@ -1188,6 +1211,12 @@ class news_admin_ui extends e_admin_ui
<td> <td>
".$frm->radio_switch('subnews_attach', $pref['subnews_attach'])." ".$frm->radio_switch('subnews_attach', $pref['subnews_attach'])."
</td> </td>
</tr>
<tr>
<td>Only accept images larger than</td>
<td>
".$frm->select('subnews_attach_minsize', $imageSizes, $pref['subnews_attach_minsize'], null, 'Any Size')."
</td>
</tr> </tr>
<tr> <tr>
<td>".NWSLAN_101."</td> <td>".NWSLAN_101."</td>

View File

@@ -191,6 +191,7 @@ function process_uploaded_files($uploaddir, $fileinfo = FALSE, $options = NULL)
$c = 0; $c = 0;
$tp = e107::getParser(); $tp = e107::getParser();
$uploadfile = null;
foreach ($files['name'] as $key=>$name) foreach ($files['name'] as $key=>$name)
{ {
@@ -299,6 +300,8 @@ function process_uploaded_files($uploaddir, $fileinfo = FALSE, $options = NULL)
if (!$first_error) // All tests passed - can store it somewhere if (!$first_error) // All tests passed - can store it somewhere
{ {
$uploaded[$c] = e107::getFile()->get_file_info($uploadfile,true);
$uploaded[$c]['name'] = $name; $uploaded[$c]['name'] = $name;
$uploaded[$c]['rawname'] = $raw_name; $uploaded[$c]['rawname'] = $raw_name;
$uploaded[$c]['origname'] = $origname; $uploaded[$c]['origname'] = $origname;
@@ -306,6 +309,8 @@ function process_uploaded_files($uploaddir, $fileinfo = FALSE, $options = NULL)
$uploaded[$c]['size'] = 0; $uploaded[$c]['size'] = 0;
$uploaded[$c]['index'] = $key; // Store the actual index from the file_userfile array $uploaded[$c]['index'] = $key; // Store the actual index from the file_userfile array
// e107::getMessage()->addDebug(print_a($uploaded[$c],true));
// Store as flat file // Store as flat file
if ((!$ul_temp_dir && @move_uploaded_file($uploadfile, $destination_file)) || ($ul_temp_dir && @rename($uploadfile, $destination_file))) // This should work on all hosts if ((!$ul_temp_dir && @move_uploaded_file($uploadfile, $destination_file)) || ($ul_temp_dir && @rename($uploadfile, $destination_file))) // This should work on all hosts
{ {

View File

@@ -25,7 +25,6 @@ if (!isset($pref['subnews_class']))
} }
if (!check_class($pref['subnews_class'])) if (!check_class($pref['subnews_class']))
{ {
$ns->tablerender(LAN_UI_403_TITLE_ERROR, LAN_UI_403_BODY_ERROR); $ns->tablerender(LAN_UI_403_TITLE_ERROR, LAN_UI_403_BODY_ERROR);
@@ -33,11 +32,58 @@ if (!check_class($pref['subnews_class']))
exit; exit;
} }
if (isset($_POST['submitnews_submit']) && $_POST['submitnews_title'] && $_POST['submitnews_item'])
if (!defined("USER_WIDTH")) { define("USER_WIDTH","width:95%"); }
class submitNews
{
private $minWidth = 1024;
private $minHeight = 768;
function __construct()
{
$mes = e107::getMessage();
$minDimensions = e107::pref('core','subnews_attach_minsize',false);
if(empty($minDimensions))
{
$this->minWidth = 0;
$this->minHeight = 0;
}
else
{
$tmp = explode('×',$minDimensions);
$this->minWidth = intval($tmp[0]);
$this->minHeight = intval($tmp[1]);
}
if(isset($_POST['submitnews_submit']) && !empty($_POST['submitnews_title']) && !empty($_POST['submitnews_item']))
{
$this->process();
}
echo $mes->render();
$this->form();
}
function process()
{ {
$ip = e107::getIPHandler()->getIP(FALSE); $ip = e107::getIPHandler()->getIP(FALSE);
$tp = e107::getParser();
$pref = e107::pref('core');
$sql = e107::getDb();
$mes = e107::getMessage();
$fp = new floodprotect; $fp = new floodprotect;
if ($fp->flood("submitnews", "submitnews_datestamp") == FALSE)
if ($fp->flood("submitnews", "submitnews_datestamp") == false)
{ {
e107::redirect(); e107::redirect();
exit; exit;
@@ -47,9 +93,11 @@ if (isset($_POST['submitnews_submit']) && $_POST['submitnews_title'] && $_POST['
$submitnews_email = (USER ? USEREMAIL : trim(check_email($tp->toDB($_POST['submitnews_email'])))); $submitnews_email = (USER ? USEREMAIL : trim(check_email($tp->toDB($_POST['submitnews_email']))));
$submitnews_title = $tp->toDB($_POST['submitnews_title']); $submitnews_title = $tp->toDB($_POST['submitnews_title']);
$submitnews_item = $tp->toDB($_POST['submitnews_item']); $submitnews_item = $tp->toDB($_POST['submitnews_item']);
$submitnews_item = str_replace("src=&quot;e107_images", "src=&quot;".SITEURL."e107_images", $submitnews_item); // $submitnews_item = str_replace("src=&quot;e107_images", "src=&quot;".SITEURL."e107_images", $submitnews_item);
$submitnews_file = ""; $submitnews_file = "";
$submitnews_error = FALSE; $submitnews_error = false;
$submitnews_filearray = array();
if (!$submitnews_user || !$submitnews_email) if (!$submitnews_user || !$submitnews_email)
{ {
$message = SUBNEWSLAN_7; $message = SUBNEWSLAN_7;
@@ -57,22 +105,28 @@ if (isset($_POST['submitnews_submit']) && $_POST['submitnews_title'] && $_POST['
} }
// ==== Process File Upload ==== // ==== Process File Upload ====
if (FILE_UPLOADS && $_FILES['file_userfile'] && vartrue($pref['subnews_attach']) && vartrue($pref['upload_enabled']) && check_class($pref['upload_class'])) if (FILE_UPLOADS && !empty($_FILES['file_userfile']) && vartrue($pref['subnews_attach']) && vartrue($pref['upload_enabled']) && check_class($pref['upload_class']))
{ {
require_once(e_HANDLER.'upload_handler.php'); $uploaded = e107::getFile()->getUploaded(e_UPLOAD, 'unique', array('file_mask' => 'jpg,gif,png', 'max_file_count' => 3));
$uploaded = process_uploaded_files(e_UPLOAD, FALSE, array('file_mask' => 'jpg,gif,png', 'max_file_count' => 1));
if (($uploaded === FALSE) || !is_array($uploaded)) if (empty($uploaded)) // Non-specific error
{ // Non-specific error {
$submitnews_error = TRUE; $submitnews_error = true;
$message = SUBNEWSLAN_8; $message = SUBNEWSLAN_8;
} }
else else
{ {
$submitnews_filearray = array();
foreach($uploaded as $c=>$v) foreach($uploaded as $c=>$v)
{ {
// Check if images is too small.
if(!empty($this->minWidth) && !empty($v['img-width']) && (intval($v['img-width']) < $this->minWidth || intval($v['img-width']) < $this->minHeight))
{
//TODO Lan and review wording.
$mes->addWarning("One of your images has dimensions smaller than ".$this->minWidth."px x ".$this->minHeight."px. Please correct the attachment and submit the form again. ");
return false;
}
if (varset($uploaded[$c]['error'],0) != 0) if (varset($uploaded[$c]['error'],0) != 0)
{ {
$submitnews_error = TRUE; $submitnews_error = TRUE;
@@ -86,7 +140,9 @@ if (isset($_POST['submitnews_submit']) && $_POST['submitnews_title'] && $_POST['
$filetype = $uploaded[$c]['type']; $filetype = $uploaded[$c]['type'];
$filesize = $uploaded[$c]['size']; $filesize = $uploaded[$c]['size'];
$fileext = substr(strrchr($filename, "."), 1); $fileext = substr(strrchr($filename, "."), 1);
$today = getdate(); $today = getdate();
$submitnews_file = USERID."_".$today[0]."_".$c."_".str_replace(" ", "_", substr($submitnews_title, 0, 6)).".".$fileext; $submitnews_file = USERID."_".$today[0]."_".$c."_".str_replace(" ", "_", substr($submitnews_title, 0, 6)).".".$fileext;
if (is_numeric($pref['subnews_resize']) && ($pref['subnews_resize'] > 30) && ($pref['subnews_resize'] < 5000)) if (is_numeric($pref['subnews_resize']) && ($pref['subnews_resize'] > 30) && ($pref['subnews_resize'] < 5000))
@@ -115,42 +171,65 @@ if (isset($_POST['submitnews_submit']) && $_POST['submitnews_title'] && $_POST['
} }
if ($submitnews_error === FALSE) if ($submitnews_error === false)
{ {
$sql->insert("submitnews", "0, '$submitnews_user', '$submitnews_email', '$submitnews_title', '".intval($_POST['cat_id'])."', '$submitnews_item', '".time()."', '$ip', '0', '".implode(',',$submitnews_filearray)."' ");
$insertQry = array(
'submitnews_id' => 0,
'submitnews_name' => $submitnews_user,
'submitnews_email' => $submitnews_email,
'submitnews_title' => $submitnews_title,
'submitnews_category' => intval($_POST['cat_id']),
'submitnews_item' => $submitnews_item,
'submitnews_datestamp' => time(),
'submitnews_ip' => $ip,
'submitnews_auth' => '0',
'submitnews_file' => implode(',',$submitnews_filearray),
);
if(!$sql->insert("submitnews", $insertQry))
{
$mes->addError(LAN_134);
return false;
}
// $sql->insert("submitnews", "0, '$submitnews_user', '$submitnews_email', '$submitnews_title', '".intval($_POST['cat_id'])."', '$submitnews_item', '".time()."', '$ip', '0', '".implode(',',$submitnews_filearray)."' ");
$edata_sn = array("user" => $submitnews_user, "email" => $submitnews_email, "itemtitle" => $submitnews_title, "catid" => intval($_POST['cat_id']), "item" => $submitnews_item, "image" => $submitnews_file, "ip" => $ip); $edata_sn = array("user" => $submitnews_user, "email" => $submitnews_email, "itemtitle" => $submitnews_title, "catid" => intval($_POST['cat_id']), "item" => $submitnews_item, "image" => $submitnews_file, "ip" => $ip);
e107::getEvent()->trigger("subnews", $edata_sn); // bc e107::getEvent()->trigger("subnews", $edata_sn); // bc
e107::getEvent()->trigger("user_news_submit", $edata_sn); e107::getEvent()->trigger("user_news_submit", $edata_sn);
$mes = e107::getMessage();
$mes->addSuccess(LAN_134); $mes->addSuccess(LAN_134);
echo $mes->render(); // echo $mes->render();
unset($_POST);
// $ns->tablerender(LAN_133, "<div style='text-align:center'>".LAN_134."</div>"); // $ns->tablerender(LAN_133, "<div style='text-align:center'>".LAN_134."</div>");
require_once(FOOTERF);
exit;
} }
else else
{ {
message_handler("P_ALERT", $message); // message_handler("P_ALERT", $message);
$mes->addWarning($message);
} }
} }
function form()
{
$tp = e107::getParser();
$sql = e107::getDb();
$ns = e107::getRender();
$pref = e107::pref('core');
$text = ""; $text = "";
if (!defined("USER_WIDTH")) { define("USER_WIDTH","width:95%"); }
if (!empty($pref['news_subheader'])) if (!empty($pref['news_subheader']))
{ {
$text .= $tp->toHTML($pref['news_subheader'], true, "BODY");
$text .= "
".$tp->toHTML($pref['news_subheader'], true, "BODY")."
";
} }
@@ -167,13 +246,13 @@ if (!USER)
<tr> <tr>
<td style='width:20%' class='forumheader3'>".LAN_7."</td> <td style='width:20%' class='forumheader3'>".LAN_7."</td>
<td style='width:80%' class='forumheader3'> <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' required /> <input class='tbox' type='text' name='submitnews_name' size='60' value='".$tp->toHTML($_POST['submitnew_name'],FALSE,'USER_TITLE')."' maxlength='100' required />
</td> </td>
</tr> </tr>
<tr> <tr>
<td style='width:20%' class='forumheader3'>".LAN_112."</td> <td style='width:20%' class='forumheader3'>".LAN_112."</td>
<td style='width:80%' class='forumheader3'> <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' required /> <input class='tbox' type='text' name='submitnews_email' size='60' value='".$tp->filter($_POST['submitnews_email'], 'email')."' maxlength='100' required />
</td> </td>
</tr>"; </tr>";
} }
@@ -189,8 +268,7 @@ if (!$sql->select("news_category"))
} }
else else
{ {
$text .= " $text .= "<select name='cat_id' class='tbox form-control'>";
<select name='cat_id' class='tbox form-control'>";
while (list($cat_id, $cat_name, $cat_icon) = $sql->fetch('num')) while (list($cat_id, $cat_name, $cat_icon) = $sql->fetch('num'))
{ {
$sel = (varset($_POST['cat_id'],'') == $cat_id) ? "selected='selected'" : ""; $sel = (varset($_POST['cat_id'],'') == $cat_id) ? "selected='selected'" : "";
@@ -210,7 +288,7 @@ $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'>
".e107::getForm()->bbarea('submitnews_item', $tp->toForm(vartrue($_POST['submitnews_item'])),null, null, 'large', 'required=1')." ".e107::getForm()->bbarea('submitnews_item', $tp->toForm(vartrue($_POST['submitnews_item'])),null, null, 'large')."
</td> </td>
</tr> </tr>
"; ";
@@ -219,9 +297,24 @@ if ($pref['subnews_attach'] && $pref['upload_enabled'] && check_class($pref['upl
{ {
$text .= " $text .= "
<tr> <tr>
<td style='width:20%' class='forumheader3'>".SUBNEWSLAN_5."<br /><span class='smalltext'>".SUBNEWSLAN_6."</span></td> <td style='width:20%' class='forumheader3'>".SUBNEWSLAN_5."<br /><span class='smalltext'>".SUBNEWSLAN_6."</span>";
$text .= "
</td>
<td style='width:80%' class='forumheader3'> <td style='width:80%' class='forumheader3'>
<input class='tbox' type='file' name='file_userfile[]' style='width:90%' multiple='multiple' />
<input class='tbox' type='file' name='file_userfile[]' multiple='multiple' />
";
if(!empty($this->minWidth))
{
$text .= "<div class='alert alert-warning'>Minimum Dimensions: ".$this->minWidth."px × ".$this->minHeight."px</div>";
}
$text .= "
</td> </td>
</tr>"; </tr>";
} }
@@ -240,6 +333,14 @@ $text .= "
$ns->tablerender(LAN_136, $text); $ns->tablerender(LAN_136, $text);
}
}
new submitNews;
if(!vartrue($pref['subnews_htmlarea'])) // check after bbarea is called. if(!vartrue($pref['subnews_htmlarea'])) // check after bbarea is called.
{ {