Merge branch 'tools-fileAttachment' of https://github.com/PrestaEdit/PrestaShop into PrestaEdit-tools-fileAttachment
Conflicts: classes/Tools.php controllers/front/ContactController.php
This commit is contained in:
commit
d55f31d3b5
3 files changed
+25
-22
No files matched your search
@@ -2516,6 +2516,21 @@ exit;
|
|||||||
// No content, return false
|
// No content, return false
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function fileAttachment($input = 'fileUpload')
|
||||||
|
{
|
||||||
|
$fileAttachment = null;
|
||||||
|
if (isset($_FILES[$input]['name']) && !empty($_FILES[$input]['name']) && !empty($_FILES[$input]['tmp_name']))
|
||||||
|
{
|
||||||
|
$fileAttachment['rename'] = uniqid(). self::strtolower(substr($_FILES[$input]['name'], -5));
|
||||||
|
$fileAttachment['content'] = file_get_contents($_FILES[$input]['tmp_name']);
|
||||||
|
$fileAttachment['tmp_name'] = $_FILES[$input]['tmp_name'];
|
||||||
|
$fileAttachment['name'] = $_FILES[$input]['name'];
|
||||||
|
$fileAttachment['mime'] = $_FILES[$input]['type'];
|
||||||
|
$fileAttachment['error'] = $_FILES[$input]['error'];
|
||||||
|
}
|
||||||
|
return $fileAttachment;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -37,15 +37,8 @@ class ContactControllerCore extends FrontController
|
|||||||
{
|
{
|
||||||
if (Tools::isSubmit('submitMessage'))
|
if (Tools::isSubmit('submitMessage'))
|
||||||
{
|
{
|
||||||
$fileAttachment = null;
|
$extension = array('.txt', '.rtf', '.doc', '.docx', '.pdf', '.zip', '.png', '.jpeg', '.gif', '.jpg');
|
||||||
if (isset($_FILES['fileUpload']['name']) && !empty($_FILES['fileUpload']['name']) && !empty($_FILES['fileUpload']['tmp_name']))
|
$fileAttachment = Tools::fileAttachment('fileUpload');
|
||||||
{
|
|
||||||
$extension = array('.txt', '.rtf', '.doc', '.docx', '.pdf', '.zip', '.png', '.jpeg', '.gif', '.jpg');
|
|
||||||
$filename = uniqid().substr($_FILES['fileUpload']['name'], -5);
|
|
||||||
$fileAttachment['content'] = file_get_contents($_FILES['fileUpload']['tmp_name']);
|
|
||||||
$fileAttachment['name'] = $_FILES['fileUpload']['name'];
|
|
||||||
$fileAttachment['mime'] = $_FILES['fileUpload']['type'];
|
|
||||||
}
|
|
||||||
$message = Tools::getValue('message'); // Html entities is not usefull, iscleanHtml check there is no bad html tags.
|
$message = Tools::getValue('message'); // Html entities is not usefull, iscleanHtml check there is no bad html tags.
|
||||||
if (!($from = trim(Tools::getValue('from'))) || !Validate::isEmail($from))
|
if (!($from = trim(Tools::getValue('from'))) || !Validate::isEmail($from))
|
||||||
$this->errors[] = Tools::displayError('Invalid email address.');
|
$this->errors[] = Tools::displayError('Invalid email address.');
|
||||||
@@ -55,9 +48,9 @@ class ContactControllerCore extends FrontController
|
|||||||
$this->errors[] = Tools::displayError('Invalid message');
|
$this->errors[] = Tools::displayError('Invalid message');
|
||||||
else if (!($id_contact = (int)(Tools::getValue('id_contact'))) || !(Validate::isLoadedObject($contact = new Contact($id_contact, $this->context->language->id))))
|
else if (!($id_contact = (int)(Tools::getValue('id_contact'))) || !(Validate::isLoadedObject($contact = new Contact($id_contact, $this->context->language->id))))
|
||||||
$this->errors[] = Tools::displayError('Please select a subject from the list provided. ');
|
$this->errors[] = Tools::displayError('Please select a subject from the list provided. ');
|
||||||
else if (!empty($_FILES['fileUpload']['name']) && $_FILES['fileUpload']['error'] != 0)
|
else if (!empty($fileAttachment['name']) && $fileAttachment['error'] != 0)
|
||||||
$this->errors[] = Tools::displayError('An error occurred during the file-upload process.');
|
$this->errors[] = Tools::displayError('An error occurred during the file-upload process.');
|
||||||
else if (!empty($_FILES['fileUpload']['name']) && !in_array(substr(Tools::strtolower($_FILES['fileUpload']['name']), -4), $extension) && !in_array(substr(Tools::strtolower($_FILES['fileUpload']['name']), -5), $extension))
|
else if (!empty($fileAttachment['name']) && !in_array( Tools::strtolower(substr($fileAttachment['name'], -4)), $extension) && !in_array( Tools::strtolower(substr($fileAttachment['name'], -5)), $extension))
|
||||||
$this->errors[] = Tools::displayError('Bad file extension');
|
$this->errors[] = Tools::displayError('Bad file extension');
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -152,8 +145,8 @@ class ContactControllerCore extends FrontController
|
|||||||
$cm = new CustomerMessage();
|
$cm = new CustomerMessage();
|
||||||
$cm->id_customer_thread = $ct->id;
|
$cm->id_customer_thread = $ct->id;
|
||||||
$cm->message = Tools::htmlentitiesUTF8($message);
|
$cm->message = Tools::htmlentitiesUTF8($message);
|
||||||
if (isset($filename) && rename($_FILES['fileUpload']['tmp_name'], _PS_MODULE_DIR_.'../upload/'.$filename))
|
if (isset($fileAttachment['rename']) && !empty($fileAttachment['rename']) && rename($fileAttachment['tmp_name'], _PS_MODULE_DIR_.'../upload/'.basename($fileAttachment['rename'])))
|
||||||
$cm->file_name = $filename;
|
$cm->file_name = $fileAttachment['rename'];
|
||||||
$cm->ip_address = ip2long($_SERVER['REMOTE_ADDR']);
|
$cm->ip_address = ip2long($_SERVER['REMOTE_ADDR']);
|
||||||
$cm->user_agent = $_SERVER['HTTP_USER_AGENT'];
|
$cm->user_agent = $_SERVER['HTTP_USER_AGENT'];
|
||||||
if (!$cm->add())
|
if (!$cm->add())
|
||||||
@@ -173,8 +166,8 @@ class ContactControllerCore extends FrontController
|
|||||||
'{product_name}' => '',
|
'{product_name}' => '',
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isset($filename))
|
if (isset($fileAttachment['name']))
|
||||||
$var_list['{attached_file}'] = $_FILES['fileUpload']['name'];
|
$var_list['{attached_file}'] = $fileAttachment['name'];
|
||||||
|
|
||||||
$id_order = (int)Tools::getValue('id_order');
|
$id_order = (int)Tools::getValue('id_order');
|
||||||
|
|
||||||
@@ -197,10 +190,6 @@ class ContactControllerCore extends FrontController
|
|||||||
$var_list['{product_name}'] = $product->name[Context::getContext()->language->id];
|
$var_list['{product_name}'] = $product->name[Context::getContext()->language->id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (empty($contact->email))
|
if (empty($contact->email))
|
||||||
Mail::Send($this->context->language->id, 'contact_form', ((isset($ct) && Validate::isLoadedObject($ct)) ? sprintf(Mail::l('Your message has been correctly sent #ct%1$s #tc%2$s'), $ct->id, $ct->token) : Mail::l('Your message has been correctly sent')), $var_list, $from, null, null, null, $fileAttachment);
|
Mail::Send($this->context->language->id, 'contact_form', ((isset($ct) && Validate::isLoadedObject($ct)) ? sprintf(Mail::l('Your message has been correctly sent #ct%1$s #tc%2$s'), $ct->id, $ct->token) : Mail::l('Your message has been correctly sent')), $var_list, $from, null, null, null, $fileAttachment);
|
||||||
else
|
else
|
||||||
@@ -297,4 +286,3 @@ class ContactControllerCore extends FrontController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,8 +89,8 @@
|
|||||||
{/foreach}
|
{/foreach}
|
||||||
</select>
|
</select>
|
||||||
{elseif !isset($customerThread.id_order) && !isset($isLogged)}
|
{elseif !isset($customerThread.id_order) && !isset($isLogged)}
|
||||||
<input type="text" name="id_order" id="id_order" value="{if isset($customerThread.id_order) && $customerThread.id_order > 0}{$customerThread.id_order|intval}{else}{if isset($smarty.post.id_order)}{$smarty.post.id_order|intval}{/if}{/if}" />
|
<input type="text" name="id_order" id="id_order" value="{if isset($customerThread.id_order) && $customerThread.id_order|intval > 0}{$customerThread.id_order|intval}{else}{if isset($smarty.post.id_order) && !empty($smarty.post.id_order|intval)}{$smarty.post.id_order|intval}{/if}{/if}" />
|
||||||
{elseif $customerThread.id_order > 0}
|
{elseif $customerThread.id_order|intval > 0}
|
||||||
<input type="text" name="id_order" id="id_order" value="{$customerThread.id_order|intval}" readonly="readonly" />
|
<input type="text" name="id_order" id="id_order" value="{$customerThread.id_order|intval}" readonly="readonly" />
|
||||||
{/if}
|
{/if}
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
Reference in new issue
Block a user