]*\>.*(\{__\("([^\}]+)"\)\}[^:\<]*).*\<\/label\>/';
if (preg_match_all($pattern, $content, $matches)) {
$cur_templ = $template->template_resource;
$template_pattern = '/([^\/\.]+)/';
$template_name = '';
$ignored_names = array('tpl');
if (preg_match_all($template_pattern, $cur_templ, $template_matches)) {
foreach ($template_matches[0] as $k => $m) {
if (!in_array($template_matches[1][$k], $ignored_names)) {
$template_name .= $template_matches[1][$k] . '_';
}
}
}
$template_pref = 'tt_' . $template_name;
$template_tooltips = fn_get_lang_vars_by_prefix($template_pref);
foreach ($matches[0] as $k => $m) {
$field_name = $matches[2][$k];
preg_match("/(^[a-zA-z0-9][\.a-zA-Z0-9_]*)/", $field_name, $name_matches);
if (@strlen($name_matches[0]) != strlen($field_name)) {
continue;
}
$label = $matches[1][$k];
$template_lang_var = $template_pref . $field_name;
$common_lang_var = 'ttc_' . $field_name;
if (isset($_REQUEST['stt'])) {
$template_text = isset($template_tooltips[$template_lang_var]) ? '{__("' . $template_lang_var . '")}' : '';
$common_tip = __($common_lang_var);
$common_text = '';
if ($common_tip != '_' . $common_lang_var) {
$common_text = '{__("' . $common_lang_var . '")}';
}
$tooltip_text = sprintf("%s: %s
%s: %s", $common_lang_var, $common_text, $template_lang_var, $template_text);
$tooltip = '{capture name="tooltip"}' . $tooltip_text . '{/capture}{include file="common/tooltip.tpl" tooltip=$smarty.capture.tooltip}';
} else {
if (isset($template_tooltips[$template_lang_var])) {
$tooltip_text = '__("' . $template_lang_var . '")';
} else {
$tooltip = __($common_lang_var);
if ($tooltip == '_' . $common_lang_var || empty($tooltip)) {
continue;
}
$tooltip_text = '__("' . $common_lang_var . '")';
}
$tooltip = '{include file="common/tooltip.tpl" tooltip=' . $tooltip_text . '}';
}
$tooltip_added = str_replace($label, $label . $tooltip, $matches[0][$k]);
$content = str_replace($matches[0][$k], $tooltip_added, $content);
}
}
return $content;
}
/**
* Prefilter: template wrapper for design mode
* @param string $content template content
* @param \Smarty_Internal_Template $template template instance
* @return string template content
*/
public static function preTemplateWrapper($content, \Smarty_Internal_Template $template)
{
$cur_templ = fn_addon_template_overrides($template->template_resource, $template);
$ignored_template = array(
'index.tpl',
'common/pagination.tpl',
'views/categories/components/menu_items.tpl',
'views/block_manager/render/location.tpl',
'views/block_manager/render/container.tpl',
'views/block_manager/render/grid.tpl',
'views/block_manager/render/block.tpl'
);
if (!in_array($cur_templ, $ignored_template) && fn_get_file_ext($cur_templ) == 'tpl') { // process only "real" templates (not eval'ed, etc.)
$content =
'{if $runtime.customization_mode.design == "Y" && $smarty.const.AREA == "C"}' .
'{capture name="template_content"}' . $content . '{/capture}' .
'{if $smarty.capture.template_content|trim}' .
'{if $auth.area == "A"}' .
'' .
'' .
'{$smarty.capture.template_content nofilter}' .
'{else}{$smarty.capture.template_content nofilter}{/if}{/if}' .
'{else}' . $content . '{/if}';
}
return $content;
}
/**
* Postfilter: gets all available language variables in templates and puts their retrieving to the template start
* @param string $content template content
* @param \Smarty_Internal_Template $template template instance
* @return string template content
*/
public static function postTranslation($content, \Smarty_Internal_Template $template)
{
$content = preg_replace('/([^\>])__\(/', '\1$_smarty_tpl->__(', $content);
if (preg_match_all('/__\(\"([\w\.]*?)\"/i', $content, $matches)) {
return "\n" . $content;
}
return $content;
}
/**
* Output filter: translation mode
* @param string $content template content
* @param \Smarty_Internal_Template $template template instance
* @return string template content
*/
public static function outputLiveEditorWrapper($content, \Smarty_Internal_Template $template)
{
$pattern = '/\<(input|img|div)[^>]*?(\[lang name\=([\w-\.]+?)( cm\-pre\-ajax)?\](.*?)\[\/lang\])[^>]*?\>/';
if (preg_match_all($pattern, $content, $matches)) {
foreach ($matches[0] as $k => $m) {
$phrase_replaced = str_replace($matches[2][$k], $matches[5][$k], $matches[0][$k]);
if (strpos($m, 'class="') !== false) {
$class_added = str_replace('class="', 'data-ca-live-edit="langvar::' . $matches[3][$k] . $matches[4][$k] . '" class="cm-live-editor-need-wrap ', $phrase_replaced);
} else {
$class_added = str_replace($matches[1][$k], $matches[1][$k] . ' data-ca-live-edit="langvar::' . $matches[3][$k] . $matches[4][$k] . '" class="cm-live-editor-need-wrap"', $phrase_replaced);
}
if ($matches[1][$k] == 'div') {
$content = str_replace($matches[0][$k], $phrase_replaced, $content);
} else {
$content = str_replace($matches[0][$k], $class_added, $content);
}
}
}
$pattern = '/(\<(textarea|option)[^<]*?)\>(\[lang name\=([\w-\.]+?)( cm\-pre\-ajax)?\](.*?)\[\/lang\])[^>]*?\>/is';
if (preg_match_all($pattern, $content, $matches)) {
foreach ($matches[0] as $k => $m) {
$phrase_replaced = str_replace($matches[3][$k], $matches[6][$k], $matches[0][$k]);
if (strpos($m, 'class="') !== false) {
$class_added = str_replace('class="', 'data-ca-live-edit="langvar::' . $matches[4][$k] . $matches[5][$k] . '" class="cm-live-editor-need-wrap ', $phrase_replaced);
} else {
$class_added = str_replace('<' . $matches[2][$k], '<' . $matches[2][$k] . ' data-ca-live-edit="langvar::' . $matches[4][$k] . $matches[5][$k] . '" class="cm-live-editor-need-wrap"', $phrase_replaced);
}
$content = str_replace($matches[0][$k], $class_added, $content);
}
}
$pattern = '/