PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / layouts / form / fields / editor.php
vikappointments / admin / layouts / form / fields Last commit date
checkbox.php 2 days ago color.php 2 days ago date.php 2 days ago editor.php 2 days ago file.php 2 days ago hidden.php 2 days ago html.php 2 days ago index.html 2 days ago number.php 2 days ago password.php 2 days ago select.php 2 days ago separator.php 2 days ago tel.php 2 days ago text.php 2 days ago textarea.php 2 days ago
editor.php
121 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 $name = !empty($displayData['name']) ? $displayData['name'] : 'name';
15 $value = isset($displayData['value']) ? $displayData['value'] : '';
16 $type = isset($displayData['editor']) ? $displayData['editor'] : null;
17 $width = isset($displayData['width']) ? $displayData['width'] : '100%';
18 $height = isset($displayData['height']) ? $displayData['height'] : 550;
19 $rows = isset($displayData['rows']) ? $displayData['rows'] : 30;
20 $cols = isset($displayData['cols']) ? $displayData['cols'] : 30;
21 $buttons = isset($displayData['buttons']) ? $displayData['buttons'] : true;
22
23 $use_tags_highlighter = !empty($displayData['use_tags_highlighter']);
24
25 // get system editor (or the specified one)
26 $editor = VAPApplication::getInstance()->getEditor($type);
27
28 // in case of tags highlighter, wraps all the strings between the
29 // curly brackets into a span, so that it is possible to apply some
30 // custom styles at runtime
31 if ($use_tags_highlighter)
32 {
33 do
34 {
35 $prev = $value;
36
37 // get rid of the tag that is already highlighting the placeholders
38 $value = preg_replace_callback("/<span class=\"highlight-tag\">({[a-zA-Z0-9_]+})<\/span>/", function($match)
39 {
40 return $match[1];
41 }, $value);
42
43 // repeat as long as something is replaced
44 } while ($value != $prev);
45
46 // Rewrap the placeholders under the tag used to highlight them.
47 // Obtain only the placeholders that are contained within the body of a tag.
48 $value = preg_replace_callback("/>[^<]*{[a-zA-Z0-9_]+}[^>]*</", function($match)
49 {
50 return preg_replace("/{[a-zA-Z0-9_]+}/", '<span class="highlight-tag">$0</span>', $match[0]);
51 }, $value);
52 }
53
54 // display editor
55 echo $editor->display($name, $value, $width, $height, $rows, $cols, $buttons);
56
57 if ($use_tags_highlighter)
58 {
59 ?>
60 <script>
61 (function($) {
62 'use strict';
63
64 /**
65 * Callback used to inject some custom CSS styles into the
66 * head of the given TinyMCE editor.
67 *
68 * @param object editor The TinyMCE instance.
69 */
70 const autoHighlightEditorTags = (editor) => {
71 const styles = '.highlight-tag { background-color: #FBEEB8; }';
72
73 // create style document
74 const css = document.createElement('style');
75 css.type = 'text/css';
76
77 if (css.styleSheet) {
78 // add support for IE
79 css.styleSheet.cssText = styles;
80 } else {
81 css.appendChild(document.createTextNode(styles));
82 }
83
84 // register style into the head of the TinyMCE iframe
85 editor.contentDocument.head.appendChild(css);
86 }
87
88 $(function() {
89 // make sure TinyMCE exists
90 if (typeof tinymce !== 'undefined') {
91 const editorName = '<?php echo addslashes($name); ?>';
92
93 onInstanceReady(() => {
94 // make sure the editor has been registered
95 if (!Joomla.editors.instances.hasOwnProperty(editorName)) {
96 return false;
97 }
98
99 // make sure the TinyMCE instance has been attached to the editor element
100 if (!Joomla.editors.instances[editorName].instance) {
101 return false;
102 }
103
104 // wait until the document of the editor is ready
105 if (!Joomla.editors.instances[editorName].instance.contentDocument) {
106 return false;
107 }
108
109 // return the TinyMCE instance
110 return Joomla.editors.instances[editorName].instance;
111 }).then((editor) => {
112 // register custom styles
113 autoHighlightEditorTags(editor);
114 });
115 }
116 });
117 })(jQuery);
118 </script>
119 <?php
120 }
121