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