public static function l($string, $specific = false, $name = '')
 {
     if (empty($name)) {
         $name = self::MODULE_NAME;
     }
     return Translate::getModuleTranslation($name, $string, $specific ? $specific : $name);
 }
Esempio n. 2
0
 /**
  * Get a translation for an admin controller
  *
  * @param $string
  * @param string $class
  * @param bool $addslashes
  * @param bool $htmlentities
  * @return string
  */
 public static function getAdminTranslation($string, $class = 'AdminTab', $addslashes = false, $htmlentities = true, $sprintf = null)
 {
     static $modules_tabs = null;
     // @todo remove global keyword in translations files and use static
     global $_LANGADM;
     if ($modules_tabs === null) {
         $modules_tabs = Tab::getModuleTabList();
     }
     if ($_LANGADM == null) {
         $iso = Context::getContext()->language->iso_code;
         include_once _PS_TRANSLATIONS_DIR_ . $iso . '/admin.php';
     }
     if (isset($modules_tabs[strtolower($class)])) {
         $class_name_controller = $class . 'controller';
         // if the class is extended by a module, use modules/[module_name]/xx.php lang file
         if (class_exists($class_name_controller) && Module::getModuleNameFromClass($class_name_controller)) {
             $string = str_replace('\'', '\\\'', $string);
             return Translate::getModuleTranslation(Module::$classInModule[$class_name_controller], $string, $class_name_controller);
         }
     }
     $key = md5(str_replace('\'', '\\\'', $string));
     if (isset($_LANGADM[$class . $key])) {
         $str = $_LANGADM[$class . $key];
     } else {
         $str = Translate::getGenericAdminTranslation($string, $key, $_LANGADM);
     }
     if ($htmlentities) {
         $str = htmlentities($str, ENT_QUOTES, 'utf-8');
     }
     $str = str_replace('"', '"', $str);
     if ($sprintf !== null) {
         $str = Translate::checkAndReplaceArgs($str, $sprintf);
     }
     return $addslashes ? addslashes($str) : stripslashes($str);
 }
function smartyTranslate($params, &$smarty)
{
    $htmlentities = !isset($params['js']);
    $pdf = isset($params['pdf']);
    $addslashes = isset($params['slashes']);
    $sprintf = isset($params['sprintf']) ? $params['sprintf'] : false;
    if ($pdf) {
        return Translate::getPdfTranslation($params['s']);
    }
    $filename = !isset($smarty->compiler_object) || !is_object($smarty->compiler_object->template) ? $smarty->template_resource : $smarty->compiler_object->template->getTemplateFilepath();
    // If the template is part of a module
    if (!empty($params['mod'])) {
        return Translate::getModuleTranslation($params['mod'], $params['s'], basename($filename, '.tpl'), $sprintf);
    }
    // If the tpl is at the root of the template folder
    if (dirname($filename) == '.') {
        $class = 'index';
    } elseif (strpos($filename, 'helpers') === 0) {
        $class = 'Helper';
    } else {
        // Split by \ and / to get the folder tree for the file
        $folder_tree = preg_split('#[/\\\\]#', $filename);
        $key = array_search('controllers', $folder_tree);
        // If there was a match, construct the class name using the child folder name
        // Eg. xxx/controllers/customers/xxx => AdminCustomers
        if ($key !== false) {
            $class = 'Admin' . Tools::toCamelCase($folder_tree[$key + 1], true);
        } else {
            $class = null;
        }
    }
    return Translate::getAdminTranslation($params['s'], $class, $addslashes, $htmlentities, $sprintf);
}
Esempio n. 4
0
function smartyTranslate($params, &$smarty)
{
    global $_LANG;
    if (!isset($params['js'])) {
        $params['js'] = false;
    }
    if (!isset($params['pdf'])) {
        $params['pdf'] = false;
    }
    if (!isset($params['mod'])) {
        $params['mod'] = false;
    }
    if (!isset($params['sprintf'])) {
        $params['sprintf'] = null;
    }
    $string = str_replace('\'', '\\\'', $params['s']);
    $filename = !isset($smarty->compiler_object) || !is_object($smarty->compiler_object->template) ? $smarty->template_resource : $smarty->compiler_object->template->getTemplateFilepath();
    $basename = basename($filename, '.tpl');
    $key = $basename . '_' . md5($string);
    if (isset($smarty->source) && strpos($smarty->source->filepath, DIRECTORY_SEPARATOR . 'override' . DIRECTORY_SEPARATOR) !== false) {
        $key = 'override_' . $key;
    }
    if ($params['mod']) {
        return Translate::getModuleTranslation($params['mod'], $params['s'], $basename, $params['sprintf'], $params['js']);
    } else {
        if ($params['pdf']) {
            return Translate::getPdfTranslation($params['s']);
        }
    }
    if ($_LANG != null && isset($_LANG[$key])) {
        $msg = $_LANG[$key];
    } elseif ($_LANG != null && isset($_LANG[Tools::strtolower($key)])) {
        $msg = $_LANG[Tools::strtolower($key)];
    } else {
        $msg = $params['s'];
    }
    if ($msg != $params['s'] && !$params['js']) {
        $msg = stripslashes($msg);
    } elseif ($params['js']) {
        $msg = addslashes($msg);
    }
    if ($params['sprintf'] !== null) {
        $msg = Translate::checkAndReplaceArgs($msg, $params['sprintf']);
    }
    return $params['js'] ? $msg : Tools::safeOutput($msg);
}
Esempio n. 5
0
 /**
  * Uses translations files to find a translation for a given string (string should be in english).
  *
  * @param string $string term or expression in english
  * @param string $class
  * @param bool $addslashes if set to true, the return value will pass through addslashes(). Otherwise, stripslashes().
  * @param bool $htmlentities if set to true(default), the return value will pass through htmlentities($string, ENT_QUOTES, 'utf-8')
  * @return string The translation if available, or the english default text.
  */
 protected function l($string, $class = 'AdminTab', $addslashes = false, $htmlentities = true)
 {
     // if the class is extended by a module, use modules/[module_name]/xx.php lang file
     $current_class = get_class($this);
     if (Module::getModuleNameFromClass($current_class)) {
         $string = str_replace('\'', '\\\'', $string);
         return Translate::getModuleTranslation(Module::$classInModule[$current_class], $string, $current_class);
     }
     global $_LANGADM;
     if ($class == __CLASS__) {
         $class = 'AdminTab';
     }
     $key = md5(str_replace('\'', '\\\'', $string));
     $str = array_key_exists(get_class($this) . $key, $_LANGADM) ? $_LANGADM[get_class($this) . $key] : (array_key_exists($class . $key, $_LANGADM) ? $_LANGADM[$class . $key] : $string);
     $str = $htmlentities ? htmlentities($str, ENT_QUOTES, 'utf-8') : $str;
     return str_replace('"', '"', $addslashes ? addslashes($str) : stripslashes($str));
 }
Esempio n. 6
0
 protected function l($string)
 {
     return Translate::getModuleTranslation($this->module, $string, Tools::getValue('controller'));
 }
Esempio n. 7
0
 protected function l($string, $class = 'AdminTab', $addslashes = false, $htmlentities = true)
 {
     return Translate::getModuleTranslation($this->module, $string, Tools::getValue('controller'));
 }
 public function postProcess()
 {
     if (Tools::isSubmit('sendCampaign')) {
         $yes = (string) Tools::getValue('YES', '');
         $yes = Tools::strtoupper($yes);
         if ($yes == Tools::strtoupper(Translate::getModuleTranslation('expressmailing', 'YES', 'footer_validation'))) {
             if ($this->sendCampaignAPI()) {
                 $this->confirmations[] = $this->module->l('Your campaign is now sending ...', 'adminmarketingestep8');
                 // Tracking Prestashop
                 // -------------------
                 return Db::getInstance()->update('expressmailing_email', array('campaign_state' => '1', 'campaign_api_validation' => '1'), 'campaign_id = ' . $this->campaign_id);
             }
         } else {
             $this->errors[] = sprintf($this->module->l('Please fill the %s field', 'adminmarketingestep8'), '« ' . Translate::getModuleTranslation('expressmailing', 'YES', 'footer_validation') . ' »');
         }
         return false;
     }
 }
 private function convertDocToFaxAPI($filename, $file_path)
 {
     $suffix = pathinfo((string) $filename, PATHINFO_EXTENSION);
     $file_data = Tools::file_get_contents((string) $file_path);
     $encoded_file_data = mb_convert_encoding($file_data, 'BASE64', 'UTF-8');
     $response_array = null;
     $parameters = array('application_id' => Translate::getModuleTranslation('expressmailing', '3320', 'session_api'), 'file_suffix' => 'prestashop.' . $suffix, 'document' => $encoded_file_data, 'return_format' => 'Png');
     if ($this->session_api->call('fax', 'tools', 'convert_doc_to_fax', $parameters, $response_array)) {
         return $response_array;
     } else {
         return false;
     }
 }
Esempio n. 10
0
 /**
  * use translations files to replace english expression.
  *
  * @param mixed $string term or expression in english
  * @param string $class
  * @param boolan $addslashes if set to true, the return value will pass through addslashes(). Otherwise, stripslashes().
  * @param boolean $htmlentities if set to true(default), the return value will pass through htmlentities($string, ENT_QUOTES, 'utf-8')
  * @return string the translation if available, or the english default text.
  */
 protected function l($string, $class = 'AdminTab', $addslashes = false, $htmlentities = true)
 {
     // if the class is extended by a module, use modules/[module_name]/xx.php lang file
     $currentClass = get_class($this);
     if (Module::getModuleNameFromClass($currentClass)) {
         return Translate::getModuleTranslation(Module::$classInModule[$currentClass], $string, $currentClass);
     }
     return Translate::getAdminTranslation($string, get_class($this), $addslashes, $htmlentities);
 }
Esempio n. 11
0
 private function l($string)
 {
     return Translate::getModuleTranslation('expressmailing', $string, 'session_api');
 }
 /**
  * @see Module::l
  */
 private static function l($string, $specific = false)
 {
     if (version_compare(_PS_VERSION_, '1.5.0.13', "<=")) {
         return PKHelper::$_module->l($string, $specific ? $specific : 'pkhelper');
     }
     return Translate::getModuleTranslation('piwikanalyticsjs', $string, $specific ? $specific : 'pkhelper');
     // the following lines are need for the translation to work properly
     // $this->l('I need Site ID and Auth Token before i can get your image tracking code')
     // $this->l('E-commerce is not active for your site in piwik!, you can enable it in the advanced settings on this page')
     // $this->l('Site search is not active for your site in piwik!, you can enable it in the advanced settings on this page')
     // $this->l('Unable to connect to api %s')
     // $this->l('E-commerce is not active for your site in piwik!')
     // $this->l('Site search is not active for your site in piwik!')
     // $this->l('A password is required for method PKHelper::getTokenAuth()!')
 }
 protected function l($string, $class = null, $addslashes = false, $htmlentities = true)
 {
     return Translate::getModuleTranslation('chronopost', $string, Tools::substr(get_class($this), 0, -10), null, false);
 }
 public function postProcess()
 {
     // On construit un login pour le compte
     // ------------------------------------
     // Si PS_SHOP_EMAIL = info@axalone.com
     // Alors login      = ps-info-axalone
     //   1/ On ajoute 'ps-' devant l'email
     //   2/ On retire l'extention .com à la fin
     //   3/ On remplace toutes les lettres accentuées par leurs équivalents sans accent
     //   4/ On remplace tous les sigles par des tirets
     //   5/ Enfin on remplace les doubles/triples tirets par des simples
     // --------------------------------------------------------------------------------
     $company_login = '******' . Configuration::get('PS_SHOP_EMAIL');
     $company_login = Tools::substr($company_login, 0, strrpos($company_login, '.'));
     $company_login = EMTools::removeAccents($company_login);
     $company_login = Tools::strtolower($company_login);
     $company_login = preg_replace('/[^a-z0-9-]/', '-', $company_login);
     $company_login = preg_replace('/-{2,}/', '-', $company_login);
     $cart_product = (string) Tools::getValue('product', '');
     // Initialisation de l'API
     // -----------------------
     if (Tools::isSubmit('submitInscription')) {
         // On prépare l'ouverture du compte
         // --------------------------------
         $company_name = (string) Tools::getValue('company_name');
         $company_email = (string) Tools::getValue('company_email');
         $company_phone = (string) Tools::getValue('company_phone');
         $company_address1 = (string) Tools::getValue('company_address1');
         $company_address2 = (string) Tools::getValue('company_address2');
         $company_zipcode = (string) Tools::getValue('company_zipcode');
         $company_city = (string) Tools::getValue('company_city');
         $country_id = (int) Tools::getValue('country_id');
         $country = new Country($country_id);
         if (!is_object($country) || empty($country->id)) {
             $this->errors[] = Tools::displayError('Country is invalid');
         } else {
             $company_country = Country::getNameById($this->context->language->id, $country_id);
         }
         if (!Validate::isGenericName($company_name)) {
             $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('Shop name', 'AdminStores') . ' »');
         }
         if (!Validate::isEmail($company_email)) {
             $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('Shop email', 'AdminStores') . ' »');
         }
         if (!Validate::isPhoneNumber($company_phone)) {
             $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('Phone', 'AdminStores') . ' »');
         }
         if (!Validate::isAddress($company_address1)) {
             $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('Shop address line 1', 'AdminStores') . ' »');
         }
         if ($country->zip_code_format && !$country->checkZipCode($company_zipcode)) {
             $this->errors[] = Tools::displayError('Your Zip/postal code is incorrect.') . '<br />' . Tools::displayError('It must be entered as follows:') . ' ' . str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format)));
         } elseif (empty($company_zipcode) && $country->need_zip_code) {
             $this->errors[] = Tools::displayError('A Zip/postal code is required.');
         } elseif ($company_zipcode && !Validate::isPostCode($company_zipcode)) {
             $this->errors[] = Tools::displayError('The Zip/postal code is invalid.');
         }
         if (!Validate::isGenericName($company_city)) {
             $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('City', 'AdminStores') . ' »');
         }
         // We save these informations in the database
         // ------------------------------------------
         Db::getInstance()->insert('expressmailing_order_address', array('id_address' => 1, 'company_name' => pSQL($company_name), 'company_email' => pSQL($company_email), 'company_address1' => pSQL($company_address1), 'company_address2' => pSQL($company_address2), 'company_zipcode' => pSQL($company_zipcode), 'company_city' => pSQL($company_city), 'country_id' => $country_id, 'company_country' => pSQL($company_country), 'company_phone' => pSQL($company_phone), 'product' => pSQL($cart_product)), false, false, Db::REPLACE);
         // If form contains 1 or more errors, we stop the process
         // ------------------------------------------------------
         if (is_array($this->errors) && count($this->errors)) {
             return false;
         }
         // Open a session on Express-Mailing API
         // -------------------------------------
         if ($this->session_api->openSession()) {
             // We create the account
             // ---------------------
             $response_array = array();
             $base_url = Configuration::get('PS_SSL_ENABLED') == 0 ? Tools::getShopDomain(true, true) : Tools::getShopDomainSsl(true, true);
             $module_dir = Tools::str_replace_once(_PS_ROOT_DIR_, '', _PS_MODULE_DIR_);
             $parameters = array('login' => $company_login, 'info_company' => $company_name, 'info_email' => $company_email, 'info_phone' => $company_phone, 'info_address' => $company_address1 . "\r\n" . $company_address2, 'info_country' => $company_country, 'info_zipcode' => $company_zipcode, 'info_city' => $company_city, 'info_phone' => $company_phone, 'info_contact_firstname' => $this->context->employee->firstname, 'info_contact_lastname' => $this->context->employee->lastname, 'email_report' => $this->context->employee->email, 'gift_code' => 'prestashop_' . Translate::getModuleTranslation('expressmailing', '3320', 'session_api'), 'INFO_WWW' => $base_url . $module_dir . $this->module->name . '/campaigns/index.php');
             if ($this->session_api->createAccount($parameters, $response_array)) {
                 // If the form include the buying process (field 'product')
                 // We initiate a new cart with the product selected
                 // --------------------------------------------------------
                 if ($cart_product) {
                     Tools::redirectAdmin('index.php?controller=AdminMarketingBuy&submitCheckout&campaign_id=' . $this->campaign_id . '&media=' . $this->next_controller . '&product=' . $cart_product . '&token=' . Tools::getAdminTokenLite('AdminMarketingBuy'));
                     exit;
                 }
                 // Else we back to the mailing process
                 // -----------------------------------
                 Tools::redirectAdmin($this->next_action);
                 exit;
             }
             if ($this->session_api->error == 11) {
                 // Account already existe, we print the rescue form (with password input)
                 // ----------------------------------------------------------------------
                 $response_array = array();
                 $parameters = array('login' => $company_login);
                 $this->session_api->resendPassword($parameters, $response_array);
                 $this->generateRescueForm();
                 return;
             } else {
                 // Other error
                 // -----------
                 $this->errors[] = sprintf($this->module->l('Unable to create an account : %s', 'adminmarketinginscription'), $this->session_api->getError());
                 return false;
             }
         } else {
             $this->errors[] = sprintf($this->module->l('Error during communication with Express-Mailing API : %s', 'adminmarketinginscription'), $this->session_api->getError());
             return false;
         }
     } elseif (Tools::isSubmit('submitRescue')) {
         // Rescue form : ask for existing password
         // ---------------------------------------
         if ($this->session_api->openSession()) {
             $response_array = array();
             $password = trim((string) Tools::getValue('api_password'));
             $parameters = array('login' => $company_login, 'password' => $password);
             if ($this->session_api->connectUser($parameters, $response_array)) {
                 Db::getInstance()->insert('expressmailing', array('api_login' => pSQL($company_login), 'api_password' => pSQL($password)), false, false, Db::REPLACE);
                 // If the form include the buying process (field 'product')
                 // We initiate a new cart with the product selected
                 // --------------------------------------------------------
                 if ($cart_product) {
                     Tools::redirectAdmin('index.php?controller=AdminMarketingBuy&submitCheckout&campaign_id=' . $this->campaign_id . '&media=' . $this->next_controller . '&product=' . $cart_product . '&token=' . Tools::getAdminTokenLite('AdminMarketingBuy'));
                     exit;
                 }
                 // Else we back to the mailing process
                 // -----------------------------------
                 Tools::redirectAdmin($this->next_action);
                 exit;
             }
         }
         $this->errors[] = sprintf($this->module->l('Error during communication with Express-Mailing API : %s', 'adminmarketinginscription'), $this->session_api->getError());
         return false;
     }
 }
Esempio n. 15
0
function smartyTranslate($params, &$smarty)
{
    $htmlentities = !isset($params['js']);
    $pdf = isset($params['pdf']);
    $addslashes = isset($params['slashes']) || isset($params['js']);
    $sprintf = isset($params['sprintf']) ? $params['sprintf'] : array();
    if (!empty($params['d'])) {
        if (isset($params['tags'])) {
            $backTrace = debug_backtrace();
            $errorMessage = sprintf('Unable to translate "%s" in %s. tags() is not supported anymore, please use sprintf().', $params['s'], $backTrace[0]['args'][1]->template_resource);
            if (_PS_MODE_DEV_) {
                throw new Exception($errorMessage);
            } else {
                PrestaShopLogger::addLog($errorMessage);
            }
        }
        if (!is_array($sprintf)) {
            $backTrace = debug_backtrace();
            $errorMessage = sprintf('Unable to translate "%s" in %s. sprintf() parameter should be an array.', $params['s'], $backTrace[0]['args'][1]->template_resource);
            if (_PS_MODE_DEV_) {
                throw new Exception($errorMessage);
            } else {
                PrestaShopLogger::addLog($errorMessage);
                return $params['s'];
            }
        }
        return Context::getContext()->getTranslator()->trans($params['s'], $sprintf, $params['d']);
    }
    if ($pdf) {
        return Translate::smartyPostProcessTranslation(Translate::getPdfTranslation($params['s'], $sprintf), $params);
    }
    $filename = !isset($smarty->compiler_object) || !is_object($smarty->compiler_object->template) ? $smarty->template_resource : $smarty->compiler_object->template->getTemplateFilepath();
    // If the template is part of a module
    if (!empty($params['mod'])) {
        return Translate::smartyPostProcessTranslation(Translate::getModuleTranslation($params['mod'], $params['s'], basename($filename, '.tpl'), $sprintf, isset($params['js'])), $params);
    }
    // If the tpl is at the root of the template folder
    if (dirname($filename) == '.') {
        $class = 'index';
    }
    // If the tpl is used by a Helper
    if (strpos($filename, 'helpers') === 0) {
        $class = 'Helper';
    } else {
        // If the tpl is used by a Controller
        if (!empty(Context::getContext()->override_controller_name_for_translations)) {
            $class = Context::getContext()->override_controller_name_for_translations;
        } elseif (isset(Context::getContext()->controller)) {
            $class_name = get_class(Context::getContext()->controller);
            $class = substr($class_name, 0, strpos(Tools::strtolower($class_name), 'controller'));
        } else {
            // Split by \ and / to get the folder tree for the file
            $folder_tree = preg_split('#[/\\\\]#', $filename);
            $key = array_search('controllers', $folder_tree);
            // If there was a match, construct the class name using the child folder name
            // Eg. xxx/controllers/customers/xxx => AdminCustomers
            if ($key !== false) {
                $class = 'Admin' . Tools::toCamelCase($folder_tree[$key + 1], true);
            } elseif (isset($folder_tree[0])) {
                $class = 'Admin' . Tools::toCamelCase($folder_tree[0], true);
            }
        }
    }
    return Translate::smartyPostProcessTranslation(Translate::getAdminTranslation($params['s'], $class, $addslashes, $htmlentities, $sprintf), $params);
}
 public function postProcess()
 {
     if (Tools::isSubmit('sendCampaign')) {
         $yes = (string) Tools::getValue('YES', '');
         $yes = Tools::strtoupper($yes);
         if ($yes == Tools::strtoupper(Translate::getModuleTranslation('expressmailing', 'YES', 'footer_validation'))) {
             if ($this->sendCampaignAPI()) {
                 $this->confirmations[] = $this->module->l('Your campaign is now sending ...', 'adminmarketingfstep8');
                 // Tracking Prestashop
                 // -------------------
                 Db::getInstance()->update('expressmailing_fax', array('campaign_state' => 2, 'campaign_api_validation' => '1'), 'campaign_id = ' . $this->campaign_id);
                 // On vide la table temporaire des contacts
                 // ----------------------------------------
                 Db::getInstance()->delete('expressmailing_fax_recipients', 'campaign_id = ' . $this->campaign_id);
                 $req = new DbQuery();
                 $req->select('*');
                 $req->from('expressmailing_fax_pages');
                 $req->where('campaign_id = ' . $this->campaign_id);
                 $req->orderBy('id');
                 $pages_db = Db::getInstance()->executeS($req, true, false);
                 foreach ($pages_db as $page) {
                     unlink($page['page_path']);
                     unlink($page['page_path_original']);
                 }
                 Db::getInstance()->delete('expressmailing_fax_pages', 'campaign_id = ' . $this->campaign_id);
                 return true;
             }
         } else {
             $this->errors[] = sprintf($this->module->l('Please fill the %s field', 'adminmarketingfstep8'), '&laquo;&nbsp;' . Translate::getModuleTranslation('expressmailing', 'YES', 'footer_validation') . '&nbsp;&raquo;');
         }
         return false;
     }
 }
Esempio n. 17
0
function smartyTranslate($params, &$smarty)
{
    global $_LANG;
    if (!isset($params['js'])) {
        $params['js'] = false;
    }
    if (!isset($params['pdf'])) {
        $params['pdf'] = false;
    }
    if (!isset($params['mod'])) {
        $params['mod'] = false;
    }
    if (!isset($params['sprintf'])) {
        $params['sprintf'] = array();
    }
    if (!isset($params['d'])) {
        $params['d'] = null;
    }
    if (!is_null($params['d'])) {
        if (isset($params['tags'])) {
            $backTrace = debug_backtrace();
            $errorMessage = sprintf('Unable to translate "%s" in %s. tags() is not supported anymore, please use sprintf().', $params['s'], $backTrace[0]['args'][1]->template_resource);
            if (_PS_MODE_DEV_) {
                throw new Exception($errorMessage);
            } else {
                PrestaShopLogger::addLog($errorMessage);
            }
        }
        if (!is_array($params['sprintf'])) {
            $backTrace = debug_backtrace();
            $errorMessage = sprintf('Unable to translate "%s" in %s. sprintf() parameter should be an array.', $params['s'], $backTrace[0]['args'][1]->template_resource);
            if (_PS_MODE_DEV_) {
                throw new Exception($errorMessage);
            } else {
                PrestaShopLogger::addLog($errorMessage);
                return $params['s'];
            }
        }
    }
    if (($translation = Context::getContext()->getTranslator()->trans($params['s'], $params['sprintf'], $params['d'])) !== $params['s']) {
        return $translation;
    }
    $string = str_replace('\'', '\\\'', $params['s']);
    $filename = !isset($smarty->compiler_object) || !is_object($smarty->compiler_object->template) ? $smarty->template_resource : $smarty->compiler_object->template->getTemplateFilepath();
    $basename = basename($filename, '.tpl');
    $key = $basename . '_' . md5($string);
    if (isset($smarty->source) && strpos($smarty->source->filepath, DIRECTORY_SEPARATOR . 'override' . DIRECTORY_SEPARATOR) !== false) {
        $key = 'override_' . $key;
    }
    if ($params['mod']) {
        return Translate::smartyPostProcessTranslation(Translate::getModuleTranslation($params['mod'], $params['s'], $basename, $params['sprintf'], $params['js']), $params);
    } elseif ($params['pdf']) {
        return Translate::smartyPostProcessTranslation(Translate::getPdfTranslation($params['s'], $params['sprintf']), $params);
    }
    if ($_LANG != null && isset($_LANG[$key])) {
        $msg = $_LANG[$key];
    } elseif ($_LANG != null && isset($_LANG[Tools::strtolower($key)])) {
        $msg = $_LANG[Tools::strtolower($key)];
    } else {
        $msg = $params['s'];
    }
    if ($msg != $params['s'] && !$params['js']) {
        $msg = stripslashes($msg);
    } elseif ($params['js']) {
        $msg = addslashes($msg);
    }
    if ($params['sprintf'] !== null) {
        $msg = Translate::checkAndReplaceArgs($msg, $params['sprintf']);
    }
    return Translate::smartyPostProcessTranslation($params['js'] ? $msg : Tools::safeOutput($msg), $params);
}
Esempio n. 18
0
 /**
  * Get translation for a given module text
  *
  * Note: $specific parameter is mandatory for library files.
  * Otherwise, translation key will not match for Module library
  * when module is loaded with eval() Module::getModulesOnDisk()
  *
  * @param string $string String to translate
  * @param bool|string $specific filename to use in translation key
  * @return string Translation
  */
 public function l($string, $specific = false)
 {
     if (self::$_generate_config_xml_mode) {
         return $string;
     }
     if (($translation = Context::getContext()->getTranslator()->trans($string)) !== $string) {
         return $translation;
     }
     return Translate::getModuleTranslation($this, $string, $specific ? $specific : $this->name);
 }
Esempio n. 19
0
 /**
  * Get translation for a given module text
  *
  * Note: $specific parameter is mandatory for library files.
  * Otherwise, translation key will not match for Module library
  * when module is loaded with eval() Module::getModulesOnDisk()
  *
  * @param string $string String to translate
  * @param boolean|string $specific filename to use in translation key
  * @return string Translation
  */
 public function l($string, $specific = false)
 {
     return Translate::getModuleTranslation($this->modName, $string, $specific ? $specific : $this->modName);
 }
Esempio n. 20
0
    public static function getModulesOnDisk($useConfig = false, $loggedOnAddons = false, $id_employee = false)
    {
        global $_MODULES;
        // Init var
        $module_list = array();
        $module_name_list = array();
        $modulesNameToCursor = array();
        $errors = array();
        // Get modules directory list and memory limit
        $modules_dir = Module::getModulesDirOnDisk();
        $modules_installed = array();
        $result = Db::getInstance()->executeS('
		SELECT m.name, m.version, mp.interest, module_shop.enable_device
		FROM `' . _DB_PREFIX_ . 'module` m
		' . Shop::addSqlAssociation('module', 'm') . '
		LEFT JOIN `' . _DB_PREFIX_ . 'module_preference` mp ON (mp.`module` = m.`name` AND mp.`id_employee` = ' . (int) $id_employee . ')');
        foreach ($result as $row) {
            $modules_installed[$row['name']] = $row;
        }
        foreach ($modules_dir as $module) {
            if (Module::useTooMuchMemory()) {
                $errors[] = Tools::displayError('All modules cannot be loaded due to memory limit restrictions, please increase your memory_limit value on your server configuration');
                break;
            }
            $iso = Tools::substr(Context::getContext()->language->iso_code, 0, 2);
            // Check if config.xml module file exists and if it's not outdated
            if ($iso == 'en') {
                $configFile = _PS_MODULE_DIR_ . $module . '/config.xml';
            } else {
                $configFile = _PS_MODULE_DIR_ . $module . '/config_' . $iso . '.xml';
            }
            $xml_exist = file_exists($configFile);
            $needNewConfigFile = $xml_exist ? @filemtime($configFile) < @filemtime(_PS_MODULE_DIR_ . $module . '/' . $module . '.php') : true;
            // If config.xml exists and that the use config flag is at true
            if ($useConfig && $xml_exist && !$needNewConfigFile) {
                // Load config.xml
                libxml_use_internal_errors(true);
                $xml_module = simplexml_load_file($configFile);
                foreach (libxml_get_errors() as $error) {
                    $errors[] = '[' . $module . '] ' . Tools::displayError('Error found in config file:') . ' ' . htmlentities($error->message);
                }
                libxml_clear_errors();
                // If no errors in Xml, no need instand and no need new config.xml file, we load only translations
                if (!count($errors) && (int) $xml_module->need_instance == 0) {
                    $file = _PS_MODULE_DIR_ . $module . '/' . Context::getContext()->language->iso_code . '.php';
                    if (Tools::file_exists_cache($file) && (include_once $file)) {
                        if (isset($_MODULE) && is_array($_MODULE)) {
                            $_MODULES = !empty($_MODULES) ? array_merge($_MODULES, $_MODULE) : $_MODULE;
                        }
                    }
                    $item = new stdClass();
                    $item->id = 0;
                    $item->warning = '';
                    foreach ($xml_module as $k => $v) {
                        $item->{$k} = (string) $v;
                    }
                    $item->displayName = Tools::stripslashes(Translate::getModuleTranslation((string) $xml_module->name, Module::configXmlStringFormat($xml_module->displayName), (string) $xml_module->name));
                    $item->description = Tools::stripslashes(Translate::getModuleTranslation((string) $xml_module->name, Module::configXmlStringFormat($xml_module->description), (string) $xml_module->name));
                    $item->author = Tools::stripslashes(Translate::getModuleTranslation((string) $xml_module->name, Module::configXmlStringFormat($xml_module->author), (string) $xml_module->name));
                    $item->is_eu_compatible = Tools::stripslashes(Translate::getModuleTranslation((string) $xml_module->name, Module::configXmlStringFormat($xml_module->is_eu_compatible), (string) $xml_module->name));
                    if (isset($xml_module->confirmUninstall)) {
                        $item->confirmUninstall = Translate::getModuleTranslation((string) $xml_module->name, html_entity_decode(Module::configXmlStringFormat($xml_module->confirmUninstall)), (string) $xml_module->name);
                    }
                    $item->active = 0;
                    $item->onclick_option = false;
                    $item->trusted = Module::isModuleTrusted($item->name);
                    $module_list[] = $item;
                    $module_name_list[] = '\'' . pSQL($item->name) . '\'';
                    $modulesNameToCursor[(string) $item->name] = $item;
                }
            }
            // If use config flag is at false or config.xml does not exist OR need instance OR need a new config.xml file
            if (!$useConfig || !$xml_exist || isset($xml_module->need_instance) && (int) $xml_module->need_instance == 1 || $needNewConfigFile) {
                // If class does not exists, we include the file
                if (!class_exists($module, false)) {
                    // Get content from php file
                    $filepath = _PS_MODULE_DIR_ . $module . '/' . $module . '.php';
                    $file = trim(Tools::file_get_contents(_PS_MODULE_DIR_ . $module . '/' . $module . '.php'));
                    if (substr($file, 0, 5) == '<?php') {
                        $file = substr($file, 5);
                    }
                    if (substr($file, -2) == '?>') {
                        $file = substr($file, 0, -2);
                    }
                    // If (false) is a trick to not load the class with "eval".
                    // This way require_once will works correctly
                    if (eval('if (false){	' . $file . ' }') !== false) {
                        require_once _PS_MODULE_DIR_ . $module . '/' . $module . '.php';
                    } else {
                        $errors[] = sprintf(Tools::displayError('%1$s (parse error in %2$s)'), $module, Tools::substr($filepath, Tools::strlen(_PS_ROOT_DIR_)));
                    }
                }
                // If class exists, we just instanciate it
                if (class_exists($module, false)) {
                    $tmp_module = new $module();
                    $item = new stdClass();
                    $item->id = $tmp_module->id;
                    $item->warning = $tmp_module->warning;
                    $item->name = $tmp_module->name;
                    $item->version = $tmp_module->version;
                    $item->tab = $tmp_module->tab;
                    $item->displayName = $tmp_module->displayName;
                    $item->description = Tools::stripslashes($tmp_module->description);
                    $item->author = $tmp_module->author;
                    $item->limited_countries = $tmp_module->limited_countries;
                    $item->parent_class = get_parent_class($module);
                    $item->is_configurable = $tmp_module->is_configurable = method_exists($tmp_module, 'getContent') ? 1 : 0;
                    $item->need_instance = isset($tmp_module->need_instance) ? $tmp_module->need_instance : 0;
                    $item->active = $tmp_module->active;
                    $item->trusted = Module::isModuleTrusted($tmp_module->name);
                    $item->currencies = isset($tmp_module->currencies) ? $tmp_module->currencies : null;
                    $item->currencies_mode = isset($tmp_module->currencies_mode) ? $tmp_module->currencies_mode : null;
                    $item->confirmUninstall = isset($tmp_module->confirmUninstall) ? html_entity_decode($tmp_module->confirmUninstall) : null;
                    $item->description_full = Tools::stripslashes($tmp_module->description_full);
                    $item->additional_description = isset($tmp_module->additional_description) ? Tools::stripslashes($tmp_module->additional_description) : null;
                    $item->compatibility = isset($tmp_module->compatibility) ? (array) $tmp_module->compatibility : null;
                    $item->nb_rates = isset($tmp_module->nb_rates) ? (array) $tmp_module->nb_rates : null;
                    $item->avg_rate = isset($tmp_module->avg_rate) ? (array) $tmp_module->avg_rate : null;
                    $item->badges = isset($tmp_module->badges) ? (array) $tmp_module->badges : null;
                    $item->url = isset($tmp_module->url) ? $tmp_module->url : null;
                    $item->is_eu_compatible = isset($tmp_module->is_eu_compatible) ? $tmp_module->is_eu_compatible : 0;
                    $item->onclick_option = method_exists($module, 'onclickOption') ? true : false;
                    if ($item->onclick_option) {
                        $href = Context::getContext()->link->getAdminLink('Module', true) . '&module_name=' . $tmp_module->name . '&tab_module=' . $tmp_module->tab;
                        $item->onclick_option_content = array();
                        $option_tab = array('desactive', 'reset', 'configure', 'delete');
                        foreach ($option_tab as $opt) {
                            $item->onclick_option_content[$opt] = $tmp_module->onclickOption($opt, $href);
                        }
                    }
                    $module_list[] = $item;
                    if (!$xml_exist || $needNewConfigFile) {
                        self::$_generate_config_xml_mode = true;
                        $tmp_module->_generateConfigXml();
                        self::$_generate_config_xml_mode = false;
                    }
                    unset($tmp_module);
                } else {
                    $errors[] = sprintf(Tools::displayError('%1$s (class missing in %2$s)'), $module, Tools::substr($filepath, Tools::strlen(_PS_ROOT_DIR_)));
                }
            }
        }
        // Get modules information from database
        if (!empty($module_name_list)) {
            $list = Shop::getContextListShopID();
            $sql = 'SELECT m.id_module, m.name, (
						SELECT COUNT(*) FROM ' . _DB_PREFIX_ . 'module_shop ms WHERE m.id_module = ms.id_module AND ms.id_shop IN (' . implode(',', $list) . ')
					) as total
					FROM ' . _DB_PREFIX_ . 'module m
					WHERE m.name IN (' . implode(',', $module_name_list) . ')';
            $results = Db::getInstance()->executeS($sql);
            foreach ($results as $result) {
                $moduleCursor = $modulesNameToCursor[$result['name']];
                $moduleCursor->id = $result['id_module'];
                $moduleCursor->active = $result['total'] == count($list) ? 1 : 0;
            }
        }
        // Get Default Country Modules and customer module
        $files_list = array(array('type' => 'addonsNative', 'file' => _PS_ROOT_DIR_ . self::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST, 'loggedOnAddons' => 0), array('type' => 'addonsBought', 'file' => _PS_ROOT_DIR_ . self::CACHE_FILE_CUSTOMER_MODULES_LIST, 'loggedOnAddons' => 1), array('type' => 'addonsMustHave', 'file' => _PS_ROOT_DIR_ . self::CACHE_FILE_MUST_HAVE_MODULES_LIST, 'loggedOnAddons' => 0));
        foreach ($files_list as $f) {
            if (file_exists($f['file']) && ($f['loggedOnAddons'] == 0 || $loggedOnAddons)) {
                if (Module::useTooMuchMemory()) {
                    $errors[] = Tools::displayError('All modules cannot be loaded due to memory limit restrictions, please increase your memory_limit value on your server configuration');
                    break;
                }
                $file = $f['file'];
                $content = Tools::file_get_contents($file);
                $xml = @simplexml_load_string($content, null, LIBXML_NOCDATA);
                if ($xml && isset($xml->module)) {
                    foreach ($xml->module as $modaddons) {
                        $flag_found = 0;
                        foreach ($module_list as $k => &$m) {
                            if ($m->name == $modaddons->name && !isset($m->available_on_addons)) {
                                $flag_found = 1;
                                if ($m->version != $modaddons->version && version_compare($m->version, $modaddons->version) === -1 && !$m->is_eu_compatible) {
                                    $module_list[$k]->version_addons = $modaddons->version;
                                }
                            }
                        }
                        if ($flag_found == 0) {
                            $item = new stdClass();
                            $item->id = 0;
                            $item->warning = '';
                            $item->type = strip_tags((string) $f['type']);
                            $item->name = strip_tags((string) $modaddons->name);
                            $item->version = strip_tags((string) $modaddons->version);
                            $item->tab = strip_tags((string) $modaddons->tab);
                            $item->displayName = strip_tags((string) $modaddons->displayName);
                            $item->description = Tools::stripslashes(strip_tags((string) $modaddons->description));
                            $item->description_full = Tools::stripslashes(strip_tags((string) $modaddons->description_full));
                            $item->author = strip_tags((string) $modaddons->author);
                            $item->limited_countries = array();
                            $item->parent_class = '';
                            $item->onclick_option = false;
                            $item->is_configurable = 0;
                            $item->need_instance = 0;
                            $item->not_on_disk = 1;
                            $item->available_on_addons = 1;
                            $item->trusted = Module::isModuleTrusted($item->name);
                            $item->active = 0;
                            $item->description_full = Tools::stripslashes($modaddons->description_full);
                            $item->additional_description = isset($modaddons->additional_description) ? Tools::stripslashes($modaddons->additional_description) : null;
                            $item->compatibility = isset($modaddons->compatibility) ? (array) $modaddons->compatibility : null;
                            $item->nb_rates = isset($modaddons->nb_rates) ? (array) $modaddons->nb_rates : null;
                            $item->avg_rate = isset($modaddons->avg_rate) ? (array) $modaddons->avg_rate : null;
                            $item->badges = isset($modaddons->badges) ? (array) $modaddons->badges : null;
                            $item->url = isset($modaddons->url) ? $modaddons->url : null;
                            if (isset($modaddons->img)) {
                                if (!file_exists(_PS_TMP_IMG_DIR_ . md5($modaddons->name) . '.jpg')) {
                                    if (!file_put_contents(_PS_TMP_IMG_DIR_ . md5($modaddons->name) . '.jpg', Tools::file_get_contents($modaddons->img))) {
                                        copy(_PS_IMG_DIR_ . '404.gif', _PS_TMP_IMG_DIR_ . md5($modaddons->name) . '.jpg');
                                    }
                                }
                                if (file_exists(_PS_TMP_IMG_DIR_ . md5($modaddons->name) . '.jpg')) {
                                    $item->image = '../img/tmp/' . md5($modaddons->name) . '.jpg';
                                }
                            }
                            if ($item->type == 'addonsMustHave') {
                                $item->addons_buy_url = strip_tags((string) $modaddons->url);
                                $prices = (array) $modaddons->price;
                                $id_default_currency = Configuration::get('PS_CURRENCY_DEFAULT');
                                foreach ($prices as $currency => $price) {
                                    if ($id_currency = Currency::getIdByIsoCode($currency)) {
                                        $item->price = (double) $price;
                                        $item->id_currency = (int) $id_currency;
                                        if ($id_default_currency == $id_currency) {
                                            break;
                                        }
                                    }
                                }
                            }
                            $module_list[] = $item;
                        }
                    }
                }
            }
        }
        foreach ($module_list as $key => &$module) {
            if (defined('_PS_HOST_MODE_') && in_array($module->name, self::$hosted_modules_blacklist)) {
                unset($module_list[$key]);
            } elseif (isset($modules_installed[$module->name])) {
                $module->installed = true;
                $module->database_version = $modules_installed[$module->name]['version'];
                $module->interest = $modules_installed[$module->name]['interest'];
                $module->enable_device = $modules_installed[$module->name]['enable_device'];
            } else {
                $module->installed = false;
                $module->database_version = 0;
                $module->interest = 0;
            }
        }
        usort($module_list, create_function('$a,$b', 'return strnatcasecmp($a->displayName, $b->displayName);'));
        if ($errors) {
            if (!isset(Context::getContext()->controller) && !Context::getContext()->controller->controller_name) {
                echo '<div class="alert error"><h3>' . Tools::displayError('The following module(s) could not be loaded') . ':</h3><ol>';
                foreach ($errors as $error) {
                    echo '<li>' . $error . '</li>';
                }
                echo '</ol></div>';
            } else {
                foreach ($errors as $error) {
                    Context::getContext()->controller->errors[] = $error;
                }
            }
        }
        return $module_list;
    }
 public function initToolbarTitle()
 {
     parent::initToolbarTitle();
     $this->toolbar_title = Translate::getModuleTranslation('expressmailing', 'My emailing statistics', 'marketing_step0');
 }
Esempio n. 22
0
 /**
  * Get translation for a given module text
  *
  * Note: $specific parameter is mandatory for library files.
  * Otherwise, translation key will not match for Module library
  * when module is loaded with eval() Module::getModulesOnDisk()
  *
  * @param string $string String to translate
  * @param boolean|string $specific filename to use in translation key
  * @return string Translation
  */
 public function l($string, $specific = false)
 {
     if (self::$_generate_config_xml_mode) {
         return $string;
     }
     return Translate::getModuleTranslation($this, $string, $specific ? $specific : $this->name);
 }
 public function initToolbarTitle()
 {
     parent::initToolbarTitle();
     $this->toolbar_title = Translate::getModuleTranslation('expressmailing', 'Send a fax-mailing', 'adminmarketingfstep1');
 }
Esempio n. 24
0
 private function l($string)
 {
     return Translate::getModuleTranslation('expressmailing', $string, 'em_tools');
 }