PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.6.4
VikBooking Hotel Booking Engine & PMS v1.6.4
1.8.16 1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 37 releases
vikbooking / libraries / adapter / editor / editor.php

editor.php in VikBooking Hotel Booking Engine & PMS 1.6.4, at libraries/adapter/editor/editor.php

131 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikWP - Libraries
4 * @subpackage adapter.editor
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 /**
15 * Editor class to handle WYSIWYG editors.
16 *
17 * @since 10.0
18 */
19 abstract class JEditor
20 {
21 /**
22 * Editor instances container.
23 *
24 * @var array
25 */
26 protected static $instances = array();
27
28 /**
29 * The editor type name.
30 *
31 * @var string
32 */
33 protected $_name;
34
35 /**
36 * Constructor
37 *
38 * @param string $editor The editor name.
39 */
40 public function __construct($editor = 'none')
41 {
42 $this->_name = !is_null($editor) ? $editor : 'none';
43 }
44
45 /**
46 * Returns the global Editor object, only creating it
47 * if it doesn't already exist.
48 *
49 * @param string $editor The editor to use.
50 *
51 * @return self The Editor object.
52 */
53 public static function getInstance($editor = 'none')
54 {
55 if (empty(static::$instances[$editor]))
56 {
57 if (!JLoader::import('adapter.editor.classes.' . $editor))
58 {
59 $editor = 'none';
60 JLoader::import('adapter.editor.classes.' . $editor);
61 }
62
63 $classname = 'JEditor' . ucwords($editor);
64
65 if (!class_exists($classname))
66 {
67 throw new Exception("The editor [$classname] does not exist.", 404);
68 }
69
70 $instance = new $classname($editor);
71
72 if (!$instance instanceof JEditor)
73 {
74 throw new Exception("The editor [$classname] must be an instance of JEditor.", 500);
75 }
76
77 static::$instances[$editor] = $instance;
78 }
79
80 return static::$instances[$editor];
81 }
82
83 /**
84 * Displays the editor area.
85 *
86 * @param string $name The control name.
87 * @param string $html The contents of the text area.
88 * @param string $width The width of the text area (px or %).
89 * @param string $height The height of the text area (px or %).
90 * @param integer $col The number of columns for the textarea.
91 * @param integer $row The number of rows for the textarea.
92 * @param boolean $buttons True and the editor buttons will be displayed.
93 * @param string $id An optional ID for the textarea (@since 10.1.20). If not supplied the name is used.
94 * @param array $params Associative array of editor parameters (@since 10.1.35).
95 *
96 * @return string The editor.
97 *
98 * @link https://codex.wordpress.org/Function_Reference/wp_editor
99 */
100 public function display($name, $html, $width, $height, $col, $row, $buttons = true, $id = null, $params = array())
101 {
102 $id = preg_replace("/[^a-zA-Z0-9_]+/", '_', $id ? $id : $name);
103
104 ob_start();
105
106 $this->render($name, $html, $width, $height, $col, $row, $buttons, $id, $params);
107
108 $output = ob_get_contents();
109 ob_end_clean();
110
111 return $output;
112 }
113
114 /**
115 * Renders the editor area.
116 *
117 * @param string $name The control name.
118 * @param string $html The contents of the text area.
119 * @param string $width The width of the text area (px or %).
120 * @param string $height The height of the text area (px or %).
121 * @param integer $col The number of columns for the textarea.
122 * @param integer $row The number of rows for the textarea.
123 * @param boolean $buttons True and the editor buttons will be displayed.
124 * @param string $id An optional ID for the textarea (@since 10.1.20).
125 * @param array $params Associative array of editor parameters (@since 10.1.35).
126 *
127 * @return string The editor.
128 */
129 abstract protected function render($name, $html, $width, $height, $col, $row, $buttons, $id, $params);
130 }
131