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::smartyPostProcessTranslation(Translate::getModuleTranslation($params['mod'], $params['s'], $basename, $params['sprintf'], $params['js']), $params);
    } else {
        if ($params['pdf']) {
            return Translate::smartyPostProcessTranslation(Translate::getPdfTranslation($params['s']), $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);
}
예제 #2
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'] : null;
    if ($pdf) {
        return Translate::smartyPostProcessTranslation(Translate::getPdfTranslation($params['s']), $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 (!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);
}
예제 #3
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);
}
예제 #4
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);
}
예제 #5
0
 protected function getConfigurableModules()
 {
     // Construct the description for the 'Enable Live Configurator' switch
     if ($this->context->shop->getBaseURL()) {
         $desc = $this->l('Only you can see this [1]on your Front-Office[/1] - your visitors will not see this tool.');
         $url = $this->context->shop->getBaseURL() . (Configuration::get('PS_REWRITING_SETTINGS') && count(Language::getLanguages(true)) > 1 ? Language::getIsoById($this->context->employee->id_lang) . '/' : '') . (Configuration::get('PS_REWRITING_SETTINGS') ? '' : 'index.php') . '?live_configurator_token=' . $this->getLiveConfiguratorToken() . '&id_employee=' . (int) $this->context->employee->id . '&id_shop=' . (int) $this->context->shop->id . (Configuration::get('PS_TC_THEME') != '' ? '&theme=' . Configuration::get('PS_TC_THEME') : '') . (Configuration::get('PS_TC_FONT') != '' ? '&theme_font=' . Configuration::get('PS_TC_FONT') : '');
         $link = '<a href="' . $url . '" onclick="return !window.open($(this).attr(\'href\'));">';
         $desc = Translate::smartyPostProcessTranslation($desc, array('tags' => array($link)));
     } else {
         $desc = $this->l('Only you can see this on your Front-Office - your visitors will not see this tool.');
     }
     return array(array('label' => $this->l('Display links to your store\'s social accounts (Twitter, Facebook, etc.)'), 'name' => 'blocksocial', 'value' => (int) Validate::isLoadedObject($module = Module::getInstanceByName('blocksocial')) && $module->isEnabledForShopContext(), 'is_module' => true), array('label' => $this->l('Display contact information'), 'name' => 'blockcontactinfos', 'value' => (int) Validate::isLoadedObject($module = Module::getInstanceByName('blockcontactinfos')) && $module->isEnabledForShopContext(), 'is_module' => true), array('label' => $this->l('Display social sharing buttons on the products page'), 'name' => 'socialsharing', 'value' => (int) Validate::isLoadedObject($module = Module::getInstanceByName('socialsharing')) && $module->isEnabledForShopContext(), 'is_module' => true), array('label' => $this->l('Display the Facebook block on the home page'), 'name' => 'blockfacebook', 'value' => (int) Validate::isLoadedObject($module = Module::getInstanceByName('blockfacebook')) && $module->isEnabledForShopContext(), 'is_module' => true), array('label' => $this->l('Custom CMS information block'), 'name' => 'blockcmsinfo', 'value' => (int) Validate::isLoadedObject($module = Module::getInstanceByName('blockcmsinfo')) && $module->isEnabledForShopContext(), 'is_module' => true), array('label' => $this->l('Enable quick view'), 'name' => 'quick_view', 'value' => (int) Tools::getValue('PS_QUICK_VIEW', Configuration::get('PS_QUICK_VIEW'))), array('label' => $this->l('Enable top banner'), 'name' => 'blockbanner', 'value' => (int) Validate::isLoadedObject($module = Module::getInstanceByName('blockbanner')) && $module->isEnabledForShopContext(), 'is_module' => true), array('label' => $this->l('Display your product payment logos'), 'name' => 'productpaymentlogos', 'value' => (int) Validate::isLoadedObject($module = Module::getInstanceByName('productpaymentlogos')) && $module->isEnabledForShopContext(), 'is_module' => true), array('label' => $this->l('Enable Live Configurator'), 'name' => 'live_conf', 'value' => (int) Tools::getValue('PS_TC_ACTIVE', Configuration::get('PS_TC_ACTIVE')), 'hint' => $this->l('The customization tool allows you to make color and font changes in your theme.'), 'desc' => $desc));
 }