升级后使用Prestashop 8.1.5提交错误工具

问题描述 投票:0回答:1

我有一个模块,开发者不再支持 PrestaShop,它已更改为 WooCommerce...

问题是,我真的很喜欢这个模块,并且我将本地主机从 PrestaShop 1.7.8.7 更新到了 PrestaShop 8.1.5。

嗯,这个模块安装得很好,选项似乎有效,但保存时出现错误。

syntax error, unexpected 'elseif' (T_ELSEIF), expecting function (T_FUNCTION) or const (T_CONST)

也许有经验的人可以指导我修复这个模块。

我认为可能是括号的原因,但我找不到错误。

我尝试修改括号,但似乎我一直失败,而且不起作用,我希望你能指导我。

public function postProcess()
    {
       if(Tools::isSubmit('submitAjaxCall')){
           $getstyle = (bool)Tools::getValue('getstyle');
            if($getstyle){
                $gwadvancedinvoice = Module::getInstanceByName('gwadvancedinvoice');
                $choose_design = Tools::getValue('choose_design');
                $template_config = Tools::getValue('template_config');
                $id_language = (int)Tools::getValue('id_language');
                if($choose_design !='' && is_array($template_config) && !empty($template_config))
                    echo  $gwadvancedinvoice->hookAjaxCallStyle(array('choose_design' => $choose_design,'template_config'=>$template_config,'id_language'=>$id_language));
            }else{
                $gwadvancedinvoice = Module::getInstanceByName('gwadvancedinvoice');
                $pagesize = Tools::getValue('pagesize');
                if($pagesize !='')
                    echo $gwadvancedinvoice->hookAjaxCall(array('template' => '','pagesize'=>$pagesize));
            }
            die();
       }elseif (Tools::isSubmit('previewTemplate')){
            $pdf_renderer = new PDFGenerator((bool)Configuration::get('PS_PDF_USE_CACHE'), Tools::getValue('pageorientation'));
            $useSSL = ((isset($this->ssl) && $this->ssl && Configuration::get('PS_SSL_ENABLED')) || Tools::usingSecureMode()) ? true : false;
            $protocol_content = ($useSSL) ? 'https://' : 'http://';
            $base_url = $protocol_content.Tools::getHttpHost().__PS_BASE_URI__;
            
            $layout = time().rand(1,999999999);
            if(version_compare(_PS_VERSION_,'1.6.0') == 1){
                $datas = $_POST+$_GET;
                // version left than 1.6.4->1.6.9 missing function Tools::getAllValues();
            }else{
                $datas = Tools::getAllValues();
            }
            $id_language = Context::getContext()->language->id;
            if(Tools::getValue('previewTemplate'))
                $id_language =  Tools::getValue('previewTemplate');
            
            $styles = '';
            $temp = $datas['choose_design'];
            $language = new Language($id_language);
            if(Tools::file_exists_no_cache(_PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/tpltemplates/base/'.$temp.'/'.$language->iso_code.'/styles.tpl')){
                $styles = Tools::file_get_contents(_PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/tpltemplates/base/'.$temp.'/'.$language->iso_code.'/styles.tpl');
            }elseif(Tools::file_exists_no_cache(_PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/tpltemplates/base/'.$temp.'/en/styles.tpl')){
                $styles = Tools::file_get_contents(_PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/tpltemplates/base/'.$temp.'/en/styles.tpl');
            }
            $discounttype = Tools::getValue('discountval');
            if($discounttype != 'exclude') $discounttype = 'include';
            gwadvancedinvoicetemplateModel::writeTemplate('styles.tpl','../modules/'.$this->module->name.'/views/templates/admin/tpltemplates/previews/'.$layout,$styles);
            gwadvancedinvoicetemplateModel::writeTemplate('product_list.tpl','../modules/'.$this->module->name.'/views/templates/admin/tpltemplates/previews/'.$layout,gwadvancedinvoicetemplateModel::getProductListTpl($datas['widthtitle'],$datas['colums_title_'.$id_language],$datas['colums_content_'.$id_language],$datas['colums_align_'.$id_language],$temp,$language->iso_code,$discounttype));
            gwadvancedinvoicetemplateModel::writeTemplate('template.tpl','../modules/'.$this->module->name.'/views/templates/admin/tpltemplates/previews/'.$layout,str_replace('{displayPrice:$','{displayPrice currency=$order->id_currency price=$',$datas['invoice_'.$id_language]));
            
            $header_content = '';
            if(Tools::getValue('header_'.$id_language)) $header_content = Tools::getValue('header_'.$id_language);
            if(Tools::getValue('activeheader')){
                gwadvancedinvoicetemplateModel::writeTemplate('header.tpl','../modules/'.$this->module->name.'/views/templates/admin/tpltemplates/previews/'.$layout,$header_content);
            }
            $footer_content = '';
            if(Tools::getValue('footer_'.$id_language)) $footer_content = Tools::getValue('footer_'.$id_language);
            if(Tools::getValue('activefooter')){
                gwadvancedinvoicetemplateModel::writeTemplate('footer.tpl','../modules/'.$this->module->name.'/views/templates/admin/tpltemplates/previews/'.$layout,$footer_content);
            }
           
            $data = gwadvancedinvoicetemplateModel::getDataDemo();
            
            $template_config = Tools::getValue('template_config');
            foreach($template_config as $key=>$template_config){
                $data[$key] = $template_config;
            }
            $code = $datas['barcodeproductformat'];
            foreach($data['order_details'] as &$order_details){
                $text = '';
                if($code == 'product_link'){
                    $text = urlencode($base_url);
                }else{
                    $text = urlencode($order_details[$code]);
                }
                $filename = md5($datas['barcodeproducttype'].'_'.$text).'.png';
                if(!Tools::file_exists_no_cache(_PS_MODULE_DIR_.'gwadvancedinvoice/views/img/barcodes/'.$filename)){
                    if($datas['barcodeproducttype'] == 'qrcode'){
                        $qrcodeObj =  new QRCodeLib($text);
                        $im = $qrcodeObj->createImage(4,2);
                        imagepng($im,_PS_MODULE_DIR_.'gwadvancedinvoice/views/img/barcodes/'.$filename);
                    }else{
                        $bacodeObj = new Barcode($text,$datas['barcodeproducttype']);
                        $bacodeObj->getBarcodePNG(_PS_MODULE_DIR_.'gwadvancedinvoice/views/img/barcodes/'.$filename,2,35,array(0,0,0)); 
                    }
                }
                if(Tools::file_exists_no_cache(_PS_MODULE_DIR_.'gwadvancedinvoice/views/img/barcodes/'.$filename)){
                    $order_details['barcode'] = '<img src="'.$base_url.'modules/gwadvancedinvoice/views/img/barcodes/'.$filename.'"/>';
                }else{
                    $order_details['barcode'] = '';
                }
            }
            Context::getContext()->smarty->assign($data);
            $products_list_temp =  _PS_MODULE_DIR_.'gwadvancedinvoice/views/templates/admin/tpltemplates/previews/'.$layout.'/product_list.tpl';
            $products_list = Context::getContext()->smarty->fetch($products_list_temp);
            $data['products_list'] = $products_list;
            $code = '1234567890';
            $filename = md5($datas['barcodetype'].'_'.$code).'.png';
            if(!Tools::file_exists_no_cache(_PS_MODULE_DIR_.'gwadvancedinvoice/views/img/barcodes/'.$filename)){
                if($datas['barcodetype'] == 'qrcode'){
                    $qrcodeObj =  new QRCodeLib($code);
                    $im = $qrcodeObj->createImage(4,2);
                    imagepng($im,_PS_MODULE_DIR_.'gwadvancedinvoice/views/img/barcodes/'.$filename);
                }else{
                    $bacodeObj = new Barcode($code,$datas['barcodetype']);
                    $bacodeObj->getBarcodePNG(_PS_MODULE_DIR_.'gwadvancedinvoice/views/img/barcodes/'.$filename,2,35,array(0,0,0)); 
                }
            }
            
            if(Tools::file_exists_no_cache(_PS_MODULE_DIR_.'gwadvancedinvoice/views/img/barcodes/'.$filename)){
                $data['barcode_invoice'] = '<img src="'.$base_url.'modules/gwadvancedinvoice/views/img/barcodes/'.$filename.'"/>';
            }else{
                $data['barcode_invoice'] = '';
            }
            $data['custom_style'] = $datas['customcss'];
            Context::getContext()->smarty->assign($data);
            $pdf_renderer->setCurOrientation($datas['pagesize'],$datas['pageorientation']);
            if(Tools::getValue('rtl')){
                $pdf_renderer->setRTL((bool)Tools::getValue('rtl'));
            }
            
            $style = Context::getContext()->smarty->fetch(_PS_MODULE_DIR_.'gwadvancedinvoice/views/templates/admin/tpltemplates/previews/'.$layout.'/styles.tpl');
            if(Tools::getValue('activeheader')){
                $temp =  _PS_MODULE_DIR_.'gwadvancedinvoice/views/templates/admin/tpltemplates/previews/'.$layout.'/header.tpl';
                $pdf_renderer->createHeader('<style>'.strip_tags($style).'</style>'.Context::getContext()->smarty->fetch($temp));
                $pdf_renderer->SetPrintHeader(true);
            }else
                $pdf_renderer->SetPrintHeader(false);
            
            
            $temp =  _PS_MODULE_DIR_.'gwadvancedinvoice/views/templates/admin/tpltemplates/previews/'.$layout.'/template.tpl';

            $content = Context::getContext()->smarty->fetch($temp);
            
            $content = preg_replace_callback("/(<img[^>]*src *= *[\"']?)([^\"']*)/i",
                function ($matches) {
                    $base_url = Tools::getHttpHost().__PS_BASE_URI__;
                        $link = str_replace(
                                array('http:/'.'/'.$base_url,'https:/'.'/'.$base_url),
                                array(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR,_PS_ROOT_DIR_.DIRECTORY_SEPARATOR),
                                $matches['2']);
                  return $matches[1] . $link;
                }
            , $content);
            $pdf_renderer->createContent('<style>'.strip_tags($style).'</style>'.$content);
            if(Tools::getValue('activefooter')){
                
                $temp =  _PS_MODULE_DIR_.'gwadvancedinvoice/views/templates/admin/tpltemplates/previews/'.$layout.'/footer.tpl';
                $pdf_renderer->createFooter('<style>'.strip_tags($style).'</style>'.Context::getContext()->smarty->fetch($temp));
                $pdf_renderer->SetPrintFooter(true);
            }else
                $pdf_renderer->SetPrintFooter(false);
                
            $pdf_renderer->writePageGw(Tools::getValue('mgheader'),Tools::getValue('mgfooter'),Tools::getValue('mgcontent'));
            $watermank_img = '';
            $type = Tools::strtolower(Tools::substr(strrchr($_FILES['watermark_'.$id_language]['name'], '.'), 1));
            $imagesize = @getimagesize($_FILES['watermark_'.$id_language]['tmp_name']);
            if (isset($_FILES['watermark_'.$id_language]) &&
                isset($_FILES['watermark_'.$id_language]['tmp_name']) &&
                !empty($_FILES['watermark_'.$id_language]['tmp_name']) &&
                !empty($imagesize) &&
                in_array(
                    Tools::strtolower(Tools::substr(strrchr($imagesize['mime'], '/'), 1)), array(
                        'jpg',
                        'gif',
                        'jpeg',
                        'png'
                    )
                ) &&
                in_array($type, array('jpg', 'gif', 'jpeg', 'png'))
            )
            {
                $error = false;
                $temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
                $salt = sha1(microtime());
                if (ImageManager::validateUpload($_FILES['watermark_'.$id_language]))
                    $error =  true;
                elseif (!$temp_name || !move_uploaded_file($_FILES['watermark_'.$id_language]['tmp_name'], $temp_name))
                    $error =  true;
                elseif (!ImageManager::resize($temp_name, _PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/tpltemplates/previews/'.$layout.'/'.$salt.'_'.$_FILES['watermark_'.$id_language]['name'], null, null, $type))
                    $error =  true;
                if(!$error) $watermank_img=$base_url.'modules/'.$this->module->name.'/views/templates/admin/tpltemplates/previews/'.$layout.'/'.$salt.'_'.$_FILES['watermark_'.$id_language]['name'];
            }else{
                 if(Tools::getValue('id_gwadvancedinvoicetemplate')){
                    $template = new gwadvancedinvoicetemplateModel((int)Tools::getValue('id_gwadvancedinvoicetemplate'));
                    if($template->watermark){
                        if(!is_dir(_PS_MODULE_DIR_.$this->module->name.'/views/img/watermark/'.$template->watermark[$id_language]))
                            if(file_exists(_PS_MODULE_DIR_.$this->module->name.'/views/img/watermark/'.$template->watermark[$id_language]))
                                $watermank_img = $base_url.'modules/gwadvancedinvoice/views/img/watermark/'.$template->watermark[$id_language];
                    }
                }
            }
            $watermank_text = Tools::getValue('watermarktext_'.$id_language);
            $watermank_font = Tools::getValue('watermarkfont_'.$id_language);
            $watermank_size = Tools::getValue('watermarksize_'.$id_language);
            if($watermank_img !='' || $watermank_text !=''){
                $pdf_renderer->addWaterMark($watermank_text,$watermank_img,45,0,'0.1',$watermank_font,$watermank_size);
            }   
            if (ob_get_level() && ob_get_length() > 0)
                ob_clean();
            $dir = _PS_MODULE_DIR_.'gwadvancedinvoice/views/templates/admin/tpltemplates/previews/'.$layout;
            gwadvancedinvoicetemplateModel::delTree($dir);
            $pdf_renderer->renderInvoice('preview.pdf', 'I');
            die();
       }elseif (Tools::isSubmit('chooseTemplate')){
            if(Tools::getValue('choose_design') != null && Tools::getValue('choose_design') !=''){
                $link = new Link();
                $_link = $link->getAdminLink('AdminGwadvancedinvoicetemplate').'&addgwadvancedinvoicetemplate&choose_design='.Tools::getValue('choose_design').'&pagesize='.Tools::getValue('pagesize');
                Tools::redirectLink($_link);
            }
        }
elseif (Tools::isSubmit('saveTemplate') || Tools::isSubmit('submitAddgwadvancedinvoicetemplateAndStay')) {
    $layout = time();
    $template = null;
    if (Tools::getValue('id_gwadvancedinvoicetemplate')) {
        $template = new gwadvancedinvoicetemplateModel((int)Tools::getValue('id_gwadvancedinvoicetemplate'));
        if ($template->layout != '' && $template->layout) {
            $layout = $template->layout;
        }
    }
    $_POST['layout'] = $layout;
    $_POST['template_config'] = (Tools::getValue('template_config') != '') ? json_encode(Tools::getValue('template_config')) : '';
    $languages = Language::getLanguages(false);
    if (!Tools::getValue('checkBoxShopAsso_gwadvancedinvoicetemplate')) {
        $_POST['checkBoxShopAsso_gwadvancedinvoicetemplate'] = array(Context::getContext()->shop->id);
    }
    $temp = Tools::getValue('choose_design');
    foreach (Tools::getValue('checkBoxShopAsso_gwadvancedinvoicetemplate') as $shop) {
        if (!file_exists(_PS_MODULE_DIR_ . $this->module->name . '/views/templates/admin/tpltemplates/customize/' . $shop . '/' . $layout . '/index.php')) {
            @copy(_PS_MODULE_DIR_ . 'gwadvancedinvoice/index.php', _PS_MODULE_DIR_ . $this->module->name . '/views/templates/admin/tpltemplates/customize/' . $shop . '/' . $layout . '/index.php');
        }
        foreach ($languages as $lang) {
            $titles = Tools::getValue('colums_title_' . $lang['id_lang']);
            if ($titles) {
                foreach ($titles as &$title) {
                    $title = htmlentities($title);
                }
            }
            $_POST['productcolumns_' . $lang['id_lang']] = json_encode(array(
                'widthtitle' => Tools::getValue('widthtitle'),
                'title' => $titles,
                'content' => Tools::getValue('colums_content_' . $lang['id_lang']),
                'align' => Tools::getValue('colums_align_' . $lang['id_lang']),
            ));
        }
                      $styles = '';
                        if(Tools::file_exists_no_cache(_PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/tpltemplates/base/'.$temp.'/'.$lang['iso_code'].'/styles.tpl')){
                            $styles = Tools::file_get_contents(_PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/tpltemplates/base/'.$temp.'/'.$lang['iso_code'].'/styles.tpl');
                        }elseif(Tools::file_exists_no_cache(_PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/tpltemplates/base/'.$temp.'/en/styles.tpl')){
                            $styles = Tools::file_get_contents(_PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/tpltemplates/base/'.$temp.'/en/styles.tpl');
                        }
                      $discounttype = Tools::getValue('discountval');
                      if($discounttype != 'exclude') $discounttype = 'include';
                      gwadvancedinvoicetemplateModel::writeTemplate('styles.tpl','../modules/'.$this->module->name.'/views/templates/admin/tpltemplates/customize/'.$shop.'/'.$layout.'/'.$lang['iso_code'],$styles);
                      gwadvancedinvoicetemplateModel::writeTemplate('product_list.tpl','../modules/'.$this->module->name.'/views/templates/admin/tpltemplates/customize/'.$shop.'/'.$layout.'/'.$lang['iso_code'],gwadvancedinvoicetemplateModel::getProductListTpl(Tools::getValue('widthtitle'),Tools::getValue('colums_title_'.$lang['id_lang']),Tools::getValue('colums_content_'.$lang['id_lang']),Tools::getValue('colums_align_'.$lang['id_lang']),$temp,$lang['iso_code'],$discounttype));
                      gwadvancedinvoicetemplateModel::writeTemplate('template.tpl','../modules/'.$this->module->name.'/views/templates/admin/tpltemplates/customize/'.$shop.'/'.$layout.'/'.$lang['iso_code'],str_replace('{displayPrice:$','{displayPrice currency=$order->id_currency price=$',Tools::getValue('invoice_'.$lang['id_lang'])));

                        $header_content = '';
                        if(Tools::getValue('header_'.$lang['id_lang'])) $header_content = Tools::getValue('header_'.$lang['id_lang']);
                        if(Tools::getValue('activeheader')){
                            gwadvancedinvoicetemplateModel::writeTemplate('header.tpl','../modules/'.$this->module->name.'/views/templates/admin/tpltemplates/customize/'.$shop.'/'.$layout.'/'.$lang['iso_code'],$header_content);
                        }
                        $footer_content = '';
                        if(Tools::getValue('footer_'.$lang['id_lang'])) $footer_content = Tools::getValue('footer_'.$lang['id_lang']);
                        if(Tools::getValue('activefooter')){
                            gwadvancedinvoicetemplateModel::writeTemplate('footer.tpl','../modules/'.$this->module->name.'/views/templates/admin/tpltemplates/customize/'.$shop.'/'.$layout.'/'.$lang['iso_code'],$footer_content);
                        }
                }
                
            }
            foreach ($languages as $language)
            {
                if(Tools::getValue('watermark_remove_'.$language['id_lang'])){
                    if($template && isset($template->watermark[$language['id_lang']])){
                        unlink(_PS_MODULE_DIR_.$this->module->name.'/views/img/watermark/'.$template->watermark[$language['id_lang']]);
                        $_POST['watermark_'.$language['id_lang']] = '';
                      }
                }
                $type = Tools::strtolower(Tools::substr(strrchr($_FILES['watermark_'.$language['id_lang']]['name'], '.'), 1));
                $imagesize = @getimagesize($_FILES['watermark_'.$language['id_lang']]['tmp_name']);
                if (isset($_FILES['watermark_'.$language['id_lang']]) &&
                    isset($_FILES['watermark_'.$language['id_lang']]['tmp_name']) &&
                    !empty($_FILES['watermark_'.$language['id_lang']]['tmp_name']) &&
                    !empty($imagesize) &&
                    in_array(
                        Tools::strtolower(Tools::substr(strrchr($imagesize['mime'], '/'), 1)), array(
                            'jpg',
                            'gif',
                            'jpeg',
                            'png'
                        )
                    ) &&
                    in_array($type, array('jpg', 'gif', 'jpeg', 'png'))
                )
                {
                    $temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
                    $salt = sha1(microtime());
                    if ($error = ImageManager::validateUpload($_FILES['watermark_'.$language['id_lang']]))
                        $this->errors[] = $error;
                    elseif (!$temp_name || !move_uploaded_file($_FILES['watermark_'.$language['id_lang']]['tmp_name'], $temp_name))
                        return false;
                    elseif (!ImageManager::resize($temp_name, _PS_MODULE_DIR_.$this->module->name.'/views/img/watermark/'.$salt.'_'.$_FILES['watermark_'.$language['id_lang']]['name'], null, null, $type))
                        $this->errors[] = $this->displayError($this->l('An error occurred during the image upload process.'));
                    if (isset($temp_name))
                        @unlink($temp_name);
                    if($template && isset($template->watermark[$language['id_lang']])){
                        unlink(_PS_MODULE_DIR_.$this->module->name.'/views/img/watermark/'.$template->watermark[$language['id_lang']]);
                    }
                    $_POST['watermark_'.$language['id_lang']] = $salt.'_'.$_FILES['watermark_'.$language['id_lang']]['name'];
                }
            }       
            parent::postProcess(true);
        }elseif (Tools::isSubmit('deletegwadvancedinvoicetemplate')){
            $id_shop_group = Shop::getContextShopGroupID();
            $id_shop = Shop::getContextShopID();
            $chossed_temp = Configuration::get('GWADVANCEDINVOICE_TEMPLATE', null, $id_shop_group, $id_shop);
            if($chossed_temp == Tools::getValue('id_gwadvancedinvoicetemplate')){
                Configuration::updateValue('GWADVANCEDINVOICE_TEMPLATE', '', false, $id_shop_group, $id_shop);
            }
            
            $layout = '';
            if(Tools::getValue('id_gwadvancedinvoicetemplate')){
                $template = new gwadvancedinvoicetemplateModel((int)Tools::getValue('id_gwadvancedinvoicetemplate'));
                if($template->layout != ''){
                    $layout = $template->layout;                     
                }
            }
            if($layout !=''){
                $shops = Shop::getContextListShopID();
                foreach ($shops as $shop_id)
                {
                    $dir = _PS_MODULE_DIR_.'gwadvancedinvoice/views/templates/admin/tpltemplates/customize/'.$shop_id.'/'.$layout;
                    if(Tools::file_exists_no_cache($dir)){
                        gwadvancedinvoicetemplateModel::delTree($dir);
                    }
                    
                }
                $dir = _PS_MODULE_DIR_.'gwadvancedinvoice/views/img/imgtemplates/'.$layout;
                if(Tools::file_exists_no_cache($dir)){
                    gwadvancedinvoicetemplateModel::delTree($dir);
                }
                
            }
            parent::postProcess(true);
        }elseif (Tools::isSubmit('duplicategwadvancedinvoicetemplate')){
            $id = (int)Tools::getValue('id_gwadvancedinvoicetemplate');
            $layout = time();
            $template = new gwadvancedinvoicetemplateModel((int)$id);
            if(Validate::isLoadedObject($template)){
                $template_new = clone $template;
                $template_new->id_gwadvancedinvoicetemplate = null;
                $template_new->id = null;
                $template_new->layout = $layout;
                foreach($template_new->title as &$title){
                    $title .='-'.$this->l('Copy');
                }
                $shops = Shop::getContextListShopID();
                foreach ($shops as $shop_id){
                    $dir = _PS_MODULE_DIR_.'gwadvancedinvoice/views/templates/admin/tpltemplates/customize/'.$shop_id;
                    gwadvancedinvoicetemplateModel::copyTree($dir.'/'.$template->layout,$dir.'/'.$template_new->layout);
                }
                $template_new->save();
            }
            parent::postProcess(true);
        }
        else
            parent::postProcess(true);
    }

正是这个专门标记了错误

}elseif (Tools::isSubmit('deletegwadvancedinvoicetemplate')){

图像 Symfony 错误

Uncaught PHP Exception ParseError

syntax error, unexpected 'elseif' (T_ELSEIF), expecting function (T_FUNCTION) or const (T_CONST)

php symfony prestashop
1个回答
0
投票

你上面有一个额外的支架

foreach ($languages as $language) {

这是正确的代码:

    public function postProcess()
    {
        if (Tools::isSubmit('submitAjaxCall')) {
            $getstyle = (bool)Tools::getValue('getstyle');
            if ($getstyle) {
                $gwadvancedinvoice = Module::getInstanceByName('gwadvancedinvoice');
                $choose_design = Tools::getValue('choose_design');
                $template_config = Tools::getValue('template_config');
                $id_language = (int)Tools::getValue('id_language');
                if ($choose_design != '' && is_array($template_config) && !empty($template_config))
                    echo $gwadvancedinvoice->hookAjaxCallStyle(array('choose_design' => $choose_design, 'template_config' => $template_config, 'id_language' => $id_language));
            } else {
                $gwadvancedinvoice = Module::getInstanceByName('gwadvancedinvoice');
                $pagesize = Tools::getValue('pagesize');
                if ($pagesize != '')
                    echo $gwadvancedinvoice->hookAjaxCall(array('template' => '', 'pagesize' => $pagesize));
            }
            die();
        } elseif (Tools::isSubmit('previewTemplate')) {
            $pdf_renderer = new PDFGenerator((bool)Configuration::get('PS_PDF_USE_CACHE'), Tools::getValue('pageorientation'));
            $useSSL = ((isset($this->ssl) && $this->ssl && Configuration::get('PS_SSL_ENABLED')) || Tools::usingSecureMode()) ? true : false;
            $protocol_content = ($useSSL) ? 'https://' : 'http://';
            $base_url = $protocol_content . Tools::getHttpHost() . __PS_BASE_URI__;

            $layout = time() . rand(1, 999999999);
            if (version_compare(_PS_VERSION_, '1.6.0') == 1) {
                $datas = $_POST + $_GET;
                // version left than 1.6.4->1.6.9 missing function Tools::getAllValues();
            } else {
                $datas = Tools::getAllValues();
            }
            $id_language = Context::getContext()->language->id;
            if (Tools::getValue('previewTemplate'))
                $id_language = Tools::getValue('previewTemplate');

            $styles = '';
            $temp = $datas['choose_design'];
            $language = new Language($id_language);
            if (Tools::file_exists_no_cache(_PS_MODULE_DIR_ . $this->module->name . '/views/templates/admin/tpltemplates/base/' . $temp . '/' . $language->iso_code . '/styles.tpl')) {
                $styles = Tools::file_get_contents(_PS_MODULE_DIR_ . $this->module->name . '/views/templates/admin/tpltemplates/base/' . $temp . '/' . $language->iso_code . '/styles.tpl');
            } elseif (Tools::file_exists_no_cache(_PS_MODULE_DIR_ . $this->module->name . '/views/templates/admin/tpltemplates/base/' . $temp . '/en/styles.tpl')) {
                $styles = Tools::file_get_contents(_PS_MODULE_DIR_ . $this->module->name . '/views/templates/admin/tpltemplates/base/' . $temp . '/en/styles.tpl');
            }
            $discounttype = Tools::getValue('discountval');
            if ($discounttype != 'exclude') $discounttype = 'include';
            gwadvancedinvoicetemplateModel::writeTemplate('styles.tpl', '../modules/' . $this->module->name . '/views/templates/admin/tpltemplates/previews/' . $layout, $styles);
            gwadvancedinvoicetemplateModel::writeTemplate('product_list.tpl', '../modules/' . $this->module->name . '/views/templates/admin/tpltemplates/previews/' . $layout, gwadvancedinvoicetemplateModel::getProductListTpl($datas['widthtitle'], $datas['colums_title_' . $id_language], $datas['colums_content_' . $id_language], $datas['colums_align_' . $id_language], $temp, $language->iso_code, $discounttype));
            gwadvancedinvoicetemplateModel::writeTemplate('template.tpl', '../modules/' . $this->module->name . '/views/templates/admin/tpltemplates/previews/' . $layout, str_replace('{displayPrice:$', '{displayPrice currency=$order->id_currency price=$', $datas['invoice_' . $id_language]));

            $header_content = '';
            if (Tools::getValue('header_' . $id_language)) $header_content = Tools::getValue('header_' . $id_language);
            if (Tools::getValue('activeheader')) {
                gwadvancedinvoicetemplateModel::writeTemplate('header.tpl', '../modules/' . $this->module->name . '/views/templates/admin/tpltemplates/previews/' . $layout, $header_content);
            }
            $footer_content = '';
            if (Tools::getValue('footer_' . $id_language)) $footer_content = Tools::getValue('footer_' . $id_language);
            if (Tools::getValue('activefooter')) {
                gwadvancedinvoicetemplateModel::writeTemplate('footer.tpl', '../modules/' . $this->module->name . '/views/templates/admin/tpltemplates/previews/' . $layout, $footer_content);
            }

            $data = gwadvancedinvoicetemplateModel::getDataDemo();

            $template_config = Tools::getValue('template_config');
            foreach ($template_config as $key => $template_config) {
                $data[$key] = $template_config;
            }
            $code = $datas['barcodeproductformat'];
            foreach ($data['order_details'] as &$order_details) {
                $text = '';
                if ($code == 'product_link') {
                    $text = urlencode($base_url);
                } else {
                    $text = urlencode($order_details[$code]);
                }
                $filename = md5($datas['barcodeproducttype'] . '_' . $text) . '.png';
                if (!Tools::file_exists_no_cache(_PS_MODULE_DIR_ . 'gwadvancedinvoice/views/img/barcodes/' . $filename)) {
                    if ($datas['barcodeproducttype'] == 'qrcode') {
                        $qrcodeObj = new QRCodeLib($text);
                        $im = $qrcodeObj->createImage(4, 2);
                        imagepng($im, _PS_MODULE_DIR_ . 'gwadvancedinvoice/views/img/barcodes/' . $filename);
                    } else {
                        $bacodeObj = new Barcode($text, $datas['barcodeproducttype']);
                        $bacodeObj->getBarcodePNG(_PS_MODULE_DIR_ . 'gwadvancedinvoice/views/img/barcodes/' . $filename, 2, 35, array(0, 0, 0));
                    }
                }
                if (Tools::file_exists_no_cache(_PS_MODULE_DIR_ . 'gwadvancedinvoice/views/img/barcodes/' . $filename)) {
                    $order_details['barcode'] = '<img src="' . $base_url . 'modules/gwadvancedinvoice/views/img/barcodes/' . $filename . '"/>';
                } else {
                    $order_details['barcode'] = '';
                }
            }
            Context::getContext()->smarty->assign($data);
            $products_list_temp = _PS_MODULE_DIR_ . 'gwadvancedinvoice/views/templates/admin/tpltemplates/previews/' . $layout . '/product_list.tpl';
            $products_list = Context::getContext()->smarty->fetch($products_list_temp);
            $data['products_list'] = $products_list;
            $code = '1234567890';
            $filename = md5($datas['barcodetype'] . '_' . $code) . '.png';
            if (!Tools::file_exists_no_cache(_PS_MODULE_DIR_ . 'gwadvancedinvoice/views/img/barcodes/' . $filename)) {
                if ($datas['barcodetype'] == 'qrcode') {
                    $qrcodeObj = new QRCodeLib($code);
                    $im = $qrcodeObj->createImage(4, 2);
                    imagepng($im, _PS_MODULE_DIR_ . 'gwadvancedinvoice/views/img/barcodes/' . $filename);
                } else {
                    $bacodeObj = new Barcode($code, $datas['barcodetype']);
                    $bacodeObj->getBarcodePNG(_PS_MODULE_DIR_ . 'gwadvancedinvoice/views/img/barcodes/' . $filename, 2, 35, array(0, 0, 0));
                }
            }

            if (Tools::file_exists_no_cache(_PS_MODULE_DIR_ . 'gwadvancedinvoice/views/img/barcodes/' . $filename)) {
                $data['barcode_invoice'] = '<img src="' . $base_url . 'modules/gwadvancedinvoice/views/img/barcodes/' . $filename . '"/>';
            } else {
                $data['barcode_invoice'] = '';
            }
            $data['custom_style'] = $datas['customcss'];
            Context::getContext()->smarty->assign($data);
            $pdf_renderer->setCurOrientation($datas['pagesize'], $datas['pageorientation']);
            if (Tools::getValue('rtl')) {
                $pdf_renderer->setRTL((bool)Tools::getValue('rtl'));
            }

            $style = Context::getContext()->smarty->fetch(_PS_MODULE_DIR_ . 'gwadvancedinvoice/views/templates/admin/tpltemplates/previews/' . $layout . '/styles.tpl');
            if (Tools::getValue('activeheader')) {
                $temp = _PS_MODULE_DIR_ . 'gwadvancedinvoice/views/templates/admin/tpltemplates/previews/' . $layout . '/header.tpl';
                $pdf_renderer->createHeader('<style>' . strip_tags($style) . '</style>' . Context::getContext()->smarty->fetch($temp));
                $pdf_renderer->SetPrintHeader(true);
            } else
                $pdf_renderer->SetPrintHeader(false);


            $temp = _PS_MODULE_DIR_ . 'gwadvancedinvoice/views/templates/admin/tpltemplates/previews/' . $layout . '/template.tpl';

            $content = Context::getContext()->smarty->fetch($temp);

            $content = preg_replace_callback("/(<img[^>]*src *= *[\"']?)([^\"']*)/i",
                function ($matches) {
                    $base_url = Tools::getHttpHost() . __PS_BASE_URI__;
                    $link = str_replace(
                        array('http:/' . '/' . $base_url, 'https:/' . '/' . $base_url),
                        array(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR, _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR),
                        $matches['2']);
                    return $matches[1] . $link;
                }
                , $content);
            $pdf_renderer->createContent('<style>' . strip_tags($style) . '</style>' . $content);
            if (Tools::getValue('activefooter')) {

                $temp = _PS_MODULE_DIR_ . 'gwadvancedinvoice/views/templates/admin/tpltemplates/previews/' . $layout . '/footer.tpl';
                $pdf_renderer->createFooter('<style>' . strip_tags($style) . '</style>' . Context::getContext()->smarty->fetch($temp));
                $pdf_renderer->SetPrintFooter(true);
            } else
                $pdf_renderer->SetPrintFooter(false);

            $pdf_renderer->writePageGw(Tools::getValue('mgheader'), Tools::getValue('mgfooter'), Tools::getValue('mgcontent'));
            $watermank_img = '';
            $type = Tools::strtolower(Tools::substr(strrchr($_FILES['watermark_' . $id_language]['name'], '.'), 1));
            $imagesize = @getimagesize($_FILES['watermark_' . $id_language]['tmp_name']);
            if (isset($_FILES['watermark_' . $id_language]) &&
                isset($_FILES['watermark_' . $id_language]['tmp_name']) &&
                !empty($_FILES['watermark_' . $id_language]['tmp_name']) &&
                !empty($imagesize) &&
                in_array(
                    Tools::strtolower(Tools::substr(strrchr($imagesize['mime'], '/'), 1)), array(
                        'jpg',
                        'gif',
                        'jpeg',
                        'png'
                    )
                ) &&
                in_array($type, array('jpg', 'gif', 'jpeg', 'png'))
            ) {
                $error = false;
                $temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
                $salt = sha1(microtime());
                if (ImageManager::validateUpload($_FILES['watermark_' . $id_language]))
                    $error = true;
                elseif (!$temp_name || !move_uploaded_file($_FILES['watermark_' . $id_language]['tmp_name'], $temp_name))
                    $error = true;
                elseif (!ImageManager::resize($temp_name, _PS_MODULE_DIR_ . $this->module->name . '/views/templates/admin/tpltemplates/previews/' . $layout . '/' . $salt . '_' . $_FILES['watermark_' . $id_language]['name'], null, null, $type))
                    $error = true;
                if (!$error) $watermank_img = $base_url . 'modules/' . $this->module->name . '/views/templates/admin/tpltemplates/previews/' . $layout . '/' . $salt . '_' . $_FILES['watermark_' . $id_language]['name'];
            } else {
                if (Tools::getValue('id_gwadvancedinvoicetemplate')) {
                    $template = new gwadvancedinvoicetemplateModel((int)Tools::getValue('id_gwadvancedinvoicetemplate'));
                    if ($template->watermark) {
                        if (!is_dir(_PS_MODULE_DIR_ . $this->module->name . '/views/img/watermark/' . $template->watermark[$id_language]))
                            if (file_exists(_PS_MODULE_DIR_ . $this->module->name . '/views/img/watermark/' . $template->watermark[$id_language]))
                                $watermank_img = $base_url . 'modules/gwadvancedinvoice/views/img/watermark/' . $template->watermark[$id_language];
                    }
                }
            }
            $watermank_text = Tools::getValue('watermarktext_' . $id_language);
            $watermank_font = Tools::getValue('watermarkfont_' . $id_language);
            $watermank_size = Tools::getValue('watermarksize_' . $id_language);
            if ($watermank_img != '' || $watermank_text != '') {
                $pdf_renderer->addWaterMark($watermank_text, $watermank_img, 45, 0, '0.1', $watermank_font, $watermank_size);
            }
            if (ob_get_level() && ob_get_length() > 0)
                ob_clean();
            $dir = _PS_MODULE_DIR_ . 'gwadvancedinvoice/views/templates/admin/tpltemplates/previews/' . $layout;
            gwadvancedinvoicetemplateModel::delTree($dir);
            $pdf_renderer->renderInvoice('preview.pdf', 'I');
            die();
        } elseif (Tools::isSubmit('chooseTemplate')) {
            if (Tools::getValue('choose_design') != null && Tools::getValue('choose_design') != '') {
                $link = new Link();
                $_link = $link->getAdminLink('AdminGwadvancedinvoicetemplate') . '&addgwadvancedinvoicetemplate&choose_design=' . Tools::getValue('choose_design') . '&pagesize=' . Tools::getValue('pagesize');
                Tools::redirectLink($_link);
            }
        } elseif (Tools::isSubmit('saveTemplate') || Tools::isSubmit('submitAddgwadvancedinvoicetemplateAndStay')) {
            $layout = time();
            $template = null;
            if (Tools::getValue('id_gwadvancedinvoicetemplate')) {
                $template = new gwadvancedinvoicetemplateModel((int)Tools::getValue('id_gwadvancedinvoicetemplate'));
                if ($template->layout != '' && $template->layout) {
                    $layout = $template->layout;
                }
            }
            $_POST['layout'] = $layout;
            $_POST['template_config'] = (Tools::getValue('template_config') != '') ? json_encode(Tools::getValue('template_config')) : '';
            $languages = Language::getLanguages(false);
            if (!Tools::getValue('checkBoxShopAsso_gwadvancedinvoicetemplate')) {
                $_POST['checkBoxShopAsso_gwadvancedinvoicetemplate'] = array(Context::getContext()->shop->id);
            }
            $temp = Tools::getValue('choose_design');
            foreach (Tools::getValue('checkBoxShopAsso_gwadvancedinvoicetemplate') as $shop) {
                if (!file_exists(_PS_MODULE_DIR_ . $this->module->name . '/views/templates/admin/tpltemplates/customize/' . $shop . '/' . $layout . '/index.php')) {
                    @copy(_PS_MODULE_DIR_ . 'gwadvancedinvoice/index.php', _PS_MODULE_DIR_ . $this->module->name . '/views/templates/admin/tpltemplates/customize/' . $shop . '/' . $layout . '/index.php');
                }
                foreach ($languages as $lang) {
                    $titles = Tools::getValue('colums_title_' . $lang['id_lang']);
                    if ($titles) {
                        foreach ($titles as &$title) {
                            $title = htmlentities($title);
                        }
                    }
                    $_POST['productcolumns_' . $lang['id_lang']] = json_encode(array(
                        'widthtitle' => Tools::getValue('widthtitle'),
                        'title' => $titles,
                        'content' => Tools::getValue('colums_content_' . $lang['id_lang']),
                        'align' => Tools::getValue('colums_align_' . $lang['id_lang']),
                    ));
                }
                $styles = '';
                if (Tools::file_exists_no_cache(_PS_MODULE_DIR_ . $this->module->name . '/views/templates/admin/tpltemplates/base/' . $temp . '/' . $lang['iso_code'] . '/styles.tpl')) {
                    $styles = Tools::file_get_contents(_PS_MODULE_DIR_ . $this->module->name . '/views/templates/admin/tpltemplates/base/' . $temp . '/' . $lang['iso_code'] . '/styles.tpl');
                } elseif (Tools::file_exists_no_cache(_PS_MODULE_DIR_ . $this->module->name . '/views/templates/admin/tpltemplates/base/' . $temp . '/en/styles.tpl')) {
                    $styles = Tools::file_get_contents(_PS_MODULE_DIR_ . $this->module->name . '/views/templates/admin/tpltemplates/base/' . $temp . '/en/styles.tpl');
                }
                $discounttype = Tools::getValue('discountval');
                if ($discounttype != 'exclude') $discounttype = 'include';
                gwadvancedinvoicetemplateModel::writeTemplate('styles.tpl', '../modules/' . $this->module->name . '/views/templates/admin/tpltemplates/customize/' . $shop . '/' . $layout . '/' . $lang['iso_code'], $styles);
                gwadvancedinvoicetemplateModel::writeTemplate('product_list.tpl', '../modules/' . $this->module->name . '/views/templates/admin/tpltemplates/customize/' . $shop . '/' . $layout . '/' . $lang['iso_code'], gwadvancedinvoicetemplateModel::getProductListTpl(Tools::getValue('widthtitle'), Tools::getValue('colums_title_' . $lang['id_lang']), Tools::getValue('colums_content_' . $lang['id_lang']), Tools::getValue('colums_align_' . $lang['id_lang']), $temp, $lang['iso_code'], $discounttype));
                gwadvancedinvoicetemplateModel::writeTemplate('template.tpl', '../modules/' . $this->module->name . '/views/templates/admin/tpltemplates/customize/' . $shop . '/' . $layout . '/' . $lang['iso_code'], str_replace('{displayPrice:$', '{displayPrice currency=$order->id_currency price=$', Tools::getValue('invoice_' . $lang['id_lang'])));

                $header_content = '';
                if (Tools::getValue('header_' . $lang['id_lang'])) $header_content = Tools::getValue('header_' . $lang['id_lang']);
                if (Tools::getValue('activeheader')) {
                    gwadvancedinvoicetemplateModel::writeTemplate('header.tpl', '../modules/' . $this->module->name . '/views/templates/admin/tpltemplates/customize/' . $shop . '/' . $layout . '/' . $lang['iso_code'], $header_content);
                }
                $footer_content = '';
                if (Tools::getValue('footer_' . $lang['id_lang'])) $footer_content = Tools::getValue('footer_' . $lang['id_lang']);
                if (Tools::getValue('activefooter')) {
                    gwadvancedinvoicetemplateModel::writeTemplate('footer.tpl', '../modules/' . $this->module->name . '/views/templates/admin/tpltemplates/customize/' . $shop . '/' . $layout . '/' . $lang['iso_code'], $footer_content);
                }
            }

            foreach ($languages as $language) {
                if (Tools::getValue('watermark_remove_' . $language['id_lang'])) {
                    if ($template && isset($template->watermark[$language['id_lang']])) {
                        unlink(_PS_MODULE_DIR_ . $this->module->name . '/views/img/watermark/' . $template->watermark[$language['id_lang']]);
                        $_POST['watermark_' . $language['id_lang']] = '';
                    }
                }
                $type = Tools::strtolower(Tools::substr(strrchr($_FILES['watermark_' . $language['id_lang']]['name'], '.'), 1));
                $imagesize = @getimagesize($_FILES['watermark_' . $language['id_lang']]['tmp_name']);
                if (isset($_FILES['watermark_' . $language['id_lang']]) &&
                    isset($_FILES['watermark_' . $language['id_lang']]['tmp_name']) &&
                    !empty($_FILES['watermark_' . $language['id_lang']]['tmp_name']) &&
                    !empty($imagesize) &&
                    in_array(
                        Tools::strtolower(Tools::substr(strrchr($imagesize['mime'], '/'), 1)), array(
                            'jpg',
                            'gif',
                            'jpeg',
                            'png'
                        )
                    ) &&
                    in_array($type, array('jpg', 'gif', 'jpeg', 'png'))
                ) {
                    $temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
                    $salt = sha1(microtime());
                    if ($error = ImageManager::validateUpload($_FILES['watermark_' . $language['id_lang']]))
                        $this->errors[] = $error;
                    elseif (!$temp_name || !move_uploaded_file($_FILES['watermark_' . $language['id_lang']]['tmp_name'], $temp_name))
                        return false;
                    elseif (!ImageManager::resize($temp_name, _PS_MODULE_DIR_ . $this->module->name . '/views/img/watermark/' . $salt . '_' . $_FILES['watermark_' . $language['id_lang']]['name'], null, null, $type))
                        $this->errors[] = $this->displayError($this->l('An error occurred during the image upload process.'));
                    if (isset($temp_name))
                        @unlink($temp_name);
                    if ($template && isset($template->watermark[$language['id_lang']])) {
                        unlink(_PS_MODULE_DIR_ . $this->module->name . '/views/img/watermark/' . $template->watermark[$language['id_lang']]);
                    }
                    $_POST['watermark_' . $language['id_lang']] = $salt . '_' . $_FILES['watermark_' . $language['id_lang']]['name'];
                }
            }
            parent::postProcess(true);
        } elseif (Tools::isSubmit('deletegwadvancedinvoicetemplate')) {
            $id_shop_group = Shop::getContextShopGroupID();
            $id_shop = Shop::getContextShopID();
            $chossed_temp = Configuration::get('GWADVANCEDINVOICE_TEMPLATE', null, $id_shop_group, $id_shop);
            if ($chossed_temp == Tools::getValue('id_gwadvancedinvoicetemplate')) {
                Configuration::updateValue('GWADVANCEDINVOICE_TEMPLATE', '', false, $id_shop_group, $id_shop);
            }

            $layout = '';
            if (Tools::getValue('id_gwadvancedinvoicetemplate')) {
                $template = new gwadvancedinvoicetemplateModel((int)Tools::getValue('id_gwadvancedinvoicetemplate'));
                if ($template->layout != '') {
                    $layout = $template->layout;
                }
            }
            if ($layout != '') {
                $shops = Shop::getContextListShopID();
                foreach ($shops as $shop_id) {
                    $dir = _PS_MODULE_DIR_ . 'gwadvancedinvoice/views/templates/admin/tpltemplates/customize/' . $shop_id . '/' . $layout;
                    if (Tools::file_exists_no_cache($dir)) {
                        gwadvancedinvoicetemplateModel::delTree($dir);
                    }

                }
                $dir = _PS_MODULE_DIR_ . 'gwadvancedinvoice/views/img/imgtemplates/' . $layout;
                if (Tools::file_exists_no_cache($dir)) {
                    gwadvancedinvoicetemplateModel::delTree($dir);
                }

            }
            parent::postProcess(true);
        } elseif (Tools::isSubmit('duplicategwadvancedinvoicetemplate')) {
            $id = (int)Tools::getValue('id_gwadvancedinvoicetemplate');
            $layout = time();
            $template = new gwadvancedinvoicetemplateModel((int)$id);
            if (Validate::isLoadedObject($template)) {
                $template_new = clone $template;
                $template_new->id_gwadvancedinvoicetemplate = null;
                $template_new->id = null;
                $template_new->layout = $layout;
                foreach ($template_new->title as &$title) {
                    $title .= '-' . $this->l('Copy');
                }
                $shops = Shop::getContextListShopID();
                foreach ($shops as $shop_id) {
                    $dir = _PS_MODULE_DIR_ . 'gwadvancedinvoice/views/templates/admin/tpltemplates/customize/' . $shop_id;
                    gwadvancedinvoicetemplateModel::copyTree($dir . '/' . $template->layout, $dir . '/' . $template_new->layout);
                }
                $template_new->save();
            }
            parent::postProcess(true);
        } else
            parent::postProcess(true);
    }
© www.soinside.com 2019 - 2024. All rights reserved.