HEX
Server: Apache
System: Linux srv13.cpanelhost.cl 3.10.0-962.3.2.lve1.5.38.el7.x86_64 #1 SMP Thu Jun 18 05:28:41 EDT 2020 x86_64
User: cca63905 (4205)
PHP: 7.3.20
Disabled: NONE
Upload Files
File: /home4/cca63905/www/nueva/override/controllers/front/CmsController.php
<?php
/**
* 2007-2015 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author    PrestaShop SA <contact@prestashop.com>
*  @copyright 2007-2015 PrestaShop SA
*  @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/
class CmsController extends CmsControllerCore
{
    /*
    * module: cmscontact
    * date: 2023-08-09 15:14:45
    * version: 1.0.0
    */
    public function initContent()
    {
        $content = $this->cms->content;
        $patron = '/\[([^>]*)\]/';
        preg_match($patron, $content, $coincidencias);
        if(Configuration::get('cmscontact_activationKey') != '') {   
            if ($coincidencias) {
                $textController = $coincidencias[0];
                $textController = str_replace('[', '', $textController);
                $textController = str_replace(']', '', $textController);
                $parametros = explode(' ', $textController);
                $cont = Tools::ucfirst(Tools::strtolower($parametros[0])).'Controller';
                if ($cont == 'ContactController') {
                    FrontController::setMedia();
                    $this->addCSS(_THEME_CSS_DIR_.'contact-form.css');
                    $this->addJS(_THEME_JS_DIR_.'contact-form.js');
                    $this->addJS(_PS_JS_DIR_.'validate.js');
                                    
                    ob_start();
                    $this->assignOrderList();
                    $email = Tools::safeOutput(
                        Tools::getValue(
                            'from',
                            ((isset($this->context->cookie) &&
                                isset($this->context->cookie->email) &&
                                Validate::isEmail($this->context->cookie->email)) ? $this->context->cookie->email : '')
                        )
                    );
                    $this->context->smarty->assign(array(
                        'errors' => $this->errors,
                        'email' => $email,
                        'fileupload' => Configuration::get('PS_CUSTOMER_SERVICE_FILE_UPLOAD'),
                        'max_upload_size' => (int)Tools::getMaxUploadSize()
                    ));
                    if (($id_customer_thread = (int)Tools::getValue('id_customer_thread')) &&
                        $token = Tools::getValue('token')) {
                        $customer_thread = Db::getInstance()->getRow('
                            SELECT cm.*
                            FROM '._DB_PREFIX_.'customer_thread cm
                            WHERE cm.id_customer_thread = '.(int)$id_customer_thread.'
                            AND cm.id_shop = '.(int)$this->context->shop->id.'
                            AND token = \''.pSQL($token).'\'
                        ');
                        $order = new Order((int)$customer_thread['id_order']);
                        if (Validate::isLoadedObject($order)) {
                            $customer_thread['reference'] = $order->getUniqReference();
                        }
                        $this->context->smarty->assign('customerThread', $customer_thread);
                    }
                    $link = new Link();
                    $this->context->smarty->assign(array(
                        'contacts' => Contact::getContacts($this->context->language->id),
                        'message' => html_entity_decode(Tools::getValue('message')),
                        'request_uri' => $link->getPageLink('contact'),
                    ));
                    echo $this->context->smarty->display(_PS_THEME_DIR_.'contact-form.tpl');
                    $template = ob_get_contents();
                    ob_clean();
                    $template .= "<script type='text/javascript'>var xxx = $('.breadcrumb');xxx[0].childNodes[4].nodeValue = '".$this->cms->meta_title."';</script>";
                    $content = str_replace('['.$parametros[0].']', $template, $content);
                }
                
            }
        }
        $this->cms->content = $content;
        parent::initContent();
    }
    /**
    * Assign template vars related to order list and product list ordered by the customer
    */
    /*
    * module: cmscontact
    * date: 2023-08-09 15:14:45
    * version: 1.0.0
    */
    protected function assignOrderList()
    {
        if ($this->context->customer->isLogged()) {
            $this->context->smarty->assign('isLogged', 1);
            $products = array();
            $result = Db::getInstance()->executeS(
                'SELECT id_order FROM '._DB_PREFIX_.'orders WHERE id_customer = '.
                (int)$this->context->customer->id.
                Shop::addSqlRestriction(Shop::SHARE_ORDER).' ORDER BY date_add'
            );
            $orders = array();
            foreach ($result as $row) {
                $order = new Order($row['id_order']);
                $date = explode(' ', $order->date_add);
                $tmp = $order->getProducts();
                foreach ($tmp as $val) {
                    $products[$row['id_order']][$val['product_id']] = array('value' => $val['product_id'],
                        'label' => $val['product_name']);
                }
                $orders[] = array('value' => $order->id,
                    'label' => $order->getUniqReference().' - '.Tools::displayDate($date[0], null),
                    'selected' => (int)$this->getOrder() == $order->id);
            }
            $this->context->smarty->assign('orderList', $orders);
            $this->context->smarty->assign('orderedProductList', $products);
        }
    }
    /*
    * module: cmscontact
    * date: 2023-08-09 15:14:45
    * version: 1.0.0
    */
    protected function getOrder()
    {
        $id_order = false;
        if (!is_numeric($reference = Tools::getValue('id_order'))) {
            $reference = ltrim($reference, '#');
            $orders = Order::getByReference($reference);
            if ($orders) {
                foreach ($orders as $order) {
                    $id_order = (int)$order->id;
                    break;
                }
            }
        } elseif (Order::getCartIdStatic((int)Tools::getValue('id_order'))) {
            $id_order = (int)Tools::getValue('id_order');
        }
        return (int)$id_order;
    }
}