| 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 |
/** |
| 14 |
* Determine whether we are rendering the template through AJAX. |
| 15 |
* |
| 16 |
* @since 1.17.6 (J) - 1.7.6 (WP) |
| 17 |
*/ |
| 18 |
$is_ajax = JFactory::getApplication()->input->getBool('ajax', false); |
| 19 |
|
| 20 |
$editor = JEditor::getInstance('codemirror'); |
| 21 |
$fcode = ''; |
| 22 |
$fp = !empty($this->fpath) ? fopen($this->fpath, "rb") : false; |
| 23 |
if (empty($this->fpath) || $fp === false) { |
| 24 |
?> |
| 25 |
<p class="err"><?php echo JText::translate('VBOTMPLFILENOTREAD'); ?></p> |
| 26 |
<?php |
| 27 |
} else { |
| 28 |
// read file bytes in chunks |
| 29 |
while (!feof($fp)) { |
| 30 |
$fcode .= fread($fp, 8192); |
| 31 |
} |
| 32 |
fclose($fp); |
| 33 |
|
| 34 |
if ($is_ajax) { |
| 35 |
?> |
| 36 |
<p class="vbo-path-tmpl-file no-margin-top"><?php echo $this->fpath; ?></p> |
| 37 |
<div class="vbo-codemirror-modal-container"> |
| 38 |
<?php |
| 39 |
/** |
| 40 |
* With PHP >= 7 supporting throwable exceptions for Fatal Errors |
| 41 |
* we try to avoid issues with third party plugins that make use |
| 42 |
* of the WP native function get_current_screen(). |
| 43 |
*/ |
| 44 |
try { |
| 45 |
echo $editor->display("cont", $fcode, '100%', 300, 70, 20, $buttons = false, $id = "vik_editor_cont", $asset = null, $author = null, $params = ['syntax' => 'php']); |
| 46 |
} catch (Throwable $t) { |
| 47 |
echo $t->getMessage() . ' in ' . $t->getFile() . ':' . $t->getLine() . '<br/>'; |
| 48 |
} |
| 49 |
?> |
| 50 |
</div> |
| 51 |
<?php |
| 52 |
} else { |
| 53 |
// regular rendering |
| 54 |
?> |
| 55 |
<form name="adminForm" id="adminForm" action="index.php" method="post"> |
| 56 |
<fieldset class="adminform"> |
| 57 |
<legend class="adminlegend"><?php echo JText::translate('VBOEDITTMPLFILE'); ?></legend> |
| 58 |
<p class="vbo-path-tmpl-file"><?php echo $this->fpath; ?></p> |
| 59 |
<?php |
| 60 |
/** |
| 61 |
* With PHP >= 7 supporting throwable exceptions for Fatal Errors |
| 62 |
* we try to avoid issues with third party plugins that make use |
| 63 |
* of the WP native function get_current_screen(). |
| 64 |
*/ |
| 65 |
try { |
| 66 |
echo $editor->display("cont", $fcode, '100%', 300, 70, 20, $buttons = false, $id = "vik_editor_cont", $asset = null, $author = null, $params = ['syntax' => 'php']); |
| 67 |
} catch (Throwable $t) { |
| 68 |
echo $t->getMessage() . ' in ' . $t->getFile() . ':' . $t->getLine() . '<br/>'; |
| 69 |
} |
| 70 |
?> |
| 71 |
<br clear="all" /> |
| 72 |
<p style="text-align: center;"> |
| 73 |
<button type="button" class="btn btn-success" onclick="vboSubmitTmplFile(this);"><?php echo JText::translate('VBOSAVETMPLFILE'); ?></button> |
| 74 |
</p> |
| 75 |
</fieldset> |
| 76 |
<input type="hidden" name="path" value="<?php echo $this->escape($this->fpath); ?>"> |
| 77 |
<input type="hidden" name="option" value="com_vikbooking" /> |
| 78 |
<input type="hidden" name="task" value="savetmplfile" /> |
| 79 |
<?php echo JHtml::fetch('form.token'); ?> |
| 80 |
</form> |
| 81 |
|
| 82 |
<script type="text/javascript"> |
| 83 |
function vboSubmitTmplFile(elem) { |
| 84 |
/** |
| 85 |
* On some CMSs, the real textarea may not update with the new codemirror content |
| 86 |
* and so we force the update of the textarea before submitting the form. |
| 87 |
*/ |
| 88 |
try { |
| 89 |
Joomla.editors.instances['vik_editor_cont'].element.codemirror.save(); |
| 90 |
} catch (err) { |
| 91 |
console.error(err); |
| 92 |
} |
| 93 |
jQuery(elem).closest('form').submit(); |
| 94 |
} |
| 95 |
</script> |
| 96 |
<?php |
| 97 |
} |
| 98 |
} |
| 99 |
|