| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikBooking |
| 4 |
* @subpackage com_vikbooking |
| 5 |
* @author Alessio Gaggii - e4j - Extensionsforjoomla.com |
| 6 |
* @copyright Copyright (C) 2018 e4j - Extensionsforjoomla.com. All rights reserved. |
| 7 |
* @license GNU General Public License version 2 or later; see LICENSE |
| 8 |
* @link https://vikwp.com |
| 9 |
*/ |
| 10 |
|
| 11 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 12 |
|
| 13 |
$vbo_tn = $this->vbo_tn; |
| 14 |
|
| 15 |
$vbo_app = VikBooking::getVboApplication(); |
| 16 |
$vbo_app->loadVisualEditorAssets(); |
| 17 |
|
| 18 |
$editor = JEditor::getInstance(JFactory::getApplication()->get('editor')); |
| 19 |
|
| 20 |
$langs = $vbo_tn->getLanguagesList(); |
| 21 |
$xml_tables = $vbo_tn->getTranslationTables(); |
| 22 |
$active_table = ''; |
| 23 |
$active_table_key = ''; |
| 24 |
|
| 25 |
// JS lang vars |
| 26 |
JText::script('VBO_COPY_ORIGINAL_TN'); |
| 27 |
JText::script('VCM_TRANSLATE'); |
| 28 |
|
| 29 |
if (!(count($langs) > 1)) { |
| 30 |
//Error: only one language is published. Translations are useless |
| 31 |
?> |
| 32 |
<p class="err"><?php echo JText::translate('VBTRANSLATIONERRONELANG'); ?></p> |
| 33 |
<form name="adminForm" id="adminForm" action="index.php" method="post"> |
| 34 |
<input type="hidden" name="task" value=""> |
| 35 |
<input type="hidden" name="option" value="com_vikbooking"> |
| 36 |
</form> |
| 37 |
<?php |
| 38 |
} elseif (!$xml_tables || strlen($vbo_tn->getError())) { |
| 39 |
//Error: XML file not readable or errors occurred |
| 40 |
?> |
| 41 |
<p class="err"><?php echo $vbo_tn->getError(); ?></p> |
| 42 |
<form name="adminForm" id="adminForm" action="index.php" method="post"> |
| 43 |
<input type="hidden" name="task" value=""> |
| 44 |
<input type="hidden" name="option" value="com_vikbooking"> |
| 45 |
</form> |
| 46 |
<?php |
| 47 |
} else { |
| 48 |
$cur_langtab = VikRequest::getString('vbo_lang', '', 'request'); |
| 49 |
$table = VikRequest::getString('vbo_table', '', 'request'); |
| 50 |
if (!empty($table)) { |
| 51 |
$table = $vbo_tn->replacePrefix($table); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Allows to filter/search translations by a key-search value. |
| 56 |
* |
| 57 |
* @since 1.16.6 (J) - 1.6.6 (WP) |
| 58 |
*/ |
| 59 |
$keysearch = VikRequest::getString('keysearch', '', 'request'); |
| 60 |
$vbo_tn->setKeySearch($keysearch); |
| 61 |
?> |
| 62 |
|
| 63 |
<form action="index.php?option=com_vikbooking&task=translations" method="post" onsubmit="return vboCheckChanges();"> |
| 64 |
<div style="width: 100%; display: inline-block;" class="btn-toolbar vbo-btn-toolbar" id="filter-bar"> |
| 65 |
<div class="btn-group pull-right"> |
| 66 |
<button class="btn" type="submit"><?php echo JText::translate('VBOGETTRANSLATIONS'); ?></button> |
| 67 |
</div> |
| 68 |
<div class="btn-group pull-right"> |
| 69 |
<select name="vbo_table"> |
| 70 |
<option value="">-----------</option> |
| 71 |
<?php |
| 72 |
foreach ($xml_tables as $key => $value) { |
| 73 |
$active_table = $vbo_tn->replacePrefix($key) == $table ? $value : $active_table; |
| 74 |
$active_table_key = $vbo_tn->replacePrefix($key) == $table ? $key : $active_table_key; |
| 75 |
?> |
| 76 |
<option value="<?php echo $key; ?>"<?php echo $vbo_tn->replacePrefix($key) == $table ? ' selected="selected"' : ''; ?>><?php echo $value; ?></option> |
| 77 |
<?php |
| 78 |
} |
| 79 |
?> |
| 80 |
</select> |
| 81 |
</div> |
| 82 |
<?php |
| 83 |
if (!empty($active_table_key)) { |
| 84 |
?> |
| 85 |
<div class="btn-group pull-left"> |
| 86 |
<input type="text" name="keysearch" value="<?php echo JHtml::fetch('esc_attr', $keysearch); ?>" placeholder="<?php echo JHtml::fetch('esc_attr', JText::translate('VBODASHSEARCHKEYS')); ?>..." /> |
| 87 |
</div> |
| 88 |
<?php |
| 89 |
} |
| 90 |
?> |
| 91 |
</div> |
| 92 |
<input type="hidden" name="vbo_lang" class="vbo_lang" value="<?php echo $vbo_tn->default_lang; ?>"> |
| 93 |
<input type="hidden" name="option" value="com_vikbooking" /> |
| 94 |
<input type="hidden" name="task" value="translations" /> |
| 95 |
</form> |
| 96 |
<form name="adminForm" id="adminForm" action="index.php" method="post"> |
| 97 |
<div class="vbo-translation-langtabs"> |
| 98 |
<?php |
| 99 |
foreach ($langs as $ltag => $lang) { |
| 100 |
$is_def = ($ltag == $vbo_tn->default_lang); |
| 101 |
$lcountry = substr($ltag, 0, 2); |
| 102 |
$flag = ''; |
| 103 |
if (VBOPlatformDetection::isJoomla() && is_file(JPATH_SITE . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'mod_languages' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . $lcountry . '.gif')) { |
| 104 |
$flag = '<img src="' . JUri::root() . 'media/mod_languages/images/' . $lcountry . '.gif"/>'; |
| 105 |
} |
| 106 |
?><div class="vbo-translation-tab<?php echo $is_def ? ' vbo-translation-tab-default' : ''; ?>" data-vbolang="<?php echo $ltag; ?>"> |
| 107 |
<?php |
| 108 |
if (!empty($flag)) { |
| 109 |
?> |
| 110 |
<span class="vbo-translation-flag"><?php echo $flag; ?></span> |
| 111 |
<?php |
| 112 |
} |
| 113 |
?> |
| 114 |
<span class="vbo-translation-langname"><?php echo $lang['name']; ?></span> |
| 115 |
</div><?php |
| 116 |
} |
| 117 |
|
| 118 |
if (VBOPlatformDetection::isJoomla()) { |
| 119 |
?> |
| 120 |
<div class="vbo-translation-tab vbo-translation-tab-ini" data-vbolang=""> |
| 121 |
<span class="vbo-translation-iniflag">.INI</span> |
| 122 |
<span class="vbo-translation-langname"><?php echo JText::translate('VBTRANSLATIONINISTATUS'); ?></span> |
| 123 |
</div> |
| 124 |
<?php |
| 125 |
} |
| 126 |
?> |
| 127 |
</div> |
| 128 |
<div class="vbo-translation-tabscontents"> |
| 129 |
<?php |
| 130 |
$table_cols = !empty($active_table_key) ? $vbo_tn->getTableColumns($active_table_key) : []; |
| 131 |
$table_def_dbvals = !empty($active_table_key) ? $vbo_tn->getTableDefaultDbValues($active_table_key, array_keys($table_cols)) : []; |
| 132 |
if (!empty($active_table_key)) { |
| 133 |
echo '<input type="hidden" name="vbo_table" value="'.$active_table_key.'"/>'."\n"; |
| 134 |
if (!empty($keysearch)) { |
| 135 |
echo '<input type="hidden" name="keysearch" value="' . JHtml::fetch('esc_attr', $keysearch) . '"/>'."\n"; |
| 136 |
} |
| 137 |
} |
| 138 |
foreach ($langs as $ltag => $lang) { |
| 139 |
$is_def = ($ltag == $vbo_tn->default_lang); |
| 140 |
?> |
| 141 |
<div class="vbo-translation-langcontent" style="display: <?php echo $is_def ? 'block' : 'none'; ?>;" id="vbo_langcontent_<?php echo $ltag; ?>"> |
| 142 |
<?php |
| 143 |
if (empty($active_table_key)) { |
| 144 |
?> |
| 145 |
<p class="warn"><?php echo JText::translate('VBTRANSLATIONSELTABLEMESS'); ?></p> |
| 146 |
<?php |
| 147 |
} elseif (strlen($vbo_tn->getError()) > 0) { |
| 148 |
?> |
| 149 |
<p class="err"><?php echo $vbo_tn->getError(); ?></p> |
| 150 |
<?php |
| 151 |
} else { |
| 152 |
?> |
| 153 |
<fieldset class="adminform"> |
| 154 |
<legend class="adminlegend"><?php echo $active_table; ?> - <?php echo $lang['name'].($is_def ? ' - '.JText::translate('VBTRANSLATIONDEFLANG') : ''); ?></legend> |
| 155 |
<div class="vbo-translations-tab-container"> |
| 156 |
<?php |
| 157 |
if ($is_def) { |
| 158 |
// values of Default Language to be translated |
| 159 |
foreach ($table_def_dbvals as $reference_id => $values) { |
| 160 |
?> |
| 161 |
<div class="vbo-translations-default-element"> |
| 162 |
<div class="vbo-translations-element-title" data-reference="<?php echo $ltag.'-'.$reference_id; ?>"> |
| 163 |
<div class="vbo-translate-element-cell"><?php echo $vbo_tn->getRecordReferenceName($table_cols, $values); ?></div> |
| 164 |
</div> |
| 165 |
<div class="vbo-translations-element-contents"> |
| 166 |
<?php |
| 167 |
foreach ($values as $field => $def_value) { |
| 168 |
$title = $table_cols[$field]['jlang']; |
| 169 |
$type = $table_cols[$field]['type']; |
| 170 |
if ($type == 'html') { |
| 171 |
$def_value = VBOPlatformDetection::isWordPress() ? wpautop($def_value) : $def_value; |
| 172 |
} |
| 173 |
?> |
| 174 |
<div class="vbo-translations-element-row" data-reference="<?php echo $ltag.'-'.$reference_id; ?>"> |
| 175 |
<div class="vbo-translations-element-lbl"><?php echo $title; ?></div> |
| 176 |
<div class="vbo-translations-element-val" data-origvalue="<?php echo $reference_id . '-' . $field; ?>"><?php echo $type != 'json' ? $def_value : ''; ?></div> |
| 177 |
</div> |
| 178 |
<?php |
| 179 |
if ($type == 'json') { |
| 180 |
$tn_keys = $table_cols[$field]['keys']; |
| 181 |
$keys = !empty($tn_keys) ? explode(',', $tn_keys) : []; |
| 182 |
$json_def_values = json_decode($def_value, true); |
| 183 |
if ($json_def_values) { |
| 184 |
foreach ($json_def_values as $jkey => $jval) { |
| 185 |
if ((!in_array($jkey, $keys) && count($keys) > 0) || empty($jval)) { |
| 186 |
continue; |
| 187 |
} |
| 188 |
$json_lbl = ' '; |
| 189 |
if (!is_numeric($jkey)) { |
| 190 |
$guess_lbl = JText::translate('VBO_' . strtoupper($jkey)); |
| 191 |
$json_lbl = $guess_lbl != 'VBO_' . strtoupper($jkey) ? $guess_lbl : ucwords($jkey); |
| 192 |
} |
| 193 |
?> |
| 194 |
<div class="vbo-translations-element-row vbo-translations-element-row-nested" data-reference="<?php echo $ltag.'-'.$reference_id; ?>"> |
| 195 |
<div class="vbo-translations-element-lbl"><?php echo $json_lbl; ?></div> |
| 196 |
<div class="vbo-translations-element-val" data-origvalue="<?php echo $reference_id . '-' . $field . '-' . $jkey; ?>"><?php echo $jval; ?></div> |
| 197 |
</div> |
| 198 |
<?php |
| 199 |
} |
| 200 |
} |
| 201 |
} |
| 202 |
?> |
| 203 |
<?php |
| 204 |
} |
| 205 |
?> |
| 206 |
</div> |
| 207 |
</div> |
| 208 |
<?php |
| 209 |
} |
| 210 |
} else { |
| 211 |
// translation fields for this language |
| 212 |
$lang_record_tn = $vbo_tn->getTranslatedTable($active_table_key, $ltag); |
| 213 |
foreach ($table_def_dbvals as $reference_id => $values) { |
| 214 |
?> |
| 215 |
<div class="vbo-translations-language-element"> |
| 216 |
<div class="vbo-translations-element-title" data-reference="<?php echo $ltag.'-'.$reference_id; ?>"> |
| 217 |
<div class="vbo-translate-element-cell"><?php echo $vbo_tn->getRecordReferenceName($table_cols, $values); ?></div> |
| 218 |
</div> |
| 219 |
<div class="vbo-translations-element-contents"> |
| 220 |
<?php |
| 221 |
foreach ($values as $field => $def_value) { |
| 222 |
$title = $table_cols[$field]['jlang']; |
| 223 |
$type = $table_cols[$field]['type']; |
| 224 |
if ($type == 'skip') { |
| 225 |
continue; |
| 226 |
} |
| 227 |
$tn_value = ''; |
| 228 |
$tn_class = ' vbo-missing-translation'; |
| 229 |
if (!isset($lang_record_tn[$reference_id])) { |
| 230 |
$lang_record_tn[$reference_id] = []; |
| 231 |
} |
| 232 |
if (array_key_exists($reference_id, ($lang_record_tn ?? [])) && array_key_exists($field, ($lang_record_tn[$reference_id]['content'] ?? [])) && strlen($lang_record_tn[$reference_id]['content'][$field])) { |
| 233 |
if (in_array($type, array('text', 'textarea', 'html'))) { |
| 234 |
$tn_class = ' vbo-field-translated'; |
| 235 |
} else { |
| 236 |
$tn_class = ''; |
| 237 |
} |
| 238 |
} |
| 239 |
?> |
| 240 |
<div class="vbo-translations-element-row<?php echo $tn_class; ?>" data-reference="<?php echo $ltag.'-'.$reference_id; ?>" data-copyoriginal="<?php echo $reference_id . '-' . $field; ?>"> |
| 241 |
<div class="vbo-translations-element-lbl"><?php echo $title; ?></div> |
| 242 |
<div class="vbo-translations-element-val"> |
| 243 |
<?php |
| 244 |
if ($type == 'text') { |
| 245 |
if (array_key_exists($reference_id, $lang_record_tn) && array_key_exists($field, ($lang_record_tn[$reference_id]['content'] ?? []))) { |
| 246 |
$tn_value = $lang_record_tn[$reference_id]['content'][$field]; |
| 247 |
} |
| 248 |
?> |
| 249 |
<input type="text" name="tn[<?php echo $ltag; ?>][<?php echo $reference_id; ?>][<?php echo $field; ?>]" value="<?php echo htmlspecialchars($tn_value); ?>" size="40" placeholder="<?php echo htmlspecialchars($def_value); ?>"/> |
| 250 |
<?php |
| 251 |
} elseif ($type == 'textarea') { |
| 252 |
if (array_key_exists($reference_id, $lang_record_tn) && array_key_exists($field, ($lang_record_tn[$reference_id]['content'] ?? []))) { |
| 253 |
$tn_value = $lang_record_tn[$reference_id]['content'][$field]; |
| 254 |
} |
| 255 |
?> |
| 256 |
<textarea name="tn[<?php echo $ltag; ?>][<?php echo $reference_id; ?>][<?php echo $field; ?>]" rows="7" cols="170" placeholder="<?php echo htmlspecialchars($def_value); ?>"><?php echo $tn_value; ?></textarea> |
| 257 |
<?php |
| 258 |
} elseif ($type == 'html') { |
| 259 |
if (array_key_exists($reference_id, $lang_record_tn) && array_key_exists($field, ($lang_record_tn[$reference_id]['content'] ?? []))) { |
| 260 |
$tn_value = $lang_record_tn[$reference_id]['content'][$field]; |
| 261 |
} |
| 262 |
if (VBOPlatformDetection::isWordPress() && interface_exists('Throwable')) { |
| 263 |
/** |
| 264 |
* With PHP >= 7 supporting throwable exceptions for Fatal Errors |
| 265 |
* we try to avoid issues with third party plugins that make use |
| 266 |
* of the WP native function get_current_screen(). |
| 267 |
* |
| 268 |
* @wponly |
| 269 |
*/ |
| 270 |
try { |
| 271 |
echo $editor->display( "tn[".$ltag."][".$reference_id."][".$field."]", $tn_value, '100%', 350, 70, 20, true, "tn_".$ltag."_".$reference_id."_".$field ); |
| 272 |
} catch (Throwable $t) { |
| 273 |
echo $t->getMessage() . ' in ' . $t->getFile() . ':' . $t->getLine() . '<br/>'; |
| 274 |
} |
| 275 |
} else { |
| 276 |
// we cannot catch Fatal Errors in PHP 5.x |
| 277 |
echo $editor->display( "tn[".$ltag."][".$reference_id."][".$field."]", $tn_value, '100%', 350, 70, 20, true, "tn_".$ltag."_".$reference_id."_".$field ); |
| 278 |
} |
| 279 |
} |
| 280 |
?> |
| 281 |
</div> |
| 282 |
</div> |
| 283 |
<?php |
| 284 |
if ($type == 'json') { |
| 285 |
$tn_keys = $table_cols[$field]['keys']; |
| 286 |
$keys = !empty($tn_keys) ? explode(',', $tn_keys) : []; |
| 287 |
$json_def_values = json_decode($def_value, true); |
| 288 |
if ($json_def_values) { |
| 289 |
$tn_json_value = []; |
| 290 |
if (array_key_exists($reference_id, $lang_record_tn) && array_key_exists($field, ($lang_record_tn[$reference_id]['content'] ?? []))) { |
| 291 |
$tn_json_value = json_decode($lang_record_tn[$reference_id]['content'][$field], true); |
| 292 |
} |
| 293 |
foreach ($json_def_values as $jkey => $jval) { |
| 294 |
if ((!in_array($jkey, $keys) && count($keys) > 0) || empty($jval)) { |
| 295 |
continue; |
| 296 |
} |
| 297 |
$json_lbl = ' '; |
| 298 |
if (!is_numeric($jkey)) { |
| 299 |
$guess_lbl = JText::translate('VBO_' . strtoupper($jkey)); |
| 300 |
$json_lbl = $guess_lbl != 'VBO_' . strtoupper($jkey) ? $guess_lbl : ucwords($jkey); |
| 301 |
} |
| 302 |
?> |
| 303 |
<div class="vbo-translations-element-row vbo-translations-element-row-nested" data-reference="<?php echo $ltag.'-'.$reference_id; ?>" data-copyoriginal="<?php echo $reference_id . '-' . $field . '-' . $jkey; ?>"> |
| 304 |
<div class="vbo-translations-element-lbl"><?php echo $json_lbl; ?></div> |
| 305 |
<div class="vbo-translations-element-val"> |
| 306 |
<?php |
| 307 |
if (strlen($jval) > 40) { |
| 308 |
// check if this translation field requires the rich text visual editor |
| 309 |
if ($jkey == 'tpl_text' && strpos($jval, '<') !== false) { |
| 310 |
// the original field contains HTML code built through the visual editor |
| 311 |
$veditor_name = 'tn[' . $ltag . '][' . $reference_id . '][' . $field . '][' . $jkey . ']'; |
| 312 |
$veditor_id = 'tn_' . $ltag . '_' . $reference_id . '_' . $field . '_' . $jkey; |
| 313 |
$tarea_attr = array( |
| 314 |
'id' => $veditor_id, |
| 315 |
'rows' => '7', |
| 316 |
'cols' => '170', |
| 317 |
'style' => 'min-width: 60%;', |
| 318 |
); |
| 319 |
$editor_opts = array( |
| 320 |
'modes' => array( |
| 321 |
'visual', |
| 322 |
'text', |
| 323 |
), |
| 324 |
); |
| 325 |
echo $vbo_app->renderVisualEditor($veditor_name, (isset($tn_json_value[$jkey]) ? $tn_json_value[$jkey] : ''), $tarea_attr, $editor_opts); |
| 326 |
} else { |
| 327 |
?> |
| 328 |
<textarea rows="7" cols="170" style="min-width: 60%;" name="tn[<?php echo $ltag; ?>][<?php echo $reference_id; ?>][<?php echo $field; ?>][<?php echo $jkey; ?>]"><?php echo isset($tn_json_value[$jkey]) ? $tn_json_value[$jkey] : ''; ?></textarea> |
| 329 |
<?php |
| 330 |
} |
| 331 |
} else { |
| 332 |
?> |
| 333 |
<input type="text" name="tn[<?php echo $ltag; ?>][<?php echo $reference_id; ?>][<?php echo $field; ?>][<?php echo $jkey; ?>]" value="<?php echo isset($tn_json_value[$jkey]) ? $tn_json_value[$jkey] : ''; ?>" size="40" placeholder="<?php echo htmlspecialchars($jval); ?>"/> |
| 334 |
<?php |
| 335 |
} |
| 336 |
?> |
| 337 |
</div> |
| 338 |
</div> |
| 339 |
<?php |
| 340 |
} |
| 341 |
} |
| 342 |
} |
| 343 |
} |
| 344 |
?> |
| 345 |
</div> |
| 346 |
</div> |
| 347 |
<?php |
| 348 |
} |
| 349 |
} |
| 350 |
?> |
| 351 |
</div> |
| 352 |
</fieldset> |
| 353 |
<?php |
| 354 |
} |
| 355 |
?> |
| 356 |
</div> |
| 357 |
<?php |
| 358 |
} |
| 359 |
|
| 360 |
// ini files status |
| 361 |
if (VBOPlatformDetection::isJoomla()) { |
| 362 |
$all_inis = $vbo_tn->getIniFiles(); |
| 363 |
?> |
| 364 |
<div class="vbo-translation-langcontent" style="display: none;" id="vbo_langcontent_ini"> |
| 365 |
<fieldset class="adminform"> |
| 366 |
<legend class="adminlegend">.INI <?php echo JText::translate('VBTRANSLATIONINISTATUS'); ?></legend> |
| 367 |
<div class="vbo-translations-tab-container"> |
| 368 |
<?php |
| 369 |
foreach ($all_inis as $initype => $inidet) { |
| 370 |
$inipath = $inidet['path']; |
| 371 |
?> |
| 372 |
<div class="vbo-translations-ini-element"> |
| 373 |
<div class="vbo-translations-element-title"> |
| 374 |
<div class="vbo-translate-element-cell"><?php echo JText::translate('VBINIEXPL'.strtoupper($initype)); ?></div> |
| 375 |
</div> |
| 376 |
<div class="vbo-translations-element-contents"> |
| 377 |
<?php |
| 378 |
foreach ($langs as $ltag => $lang) { |
| 379 |
$t_file_exists = file_exists(str_replace('en-GB', $ltag, $inipath)); |
| 380 |
$t_parsed_ini = $t_file_exists ? parse_ini_file(str_replace('en-GB', $ltag, $inipath)) : false; |
| 381 |
?> |
| 382 |
<div class="vbo-translations-element-row <?php echo $t_file_exists ? 'vbo-field-translated' : 'vbo-missing-translation'; ?>"> |
| 383 |
<div class="vbo-translations-element-lbl"><?php echo ($ltag == 'en-GB' ? 'Native ' : '').$lang['name']; ?></div> |
| 384 |
<div class="vbo-translations-element-val"> |
| 385 |
<span class="vbo-inifile-totrows <?php echo $t_file_exists ? 'vbo-inifile-exists' : 'vbo-inifile-notfound'; ?>"><?php echo $t_file_exists && $t_parsed_ini !== false ? JText::translate('VBOINIDEFINITIONS').': '.count($t_parsed_ini) : JText::translate('VBOINIMISSINGFILE'); ?></span> |
| 386 |
<span class="vbo-inifile-path <?php echo $t_file_exists ? 'vbo-inifile-exists' : 'vbo-inifile-notfound'; ?>"><?php echo JText::translate('VBOINIPATH').': '.str_replace('en-GB', $ltag, $inipath); ?></span> |
| 387 |
</div> |
| 388 |
</div> |
| 389 |
<?php |
| 390 |
} |
| 391 |
?> |
| 392 |
</div> |
| 393 |
</div> |
| 394 |
<?php |
| 395 |
} |
| 396 |
?> |
| 397 |
</div> |
| 398 |
</fieldset> |
| 399 |
</div> |
| 400 |
<?php |
| 401 |
// end ini files status |
| 402 |
} |
| 403 |
?> |
| 404 |
</div> |
| 405 |
<input type="hidden" name="vbo_lang" class="vbo_lang" value="<?php echo $vbo_tn->default_lang; ?>"> |
| 406 |
<input type="hidden" name="task" value="translations"> |
| 407 |
<input type="hidden" name="option" value="com_vikbooking"> |
| 408 |
<?php echo JHtml::fetch('form.token'); ?> |
| 409 |
|
| 410 |
<div class="vbo-translations-lim-wrap"> |
| 411 |
<table align="center"> |
| 412 |
<tr> |
| 413 |
<td align="center"><?php echo $vbo_tn->getPagination(); ?></td> |
| 414 |
</tr> |
| 415 |
<tr> |
| 416 |
<td align="center"> |
| 417 |
<select name="limit" onchange="vboHandleCustomLimit(this.value);"> |
| 418 |
<option value="2"<?php echo $vbo_tn->lim == 2 ? ' selected="selected"' : ''; ?>>2</option> |
| 419 |
<option value="5"<?php echo $vbo_tn->lim == 5 ? ' selected="selected"' : ''; ?>>5</option> |
| 420 |
<option value="10"<?php echo $vbo_tn->lim == 10 ? ' selected="selected"' : ''; ?>>10</option> |
| 421 |
<option value="20"<?php echo $vbo_tn->lim == 20 ? ' selected="selected"' : ''; ?>>20</option> |
| 422 |
</select> |
| 423 |
</td> |
| 424 |
</tr> |
| 425 |
</table> |
| 426 |
</div> |
| 427 |
</form> |
| 428 |
|
| 429 |
<script type="text/Javascript"> |
| 430 |
var vbo_tn_changes = false; |
| 431 |
var vbo_copy_delay = 500; |
| 432 |
var vbo_copy_timeout = null; |
| 433 |
|
| 434 |
function vboHandleCustomLimit(lim) { |
| 435 |
var cur_limstart = document.adminForm.limitstart; |
| 436 |
if (typeof cur_limstart === 'undefined') { |
| 437 |
// append hidden input field to form |
| 438 |
var limstart_node = document.createElement('INPUT'); |
| 439 |
limstart_node.setAttribute('type', 'hidden'); |
| 440 |
limstart_node.setAttribute('name', 'limitstart'); |
| 441 |
limstart_node.setAttribute('value', '0'); |
| 442 |
document.adminForm.appendChild(limstart_node); |
| 443 |
} else { |
| 444 |
// update existing value |
| 445 |
document.adminForm.limitstart.value = '0'; |
| 446 |
} |
| 447 |
// submit form |
| 448 |
document.adminForm.submit(); |
| 449 |
} |
| 450 |
|
| 451 |
function vboCheckChanges() { |
| 452 |
if (!vbo_tn_changes) { |
| 453 |
return true; |
| 454 |
} |
| 455 |
return confirm("<?php echo addslashes(JText::translate('VBTANSLATIONSCHANGESCONF')); ?>"); |
| 456 |
} |
| 457 |
|
| 458 |
function vboHoverCopyTranslation(elem) { |
| 459 |
if (!elem) { |
| 460 |
return false; |
| 461 |
} |
| 462 |
var copy_reference = elem.attr('data-copyoriginal'); |
| 463 |
if (!copy_reference) { |
| 464 |
return false; |
| 465 |
} |
| 466 |
var orig_elem = jQuery('.vbo-translations-element-val[data-origvalue="' + copy_reference + '"]'); |
| 467 |
if (!orig_elem || !orig_elem.length || !orig_elem.html().length) { |
| 468 |
return false; |
| 469 |
} |
| 470 |
|
| 471 |
const label = elem.find('.vbo-translations-element-lbl'); |
| 472 |
|
| 473 |
// translation actions wrapper |
| 474 |
const txActions = jQuery('<div class="vbo-tn-actions"></div>'); |
| 475 |
|
| 476 |
let tn_field_val; |
| 477 |
|
| 478 |
try { |
| 479 |
let lang_reference_arr = elem.closest('.vbo-translations-element-row[data-copyoriginal]').attr('data-reference').split('-'); |
| 480 |
lang_reference_arr.splice(lang_reference_arr.length - 1, 1); |
| 481 |
let wysiwyg_hipo_id = 'tn_' + (lang_reference_arr.join('-') + '-' + copy_reference).replace(/-/g, '_'); |
| 482 |
|
| 483 |
tn_field_val = Joomla.editors.instances[wysiwyg_hipo_id].getValue(); |
| 484 |
} catch (err) { |
| 485 |
// fallback to default input/textarea |
| 486 |
tn_field_val = elem.find('.vbo-translations-element-val').find('input[type="text"],textarea').val(); |
| 487 |
} |
| 488 |
|
| 489 |
// check if translation field has got a value |
| 490 |
if (!(tn_field_val || '').trim()) { |
| 491 |
// add button to copy the original translation |
| 492 |
txActions.append( |
| 493 |
jQuery('<span class="tn-copy-original vbo-tooltip vbo-tooltip-bottom" onclick="vboApplyCopyTranslation(this)"></span>') |
| 494 |
.attr('data-tooltiptext', Joomla.JText._('VBO_COPY_ORIGINAL_TN')) |
| 495 |
.html('<?php VikBookingIcons::e('copy'); ?>') |
| 496 |
); |
| 497 |
|
| 498 |
// check whether the channel manager is installed |
| 499 |
if (<?php echo (int) class_exists('VikChannelManager'); ?>) { |
| 500 |
// add button to translate the original text |
| 501 |
txActions.append( |
| 502 |
jQuery('<span class="tn-translate-original vbo-tooltip vbo-tooltip-bottom" onclick="vboTranslateOriginal(this)"></span>') |
| 503 |
.attr('data-tooltiptext', Joomla.JText._('VCM_TRANSLATE')) |
| 504 |
.html('<?php VikBookingIcons::e('language'); ?>') |
| 505 |
); |
| 506 |
} |
| 507 |
|
| 508 |
// append the actions below the label |
| 509 |
label.append(txActions); |
| 510 |
} |
| 511 |
} |
| 512 |
|
| 513 |
async function vboApplyCopyTranslation(elem) { |
| 514 |
let orig_elem = null; |
| 515 |
|
| 516 |
try { |
| 517 |
orig_elem = await vboGetOriginalTranslationElement(elem); |
| 518 |
} catch (error) { |
| 519 |
return false; |
| 520 |
} |
| 521 |
|
| 522 |
vboSetTranslation(jQuery(elem).closest('.vbo-translations-element-row[data-copyoriginal]'), orig_elem.html()); |
| 523 |
|
| 524 |
// make sure to remove any copy-from-original button |
| 525 |
// jQuery('.vbo-tn-actions').remove(); |
| 526 |
} |
| 527 |
|
| 528 |
function vboGetOriginalTranslationElement(elem) { |
| 529 |
return new Promise((resolve, reject) => { |
| 530 |
elem = jQuery(elem).closest('.vbo-translations-element-row[data-copyoriginal]'); |
| 531 |
|
| 532 |
if (!elem || !elem.length) { |
| 533 |
reject(new Error('Copiable record not found')); |
| 534 |
return false; |
| 535 |
} |
| 536 |
|
| 537 |
const copy_reference = elem.attr('data-copyoriginal'); |
| 538 |
if (!copy_reference) { |
| 539 |
reject(new Error('Reference dara attribute not found')); |
| 540 |
return false; |
| 541 |
} |
| 542 |
|
| 543 |
const orig_elem = jQuery('.vbo-translations-element-val[data-origvalue="' + copy_reference + '"]'); |
| 544 |
if (!orig_elem || !orig_elem.length) { |
| 545 |
reject(new Error('Missing original value')); |
| 546 |
return false; |
| 547 |
} |
| 548 |
|
| 549 |
resolve(orig_elem); |
| 550 |
}); |
| 551 |
} |
| 552 |
|
| 553 |
function vboSetTranslation(elem, translation) { |
| 554 |
const copy_reference = elem.attr('data-copyoriginal'); |
| 555 |
|
| 556 |
try { |
| 557 |
// grab lang tag, which could be part of the ID of a WYSIWYG editor |
| 558 |
let lang_reference_arr = elem.attr('data-reference').split('-'); |
| 559 |
lang_reference_arr.splice((lang_reference_arr.length - 1), 1); |
| 560 |
let wysiwyg_hipo_id = 'tn_' + (lang_reference_arr.join('-') + '-' + copy_reference).replace(/-/g, '_'); |
| 561 |
|
| 562 |
// attempt to inject value inside wysiwyg editor |
| 563 |
Joomla.editors.instances[wysiwyg_hipo_id].setValue(translation); |
| 564 |
} catch(e) { |
| 565 |
// fallback to standard input/textarea |
| 566 |
const input = elem.find('.vbo-translations-element-val').find('input[type="text"]'); |
| 567 |
if (input && input.length) { |
| 568 |
input.val(translation).trigger('change'); |
| 569 |
} |
| 570 |
|
| 571 |
const textarea = elem.find('.vbo-translations-element-val').find('textarea'); |
| 572 |
if (textarea && textarea.length) { |
| 573 |
textarea.val(translation).trigger('change'); |
| 574 |
} |
| 575 |
} |
| 576 |
} |
| 577 |
|
| 578 |
async function vboTranslateOriginal(elem) { |
| 579 |
if (jQuery(elem).prop('aria-disabled') == true) { |
| 580 |
return false; |
| 581 |
} |
| 582 |
|
| 583 |
let orig_elem = null; |
| 584 |
|
| 585 |
try { |
| 586 |
orig_elem = await vboGetOriginalTranslationElement(elem); |
| 587 |
} catch (error) { |
| 588 |
return false; |
| 589 |
} |
| 590 |
|
| 591 |
const originalRow = jQuery(elem).closest('.vbo-translations-element-row[data-copyoriginal]'); |
| 592 |
|
| 593 |
const locale = originalRow.attr('data-reference').split('-').slice(0, -1).join('-'); |
| 594 |
|
| 595 |
jQuery(elem).prop('aria-disabled', true); |
| 596 |
jQuery(elem).find('i').attr('class', '<?php echo VikBookingIcons::i('spinner', 'fa-spin'); ?>'); |
| 597 |
|
| 598 |
VBOCore.doAjax( |
| 599 |
'<?php echo VikBooking::ajaxUrl('index.php?option=com_vikchannelmanager&task=ai.translate'); ?>', |
| 600 |
{ |
| 601 |
text: orig_elem.html(), |
| 602 |
locale: locale, |
| 603 |
}, |
| 604 |
(response) => { |
| 605 |
vboSetTranslation(originalRow, response.translated); |
| 606 |
jQuery(elem).hide(); |
| 607 |
}, |
| 608 |
(error) => { |
| 609 |
alert(error.responseText || error.statusText || 'An error has occurred.'); |
| 610 |
jQuery(elem).find('i').attr('class', '<?php echo VikBookingIcons::i('language'); ?>'); |
| 611 |
jQuery(elem).prop('aria-disabled', false); |
| 612 |
} |
| 613 |
); |
| 614 |
} |
| 615 |
|
| 616 |
jQuery(function() { |
| 617 |
|
| 618 |
jQuery('.vbo-translation-tab').click(function() { |
| 619 |
var langtag = jQuery(this).attr('data-vbolang'); |
| 620 |
if (jQuery('#vbo_langcontent_'+langtag).length) { |
| 621 |
jQuery('.vbo_lang').val(langtag); |
| 622 |
jQuery('.vbo-translation-tab').removeClass('vbo-translation-tab-default'); |
| 623 |
jQuery(this).addClass('vbo-translation-tab-default'); |
| 624 |
jQuery('.vbo-translation-langcontent').hide(); |
| 625 |
jQuery('#vbo_langcontent_'+langtag).fadeIn(); |
| 626 |
} else { |
| 627 |
jQuery('.vbo-translation-tab').removeClass('vbo-translation-tab-default'); |
| 628 |
jQuery(this).addClass('vbo-translation-tab-default'); |
| 629 |
jQuery('.vbo-translation-langcontent').hide(); |
| 630 |
jQuery('#vbo_langcontent_ini').fadeIn(); |
| 631 |
} |
| 632 |
}); |
| 633 |
|
| 634 |
jQuery('#adminForm input[type=text], #adminForm textarea').change(function() { |
| 635 |
vbo_tn_changes = true; |
| 636 |
}); |
| 637 |
|
| 638 |
jQuery('.vbo-translations-element-row[data-copyoriginal]').hover(function() { |
| 639 |
var elem = jQuery(this); |
| 640 |
vbo_copy_timeout = setTimeout(function() { |
| 641 |
vboHoverCopyTranslation(elem); |
| 642 |
}, vbo_copy_delay); |
| 643 |
}, function() { |
| 644 |
// cancel scheduled hovering function |
| 645 |
clearTimeout(vbo_copy_timeout); |
| 646 |
// make sure to remove any copy-from-original button |
| 647 |
jQuery('.vbo-tn-actions').remove(); |
| 648 |
}); |
| 649 |
<?php |
| 650 |
if (!empty($cur_langtab)) { |
| 651 |
?> |
| 652 |
jQuery('.vbo-translation-tab').each(function() { |
| 653 |
var langtag = jQuery(this).attr('data-vbolang'); |
| 654 |
if (langtag != '<?php echo $cur_langtab; ?>') { |
| 655 |
return true; |
| 656 |
} |
| 657 |
if (jQuery('#vbo_langcontent_'+langtag).length) { |
| 658 |
jQuery('.vbo_lang').val(langtag); |
| 659 |
jQuery('.vbo-translation-tab').removeClass('vbo-translation-tab-default'); |
| 660 |
jQuery(this).addClass('vbo-translation-tab-default'); |
| 661 |
jQuery('.vbo-translation-langcontent').hide(); |
| 662 |
jQuery('#vbo_langcontent_'+langtag).fadeIn(); |
| 663 |
} |
| 664 |
}); |
| 665 |
<?php |
| 666 |
} |
| 667 |
?> |
| 668 |
}); |
| 669 |
</script> |
| 670 |
<?php |
| 671 |
} |
| 672 |
|