Version Description
Release date: January 8th, 2019 * The consent description now allows HTML. * Added ability to change the colors of the consent bar. * Fixed bug where post ID was null.
Download this release
Release Info
Developer | Van Ons |
Plugin | WP GDPR Compliance |
Version | 1.4.8 |
Comparing to | |
See all releases |
Code changes from version 1.4.7 to 1.4.8
- Includes/AccessRequest.php +355 -355
- Includes/Action.php +338 -332
- Includes/Ajax.php +451 -451
- Includes/Consent.php +479 -479
- Includes/Cron.php +90 -90
- Includes/Data.php +260 -260
- Includes/Data/Comment.php +166 -166
- Includes/Data/User.php +187 -187
- Includes/Data/WooCommerceOrder.php +391 -391
- Includes/DeleteRequest.php +407 -407
- Includes/Extensions/CF7.php +292 -292
- Includes/Extensions/GForms.php +287 -287
- Includes/Extensions/WC.php +111 -111
- Includes/Extensions/WP.php +93 -93
- Includes/Extensions/WPRegistration.php +70 -70
- Includes/Filter.php +21 -21
- Includes/Helper.php +783 -783
- Includes/Integration.php +439 -439
- Includes/Page.php +961 -925
- Includes/SessionHelper.php +51 -51
- Includes/Shortcode.php +180 -180
- assets/css/admin.css +697 -697
- assets/css/front.css +433 -433
- assets/js/admin.js +195 -195
- assets/js/front.js +316 -316
- assets/svg/stars.svg +8 -8
- assets/vendor/codemirror/codemirror.css +346 -346
- assets/vendor/codemirror/codemirror.js +585 -9684
Includes/AccessRequest.php
CHANGED
@@ -1,356 +1,356 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WPGDPRC\Includes;
|
4 |
-
|
5 |
-
/**
|
6 |
-
* Class Requests
|
7 |
-
* @package WPGDPRC\Includes
|
8 |
-
*/
|
9 |
-
class AccessRequest {
|
10 |
-
/** @var null */
|
11 |
-
private static $instance = null;
|
12 |
-
/** @var int */
|
13 |
-
private $id = 0;
|
14 |
-
/** @var int */
|
15 |
-
private $siteId = 0;
|
16 |
-
/** @var string */
|
17 |
-
private $emailAddress = '';
|
18 |
-
/** @var string */
|
19 |
-
private $sessionId = '';
|
20 |
-
/** @var string */
|
21 |
-
private $ipAddress = '';
|
22 |
-
/** @var string */
|
23 |
-
private $token = '';
|
24 |
-
/** @var int */
|
25 |
-
private $expired = 0;
|
26 |
-
/** @var string */
|
27 |
-
private $dateCreated = '';
|
28 |
-
|
29 |
-
/**
|
30 |
-
* AccessRequest constructor.
|
31 |
-
* @param int $id
|
32 |
-
*/
|
33 |
-
public function __construct($id = 0) {
|
34 |
-
if ((int)$id > 0) {
|
35 |
-
$this->setId($id);
|
36 |
-
$this->load();
|
37 |
-
}
|
38 |
-
}
|
39 |
-
|
40 |
-
/**
|
41 |
-
* @param string $emailAddress
|
42 |
-
* @param string $sessionId
|
43 |
-
* @return bool|AccessRequest
|
44 |
-
*/
|
45 |
-
public function getByEmailAddressAndSessionId($emailAddress = '', $sessionId = '') {
|
46 |
-
global $wpdb;
|
47 |
-
$query = "SELECT * FROM `" . self::getDatabaseTableName() . "`";
|
48 |
-
$query .= " WHERE `email_address` = %s";
|
49 |
-
$query .= " AND `session_id` = %s";
|
50 |
-
$query .= " AND `expired` = '0'";
|
51 |
-
$query .= " AND `site_id` = %d";
|
52 |
-
$row = $wpdb->get_row($wpdb->prepare($query, $emailAddress, $sessionId, get_current_blog_id()));
|
53 |
-
if ($row !== null) {
|
54 |
-
return new self($row->ID);
|
55 |
-
}
|
56 |
-
return false;
|
57 |
-
}
|
58 |
-
|
59 |
-
/**
|
60 |
-
* @param string $token
|
61 |
-
* @return bool|AccessRequest
|
62 |
-
*/
|
63 |
-
public function getByToken($token = '') {
|
64 |
-
global $wpdb;
|
65 |
-
$query = "SELECT * FROM `" . self::getDatabaseTableName() . "`";
|
66 |
-
$query .= " WHERE `token` = %s";
|
67 |
-
$query .= " AND `expired` = '0'";
|
68 |
-
$query .= " AND `site_id` = %d";
|
69 |
-
$row = $wpdb->get_row($wpdb->prepare($query, $token, get_current_blog_id()));
|
70 |
-
if ($row !== null) {
|
71 |
-
return new self($row->ID);
|
72 |
-
}
|
73 |
-
return false;
|
74 |
-
}
|
75 |
-
|
76 |
-
/**
|
77 |
-
* @param array $filters
|
78 |
-
* @return int
|
79 |
-
*/
|
80 |
-
public function getTotal($filters = array()) {
|
81 |
-
global $wpdb;
|
82 |
-
$query = "SELECT COUNT(`ID`) FROM `" . self::getDatabaseTableName() . "` WHERE 1";
|
83 |
-
$query .= Helper::getQueryByFilters($filters);
|
84 |
-
$query .= sprintf(" AND `site_id` = %d", get_current_blog_id());
|
85 |
-
$result = $wpdb->get_var($query);
|
86 |
-
if ($result !== null) {
|
87 |
-
return absint($result);
|
88 |
-
}
|
89 |
-
return 0;
|
90 |
-
}
|
91 |
-
|
92 |
-
/**
|
93 |
-
* @param array $filters
|
94 |
-
* @param int $limit
|
95 |
-
* @param int $offset
|
96 |
-
* @return AccessRequest[]
|
97 |
-
*/
|
98 |
-
public function getList($filters = array(), $limit = 0, $offset = 0) {
|
99 |
-
global $wpdb;
|
100 |
-
$output = array();
|
101 |
-
$query = "SELECT * FROM `" . self::getDatabaseTableName() . "` WHERE 1";
|
102 |
-
$query .= Helper::getQueryByFilters($filters);
|
103 |
-
$query .= sprintf(" AND `site_id` = %d", get_current_blog_id());
|
104 |
-
$query .= " ORDER BY `date_created` DESC";
|
105 |
-
if (!empty($limit)) {
|
106 |
-
$query .= " LIMIT $offset, $limit";
|
107 |
-
}
|
108 |
-
$results = $wpdb->get_results($query);
|
109 |
-
if ($results !== null) {
|
110 |
-
foreach ($results as $row) {
|
111 |
-
$object = new self;
|
112 |
-
$object->loadByRow($row);
|
113 |
-
$output[] = $object;
|
114 |
-
}
|
115 |
-
}
|
116 |
-
return $output;
|
117 |
-
}
|
118 |
-
|
119 |
-
/**
|
120 |
-
* @param $row
|
121 |
-
*/
|
122 |
-
private function loadByRow($row) {
|
123 |
-
$this->setId($row->ID);
|
124 |
-
$this->setSiteId($row->site_id);
|
125 |
-
$this->setEmailAddress($row->email_address);
|
126 |
-
$this->setSessionId($row->session_id);
|
127 |
-
$this->setIpAddress($row->ip_address);
|
128 |
-
$this->setToken($row->token);
|
129 |
-
$this->setExpired($row->expired);
|
130 |
-
$this->setDateCreated($row->date_created);
|
131 |
-
}
|
132 |
-
|
133 |
-
public function load() {
|
134 |
-
global $wpdb;
|
135 |
-
$query = "SELECT * FROM `" . self::getDatabaseTableName() . "` WHERE `ID` = %d";
|
136 |
-
$row = $wpdb->get_row($wpdb->prepare($query, $this->getId()));
|
137 |
-
if ($row !== null) {
|
138 |
-
$this->loadByRow($row);
|
139 |
-
}
|
140 |
-
}
|
141 |
-
|
142 |
-
/**
|
143 |
-
* @param int $id
|
144 |
-
* @return bool
|
145 |
-
*/
|
146 |
-
public function exists($id = 0) {
|
147 |
-
global $wpdb;
|
148 |
-
$row = $wpdb->get_row(
|
149 |
-
$wpdb->prepare(
|
150 |
-
"SELECT * FROM `" . self::getDatabaseTableName() . "` WHERE `ID` = %d",
|
151 |
-
intval($id)
|
152 |
-
)
|
153 |
-
);
|
154 |
-
return ($row !== null);
|
155 |
-
}
|
156 |
-
|
157 |
-
/**
|
158 |
-
* @param string $emailAddress
|
159 |
-
* @param bool $nonExpiredOnly
|
160 |
-
* @return bool
|
161 |
-
*/
|
162 |
-
public function existsByEmailAddress($emailAddress = '', $nonExpiredOnly = false) {
|
163 |
-
global $wpdb;
|
164 |
-
$query = "SELECT * FROM `" . self::getDatabaseTableName() . "`";
|
165 |
-
$query .= " WHERE `email_address` = %s";
|
166 |
-
$query .= " AND `site_id` = %d";
|
167 |
-
if ($nonExpiredOnly === true) {
|
168 |
-
$query .= " AND `expired` = '0'";
|
169 |
-
}
|
170 |
-
$row = $wpdb->get_row($wpdb->prepare($query, $emailAddress, get_current_blog_id()));
|
171 |
-
return ($row !== null);
|
172 |
-
}
|
173 |
-
|
174 |
-
/**
|
175 |
-
* @return bool|int
|
176 |
-
*/
|
177 |
-
public function save() {
|
178 |
-
global $wpdb;
|
179 |
-
if ($this->exists($this->getId())) {
|
180 |
-
$wpdb->update(
|
181 |
-
self::getDatabaseTableName(),
|
182 |
-
array(
|
183 |
-
'email_address' => $this->getEmailAddress(),
|
184 |
-
'ip_address' => $this->getIpAddress(),
|
185 |
-
'expired' => $this->getExpired()
|
186 |
-
),
|
187 |
-
array('ID' => $this->getId()),
|
188 |
-
array('%s', '%s', '%d'),
|
189 |
-
array('%d')
|
190 |
-
);
|
191 |
-
return $this->getId();
|
192 |
-
} else {
|
193 |
-
$result = $wpdb->insert(
|
194 |
-
self::getDatabaseTableName(),
|
195 |
-
array(
|
196 |
-
'site_id' => $this->getSiteId(),
|
197 |
-
'email_address' => $this->getEmailAddress(),
|
198 |
-
'session_id' => $this->getSessionId(),
|
199 |
-
'ip_address' => $this->getIpAddress(),
|
200 |
-
'token' => $this->getToken(),
|
201 |
-
'expired' => $this->getExpired(),
|
202 |
-
'date_created' => date_i18n('Y-m-d H:i:s'),
|
203 |
-
),
|
204 |
-
array('%d', '%s', '%s', '%s', '%s', '%d', '%s')
|
205 |
-
);
|
206 |
-
if ($result !== false) {
|
207 |
-
$this->setId($wpdb->insert_id);
|
208 |
-
return $this->getId();
|
209 |
-
}
|
210 |
-
}
|
211 |
-
return false;
|
212 |
-
}
|
213 |
-
|
214 |
-
public function isAnonymised() {
|
215 |
-
return ($this->getIpAddress() === '127.0.0.1');
|
216 |
-
}
|
217 |
-
|
218 |
-
/**
|
219 |
-
* @return null|AccessRequest
|
220 |
-
*/
|
221 |
-
public static function getInstance() {
|
222 |
-
if (!isset(self::$instance)) {
|
223 |
-
self::$instance = new self();
|
224 |
-
}
|
225 |
-
return self::$instance;
|
226 |
-
}
|
227 |
-
|
228 |
-
/**
|
229 |
-
* @return int
|
230 |
-
*/
|
231 |
-
public function getId() {
|
232 |
-
return $this->id;
|
233 |
-
}
|
234 |
-
|
235 |
-
/**
|
236 |
-
* @param int $id
|
237 |
-
*/
|
238 |
-
public function setId($id) {
|
239 |
-
$this->id = $id;
|
240 |
-
}
|
241 |
-
|
242 |
-
/**
|
243 |
-
* @return int
|
244 |
-
*/
|
245 |
-
public function getSiteId() {
|
246 |
-
return $this->siteId;
|
247 |
-
}
|
248 |
-
|
249 |
-
/**
|
250 |
-
* @param int $siteId
|
251 |
-
*/
|
252 |
-
public function setSiteId($siteId) {
|
253 |
-
$this->siteId = $siteId;
|
254 |
-
}
|
255 |
-
|
256 |
-
/**
|
257 |
-
* @return string
|
258 |
-
*/
|
259 |
-
public function getEmailAddress() {
|
260 |
-
return $this->emailAddress;
|
261 |
-
}
|
262 |
-
|
263 |
-
/**
|
264 |
-
* @param string $emailAddress
|
265 |
-
*/
|
266 |
-
public function setEmailAddress($emailAddress) {
|
267 |
-
$this->emailAddress = $emailAddress;
|
268 |
-
}
|
269 |
-
|
270 |
-
/**
|
271 |
-
* @return string
|
272 |
-
*/
|
273 |
-
public function getSessionId() {
|
274 |
-
return $this->sessionId;
|
275 |
-
}
|
276 |
-
|
277 |
-
/**
|
278 |
-
* @param string $sessionId
|
279 |
-
*/
|
280 |
-
public function setSessionId($sessionId) {
|
281 |
-
$this->sessionId = $sessionId;
|
282 |
-
}
|
283 |
-
|
284 |
-
/**
|
285 |
-
* @return string
|
286 |
-
*/
|
287 |
-
public function getIpAddress() {
|
288 |
-
return $this->ipAddress;
|
289 |
-
}
|
290 |
-
|
291 |
-
/**
|
292 |
-
* @param string $ipAddress
|
293 |
-
*/
|
294 |
-
public function setIpAddress($ipAddress) {
|
295 |
-
$this->ipAddress = $ipAddress;
|
296 |
-
}
|
297 |
-
|
298 |
-
/**
|
299 |
-
* @return string
|
300 |
-
*/
|
301 |
-
public function getToken() {
|
302 |
-
return $this->token;
|
303 |
-
}
|
304 |
-
|
305 |
-
/**
|
306 |
-
* @param string $token
|
307 |
-
*/
|
308 |
-
public function setToken($token) {
|
309 |
-
$this->token = $token;
|
310 |
-
}
|
311 |
-
|
312 |
-
/**
|
313 |
-
* @return int
|
314 |
-
*/
|
315 |
-
public function getExpired() {
|
316 |
-
return $this->expired;
|
317 |
-
}
|
318 |
-
|
319 |
-
/**
|
320 |
-
* @param int $expired
|
321 |
-
*/
|
322 |
-
public function setExpired($expired) {
|
323 |
-
$this->expired = $expired;
|
324 |
-
}
|
325 |
-
|
326 |
-
/**
|
327 |
-
* @return string
|
328 |
-
*/
|
329 |
-
public function getDateCreated() {
|
330 |
-
return $this->dateCreated;
|
331 |
-
}
|
332 |
-
|
333 |
-
/**
|
334 |
-
* @param string $dateCreated
|
335 |
-
*/
|
336 |
-
public function setDateCreated($dateCreated) {
|
337 |
-
$this->dateCreated = $dateCreated;
|
338 |
-
}
|
339 |
-
|
340 |
-
/**
|
341 |
-
* @return bool
|
342 |
-
*/
|
343 |
-
public static function databaseTableExists() {
|
344 |
-
global $wpdb;
|
345 |
-
$result = $wpdb->query("SHOW TABLES LIKE '" . self::getDatabaseTableName() . "'");
|
346 |
-
return ($result === 1);
|
347 |
-
}
|
348 |
-
|
349 |
-
/**
|
350 |
-
* @return string
|
351 |
-
*/
|
352 |
-
public static function getDatabaseTableName() {
|
353 |
-
global $wpdb;
|
354 |
-
return $wpdb->base_prefix . 'wpgdprc_access_requests';
|
355 |
-
}
|
356 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WPGDPRC\Includes;
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Class Requests
|
7 |
+
* @package WPGDPRC\Includes
|
8 |
+
*/
|
9 |
+
class AccessRequest {
|
10 |
+
/** @var null */
|
11 |
+
private static $instance = null;
|
12 |
+
/** @var int */
|
13 |
+
private $id = 0;
|
14 |
+
/** @var int */
|
15 |
+
private $siteId = 0;
|
16 |
+
/** @var string */
|
17 |
+
private $emailAddress = '';
|
18 |
+
/** @var string */
|
19 |
+
private $sessionId = '';
|
20 |
+
/** @var string */
|
21 |
+
private $ipAddress = '';
|
22 |
+
/** @var string */
|
23 |
+
private $token = '';
|
24 |
+
/** @var int */
|
25 |
+
private $expired = 0;
|
26 |
+
/** @var string */
|
27 |
+
private $dateCreated = '';
|
28 |
+
|
29 |
+
/**
|
30 |
+
* AccessRequest constructor.
|
31 |
+
* @param int $id
|
32 |
+
*/
|
33 |
+
public function __construct($id = 0) {
|
34 |
+
if ((int)$id > 0) {
|
35 |
+
$this->setId($id);
|
36 |
+
$this->load();
|
37 |
+
}
|
38 |
+
}
|
39 |
+
|
40 |
+
/**
|
41 |
+
* @param string $emailAddress
|
42 |
+
* @param string $sessionId
|
43 |
+
* @return bool|AccessRequest
|
44 |
+
*/
|
45 |
+
public function getByEmailAddressAndSessionId($emailAddress = '', $sessionId = '') {
|
46 |
+
global $wpdb;
|
47 |
+
$query = "SELECT * FROM `" . self::getDatabaseTableName() . "`";
|
48 |
+
$query .= " WHERE `email_address` = %s";
|
49 |
+
$query .= " AND `session_id` = %s";
|
50 |
+
$query .= " AND `expired` = '0'";
|
51 |
+
$query .= " AND `site_id` = %d";
|
52 |
+
$row = $wpdb->get_row($wpdb->prepare($query, $emailAddress, $sessionId, get_current_blog_id()));
|
53 |
+
if ($row !== null) {
|
54 |
+
return new self($row->ID);
|
55 |
+
}
|
56 |
+
return false;
|
57 |
+
}
|
58 |
+
|
59 |
+
/**
|
60 |
+
* @param string $token
|
61 |
+
* @return bool|AccessRequest
|
62 |
+
*/
|
63 |
+
public function getByToken($token = '') {
|
64 |
+
global $wpdb;
|
65 |
+
$query = "SELECT * FROM `" . self::getDatabaseTableName() . "`";
|
66 |
+
$query .= " WHERE `token` = %s";
|
67 |
+
$query .= " AND `expired` = '0'";
|
68 |
+
$query .= " AND `site_id` = %d";
|
69 |
+
$row = $wpdb->get_row($wpdb->prepare($query, $token, get_current_blog_id()));
|
70 |
+
if ($row !== null) {
|
71 |
+
return new self($row->ID);
|
72 |
+
}
|
73 |
+
return false;
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* @param array $filters
|
78 |
+
* @return int
|
79 |
+
*/
|
80 |
+
public function getTotal($filters = array()) {
|
81 |
+
global $wpdb;
|
82 |
+
$query = "SELECT COUNT(`ID`) FROM `" . self::getDatabaseTableName() . "` WHERE 1";
|
83 |
+
$query .= Helper::getQueryByFilters($filters);
|
84 |
+
$query .= sprintf(" AND `site_id` = %d", get_current_blog_id());
|
85 |
+
$result = $wpdb->get_var($query);
|
86 |
+
if ($result !== null) {
|
87 |
+
return absint($result);
|
88 |
+
}
|
89 |
+
return 0;
|
90 |
+
}
|
91 |
+
|
92 |
+
/**
|
93 |
+
* @param array $filters
|
94 |
+
* @param int $limit
|
95 |
+
* @param int $offset
|
96 |
+
* @return AccessRequest[]
|
97 |
+
*/
|
98 |
+
public function getList($filters = array(), $limit = 0, $offset = 0) {
|
99 |
+
global $wpdb;
|
100 |
+
$output = array();
|
101 |
+
$query = "SELECT * FROM `" . self::getDatabaseTableName() . "` WHERE 1";
|
102 |
+
$query .= Helper::getQueryByFilters($filters);
|
103 |
+
$query .= sprintf(" AND `site_id` = %d", get_current_blog_id());
|
104 |
+
$query .= " ORDER BY `date_created` DESC";
|
105 |
+
if (!empty($limit)) {
|
106 |
+
$query .= " LIMIT $offset, $limit";
|
107 |
+
}
|
108 |
+
$results = $wpdb->get_results($query);
|
109 |
+
if ($results !== null) {
|
110 |
+
foreach ($results as $row) {
|
111 |
+
$object = new self;
|
112 |
+
$object->loadByRow($row);
|
113 |
+
$output[] = $object;
|
114 |
+
}
|
115 |
+
}
|
116 |
+
return $output;
|
117 |
+
}
|
118 |
+
|
119 |
+
/**
|
120 |
+
* @param $row
|
121 |
+
*/
|
122 |
+
private function loadByRow($row) {
|
123 |
+
$this->setId($row->ID);
|
124 |
+
$this->setSiteId($row->site_id);
|
125 |
+
$this->setEmailAddress($row->email_address);
|
126 |
+
$this->setSessionId($row->session_id);
|
127 |
+
$this->setIpAddress($row->ip_address);
|
128 |
+
$this->setToken($row->token);
|
129 |
+
$this->setExpired($row->expired);
|
130 |
+
$this->setDateCreated($row->date_created);
|
131 |
+
}
|
132 |
+
|
133 |
+
public function load() {
|
134 |
+
global $wpdb;
|
135 |
+
$query = "SELECT * FROM `" . self::getDatabaseTableName() . "` WHERE `ID` = %d";
|
136 |
+
$row = $wpdb->get_row($wpdb->prepare($query, $this->getId()));
|
137 |
+
if ($row !== null) {
|
138 |
+
$this->loadByRow($row);
|
139 |
+
}
|
140 |
+
}
|
141 |
+
|
142 |
+
/**
|
143 |
+
* @param int $id
|
144 |
+
* @return bool
|
145 |
+
*/
|
146 |
+
public function exists($id = 0) {
|
147 |
+
global $wpdb;
|
148 |
+
$row = $wpdb->get_row(
|
149 |
+
$wpdb->prepare(
|
150 |
+
"SELECT * FROM `" . self::getDatabaseTableName() . "` WHERE `ID` = %d",
|
151 |
+
intval($id)
|
152 |
+
)
|
153 |
+
);
|
154 |
+
return ($row !== null);
|
155 |
+
}
|
156 |
+
|
157 |
+
/**
|
158 |
+
* @param string $emailAddress
|
159 |
+
* @param bool $nonExpiredOnly
|
160 |
+
* @return bool
|
161 |
+
*/
|
162 |
+
public function existsByEmailAddress($emailAddress = '', $nonExpiredOnly = false) {
|
163 |
+
global $wpdb;
|
164 |
+
$query = "SELECT * FROM `" . self::getDatabaseTableName() . "`";
|
165 |
+
$query .= " WHERE `email_address` = %s";
|
166 |
+
$query .= " AND `site_id` = %d";
|
167 |
+
if ($nonExpiredOnly === true) {
|
168 |
+
$query .= " AND `expired` = '0'";
|
169 |
+
}
|
170 |
+
$row = $wpdb->get_row($wpdb->prepare($query, $emailAddress, get_current_blog_id()));
|
171 |
+
return ($row !== null);
|
172 |
+
}
|
173 |
+
|
174 |
+
/**
|
175 |
+
* @return bool|int
|
176 |
+
*/
|
177 |
+
public function save() {
|
178 |
+
global $wpdb;
|
179 |
+
if ($this->exists($this->getId())) {
|
180 |
+
$wpdb->update(
|
181 |
+
self::getDatabaseTableName(),
|
182 |
+
array(
|
183 |
+
'email_address' => $this->getEmailAddress(),
|
184 |
+
'ip_address' => $this->getIpAddress(),
|
185 |
+
'expired' => $this->getExpired()
|
186 |
+
),
|
187 |
+
array('ID' => $this->getId()),
|
188 |
+
array('%s', '%s', '%d'),
|
189 |
+
array('%d')
|
190 |
+
);
|
191 |
+
return $this->getId();
|
192 |
+
} else {
|
193 |
+
$result = $wpdb->insert(
|
194 |
+
self::getDatabaseTableName(),
|
195 |
+
array(
|
196 |
+
'site_id' => $this->getSiteId(),
|
197 |
+
'email_address' => $this->getEmailAddress(),
|
198 |
+
'session_id' => $this->getSessionId(),
|
199 |
+
'ip_address' => $this->getIpAddress(),
|
200 |
+
'token' => $this->getToken(),
|
201 |
+
'expired' => $this->getExpired(),
|
202 |
+
'date_created' => date_i18n('Y-m-d H:i:s'),
|
203 |
+
),
|
204 |
+
array('%d', '%s', '%s', '%s', '%s', '%d', '%s')
|
205 |
+
);
|
206 |
+
if ($result !== false) {
|
207 |
+
$this->setId($wpdb->insert_id);
|
208 |
+
return $this->getId();
|
209 |
+
}
|
210 |
+
}
|
211 |
+
return false;
|
212 |
+
}
|
213 |
+
|
214 |
+
public function isAnonymised() {
|
215 |
+
return ($this->getIpAddress() === '127.0.0.1');
|
216 |
+
}
|
217 |
+
|
218 |
+
/**
|
219 |
+
* @return null|AccessRequest
|
220 |
+
*/
|
221 |
+
public static function getInstance() {
|
222 |
+
if (!isset(self::$instance)) {
|
223 |
+
self::$instance = new self();
|
224 |
+
}
|
225 |
+
return self::$instance;
|
226 |
+
}
|
227 |
+
|
228 |
+
/**
|
229 |
+
* @return int
|
230 |
+
*/
|
231 |
+
public function getId() {
|
232 |
+
return $this->id;
|
233 |
+
}
|
234 |
+
|
235 |
+
/**
|
236 |
+
* @param int $id
|
237 |
+
*/
|
238 |
+
public function setId($id) {
|
239 |
+
$this->id = $id;
|
240 |
+
}
|
241 |
+
|
242 |
+
/**
|
243 |
+
* @return int
|
244 |
+
*/
|
245 |
+
public function getSiteId() {
|
246 |
+
return $this->siteId;
|
247 |
+
}
|
248 |
+
|
249 |
+
/**
|
250 |
+
* @param int $siteId
|
251 |
+
*/
|
252 |
+
public function setSiteId($siteId) {
|
253 |
+
$this->siteId = $siteId;
|
254 |
+
}
|
255 |
+
|
256 |
+
/**
|
257 |
+
* @return string
|
258 |
+
*/
|
259 |
+
public function getEmailAddress() {
|
260 |
+
return $this->emailAddress;
|
261 |
+
}
|
262 |
+
|
263 |
+
/**
|
264 |
+
* @param string $emailAddress
|
265 |
+
*/
|
266 |
+
public function setEmailAddress($emailAddress) {
|
267 |
+
$this->emailAddress = $emailAddress;
|
268 |
+
}
|
269 |
+
|
270 |
+
/**
|
271 |
+
* @return string
|
272 |
+
*/
|
273 |
+
public function getSessionId() {
|
274 |
+
return $this->sessionId;
|
275 |
+
}
|
276 |
+
|
277 |
+
/**
|
278 |
+
* @param string $sessionId
|
279 |
+
*/
|
280 |
+
public function setSessionId($sessionId) {
|
281 |
+
$this->sessionId = $sessionId;
|
282 |
+
}
|
283 |
+
|
284 |
+
/**
|
285 |
+
* @return string
|
286 |
+
*/
|
287 |
+
public function getIpAddress() {
|
288 |
+
return $this->ipAddress;
|
289 |
+
}
|
290 |
+
|
291 |
+
/**
|
292 |
+
* @param string $ipAddress
|
293 |
+
*/
|
294 |
+
public function setIpAddress($ipAddress) {
|
295 |
+
$this->ipAddress = $ipAddress;
|
296 |
+
}
|
297 |
+
|
298 |
+
/**
|
299 |
+
* @return string
|
300 |
+
*/
|
301 |
+
public function getToken() {
|
302 |
+
return $this->token;
|
303 |
+
}
|
304 |
+
|
305 |
+
/**
|
306 |
+
* @param string $token
|
307 |
+
*/
|
308 |
+
public function setToken($token) {
|
309 |
+
$this->token = $token;
|
310 |
+
}
|
311 |
+
|
312 |
+
/**
|
313 |
+
* @return int
|
314 |
+
*/
|
315 |
+
public function getExpired() {
|
316 |
+
return $this->expired;
|
317 |
+
}
|
318 |
+
|
319 |
+
/**
|
320 |
+
* @param int $expired
|
321 |
+
*/
|
322 |
+
public function setExpired($expired) {
|
323 |
+
$this->expired = $expired;
|
324 |
+
}
|
325 |
+
|
326 |
+
/**
|
327 |
+
* @return string
|
328 |
+
*/
|
329 |
+
public function getDateCreated() {
|
330 |
+
return $this->dateCreated;
|
331 |
+
}
|
332 |
+
|
333 |
+
/**
|
334 |
+
* @param string $dateCreated
|
335 |
+
*/
|
336 |
+
public function setDateCreated($dateCreated) {
|
337 |
+
$this->dateCreated = $dateCreated;
|
338 |
+
}
|
339 |
+
|
340 |
+
/**
|
341 |
+
* @return bool
|
342 |
+
*/
|
343 |
+
public static function databaseTableExists() {
|
344 |
+
global $wpdb;
|
345 |
+
$result = $wpdb->query("SHOW TABLES LIKE '" . self::getDatabaseTableName() . "'");
|
346 |
+
return ($result === 1);
|
347 |
+
}
|
348 |
+
|
349 |
+
/**
|
350 |
+
* @return string
|
351 |
+
*/
|
352 |
+
public static function getDatabaseTableName() {
|
353 |
+
global $wpdb;
|
354 |
+
return $wpdb->base_prefix . 'wpgdprc_access_requests';
|
355 |
+
}
|
356 |
}
|
Includes/Action.php
CHANGED
@@ -1,333 +1,339 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WPGDPRC\Includes;
|
4 |
-
|
5 |
-
use WPGDPRC\Includes\Extensions\CF7;
|
6 |
-
use WPGDPRC\Includes\Extensions\GForms;
|
7 |
-
|
8 |
-
/**
|
9 |
-
* Class Action
|
10 |
-
* @package WPGDPRC\Includes
|
11 |
-
*/
|
12 |
-
class Action {
|
13 |
-
/** @var null */
|
14 |
-
private static $instance = null;
|
15 |
-
|
16 |
-
public function handleRedirects() {
|
17 |
-
global $pagenow;
|
18 |
-
if ($pagenow === 'tools.php' && isset($_REQUEST['page']) && $_REQUEST['page'] === str_replace('-', '_', WP_GDPR_C_SLUG)) {
|
19 |
-
$type = (isset($_REQUEST['type'])) ? esc_html($_REQUEST['type']) : false;
|
20 |
-
if ($type !== false) {
|
21 |
-
switch ($type) {
|
22 |
-
case 'consents' :
|
23 |
-
$action = (isset($_REQUEST['action'])) ? esc_html($_REQUEST['action']) : false;
|
24 |
-
switch ($action) {
|
25 |
-
case 'manage' :
|
26 |
-
$id = (isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) ? intval($_REQUEST['id']) : 0;
|
27 |
-
if (!empty($id) && !Consent::getInstance()->exists($id)) {
|
28 |
-
wp_safe_redirect(Helper::getPluginAdminUrl('consents', array('notice' => 'wpgdprc-consent-not-found')));
|
29 |
-
exit;
|
30 |
-
}
|
31 |
-
Helper::resetCookieBar();
|
32 |
-
break;
|
33 |
-
case 'create' :
|
34 |
-
$consent = new Consent();
|
35 |
-
$consent->setSiteId(get_current_blog_id());
|
36 |
-
$id = $consent->save();
|
37 |
-
if (!empty($id)) {
|
38 |
-
Helper::resetCookieBar();
|
39 |
-
wp_safe_redirect(add_query_arg(
|
40 |
-
array('notice' => 'wpgdprc-consent-added'),
|
41 |
-
Consent::getActionUrl($id)
|
42 |
-
));
|
43 |
-
exit;
|
44 |
-
}
|
45 |
-
break;
|
46 |
-
case 'delete' :
|
47 |
-
$id = (isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) ? intval($_REQUEST['id']) : 0;
|
48 |
-
if (!empty($id) && Consent::getInstance()->exists($id)) {
|
49 |
-
$result = Consent::getInstance()->delete($id);
|
50 |
-
if ($result !== false) {
|
51 |
-
wp_safe_redirect(Helper::getPluginAdminUrl('consents', array('notice' => 'wpgdprc-consent-removed')));
|
52 |
-
exit;
|
53 |
-
}
|
54 |
-
}
|
55 |
-
break;
|
56 |
-
}
|
57 |
-
break;
|
58 |
-
}
|
59 |
-
}
|
60 |
-
}
|
61 |
-
}
|
62 |
-
|
63 |
-
public function showAdminNotices() {
|
64 |
-
if (!empty($_REQUEST['notice'])) {
|
65 |
-
Helper::showAdminNotice(esc_html($_REQUEST['notice']));
|
66 |
-
}
|
67 |
-
}
|
68 |
-
|
69 |
-
/**
|
70 |
-
* Stop WordPress from sending anything but essential data during the update check
|
71 |
-
* @param array $query
|
72 |
-
* @return array
|
73 |
-
*/
|
74 |
-
public function onlySendEssentialDataDuringUpdateCheck($query = array()) {
|
75 |
-
unset($query['php']);
|
76 |
-
unset($query['mysql']);
|
77 |
-
unset($query['local_package']);
|
78 |
-
unset($query['blogs']);
|
79 |
-
unset($query['users']);
|
80 |
-
unset($query['multisite_enabled']);
|
81 |
-
unset($query['initial_db_version']);
|
82 |
-
return $query;
|
83 |
-
}
|
84 |
-
|
85 |
-
public function processEnableAccessRequest() {
|
86 |
-
$enabled = Helper::isEnabled('enable_access_request', 'settings');
|
87 |
-
if ($enabled) {
|
88 |
-
$accessRequest = AccessRequest::databaseTableExists();
|
89 |
-
$deleteRequest = DeleteRequest::databaseTableExists();
|
90 |
-
if (!$accessRequest || !$deleteRequest) {
|
91 |
-
Helper::createUserRequestDataTables();
|
92 |
-
$result = wp_insert_post(array(
|
93 |
-
'post_type' => 'page',
|
94 |
-
'post_status' => 'private',
|
95 |
-
'post_title' => __('Data Access Request', WP_GDPR_C_SLUG),
|
96 |
-
'post_content' => '[wpgdprc_access_request_form]',
|
97 |
-
'meta_input' => array(
|
98 |
-
'_wpgdprc_access_request' => 1,
|
99 |
-
),
|
100 |
-
), true);
|
101 |
-
if (!is_wp_error($result)) {
|
102 |
-
update_option(WP_GDPR_C_PREFIX . '_settings_access_request_page', $result);
|
103 |
-
}
|
104 |
-
}
|
105 |
-
}
|
106 |
-
}
|
107 |
-
|
108 |
-
public function processToggleAccessRequest() {
|
109 |
-
$page = Helper::getAccessRequestPage();
|
110 |
-
if (!empty($page)) {
|
111 |
-
$enabled = Helper::isEnabled('enable_access_request', 'settings');
|
112 |
-
$status = ($enabled) ? 'private' : 'draft';
|
113 |
-
wp_update_post(array(
|
114 |
-
'ID' => $page->ID,
|
115 |
-
'post_status' => $status
|
116 |
-
));
|
117 |
-
}
|
118 |
-
}
|
119 |
-
|
120 |
-
public function showNoticesRequestUserData() {
|
121 |
-
$enabled = Helper::isEnabled('enable_access_request', 'settings');
|
122 |
-
if ($enabled) {
|
123 |
-
$accessRequest = AccessRequest::databaseTableExists();
|
124 |
-
$deleteRequest = DeleteRequest::databaseTableExists();
|
125 |
-
if (!$accessRequest || !$deleteRequest) {
|
126 |
-
$pluginData = Helper::getPluginData();
|
127 |
-
printf(
|
128 |
-
'<div class="%s"><p><strong>%s:</strong> %s %s</p></div>',
|
129 |
-
'notice notice-error',
|
130 |
-
$pluginData['Name'],
|
131 |
-
__('Couldn\'t create the required database tables.', WP_GDPR_C_SLUG),
|
132 |
-
sprintf(
|
133 |
-
'<a class="button" href="%s">%s</a>',
|
134 |
-
Helper::getPluginAdminUrl('', array('wpgdprc-action' => 'create_request_tables')),
|
135 |
-
__('Retry', WP_GDPR_C_SLUG)
|
136 |
-
)
|
137 |
-
);
|
138 |
-
}
|
139 |
-
}
|
140 |
-
}
|
141 |
-
|
142 |
-
public function addConsentBar() {
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
$output
|
148 |
-
$output .=
|
149 |
-
$output .= '
|
150 |
-
$output .= '
|
151 |
-
$output .= '<div class="wpgdprc-consent-
|
152 |
-
$output .=
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
$output .=
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
$output .=
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
$
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
$output .=
|
196 |
-
$output .=
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
)
|
201 |
-
$output .= '
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
$
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
$output .= '<
|
219 |
-
$output .=
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
$output .=
|
225 |
-
$output .= '
|
226 |
-
$output .= '
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
$output .= '
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
$output .=
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
$
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
'
|
261 |
-
'value' =>
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
'
|
282 |
-
'value' =>
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
//
|
298 |
-
if (Helper::isEnabled(
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
//
|
315 |
-
if (Helper::isEnabled(
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
333 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WPGDPRC\Includes;
|
4 |
+
|
5 |
+
use WPGDPRC\Includes\Extensions\CF7;
|
6 |
+
use WPGDPRC\Includes\Extensions\GForms;
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Class Action
|
10 |
+
* @package WPGDPRC\Includes
|
11 |
+
*/
|
12 |
+
class Action {
|
13 |
+
/** @var null */
|
14 |
+
private static $instance = null;
|
15 |
+
|
16 |
+
public function handleRedirects() {
|
17 |
+
global $pagenow;
|
18 |
+
if ($pagenow === 'tools.php' && isset($_REQUEST['page']) && $_REQUEST['page'] === str_replace('-', '_', WP_GDPR_C_SLUG)) {
|
19 |
+
$type = (isset($_REQUEST['type'])) ? esc_html($_REQUEST['type']) : false;
|
20 |
+
if ($type !== false) {
|
21 |
+
switch ($type) {
|
22 |
+
case 'consents' :
|
23 |
+
$action = (isset($_REQUEST['action'])) ? esc_html($_REQUEST['action']) : false;
|
24 |
+
switch ($action) {
|
25 |
+
case 'manage' :
|
26 |
+
$id = (isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) ? intval($_REQUEST['id']) : 0;
|
27 |
+
if (!empty($id) && !Consent::getInstance()->exists($id)) {
|
28 |
+
wp_safe_redirect(Helper::getPluginAdminUrl('consents', array('notice' => 'wpgdprc-consent-not-found')));
|
29 |
+
exit;
|
30 |
+
}
|
31 |
+
Helper::resetCookieBar();
|
32 |
+
break;
|
33 |
+
case 'create' :
|
34 |
+
$consent = new Consent();
|
35 |
+
$consent->setSiteId(get_current_blog_id());
|
36 |
+
$id = $consent->save();
|
37 |
+
if (!empty($id)) {
|
38 |
+
Helper::resetCookieBar();
|
39 |
+
wp_safe_redirect(add_query_arg(
|
40 |
+
array('notice' => 'wpgdprc-consent-added'),
|
41 |
+
Consent::getActionUrl($id)
|
42 |
+
));
|
43 |
+
exit;
|
44 |
+
}
|
45 |
+
break;
|
46 |
+
case 'delete' :
|
47 |
+
$id = (isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) ? intval($_REQUEST['id']) : 0;
|
48 |
+
if (!empty($id) && Consent::getInstance()->exists($id)) {
|
49 |
+
$result = Consent::getInstance()->delete($id);
|
50 |
+
if ($result !== false) {
|
51 |
+
wp_safe_redirect(Helper::getPluginAdminUrl('consents', array('notice' => 'wpgdprc-consent-removed')));
|
52 |
+
exit;
|
53 |
+
}
|
54 |
+
}
|
55 |
+
break;
|
56 |
+
}
|
57 |
+
break;
|
58 |
+
}
|
59 |
+
}
|
60 |
+
}
|
61 |
+
}
|
62 |
+
|
63 |
+
public function showAdminNotices() {
|
64 |
+
if (!empty($_REQUEST['notice'])) {
|
65 |
+
Helper::showAdminNotice(esc_html($_REQUEST['notice']));
|
66 |
+
}
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Stop WordPress from sending anything but essential data during the update check
|
71 |
+
* @param array $query
|
72 |
+
* @return array
|
73 |
+
*/
|
74 |
+
public function onlySendEssentialDataDuringUpdateCheck($query = array()) {
|
75 |
+
unset($query['php']);
|
76 |
+
unset($query['mysql']);
|
77 |
+
unset($query['local_package']);
|
78 |
+
unset($query['blogs']);
|
79 |
+
unset($query['users']);
|
80 |
+
unset($query['multisite_enabled']);
|
81 |
+
unset($query['initial_db_version']);
|
82 |
+
return $query;
|
83 |
+
}
|
84 |
+
|
85 |
+
public function processEnableAccessRequest() {
|
86 |
+
$enabled = Helper::isEnabled('enable_access_request', 'settings');
|
87 |
+
if ($enabled) {
|
88 |
+
$accessRequest = AccessRequest::databaseTableExists();
|
89 |
+
$deleteRequest = DeleteRequest::databaseTableExists();
|
90 |
+
if (!$accessRequest || !$deleteRequest) {
|
91 |
+
Helper::createUserRequestDataTables();
|
92 |
+
$result = wp_insert_post(array(
|
93 |
+
'post_type' => 'page',
|
94 |
+
'post_status' => 'private',
|
95 |
+
'post_title' => __('Data Access Request', WP_GDPR_C_SLUG),
|
96 |
+
'post_content' => '[wpgdprc_access_request_form]',
|
97 |
+
'meta_input' => array(
|
98 |
+
'_wpgdprc_access_request' => 1,
|
99 |
+
),
|
100 |
+
), true);
|
101 |
+
if (!is_wp_error($result)) {
|
102 |
+
update_option(WP_GDPR_C_PREFIX . '_settings_access_request_page', $result);
|
103 |
+
}
|
104 |
+
}
|
105 |
+
}
|
106 |
+
}
|
107 |
+
|
108 |
+
public function processToggleAccessRequest() {
|
109 |
+
$page = Helper::getAccessRequestPage();
|
110 |
+
if (!empty($page)) {
|
111 |
+
$enabled = Helper::isEnabled('enable_access_request', 'settings');
|
112 |
+
$status = ($enabled) ? 'private' : 'draft';
|
113 |
+
wp_update_post(array(
|
114 |
+
'ID' => $page->ID,
|
115 |
+
'post_status' => $status
|
116 |
+
));
|
117 |
+
}
|
118 |
+
}
|
119 |
+
|
120 |
+
public function showNoticesRequestUserData() {
|
121 |
+
$enabled = Helper::isEnabled('enable_access_request', 'settings');
|
122 |
+
if ($enabled) {
|
123 |
+
$accessRequest = AccessRequest::databaseTableExists();
|
124 |
+
$deleteRequest = DeleteRequest::databaseTableExists();
|
125 |
+
if (!$accessRequest || !$deleteRequest) {
|
126 |
+
$pluginData = Helper::getPluginData();
|
127 |
+
printf(
|
128 |
+
'<div class="%s"><p><strong>%s:</strong> %s %s</p></div>',
|
129 |
+
'notice notice-error',
|
130 |
+
$pluginData['Name'],
|
131 |
+
__('Couldn\'t create the required database tables.', WP_GDPR_C_SLUG),
|
132 |
+
sprintf(
|
133 |
+
'<a class="button" href="%s">%s</a>',
|
134 |
+
Helper::getPluginAdminUrl('', array('wpgdprc-action' => 'create_request_tables')),
|
135 |
+
__('Retry', WP_GDPR_C_SLUG)
|
136 |
+
)
|
137 |
+
);
|
138 |
+
}
|
139 |
+
}
|
140 |
+
}
|
141 |
+
|
142 |
+
public function addConsentBar() {
|
143 |
+
$consentBarColor = get_option(WP_GDPR_C_PREFIX . '_settings_consents_bar_color');
|
144 |
+
$consentBarTextColor = get_option(WP_GDPR_C_PREFIX . '_settings_consents_bar_text_color');
|
145 |
+
$consentBarButtonColor = get_option(WP_GDPR_C_PREFIX . '_settings_consents_bar_button_color_primary');
|
146 |
+
$consentBarButtonTextColor = get_option(WP_GDPR_C_PREFIX . '_settings_consents_bar_button_color_secondary');
|
147 |
+
$output = '<div class="wpgdprc wpgdprc-consent-bar" style="display: none; background: ' . $consentBarColor .'">';
|
148 |
+
$output .= '<div class="wpgdprc-consent-bar__container">';
|
149 |
+
$output .= '<div class="wpgdprc-consent-bar__content" style="color: ' . $consentBarTextColor .';">';
|
150 |
+
$output .= '<div class="wpgdprc-consent-bar__column">';
|
151 |
+
$output .= '<div class="wpgdprc-consent-bar__notice">';
|
152 |
+
$output .= apply_filters('wpgdprc_the_content', Consent::getBarExplanationText());
|
153 |
+
$output .= '</div>';
|
154 |
+
$output .= '</div>';
|
155 |
+
$output .= '<div class="wpgdprc-consent-bar__column">';
|
156 |
+
$output .= sprintf(
|
157 |
+
'<a class="wpgdprc-consent-bar__settings" href="javascript:void(0);" data-micromodal-trigger="wpgdprc-consent-modal">%s</a>',
|
158 |
+
esc_attr__('My settings', WP_GDPR_C_SLUG)
|
159 |
+
);
|
160 |
+
$output .= '</div>';
|
161 |
+
$output .= '<div class="wpgdprc-consent-bar__column">';
|
162 |
+
$output .= sprintf(
|
163 |
+
'<button class="wpgdprc-button wpgdprc-consent-bar__button" style="background: ' . $consentBarButtonColor .'; color: ' . $consentBarButtonTextColor . ';">%s</button>',
|
164 |
+
__('Accept', WP_GDPR_C_SLUG)
|
165 |
+
);
|
166 |
+
$output .= '</div>';
|
167 |
+
$output .= '</div>';
|
168 |
+
$output .= '</div>';
|
169 |
+
$output .= '</div>';
|
170 |
+
echo apply_filters('wpgdprc_consent_bar', $output);
|
171 |
+
}
|
172 |
+
|
173 |
+
public function addConsentModal() {
|
174 |
+
$consentModalButtonColor = get_option(WP_GDPR_C_PREFIX . '_settings_consents_bar_button_color_secondary');
|
175 |
+
$consentModalButtonTextColor = get_option(WP_GDPR_C_PREFIX . '_settings_consents_bar_button_color_primary');
|
176 |
+
$consentIds = (array)Helper::getConsentIdsByCookie();
|
177 |
+
$consents = Consent::getInstance()->getList(array(
|
178 |
+
'active' => array('value' => 1)
|
179 |
+
));
|
180 |
+
$output = '<div class="wpgdprc wpgdprc-consent-modal" id="wpgdprc-consent-modal" aria-hidden="true">';
|
181 |
+
$output .= '<div class="wpgdprc-consent-modal__overlay" tabindex="-1" data-micromodal-close>';
|
182 |
+
$output .= '<div class="wpgdprc-consent-modal__container" role="dialog" aria-modal="true">';
|
183 |
+
if (!empty($consents)) {
|
184 |
+
$output .= '<nav class="wpgdprc-consent-modal__navigation">';
|
185 |
+
/** @var Consent $consent */
|
186 |
+
foreach ($consents as $consent) {
|
187 |
+
$title = $consent->getTitle();
|
188 |
+
$output .= sprintf(
|
189 |
+
'<a class="wpgdprc-button" href="javascript:void(0);" data-target="%d">%s</a>',
|
190 |
+
$consent->getId(),
|
191 |
+
((!empty($title)) ? $title : __('(no title)', WP_GDPR_C_SLUG))
|
192 |
+
);
|
193 |
+
}
|
194 |
+
$output .= '</nav>'; // .wpgdprc-consent-modal__navigation
|
195 |
+
$output .= '<div class="wpgdprc-consent-modal__information">';
|
196 |
+
$output .= '<div class="wpgdprc-consent-modal__description">';
|
197 |
+
$output .= sprintf(
|
198 |
+
'<h3 class="wpgdprc-consent-modal__title">%s</h3>',
|
199 |
+
Consent::getModalTitle()
|
200 |
+
);
|
201 |
+
$output .= apply_filters('wpgdprc_the_content', Consent::getModalExplanationText());
|
202 |
+
$output .= apply_filters('wpgdprc_the_content', sprintf(
|
203 |
+
'<strong>%s:</strong> %s',
|
204 |
+
strtoupper(__('Note', WP_GDPR_C_SLUG)),
|
205 |
+
__('These settings will only apply to the browser and device you are currently using.', WP_GDPR_C_SLUG)
|
206 |
+
));
|
207 |
+
$output .= '</div>'; // .wpgdprc-consent-modal__description
|
208 |
+
/** @var Consent $consent */
|
209 |
+
foreach ($consents as $consent) {
|
210 |
+
$output .= sprintf(
|
211 |
+
'<div class="wpgdprc-consent-modal__description" style="display: none;" data-target="%d">',
|
212 |
+
$consent->getId()
|
213 |
+
);
|
214 |
+
$output .= sprintf('<h3 class="wpgdprc-consent-modal__title">%s</h3>', $consent->getTitle());
|
215 |
+
$output .= apply_filters('wpgdprc_the_content', $consent->getDescription());
|
216 |
+
if (!$consent->getRequired()) {
|
217 |
+
$output .= '<div class="wpgdprc-checkbox">';
|
218 |
+
$output .= '<label>';
|
219 |
+
$output .= sprintf(
|
220 |
+
'<input type="checkbox" value="%d" tabindex="1" %s />',
|
221 |
+
$consent->getId(),
|
222 |
+
checked(true, in_array($consent->getId(), $consentIds), false)
|
223 |
+
);
|
224 |
+
$output .= '<span class="wpgdprc-switch" aria-hidden="true">';
|
225 |
+
$output .= '<span class="wpgdprc-switch-label">';
|
226 |
+
$output .= '<span class="wpgdprc-switch-inner"></span>';
|
227 |
+
$output .= '<span class="wpgdprc-switch-switch"></span>';
|
228 |
+
$output .= '</span>';
|
229 |
+
$output .= '</span>';
|
230 |
+
$output .= __('Enable', WP_GDPR_C_SLUG);
|
231 |
+
$output .= '</label>';
|
232 |
+
$output .= '</div>';
|
233 |
+
}
|
234 |
+
$output .= '</div>'; // .wpgdprc-consent-modal__description
|
235 |
+
}
|
236 |
+
$output .= '<footer class="wpgdprc-consent-modal__footer">';
|
237 |
+
$output .= sprintf(
|
238 |
+
'<a class="wpgdprc-button wpgdprc-button--secondary" href="javascript:void(0);" style="background: ' . $consentModalButtonColor . '; color: ' . $consentModalButtonTextColor . ';">%s</a>',
|
239 |
+
__('Save my settings', WP_GDPR_C_SLUG)
|
240 |
+
);
|
241 |
+
$output .= '</footer>'; // .wpgdprc-consent-modal__footer
|
242 |
+
$output .= '</div>'; // .wpgdprc-consent-modal__information
|
243 |
+
}
|
244 |
+
$output .= sprintf(
|
245 |
+
'<button class="wpgdprc-consent-modal__close" aria-label="%s" data-micromodal-close>✕</button>',
|
246 |
+
esc_attr__('Close modal', WP_GDPR_C_SLUG)
|
247 |
+
);
|
248 |
+
$output .= '</div>'; // .wpgdprc-consent-modal__container
|
249 |
+
$output .= '</div>'; // .wpgdprc-consent-modal__overlay
|
250 |
+
$output .= '</div>'; // #wpgdprc-consent-modal
|
251 |
+
echo $output;
|
252 |
+
}
|
253 |
+
|
254 |
+
public function addConsentsToHead() {
|
255 |
+
$consentIds = Helper::getConsentIdsByCookie();
|
256 |
+
if (empty($consentIds)) {
|
257 |
+
return;
|
258 |
+
}
|
259 |
+
$args = array(
|
260 |
+
'placement' => array(
|
261 |
+
'value' => 'head'
|
262 |
+
),
|
263 |
+
'active' => array(
|
264 |
+
'value' => 1
|
265 |
+
),
|
266 |
+
'ID' => array(
|
267 |
+
'value' => $consentIds,
|
268 |
+
'compare' => 'IN'
|
269 |
+
)
|
270 |
+
);
|
271 |
+
$consents = Consent::getInstance()->getList($args);
|
272 |
+
echo Consent::output($consents);
|
273 |
+
}
|
274 |
+
|
275 |
+
public function addConsentsToFooter() {
|
276 |
+
$consentIds = Helper::getConsentIdsByCookie();
|
277 |
+
if (empty($consentIds)) {
|
278 |
+
return;
|
279 |
+
}
|
280 |
+
$args = array(
|
281 |
+
'placement' => array(
|
282 |
+
'value' => 'footer'
|
283 |
+
),
|
284 |
+
'active' => array(
|
285 |
+
'value' => 1
|
286 |
+
),
|
287 |
+
'ID' => array(
|
288 |
+
'value' => $consentIds,
|
289 |
+
'compare' => 'IN'
|
290 |
+
)
|
291 |
+
);
|
292 |
+
$consents = Consent::getInstance()->getList($args);
|
293 |
+
echo Consent::output($consents);
|
294 |
+
}
|
295 |
+
|
296 |
+
public function addTagsToFields() {
|
297 |
+
// Contact Form 7
|
298 |
+
if (Helper::isEnabled(CF7::ID)) {
|
299 |
+
CF7::getInstance()->addFormTagToForms();
|
300 |
+
CF7::getInstance()->addAcceptedDateToForms();
|
301 |
+
}
|
302 |
+
|
303 |
+
// Gravity Forms
|
304 |
+
if (Helper::isEnabled(GForms::ID)) {
|
305 |
+
foreach (GForms::getInstance()->getForms() as $form) {
|
306 |
+
if (in_array($form['id'], GForms::getInstance()->getEnabledForms())) {
|
307 |
+
GForms::getInstance()->addField($form);
|
308 |
+
}
|
309 |
+
}
|
310 |
+
}
|
311 |
+
}
|
312 |
+
|
313 |
+
public function removeTagsFromFields() {
|
314 |
+
// Contact Form 7
|
315 |
+
if (Helper::isEnabled(CF7::ID)) {
|
316 |
+
CF7::getInstance()->removeFormTagFromForms();
|
317 |
+
CF7::getInstance()->removeAcceptedDateFromForms();
|
318 |
+
}
|
319 |
+
|
320 |
+
// Gravity Forms
|
321 |
+
if (Helper::isEnabled(GForms::ID)) {
|
322 |
+
foreach (GForms::getInstance()->getForms() as $form) {
|
323 |
+
if (in_array($form['id'], GForms::getInstance()->getEnabledForms())) {
|
324 |
+
GForms::getInstance()->removeField($form);
|
325 |
+
}
|
326 |
+
}
|
327 |
+
}
|
328 |
+
}
|
329 |
+
|
330 |
+
/**
|
331 |
+
* @return null|Action
|
332 |
+
*/
|
333 |
+
public static function getInstance() {
|
334 |
+
if (!isset(self::$instance)) {
|
335 |
+
self::$instance = new self();
|
336 |
+
}
|
337 |
+
return self::$instance;
|
338 |
+
}
|
339 |
}
|
Includes/Ajax.php
CHANGED
@@ -1,452 +1,452 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WPGDPRC\Includes;
|
4 |
-
|
5 |
-
/**
|
6 |
-
* Class Ajax
|
7 |
-
* @package WPGDPRC\Includes
|
8 |
-
*/
|
9 |
-
class Ajax {
|
10 |
-
/** @var null */
|
11 |
-
private static $instance = null;
|
12 |
-
|
13 |
-
public function processSettings() {
|
14 |
-
check_ajax_referer('wpgdprc', 'security');
|
15 |
-
|
16 |
-
$output = array(
|
17 |
-
'message' => '',
|
18 |
-
'error' => '',
|
19 |
-
);
|
20 |
-
$data = (isset($_POST['data']) && (is_array($_POST['data']) || is_string($_POST['data']))) ? $_POST['data'] : false;
|
21 |
-
if (is_string($data)) {
|
22 |
-
$data = json_decode(stripslashes($data), true);
|
23 |
-
}
|
24 |
-
|
25 |
-
if (!$data) {
|
26 |
-
$output['error'] = __('Missing data.', WP_GDPR_C_SLUG);
|
27 |
-
}
|
28 |
-
|
29 |
-
if (empty($output['error'])) {
|
30 |
-
$option = (isset($data['option']) && is_string($data['option'])) ? esc_html($data['option']) : false;
|
31 |
-
$value = (isset($data['value'])) ? self::sanitizeValue($data['value']) : false;
|
32 |
-
$enabled = (isset($data['enabled'])) ? filter_var($data['enabled'], FILTER_VALIDATE_BOOLEAN) : false;
|
33 |
-
$append = (isset($data['append'])) ? filter_var($data['append'], FILTER_VALIDATE_BOOLEAN) : false;
|
34 |
-
|
35 |
-
if (!$option) {
|
36 |
-
$output['error'] = __('Missing option name.', WP_GDPR_C_SLUG);
|
37 |
-
}
|
38 |
-
|
39 |
-
if (!current_user_can('manage_options')) {
|
40 |
-
$output['error'] = __('You\'re not allowed to manage settings.', WP_GDPR_C_SLUG);
|
41 |
-
}
|
42 |
-
|
43 |
-
if (!in_array($option, Helper::getAvailableOptions())) {
|
44 |
-
$output['error'] = __('You\'re not allowed to manage this setting.', WP_GDPR_C_SLUG);
|
45 |
-
}
|
46 |
-
|
47 |
-
if (!isset($data['value'])) {
|
48 |
-
$output['error'] = __('Missing value.', WP_GDPR_C_SLUG);
|
49 |
-
}
|
50 |
-
|
51 |
-
// Let's do this!
|
52 |
-
if (empty($output['error'])) {
|
53 |
-
if ($append) {
|
54 |
-
$values = (array)get_option($option, array());
|
55 |
-
if ($enabled) {
|
56 |
-
if (!in_array($value, $values)) {
|
57 |
-
$values[] = $value;
|
58 |
-
}
|
59 |
-
} else {
|
60 |
-
$index = array_search($value, $values);
|
61 |
-
if ($index !== false) {
|
62 |
-
unset($values[$index]);
|
63 |
-
}
|
64 |
-
}
|
65 |
-
$value = $values;
|
66 |
-
} else {
|
67 |
-
if (isset($data['enabled'])) {
|
68 |
-
$value = $enabled;
|
69 |
-
}
|
70 |
-
}
|
71 |
-
update_option($option, $value);
|
72 |
-
do_action($option, $value);
|
73 |
-
}
|
74 |
-
}
|
75 |
-
|
76 |
-
header('Content-type: application/json');
|
77 |
-
echo json_encode($output);
|
78 |
-
die();
|
79 |
-
}
|
80 |
-
|
81 |
-
public function processAction() {
|
82 |
-
check_ajax_referer('wpgdprc', 'security');
|
83 |
-
|
84 |
-
$output = array(
|
85 |
-
'message' => '',
|
86 |
-
'error' => '',
|
87 |
-
);
|
88 |
-
$data = (isset($_POST['data']) && (is_array($_POST['data']) || is_string($_POST['data']))) ? $_POST['data'] : false;
|
89 |
-
if (is_string($data)) {
|
90 |
-
$data = json_decode(stripslashes($data), true);
|
91 |
-
}
|
92 |
-
$type = (isset($data['type']) && is_string($data['type'])) ? esc_html($data['type']) : false;
|
93 |
-
|
94 |
-
if (!$data) {
|
95 |
-
$output['error'] = __('Missing data.', WP_GDPR_C_SLUG);
|
96 |
-
}
|
97 |
-
|
98 |
-
if (!$type) {
|
99 |
-
$output['error'] = __('Missing type.', WP_GDPR_C_SLUG);
|
100 |
-
}
|
101 |
-
|
102 |
-
if (empty($output['error'])) {
|
103 |
-
switch ($type) {
|
104 |
-
case 'access_request' :
|
105 |
-
if (Helper::isEnabled('enable_access_request', 'settings')) {
|
106 |
-
$emailAddress = (isset($data['email']) && is_email($data['email'])) ? $data['email'] : false;
|
107 |
-
$consent = (isset($data['consent'])) ? filter_var($data['consent'], FILTER_VALIDATE_BOOLEAN) : false;
|
108 |
-
|
109 |
-
if (!$emailAddress) {
|
110 |
-
$output['error'] = __('Missing or incorrect email address.', WP_GDPR_C_SLUG);
|
111 |
-
}
|
112 |
-
|
113 |
-
if (!$consent) {
|
114 |
-
$output['error'] = __('You need to accept the privacy checkbox.', WP_GDPR_C_SLUG);
|
115 |
-
}
|
116 |
-
|
117 |
-
// Let's do this!
|
118 |
-
if (empty($output['error'])) {
|
119 |
-
if (!AccessRequest::getInstance()->existsByEmailAddress($emailAddress, true)) {
|
120 |
-
$request = new AccessRequest();
|
121 |
-
$request->setSiteId(get_current_blog_id());
|
122 |
-
$request->setEmailAddress($emailAddress);
|
123 |
-
$request->setSessionId(SessionHelper::getSessionId());
|
124 |
-
$request->setIpAddress(Helper::getClientIpAddress());
|
125 |
-
$request->setToken(substr(md5(openssl_random_pseudo_bytes(20)), -32));
|
126 |
-
$request->setExpired(0);
|
127 |
-
$id = $request->save();
|
128 |
-
if ($id !== false) {
|
129 |
-
$page = Helper::getAccessRequestPage();
|
130 |
-
if (!empty($page)) {
|
131 |
-
$deleteRequestPage = sprintf(
|
132 |
-
'<a target="_blank" href="%s">%s</a>',
|
133 |
-
add_query_arg(
|
134 |
-
array(
|
135 |
-
'wpgdprc' => urlencode($request->getToken())
|
136 |
-
),
|
137 |
-
get_permalink($page)
|
138 |
-
),
|
139 |
-
__('page', WP_GDPR_C_SLUG)
|
140 |
-
);
|
141 |
-
$siteName = Helper::getSiteData('blogname', $request->getSiteId());
|
142 |
-
$siteEmail = Helper::getSiteData('admin_email', $request->getSiteId());
|
143 |
-
$siteUrl = Helper::getSiteData('siteurl', $request->getSiteId());
|
144 |
-
$subject = apply_filters(
|
145 |
-
'wpgdprc_access_request_mail_subject',
|
146 |
-
sprintf(__('%s - Your data request', WP_GDPR_C_SLUG), $siteName),
|
147 |
-
$request,
|
148 |
-
$siteName
|
149 |
-
);
|
150 |
-
|
151 |
-
$message = sprintf(
|
152 |
-
__('You have requested to access your data on %s.', WP_GDPR_C_SLUG),
|
153 |
-
sprintf('<a target="_blank" href="%s">%s</a>', $siteUrl, $siteName)
|
154 |
-
) . '<br /><br />';
|
155 |
-
$message .= sprintf(
|
156 |
-
__('Please visit this %s to view the data linked to the email address %s.', WP_GDPR_C_SLUG),
|
157 |
-
$deleteRequestPage,
|
158 |
-
$emailAddress
|
159 |
-
) . '<br /><br />';
|
160 |
-
$message .= __('This page is available for 24 hours and can only be reached from the same device, IP address and browser session you requested from.', WP_GDPR_C_SLUG) . '<br /><br />';
|
161 |
-
$message .= sprintf(
|
162 |
-
__('If your link is invalid you can fill in a new request after 24 hours: %s.', WP_GDPR_C_SLUG),
|
163 |
-
sprintf(
|
164 |
-
'<a target="_blank" href="%s">%s</a>',
|
165 |
-
get_permalink($page),
|
166 |
-
get_the_title($page)
|
167 |
-
)
|
168 |
-
);
|
169 |
-
$message = apply_filters('wpgdprc_access_request_mail_content', $message, $request, $deleteRequestPage);
|
170 |
-
$headers = array(
|
171 |
-
'Content-Type: text/html; charset=UTF-8',
|
172 |
-
"From: $siteName <$siteEmail>"
|
173 |
-
);
|
174 |
-
$response = wp_mail($emailAddress, $subject, $message, $headers);
|
175 |
-
if ($response !== false) {
|
176 |
-
$output['message'] = __('Success. You will receive an email with your data shortly.', WP_GDPR_C_SLUG);
|
177 |
-
}
|
178 |
-
}
|
179 |
-
} else {
|
180 |
-
$output['error'] = __('Something went wrong while saving the request. Please try again.', WP_GDPR_C_SLUG);
|
181 |
-
}
|
182 |
-
} else {
|
183 |
-
$output['error'] = __('You have already requested your data. Please check your mailbox. After 24 hours you can put in a new request.', WP_GDPR_C_SLUG);
|
184 |
-
}
|
185 |
-
}
|
186 |
-
}
|
187 |
-
break;
|
188 |
-
case 'delete_request' :
|
189 |
-
if (Helper::isEnabled('enable_access_request', 'settings')) {
|
190 |
-
$token = (isset($data['token'])) ? esc_html(urldecode($data['token'])) : false;
|
191 |
-
$settings = (isset($data['settings']) && is_array($data['settings'])) ? $data['settings'] : array();
|
192 |
-
$type = (isset($settings['type']) && in_array($settings['type'], Data::getPossibleDataTypes())) ? $settings['type'] : '';
|
193 |
-
$value = (isset($data['value']) && is_numeric($data['value'])) ? (int)$data['value'] : 0;
|
194 |
-
|
195 |
-
if (empty($token)) {
|
196 |
-
$output['error'] = __('Missing token.', WP_GDPR_C_SLUG);
|
197 |
-
}
|
198 |
-
|
199 |
-
if (empty($type)) {
|
200 |
-
$output['error'] = __('Missing or invalid type.', WP_GDPR_C_SLUG);
|
201 |
-
}
|
202 |
-
|
203 |
-
if ($value === 0) {
|
204 |
-
$output['error'] = __('No value selected.', WP_GDPR_C_SLUG);
|
205 |
-
}
|
206 |
-
|
207 |
-
// Let's do this!
|
208 |
-
if (empty($output['error'])) {
|
209 |
-
$accessRequest = ($token !== false) ? AccessRequest::getInstance()->getByToken($token) : false;
|
210 |
-
if ($accessRequest !== false) {
|
211 |
-
if (
|
212 |
-
SessionHelper::checkSession($accessRequest->getSessionId()) &&
|
213 |
-
Helper::checkIpAddress($accessRequest->getIpAddress())
|
214 |
-
) {
|
215 |
-
$request = new DeleteRequest();
|
216 |
-
$request->setSiteId(get_current_blog_id());
|
217 |
-
$request->setAccessRequestId($accessRequest->getId());
|
218 |
-
$request->setSessionId($accessRequest->getSessionId());
|
219 |
-
$request->setIpAddress($accessRequest->getIpAddress());
|
220 |
-
$request->setDataId($value);
|
221 |
-
$request->setType($type);
|
222 |
-
$id = $request->save();
|
223 |
-
if ($id === false) {
|
224 |
-
$output['error'] = __('Something went wrong while saving this request. Please try again.', WP_GDPR_C_SLUG);
|
225 |
-
} else {
|
226 |
-
$siteName = Helper::getSiteData('blogname', $request->getSiteId());
|
227 |
-
$siteEmail = Helper::getSiteData('admin_email', $request->getSiteId());
|
228 |
-
$siteUrl = Helper::getSiteData('siteurl', $request->getSiteId());
|
229 |
-
$adminPage = sprintf(
|
230 |
-
'<a target="_blank" href="%s">%s</a>',
|
231 |
-
Helper::getPluginAdminUrl('requests'),
|
232 |
-
__('Requests', WP_GDPR_C_SLUG)
|
233 |
-
);
|
234 |
-
$subject = apply_filters(
|
235 |
-
'wpgdprc_delete_request_admin_mail_subject',
|
236 |
-
sprintf(__('%s - New anonymise request', WP_GDPR_C_SLUG), $siteName),
|
237 |
-
$request,
|
238 |
-
$siteName
|
239 |
-
);
|
240 |
-
$message = sprintf(
|
241 |
-
__('You have received a new anonymise request on %s.', WP_GDPR_C_SLUG),
|
242 |
-
sprintf('<a target="_blank" href="%s">%s</a>', $siteUrl, $siteName)
|
243 |
-
) . '<br /><br />';
|
244 |
-
$message .= sprintf(
|
245 |
-
__('You can manage this request in the admin panel: %s', WP_GDPR_C_SLUG),
|
246 |
-
$adminPage
|
247 |
-
);
|
248 |
-
$message = apply_filters('wpgdprc_delete_request_admin_mail_content', $message, $request, $adminPage);
|
249 |
-
$headers = array(
|
250 |
-
'Content-Type: text/html; charset=UTF-8',
|
251 |
-
"From: $siteName <$siteEmail>"
|
252 |
-
);
|
253 |
-
wp_mail($siteEmail, $subject, $message, $headers);
|
254 |
-
}
|
255 |
-
} else {
|
256 |
-
$output['error'] = __('Session doesn\'t match.', WP_GDPR_C_SLUG);
|
257 |
-
}
|
258 |
-
} else {
|
259 |
-
$output['error'] = __('No session found.', WP_GDPR_C_SLUG);
|
260 |
-
}
|
261 |
-
}
|
262 |
-
}
|
263 |
-
break;
|
264 |
-
}
|
265 |
-
}
|
266 |
-
|
267 |
-
header('Content-type: application/json');
|
268 |
-
echo json_encode($output);
|
269 |
-
die();
|
270 |
-
}
|
271 |
-
|
272 |
-
public function processDeleteRequest() {
|
273 |
-
check_ajax_referer('wpgdprc', 'security');
|
274 |
-
|
275 |
-
$output = array(
|
276 |
-
'message' => '',
|
277 |
-
'error' => '',
|
278 |
-
);
|
279 |
-
|
280 |
-
if (!Helper::isEnabled('enable_access_request', 'settings')) {
|
281 |
-
$output['error'] = __('The access request functionality is not enabled.', WP_GDPR_C_SLUG);
|
282 |
-
}
|
283 |
-
|
284 |
-
$data = (isset($_POST['data']) && (is_array($_POST['data']) || is_string($_POST['data']))) ? $_POST['data'] : false;
|
285 |
-
if (is_string($data)) {
|
286 |
-
$data = json_decode(stripslashes($data), true);
|
287 |
-
}
|
288 |
-
$id = (isset($data['id']) && is_numeric($data['id'])) ? absint($data['id']) : 0;
|
289 |
-
|
290 |
-
if (!$data) {
|
291 |
-
$output['error'] = __('Missing data.', WP_GDPR_C_SLUG);
|
292 |
-
}
|
293 |
-
|
294 |
-
if ($id === 0 || !DeleteRequest::getInstance()->exists($id)) {
|
295 |
-
$output['error'] = __('This request doesn\'t exist.', WP_GDPR_C_SLUG);
|
296 |
-
}
|
297 |
-
|
298 |
-
// Let's do this!
|
299 |
-
if (empty($output['error'])) {
|
300 |
-
$request = new DeleteRequest($id);
|
301 |
-
if (!$request->getProcessed()) {
|
302 |
-
switch ($request->getType()) {
|
303 |
-
case 'user' :
|
304 |
-
global $wpdb;
|
305 |
-
if (current_user_can('edit_users')) {
|
306 |
-
$date = Helper::localDateTime( time() );
|
307 |
-
$result = wp_update_user( array(
|
308 |
-
'ID' => $request->getDataId(),
|
309 |
-
'user_pass' => wp_generate_password( 30 ),
|
310 |
-
'display_name' => 'DISPLAY_NAME',
|
311 |
-
'user_nicename' => 'NICENAME' . $request->getDataId(),
|
312 |
-
'first_name' => 'FIRST_NAME',
|
313 |
-
'last_name' => 'LAST_NAME',
|
314 |
-
'user_email' => $request->getDataId() . '.' . $date->format( 'Ymd.His' ) . '@example.org'
|
315 |
-
) );
|
316 |
-
if ( is_wp_error( $result ) ) {
|
317 |
-
$output['error'] = __( 'This user doesn\'t exist.', WP_GDPR_C_SLUG );
|
318 |
-
} else {
|
319 |
-
$wpdb->update( $wpdb->users, array( 'user_login' => 'USERNAME_' . $date->format( 'Ymd.His' ) ), array( 'ID' => $request->getDataId() ) );
|
320 |
-
$request->setProcessed( 1 );
|
321 |
-
$request->save();
|
322 |
-
}
|
323 |
-
} else {
|
324 |
-
$output['error'] = __('You\'re not allowed to edit users.', WP_GDPR_C_SLUG);
|
325 |
-
}
|
326 |
-
break;
|
327 |
-
case 'comment' :
|
328 |
-
if (current_user_can('edit_posts')) {
|
329 |
-
$date = Helper::localDateTime(time());
|
330 |
-
$result = wp_update_comment(array(
|
331 |
-
'comment_ID' => $request->getDataId(),
|
332 |
-
'comment_author' => 'NAME',
|
333 |
-
'comment_author_email' => $request->getDataId() . '.' . $date->format('Ymd.His') . '@example.org',
|
334 |
-
'comment_author_IP' => '127.0.0.1'
|
335 |
-
));
|
336 |
-
if ($result === 0) {
|
337 |
-
$output['error'] = __('This comment doesn\'t exist.', WP_GDPR_C_SLUG);
|
338 |
-
} else {
|
339 |
-
$request->setProcessed(1);
|
340 |
-
$request->save();
|
341 |
-
}
|
342 |
-
} else {
|
343 |
-
$output['error'] = __('You\'re not allowed to edit comments.', WP_GDPR_C_SLUG);
|
344 |
-
}
|
345 |
-
break;
|
346 |
-
case 'woocommerce_order' :
|
347 |
-
if (current_user_can('edit_shop_orders')) {
|
348 |
-
$date = Helper::localDateTime(time());
|
349 |
-
$userId = get_post_meta($request->getDataId(), '_customer_user', true);
|
350 |
-
update_post_meta($request->getDataId(), '_billing_first_name', 'FIRST_NAME');
|
351 |
-
update_post_meta($request->getDataId(), '_billing_last_name', 'LAST_NAME');
|
352 |
-
update_post_meta($request->getDataId(), '_billing_company', 'COMPANY_NAME');
|
353 |
-
update_post_meta($request->getDataId(), '_billing_address_1', 'ADDRESS_1');
|
354 |
-
update_post_meta($request->getDataId(), '_billing_address_2', 'ADDRESS_2');
|
355 |
-
update_post_meta($request->getDataId(), '_billing_postcode', 'ZIP_CODE');
|
356 |
-
update_post_meta($request->getDataId(), '_billing_city', 'CITY');
|
357 |
-
update_post_meta($request->getDataId(), '_billing_phone', 'PHONE_NUMBER');
|
358 |
-
update_post_meta($request->getDataId(), '_billing_email', $request->getDataId() . '.' . $date->format('Ymd') . '.' . $date->format('His') . '@example.org');
|
359 |
-
update_post_meta($request->getDataId(), '_shipping_first_name', 'FIRST_NAME');
|
360 |
-
update_post_meta($request->getDataId(), '_shipping_last_name', 'LAST_NAME');
|
361 |
-
update_post_meta($request->getDataId(), '_shipping_company', 'COMPANY_NAME');
|
362 |
-
update_post_meta($request->getDataId(), '_shipping_address_1', 'ADDRESS_1');
|
363 |
-
update_post_meta($request->getDataId(), '_shipping_address_2', 'ADDRESS_2');
|
364 |
-
update_post_meta($request->getDataId(), '_shipping_postcode', 'ZIP_CODE');
|
365 |
-
update_post_meta($request->getDataId(), '_shipping_city', 'CITY');
|
366 |
-
if (!empty($userId) && get_user_by('id', $userId) !== false) {
|
367 |
-
update_user_meta($userId, 'billing_first_name', 'FIRST_NAME');
|
368 |
-
update_user_meta($userId, 'billing_last_name', 'LAST_NAME');
|
369 |
-
update_user_meta($userId, 'billing_company', 'COMPANY_NAME');
|
370 |
-
update_user_meta($userId, 'billing_address_1', 'ADDRESS_1');
|
371 |
-
update_user_meta($userId, 'billing_address_2', 'ADDRESS_2');
|
372 |
-
update_user_meta($userId, 'billing_postcode', 'ZIP_CODE');
|
373 |
-
update_user_meta($userId, 'billing_city', 'CITY');
|
374 |
-
update_user_meta($userId, 'billing_phone', 'PHONE_NUMBER');
|
375 |
-
update_user_meta($userId, 'billing_email', $request->getDataId() . '.' . $date->format('Ymd') . '.' . $date->format('His') . '@example.org');
|
376 |
-
update_user_meta($userId, 'shipping_first_name', 'FIRST_NAME');
|
377 |
-
update_user_meta($userId, 'shipping_last_name', 'LAST_NAME');
|
378 |
-
update_user_meta($userId, 'shipping_company', 'COMPANY_NAME');
|
379 |
-
update_user_meta($userId, 'shipping_address_1', 'ADDRESS_1');
|
380 |
-
update_user_meta($userId, 'shipping_address_2', 'ADDRESS_2');
|
381 |
-
update_user_meta($userId, 'shipping_postcode', 'ZIP_CODE');
|
382 |
-
update_user_meta($userId, 'shipping_city', 'CITY');
|
383 |
-
}
|
384 |
-
$request->setProcessed(1);
|
385 |
-
$request->save();
|
386 |
-
} else {
|
387 |
-
$output['error'] = __('You\'re not allowed to edit WooCommerce orders.', WP_GDPR_C_SLUG);
|
388 |
-
}
|
389 |
-
break;
|
390 |
-
}
|
391 |
-
|
392 |
-
if (empty($output['error']) && $request->getProcessed()) {
|
393 |
-
$accessRequest = new AccessRequest($request->getAccessRequestId());
|
394 |
-
$siteName = Helper::getSiteData('blogname', $request->getSiteId());
|
395 |
-
$siteEmail = Helper::getSiteData('admin_email', $request->getSiteId());
|
396 |
-
$siteUrl = Helper::getSiteData('siteurl', $request->getSiteId());
|
397 |
-
$subject = apply_filters(
|
398 |
-
'wpgdprc_delete_request_mail_subject',
|
399 |
-
sprintf(__('%s - Your request', WP_GDPR_C_SLUG), $siteName),
|
400 |
-
$request,
|
401 |
-
$accessRequest
|
402 |
-
);
|
403 |
-
$message = sprintf(
|
404 |
-
__('We have successfully processed your request and your data has been anonymised on %s.', WP_GDPR_C_SLUG),
|
405 |
-
sprintf('<a target="_blank" href="%s">%s</a>', $siteUrl, $siteName)
|
406 |
-
) . '<br /><br />';
|
407 |
-
$message .= __('The following has been processed:', WP_GDPR_C_SLUG) . '<br />';
|
408 |
-
$message .= sprintf('%s #%d with email address %s.', $request->getNiceTypeLabel(), $request->getDataId(), $accessRequest->getEmailAddress());
|
409 |
-
$message = apply_filters('wpgdprc_delete_request_mail_content', $message, $request, $accessRequest);
|
410 |
-
$headers = array(
|
411 |
-
'Content-Type: text/html; charset=UTF-8',
|
412 |
-
"From: $siteName <$siteEmail>"
|
413 |
-
);
|
414 |
-
$response = wp_mail($accessRequest->getEmailAddress(), $subject, $message, $headers);
|
415 |
-
if ($response !== false) {
|
416 |
-
$output['message'] = __('Successfully sent an confirmation mail to the user.', WP_GDPR_C_SLUG);
|
417 |
-
}
|
418 |
-
}
|
419 |
-
} else {
|
420 |
-
$output['error'] = __('This request has already been processed.', WP_GDPR_C_SLUG);
|
421 |
-
}
|
422 |
-
}
|
423 |
-
|
424 |
-
header('Content-type: application/json');
|
425 |
-
echo json_encode($output);
|
426 |
-
die();
|
427 |
-
}
|
428 |
-
|
429 |
-
/**
|
430 |
-
* @param $value
|
431 |
-
* @return mixed
|
432 |
-
*/
|
433 |
-
private static function sanitizeValue($value) {
|
434 |
-
if (is_numeric($value)) {
|
435 |
-
$value = intval($value);
|
436 |
-
}
|
437 |
-
if (is_string($value)) {
|
438 |
-
$value = esc_html($value);
|
439 |
-
}
|
440 |
-
return $value;
|
441 |
-
}
|
442 |
-
|
443 |
-
/**
|
444 |
-
* @return null|Ajax
|
445 |
-
*/
|
446 |
-
public static function getInstance() {
|
447 |
-
if (!isset(self::$instance)) {
|
448 |
-
self::$instance = new self();
|
449 |
-
}
|
450 |
-
return self::$instance;
|
451 |
-
}
|
452 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WPGDPRC\Includes;
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Class Ajax
|
7 |
+
* @package WPGDPRC\Includes
|
8 |
+
*/
|
9 |
+
class Ajax {
|
10 |
+
/** @var null */
|
11 |
+
private static $instance = null;
|
12 |
+
|
13 |
+
public function processSettings() {
|
14 |
+
check_ajax_referer('wpgdprc', 'security');
|
15 |
+
|
16 |
+
$output = array(
|
17 |
+
'message' => '',
|
18 |
+
'error' => '',
|
19 |
+
);
|
20 |
+
$data = (isset($_POST['data']) && (is_array($_POST['data']) || is_string($_POST['data']))) ? $_POST['data'] : false;
|
21 |
+
if (is_string($data)) {
|
22 |
+
$data = json_decode(stripslashes($data), true);
|
23 |
+
}
|
24 |
+
|
25 |
+
if (!$data) {
|
26 |
+
$output['error'] = __('Missing data.', WP_GDPR_C_SLUG);
|
27 |
+
}
|
28 |
+
|
29 |
+
if (empty($output['error'])) {
|
30 |
+
$option = (isset($data['option']) && is_string($data['option'])) ? esc_html($data['option']) : false;
|
31 |
+
$value = (isset($data['value'])) ? self::sanitizeValue($data['value']) : false;
|
32 |
+
$enabled = (isset($data['enabled'])) ? filter_var($data['enabled'], FILTER_VALIDATE_BOOLEAN) : false;
|
33 |
+
$append = (isset($data['append'])) ? filter_var($data['append'], FILTER_VALIDATE_BOOLEAN) : false;
|
34 |
+
|
35 |
+
if (!$option) {
|
36 |
+
$output['error'] = __('Missing option name.', WP_GDPR_C_SLUG);
|
37 |
+
}
|
38 |
+
|
39 |
+
if (!current_user_can('manage_options')) {
|
40 |
+
$output['error'] = __('You\'re not allowed to manage settings.', WP_GDPR_C_SLUG);
|
41 |
+
}
|
42 |
+
|
43 |
+
if (!in_array($option, Helper::getAvailableOptions())) {
|
44 |
+
$output['error'] = __('You\'re not allowed to manage this setting.', WP_GDPR_C_SLUG);
|
45 |
+
}
|
46 |
+
|
47 |
+
if (!isset($data['value'])) {
|
48 |
+
$output['error'] = __('Missing value.', WP_GDPR_C_SLUG);
|
49 |
+
}
|
50 |
+
|
51 |
+
// Let's do this!
|
52 |
+
if (empty($output['error'])) {
|
53 |
+
if ($append) {
|
54 |
+
$values = (array)get_option($option, array());
|
55 |
+
if ($enabled) {
|
56 |
+
if (!in_array($value, $values)) {
|
57 |
+
$values[] = $value;
|
58 |
+
}
|
59 |
+
} else {
|
60 |
+
$index = array_search($value, $values);
|
61 |
+
if ($index !== false) {
|
62 |
+
unset($values[$index]);
|
63 |
+
}
|
64 |
+
}
|
65 |
+
$value = $values;
|
66 |
+
} else {
|
67 |
+
if (isset($data['enabled'])) {
|
68 |
+
$value = $enabled;
|
69 |
+
}
|
70 |
+
}
|
71 |
+
update_option($option, $value);
|
72 |
+
do_action($option, $value);
|
73 |
+
}
|
74 |
+
}
|
75 |
+
|
76 |
+
header('Content-type: application/json');
|
77 |
+
echo json_encode($output);
|
78 |
+
die();
|
79 |
+
}
|
80 |
+
|
81 |
+
public function processAction() {
|
82 |
+
check_ajax_referer('wpgdprc', 'security');
|
83 |
+
|
84 |
+
$output = array(
|
85 |
+
'message' => '',
|
86 |
+
'error' => '',
|
87 |
+
);
|
88 |
+
$data = (isset($_POST['data']) && (is_array($_POST['data']) || is_string($_POST['data']))) ? $_POST['data'] : false;
|
89 |
+
if (is_string($data)) {
|
90 |
+
$data = json_decode(stripslashes($data), true);
|
91 |
+
}
|
92 |
+
$type = (isset($data['type']) && is_string($data['type'])) ? esc_html($data['type']) : false;
|
93 |
+
|
94 |
+
if (!$data) {
|
95 |
+
$output['error'] = __('Missing data.', WP_GDPR_C_SLUG);
|
96 |
+
}
|
97 |
+
|
98 |
+
if (!$type) {
|
99 |
+
$output['error'] = __('Missing type.', WP_GDPR_C_SLUG);
|
100 |
+
}
|
101 |
+
|
102 |
+
if (empty($output['error'])) {
|
103 |
+
switch ($type) {
|
104 |
+
case 'access_request' :
|
105 |
+
if (Helper::isEnabled('enable_access_request', 'settings')) {
|
106 |
+
$emailAddress = (isset($data['email']) && is_email($data['email'])) ? $data['email'] : false;
|
107 |
+
$consent = (isset($data['consent'])) ? filter_var($data['consent'], FILTER_VALIDATE_BOOLEAN) : false;
|
108 |
+
|
109 |
+
if (!$emailAddress) {
|
110 |
+
$output['error'] = __('Missing or incorrect email address.', WP_GDPR_C_SLUG);
|
111 |
+
}
|
112 |
+
|
113 |
+
if (!$consent) {
|
114 |
+
$output['error'] = __('You need to accept the privacy checkbox.', WP_GDPR_C_SLUG);
|
115 |
+
}
|
116 |
+
|
117 |
+
// Let's do this!
|
118 |
+
if (empty($output['error'])) {
|
119 |
+
if (!AccessRequest::getInstance()->existsByEmailAddress($emailAddress, true)) {
|
120 |
+
$request = new AccessRequest();
|
121 |
+
$request->setSiteId(get_current_blog_id());
|
122 |
+
$request->setEmailAddress($emailAddress);
|
123 |
+
$request->setSessionId(SessionHelper::getSessionId());
|
124 |
+
$request->setIpAddress(Helper::getClientIpAddress());
|
125 |
+
$request->setToken(substr(md5(openssl_random_pseudo_bytes(20)), -32));
|
126 |
+
$request->setExpired(0);
|
127 |
+
$id = $request->save();
|
128 |
+
if ($id !== false) {
|
129 |
+
$page = Helper::getAccessRequestPage();
|
130 |
+
if (!empty($page)) {
|
131 |
+
$deleteRequestPage = sprintf(
|
132 |
+
'<a target="_blank" href="%s">%s</a>',
|
133 |
+
add_query_arg(
|
134 |
+
array(
|
135 |
+
'wpgdprc' => urlencode($request->getToken())
|
136 |
+
),
|
137 |
+
get_permalink($page)
|
138 |
+
),
|
139 |
+
__('page', WP_GDPR_C_SLUG)
|
140 |
+
);
|
141 |
+
$siteName = Helper::getSiteData('blogname', $request->getSiteId());
|
142 |
+
$siteEmail = Helper::getSiteData('admin_email', $request->getSiteId());
|
143 |
+
$siteUrl = Helper::getSiteData('siteurl', $request->getSiteId());
|
144 |
+
$subject = apply_filters(
|
145 |
+
'wpgdprc_access_request_mail_subject',
|
146 |
+
sprintf(__('%s - Your data request', WP_GDPR_C_SLUG), $siteName),
|
147 |
+
$request,
|
148 |
+
$siteName
|
149 |
+
);
|
150 |
+
|
151 |
+
$message = sprintf(
|
152 |
+
__('You have requested to access your data on %s.', WP_GDPR_C_SLUG),
|
153 |
+
sprintf('<a target="_blank" href="%s">%s</a>', $siteUrl, $siteName)
|
154 |
+
) . '<br /><br />';
|
155 |
+
$message .= sprintf(
|
156 |
+
__('Please visit this %s to view the data linked to the email address %s.', WP_GDPR_C_SLUG),
|
157 |
+
$deleteRequestPage,
|
158 |
+
$emailAddress
|
159 |
+
) . '<br /><br />';
|
160 |
+
$message .= __('This page is available for 24 hours and can only be reached from the same device, IP address and browser session you requested from.', WP_GDPR_C_SLUG) . '<br /><br />';
|
161 |
+
$message .= sprintf(
|
162 |
+
__('If your link is invalid you can fill in a new request after 24 hours: %s.', WP_GDPR_C_SLUG),
|
163 |
+
sprintf(
|
164 |
+
'<a target="_blank" href="%s">%s</a>',
|
165 |
+
get_permalink($page),
|
166 |
+
get_the_title($page)
|
167 |
+
)
|
168 |
+
);
|
169 |
+
$message = apply_filters('wpgdprc_access_request_mail_content', $message, $request, $deleteRequestPage);
|
170 |
+
$headers = array(
|
171 |
+
'Content-Type: text/html; charset=UTF-8',
|
172 |
+
"From: $siteName <$siteEmail>"
|
173 |
+
);
|
174 |
+
$response = wp_mail($emailAddress, $subject, $message, $headers);
|
175 |
+
if ($response !== false) {
|
176 |
+
$output['message'] = __('Success. You will receive an email with your data shortly.', WP_GDPR_C_SLUG);
|
177 |
+
}
|
178 |
+
}
|
179 |
+
} else {
|
180 |
+
$output['error'] = __('Something went wrong while saving the request. Please try again.', WP_GDPR_C_SLUG);
|
181 |
+
}
|
182 |
+
} else {
|
183 |
+
$output['error'] = __('You have already requested your data. Please check your mailbox. After 24 hours you can put in a new request.', WP_GDPR_C_SLUG);
|
184 |
+
}
|
185 |
+
}
|
186 |
+
}
|
187 |
+
break;
|
188 |
+
case 'delete_request' :
|
189 |
+
if (Helper::isEnabled('enable_access_request', 'settings')) {
|
190 |
+
$token = (isset($data['token'])) ? esc_html(urldecode($data['token'])) : false;
|
191 |
+
$settings = (isset($data['settings']) && is_array($data['settings'])) ? $data['settings'] : array();
|
192 |
+
$type = (isset($settings['type']) && in_array($settings['type'], Data::getPossibleDataTypes())) ? $settings['type'] : '';
|
193 |
+
$value = (isset($data['value']) && is_numeric($data['value'])) ? (int)$data['value'] : 0;
|
194 |
+
|
195 |
+
if (empty($token)) {
|
196 |
+
$output['error'] = __('Missing token.', WP_GDPR_C_SLUG);
|
197 |
+
}
|
198 |
+
|
199 |
+
if (empty($type)) {
|
200 |
+
$output['error'] = __('Missing or invalid type.', WP_GDPR_C_SLUG);
|
201 |
+
}
|
202 |
+
|
203 |
+
if ($value === 0) {
|
204 |
+
$output['error'] = __('No value selected.', WP_GDPR_C_SLUG);
|
205 |
+
}
|
206 |
+
|
207 |
+
// Let's do this!
|
208 |
+
if (empty($output['error'])) {
|
209 |
+
$accessRequest = ($token !== false) ? AccessRequest::getInstance()->getByToken($token) : false;
|
210 |
+
if ($accessRequest !== false) {
|
211 |
+
if (
|
212 |
+
SessionHelper::checkSession($accessRequest->getSessionId()) &&
|
213 |
+
Helper::checkIpAddress($accessRequest->getIpAddress())
|
214 |
+
) {
|
215 |
+
$request = new DeleteRequest();
|
216 |
+
$request->setSiteId(get_current_blog_id());
|
217 |
+
$request->setAccessRequestId($accessRequest->getId());
|
218 |
+
$request->setSessionId($accessRequest->getSessionId());
|
219 |
+
$request->setIpAddress($accessRequest->getIpAddress());
|
220 |
+
$request->setDataId($value);
|
221 |
+
$request->setType($type);
|
222 |
+
$id = $request->save();
|
223 |
+
if ($id === false) {
|
224 |
+
$output['error'] = __('Something went wrong while saving this request. Please try again.', WP_GDPR_C_SLUG);
|
225 |
+
} else {
|
226 |
+
$siteName = Helper::getSiteData('blogname', $request->getSiteId());
|
227 |
+
$siteEmail = Helper::getSiteData('admin_email', $request->getSiteId());
|
228 |
+
$siteUrl = Helper::getSiteData('siteurl', $request->getSiteId());
|
229 |
+
$adminPage = sprintf(
|
230 |
+
'<a target="_blank" href="%s">%s</a>',
|
231 |
+
Helper::getPluginAdminUrl('requests'),
|
232 |
+
__('Requests', WP_GDPR_C_SLUG)
|
233 |
+
);
|
234 |
+
$subject = apply_filters(
|
235 |
+
'wpgdprc_delete_request_admin_mail_subject',
|
236 |
+
sprintf(__('%s - New anonymise request', WP_GDPR_C_SLUG), $siteName),
|
237 |
+
$request,
|
238 |
+
$siteName
|
239 |
+
);
|
240 |
+
$message = sprintf(
|
241 |
+
__('You have received a new anonymise request on %s.', WP_GDPR_C_SLUG),
|
242 |
+
sprintf('<a target="_blank" href="%s">%s</a>', $siteUrl, $siteName)
|
243 |
+
) . '<br /><br />';
|
244 |
+
$message .= sprintf(
|
245 |
+
__('You can manage this request in the admin panel: %s', WP_GDPR_C_SLUG),
|
246 |
+
$adminPage
|
247 |
+
);
|
248 |
+
$message = apply_filters('wpgdprc_delete_request_admin_mail_content', $message, $request, $adminPage);
|
249 |
+
$headers = array(
|
250 |
+
'Content-Type: text/html; charset=UTF-8',
|
251 |
+
"From: $siteName <$siteEmail>"
|
252 |
+
);
|
253 |
+
wp_mail($siteEmail, $subject, $message, $headers);
|
254 |
+
}
|
255 |
+
} else {
|
256 |
+
$output['error'] = __('Session doesn\'t match.', WP_GDPR_C_SLUG);
|
257 |
+
}
|
258 |
+
} else {
|
259 |
+
$output['error'] = __('No session found.', WP_GDPR_C_SLUG);
|
260 |
+
}
|
261 |
+
}
|
262 |
+
}
|
263 |
+
break;
|
264 |
+
}
|
265 |
+
}
|
266 |
+
|
267 |
+
header('Content-type: application/json');
|
268 |
+
echo json_encode($output);
|
269 |
+
die();
|
270 |
+
}
|
271 |
+
|
272 |
+
public function processDeleteRequest() {
|
273 |
+
check_ajax_referer('wpgdprc', 'security');
|
274 |
+
|
275 |
+
$output = array(
|
276 |
+
'message' => '',
|
277 |
+
'error' => '',
|
278 |
+
);
|
279 |
+
|
280 |
+
if (!Helper::isEnabled('enable_access_request', 'settings')) {
|
281 |
+
$output['error'] = __('The access request functionality is not enabled.', WP_GDPR_C_SLUG);
|
282 |
+
}
|
283 |
+
|
284 |
+
$data = (isset($_POST['data']) && (is_array($_POST['data']) || is_string($_POST['data']))) ? $_POST['data'] : false;
|
285 |
+
if (is_string($data)) {
|
286 |
+
$data = json_decode(stripslashes($data), true);
|
287 |
+
}
|
288 |
+
$id = (isset($data['id']) && is_numeric($data['id'])) ? absint($data['id']) : 0;
|
289 |
+
|
290 |
+
if (!$data) {
|
291 |
+
$output['error'] = __('Missing data.', WP_GDPR_C_SLUG);
|
292 |
+
}
|
293 |
+
|
294 |
+
if ($id === 0 || !DeleteRequest::getInstance()->exists($id)) {
|
295 |
+
$output['error'] = __('This request doesn\'t exist.', WP_GDPR_C_SLUG);
|
296 |
+
}
|
297 |
+
|
298 |
+
// Let's do this!
|
299 |
+
if (empty($output['error'])) {
|
300 |
+
$request = new DeleteRequest($id);
|
301 |
+
if (!$request->getProcessed()) {
|
302 |
+
switch ($request->getType()) {
|
303 |
+
case 'user' :
|
304 |
+
global $wpdb;
|
305 |
+
if (current_user_can('edit_users')) {
|
306 |
+
$date = Helper::localDateTime( time() );
|
307 |
+
$result = wp_update_user( array(
|
308 |
+
'ID' => $request->getDataId(),
|
309 |
+
'user_pass' => wp_generate_password( 30 ),
|
310 |
+
'display_name' => 'DISPLAY_NAME',
|
311 |
+
'user_nicename' => 'NICENAME' . $request->getDataId(),
|
312 |
+
'first_name' => 'FIRST_NAME',
|
313 |
+
'last_name' => 'LAST_NAME',
|
314 |
+
'user_email' => $request->getDataId() . '.' . $date->format( 'Ymd.His' ) . '@example.org'
|
315 |
+
) );
|
316 |
+
if ( is_wp_error( $result ) ) {
|
317 |
+
$output['error'] = __( 'This user doesn\'t exist.', WP_GDPR_C_SLUG );
|
318 |
+
} else {
|
319 |
+
$wpdb->update( $wpdb->users, array( 'user_login' => 'USERNAME_' . $date->format( 'Ymd.His' ) ), array( 'ID' => $request->getDataId() ) );
|
320 |
+
$request->setProcessed( 1 );
|
321 |
+
$request->save();
|
322 |
+
}
|
323 |
+
} else {
|
324 |
+
$output['error'] = __('You\'re not allowed to edit users.', WP_GDPR_C_SLUG);
|
325 |
+
}
|
326 |
+
break;
|
327 |
+
case 'comment' :
|
328 |
+
if (current_user_can('edit_posts')) {
|
329 |
+
$date = Helper::localDateTime(time());
|
330 |
+
$result = wp_update_comment(array(
|
331 |
+
'comment_ID' => $request->getDataId(),
|
332 |
+
'comment_author' => 'NAME',
|
333 |
+
'comment_author_email' => $request->getDataId() . '.' . $date->format('Ymd.His') . '@example.org',
|
334 |
+
'comment_author_IP' => '127.0.0.1'
|
335 |
+
));
|
336 |
+
if ($result === 0) {
|
337 |
+
$output['error'] = __('This comment doesn\'t exist.', WP_GDPR_C_SLUG);
|
338 |
+
} else {
|
339 |
+
$request->setProcessed(1);
|
340 |
+
$request->save();
|
341 |
+
}
|
342 |
+
} else {
|
343 |
+
$output['error'] = __('You\'re not allowed to edit comments.', WP_GDPR_C_SLUG);
|
344 |
+
}
|
345 |
+
break;
|
346 |
+
case 'woocommerce_order' :
|
347 |
+
if (current_user_can('edit_shop_orders')) {
|
348 |
+
$date = Helper::localDateTime(time());
|
349 |
+
$userId = get_post_meta($request->getDataId(), '_customer_user', true);
|
350 |
+
update_post_meta($request->getDataId(), '_billing_first_name', 'FIRST_NAME');
|
351 |
+
update_post_meta($request->getDataId(), '_billing_last_name', 'LAST_NAME');
|
352 |
+
update_post_meta($request->getDataId(), '_billing_company', 'COMPANY_NAME');
|
353 |
+
update_post_meta($request->getDataId(), '_billing_address_1', 'ADDRESS_1');
|
354 |
+
update_post_meta($request->getDataId(), '_billing_address_2', 'ADDRESS_2');
|
355 |
+
update_post_meta($request->getDataId(), '_billing_postcode', 'ZIP_CODE');
|
356 |
+
update_post_meta($request->getDataId(), '_billing_city', 'CITY');
|
357 |
+
update_post_meta($request->getDataId(), '_billing_phone', 'PHONE_NUMBER');
|
358 |
+
update_post_meta($request->getDataId(), '_billing_email', $request->getDataId() . '.' . $date->format('Ymd') . '.' . $date->format('His') . '@example.org');
|
359 |
+
update_post_meta($request->getDataId(), '_shipping_first_name', 'FIRST_NAME');
|
360 |
+
update_post_meta($request->getDataId(), '_shipping_last_name', 'LAST_NAME');
|
361 |
+
update_post_meta($request->getDataId(), '_shipping_company', 'COMPANY_NAME');
|
362 |
+
update_post_meta($request->getDataId(), '_shipping_address_1', 'ADDRESS_1');
|
363 |
+
update_post_meta($request->getDataId(), '_shipping_address_2', 'ADDRESS_2');
|
364 |
+
update_post_meta($request->getDataId(), '_shipping_postcode', 'ZIP_CODE');
|
365 |
+
update_post_meta($request->getDataId(), '_shipping_city', 'CITY');
|
366 |
+
if (!empty($userId) && get_user_by('id', $userId) !== false) {
|
367 |
+
update_user_meta($userId, 'billing_first_name', 'FIRST_NAME');
|
368 |
+
update_user_meta($userId, 'billing_last_name', 'LAST_NAME');
|
369 |
+
update_user_meta($userId, 'billing_company', 'COMPANY_NAME');
|
370 |
+
update_user_meta($userId, 'billing_address_1', 'ADDRESS_1');
|
371 |
+
update_user_meta($userId, 'billing_address_2', 'ADDRESS_2');
|
372 |
+
update_user_meta($userId, 'billing_postcode', 'ZIP_CODE');
|
373 |
+
update_user_meta($userId, 'billing_city', 'CITY');
|
374 |
+
update_user_meta($userId, 'billing_phone', 'PHONE_NUMBER');
|
375 |
+
update_user_meta($userId, 'billing_email', $request->getDataId() . '.' . $date->format('Ymd') . '.' . $date->format('His') . '@example.org');
|
376 |
+
update_user_meta($userId, 'shipping_first_name', 'FIRST_NAME');
|
377 |
+
update_user_meta($userId, 'shipping_last_name', 'LAST_NAME');
|
378 |
+
update_user_meta($userId, 'shipping_company', 'COMPANY_NAME');
|
379 |
+
update_user_meta($userId, 'shipping_address_1', 'ADDRESS_1');
|
380 |
+
update_user_meta($userId, 'shipping_address_2', 'ADDRESS_2');
|
381 |
+
update_user_meta($userId, 'shipping_postcode', 'ZIP_CODE');
|
382 |
+
update_user_meta($userId, 'shipping_city', 'CITY');
|
383 |
+
}
|
384 |
+
$request->setProcessed(1);
|
385 |
+
$request->save();
|
386 |
+
} else {
|
387 |
+
$output['error'] = __('You\'re not allowed to edit WooCommerce orders.', WP_GDPR_C_SLUG);
|
388 |
+
}
|
389 |
+
break;
|
390 |
+
}
|
391 |
+
|
392 |
+
if (empty($output['error']) && $request->getProcessed()) {
|
393 |
+
$accessRequest = new AccessRequest($request->getAccessRequestId());
|
394 |
+
$siteName = Helper::getSiteData('blogname', $request->getSiteId());
|
395 |
+
$siteEmail = Helper::getSiteData('admin_email', $request->getSiteId());
|
396 |
+
$siteUrl = Helper::getSiteData('siteurl', $request->getSiteId());
|
397 |
+
$subject = apply_filters(
|
398 |
+
'wpgdprc_delete_request_mail_subject',
|
399 |
+
sprintf(__('%s - Your request', WP_GDPR_C_SLUG), $siteName),
|
400 |
+
$request,
|
401 |
+
$accessRequest
|
402 |
+
);
|
403 |
+
$message = sprintf(
|
404 |
+
__('We have successfully processed your request and your data has been anonymised on %s.', WP_GDPR_C_SLUG),
|
405 |
+
sprintf('<a target="_blank" href="%s">%s</a>', $siteUrl, $siteName)
|
406 |
+
) . '<br /><br />';
|
407 |
+
$message .= __('The following has been processed:', WP_GDPR_C_SLUG) . '<br />';
|
408 |
+
$message .= sprintf('%s #%d with email address %s.', $request->getNiceTypeLabel(), $request->getDataId(), $accessRequest->getEmailAddress());
|
409 |
+
$message = apply_filters('wpgdprc_delete_request_mail_content', $message, $request, $accessRequest);
|
410 |
+
$headers = array(
|
411 |
+
'Content-Type: text/html; charset=UTF-8',
|
412 |
+
"From: $siteName <$siteEmail>"
|
413 |
+
);
|
414 |
+
$response = wp_mail($accessRequest->getEmailAddress(), $subject, $message, $headers);
|
415 |
+
if ($response !== false) {
|
416 |
+
$output['message'] = __('Successfully sent an confirmation mail to the user.', WP_GDPR_C_SLUG);
|
417 |
+
}
|
418 |
+
}
|
419 |
+
} else {
|
420 |
+
$output['error'] = __('This request has already been processed.', WP_GDPR_C_SLUG);
|
421 |
+
}
|
422 |
+
}
|
423 |
+
|
424 |
+
header('Content-type: application/json');
|
425 |
+
echo json_encode($output);
|
426 |
+
die();
|
427 |
+
}
|
428 |
+
|
429 |
+
/**
|
430 |
+
* @param $value
|
431 |
+
* @return mixed
|
432 |
+
*/
|
433 |
+
private static function sanitizeValue($value) {
|
434 |
+
if (is_numeric($value)) {
|
435 |
+
$value = intval($value);
|
436 |
+
}
|
437 |
+
if (is_string($value)) {
|
438 |
+
$value = esc_html($value);
|
439 |
+
}
|
440 |
+
return $value;
|
441 |
+
}
|
442 |
+
|
443 |
+
/**
|
444 |
+
* @return null|Ajax
|
445 |
+
*/
|
446 |
+
public static function getInstance() {
|
447 |
+
if (!isset(self::$instance)) {
|
448 |
+
self::$instance = new self();
|
449 |
+
}
|
450 |
+
return self::$instance;
|
451 |
+
}
|
452 |
}
|
Includes/Consent.php
CHANGED
@@ -1,480 +1,480 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WPGDPRC\Includes;
|
4 |
-
|
5 |
-
/**
|
6 |
-
* Class Consent
|
7 |
-
* @package WPGDPRC\Includes
|
8 |
-
*/
|
9 |
-
class Consent {
|
10 |
-
/** @var null */
|
11 |
-
private static $instance = null;
|
12 |
-
/** @var int */
|
13 |
-
private $id = 0;
|
14 |
-
/** @var int */
|
15 |
-
private $siteId = 0;
|
16 |
-
/** @var string */
|
17 |
-
private $title = '';
|
18 |
-
/** @var string */
|
19 |
-
private $description = '';
|
20 |
-
/** @var string */
|
21 |
-
private $snippet = '';
|
22 |
-
/** @var int */
|
23 |
-
private $wrap = 1;
|
24 |
-
/** @var string */
|
25 |
-
private $placement = '';
|
26 |
-
/** @var string */
|
27 |
-
private $plugins = '';
|
28 |
-
/** @var int */
|
29 |
-
private $required = 0;
|
30 |
-
/** @var int */
|
31 |
-
private $active = 0;
|
32 |
-
/** @var string */
|
33 |
-
private $dateModified = '';
|
34 |
-
/** @var string */
|
35 |
-
private $dateCreated = '';
|
36 |
-
|
37 |
-
/**
|
38 |
-
* Consent constructor.
|
39 |
-
* @param int $id
|
40 |
-
*/
|
41 |
-
public function __construct($id = 0) {
|
42 |
-
if ((int)$id > 0) {
|
43 |
-
$this->setId($id);
|
44 |
-
$this->load();
|
45 |
-
}
|
46 |
-
}
|
47 |
-
|
48 |
-
/**
|
49 |
-
* @param bool $insertPrivacyPolicyLink
|
50 |
-
* @return mixed
|
51 |
-
*/
|
52 |
-
public static function getModalTitle($insertPrivacyPolicyLink = true) {
|
53 |
-
$output = get_option(WP_GDPR_C_PREFIX . '_settings_consents_modal_title');
|
54 |
-
if (empty($output)) {
|
55 |
-
$output = __('Privacy Settings', WP_GDPR_C_SLUG);
|
56 |
-
}
|
57 |
-
$output = ($insertPrivacyPolicyLink === true) ? Integration::insertPrivacyPolicyLink($output) : $output;
|
58 |
-
return apply_filters('wpgdprc_consents_modal_title', wp_kses($output, Helper::getAllowedHTMLTags()));
|
59 |
-
}
|
60 |
-
|
61 |
-
/**
|
62 |
-
* @param bool $insertPrivacyPolicyLink
|
63 |
-
* @return mixed
|
64 |
-
*/
|
65 |
-
public static function getModalExplanationText($insertPrivacyPolicyLink = true) {
|
66 |
-
$output = get_option(WP_GDPR_C_PREFIX . '_settings_consents_modal_explanation_text');
|
67 |
-
if (empty($output)) {
|
68 |
-
$output = __('This site uses functional cookies and external scripts to improve your experience. Which cookies and scripts are used and how they impact your visit is specified on the left. You may change your settings at any time. Your choices will not impact your visit.', WP_GDPR_C_SLUG);
|
69 |
-
}
|
70 |
-
$output = ($insertPrivacyPolicyLink === true) ? Integration::insertPrivacyPolicyLink($output) : $output;
|
71 |
-
return apply_filters('wpgdprc_consents_modal_explanation_text', wp_kses($output, Helper::getAllowedHTMLTags()));
|
72 |
-
}
|
73 |
-
|
74 |
-
/**
|
75 |
-
* @param bool $insertPrivacyPolicyLink
|
76 |
-
* @return mixed
|
77 |
-
*/
|
78 |
-
public static function getBarExplanationText($insertPrivacyPolicyLink = true) {
|
79 |
-
$output = get_option(WP_GDPR_C_PREFIX . '_settings_consents_bar_explanation_text');
|
80 |
-
if (empty($output)) {
|
81 |
-
$output = __('This site uses functional cookies and external scripts to improve your experience.', WP_GDPR_C_SLUG);
|
82 |
-
}
|
83 |
-
$output = ($insertPrivacyPolicyLink === true) ? Integration::insertPrivacyPolicyLink($output) : $output;
|
84 |
-
return apply_filters('wpgdprc_consents_bar_explanation_text', wp_kses($output, Helper::getAllowedHTMLTags()));
|
85 |
-
}
|
86 |
-
|
87 |
-
/**
|
88 |
-
* @param array $consents
|
89 |
-
* @return string
|
90 |
-
*/
|
91 |
-
public static function output($consents = array()) {
|
92 |
-
$output = '';
|
93 |
-
if (!empty($consents)) {
|
94 |
-
/** @var Consent $consent */
|
95 |
-
foreach ($consents as $consent) {
|
96 |
-
if ($consent->getWrap()) {
|
97 |
-
$output .= sprintf(
|
98 |
-
'<script type="text/javascript">%s</script>',
|
99 |
-
$consent->getSnippet()
|
100 |
-
);
|
101 |
-
} else {
|
102 |
-
$output .= sprintf('%s', $consent->getSnippet());
|
103 |
-
}
|
104 |
-
}
|
105 |
-
}
|
106 |
-
return $output;
|
107 |
-
}
|
108 |
-
|
109 |
-
/**
|
110 |
-
* @param array $filters
|
111 |
-
* @return int
|
112 |
-
*/
|
113 |
-
public function getTotal($filters = array()) {
|
114 |
-
global $wpdb;
|
115 |
-
$query = "SELECT COUNT(`ID`) FROM `" . self::getDatabaseTableName() . "` WHERE 1";
|
116 |
-
$query .= Helper::getQueryByFilters($filters);
|
117 |
-
$query .= sprintf(" AND `site_id` = '%d'", get_current_blog_id());
|
118 |
-
$result = $wpdb->get_var($query);
|
119 |
-
if ($result !== null) {
|
120 |
-
return absint($result);
|
121 |
-
}
|
122 |
-
return 0;
|
123 |
-
}
|
124 |
-
|
125 |
-
/**
|
126 |
-
* @param array $filters
|
127 |
-
* @param int $limit
|
128 |
-
* @param int $offset
|
129 |
-
* @return Consent[]
|
130 |
-
*/
|
131 |
-
public function getList($filters = array(), $limit = 0, $offset = 0) {
|
132 |
-
global $wpdb;
|
133 |
-
$output = array();
|
134 |
-
$query = "SELECT * FROM `" . self::getDatabaseTableName() . "` WHERE 1";
|
135 |
-
$query .= Helper::getQueryByFilters($filters);
|
136 |
-
$query .= sprintf(" AND `site_id` = '%d'", get_current_blog_id());
|
137 |
-
$query .= " ORDER BY `date_modified` DESC";
|
138 |
-
if (!empty($limit)) {
|
139 |
-
$query .= " LIMIT $offset, $limit";
|
140 |
-
}
|
141 |
-
$results = $wpdb->get_results($query);
|
142 |
-
if ($results !== null) {
|
143 |
-
foreach ($results as $row) {
|
144 |
-
$object = new self;
|
145 |
-
$object->loadByRow($row);
|
146 |
-
$output[] = $object;
|
147 |
-
}
|
148 |
-
}
|
149 |
-
return $output;
|
150 |
-
}
|
151 |
-
|
152 |
-
/**
|
153 |
-
* @param $row
|
154 |
-
*/
|
155 |
-
private function loadByRow($row) {
|
156 |
-
$this->setId($row->ID);
|
157 |
-
$this->setSiteId($row->site_id);
|
158 |
-
$this->setTitle($row->title);
|
159 |
-
$this->setDescription($row->description);
|
160 |
-
$this->setSnippet($row->snippet);
|
161 |
-
$this->setWrap($row->wrap);
|
162 |
-
$this->setPlacement($row->placement);
|
163 |
-
$this->setPlugins($row->plugins);
|
164 |
-
$this->setRequired($row->required);
|
165 |
-
$this->setActive($row->active);
|
166 |
-
$this->setDateModified($row->date_modified);
|
167 |
-
$this->setDateCreated($row->date_created);
|
168 |
-
}
|
169 |
-
|
170 |
-
public function load() {
|
171 |
-
global $wpdb;
|
172 |
-
$query = "SELECT * FROM `" . self::getDatabaseTableName() . "` WHERE `ID` = %d";
|
173 |
-
$row = $wpdb->get_row($wpdb->prepare($query, $this->getId()));
|
174 |
-
if ($row !== null) {
|
175 |
-
$this->loadByRow($row);
|
176 |
-
}
|
177 |
-
}
|
178 |
-
|
179 |
-
/**
|
180 |
-
* @param int $id
|
181 |
-
* @return bool
|
182 |
-
*/
|
183 |
-
public function exists($id = 0) {
|
184 |
-
global $wpdb;
|
185 |
-
$row = $wpdb->get_row(
|
186 |
-
$wpdb->prepare(
|
187 |
-
"SELECT * FROM `" . self::getDatabaseTableName() . "` WHERE `ID` = %d",
|
188 |
-
intval($id)
|
189 |
-
)
|
190 |
-
);
|
191 |
-
return ($row !== null);
|
192 |
-
}
|
193 |
-
|
194 |
-
/**
|
195 |
-
* @return bool|int
|
196 |
-
*/
|
197 |
-
public function save() {
|
198 |
-
global $wpdb;
|
199 |
-
$data = array(
|
200 |
-
'title' => $this->getTitle(),
|
201 |
-
'description' => $this->getDescription(),
|
202 |
-
'snippet' => $this->getSnippet(),
|
203 |
-
'wrap' => $this->getWrap(),
|
204 |
-
'placement' => $this->getPlacement(),
|
205 |
-
'plugins' => $this->getPlugins(),
|
206 |
-
'required' => $this->getRequired(),
|
207 |
-
'active' => $this->getActive(),
|
208 |
-
);
|
209 |
-
$dataTypes = array('%s', '%s', '%s', '%d', '%s', '%s', '%d', '%d');
|
210 |
-
if ($this->exists($this->getId())) {
|
211 |
-
$wpdb->update(
|
212 |
-
self::getDatabaseTableName(),
|
213 |
-
$data,
|
214 |
-
array('ID' => $this->getId()),
|
215 |
-
$dataTypes,
|
216 |
-
array('%d')
|
217 |
-
);
|
218 |
-
return $this->getId();
|
219 |
-
} else {
|
220 |
-
$data['site_id'] = $this->getSiteId();
|
221 |
-
$data['date_created'] = date_i18n('Y-m-d H:i:s');
|
222 |
-
$dataTypes = array_merge($dataTypes, array('%d', '%s', '%d'));
|
223 |
-
$result = $wpdb->insert(
|
224 |
-
self::getDatabaseTableName(),
|
225 |
-
$data,
|
226 |
-
$dataTypes
|
227 |
-
);
|
228 |
-
if ($result !== false) {
|
229 |
-
$this->setId($wpdb->insert_id);
|
230 |
-
return $this->getId();
|
231 |
-
}
|
232 |
-
}
|
233 |
-
return false;
|
234 |
-
}
|
235 |
-
|
236 |
-
/**
|
237 |
-
* @param int $id
|
238 |
-
* @return bool
|
239 |
-
*/
|
240 |
-
public function delete($id = 0) {
|
241 |
-
if ((int)$id > 0) {
|
242 |
-
global $wpdb;
|
243 |
-
$result = $wpdb->delete(self::getDatabaseTableName(), array('ID' => $id), array('%d'));
|
244 |
-
if ($result !== false) {
|
245 |
-
return true;
|
246 |
-
}
|
247 |
-
}
|
248 |
-
return false;
|
249 |
-
}
|
250 |
-
|
251 |
-
/**
|
252 |
-
* @param int $id
|
253 |
-
* @param string $action
|
254 |
-
* @return string
|
255 |
-
*/
|
256 |
-
public static function getActionUrl($id = 0, $action = 'manage') {
|
257 |
-
return Helper::getPluginAdminUrl(
|
258 |
-
'consents',
|
259 |
-
array(
|
260 |
-
'action' => $action,
|
261 |
-
'id' => $id,
|
262 |
-
)
|
263 |
-
);
|
264 |
-
}
|
265 |
-
|
266 |
-
/**
|
267 |
-
* @return array
|
268 |
-
*/
|
269 |
-
public static function getPossibleCodeWraps() {
|
270 |
-
return array(
|
271 |
-
'1' => esc_html__('Wrap my code snippet with <script> tags', WP_GDPR_C_SLUG),
|
272 |
-
'0' => __('Do not wrap my code snippet', WP_GDPR_C_SLUG)
|
273 |
-
);
|
274 |
-
}
|
275 |
-
|
276 |
-
/**
|
277 |
-
* @return array
|
278 |
-
*/
|
279 |
-
public static function getPossiblePlacements() {
|
280 |
-
return array(
|
281 |
-
'head' => __('Head', WP_GDPR_C_SLUG),
|
282 |
-
'footer' => __('Footer', WP_GDPR_C_SLUG)
|
283 |
-
);
|
284 |
-
}
|
285 |
-
|
286 |
-
/**
|
287 |
-
* @return null|Consent
|
288 |
-
*/
|
289 |
-
public static function getInstance() {
|
290 |
-
if (!isset(self::$instance)) {
|
291 |
-
self::$instance = new self();
|
292 |
-
}
|
293 |
-
return self::$instance;
|
294 |
-
}
|
295 |
-
|
296 |
-
/**
|
297 |
-
* @return int
|
298 |
-
*/
|
299 |
-
public function getId() {
|
300 |
-
return $this->id;
|
301 |
-
}
|
302 |
-
|
303 |
-
/**
|
304 |
-
* @param int $id
|
305 |
-
*/
|
306 |
-
public function setId($id) {
|
307 |
-
$this->id = $id;
|
308 |
-
}
|
309 |
-
|
310 |
-
/**
|
311 |
-
* @return int
|
312 |
-
*/
|
313 |
-
public function getSiteId() {
|
314 |
-
return $this->siteId;
|
315 |
-
}
|
316 |
-
|
317 |
-
/**
|
318 |
-
* @param int $siteId
|
319 |
-
*/
|
320 |
-
public function setSiteId($siteId) {
|
321 |
-
$this->siteId = $siteId;
|
322 |
-
}
|
323 |
-
|
324 |
-
/**
|
325 |
-
* @return string
|
326 |
-
*/
|
327 |
-
public function getTitle() {
|
328 |
-
return $this->title;
|
329 |
-
}
|
330 |
-
|
331 |
-
/**
|
332 |
-
* @param string $title
|
333 |
-
*/
|
334 |
-
public function setTitle($title) {
|
335 |
-
$this->title = $title;
|
336 |
-
}
|
337 |
-
|
338 |
-
/**
|
339 |
-
* @return string
|
340 |
-
*/
|
341 |
-
public function getDescription() {
|
342 |
-
return $this->description;
|
343 |
-
}
|
344 |
-
|
345 |
-
/**
|
346 |
-
* @param string $description
|
347 |
-
*/
|
348 |
-
public function setDescription($description) {
|
349 |
-
$this->description = $description;
|
350 |
-
}
|
351 |
-
|
352 |
-
/**
|
353 |
-
* @return string
|
354 |
-
*/
|
355 |
-
public function getSnippet() {
|
356 |
-
return $this->snippet;
|
357 |
-
}
|
358 |
-
|
359 |
-
/**
|
360 |
-
* @param string $snippet
|
361 |
-
*/
|
362 |
-
public function setSnippet($snippet) {
|
363 |
-
$this->snippet = $snippet;
|
364 |
-
}
|
365 |
-
|
366 |
-
/**
|
367 |
-
* @return int
|
368 |
-
*/
|
369 |
-
public function getWrap() {
|
370 |
-
return $this->wrap;
|
371 |
-
}
|
372 |
-
|
373 |
-
/**
|
374 |
-
* @param int $wrap
|
375 |
-
*/
|
376 |
-
public function setWrap($wrap) {
|
377 |
-
$this->wrap = $wrap;
|
378 |
-
}
|
379 |
-
|
380 |
-
/**
|
381 |
-
* @return string
|
382 |
-
*/
|
383 |
-
public function getPlacement() {
|
384 |
-
return $this->placement;
|
385 |
-
}
|
386 |
-
|
387 |
-
/**
|
388 |
-
* @param string $placement
|
389 |
-
*/
|
390 |
-
public function setPlacement($placement) {
|
391 |
-
$this->placement = $placement;
|
392 |
-
}
|
393 |
-
|
394 |
-
/**
|
395 |
-
* @return string
|
396 |
-
*/
|
397 |
-
public function getPlugins() {
|
398 |
-
return $this->plugins;
|
399 |
-
}
|
400 |
-
|
401 |
-
/**
|
402 |
-
* @param string $plugins
|
403 |
-
*/
|
404 |
-
public function setPlugins($plugins) {
|
405 |
-
$this->plugins = $plugins;
|
406 |
-
}
|
407 |
-
|
408 |
-
/**
|
409 |
-
* @return int
|
410 |
-
*/
|
411 |
-
public function getRequired() {
|
412 |
-
return $this->required;
|
413 |
-
}
|
414 |
-
|
415 |
-
/**
|
416 |
-
* @param int $required
|
417 |
-
*/
|
418 |
-
public function setRequired($required) {
|
419 |
-
$this->required = $required;
|
420 |
-
}
|
421 |
-
|
422 |
-
/**
|
423 |
-
* @return int
|
424 |
-
*/
|
425 |
-
public function getActive() {
|
426 |
-
return $this->active;
|
427 |
-
}
|
428 |
-
|
429 |
-
/**
|
430 |
-
* @param int $active
|
431 |
-
*/
|
432 |
-
public function setActive($active) {
|
433 |
-
$this->active = $active;
|
434 |
-
}
|
435 |
-
|
436 |
-
/**
|
437 |
-
* @return string
|
438 |
-
*/
|
439 |
-
public function getDateModified() {
|
440 |
-
return $this->dateModified;
|
441 |
-
}
|
442 |
-
|
443 |
-
/**
|
444 |
-
* @param string $dateModified
|
445 |
-
*/
|
446 |
-
public function setDateModified($dateModified) {
|
447 |
-
$this->dateModified = $dateModified;
|
448 |
-
}
|
449 |
-
|
450 |
-
/**
|
451 |
-
* @return string
|
452 |
-
*/
|
453 |
-
public function getDateCreated() {
|
454 |
-
return $this->dateCreated;
|
455 |
-
}
|
456 |
-
|
457 |
-
/**
|
458 |
-
* @param string $dateCreated
|
459 |
-
*/
|
460 |
-
public function setDateCreated($dateCreated) {
|
461 |
-
$this->dateCreated = $dateCreated;
|
462 |
-
}
|
463 |
-
|
464 |
-
/**
|
465 |
-
* @return bool
|
466 |
-
*/
|
467 |
-
public static function databaseTableExists() {
|
468 |
-
global $wpdb;
|
469 |
-
$result = $wpdb->query("SHOW TABLES LIKE '" . self::getDatabaseTableName() . "'");
|
470 |
-
return ($result === 1);
|
471 |
-
}
|
472 |
-
|
473 |
-
/**
|
474 |
-
* @return string
|
475 |
-
*/
|
476 |
-
public static function getDatabaseTableName() {
|
477 |
-
global $wpdb;
|
478 |
-
return $wpdb->base_prefix . 'wpgdprc_consents';
|
479 |
-
}
|
480 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WPGDPRC\Includes;
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Class Consent
|
7 |
+
* @package WPGDPRC\Includes
|
8 |
+
*/
|
9 |
+
class Consent {
|
10 |
+
/** @var null */
|
11 |
+
private static $instance = null;
|
12 |
+
/** @var int */
|
13 |
+
private $id = 0;
|
14 |
+
/** @var int */
|
15 |
+
private $siteId = 0;
|
16 |
+
/** @var string */
|
17 |
+
private $title = '';
|
18 |
+
/** @var string */
|
19 |
+
private $description = '';
|
20 |
+
/** @var string */
|
21 |
+
private $snippet = '';
|
22 |
+
/** @var int */
|
23 |
+
private $wrap = 1;
|
24 |
+
/** @var string */
|
25 |
+
private $placement = '';
|
26 |
+
/** @var string */
|
27 |
+
private $plugins = '';
|
28 |
+
/** @var int */
|
29 |
+
private $required = 0;
|
30 |
+
/** @var int */
|
31 |
+
private $active = 0;
|
32 |
+
/** @var string */
|
33 |
+
private $dateModified = '';
|
34 |
+
/** @var string */
|
35 |
+
private $dateCreated = '';
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Consent constructor.
|
39 |
+
* @param int $id
|
40 |
+
*/
|
41 |
+
public function __construct($id = 0) {
|
42 |
+
if ((int)$id > 0) {
|
43 |
+
$this->setId($id);
|
44 |
+
$this->load();
|
45 |
+
}
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* @param bool $insertPrivacyPolicyLink
|
50 |
+
* @return mixed
|
51 |
+
*/
|
52 |
+
public static function getModalTitle($insertPrivacyPolicyLink = true) {
|
53 |
+
$output = get_option(WP_GDPR_C_PREFIX . '_settings_consents_modal_title');
|
54 |
+
if (empty($output)) {
|
55 |
+
$output = __('Privacy Settings', WP_GDPR_C_SLUG);
|
56 |
+
}
|
57 |
+
$output = ($insertPrivacyPolicyLink === true) ? Integration::insertPrivacyPolicyLink($output) : $output;
|
58 |
+
return apply_filters('wpgdprc_consents_modal_title', wp_kses($output, Helper::getAllowedHTMLTags()));
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* @param bool $insertPrivacyPolicyLink
|
63 |
+
* @return mixed
|
64 |
+
*/
|
65 |
+
public static function getModalExplanationText($insertPrivacyPolicyLink = true) {
|
66 |
+
$output = get_option(WP_GDPR_C_PREFIX . '_settings_consents_modal_explanation_text');
|
67 |
+
if (empty($output)) {
|
68 |
+
$output = __('This site uses functional cookies and external scripts to improve your experience. Which cookies and scripts are used and how they impact your visit is specified on the left. You may change your settings at any time. Your choices will not impact your visit.', WP_GDPR_C_SLUG);
|
69 |
+
}
|
70 |
+
$output = ($insertPrivacyPolicyLink === true) ? Integration::insertPrivacyPolicyLink($output) : $output;
|
71 |
+
return apply_filters('wpgdprc_consents_modal_explanation_text', wp_kses($output, Helper::getAllowedHTMLTags()));
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* @param bool $insertPrivacyPolicyLink
|
76 |
+
* @return mixed
|
77 |
+
*/
|
78 |
+
public static function getBarExplanationText($insertPrivacyPolicyLink = true) {
|
79 |
+
$output = get_option(WP_GDPR_C_PREFIX . '_settings_consents_bar_explanation_text');
|
80 |
+
if (empty($output)) {
|
81 |
+
$output = __('This site uses functional cookies and external scripts to improve your experience.', WP_GDPR_C_SLUG);
|
82 |
+
}
|
83 |
+
$output = ($insertPrivacyPolicyLink === true) ? Integration::insertPrivacyPolicyLink($output) : $output;
|
84 |
+
return apply_filters('wpgdprc_consents_bar_explanation_text', wp_kses($output, Helper::getAllowedHTMLTags()));
|
85 |
+
}
|
86 |
+
|
87 |
+
/**
|
88 |
+
* @param array $consents
|
89 |
+
* @return string
|
90 |
+
*/
|
91 |
+
public static function output($consents = array()) {
|
92 |
+
$output = '';
|
93 |
+
if (!empty($consents)) {
|
94 |
+
/** @var Consent $consent */
|
95 |
+
foreach ($consents as $consent) {
|
96 |
+
if ($consent->getWrap()) {
|
97 |
+
$output .= sprintf(
|
98 |
+
'<script type="text/javascript">%s</script>',
|
99 |
+
$consent->getSnippet()
|
100 |
+
);
|
101 |
+
} else {
|
102 |
+
$output .= sprintf('%s', $consent->getSnippet());
|
103 |
+
}
|
104 |
+
}
|
105 |
+
}
|
106 |
+
return $output;
|
107 |
+
}
|
108 |
+
|
109 |
+
/**
|
110 |
+
* @param array $filters
|
111 |
+
* @return int
|
112 |
+
*/
|
113 |
+
public function getTotal($filters = array()) {
|
114 |
+
global $wpdb;
|
115 |
+
$query = "SELECT COUNT(`ID`) FROM `" . self::getDatabaseTableName() . "` WHERE 1";
|
116 |
+
$query .= Helper::getQueryByFilters($filters);
|
117 |
+
$query .= sprintf(" AND `site_id` = '%d'", get_current_blog_id());
|
118 |
+
$result = $wpdb->get_var($query);
|
119 |
+
if ($result !== null) {
|
120 |
+
return absint($result);
|
121 |
+
}
|
122 |
+
return 0;
|
123 |
+
}
|
124 |
+
|
125 |
+
/**
|
126 |
+
* @param array $filters
|
127 |
+
* @param int $limit
|
128 |
+
* @param int $offset
|
129 |
+
* @return Consent[]
|
130 |
+
*/
|
131 |
+
public function getList($filters = array(), $limit = 0, $offset = 0) {
|
132 |
+
global $wpdb;
|
133 |
+
$output = array();
|
134 |
+
$query = "SELECT * FROM `" . self::getDatabaseTableName() . "` WHERE 1";
|
135 |
+
$query .= Helper::getQueryByFilters($filters);
|
136 |
+
$query .= sprintf(" AND `site_id` = '%d'", get_current_blog_id());
|
137 |
+
$query .= " ORDER BY `date_modified` DESC";
|
138 |
+
if (!empty($limit)) {
|
139 |
+
$query .= " LIMIT $offset, $limit";
|
140 |
+
}
|
141 |
+
$results = $wpdb->get_results($query);
|
142 |
+
if ($results !== null) {
|
143 |
+
foreach ($results as $row) {
|
144 |
+
$object = new self;
|
145 |
+
$object->loadByRow($row);
|
146 |
+
$output[] = $object;
|
147 |
+
}
|
148 |
+
}
|
149 |
+
return $output;
|
150 |
+
}
|
151 |
+
|
152 |
+
/**
|
153 |
+
* @param $row
|
154 |
+
*/
|
155 |
+
private function loadByRow($row) {
|
156 |
+
$this->setId($row->ID);
|
157 |
+
$this->setSiteId($row->site_id);
|
158 |
+
$this->setTitle($row->title);
|
159 |
+
$this->setDescription($row->description);
|
160 |
+
$this->setSnippet($row->snippet);
|
161 |
+
$this->setWrap($row->wrap);
|
162 |
+
$this->setPlacement($row->placement);
|
163 |
+
$this->setPlugins($row->plugins);
|
164 |
+
$this->setRequired($row->required);
|
165 |
+
$this->setActive($row->active);
|
166 |
+
$this->setDateModified($row->date_modified);
|
167 |
+
$this->setDateCreated($row->date_created);
|
168 |
+
}
|
169 |
+
|
170 |
+
public function load() {
|
171 |
+
global $wpdb;
|
172 |
+
$query = "SELECT * FROM `" . self::getDatabaseTableName() . "` WHERE `ID` = %d";
|
173 |
+
$row = $wpdb->get_row($wpdb->prepare($query, $this->getId()));
|
174 |
+
if ($row !== null) {
|
175 |
+
$this->loadByRow($row);
|
176 |
+
}
|
177 |
+
}
|
178 |
+
|
179 |
+
/**
|
180 |
+
* @param int $id
|
181 |
+
* @return bool
|
182 |
+
*/
|
183 |
+
public function exists($id = 0) {
|
184 |
+
global $wpdb;
|
185 |
+
$row = $wpdb->get_row(
|
186 |
+
$wpdb->prepare(
|
187 |
+
"SELECT * FROM `" . self::getDatabaseTableName() . "` WHERE `ID` = %d",
|
188 |
+
intval($id)
|
189 |
+
)
|
190 |
+
);
|
191 |
+
return ($row !== null);
|
192 |
+
}
|
193 |
+
|
194 |
+
/**
|
195 |
+
* @return bool|int
|
196 |
+
*/
|
197 |
+
public function save() {
|
198 |
+
global $wpdb;
|
199 |
+
$data = array(
|
200 |
+
'title' => $this->getTitle(),
|
201 |
+
'description' => $this->getDescription(),
|
202 |
+
'snippet' => $this->getSnippet(),
|
203 |
+
'wrap' => $this->getWrap(),
|
204 |
+
'placement' => $this->getPlacement(),
|
205 |
+
'plugins' => $this->getPlugins(),
|
206 |
+
'required' => $this->getRequired(),
|
207 |
+
'active' => $this->getActive(),
|
208 |
+
);
|
209 |
+
$dataTypes = array('%s', '%s', '%s', '%d', '%s', '%s', '%d', '%d');
|
210 |
+
if ($this->exists($this->getId())) {
|
211 |
+
$wpdb->update(
|
212 |
+
self::getDatabaseTableName(),
|
213 |
+
$data,
|
214 |
+
array('ID' => $this->getId()),
|
215 |
+
$dataTypes,
|
216 |
+
array('%d')
|
217 |
+
);
|
218 |
+
return $this->getId();
|
219 |
+
} else {
|
220 |
+
$data['site_id'] = $this->getSiteId();
|
221 |
+
$data['date_created'] = date_i18n('Y-m-d H:i:s');
|
222 |
+
$dataTypes = array_merge($dataTypes, array('%d', '%s', '%d'));
|
223 |
+
$result = $wpdb->insert(
|
224 |
+
self::getDatabaseTableName(),
|
225 |
+
$data,
|
226 |
+
$dataTypes
|
227 |
+
);
|
228 |
+
if ($result !== false) {
|
229 |
+
$this->setId($wpdb->insert_id);
|
230 |
+
return $this->getId();
|
231 |
+
}
|
232 |
+
}
|
233 |
+
return false;
|
234 |
+
}
|
235 |
+
|
236 |
+
/**
|
237 |
+
* @param int $id
|
238 |
+
* @return bool
|
239 |
+
*/
|
240 |
+
public function delete($id = 0) {
|
241 |
+
if ((int)$id > 0) {
|
242 |
+
global $wpdb;
|
243 |
+
$result = $wpdb->delete(self::getDatabaseTableName(), array('ID' => $id), array('%d'));
|
244 |
+
if ($result !== false) {
|
245 |
+
return true;
|
246 |
+
}
|
247 |
+
}
|
248 |
+
return false;
|
249 |
+
}
|
250 |
+
|
251 |
+
/**
|
252 |
+
* @param int $id
|
253 |
+
* @param string $action
|
254 |
+
* @return string
|
255 |
+
*/
|
256 |
+
public static function getActionUrl($id = 0, $action = 'manage') {
|
257 |
+
return Helper::getPluginAdminUrl(
|
258 |
+
'consents',
|
259 |
+
array(
|
260 |
+
'action' => $action,
|
261 |
+
'id' => $id,
|
262 |
+
)
|
263 |
+
);
|
264 |
+
}
|
265 |
+
|
266 |
+
/**
|
267 |
+
* @return array
|
268 |
+
*/
|
269 |
+
public static function getPossibleCodeWraps() {
|
270 |
+
return array(
|
271 |
+
'1' => esc_html__('Wrap my code snippet with <script> tags', WP_GDPR_C_SLUG),
|
272 |
+
'0' => __('Do not wrap my code snippet', WP_GDPR_C_SLUG)
|
273 |
+
);
|
274 |
+
}
|
275 |
+
|
276 |
+
/**
|
277 |
+
* @return array
|
278 |
+
*/
|
279 |
+
public static function getPossiblePlacements() {
|
280 |
+
return array(
|
281 |
+
'head' => __('Head', WP_GDPR_C_SLUG),
|
282 |
+
'footer' => __('Footer', WP_GDPR_C_SLUG)
|
283 |
+
);
|
284 |
+
}
|
285 |
+
|
286 |
+
/**
|
287 |
+
* @return null|Consent
|
288 |
+
*/
|
289 |
+
public static function getInstance() {
|
290 |
+
if (!isset(self::$instance)) {
|
291 |
+
self::$instance = new self();
|
292 |
+
}
|
293 |
+
return self::$instance;
|
294 |
+
}
|
295 |
+
|
296 |
+
/**
|
297 |
+
* @return int
|
298 |
+
*/
|
299 |
+
public function getId() {
|
300 |
+
return $this->id;
|
301 |
+
}
|
302 |
+
|
303 |
+
/**
|
304 |
+
* @param int $id
|
305 |
+
*/
|
306 |
+
public function setId($id) {
|
307 |
+
$this->id = $id;
|
308 |
+
}
|
309 |
+
|
310 |
+
/**
|
311 |
+
* @return int
|
312 |
+
*/
|
313 |
+
public function getSiteId() {
|
314 |
+
return $this->siteId;
|
315 |
+
}
|
316 |
+
|
317 |
+
/**
|
318 |
+
* @param int $siteId
|
319 |
+
*/
|
320 |
+
public function setSiteId($siteId) {
|
321 |
+
$this->siteId = $siteId;
|
322 |
+
}
|
323 |
+
|
324 |
+
/**
|
325 |
+
* @return string
|
326 |
+
*/
|
327 |
+
public function getTitle() {
|
328 |
+
return $this->title;
|
329 |
+
}
|
330 |
+
|
331 |
+
/**
|
332 |
+
* @param string $title
|
333 |
+
*/
|
334 |
+
public function setTitle($title) {
|
335 |
+
$this->title = $title;
|
336 |
+
}
|
337 |
+
|
338 |
+
/**
|
339 |
+
* @return string
|
340 |
+
*/
|
341 |
+
public function getDescription() {
|
342 |
+
return $this->description;
|
343 |
+
}
|
344 |
+
|
345 |
+
/**
|
346 |
+
* @param string $description
|
347 |
+
*/
|
348 |
+
public function setDescription($description) {
|
349 |
+
$this->description = $description;
|
350 |
+
}
|
351 |
+
|
352 |
+
/**
|
353 |
+
* @return string
|
354 |
+
*/
|
355 |
+
public function getSnippet() {
|
356 |
+
return $this->snippet;
|
357 |
+
}
|
358 |
+
|
359 |
+
/**
|
360 |
+
* @param string $snippet
|
361 |
+
*/
|
362 |
+
public function setSnippet($snippet) {
|
363 |
+
$this->snippet = $snippet;
|
364 |
+
}
|
365 |
+
|
366 |
+
/**
|
367 |
+
* @return int
|
368 |
+
*/
|
369 |
+
public function getWrap() {
|
370 |
+
return $this->wrap;
|
371 |
+
}
|
372 |
+
|
373 |
+
/**
|
374 |
+
* @param int $wrap
|
375 |
+
*/
|
376 |
+
public function setWrap($wrap) {
|
377 |
+
$this->wrap = $wrap;
|
378 |
+
}
|
379 |
+
|
380 |
+
/**
|
381 |
+
* @return string
|
382 |
+
*/
|
383 |
+
public function getPlacement() {
|
384 |
+
return $this->placement;
|
385 |
+
}
|
386 |
+
|
387 |
+
/**
|
388 |
+
* @param string $placement
|
389 |
+
*/
|
390 |
+
public function setPlacement($placement) {
|
391 |
+
$this->placement = $placement;
|
392 |
+
}
|
393 |
+
|
394 |
+
/**
|
395 |
+
* @return string
|
396 |
+
*/
|
397 |
+
public function getPlugins() {
|
398 |
+
return $this->plugins;
|
399 |
+
}
|
400 |
+
|
401 |
+
/**
|
402 |
+
* @param string $plugins
|
403 |
+
*/
|
404 |
+
public function setPlugins($plugins) {
|
405 |
+
$this->plugins = $plugins;
|
406 |
+
}
|
407 |
+
|
408 |
+
/**
|
409 |
+
* @return int
|
410 |
+
*/
|
411 |
+
public function getRequired() {
|
412 |
+
return $this->required;
|
413 |
+
}
|
414 |
+
|
415 |
+
/**
|
416 |
+
* @param int $required
|
417 |
+
*/
|
418 |
+
public function setRequired($required) {
|
419 |
+
$this->required = $required;
|
420 |
+
}
|
421 |
+
|
422 |
+
/**
|
423 |
+
* @return int
|
424 |
+
*/
|
425 |
+
public function getActive() {
|
426 |
+
return $this->active;
|
427 |
+
}
|
428 |
+
|
429 |
+
/**
|
430 |
+
* @param int $active
|
431 |
+
*/
|
432 |
+
public function setActive($active) {
|
433 |
+
$this->active = $active;
|
434 |
+
}
|
435 |
+
|
436 |
+
/**
|
437 |
+
* @return string
|
438 |
+
*/
|
439 |
+
public function getDateModified() {
|
440 |
+
return $this->dateModified;
|
441 |
+
}
|
442 |
+
|
443 |
+
/**
|
444 |
+
* @param string $dateModified
|
445 |
+
*/
|
446 |
+
public function setDateModified($dateModified) {
|
447 |
+
$this->dateModified = $dateModified;
|
448 |
+
}
|
449 |
+
|
450 |
+
/**
|
451 |
+
* @return string
|
452 |
+
*/
|
453 |
+
public function getDateCreated() {
|
454 |
+
return $this->dateCreated;
|
455 |
+
}
|
456 |
+
|
457 |
+
/**
|
458 |
+
* @param string $dateCreated
|
459 |
+
*/
|
460 |
+
public function setDateCreated($dateCreated) {
|
461 |
+
$this->dateCreated = $dateCreated;
|
462 |
+
}
|
463 |
+
|
464 |
+
/**
|
465 |
+
* @return bool
|
466 |
+
*/
|
467 |
+
public static function databaseTableExists() {
|
468 |
+
global $wpdb;
|
469 |
+
$result = $wpdb->query("SHOW TABLES LIKE '" . self::getDatabaseTableName() . "'");
|
470 |
+
return ($result === 1);
|
471 |
+
}
|
472 |
+
|
473 |
+
/**
|
474 |
+
* @return string
|
475 |
+
*/
|
476 |
+
public static function getDatabaseTableName() {
|
477 |
+
global $wpdb;
|
478 |
+
return $wpdb->base_prefix . 'wpgdprc_consents';
|
479 |
+
}
|
480 |
}
|
Includes/Cron.php
CHANGED
@@ -1,91 +1,91 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WPGDPRC\Includes;
|
4 |
-
|
5 |
-
/**
|
6 |
-
* Class Cron
|
7 |
-
* @package WPGDPRC\Includes
|
8 |
-
*/
|
9 |
-
class Cron {
|
10 |
-
/** @var null */
|
11 |
-
private static $instance = null;
|
12 |
-
|
13 |
-
/**
|
14 |
-
* @param array $schedules
|
15 |
-
* @return array
|
16 |
-
*/
|
17 |
-
public function addCronSchedules($schedules = array()) {
|
18 |
-
// Once a month
|
19 |
-
$schedules['wpgdprc-monthly'] = array(
|
20 |
-
'interval' => 2635200,
|
21 |
-
'display' => __('Once a month', WP_GDPR_C_SLUG),
|
22 |
-
);
|
23 |
-
return $schedules;
|
24 |
-
}
|
25 |
-
|
26 |
-
/**
|
27 |
-
* Deactivate requests after 24 hours
|
28 |
-
*/
|
29 |
-
public function deactivateAccessRequests() {
|
30 |
-
$date = Helper::localDateTime(time());
|
31 |
-
$date->modify('-24 hours');
|
32 |
-
$requests = AccessRequest::getInstance()->getList(array(
|
33 |
-
'expired' => array(
|
34 |
-
'value' => 0
|
35 |
-
),
|
36 |
-
'date_created' => array(
|
37 |
-
'value' => $date->format('Y-m-d H:i:s'),
|
38 |
-
'compare' => '<='
|
39 |
-
)
|
40 |
-
));
|
41 |
-
if (!empty($requests)) {
|
42 |
-
foreach ($requests as $request) {
|
43 |
-
$request->setExpired(1);
|
44 |
-
$request->save();
|
45 |
-
}
|
46 |
-
}
|
47 |
-
}
|
48 |
-
|
49 |
-
/**
|
50 |
-
* Anonymise requests after 1 month
|
51 |
-
*/
|
52 |
-
public function anonymiseRequests() {
|
53 |
-
$date = Helper::localDateTime(time());
|
54 |
-
$aMonthAgo = clone $date;
|
55 |
-
$aMonthAgo->modify('-1 month');
|
56 |
-
$arguments = array(
|
57 |
-
'ip_address' => array(
|
58 |
-
'value' => '127.0.0.1',
|
59 |
-
'compare' => '!='
|
60 |
-
),
|
61 |
-
'date_created' => array(
|
62 |
-
'value' => $aMonthAgo->format('Y-m-d H:i:s'),
|
63 |
-
'compare' => '<='
|
64 |
-
)
|
65 |
-
);
|
66 |
-
$accessRequests = AccessRequest::getInstance()->getList($arguments);
|
67 |
-
$deleteRequests = DeleteRequest::getInstance()->getList($arguments);
|
68 |
-
foreach ($accessRequests as $accessRequest) {
|
69 |
-
$accessRequest->setEmailAddress(($accessRequest->getId() . '.' . $date->format('Ymd.His') . '@example.org'));
|
70 |
-
$accessRequest->setIpAddress('127.0.0.1');
|
71 |
-
$accessRequest->setExpired(1);
|
72 |
-
$accessRequest->save();
|
73 |
-
}
|
74 |
-
foreach ($deleteRequests as $deleteRequest) {
|
75 |
-
$deleteRequest->setIpAddress('127.0.0.1');
|
76 |
-
$deleteRequest->setDataId(0);
|
77 |
-
$deleteRequest->setType('unknown');
|
78 |
-
$deleteRequest->save();
|
79 |
-
}
|
80 |
-
}
|
81 |
-
|
82 |
-
/**
|
83 |
-
* @return null|Cron
|
84 |
-
*/
|
85 |
-
public static function getInstance() {
|
86 |
-
if (!isset(self::$instance)) {
|
87 |
-
self::$instance = new self();
|
88 |
-
}
|
89 |
-
return self::$instance;
|
90 |
-
}
|
91 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WPGDPRC\Includes;
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Class Cron
|
7 |
+
* @package WPGDPRC\Includes
|
8 |
+
*/
|
9 |
+
class Cron {
|
10 |
+
/** @var null */
|
11 |
+
private static $instance = null;
|
12 |
+
|
13 |
+
/**
|
14 |
+
* @param array $schedules
|
15 |
+
* @return array
|
16 |
+
*/
|
17 |
+
public function addCronSchedules($schedules = array()) {
|
18 |
+
// Once a month
|
19 |
+
$schedules['wpgdprc-monthly'] = array(
|
20 |
+
'interval' => 2635200,
|
21 |
+
'display' => __('Once a month', WP_GDPR_C_SLUG),
|
22 |
+
);
|
23 |
+
return $schedules;
|
24 |
+
}
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Deactivate requests after 24 hours
|
28 |
+
*/
|
29 |
+
public function deactivateAccessRequests() {
|
30 |
+
$date = Helper::localDateTime(time());
|
31 |
+
$date->modify('-24 hours');
|
32 |
+
$requests = AccessRequest::getInstance()->getList(array(
|
33 |
+
'expired' => array(
|
34 |
+
'value' => 0
|
35 |
+
),
|
36 |
+
'date_created' => array(
|
37 |
+
'value' => $date->format('Y-m-d H:i:s'),
|
38 |
+
'compare' => '<='
|
39 |
+
)
|
40 |
+
));
|
41 |
+
if (!empty($requests)) {
|
42 |
+
foreach ($requests as $request) {
|
43 |
+
$request->setExpired(1);
|
44 |
+
$request->save();
|
45 |
+
}
|
46 |
+
}
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Anonymise requests after 1 month
|
51 |
+
*/
|
52 |
+
public function anonymiseRequests() {
|
53 |
+
$date = Helper::localDateTime(time());
|
54 |
+
$aMonthAgo = clone $date;
|
55 |
+
$aMonthAgo->modify('-1 month');
|
56 |
+
$arguments = array(
|
57 |
+
'ip_address' => array(
|
58 |
+
'value' => '127.0.0.1',
|
59 |
+
'compare' => '!='
|
60 |
+
),
|
61 |
+
'date_created' => array(
|
62 |
+
'value' => $aMonthAgo->format('Y-m-d H:i:s'),
|
63 |
+
'compare' => '<='
|
64 |
+
)
|
65 |
+
);
|
66 |
+
$accessRequests = AccessRequest::getInstance()->getList($arguments);
|
67 |
+
$deleteRequests = DeleteRequest::getInstance()->getList($arguments);
|
68 |
+
foreach ($accessRequests as $accessRequest) {
|
69 |
+
$accessRequest->setEmailAddress(($accessRequest->getId() . '.' . $date->format('Ymd.His') . '@example.org'));
|
70 |
+
$accessRequest->setIpAddress('127.0.0.1');
|
71 |
+
$accessRequest->setExpired(1);
|
72 |
+
$accessRequest->save();
|
73 |
+
}
|
74 |
+
foreach ($deleteRequests as $deleteRequest) {
|
75 |
+
$deleteRequest->setIpAddress('127.0.0.1');
|
76 |
+
$deleteRequest->setDataId(0);
|
77 |
+
$deleteRequest->setType('unknown');
|
78 |
+
$deleteRequest->save();
|
79 |
+
}
|
80 |
+
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* @return null|Cron
|
84 |
+
*/
|
85 |
+
public static function getInstance() {
|
86 |
+
if (!isset(self::$instance)) {
|
87 |
+
self::$instance = new self();
|
88 |
+
}
|
89 |
+
return self::$instance;
|
90 |
+
}
|
91 |
}
|
Includes/Data.php
CHANGED
@@ -1,261 +1,261 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WPGDPRC\Includes;
|
4 |
-
|
5 |
-
use WPGDPRC\Includes\Data\Comment;
|
6 |
-
use WPGDPRC\Includes\Data\User;
|
7 |
-
use WPGDPRC\Includes\Data\WooCommerceOrder;
|
8 |
-
|
9 |
-
/**
|
10 |
-
* Class Data
|
11 |
-
* @package WPGDPRC\Includes
|
12 |
-
*/
|
13 |
-
class Data {
|
14 |
-
/** @var null */
|
15 |
-
private static $instance = null;
|
16 |
-
/** @var string */
|
17 |
-
protected $emailAddress = '';
|
18 |
-
|
19 |
-
/**
|
20 |
-
* Data constructor.
|
21 |
-
* @param string $emailAddress
|
22 |
-
*/
|
23 |
-
public function __construct($emailAddress = '') {
|
24 |
-
if (empty($emailAddress)) {
|
25 |
-
wp_die(
|
26 |
-
'<p>' . sprintf(
|
27 |
-
__('<strong>ERROR</strong>: %s', WP_GDPR_C_SLUG),
|
28 |
-
__('Email Address is required.', WP_GDPR_C_SLUG)
|
29 |
-
) . '</p>'
|
30 |
-
);
|
31 |
-
exit;
|
32 |
-
}
|
33 |
-
$this->setEmailAddress($emailAddress);
|
34 |
-
}
|
35 |
-
|
36 |
-
/**
|
37 |
-
* @return array
|
38 |
-
*/
|
39 |
-
public static function getPossibleDataTypes() {
|
40 |
-
return array('user', 'comment', 'woocommerce_order');
|
41 |
-
}
|
42 |
-
|
43 |
-
/**
|
44 |
-
* @param string $type
|
45 |
-
* @return array
|
46 |
-
*/
|
47 |
-
private static function getOutputColumns($type = '') {
|
48 |
-
$output = array();
|
49 |
-
switch ($type) {
|
50 |
-
case 'user' :
|
51 |
-
$output = array(
|
52 |
-
__('Username', WP_GDPR_C_SLUG),
|
53 |
-
__('Display Name', WP_GDPR_C_SLUG),
|
54 |
-
__('Email Address', WP_GDPR_C_SLUG),
|
55 |
-
__('Website', WP_GDPR_C_SLUG),
|
56 |
-
__('Registered on', WP_GDPR_C_SLUG)
|
57 |
-
);
|
58 |
-
break;
|
59 |
-
case 'comment' :
|
60 |
-
$output = array(
|
61 |
-
__('Author', WP_GDPR_C_SLUG),
|
62 |
-
__('Content', WP_GDPR_C_SLUG),
|
63 |
-
__('Email Address', WP_GDPR_C_SLUG),
|
64 |
-
__('IP Address', WP_GDPR_C_SLUG)
|
65 |
-
);
|
66 |
-
break;
|
67 |
-
case 'woocommerce_order' :
|
68 |
-
$output = array(
|
69 |
-
__('Order', WP_GDPR_C_SLUG),
|
70 |
-
__('Email Address', WP_GDPR_C_SLUG),
|
71 |
-
__('Name', WP_GDPR_C_SLUG),
|
72 |
-
__('Address', WP_GDPR_C_SLUG),
|
73 |
-
__('Postcode / ZIP', WP_GDPR_C_SLUG),
|
74 |
-
__('City', WP_GDPR_C_SLUG)
|
75 |
-
);
|
76 |
-
break;
|
77 |
-
}
|
78 |
-
$output['checkbox'] = '<input type="checkbox" class="wpgdprc-select-all" />';
|
79 |
-
return $output;
|
80 |
-
}
|
81 |
-
|
82 |
-
/**
|
83 |
-
* @param array $data
|
84 |
-
* @param string $type
|
85 |
-
* @param int $requestId
|
86 |
-
* @return array
|
87 |
-
*/
|
88 |
-
private static function getOutputData($data = array(), $type = '', $requestId = 0) {
|
89 |
-
$output = array();
|
90 |
-
$action = '<input type="checkbox" name="' . WP_GDPR_C_PREFIX . '_remove[]" class="wpgdprc-checkbox" value="%d" tabindex="1" />';
|
91 |
-
switch ($type) {
|
92 |
-
case 'user' :
|
93 |
-
/** @var User $user */
|
94 |
-
foreach ($data as $user) {
|
95 |
-
$request = DeleteRequest::getInstance()->getByTypeAndDataIdAndAccessRequestId($type, $user->getId(), $requestId);
|
96 |
-
$output[$user->getId()] = array(
|
97 |
-
$user->getUsername(),
|
98 |
-
$user->getDisplayName(),
|
99 |
-
$user->getEmailAddress(),
|
100 |
-
$user->getWebsite(),
|
101 |
-
$user->getRegisteredDate(),
|
102 |
-
(($request === false) ? sprintf($action, $user->getId()) : ' ')
|
103 |
-
);
|
104 |
-
}
|
105 |
-
break;
|
106 |
-
case 'comment' :
|
107 |
-
/** @var Comment $comment */
|
108 |
-
foreach ($data as $comment) {
|
109 |
-
$request = DeleteRequest::getInstance()->getByTypeAndDataIdAndAccessRequestId($type, $comment->getId(), $requestId);
|
110 |
-
$output[$comment->getId()] = array(
|
111 |
-
$comment->getAuthorName(),
|
112 |
-
Helper::shortenStringByWords(wp_strip_all_tags($comment->getContent(), true), 5),
|
113 |
-
$comment->getEmailAddress(),
|
114 |
-
$comment->getIpAddress(),
|
115 |
-
(($request === false) ? sprintf($action, $comment->getId()) : ' ')
|
116 |
-
);
|
117 |
-
}
|
118 |
-
break;
|
119 |
-
case 'woocommerce_order' :
|
120 |
-
/** @var WooCommerceOrder $woocommerceOrder */
|
121 |
-
foreach ($data as $woocommerceOrder) {
|
122 |
-
$request = DeleteRequest::getInstance()->getByTypeAndDataIdAndAccessRequestId($type, $woocommerceOrder->getOrderId(), $requestId);
|
123 |
-
$billingAddressTwo = $woocommerceOrder->getBillingAddressTwo();
|
124 |
-
$address = (!empty($billingAddressTwo)) ? sprintf('%s,<br />%s', $woocommerceOrder->getBillingAddressOne(), $billingAddressTwo) : $woocommerceOrder->getBillingAddressOne();
|
125 |
-
$output[$woocommerceOrder->getOrderId()] = array(
|
126 |
-
sprintf('#%d', $woocommerceOrder->getOrderId()),
|
127 |
-
$woocommerceOrder->getBillingEmailAddress(),
|
128 |
-
sprintf('%s %s', $woocommerceOrder->getBillingFirstName(), $woocommerceOrder->getBillingLastName()),
|
129 |
-
$address,
|
130 |
-
$woocommerceOrder->getBillingPostCode(),
|
131 |
-
$woocommerceOrder->getBillingCity(),
|
132 |
-
(($request === false) ? sprintf($action, $woocommerceOrder->getOrderId()) : ' ')
|
133 |
-
);
|
134 |
-
}
|
135 |
-
break;
|
136 |
-
}
|
137 |
-
return $output;
|
138 |
-
}
|
139 |
-
|
140 |
-
/**
|
141 |
-
* @param array $data
|
142 |
-
* @param string $type
|
143 |
-
* @param int $requestId
|
144 |
-
* @return string
|
145 |
-
*/
|
146 |
-
public static function getOutput($data = array(), $type = '', $requestId = 0) {
|
147 |
-
$output = '';
|
148 |
-
if (!empty($data)) {
|
149 |
-
$output .= sprintf(
|
150 |
-
'<form class="wpgdprc-form wpgdprc-form--delete-request" data-wpgdprc=\'%s\' method="POST" novalidate="novalidate">',
|
151 |
-
json_encode(array(
|
152 |
-
'type' => $type
|
153 |
-
))
|
154 |
-
);
|
155 |
-
$output .= '<div class="wpgdprc-message" style="display: none;"></div>';
|
156 |
-
$output .= '<table class="wpgdprc-table">';
|
157 |
-
$output .= '<thead>';
|
158 |
-
$output .= '<tr>';
|
159 |
-
foreach (self::getOutputColumns($type) as $key => $column) {
|
160 |
-
$class = (is_string($key)) ? $key : sanitize_title($column);
|
161 |
-
$output .= sprintf('<th class="wpgdprc-table__head wpgdprc-table__head--%s" scope="col">%s</th>', $class, $column);
|
162 |
-
}
|
163 |
-
$output .= '</tr>';
|
164 |
-
$output .= '</thead>';
|
165 |
-
$output .= '<tbody>';
|
166 |
-
foreach (self::getOutputData($data, $type, $requestId) as $id => $row) {
|
167 |
-
$output .= sprintf('<tr data-id="%d">', $id);
|
168 |
-
foreach ($row as $value) {
|
169 |
-
$output .= sprintf('<td>%s</td>', $value);
|
170 |
-
}
|
171 |
-
$output .= '</tr>';
|
172 |
-
}
|
173 |
-
$output .= '</tbody>';
|
174 |
-
$output .= '</table>';
|
175 |
-
$output .= sprintf(
|
176 |
-
'<p><input type="submit" class="wpgdprc-remove" value="%s" /></p>',
|
177 |
-
sprintf(
|
178 |
-
__('Anonymise selected %s(s)', WP_GDPR_C_SLUG),
|
179 |
-
str_replace('_', ' ', $type)
|
180 |
-
)
|
181 |
-
);
|
182 |
-
$output .= '</form>';
|
183 |
-
}
|
184 |
-
return $output;
|
185 |
-
}
|
186 |
-
|
187 |
-
/**
|
188 |
-
* @return User[]
|
189 |
-
*/
|
190 |
-
public function getUsers() {
|
191 |
-
global $wpdb;
|
192 |
-
$output = array();
|
193 |
-
$query = "SELECT * FROM `" . $wpdb->users . "` WHERE `user_email` = %s";
|
194 |
-
$results = $wpdb->get_results($wpdb->prepare($query, $this->getEmailAddress()));
|
195 |
-
if ($results !== null) {
|
196 |
-
foreach ($results as $row) {
|
197 |
-
$object = new User($row->ID);
|
198 |
-
$output[] = $object;
|
199 |
-
}
|
200 |
-
}
|
201 |
-
return $output;
|
202 |
-
}
|
203 |
-
|
204 |
-
/**
|
205 |
-
* @return Comment[]
|
206 |
-
*/
|
207 |
-
public function getComments() {
|
208 |
-
global $wpdb;
|
209 |
-
$output = array();
|
210 |
-
$query = "SELECT * FROM " . $wpdb->comments . " WHERE `comment_author_email` = %s";
|
211 |
-
$results = $wpdb->get_results($wpdb->prepare($query, $this->getEmailAddress()));
|
212 |
-
if ($results !== null) {
|
213 |
-
foreach ($results as $row) {
|
214 |
-
$object = new Comment();
|
215 |
-
$object->loadByRow($row);
|
216 |
-
$output[] = $object;
|
217 |
-
}
|
218 |
-
}
|
219 |
-
return $output;
|
220 |
-
}
|
221 |
-
|
222 |
-
/**
|
223 |
-
* @return WooCommerceOrder[]
|
224 |
-
*/
|
225 |
-
public function getWooCommerceOrders() {
|
226 |
-
global $wpdb;
|
227 |
-
$output = array();
|
228 |
-
$query = "SELECT * FROM " . $wpdb->postmeta . " WHERE `meta_key` = '_billing_email' AND `meta_value` = %s";
|
229 |
-
$results = $wpdb->get_results($wpdb->prepare($query, $this->getEmailAddress()));
|
230 |
-
if ($results !== null) {
|
231 |
-
foreach ($results as $row) {
|
232 |
-
$output[] = new WooCommerceOrder($row->post_id);
|
233 |
-
}
|
234 |
-
}
|
235 |
-
return $output;
|
236 |
-
}
|
237 |
-
|
238 |
-
/**
|
239 |
-
* @return string
|
240 |
-
*/
|
241 |
-
public function getEmailAddress() {
|
242 |
-
return $this->emailAddress;
|
243 |
-
}
|
244 |
-
|
245 |
-
/**
|
246 |
-
* @param string $emailAddress
|
247 |
-
*/
|
248 |
-
public function setEmailAddress($emailAddress) {
|
249 |
-
$this->emailAddress = $emailAddress;
|
250 |
-
}
|
251 |
-
|
252 |
-
/**
|
253 |
-
* @return null|Data
|
254 |
-
*/
|
255 |
-
public static function getInstance() {
|
256 |
-
if (!isset(self::$instance)) {
|
257 |
-
self::$instance = new self();
|
258 |
-
}
|
259 |
-
return self::$instance;
|
260 |
-
}
|
261 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WPGDPRC\Includes;
|
4 |
+
|
5 |
+
use WPGDPRC\Includes\Data\Comment;
|
6 |
+
use WPGDPRC\Includes\Data\User;
|
7 |
+
use WPGDPRC\Includes\Data\WooCommerceOrder;
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Class Data
|
11 |
+
* @package WPGDPRC\Includes
|
12 |
+
*/
|
13 |
+
class Data {
|
14 |
+
/** @var null */
|
15 |
+
private static $instance = null;
|
16 |
+
/** @var string */
|
17 |
+
protected $emailAddress = '';
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Data constructor.
|
21 |
+
* @param string $emailAddress
|
22 |
+
*/
|
23 |
+
public function __construct($emailAddress = '') {
|
24 |
+
if (empty($emailAddress)) {
|
25 |
+
wp_die(
|
26 |
+
'<p>' . sprintf(
|
27 |
+
__('<strong>ERROR</strong>: %s', WP_GDPR_C_SLUG),
|
28 |
+
__('Email Address is required.', WP_GDPR_C_SLUG)
|
29 |
+
) . '</p>'
|
30 |
+
);
|
31 |
+
exit;
|
32 |
+
}
|
33 |
+
$this->setEmailAddress($emailAddress);
|
34 |
+
}
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @return array
|
38 |
+
*/
|
39 |
+
public static function getPossibleDataTypes() {
|
40 |
+
return array('user', 'comment', 'woocommerce_order');
|
41 |
+
}
|
42 |
+
|
43 |
+
/**
|
44 |
+
* @param string $type
|
45 |
+
* @return array
|
46 |
+
*/
|
47 |
+
private static function getOutputColumns($type = '') {
|
48 |
+
$output = array();
|
49 |
+
switch ($type) {
|
50 |
+
case 'user' :
|
51 |
+
$output = array(
|
52 |
+
__('Username', WP_GDPR_C_SLUG),
|
53 |
+
__('Display Name', WP_GDPR_C_SLUG),
|
54 |
+
__('Email Address', WP_GDPR_C_SLUG),
|
55 |
+
__('Website', WP_GDPR_C_SLUG),
|
56 |
+
__('Registered on', WP_GDPR_C_SLUG)
|
57 |
+
);
|
58 |
+
break;
|
59 |
+
case 'comment' :
|
60 |
+
$output = array(
|
61 |
+
__('Author', WP_GDPR_C_SLUG),
|
62 |
+
__('Content', WP_GDPR_C_SLUG),
|
63 |
+
__('Email Address', WP_GDPR_C_SLUG),
|
64 |
+
__('IP Address', WP_GDPR_C_SLUG)
|
65 |
+
);
|
66 |
+
break;
|
67 |
+
case 'woocommerce_order' :
|
68 |
+
$output = array(
|
69 |
+
__('Order', WP_GDPR_C_SLUG),
|
70 |
+
__('Email Address', WP_GDPR_C_SLUG),
|
71 |
+
__('Name', WP_GDPR_C_SLUG),
|
72 |
+
__('Address', WP_GDPR_C_SLUG),
|
73 |
+
__('Postcode / ZIP', WP_GDPR_C_SLUG),
|
74 |
+
__('City', WP_GDPR_C_SLUG)
|
75 |
+
);
|
76 |
+
break;
|
77 |
+
}
|
78 |
+
$output['checkbox'] = '<input type="checkbox" class="wpgdprc-select-all" />';
|
79 |
+
return $output;
|
80 |
+
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* @param array $data
|
84 |
+
* @param string $type
|
85 |
+
* @param int $requestId
|
86 |
+
* @return array
|
87 |
+
*/
|
88 |
+
private static function getOutputData($data = array(), $type = '', $requestId = 0) {
|
89 |
+
$output = array();
|
90 |
+
$action = '<input type="checkbox" name="' . WP_GDPR_C_PREFIX . '_remove[]" class="wpgdprc-checkbox" value="%d" tabindex="1" />';
|
91 |
+
switch ($type) {
|
92 |
+
case 'user' :
|
93 |
+
/** @var User $user */
|
94 |
+
foreach ($data as $user) {
|
95 |
+
$request = DeleteRequest::getInstance()->getByTypeAndDataIdAndAccessRequestId($type, $user->getId(), $requestId);
|
96 |
+
$output[$user->getId()] = array(
|
97 |
+
$user->getUsername(),
|
98 |
+
$user->getDisplayName(),
|
99 |
+
$user->getEmailAddress(),
|
100 |
+
$user->getWebsite(),
|
101 |
+
$user->getRegisteredDate(),
|
102 |
+
(($request === false) ? sprintf($action, $user->getId()) : ' ')
|
103 |
+
);
|
104 |
+
}
|
105 |
+
break;
|
106 |
+
case 'comment' :
|
107 |
+
/** @var Comment $comment */
|
108 |
+
foreach ($data as $comment) {
|
109 |
+
$request = DeleteRequest::getInstance()->getByTypeAndDataIdAndAccessRequestId($type, $comment->getId(), $requestId);
|
110 |
+
$output[$comment->getId()] = array(
|
111 |
+
$comment->getAuthorName(),
|
112 |
+
Helper::shortenStringByWords(wp_strip_all_tags($comment->getContent(), true), 5),
|
113 |
+
$comment->getEmailAddress(),
|
114 |
+
$comment->getIpAddress(),
|
115 |
+
(($request === false) ? sprintf($action, $comment->getId()) : ' ')
|
116 |
+
);
|
117 |
+
}
|
118 |
+
break;
|
119 |
+
case 'woocommerce_order' :
|
120 |
+
/** @var WooCommerceOrder $woocommerceOrder */
|
121 |
+
foreach ($data as $woocommerceOrder) {
|
122 |
+
$request = DeleteRequest::getInstance()->getByTypeAndDataIdAndAccessRequestId($type, $woocommerceOrder->getOrderId(), $requestId);
|
123 |
+
$billingAddressTwo = $woocommerceOrder->getBillingAddressTwo();
|
124 |
+
$address = (!empty($billingAddressTwo)) ? sprintf('%s,<br />%s', $woocommerceOrder->getBillingAddressOne(), $billingAddressTwo) : $woocommerceOrder->getBillingAddressOne();
|
125 |
+
$output[$woocommerceOrder->getOrderId()] = array(
|
126 |
+
sprintf('#%d', $woocommerceOrder->getOrderId()),
|
127 |
+
$woocommerceOrder->getBillingEmailAddress(),
|
128 |
+
sprintf('%s %s', $woocommerceOrder->getBillingFirstName(), $woocommerceOrder->getBillingLastName()),
|
129 |
+
$address,
|
130 |
+
$woocommerceOrder->getBillingPostCode(),
|
131 |
+
$woocommerceOrder->getBillingCity(),
|
132 |
+
(($request === false) ? sprintf($action, $woocommerceOrder->getOrderId()) : ' ')
|
133 |
+
);
|
134 |
+
}
|
135 |
+
break;
|
136 |
+
}
|
137 |
+
return $output;
|
138 |
+
}
|
139 |
+
|
140 |
+
/**
|
141 |
+
* @param array $data
|
142 |
+
* @param string $type
|
143 |
+
* @param int $requestId
|
144 |
+
* @return string
|
145 |
+
*/
|
146 |
+
public static function getOutput($data = array(), $type = '', $requestId = 0) {
|
147 |
+
$output = '';
|
148 |
+
if (!empty($data)) {
|
149 |
+
$output .= sprintf(
|
150 |
+
'<form class="wpgdprc-form wpgdprc-form--delete-request" data-wpgdprc=\'%s\' method="POST" novalidate="novalidate">',
|
151 |
+
json_encode(array(
|
152 |
+
'type' => $type
|
153 |
+
))
|
154 |
+
);
|
155 |
+
$output .= '<div class="wpgdprc-message" style="display: none;"></div>';
|
156 |
+
$output .= '<table class="wpgdprc-table">';
|
157 |
+
$output .= '<thead>';
|
158 |
+
$output .= '<tr>';
|
159 |
+
foreach (self::getOutputColumns($type) as $key => $column) {
|
160 |
+
$class = (is_string($key)) ? $key : sanitize_title($column);
|
161 |
+
$output .= sprintf('<th class="wpgdprc-table__head wpgdprc-table__head--%s" scope="col">%s</th>', $class, $column);
|
162 |
+
}
|
163 |
+
$output .= '</tr>';
|
164 |
+
$output .= '</thead>';
|
165 |
+
$output .= '<tbody>';
|
166 |
+
foreach (self::getOutputData($data, $type, $requestId) as $id => $row) {
|
167 |
+
$output .= sprintf('<tr data-id="%d">', $id);
|
168 |
+
foreach ($row as $value) {
|
169 |
+
$output .= sprintf('<td>%s</td>', $value);
|
170 |
+
}
|
171 |
+
$output .= '</tr>';
|
172 |
+
}
|
173 |
+
$output .= '</tbody>';
|
174 |
+
$output .= '</table>';
|
175 |
+
$output .= sprintf(
|
176 |
+
'<p><input type="submit" class="wpgdprc-remove" value="%s" /></p>',
|
177 |
+
sprintf(
|
178 |
+
__('Anonymise selected %s(s)', WP_GDPR_C_SLUG),
|
179 |
+
str_replace('_', ' ', $type)
|
180 |
+
)
|
181 |
+
);
|
182 |
+
$output .= '</form>';
|
183 |
+
}
|
184 |
+
return $output;
|
185 |
+
}
|
186 |
+
|
187 |
+
/**
|
188 |
+
* @return User[]
|
189 |
+
*/
|
190 |
+
public function getUsers() {
|
191 |
+
global $wpdb;
|
192 |
+
$output = array();
|
193 |
+
$query = "SELECT * FROM `" . $wpdb->users . "` WHERE `user_email` = %s";
|
194 |
+
$results = $wpdb->get_results($wpdb->prepare($query, $this->getEmailAddress()));
|
195 |
+
if ($results !== null) {
|
196 |
+
foreach ($results as $row) {
|
197 |
+
$object = new User($row->ID);
|
198 |
+
$output[] = $object;
|
199 |
+
}
|
200 |
+
}
|
201 |
+
return $output;
|
202 |
+
}
|
203 |
+
|
204 |
+
/**
|
205 |
+
* @return Comment[]
|
206 |
+
*/
|
207 |
+
public function getComments() {
|
208 |
+
global $wpdb;
|
209 |
+
$output = array();
|
210 |
+
$query = "SELECT * FROM " . $wpdb->comments . " WHERE `comment_author_email` = %s";
|
211 |
+
$results = $wpdb->get_results($wpdb->prepare($query, $this->getEmailAddress()));
|
212 |
+
if ($results !== null) {
|
213 |
+
foreach ($results as $row) {
|
214 |
+
$object = new Comment();
|
215 |
+
$object->loadByRow($row);
|
216 |
+
$output[] = $object;
|
217 |
+
}
|
218 |
+
}
|
219 |
+
return $output;
|
220 |
+
}
|
221 |
+
|
222 |
+
/**
|
223 |
+
* @return WooCommerceOrder[]
|
224 |
+
*/
|
225 |
+
public function getWooCommerceOrders() {
|
226 |
+
global $wpdb;
|
227 |
+
$output = array();
|
228 |
+
$query = "SELECT * FROM " . $wpdb->postmeta . " WHERE `meta_key` = '_billing_email' AND `meta_value` = %s";
|
229 |
+
$results = $wpdb->get_results($wpdb->prepare($query, $this->getEmailAddress()));
|
230 |
+
if ($results !== null) {
|
231 |
+
foreach ($results as $row) {
|
232 |
+
$output[] = new WooCommerceOrder($row->post_id);
|
233 |
+
}
|
234 |
+
}
|
235 |
+
return $output;
|
236 |
+
}
|
237 |
+
|
238 |
+
/**
|
239 |
+
* @return string
|
240 |
+
*/
|
241 |
+
public function getEmailAddress() {
|
242 |
+
return $this->emailAddress;
|
243 |
+
}
|
244 |
+
|
245 |
+
/**
|
246 |
+
* @param string $emailAddress
|
247 |
+
*/
|
248 |
+
public function setEmailAddress($emailAddress) {
|
249 |
+
$this->emailAddress = $emailAddress;
|
250 |
+
}
|
251 |
+
|
252 |
+
/**
|
253 |
+
* @return null|Data
|
254 |
+
*/
|
255 |
+
public static function getInstance() {
|
256 |
+
if (!isset(self::$instance)) {
|
257 |
+
self::$instance = new self();
|
258 |
+
}
|
259 |
+
return self::$instance;
|
260 |
+
}
|
261 |
}
|
Includes/Data/Comment.php
CHANGED
@@ -1,167 +1,167 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WPGDPRC\Includes\Data;
|
4 |
-
|
5 |
-
/**
|
6 |
-
* Class Comment
|
7 |
-
* @package WPGDPRC\Includes\Data
|
8 |
-
*/
|
9 |
-
class Comment {
|
10 |
-
/** @var null */
|
11 |
-
private static $instance = null;
|
12 |
-
/** @var int */
|
13 |
-
protected $id = 0;
|
14 |
-
/** @var int */
|
15 |
-
protected $postId = 0;
|
16 |
-
/** @var string */
|
17 |
-
protected $name = '';
|
18 |
-
/** @var string */
|
19 |
-
protected $emailAddress = '';
|
20 |
-
/** @var string */
|
21 |
-
protected $content = '';
|
22 |
-
/** @var string */
|
23 |
-
protected $ipAddress = '';
|
24 |
-
/** @var string */
|
25 |
-
protected $date = '';
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Comment constructor.
|
29 |
-
* @param int $id
|
30 |
-
*/
|
31 |
-
public function __construct($id = 0) {
|
32 |
-
if ((int)$id > 0) {
|
33 |
-
$this->setId($id);
|
34 |
-
$this->load();
|
35 |
-
}
|
36 |
-
}
|
37 |
-
|
38 |
-
public function load() {
|
39 |
-
global $wpdb;
|
40 |
-
$query = "SELECT * FROM `" . $wpdb->users . "` WHERE `ID` = %d";
|
41 |
-
$row = $wpdb->get_row($wpdb->prepare($query, $this->getId()));
|
42 |
-
if ($row !== null) {
|
43 |
-
$this->loadByRow($row);
|
44 |
-
}
|
45 |
-
}
|
46 |
-
|
47 |
-
/**
|
48 |
-
* @param \stdClass $row
|
49 |
-
*/
|
50 |
-
public function loadByRow(\stdClass $row) {
|
51 |
-
$this->setId($row->comment_ID);
|
52 |
-
$this->setPostId($row->comment_post_ID);
|
53 |
-
$this->setName($row->comment_author);
|
54 |
-
$this->setEmailAddress($row->comment_author_email);
|
55 |
-
$this->setIpAddress($row->comment_author_IP);
|
56 |
-
$this->setContent($row->comment_content);
|
57 |
-
$this->setDate($row->comment_date);
|
58 |
-
}
|
59 |
-
|
60 |
-
/**
|
61 |
-
* @return null|Comment
|
62 |
-
*/
|
63 |
-
public static function getInstance() {
|
64 |
-
if (!isset(self::$instance)) {
|
65 |
-
self::$instance = new self();
|
66 |
-
}
|
67 |
-
return self::$instance;
|
68 |
-
}
|
69 |
-
|
70 |
-
/**
|
71 |
-
* @return int
|
72 |
-
*/
|
73 |
-
public function getId() {
|
74 |
-
return $this->id;
|
75 |
-
}
|
76 |
-
|
77 |
-
/**
|
78 |
-
* @param int $id
|
79 |
-
*/
|
80 |
-
public function setId($id) {
|
81 |
-
$this->id = $id;
|
82 |
-
}
|
83 |
-
|
84 |
-
/**
|
85 |
-
* @return int
|
86 |
-
*/
|
87 |
-
public function getPostId() {
|
88 |
-
return $this->postId;
|
89 |
-
}
|
90 |
-
|
91 |
-
/**
|
92 |
-
* @param int $postId
|
93 |
-
*/
|
94 |
-
public function setPostId($postId) {
|
95 |
-
$this->postId = $postId;
|
96 |
-
}
|
97 |
-
|
98 |
-
/**
|
99 |
-
* @return string
|
100 |
-
*/
|
101 |
-
public function getAuthorName() {
|
102 |
-
return $this->name;
|
103 |
-
}
|
104 |
-
|
105 |
-
/**
|
106 |
-
* @param string $name
|
107 |
-
*/
|
108 |
-
public function setName($name) {
|
109 |
-
$this->name = $name;
|
110 |
-
}
|
111 |
-
|
112 |
-
/**
|
113 |
-
* @return string
|
114 |
-
*/
|
115 |
-
public function getEmailAddress() {
|
116 |
-
return $this->emailAddress;
|
117 |
-
}
|
118 |
-
|
119 |
-
/**
|
120 |
-
* @param string $emailAddress
|
121 |
-
*/
|
122 |
-
public function setEmailAddress($emailAddress) {
|
123 |
-
$this->emailAddress = $emailAddress;
|
124 |
-
}
|
125 |
-
|
126 |
-
/**
|
127 |
-
* @return string
|
128 |
-
*/
|
129 |
-
public function getIpAddress() {
|
130 |
-
return $this->ipAddress;
|
131 |
-
}
|
132 |
-
|
133 |
-
/**
|
134 |
-
* @param string $ipAddress
|
135 |
-
*/
|
136 |
-
public function setIpAddress($ipAddress) {
|
137 |
-
$this->ipAddress = $ipAddress;
|
138 |
-
}
|
139 |
-
|
140 |
-
/**
|
141 |
-
* @return string
|
142 |
-
*/
|
143 |
-
public function getContent() {
|
144 |
-
return $this->content;
|
145 |
-
}
|
146 |
-
|
147 |
-
/**
|
148 |
-
* @param string $content
|
149 |
-
*/
|
150 |
-
public function setContent($content) {
|
151 |
-
$this->content = $content;
|
152 |
-
}
|
153 |
-
|
154 |
-
/**
|
155 |
-
* @return string
|
156 |
-
*/
|
157 |
-
public function getDate() {
|
158 |
-
return $this->date;
|
159 |
-
}
|
160 |
-
|
161 |
-
/**
|
162 |
-
* @param string $date
|
163 |
-
*/
|
164 |
-
public function setDate($date) {
|
165 |
-
$this->date = $date;
|
166 |
-
}
|
167 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WPGDPRC\Includes\Data;
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Class Comment
|
7 |
+
* @package WPGDPRC\Includes\Data
|
8 |
+
*/
|
9 |
+
class Comment {
|
10 |
+
/** @var null */
|
11 |
+
private static $instance = null;
|
12 |
+
/** @var int */
|
13 |
+
protected $id = 0;
|
14 |
+
/** @var int */
|
15 |
+
protected $postId = 0;
|
16 |
+
/** @var string */
|
17 |
+
protected $name = '';
|
18 |
+
/** @var string */
|
19 |
+
protected $emailAddress = '';
|
20 |
+
/** @var string */
|
21 |
+
protected $content = '';
|
22 |
+
/** @var string */
|
23 |
+
protected $ipAddress = '';
|
24 |
+
/** @var string */
|
25 |
+
protected $date = '';
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Comment constructor.
|
29 |
+
* @param int $id
|
30 |
+
*/
|
31 |
+
public function __construct($id = 0) {
|
32 |
+
if ((int)$id > 0) {
|
33 |
+
$this->setId($id);
|
34 |
+
$this->load();
|
35 |
+
}
|
36 |
+
}
|
37 |
+
|
38 |
+
public function load() {
|
39 |
+
global $wpdb;
|
40 |
+
$query = "SELECT * FROM `" . $wpdb->users . "` WHERE `ID` = %d";
|
41 |
+
$row = $wpdb->get_row($wpdb->prepare($query, $this->getId()));
|
42 |
+
if ($row !== null) {
|
43 |
+
$this->loadByRow($row);
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* @param \stdClass $row
|
49 |
+
*/
|
50 |
+
public function loadByRow(\stdClass $row) {
|
51 |
+
$this->setId($row->comment_ID);
|
52 |
+
$this->setPostId($row->comment_post_ID);
|
53 |
+
$this->setName($row->comment_author);
|
54 |
+
$this->setEmailAddress($row->comment_author_email);
|
55 |
+
$this->setIpAddress($row->comment_author_IP);
|
56 |
+
$this->setContent($row->comment_content);
|
57 |
+
$this->setDate($row->comment_date);
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* @return null|Comment
|
62 |
+
*/
|
63 |
+
public static function getInstance() {
|
64 |
+
if (!isset(self::$instance)) {
|
65 |
+
self::$instance = new self();
|
66 |
+
}
|
67 |
+
return self::$instance;
|
68 |
+
}
|
69 |
+
|
70 |
+
/**
|
71 |
+
* @return int
|
72 |
+
*/
|
73 |
+
public function getId() {
|
74 |
+
return $this->id;
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
* @param int $id
|
79 |
+
*/
|
80 |
+
public function setId($id) {
|
81 |
+
$this->id = $id;
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* @return int
|
86 |
+
*/
|
87 |
+
public function getPostId() {
|
88 |
+
return $this->postId;
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* @param int $postId
|
93 |
+
*/
|
94 |
+
public function setPostId($postId) {
|
95 |
+
$this->postId = $postId;
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* @return string
|
100 |
+
*/
|
101 |
+
public function getAuthorName() {
|
102 |
+
return $this->name;
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* @param string $name
|
107 |
+
*/
|
108 |
+
public function setName($name) {
|
109 |
+
$this->name = $name;
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* @return string
|
114 |
+
*/
|
115 |
+
public function getEmailAddress() {
|
116 |
+
return $this->emailAddress;
|
117 |
+
}
|
118 |
+
|
119 |
+
/**
|
120 |
+
* @param string $emailAddress
|
121 |
+
*/
|
122 |
+
public function setEmailAddress($emailAddress) {
|
123 |
+
$this->emailAddress = $emailAddress;
|
124 |
+
}
|
125 |
+
|
126 |
+
/**
|
127 |
+
* @return string
|
128 |
+
*/
|
129 |
+
public function getIpAddress() {
|
130 |
+
return $this->ipAddress;
|
131 |
+
}
|
132 |
+
|
133 |
+
/**
|
134 |
+
* @param string $ipAddress
|
135 |
+
*/
|
136 |
+
public function setIpAddress($ipAddress) {
|
137 |
+
$this->ipAddress = $ipAddress;
|
138 |
+
}
|
139 |
+
|
140 |
+
/**
|
141 |
+
* @return string
|
142 |
+
*/
|
143 |
+
public function getContent() {
|
144 |
+
return $this->content;
|
145 |
+
}
|
146 |
+
|
147 |
+
/**
|
148 |
+
* @param string $content
|
149 |
+
*/
|
150 |
+
public function setContent($content) {
|
151 |
+
$this->content = $content;
|
152 |
+
}
|
153 |
+
|
154 |
+
/**
|
155 |
+
* @return string
|
156 |
+
*/
|
157 |
+
public function getDate() {
|
158 |
+
return $this->date;
|
159 |
+
}
|
160 |
+
|
161 |
+
/**
|
162 |
+
* @param string $date
|
163 |
+
*/
|
164 |
+
public function setDate($date) {
|
165 |
+
$this->date = $date;
|
166 |
+
}
|
167 |
}
|
Includes/Data/User.php
CHANGED
@@ -1,188 +1,188 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WPGDPRC\Includes\Data;
|
4 |
-
|
5 |
-
/**
|
6 |
-
* Class User
|
7 |
-
* @package WPGDPRC\Includes\Data
|
8 |
-
*/
|
9 |
-
class User {
|
10 |
-
/** @var null */
|
11 |
-
private static $instance = null;
|
12 |
-
/** @var int */
|
13 |
-
protected $id = 0;
|
14 |
-
/** @var string */
|
15 |
-
protected $username = '';
|
16 |
-
/** @var string */
|
17 |
-
protected $displayName = '';
|
18 |
-
/** @var string */
|
19 |
-
protected $emailAddress = '';
|
20 |
-
/** @var string */
|
21 |
-
protected $website = '';
|
22 |
-
/** @var array */
|
23 |
-
protected $metaData = array();
|
24 |
-
/** @var string */
|
25 |
-
protected $registeredDate = '';
|
26 |
-
|
27 |
-
/**
|
28 |
-
* User constructor.
|
29 |
-
* @param int $id
|
30 |
-
*/
|
31 |
-
public function __construct($id = 0) {
|
32 |
-
if ((int)$id > 0) {
|
33 |
-
$this->setId($id);
|
34 |
-
$this->load();
|
35 |
-
$this->loadMetaData();
|
36 |
-
}
|
37 |
-
}
|
38 |
-
|
39 |
-
public function load() {
|
40 |
-
global $wpdb;
|
41 |
-
$query = "SELECT * FROM `" . $wpdb->users . "` WHERE `ID` = %d";
|
42 |
-
$row = $wpdb->get_row($wpdb->prepare($query, $this->getId()));
|
43 |
-
if ($row !== null) {
|
44 |
-
$this->loadByRow($row);
|
45 |
-
}
|
46 |
-
}
|
47 |
-
|
48 |
-
public function loadMetaData() {
|
49 |
-
$this->setMetaData($this->getMetaDataByUserId($this->getId()));
|
50 |
-
}
|
51 |
-
|
52 |
-
/**
|
53 |
-
* @param \stdClass $row
|
54 |
-
*/
|
55 |
-
public function loadByRow(\stdClass $row) {
|
56 |
-
$this->setId($row->ID);
|
57 |
-
$this->setUsername($row->user_login);
|
58 |
-
$this->setDisplayName($row->display_name);
|
59 |
-
$this->setEmailAddress($row->user_email);
|
60 |
-
$this->setWebsite($row->user_url);
|
61 |
-
$this->setRegisteredDate($row->user_registered);
|
62 |
-
}
|
63 |
-
|
64 |
-
/**
|
65 |
-
* @param int $userId
|
66 |
-
* @return array
|
67 |
-
*/
|
68 |
-
public function getMetaDataByUserId($userId = 0) {
|
69 |
-
global $wpdb;
|
70 |
-
$output = array();
|
71 |
-
$query = "SELECT * FROM `" . $wpdb->usermeta . "` WHERE `user_id` = %d";
|
72 |
-
$results = $wpdb->get_results($wpdb->prepare($query, $userId));
|
73 |
-
if ($results !== null) {
|
74 |
-
foreach ($results as $row) {
|
75 |
-
$output[] = $row;
|
76 |
-
}
|
77 |
-
}
|
78 |
-
return $output;
|
79 |
-
}
|
80 |
-
|
81 |
-
/**
|
82 |
-
* @return null|User
|
83 |
-
*/
|
84 |
-
public static function getInstance() {
|
85 |
-
if (!isset(self::$instance)) {
|
86 |
-
self::$instance = new self();
|
87 |
-
}
|
88 |
-
return self::$instance;
|
89 |
-
}
|
90 |
-
|
91 |
-
/**
|
92 |
-
* @return int
|
93 |
-
*/
|
94 |
-
public function getId() {
|
95 |
-
return $this->id;
|
96 |
-
}
|
97 |
-
|
98 |
-
/**
|
99 |
-
* @param int $id
|
100 |
-
*/
|
101 |
-
public function setId($id) {
|
102 |
-
$this->id = $id;
|
103 |
-
}
|
104 |
-
|
105 |
-
/**
|
106 |
-
* @return string
|
107 |
-
*/
|
108 |
-
public function getUsername() {
|
109 |
-
return $this->username;
|
110 |
-
}
|
111 |
-
|
112 |
-
/**
|
113 |
-
* @param string $username
|
114 |
-
*/
|
115 |
-
public function setUsername($username) {
|
116 |
-
$this->username = $username;
|
117 |
-
}
|
118 |
-
|
119 |
-
/**
|
120 |
-
* @return string
|
121 |
-
*/
|
122 |
-
public function getDisplayName() {
|
123 |
-
return $this->displayName;
|
124 |
-
}
|
125 |
-
|
126 |
-
/**
|
127 |
-
* @param string $displayName
|
128 |
-
*/
|
129 |
-
public function setDisplayName($displayName) {
|
130 |
-
$this->displayName = $displayName;
|
131 |
-
}
|
132 |
-
|
133 |
-
/**
|
134 |
-
* @return string
|
135 |
-
*/
|
136 |
-
public function getEmailAddress() {
|
137 |
-
return $this->emailAddress;
|
138 |
-
}
|
139 |
-
|
140 |
-
/**
|
141 |
-
* @param string $emailAddress
|
142 |
-
*/
|
143 |
-
public function setEmailAddress($emailAddress) {
|
144 |
-
$this->emailAddress = $emailAddress;
|
145 |
-
}
|
146 |
-
|
147 |
-
/**
|
148 |
-
* @return string
|
149 |
-
*/
|
150 |
-
public function getWebsite() {
|
151 |
-
return $this->website;
|
152 |
-
}
|
153 |
-
|
154 |
-
/**
|
155 |
-
* @param string $website
|
156 |
-
*/
|
157 |
-
public function setWebsite($website) {
|
158 |
-
$this->website = $website;
|
159 |
-
}
|
160 |
-
|
161 |
-
/**
|
162 |
-
* @return array
|
163 |
-
*/
|
164 |
-
public function getMetaData() {
|
165 |
-
return $this->metaData;
|
166 |
-
}
|
167 |
-
|
168 |
-
/**
|
169 |
-
* @param array $metaData
|
170 |
-
*/
|
171 |
-
public function setMetaData($metaData) {
|
172 |
-
$this->metaData = $metaData;
|
173 |
-
}
|
174 |
-
|
175 |
-
/**
|
176 |
-
* @return string
|
177 |
-
*/
|
178 |
-
public function getRegisteredDate() {
|
179 |
-
return $this->registeredDate;
|
180 |
-
}
|
181 |
-
|
182 |
-
/**
|
183 |
-
* @param string $registeredDate
|
184 |
-
*/
|
185 |
-
public function setRegisteredDate($registeredDate) {
|
186 |
-
$this->registeredDate = $registeredDate;
|
187 |
-
}
|
188 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WPGDPRC\Includes\Data;
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Class User
|
7 |
+
* @package WPGDPRC\Includes\Data
|
8 |
+
*/
|
9 |
+
class User {
|
10 |
+
/** @var null */
|
11 |
+
private static $instance = null;
|
12 |
+
/** @var int */
|
13 |
+
protected $id = 0;
|
14 |
+
/** @var string */
|
15 |
+
protected $username = '';
|
16 |
+
/** @var string */
|
17 |
+
protected $displayName = '';
|
18 |
+
/** @var string */
|
19 |
+
protected $emailAddress = '';
|
20 |
+
/** @var string */
|
21 |
+
protected $website = '';
|
22 |
+
/** @var array */
|
23 |
+
protected $metaData = array();
|
24 |
+
/** @var string */
|
25 |
+
protected $registeredDate = '';
|
26 |
+
|
27 |
+
/**
|
28 |
+
* User constructor.
|
29 |
+
* @param int $id
|
30 |
+
*/
|
31 |
+
public function __construct($id = 0) {
|
32 |
+
if ((int)$id > 0) {
|
33 |
+
$this->setId($id);
|
34 |
+
$this->load();
|
35 |
+
$this->loadMetaData();
|
36 |
+
}
|
37 |
+
}
|
38 |
+
|
39 |
+
public function load() {
|
40 |
+
global $wpdb;
|
41 |
+
$query = "SELECT * FROM `" . $wpdb->users . "` WHERE `ID` = %d";
|
42 |
+
$row = $wpdb->get_row($wpdb->prepare($query, $this->getId()));
|
43 |
+
if ($row !== null) {
|
44 |
+
$this->loadByRow($row);
|
45 |
+
}
|
46 |
+
}
|
47 |
+
|
48 |
+
public function loadMetaData() {
|
49 |
+
$this->setMetaData($this->getMetaDataByUserId($this->getId()));
|
50 |
+
}
|
51 |
+
|
52 |
+
/**
|
53 |
+
* @param \stdClass $row
|
54 |
+
*/
|
55 |
+
public function loadByRow(\stdClass $row) {
|
56 |
+
$this->setId($row->ID);
|
57 |
+
$this->setUsername($row->user_login);
|
58 |
+
$this->setDisplayName($row->display_name);
|
59 |
+
$this->setEmailAddress($row->user_email);
|
60 |
+
$this->setWebsite($row->user_url);
|
61 |
+
$this->setRegisteredDate($row->user_registered);
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* @param int $userId
|
66 |
+
* @return array
|
67 |
+
*/
|
68 |
+
public function getMetaDataByUserId($userId = 0) {
|
69 |
+
global $wpdb;
|
70 |
+
$output = array();
|
71 |
+
$query = "SELECT * FROM `" . $wpdb->usermeta . "` WHERE `user_id` = %d";
|
72 |
+
$results = $wpdb->get_results($wpdb->prepare($query, $userId));
|
73 |
+
if ($results !== null) {
|
74 |
+
foreach ($results as $row) {
|
75 |
+
$output[] = $row;
|
76 |
+
}
|
77 |
+
}
|
78 |
+
return $output;
|
79 |
+
}
|
80 |
+
|
81 |
+
/**
|
82 |
+
* @return null|User
|
83 |
+
*/
|
84 |
+
public static function getInstance() {
|
85 |
+
if (!isset(self::$instance)) {
|
86 |
+
self::$instance = new self();
|
87 |
+
}
|
88 |
+
return self::$instance;
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* @return int
|
93 |
+
*/
|
94 |
+
public function getId() {
|
95 |
+
return $this->id;
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* @param int $id
|
100 |
+
*/
|
101 |
+
public function setId($id) {
|
102 |
+
$this->id = $id;
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* @return string
|
107 |
+
*/
|
108 |
+
public function getUsername() {
|
109 |
+
return $this->username;
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* @param string $username
|
114 |
+
*/
|
115 |
+
public function setUsername($username) {
|
116 |
+
$this->username = $username;
|
117 |
+
}
|
118 |
+
|
119 |
+
/**
|
120 |
+
* @return string
|
121 |
+
*/
|
122 |
+
public function getDisplayName() {
|
123 |
+
return $this->displayName;
|
124 |
+
}
|
125 |
+
|
126 |
+
/**
|
127 |
+
* @param string $displayName
|
128 |
+
*/
|
129 |
+
public function setDisplayName($displayName) {
|
130 |
+
$this->displayName = $displayName;
|
131 |
+
}
|
132 |
+
|
133 |
+
/**
|
134 |
+
* @return string
|
135 |
+
*/
|
136 |
+
public function getEmailAddress() {
|
137 |
+
return $this->emailAddress;
|
138 |
+
}
|
139 |
+
|
140 |
+
/**
|
141 |
+
* @param string $emailAddress
|
142 |
+
*/
|
143 |
+
public function setEmailAddress($emailAddress) {
|
144 |
+
$this->emailAddress = $emailAddress;
|
145 |
+
}
|
146 |
+
|
147 |
+
/**
|
148 |
+
* @return string
|
149 |
+
*/
|
150 |
+
public function getWebsite() {
|
151 |
+
return $this->website;
|
152 |
+
}
|
153 |
+
|
154 |
+
/**
|
155 |
+
* @param string $website
|
156 |
+
*/
|
157 |
+
public function setWebsite($website) {
|
158 |
+
$this->website = $website;
|
159 |
+
}
|
160 |
+
|
161 |
+
/**
|
162 |
+
* @return array
|
163 |
+
*/
|
164 |
+
public function getMetaData() {
|
165 |
+
return $this->metaData;
|
166 |
+
}
|
167 |
+
|
168 |
+
/**
|
169 |
+
* @param array $metaData
|
170 |
+
*/
|
171 |
+
public function setMetaData($metaData) {
|
172 |
+
$this->metaData = $metaData;
|
173 |
+
}
|
174 |
+
|
175 |
+
/**
|
176 |
+
* @return string
|
177 |
+
*/
|
178 |
+
public function getRegisteredDate() {
|
179 |
+
return $this->registeredDate;
|
180 |
+
}
|
181 |
+
|
182 |
+
/**
|
183 |
+
* @param string $registeredDate
|
184 |
+
*/
|
185 |
+
public function setRegisteredDate($registeredDate) {
|
186 |
+
$this->registeredDate = $registeredDate;
|
187 |
+
}
|
188 |
}
|
Includes/Data/WooCommerceOrder.php
CHANGED
@@ -1,392 +1,392 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WPGDPRC\Includes\Data;
|
4 |
-
|
5 |
-
/**
|
6 |
-
* Class WooCommerceOrder
|
7 |
-
* @package WPGDPRC\Includes\Data
|
8 |
-
*/
|
9 |
-
class WooCommerceOrder {
|
10 |
-
/** @var null */
|
11 |
-
private static $instance = null;
|
12 |
-
/** @var int */
|
13 |
-
protected $orderId = 0;
|
14 |
-
/** @var string */
|
15 |
-
protected $billingEmailAddress = '';
|
16 |
-
/** @var string */
|
17 |
-
protected $billingFirstName = '';
|
18 |
-
/** @var string */
|
19 |
-
protected $billingLastName = '';
|
20 |
-
/** @var string */
|
21 |
-
protected $billingCompany = '';
|
22 |
-
/** @var string */
|
23 |
-
protected $billingAddressOne = '';
|
24 |
-
/** @var string */
|
25 |
-
protected $billingAddressTwo = '';
|
26 |
-
/** @var string */
|
27 |
-
protected $billingCity = '';
|
28 |
-
/** @var string */
|
29 |
-
protected $billingState = '';
|
30 |
-
/** @var string */
|
31 |
-
protected $billingPostCode = '';
|
32 |
-
/** @var string */
|
33 |
-
protected $billingCountry = '';
|
34 |
-
/** @var string */
|
35 |
-
protected $billingPhone = '';
|
36 |
-
/** @var string */
|
37 |
-
protected $shippingFirstName = '';
|
38 |
-
/** @var string */
|
39 |
-
protected $shippingLastName = '';
|
40 |
-
/** @var string */
|
41 |
-
protected $shippingCompany = '';
|
42 |
-
/** @var string */
|
43 |
-
protected $shippingAddressOne = '';
|
44 |
-
/** @var string */
|
45 |
-
protected $shippingAddressTwo = '';
|
46 |
-
/** @var string */
|
47 |
-
protected $shippingCity = '';
|
48 |
-
/** @var string */
|
49 |
-
protected $shippingState = '';
|
50 |
-
/** @var string */
|
51 |
-
protected $shippingPostCode = '';
|
52 |
-
/** @var string */
|
53 |
-
protected $shippingCountry = '';
|
54 |
-
|
55 |
-
/**
|
56 |
-
* User constructor.
|
57 |
-
* @param int $orderId
|
58 |
-
*/
|
59 |
-
public function __construct($orderId = 0) {
|
60 |
-
if ((int)$orderId > 0) {
|
61 |
-
$this->setOrderId($orderId);
|
62 |
-
$this->load();
|
63 |
-
}
|
64 |
-
}
|
65 |
-
|
66 |
-
public function load() {
|
67 |
-
$this->setBillingEmailAddress(get_post_meta($this->getOrderId(), '_billing_email', true));
|
68 |
-
$this->setBillingFirstName(get_post_meta($this->getOrderId(), '_billing_first_name', true));
|
69 |
-
$this->setBillingLastName(get_post_meta($this->getOrderId(), '_billing_last_name', true));
|
70 |
-
$this->setBillingCompany(get_post_meta($this->getOrderId(), '_billing_company', true));
|
71 |
-
$this->setBillingAddressOne(get_post_meta($this->getOrderId(), '_billing_address_1', true));
|
72 |
-
$this->setBillingAddressTwo(get_post_meta($this->getOrderId(), '_billing_address_2', true));
|
73 |
-
$this->setBillingCity(get_post_meta($this->getOrderId(), '_billing_city', true));
|
74 |
-
$this->setBillingState(get_post_meta($this->getOrderId(), '_billing_state', true));
|
75 |
-
$this->setBillingPostCode(get_post_meta($this->getOrderId(), '_billing_postcode', true));
|
76 |
-
$this->setBillingCountry(get_post_meta($this->getOrderId(), '_billing_country', true));
|
77 |
-
$this->setBillingPhone(get_post_meta($this->getOrderId(), '_billing_phone', true));
|
78 |
-
$this->setShippingFirstName(get_post_meta($this->getOrderId(), '_shipping_first_name', true));
|
79 |
-
$this->setShippingLastName(get_post_meta($this->getOrderId(), '_shipping_last_name', true));
|
80 |
-
$this->setShippingCompany(get_post_meta($this->getOrderId(), '_shipping_company', true));
|
81 |
-
$this->setShippingAddressOne(get_post_meta($this->getOrderId(), '_shipping_address_1', true));
|
82 |
-
$this->setShippingAddressTwo(get_post_meta($this->getOrderId(), '_shipping_address_2', true));
|
83 |
-
$this->setShippingCity(get_post_meta($this->getOrderId(), '_shipping_city', true));
|
84 |
-
$this->setShippingState(get_post_meta($this->getOrderId(), '_shipping_state', true));
|
85 |
-
$this->setShippingPostCode(get_post_meta($this->getOrderId(), '_shipping_postcode', true));
|
86 |
-
$this->setShippingCountry(get_post_meta($this->getOrderId(), '_shipping_country', true));
|
87 |
-
}
|
88 |
-
|
89 |
-
/**
|
90 |
-
* @return null|WooCommerceOrder
|
91 |
-
*/
|
92 |
-
public static function getInstance() {
|
93 |
-
if (!isset(self::$instance)) {
|
94 |
-
self::$instance = new self();
|
95 |
-
}
|
96 |
-
return self::$instance;
|
97 |
-
}
|
98 |
-
|
99 |
-
/**
|
100 |
-
* @return int
|
101 |
-
*/
|
102 |
-
public function getOrderId() {
|
103 |
-
return $this->orderId;
|
104 |
-
}
|
105 |
-
|
106 |
-
/**
|
107 |
-
* @param int $orderId
|
108 |
-
*/
|
109 |
-
public function setOrderId($orderId) {
|
110 |
-
$this->orderId = $orderId;
|
111 |
-
}
|
112 |
-
|
113 |
-
/**
|
114 |
-
* @return string
|
115 |
-
*/
|
116 |
-
public function getBillingEmailAddress() {
|
117 |
-
return $this->billingEmailAddress;
|
118 |
-
}
|
119 |
-
|
120 |
-
/**
|
121 |
-
* @param string $billingEmailAddress
|
122 |
-
*/
|
123 |
-
public function setBillingEmailAddress($billingEmailAddress) {
|
124 |
-
$this->billingEmailAddress = $billingEmailAddress;
|
125 |
-
}
|
126 |
-
|
127 |
-
/**
|
128 |
-
* @return string
|
129 |
-
*/
|
130 |
-
public function getBillingFirstName() {
|
131 |
-
return $this->billingFirstName;
|
132 |
-
}
|
133 |
-
|
134 |
-
/**
|
135 |
-
* @param string $billingFirstName
|
136 |
-
*/
|
137 |
-
public function setBillingFirstName($billingFirstName) {
|
138 |
-
$this->billingFirstName = $billingFirstName;
|
139 |
-
}
|
140 |
-
|
141 |
-
/**
|
142 |
-
* @return string
|
143 |
-
*/
|
144 |
-
public function getBillingLastName() {
|
145 |
-
return $this->billingLastName;
|
146 |
-
}
|
147 |
-
|
148 |
-
/**
|
149 |
-
* @param string $billingLastName
|
150 |
-
*/
|
151 |
-
public function setBillingLastName($billingLastName) {
|
152 |
-
$this->billingLastName = $billingLastName;
|
153 |
-
}
|
154 |
-
|
155 |
-
/**
|
156 |
-
* @return string
|
157 |
-
*/
|
158 |
-
public function getBillingCompany() {
|
159 |
-
return $this->billingCompany;
|
160 |
-
}
|
161 |
-
|
162 |
-
/**
|
163 |
-
* @param string $billingCompany
|
164 |
-
*/
|
165 |
-
public function setBillingCompany($billingCompany) {
|
166 |
-
$this->billingCompany = $billingCompany;
|
167 |
-
}
|
168 |
-
|
169 |
-
/**
|
170 |
-
* @return string
|
171 |
-
*/
|
172 |
-
public function getBillingAddressOne() {
|
173 |
-
return $this->billingAddressOne;
|
174 |
-
}
|
175 |
-
|
176 |
-
/**
|
177 |
-
* @param string $billingAddressOne
|
178 |
-
*/
|
179 |
-
public function setBillingAddressOne($billingAddressOne) {
|
180 |
-
$this->billingAddressOne = $billingAddressOne;
|
181 |
-
}
|
182 |
-
|
183 |
-
/**
|
184 |
-
* @return string
|
185 |
-
*/
|
186 |
-
public function getBillingAddressTwo() {
|
187 |
-
return $this->billingAddressTwo;
|
188 |
-
}
|
189 |
-
|
190 |
-
/**
|
191 |
-
* @param string $billingAddressTwo
|
192 |
-
*/
|
193 |
-
public function setBillingAddressTwo($billingAddressTwo) {
|
194 |
-
$this->billingAddressTwo = $billingAddressTwo;
|
195 |
-
}
|
196 |
-
|
197 |
-
/**
|
198 |
-
* @return string
|
199 |
-
*/
|
200 |
-
public function getBillingCity() {
|
201 |
-
return $this->billingCity;
|
202 |
-
}
|
203 |
-
|
204 |
-
/**
|
205 |
-
* @param string $billingCity
|
206 |
-
*/
|
207 |
-
public function setBillingCity($billingCity) {
|
208 |
-
$this->billingCity = $billingCity;
|
209 |
-
}
|
210 |
-
|
211 |
-
/**
|
212 |
-
* @return string
|
213 |
-
*/
|
214 |
-
public function getBillingState() {
|
215 |
-
return $this->billingState;
|
216 |
-
}
|
217 |
-
|
218 |
-
/**
|
219 |
-
* @param string $billingState
|
220 |
-
*/
|
221 |
-
public function setBillingState($billingState) {
|
222 |
-
$this->billingState = $billingState;
|
223 |
-
}
|
224 |
-
|
225 |
-
/**
|
226 |
-
* @return string
|
227 |
-
*/
|
228 |
-
public function getBillingPostCode() {
|
229 |
-
return $this->billingPostCode;
|
230 |
-
}
|
231 |
-
|
232 |
-
/**
|
233 |
-
* @param string $billingPostCode
|
234 |
-
*/
|
235 |
-
public function setBillingPostCode($billingPostCode) {
|
236 |
-
$this->billingPostCode = $billingPostCode;
|
237 |
-
}
|
238 |
-
|
239 |
-
/**
|
240 |
-
* @return string
|
241 |
-
*/
|
242 |
-
public function getBillingCountry() {
|
243 |
-
return $this->billingCountry;
|
244 |
-
}
|
245 |
-
|
246 |
-
/**
|
247 |
-
* @param string $billingCountry
|
248 |
-
*/
|
249 |
-
public function setBillingCountry($billingCountry) {
|
250 |
-
$this->billingCountry = $billingCountry;
|
251 |
-
}
|
252 |
-
|
253 |
-
/**
|
254 |
-
* @return string
|
255 |
-
*/
|
256 |
-
public function getBillingPhone() {
|
257 |
-
return $this->billingPhone;
|
258 |
-
}
|
259 |
-
|
260 |
-
/**
|
261 |
-
* @param string $billingPhone
|
262 |
-
*/
|
263 |
-
public function setBillingPhone($billingPhone) {
|
264 |
-
$this->billingPhone = $billingPhone;
|
265 |
-
}
|
266 |
-
|
267 |
-
/**
|
268 |
-
* @return string
|
269 |
-
*/
|
270 |
-
public function getShippingFirstName() {
|
271 |
-
return $this->shippingFirstName;
|
272 |
-
}
|
273 |
-
|
274 |
-
/**
|
275 |
-
* @param string $shippingFirstName
|
276 |
-
*/
|
277 |
-
public function setShippingFirstName($shippingFirstName) {
|
278 |
-
$this->shippingFirstName = $shippingFirstName;
|
279 |
-
}
|
280 |
-
|
281 |
-
/**
|
282 |
-
* @return string
|
283 |
-
*/
|
284 |
-
public function getShippingLastName() {
|
285 |
-
return $this->shippingLastName;
|
286 |
-
}
|
287 |
-
|
288 |
-
/**
|
289 |
-
* @param string $shippingLastName
|
290 |
-
*/
|
291 |
-
public function setShippingLastName($shippingLastName) {
|
292 |
-
$this->shippingLastName = $shippingLastName;
|
293 |
-
}
|
294 |
-
|
295 |
-
/**
|
296 |
-
* @return string
|
297 |
-
*/
|
298 |
-
public function getShippingCompany() {
|
299 |
-
return $this->shippingCompany;
|
300 |
-
}
|
301 |
-
|
302 |
-
/**
|
303 |
-
* @param string $shippingCompany
|
304 |
-
*/
|
305 |
-
public function setShippingCompany($shippingCompany) {
|
306 |
-
$this->shippingCompany = $shippingCompany;
|
307 |
-
}
|
308 |
-
|
309 |
-
/**
|
310 |
-
* @return string
|
311 |
-
*/
|
312 |
-
public function getShippingAddressOne() {
|
313 |
-
return $this->shippingAddressOne;
|
314 |
-
}
|
315 |
-
|
316 |
-
/**
|
317 |
-
* @param string $shippingAddressOne
|
318 |
-
*/
|
319 |
-
public function setShippingAddressOne($shippingAddressOne) {
|
320 |
-
$this->shippingAddressOne = $shippingAddressOne;
|
321 |
-
}
|
322 |
-
|
323 |
-
/**
|
324 |
-
* @return string
|
325 |
-
*/
|
326 |
-
public function getShippingAddressTwo() {
|
327 |
-
return $this->shippingAddressTwo;
|
328 |
-
}
|
329 |
-
|
330 |
-
/**
|
331 |
-
* @param string $shippingAddressTwo
|
332 |
-
*/
|
333 |
-
public function setShippingAddressTwo($shippingAddressTwo) {
|
334 |
-
$this->shippingAddressTwo = $shippingAddressTwo;
|
335 |
-
}
|
336 |
-
|
337 |
-
/**
|
338 |
-
* @return string
|
339 |
-
*/
|
340 |
-
public function getShippingCity() {
|
341 |
-
return $this->shippingCity;
|
342 |
-
}
|
343 |
-
|
344 |
-
/**
|
345 |
-
* @param string $shippingCity
|
346 |
-
*/
|
347 |
-
public function setShippingCity($shippingCity) {
|
348 |
-
$this->shippingCity = $shippingCity;
|
349 |
-
}
|
350 |
-
|
351 |
-
/**
|
352 |
-
* @return string
|
353 |
-
*/
|
354 |
-
public function getShippingState() {
|
355 |
-
return $this->shippingState;
|
356 |
-
}
|
357 |
-
|
358 |
-
/**
|
359 |
-
* @param string $shippingState
|
360 |
-
*/
|
361 |
-
public function setShippingState($shippingState) {
|
362 |
-
$this->shippingState = $shippingState;
|
363 |
-
}
|
364 |
-
|
365 |
-
/**
|
366 |
-
* @return string
|
367 |
-
*/
|
368 |
-
public function getShippingPostCode() {
|
369 |
-
return $this->shippingPostCode;
|
370 |
-
}
|
371 |
-
|
372 |
-
/**
|
373 |
-
* @param string $shippingPostCode
|
374 |
-
*/
|
375 |
-
public function setShippingPostCode($shippingPostCode) {
|
376 |
-
$this->shippingPostCode = $shippingPostCode;
|
377 |
-
}
|
378 |
-
|
379 |
-
/**
|
380 |
-
* @return string
|
381 |
-
*/
|
382 |
-
public function getShippingCountry() {
|
383 |
-
return $this->shippingCountry;
|
384 |
-
}
|
385 |
-
|
386 |
-
/**
|
387 |
-
* @param string $shippingCountry
|
388 |
-
*/
|
389 |
-
public function setShippingCountry($shippingCountry) {
|
390 |
-
$this->shippingCountry = $shippingCountry;
|
391 |
-
}
|
392 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WPGDPRC\Includes\Data;
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Class WooCommerceOrder
|
7 |
+
* @package WPGDPRC\Includes\Data
|
8 |
+
*/
|
9 |
+
class WooCommerceOrder {
|
10 |
+
/** @var null */
|
11 |
+
private static $instance = null;
|
12 |
+
/** @var int */
|
13 |
+
protected $orderId = 0;
|
14 |
+
/** @var string */
|
15 |
+
protected $billingEmailAddress = '';
|
16 |
+
/** @var string */
|
17 |
+
protected $billingFirstName = '';
|
18 |
+
/** @var string */
|
19 |
+
protected $billingLastName = '';
|
20 |
+
/** @var string */
|
21 |
+
protected $billingCompany = '';
|
22 |
+
/** @var string */
|
23 |
+
protected $billingAddressOne = '';
|
24 |
+
/** @var string */
|
25 |
+
protected $billingAddressTwo = '';
|
26 |
+
/** @var string */
|
27 |
+
protected $billingCity = '';
|
28 |
+
/** @var string */
|
29 |
+
protected $billingState = '';
|
30 |
+
/** @var string */
|
31 |
+
protected $billingPostCode = '';
|
32 |
+
/** @var string */
|
33 |
+
protected $billingCountry = '';
|
34 |
+
/** @var string */
|
35 |
+
protected $billingPhone = '';
|
36 |
+
/** @var string */
|
37 |
+
protected $shippingFirstName = '';
|
38 |
+
/** @var string */
|
39 |
+
protected $shippingLastName = '';
|
40 |
+
/** @var string */
|
41 |
+
protected $shippingCompany = '';
|
42 |
+
/** @var string */
|
43 |
+
protected $shippingAddressOne = '';
|
44 |
+
/** @var string */
|
45 |
+
protected $shippingAddressTwo = '';
|
46 |
+
/** @var string */
|
47 |
+
protected $shippingCity = '';
|
48 |
+
/** @var string */
|
49 |
+
protected $shippingState = '';
|
50 |
+
/** @var string */
|
51 |
+
protected $shippingPostCode = '';
|
52 |
+
/** @var string */
|
53 |
+
protected $shippingCountry = '';
|
54 |
+
|
55 |
+
/**
|
56 |
+
* User constructor.
|
57 |
+
* @param int $orderId
|
58 |
+
*/
|
59 |
+
public function __construct($orderId = 0) {
|
60 |
+
if ((int)$orderId > 0) {
|
61 |
+
$this->setOrderId($orderId);
|
62 |
+
$this->load();
|
63 |
+
}
|
64 |
+
}
|
65 |
+
|
66 |
+
public function load() {
|
67 |
+
$this->setBillingEmailAddress(get_post_meta($this->getOrderId(), '_billing_email', true));
|
68 |
+
$this->setBillingFirstName(get_post_meta($this->getOrderId(), '_billing_first_name', true));
|
69 |
+
$this->setBillingLastName(get_post_meta($this->getOrderId(), '_billing_last_name', true));
|
70 |
+
$this->setBillingCompany(get_post_meta($this->getOrderId(), '_billing_company', true));
|
71 |
+
$this->setBillingAddressOne(get_post_meta($this->getOrderId(), '_billing_address_1', true));
|
72 |
+
$this->setBillingAddressTwo(get_post_meta($this->getOrderId(), '_billing_address_2', true));
|
73 |
+
$this->setBillingCity(get_post_meta($this->getOrderId(), '_billing_city', true));
|
74 |
+
$this->setBillingState(get_post_meta($this->getOrderId(), '_billing_state', true));
|
75 |
+
$this->setBillingPostCode(get_post_meta($this->getOrderId(), '_billing_postcode', true));
|
76 |
+
$this->setBillingCountry(get_post_meta($this->getOrderId(), '_billing_country', true));
|
77 |
+
$this->setBillingPhone(get_post_meta($this->getOrderId(), '_billing_phone', true));
|
78 |
+
$this->setShippingFirstName(get_post_meta($this->getOrderId(), '_shipping_first_name', true));
|
79 |
+
$this->setShippingLastName(get_post_meta($this->getOrderId(), '_shipping_last_name', true));
|
80 |
+
$this->setShippingCompany(get_post_meta($this->getOrderId(), '_shipping_company', true));
|
81 |
+
$this->setShippingAddressOne(get_post_meta($this->getOrderId(), '_shipping_address_1', true));
|
82 |
+
$this->setShippingAddressTwo(get_post_meta($this->getOrderId(), '_shipping_address_2', true));
|
83 |
+
$this->setShippingCity(get_post_meta($this->getOrderId(), '_shipping_city', true));
|
84 |
+
$this->setShippingState(get_post_meta($this->getOrderId(), '_shipping_state', true));
|
85 |
+
$this->setShippingPostCode(get_post_meta($this->getOrderId(), '_shipping_postcode', true));
|
86 |
+
$this->setShippingCountry(get_post_meta($this->getOrderId(), '_shipping_country', true));
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* @return null|WooCommerceOrder
|
91 |
+
*/
|
92 |
+
public static function getInstance() {
|
93 |
+
if (!isset(self::$instance)) {
|
94 |
+
self::$instance = new self();
|
95 |
+
}
|
96 |
+
return self::$instance;
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* @return int
|
101 |
+
*/
|
102 |
+
public function getOrderId() {
|
103 |
+
return $this->orderId;
|
104 |
+
}
|
105 |
+
|
106 |
+
/**
|
107 |
+
* @param int $orderId
|
108 |
+
*/
|
109 |
+
public function setOrderId($orderId) {
|
110 |
+
$this->orderId = $orderId;
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* @return string
|
115 |
+
*/
|
116 |
+
public function getBillingEmailAddress() {
|
117 |
+
return $this->billingEmailAddress;
|
118 |
+
}
|
119 |
+
|
120 |
+
/**
|
121 |
+
* @param string $billingEmailAddress
|
122 |
+
*/
|
123 |
+
public function setBillingEmailAddress($billingEmailAddress) {
|
124 |
+
$this->billingEmailAddress = $billingEmailAddress;
|
125 |
+
}
|
126 |
+
|
127 |
+
/**
|
128 |
+
* @return string
|
129 |
+
*/
|
130 |
+
public function getBillingFirstName() {
|
131 |
+
return $this->billingFirstName;
|
132 |
+
}
|
133 |
+
|
134 |
+
/**
|
135 |
+
* @param string $billingFirstName
|
136 |
+
*/
|
137 |
+
public function setBillingFirstName($billingFirstName) {
|
138 |
+
$this->billingFirstName = $billingFirstName;
|
139 |
+
}
|
140 |
+
|
141 |
+
/**
|
142 |
+
* @return string
|
143 |
+
*/
|
144 |
+
public function getBillingLastName() {
|
145 |
+
return $this->billingLastName;
|
146 |
+
}
|
147 |
+
|
148 |
+
/**
|
149 |
+
* @param string $billingLastName
|
150 |
+
*/
|
151 |
+
public function setBillingLastName($billingLastName) {
|
152 |
+
$this->billingLastName = $billingLastName;
|
153 |
+
}
|
154 |
+
|
155 |
+
/**
|
156 |
+
* @return string
|
157 |
+
*/
|
158 |
+
public function getBillingCompany() {
|
159 |
+
return $this->billingCompany;
|
160 |
+
}
|
161 |
+
|
162 |
+
/**
|
163 |
+
* @param string $billingCompany
|
164 |
+
*/
|
165 |
+
public function setBillingCompany($billingCompany) {
|
166 |
+
$this->billingCompany = $billingCompany;
|
167 |
+
}
|
168 |
+
|
169 |
+
/**
|
170 |
+
* @return string
|
171 |
+
*/
|
172 |
+
public function getBillingAddressOne() {
|
173 |
+
return $this->billingAddressOne;
|
174 |
+
}
|
175 |
+
|
176 |
+
/**
|
177 |
+
* @param string $billingAddressOne
|
178 |
+
*/
|
179 |
+
public function setBillingAddressOne($billingAddressOne) {
|
180 |
+
$this->billingAddressOne = $billingAddressOne;
|
181 |
+
}
|
182 |
+
|
183 |
+
/**
|
184 |
+
* @return string
|
185 |
+
*/
|
186 |
+
public function getBillingAddressTwo() {
|
187 |
+
return $this->billingAddressTwo;
|
188 |
+
}
|
189 |
+
|
190 |
+
/**
|
191 |
+
* @param string $billingAddressTwo
|
192 |
+
*/
|
193 |
+
public function setBillingAddressTwo($billingAddressTwo) {
|
194 |
+
$this->billingAddressTwo = $billingAddressTwo;
|
195 |
+
}
|
196 |
+
|
197 |
+
/**
|
198 |
+
* @return string
|
199 |
+
*/
|
200 |
+
public function getBillingCity() {
|
201 |
+
return $this->billingCity;
|
202 |
+
}
|
203 |
+
|
204 |
+
/**
|
205 |
+
* @param string $billingCity
|
206 |
+
*/
|
207 |
+
public function setBillingCity($billingCity) {
|
208 |
+
$this->billingCity = $billingCity;
|
209 |
+
}
|
210 |
+
|
211 |
+
/**
|
212 |
+
* @return string
|
213 |
+
*/
|
214 |
+
public function getBillingState() {
|
215 |
+
return $this->billingState;
|
216 |
+
}
|
217 |
+
|
218 |
+
/**
|
219 |
+
* @param string $billingState
|
220 |
+
*/
|
221 |
+
public function setBillingState($billingState) {
|
222 |
+
$this->billingState = $billingState;
|
223 |
+
}
|
224 |
+
|
225 |
+
/**
|
226 |
+
* @return string
|
227 |
+
*/
|
228 |
+
public function getBillingPostCode() {
|
229 |
+
return $this->billingPostCode;
|
230 |
+
}
|
231 |
+
|
232 |
+
/**
|
233 |
+
* @param string $billingPostCode
|
234 |
+
*/
|
235 |
+
public function setBillingPostCode($billingPostCode) {
|
236 |
+
$this->billingPostCode = $billingPostCode;
|
237 |
+
}
|
238 |
+
|
239 |
+
/**
|
240 |
+
* @return string
|
241 |
+
*/
|
242 |
+
public function getBillingCountry() {
|
243 |
+
return $this->billingCountry;
|
244 |
+
}
|
245 |
+
|
246 |
+
/**
|
247 |
+
* @param string $billingCountry
|
248 |
+
*/
|
249 |
+
public function setBillingCountry($billingCountry) {
|
250 |
+
$this->billingCountry = $billingCountry;
|
251 |
+
}
|
252 |
+
|
253 |
+
/**
|
254 |
+
* @return string
|
255 |
+
*/
|
256 |
+
public function getBillingPhone() {
|
257 |
+
return $this->billingPhone;
|
258 |
+
}
|
259 |
+
|
260 |
+
/**
|
261 |
+
* @param string $billingPhone
|
262 |
+
*/
|
263 |
+
public function setBillingPhone($billingPhone) {
|
264 |
+
$this->billingPhone = $billingPhone;
|
265 |
+
}
|
266 |
+
|
267 |
+
/**
|
268 |
+
* @return string
|
269 |
+
*/
|
270 |
+
public function getShippingFirstName() {
|
271 |
+
return $this->shippingFirstName;
|
272 |
+
}
|
273 |
+
|
274 |
+
/**
|
275 |
+
* @param string $shippingFirstName
|
276 |
+
*/
|
277 |
+
public function setShippingFirstName($shippingFirstName) {
|
278 |
+
$this->shippingFirstName = $shippingFirstName;
|
279 |
+
}
|
280 |
+
|
281 |
+
/**
|
282 |
+
* @return string
|
283 |
+
*/
|
284 |
+
public function getShippingLastName() {
|
285 |
+
return $this->shippingLastName;
|
286 |
+
}
|
287 |
+
|
288 |
+
/**
|
289 |
+
* @param string $shippingLastName
|
290 |
+
*/
|
291 |
+
public function setShippingLastName($shippingLastName) {
|
292 |
+
$this->shippingLastName = $shippingLastName;
|
293 |
+
}
|
294 |
+
|
295 |
+
/**
|
296 |
+
* @return string
|
297 |
+
*/
|
298 |
+
public function getShippingCompany() {
|
299 |
+
return $this->shippingCompany;
|
300 |
+
}
|
301 |
+
|
302 |
+
/**
|
303 |
+
* @param string $shippingCompany
|
304 |
+
*/
|
305 |
+
public function setShippingCompany($shippingCompany) {
|
306 |
+
$this->shippingCompany = $shippingCompany;
|
307 |
+
}
|
308 |
+
|
309 |
+
/**
|
310 |
+
* @return string
|
311 |
+
*/
|
312 |
+
public function getShippingAddressOne() {
|
313 |
+
return $this->shippingAddressOne;
|
314 |
+
}
|
315 |
+
|
316 |
+
/**
|
317 |
+
* @param string $shippingAddressOne
|
318 |
+
*/
|
319 |
+
public function setShippingAddressOne($shippingAddressOne) {
|
320 |
+
$this->shippingAddressOne = $shippingAddressOne;
|
321 |
+
}
|
322 |
+
|
323 |
+
/**
|
324 |
+
* @return string
|
325 |
+
*/
|
326 |
+
public function getShippingAddressTwo() {
|
327 |
+
return $this->shippingAddressTwo;
|
328 |
+
}
|
329 |
+
|
330 |
+
/**
|
331 |
+
* @param string $shippingAddressTwo
|
332 |
+
*/
|
333 |
+
public function setShippingAddressTwo($shippingAddressTwo) {
|
334 |
+
$this->shippingAddressTwo = $shippingAddressTwo;
|
335 |
+
}
|
336 |
+
|
337 |
+
/**
|
338 |
+
* @return string
|
339 |
+
*/
|
340 |
+
public function getShippingCity() {
|
341 |
+
return $this->shippingCity;
|
342 |
+
}
|
343 |
+
|
344 |
+
/**
|
345 |
+
* @param string $shippingCity
|
346 |
+
*/
|
347 |
+
public function setShippingCity($shippingCity) {
|
348 |
+
$this->shippingCity = $shippingCity;
|
349 |
+
}
|
350 |
+
|
351 |
+
/**
|
352 |
+
* @return string
|
353 |
+
*/
|
354 |
+
public function getShippingState() {
|
355 |
+
return $this->shippingState;
|
356 |
+
}
|
357 |
+
|
358 |
+
/**
|
359 |
+
* @param string $shippingState
|
360 |
+
*/
|
361 |
+
public function setShippingState($shippingState) {
|
362 |
+
$this->shippingState = $shippingState;
|
363 |
+
}
|
364 |
+
|
365 |
+
/**
|
366 |
+
* @return string
|
367 |
+
*/
|
368 |
+
public function getShippingPostCode() {
|
369 |
+
return $this->shippingPostCode;
|
370 |
+
}
|
371 |
+
|
372 |
+
/**
|
373 |
+
* @param string $shippingPostCode
|
374 |
+
*/
|
375 |
+
public function setShippingPostCode($shippingPostCode) {
|
376 |
+
$this->shippingPostCode = $shippingPostCode;
|
377 |
+
}
|
378 |
+
|
379 |
+
/**
|
380 |
+
* @return string
|
381 |
+
*/
|
382 |
+
public function getShippingCountry() {
|
383 |
+
return $this->shippingCountry;
|
384 |
+
}
|
385 |
+
|
386 |
+
/**
|
387 |
+
* @param string $shippingCountry
|
388 |
+
*/
|
389 |
+
public function setShippingCountry($shippingCountry) {
|
390 |
+
$this->shippingCountry = $shippingCountry;
|
391 |
+
}
|
392 |
}
|
Includes/DeleteRequest.php
CHANGED
@@ -1,408 +1,408 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WPGDPRC\Includes;
|
4 |
-
|
5 |
-
/**
|
6 |
-
* Class DeleteRequest
|
7 |
-
* @package WPGDPRC\Includes
|
8 |
-
*/
|
9 |
-
class DeleteRequest {
|
10 |
-
/** @var null */
|
11 |
-
private static $instance = null;
|
12 |
-
/** @var int */
|
13 |
-
private $id = 0;
|
14 |
-
/** @var int */
|
15 |
-
private $siteId = 0;
|
16 |
-
/** @var int */
|
17 |
-
private $accessRequestId = 0;
|
18 |
-
/** @var string */
|
19 |
-
private $sessionId = '';
|
20 |
-
/** @var string */
|
21 |
-
private $ipAddress = '';
|
22 |
-
/** @var int */
|
23 |
-
private $dataId = 0;
|
24 |
-
/** @var string */
|
25 |
-
private $type = '';
|
26 |
-
/** @var int */
|
27 |
-
private $processed = 0;
|
28 |
-
/** @var string */
|
29 |
-
private $dateCreated = '';
|
30 |
-
|
31 |
-
/**
|
32 |
-
* DeleteRequest constructor.
|
33 |
-
* @param int $id
|
34 |
-
*/
|
35 |
-
public function __construct($id = 0) {
|
36 |
-
if ((int)$id > 0) {
|
37 |
-
$this->setId($id);
|
38 |
-
$this->load();
|
39 |
-
}
|
40 |
-
}
|
41 |
-
|
42 |
-
/**
|
43 |
-
* @param string $type
|
44 |
-
* @param int $dataId
|
45 |
-
* @param int $accessRequestId
|
46 |
-
* @return bool|DeleteRequest
|
47 |
-
*/
|
48 |
-
public function getByTypeAndDataIdAndAccessRequestId($type = '', $dataId = 0, $accessRequestId = 0) {
|
49 |
-
global $wpdb;
|
50 |
-
$query = "SELECT `ID` FROM `" . self::getDatabaseTableName() . "`";
|
51 |
-
$query .= " WHERE `type` = %s";
|
52 |
-
$query .= " AND `data_id` = %d";
|
53 |
-
$query .= " AND `access_request_id` = %d";
|
54 |
-
$query .= " AND `site_id` = %d";
|
55 |
-
$result = $wpdb->get_row($wpdb->prepare($query, $type, $dataId, $accessRequestId, get_current_blog_id()));
|
56 |
-
if ($result !== null) {
|
57 |
-
return new self($result->ID);
|
58 |
-
}
|
59 |
-
return false;
|
60 |
-
}
|
61 |
-
|
62 |
-
/**
|
63 |
-
* @param int $accessRequestId
|
64 |
-
* @param bool $showAnonymised
|
65 |
-
* @return int
|
66 |
-
*/
|
67 |
-
public function getAmountByAccessRequestId($accessRequestId = 0, $showAnonymised = true) {
|
68 |
-
global $wpdb;
|
69 |
-
$query = "SELECT COUNT(`ID`) FROM `" . self::getDatabaseTableName() . "`";
|
70 |
-
$query .= " WHERE `access_request_id` = %d";
|
71 |
-
if ($showAnonymised === false) {
|
72 |
-
$query .= " AND `ip_address` != '127.0.0.1'";
|
73 |
-
}
|
74 |
-
$query .= " AND `processed` = '0'";
|
75 |
-
$query .= " AND `site_id` = %d";
|
76 |
-
$result = $wpdb->get_var($wpdb->prepare($query, intval($accessRequestId), get_current_blog_id()));
|
77 |
-
if ($result !== null) {
|
78 |
-
return absint($result);
|
79 |
-
}
|
80 |
-
return 0;
|
81 |
-
}
|
82 |
-
|
83 |
-
/**
|
84 |
-
* @param array $filters
|
85 |
-
* @return int
|
86 |
-
*/
|
87 |
-
public function getTotal($filters = array()) {
|
88 |
-
global $wpdb;
|
89 |
-
$query = "SELECT COUNT(`ID`) FROM `" . self::getDatabaseTableName() . "` WHERE 1";
|
90 |
-
$query .= Helper::getQueryByFilters($filters);
|
91 |
-
$query .= sprintf(" AND `site_id` = '%d'", get_current_blog_id());
|
92 |
-
$result = $wpdb->get_var($query);
|
93 |
-
if ($result !== null) {
|
94 |
-
return absint($result);
|
95 |
-
}
|
96 |
-
return 0;
|
97 |
-
}
|
98 |
-
|
99 |
-
/**
|
100 |
-
* @param array $filters
|
101 |
-
* @param int $limit
|
102 |
-
* @param int $offset
|
103 |
-
* @return DeleteRequest[]
|
104 |
-
*/
|
105 |
-
public function getList($filters = array(), $limit = 0, $offset = 0) {
|
106 |
-
global $wpdb;
|
107 |
-
$output = array();
|
108 |
-
$query = "SELECT * FROM `" . self::getDatabaseTableName() . "` WHERE 1";
|
109 |
-
$query .= Helper::getQueryByFilters($filters);
|
110 |
-
$query .= sprintf(" AND `site_id` = '%d'", get_current_blog_id());
|
111 |
-
$query .= " ORDER BY `date_created` DESC";
|
112 |
-
if (!empty($limit)) {
|
113 |
-
$query .= " LIMIT $offset, $limit";
|
114 |
-
}
|
115 |
-
$results = $wpdb->get_results($query);
|
116 |
-
if ($results !== null) {
|
117 |
-
foreach ($results as $row) {
|
118 |
-
$object = new self;
|
119 |
-
$object->loadByRow($row);
|
120 |
-
$output[] = $object;
|
121 |
-
}
|
122 |
-
}
|
123 |
-
return $output;
|
124 |
-
}
|
125 |
-
|
126 |
-
/**
|
127 |
-
* @param $row
|
128 |
-
*/
|
129 |
-
private function loadByRow($row) {
|
130 |
-
$this->setId($row->ID);
|
131 |
-
$this->setSiteId($row->site_id);
|
132 |
-
$this->setAccessRequestId($row->access_request_id);
|
133 |
-
$this->setSessionId($row->session_id);
|
134 |
-
$this->setIpAddress($row->ip_address);
|
135 |
-
$this->setDataId($row->data_id);
|
136 |
-
$this->setType($row->type);
|
137 |
-
$this->setProcessed($row->processed);
|
138 |
-
$this->setDateCreated($row->date_created);
|
139 |
-
}
|
140 |
-
|
141 |
-
public function load() {
|
142 |
-
global $wpdb;
|
143 |
-
$query = "SELECT * FROM `" . self::getDatabaseTableName() . "` WHERE `ID` = %d";
|
144 |
-
$row = $wpdb->get_row($wpdb->prepare($query, $this->getId()));
|
145 |
-
if ($row !== null) {
|
146 |
-
$this->loadByRow($row);
|
147 |
-
}
|
148 |
-
}
|
149 |
-
|
150 |
-
/**
|
151 |
-
* @param int $id
|
152 |
-
* @return bool
|
153 |
-
*/
|
154 |
-
public function exists($id = 0) {
|
155 |
-
global $wpdb;
|
156 |
-
$row = $wpdb->get_row(
|
157 |
-
$wpdb->prepare(
|
158 |
-
"SELECT * FROM `" . self::getDatabaseTableName() . "` WHERE `ID` = %d",
|
159 |
-
intval($id)
|
160 |
-
)
|
161 |
-
);
|
162 |
-
return ($row !== null);
|
163 |
-
}
|
164 |
-
|
165 |
-
/**
|
166 |
-
* @return bool|int
|
167 |
-
*/
|
168 |
-
public function save() {
|
169 |
-
global $wpdb;
|
170 |
-
if ($this->exists($this->getId())) {
|
171 |
-
$wpdb->update(
|
172 |
-
self::getDatabaseTableName(),
|
173 |
-
array(
|
174 |
-
'ip_address' => $this->getIpAddress(),
|
175 |
-
'data_id' => $this->getDataId(),
|
176 |
-
'type' => $this->getType(),
|
177 |
-
'processed' => $this->getProcessed()
|
178 |
-
),
|
179 |
-
array('ID' => $this->getId()),
|
180 |
-
array('%s', '%d', '%s', '%d'),
|
181 |
-
array('%d')
|
182 |
-
);
|
183 |
-
return $this->getId();
|
184 |
-
} else {
|
185 |
-
$result = $wpdb->insert(
|
186 |
-
self::getDatabaseTableName(),
|
187 |
-
array(
|
188 |
-
'site_id' => $this->getSiteId(),
|
189 |
-
'access_request_id' => $this->getAccessRequestId(),
|
190 |
-
'session_id' => $this->getSessionId(),
|
191 |
-
'ip_address' => $this->getIpAddress(),
|
192 |
-
'type' => $this->getType(),
|
193 |
-
'data_id' => $this->getDataId(),
|
194 |
-
'processed' => $this->getProcessed(),
|
195 |
-
'date_created' => date_i18n('Y-m-d H:i:s'),
|
196 |
-
),
|
197 |
-
array('%d', '%d', '%s', '%s', '%s', '%d', '%d', '%s')
|
198 |
-
);
|
199 |
-
if ($result !== false) {
|
200 |
-
$this->setId($wpdb->insert_id);
|
201 |
-
return $this->getId();
|
202 |
-
}
|
203 |
-
}
|
204 |
-
return false;
|
205 |
-
}
|
206 |
-
|
207 |
-
/**
|
208 |
-
* @return null|string
|
209 |
-
*/
|
210 |
-
public function getManageUrl() {
|
211 |
-
$dataId = intval($this->getDataId());
|
212 |
-
if ($dataId > 0) {
|
213 |
-
switch ($this->getType()) {
|
214 |
-
case 'user' :
|
215 |
-
return get_edit_user_link($this->getDataId());
|
216 |
-
break;
|
217 |
-
case 'comment' :
|
218 |
-
return get_edit_comment_link($this->getDataId());
|
219 |
-
break;
|
220 |
-
case 'woocommerce_order' :
|
221 |
-
return get_edit_post_link($this->getDataId());
|
222 |
-
break;
|
223 |
-
}
|
224 |
-
}
|
225 |
-
return '';
|
226 |
-
}
|
227 |
-
|
228 |
-
/**
|
229 |
-
* @return string
|
230 |
-
*/
|
231 |
-
public function getNiceTypeLabel() {
|
232 |
-
switch ($this->getType()) {
|
233 |
-
case 'unknown' :
|
234 |
-
$output = __('Unknown', WP_GDPR_C_SLUG);
|
235 |
-
break;
|
236 |
-
case 'user' :
|
237 |
-
$output = __('User', WP_GDPR_C_SLUG);
|
238 |
-
break;
|
239 |
-
case 'comment' :
|
240 |
-
$output = __('Comment', WP_GDPR_C_SLUG);
|
241 |
-
break;
|
242 |
-
case 'woocommerce_order' :
|
243 |
-
$output = __('WooCommerce Order', WP_GDPR_C_SLUG);
|
244 |
-
break;
|
245 |
-
default :
|
246 |
-
$output = $this->getType();
|
247 |
-
break;
|
248 |
-
}
|
249 |
-
return $output;
|
250 |
-
}
|
251 |
-
|
252 |
-
public function isAnonymised() {
|
253 |
-
return ($this->getIpAddress() === '127.0.0.1');
|
254 |
-
}
|
255 |
-
|
256 |
-
/**
|
257 |
-
* @return null|DeleteRequest
|
258 |
-
*/
|
259 |
-
public static function getInstance() {
|
260 |
-
if (!isset(self::$instance)) {
|
261 |
-
self::$instance = new self();
|
262 |
-
}
|
263 |
-
return self::$instance;
|
264 |
-
}
|
265 |
-
|
266 |
-
/**
|
267 |
-
* @return int
|
268 |
-
*/
|
269 |
-
public function getId() {
|
270 |
-
return $this->id;
|
271 |
-
}
|
272 |
-
|
273 |
-
/**
|
274 |
-
* @param int $id
|
275 |
-
*/
|
276 |
-
public function setId($id) {
|
277 |
-
$this->id = $id;
|
278 |
-
}
|
279 |
-
|
280 |
-
/**
|
281 |
-
* @return int
|
282 |
-
*/
|
283 |
-
public function getSiteId() {
|
284 |
-
return $this->siteId;
|
285 |
-
}
|
286 |
-
|
287 |
-
/**
|
288 |
-
* @param int $siteId
|
289 |
-
*/
|
290 |
-
public function setSiteId($siteId) {
|
291 |
-
$this->siteId = $siteId;
|
292 |
-
}
|
293 |
-
|
294 |
-
/**
|
295 |
-
* @return int
|
296 |
-
*/
|
297 |
-
public function getAccessRequestId() {
|
298 |
-
return $this->accessRequestId;
|
299 |
-
}
|
300 |
-
|
301 |
-
/**
|
302 |
-
* @param int $accessRequestId
|
303 |
-
*/
|
304 |
-
public function setAccessRequestId($accessRequestId) {
|
305 |
-
$this->accessRequestId = $accessRequestId;
|
306 |
-
}
|
307 |
-
|
308 |
-
/**
|
309 |
-
* @return string
|
310 |
-
*/
|
311 |
-
public function getSessionId() {
|
312 |
-
return $this->sessionId;
|
313 |
-
}
|
314 |
-
|
315 |
-
/**
|
316 |
-
* @param string $sessionId
|
317 |
-
*/
|
318 |
-
public function setSessionId($sessionId) {
|
319 |
-
$this->sessionId = $sessionId;
|
320 |
-
}
|
321 |
-
|
322 |
-
/**
|
323 |
-
* @return string
|
324 |
-
*/
|
325 |
-
public function getIpAddress() {
|
326 |
-
return $this->ipAddress;
|
327 |
-
}
|
328 |
-
|
329 |
-
/**
|
330 |
-
* @param string $ipAddress
|
331 |
-
*/
|
332 |
-
public function setIpAddress($ipAddress) {
|
333 |
-
$this->ipAddress = $ipAddress;
|
334 |
-
}
|
335 |
-
|
336 |
-
/**
|
337 |
-
* @return int
|
338 |
-
*/
|
339 |
-
public function getDataId() {
|
340 |
-
return $this->dataId;
|
341 |
-
}
|
342 |
-
|
343 |
-
/**
|
344 |
-
* @param int $dataId
|
345 |
-
*/
|
346 |
-
public function setDataId($dataId) {
|
347 |
-
$this->dataId = $dataId;
|
348 |
-
}
|
349 |
-
|
350 |
-
/**
|
351 |
-
* @return string
|
352 |
-
*/
|
353 |
-
public function getType() {
|
354 |
-
return $this->type;
|
355 |
-
}
|
356 |
-
|
357 |
-
/**
|
358 |
-
* @param string $type
|
359 |
-
*/
|
360 |
-
public function setType($type) {
|
361 |
-
$this->type = $type;
|
362 |
-
}
|
363 |
-
|
364 |
-
/**
|
365 |
-
* @return int
|
366 |
-
*/
|
367 |
-
public function getProcessed() {
|
368 |
-
return $this->processed;
|
369 |
-
}
|
370 |
-
|
371 |
-
/**
|
372 |
-
* @param int $processed
|
373 |
-
*/
|
374 |
-
public function setProcessed($processed) {
|
375 |
-
$this->processed = $processed;
|
376 |
-
}
|
377 |
-
|
378 |
-
/**
|
379 |
-
* @return string
|
380 |
-
*/
|
381 |
-
public function getDateCreated() {
|
382 |
-
return $this->dateCreated;
|
383 |
-
}
|
384 |
-
|
385 |
-
/**
|
386 |
-
* @param string $dateCreated
|
387 |
-
*/
|
388 |
-
public function setDateCreated($dateCreated) {
|
389 |
-
$this->dateCreated = $dateCreated;
|
390 |
-
}
|
391 |
-
|
392 |
-
/**
|
393 |
-
* @return bool
|
394 |
-
*/
|
395 |
-
public static function databaseTableExists() {
|
396 |
-
global $wpdb;
|
397 |
-
$result = $wpdb->query("SHOW TABLES LIKE '" . self::getDatabaseTableName() . "'");
|
398 |
-
return ($result === 1);
|
399 |
-
}
|
400 |
-
|
401 |
-
/**
|
402 |
-
* @return string
|
403 |
-
*/
|
404 |
-
public static function getDatabaseTableName() {
|
405 |
-
global $wpdb;
|
406 |
-
return $wpdb->base_prefix . 'wpgdprc_delete_requests';
|
407 |
-
}
|
408 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WPGDPRC\Includes;
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Class DeleteRequest
|
7 |
+
* @package WPGDPRC\Includes
|
8 |
+
*/
|
9 |
+
class DeleteRequest {
|
10 |
+
/** @var null */
|
11 |
+
private static $instance = null;
|
12 |
+
/** @var int */
|
13 |
+
private $id = 0;
|
14 |
+
/** @var int */
|
15 |
+
private $siteId = 0;
|
16 |
+
/** @var int */
|
17 |
+
private $accessRequestId = 0;
|
18 |
+
/** @var string */
|
19 |
+
private $sessionId = '';
|
20 |
+
/** @var string */
|
21 |
+
private $ipAddress = '';
|
22 |
+
/** @var int */
|
23 |
+
private $dataId = 0;
|
24 |
+
/** @var string */
|
25 |
+
private $type = '';
|
26 |
+
/** @var int */
|
27 |
+
private $processed = 0;
|
28 |
+
/** @var string */
|
29 |
+
private $dateCreated = '';
|
30 |
+
|
31 |
+
/**
|
32 |
+
* DeleteRequest constructor.
|
33 |
+
* @param int $id
|
34 |
+
*/
|
35 |
+
public function __construct($id = 0) {
|
36 |
+
if ((int)$id > 0) {
|
37 |
+
$this->setId($id);
|
38 |
+
$this->load();
|
39 |
+
}
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* @param string $type
|
44 |
+
* @param int $dataId
|
45 |
+
* @param int $accessRequestId
|
46 |
+
* @return bool|DeleteRequest
|
47 |
+
*/
|
48 |
+
public function getByTypeAndDataIdAndAccessRequestId($type = '', $dataId = 0, $accessRequestId = 0) {
|
49 |
+
global $wpdb;
|
50 |
+
$query = "SELECT `ID` FROM `" . self::getDatabaseTableName() . "`";
|
51 |
+
$query .= " WHERE `type` = %s";
|
52 |
+
$query .= " AND `data_id` = %d";
|
53 |
+
$query .= " AND `access_request_id` = %d";
|
54 |
+
$query .= " AND `site_id` = %d";
|
55 |
+
$result = $wpdb->get_row($wpdb->prepare($query, $type, $dataId, $accessRequestId, get_current_blog_id()));
|
56 |
+
if ($result !== null) {
|
57 |
+
return new self($result->ID);
|
58 |
+
}
|
59 |
+
return false;
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* @param int $accessRequestId
|
64 |
+
* @param bool $showAnonymised
|
65 |
+
* @return int
|
66 |
+
*/
|
67 |
+
public function getAmountByAccessRequestId($accessRequestId = 0, $showAnonymised = true) {
|
68 |
+
global $wpdb;
|
69 |
+
$query = "SELECT COUNT(`ID`) FROM `" . self::getDatabaseTableName() . "`";
|
70 |
+
$query .= " WHERE `access_request_id` = %d";
|
71 |
+
if ($showAnonymised === false) {
|
72 |
+
$query .= " AND `ip_address` != '127.0.0.1'";
|
73 |
+
}
|
74 |
+
$query .= " AND `processed` = '0'";
|
75 |
+
$query .= " AND `site_id` = %d";
|
76 |
+
$result = $wpdb->get_var($wpdb->prepare($query, intval($accessRequestId), get_current_blog_id()));
|
77 |
+
if ($result !== null) {
|
78 |
+
return absint($result);
|
79 |
+
}
|
80 |
+
return 0;
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* @param array $filters
|
85 |
+
* @return int
|
86 |
+
*/
|
87 |
+
public function getTotal($filters = array()) {
|
88 |
+
global $wpdb;
|
89 |
+
$query = "SELECT COUNT(`ID`) FROM `" . self::getDatabaseTableName() . "` WHERE 1";
|
90 |
+
$query .= Helper::getQueryByFilters($filters);
|
91 |
+
$query .= sprintf(" AND `site_id` = '%d'", get_current_blog_id());
|
92 |
+
$result = $wpdb->get_var($query);
|
93 |
+
if ($result !== null) {
|
94 |
+
return absint($result);
|
95 |
+
}
|
96 |
+
return 0;
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* @param array $filters
|
101 |
+
* @param int $limit
|
102 |
+
* @param int $offset
|
103 |
+
* @return DeleteRequest[]
|
104 |
+
*/
|
105 |
+
public function getList($filters = array(), $limit = 0, $offset = 0) {
|
106 |
+
global $wpdb;
|
107 |
+
$output = array();
|
108 |
+
$query = "SELECT * FROM `" . self::getDatabaseTableName() . "` WHERE 1";
|
109 |
+
$query .= Helper::getQueryByFilters($filters);
|
110 |
+
$query .= sprintf(" AND `site_id` = '%d'", get_current_blog_id());
|
111 |
+
$query .= " ORDER BY `date_created` DESC";
|
112 |
+
if (!empty($limit)) {
|
113 |
+
$query .= " LIMIT $offset, $limit";
|
114 |
+
}
|
115 |
+
$results = $wpdb->get_results($query);
|
116 |
+
if ($results !== null) {
|
117 |
+
foreach ($results as $row) {
|
118 |
+
$object = new self;
|
119 |
+
$object->loadByRow($row);
|
120 |
+
$output[] = $object;
|
121 |
+
}
|
122 |
+
}
|
123 |
+
return $output;
|
124 |
+
}
|
125 |
+
|
126 |
+
/**
|
127 |
+
* @param $row
|
128 |
+
*/
|
129 |
+
private function loadByRow($row) {
|
130 |
+
$this->setId($row->ID);
|
131 |
+
$this->setSiteId($row->site_id);
|
132 |
+
$this->setAccessRequestId($row->access_request_id);
|
133 |
+
$this->setSessionId($row->session_id);
|
134 |
+
$this->setIpAddress($row->ip_address);
|
135 |
+
$this->setDataId($row->data_id);
|
136 |
+
$this->setType($row->type);
|
137 |
+
$this->setProcessed($row->processed);
|
138 |
+
$this->setDateCreated($row->date_created);
|
139 |
+
}
|
140 |
+
|
141 |
+
public function load() {
|
142 |
+
global $wpdb;
|
143 |
+
$query = "SELECT * FROM `" . self::getDatabaseTableName() . "` WHERE `ID` = %d";
|
144 |
+
$row = $wpdb->get_row($wpdb->prepare($query, $this->getId()));
|
145 |
+
if ($row !== null) {
|
146 |
+
$this->loadByRow($row);
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* @param int $id
|
152 |
+
* @return bool
|
153 |
+
*/
|
154 |
+
public function exists($id = 0) {
|
155 |
+
global $wpdb;
|
156 |
+
$row = $wpdb->get_row(
|
157 |
+
$wpdb->prepare(
|
158 |
+
"SELECT * FROM `" . self::getDatabaseTableName() . "` WHERE `ID` = %d",
|
159 |
+
intval($id)
|
160 |
+
)
|
161 |
+
);
|
162 |
+
return ($row !== null);
|
163 |
+
}
|
164 |
+
|
165 |
+
/**
|
166 |
+
* @return bool|int
|
167 |
+
*/
|
168 |
+
public function save() {
|
169 |
+
global $wpdb;
|
170 |
+
if ($this->exists($this->getId())) {
|
171 |
+
$wpdb->update(
|
172 |
+
self::getDatabaseTableName(),
|
173 |
+
array(
|
174 |
+
'ip_address' => $this->getIpAddress(),
|
175 |
+
'data_id' => $this->getDataId(),
|
176 |
+
'type' => $this->getType(),
|
177 |
+
'processed' => $this->getProcessed()
|
178 |
+
),
|
179 |
+
array('ID' => $this->getId()),
|
180 |
+
array('%s', '%d', '%s', '%d'),
|
181 |
+
array('%d')
|
182 |
+
);
|
183 |
+
return $this->getId();
|
184 |
+
} else {
|
185 |
+
$result = $wpdb->insert(
|
186 |
+
self::getDatabaseTableName(),
|
187 |
+
array(
|
188 |
+
'site_id' => $this->getSiteId(),
|
189 |
+
'access_request_id' => $this->getAccessRequestId(),
|
190 |
+
'session_id' => $this->getSessionId(),
|
191 |
+
'ip_address' => $this->getIpAddress(),
|
192 |
+
'type' => $this->getType(),
|
193 |
+
'data_id' => $this->getDataId(),
|
194 |
+
'processed' => $this->getProcessed(),
|
195 |
+
'date_created' => date_i18n('Y-m-d H:i:s'),
|
196 |
+
),
|
197 |
+
array('%d', '%d', '%s', '%s', '%s', '%d', '%d', '%s')
|
198 |
+
);
|
199 |
+
if ($result !== false) {
|
200 |
+
$this->setId($wpdb->insert_id);
|
201 |
+
return $this->getId();
|
202 |
+
}
|
203 |
+
}
|
204 |
+
return false;
|
205 |
+
}
|
206 |
+
|
207 |
+
/**
|
208 |
+
* @return null|string
|
209 |
+
*/
|
210 |
+
public function getManageUrl() {
|
211 |
+
$dataId = intval($this->getDataId());
|
212 |
+
if ($dataId > 0) {
|
213 |
+
switch ($this->getType()) {
|
214 |
+
case 'user' :
|
215 |
+
return get_edit_user_link($this->getDataId());
|
216 |
+
break;
|
217 |
+
case 'comment' :
|
218 |
+
return get_edit_comment_link($this->getDataId());
|
219 |
+
break;
|
220 |
+
case 'woocommerce_order' :
|
221 |
+
return get_edit_post_link($this->getDataId());
|
222 |
+
break;
|
223 |
+
}
|
224 |
+
}
|
225 |
+
return '';
|
226 |
+
}
|
227 |
+
|
228 |
+
/**
|
229 |
+
* @return string
|
230 |
+
*/
|
231 |
+
public function getNiceTypeLabel() {
|
232 |
+
switch ($this->getType()) {
|
233 |
+
case 'unknown' :
|
234 |
+
$output = __('Unknown', WP_GDPR_C_SLUG);
|
235 |
+
break;
|
236 |
+
case 'user' :
|
237 |
+
$output = __('User', WP_GDPR_C_SLUG);
|
238 |
+
break;
|
239 |
+
case 'comment' :
|
240 |
+
$output = __('Comment', WP_GDPR_C_SLUG);
|
241 |
+
break;
|
242 |
+
case 'woocommerce_order' :
|
243 |
+
$output = __('WooCommerce Order', WP_GDPR_C_SLUG);
|
244 |
+
break;
|
245 |
+
default :
|
246 |
+
$output = $this->getType();
|
247 |
+
break;
|
248 |
+
}
|
249 |
+
return $output;
|
250 |
+
}
|
251 |
+
|
252 |
+
public function isAnonymised() {
|
253 |
+
return ($this->getIpAddress() === '127.0.0.1');
|
254 |
+
}
|
255 |
+
|
256 |
+
/**
|
257 |
+
* @return null|DeleteRequest
|
258 |
+
*/
|
259 |
+
public static function getInstance() {
|
260 |
+
if (!isset(self::$instance)) {
|
261 |
+
self::$instance = new self();
|
262 |
+
}
|
263 |
+
return self::$instance;
|
264 |
+
}
|
265 |
+
|
266 |
+
/**
|
267 |
+
* @return int
|
268 |
+
*/
|
269 |
+
public function getId() {
|
270 |
+
return $this->id;
|
271 |
+
}
|
272 |
+
|
273 |
+
/**
|
274 |
+
* @param int $id
|
275 |
+
*/
|
276 |
+
public function setId($id) {
|
277 |
+
$this->id = $id;
|
278 |
+
}
|
279 |
+
|
280 |
+
/**
|
281 |
+
* @return int
|
282 |
+
*/
|
283 |
+
public function getSiteId() {
|
284 |
+
return $this->siteId;
|
285 |
+
}
|
286 |
+
|
287 |
+
/**
|
288 |
+
* @param int $siteId
|
289 |
+
*/
|
290 |
+
public function setSiteId($siteId) {
|
291 |
+
$this->siteId = $siteId;
|
292 |
+
}
|
293 |
+
|
294 |
+
/**
|
295 |
+
* @return int
|
296 |
+
*/
|
297 |
+
public function getAccessRequestId() {
|
298 |
+
return $this->accessRequestId;
|
299 |
+
}
|
300 |
+
|
301 |
+
/**
|
302 |
+
* @param int $accessRequestId
|
303 |
+
*/
|
304 |
+
public function setAccessRequestId($accessRequestId) {
|
305 |
+
$this->accessRequestId = $accessRequestId;
|
306 |
+
}
|
307 |
+
|
308 |
+
/**
|
309 |
+
* @return string
|
310 |
+
*/
|
311 |
+
public function getSessionId() {
|
312 |
+
return $this->sessionId;
|
313 |
+
}
|
314 |
+
|
315 |
+
/**
|
316 |
+
* @param string $sessionId
|
317 |
+
*/
|
318 |
+
public function setSessionId($sessionId) {
|
319 |
+
$this->sessionId = $sessionId;
|
320 |
+
}
|
321 |
+
|
322 |
+
/**
|
323 |
+
* @return string
|
324 |
+
*/
|
325 |
+
public function getIpAddress() {
|
326 |
+
return $this->ipAddress;
|
327 |
+
}
|
328 |
+
|
329 |
+
/**
|
330 |
+
* @param string $ipAddress
|
331 |
+
*/
|
332 |
+
public function setIpAddress($ipAddress) {
|
333 |
+
$this->ipAddress = $ipAddress;
|
334 |
+
}
|
335 |
+
|
336 |
+
/**
|
337 |
+
* @return int
|
338 |
+
*/
|
339 |
+
public function getDataId() {
|
340 |
+
return $this->dataId;
|
341 |
+
}
|
342 |
+
|
343 |
+
/**
|
344 |
+
* @param int $dataId
|
345 |
+
*/
|
346 |
+
public function setDataId($dataId) {
|
347 |
+
$this->dataId = $dataId;
|
348 |
+
}
|
349 |
+
|
350 |
+
/**
|
351 |
+
* @return string
|
352 |
+
*/
|
353 |
+
public function getType() {
|
354 |
+
return $this->type;
|
355 |
+
}
|
356 |
+
|
357 |
+
/**
|
358 |
+
* @param string $type
|
359 |
+
*/
|
360 |
+
public function setType($type) {
|
361 |
+
$this->type = $type;
|
362 |
+
}
|
363 |
+
|
364 |
+
/**
|
365 |
+
* @return int
|
366 |
+
*/
|
367 |
+
public function getProcessed() {
|
368 |
+
return $this->processed;
|
369 |
+
}
|
370 |
+
|
371 |
+
/**
|
372 |
+
* @param int $processed
|
373 |
+
*/
|
374 |
+
public function setProcessed($processed) {
|
375 |
+
$this->processed = $processed;
|
376 |
+
}
|
377 |
+
|
378 |
+
/**
|
379 |
+
* @return string
|
380 |
+
*/
|
381 |
+
public function getDateCreated() {
|
382 |
+
return $this->dateCreated;
|
383 |
+
}
|
384 |
+
|
385 |
+
/**
|
386 |
+
* @param string $dateCreated
|
387 |
+
*/
|
388 |
+
public function setDateCreated($dateCreated) {
|
389 |
+
$this->dateCreated = $dateCreated;
|
390 |
+
}
|
391 |
+
|
392 |
+
/**
|
393 |
+
* @return bool
|
394 |
+
*/
|
395 |
+
public static function databaseTableExists() {
|
396 |
+
global $wpdb;
|
397 |
+
$result = $wpdb->query("SHOW TABLES LIKE '" . self::getDatabaseTableName() . "'");
|
398 |
+
return ($result === 1);
|
399 |
+
}
|
400 |
+
|
401 |
+
/**
|
402 |
+
* @return string
|
403 |
+
*/
|
404 |
+
public static function getDatabaseTableName() {
|
405 |
+
global $wpdb;
|
406 |
+
return $wpdb->base_prefix . 'wpgdprc_delete_requests';
|
407 |
+
}
|
408 |
}
|
Includes/Extensions/CF7.php
CHANGED
@@ -1,293 +1,293 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WPGDPRC\Includes\Extensions;
|
4 |
-
|
5 |
-
use WPGDPRC\Includes\Helper;
|
6 |
-
use WPGDPRC\Includes\Integration;
|
7 |
-
|
8 |
-
/**
|
9 |
-
* Class CF7
|
10 |
-
* @package WPGDPRC\Includes\Extensions
|
11 |
-
*/
|
12 |
-
class CF7 {
|
13 |
-
const ID = 'contact-form-7';
|
14 |
-
const SUPPORTED_VERSION = '4.6';
|
15 |
-
/** @var null */
|
16 |
-
private static $instance = null;
|
17 |
-
|
18 |
-
public function processIntegration() {
|
19 |
-
$this->removeFormTagFromForms();
|
20 |
-
$this->removeAcceptedDateFromForms();
|
21 |
-
if (Helper::isEnabled(self::ID)) {
|
22 |
-
$this->addFormTagToForms();
|
23 |
-
$this->addAcceptedDateToForms();
|
24 |
-
}
|
25 |
-
}
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Add [wpgdprc] string to enabled forms
|
29 |
-
*/
|
30 |
-
public function addFormTagToForms() {
|
31 |
-
foreach ($this->getEnabledForms() as $formId) {
|
32 |
-
$tag = '[wpgdprc "' . $this->getCheckboxText($formId) . '"]';
|
33 |
-
$output = get_post_meta($formId, '_form', true);
|
34 |
-
preg_match('/(\[wpgdprc?.*\])/', $output, $matches);
|
35 |
-
if (!empty($matches)) {
|
36 |
-
$output = str_replace($matches[0], $tag, $output);
|
37 |
-
} else {
|
38 |
-
$pattern = '/(\[submit?.*\])/';
|
39 |
-
preg_match($pattern, $output, $matches);
|
40 |
-
if (!empty($matches)) {
|
41 |
-
$output = preg_replace($pattern, "$tag\n\n" . $matches[0], $output);
|
42 |
-
} else {
|
43 |
-
$output = $output . "\n\n$tag";
|
44 |
-
}
|
45 |
-
}
|
46 |
-
update_post_meta($formId, '_form', $output);
|
47 |
-
}
|
48 |
-
}
|
49 |
-
|
50 |
-
/**
|
51 |
-
* Add [wpgdprc] string to enabled forms
|
52 |
-
*/
|
53 |
-
public function addAcceptedDateToForms() {
|
54 |
-
foreach ($this->getEnabledForms() as $formId) {
|
55 |
-
$output = get_post_meta($formId, '_mail', true);
|
56 |
-
if (!empty($output)) {
|
57 |
-
$tag = '[wpgdprc]';
|
58 |
-
$body = $output['body'];
|
59 |
-
preg_match('/(\[wpgdprc\])/', $body, $matches);
|
60 |
-
if (empty($matches)) {
|
61 |
-
$pattern = '/(--)/';
|
62 |
-
preg_match($pattern, $body, $matches);
|
63 |
-
if (!empty($matches)) {
|
64 |
-
$body = preg_replace($pattern, "$tag\n\n" . $matches[0], $body);
|
65 |
-
} else {
|
66 |
-
$body = $body . "\n\n$tag";
|
67 |
-
}
|
68 |
-
}
|
69 |
-
$output['body'] = $body;
|
70 |
-
update_post_meta($formId, '_mail', $output);
|
71 |
-
}
|
72 |
-
}
|
73 |
-
}
|
74 |
-
|
75 |
-
/**
|
76 |
-
* Remove [wpgdprc] string from disabled forms
|
77 |
-
*/
|
78 |
-
public function removeFormTagFromForms() {
|
79 |
-
foreach (CF7::getInstance()->getForms() as $formId) {
|
80 |
-
$output = get_post_meta($formId, '_form', true);
|
81 |
-
$pattern = '/(\n\n\[wpgdprc?.*\])/';
|
82 |
-
preg_match($pattern, $output, $matches);
|
83 |
-
if (!empty($matches)) {
|
84 |
-
$output = preg_replace($pattern, '', $output);
|
85 |
-
update_post_meta($formId, '_form', $output);
|
86 |
-
}
|
87 |
-
}
|
88 |
-
}
|
89 |
-
|
90 |
-
/**
|
91 |
-
* Remove [wpgdprc] string from disabled forms
|
92 |
-
*/
|
93 |
-
public function removeAcceptedDateFromForms() {
|
94 |
-
foreach (CF7::getInstance()->getForms() as $formId) {
|
95 |
-
$output = get_post_meta($formId, '_mail', true);
|
96 |
-
$pattern = '/(\n\n\[wpgdprc\])/';
|
97 |
-
preg_match($pattern, $output['body'], $matches);
|
98 |
-
if (!empty($matches)) {
|
99 |
-
$output['body'] = preg_replace($pattern, '', $output['body']);
|
100 |
-
update_post_meta($formId, '_mail', $output);
|
101 |
-
}
|
102 |
-
}
|
103 |
-
}
|
104 |
-
|
105 |
-
public function addFormTagSupport() {
|
106 |
-
wpcf7_add_form_tag('wpgdprc', array($this, 'addFormTagHandler'));
|
107 |
-
}
|
108 |
-
|
109 |
-
/**
|
110 |
-
* @param \WPCF7_FormTag|array $tag
|
111 |
-
* @return string
|
112 |
-
*/
|
113 |
-
public function addFormTagHandler($tag) {
|
114 |
-
$tag = (is_array($tag)) ? new \WPCF7_FormTag($tag) : $tag;
|
115 |
-
$output = '';
|
116 |
-
switch ($tag->type) {
|
117 |
-
case 'wpgdprc' :
|
118 |
-
$tag->name = 'wpgdprc';
|
119 |
-
$label = (!empty($tag->labels[0])) ? esc_html($tag->labels[0]) : self::getCheckboxText();
|
120 |
-
$class = wpcf7_form_controls_class($tag->type, 'wpcf7-validates-as-required');
|
121 |
-
$validation_error = wpcf7_get_validation_error($tag->name);
|
122 |
-
if ($validation_error) {
|
123 |
-
$class .= ' wpcf7-not-valid';
|
124 |
-
}
|
125 |
-
$label_first = $tag->has_option('label_first');
|
126 |
-
$use_label_element = $tag->has_option('use_label_element');
|
127 |
-
$atts = wpcf7_format_atts(array(
|
128 |
-
'class' => $tag->get_class_option($class),
|
129 |
-
'id' => $tag->get_id_option(),
|
130 |
-
));
|
131 |
-
$item_atts = wpcf7_format_atts(array(
|
132 |
-
'type' => 'checkbox',
|
133 |
-
'name' => $tag->name,
|
134 |
-
'value' => 1,
|
135 |
-
'tabindex' => $tag->get_option('tabindex', 'signed_int', true),
|
136 |
-
'aria-required' => 'true',
|
137 |
-
'aria-invalid' => ($validation_error) ? 'true' : 'false',
|
138 |
-
));
|
139 |
-
|
140 |
-
if ($label_first) { // put label first, input last
|
141 |
-
$output = sprintf(
|
142 |
-
'<span class="wpcf7-list-item-label">%1$s</span><input %2$s />',
|
143 |
-
esc_html($label),
|
144 |
-
$item_atts
|
145 |
-
);
|
146 |
-
} else {
|
147 |
-
$output = sprintf(
|
148 |
-
'<input %2$s /><span class="wpcf7-list-item-label">%1$s</span>',
|
149 |
-
esc_html($label),
|
150 |
-
$item_atts
|
151 |
-
);
|
152 |
-
}
|
153 |
-
|
154 |
-
if ($use_label_element) {
|
155 |
-
$output = '<label>' . $output . '</label>';
|
156 |
-
}
|
157 |
-
|
158 |
-
$output = '<span class="wpcf7-list-item">' . $output . '</span>';
|
159 |
-
$output = sprintf(
|
160 |
-
'<span class="wpcf7-form-control-wrap %1$s"><span %2$s>%3$s</span>%4$s</span>',
|
161 |
-
sanitize_html_class($tag->name),
|
162 |
-
$atts,
|
163 |
-
$output,
|
164 |
-
$validation_error
|
165 |
-
);
|
166 |
-
break;
|
167 |
-
}
|
168 |
-
return $output;
|
169 |
-
}
|
170 |
-
|
171 |
-
/**
|
172 |
-
* @param \WPCF7_ContactForm $contactForm
|
173 |
-
* @return \WPCF7_ContactForm
|
174 |
-
*/
|
175 |
-
public function changeMailBodyOutput(\WPCF7_ContactForm $contactForm) {
|
176 |
-
$mail = $contactForm->prop('mail');
|
177 |
-
if (!empty($mail['body'])) {
|
178 |
-
$submission = \WPCF7_Submission::get_instance();
|
179 |
-
if (!empty($submission)) {
|
180 |
-
$data = $submission->get_posted_data();
|
181 |
-
if (isset($data['wpgdprc']) && $data['wpgdprc'] == 1) {
|
182 |
-
$value = Helper::localDateFormat(get_option('date_format') . ' ' . get_option('time_format'), time());
|
183 |
-
} else {
|
184 |
-
$value = __('Not accepted.', WP_GDPR_C_SLUG);
|
185 |
-
}
|
186 |
-
$output = apply_filters(
|
187 |
-
'wpgdprc_cf7_mail_body_output',
|
188 |
-
__('GDPR accepted on:', WP_GDPR_C_SLUG) . "\n$value",
|
189 |
-
$data,
|
190 |
-
$submission
|
191 |
-
);
|
192 |
-
$mail['body'] = str_replace('[wpgdprc]', $output, $mail['body']);
|
193 |
-
$contactForm->set_properties(array('mail' => $mail));
|
194 |
-
}
|
195 |
-
}
|
196 |
-
return $contactForm;
|
197 |
-
}
|
198 |
-
|
199 |
-
/**
|
200 |
-
* @param \WPCF7_Validation $result
|
201 |
-
* @param \WPCF7_FormTag|array $tag
|
202 |
-
* @return \WPCF7_Validation
|
203 |
-
*/
|
204 |
-
public function validateField(\WPCF7_Validation $result, $tag) {
|
205 |
-
$tag = (gettype($tag) == 'array') ? new \WPCF7_FormTag($tag) : $tag;
|
206 |
-
$formId = (isset($_POST['_wpcf7']) && is_numeric($_POST['_wpcf7'])) ? (int)$_POST['_wpcf7'] : 0;
|
207 |
-
switch ($tag->type) {
|
208 |
-
case 'wpgdprc' :
|
209 |
-
$tag->name = 'wpgdprc';
|
210 |
-
$name = $tag->name;
|
211 |
-
$value = (isset($_POST[$name])) ? filter_var($_POST[$name], FILTER_VALIDATE_BOOLEAN) : false;
|
212 |
-
if ($value === false) {
|
213 |
-
$result->invalidate($tag, self::getErrorMessage($formId));
|
214 |
-
}
|
215 |
-
break;
|
216 |
-
}
|
217 |
-
return $result;
|
218 |
-
}
|
219 |
-
|
220 |
-
/**
|
221 |
-
* @return array
|
222 |
-
*/
|
223 |
-
public function getForms() {
|
224 |
-
return get_posts(array(
|
225 |
-
'post_type' => 'wpcf7_contact_form',
|
226 |
-
'posts_per_page' => -1,
|
227 |
-
'fields' => 'ids'
|
228 |
-
));
|
229 |
-
}
|
230 |
-
|
231 |
-
/**
|
232 |
-
* @return array
|
233 |
-
*/
|
234 |
-
public function getEnabledForms() {
|
235 |
-
return (array)get_option(WP_GDPR_C_PREFIX . '_integrations_' . self::ID . '_forms', array());
|
236 |
-
}
|
237 |
-
|
238 |
-
/**
|
239 |
-
* @return array
|
240 |
-
*/
|
241 |
-
public function getFormTexts() {
|
242 |
-
return (array)get_option(WP_GDPR_C_PREFIX . '_integrations_' . self::ID . '_form_text', array());
|
243 |
-
}
|
244 |
-
|
245 |
-
/**
|
246 |
-
* @return array
|
247 |
-
*/
|
248 |
-
public function getFormErrorMessages() {
|
249 |
-
return (array)get_option(WP_GDPR_C_PREFIX . '_integrations_' . self::ID . '_error_message', array());
|
250 |
-
}
|
251 |
-
|
252 |
-
/**
|
253 |
-
* @param int $formId
|
254 |
-
* @param bool $insertPrivacyPolicyLink
|
255 |
-
* @return string
|
256 |
-
*/
|
257 |
-
public function getCheckboxText($formId = 0, $insertPrivacyPolicyLink = true) {
|
258 |
-
if (!empty($formId)) {
|
259 |
-
$texts = $this->getFormTexts();
|
260 |
-
if (!empty($texts[$formId])) {
|
261 |
-
$result = esc_html($texts[$formId]);
|
262 |
-
$result = ($insertPrivacyPolicyLink === true) ? Integration::insertPrivacyPolicyLink($result) : $result;
|
263 |
-
return apply_filters('wpgdprc_cf7_checkbox_text', $result, $formId);
|
264 |
-
}
|
265 |
-
}
|
266 |
-
return Integration::getCheckboxText();
|
267 |
-
}
|
268 |
-
|
269 |
-
/**
|
270 |
-
* @param int $formId
|
271 |
-
* @return string
|
272 |
-
*/
|
273 |
-
public function getErrorMessage($formId = 0) {
|
274 |
-
if (!empty($formId)) {
|
275 |
-
$errors = $this->getFormErrorMessages();
|
276 |
-
if (!empty($errors[$formId])) {
|
277 |
-
$result = esc_html($errors[$formId]);
|
278 |
-
return apply_filters('wpgdprc_cf7_error_message', $result, $formId);
|
279 |
-
}
|
280 |
-
}
|
281 |
-
return Integration::getErrorMessage();
|
282 |
-
}
|
283 |
-
|
284 |
-
/**
|
285 |
-
* @return null|CF7
|
286 |
-
*/
|
287 |
-
public static function getInstance() {
|
288 |
-
if (!isset(self::$instance)) {
|
289 |
-
self::$instance = new self();
|
290 |
-
}
|
291 |
-
return self::$instance;
|
292 |
-
}
|
293 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WPGDPRC\Includes\Extensions;
|
4 |
+
|
5 |
+
use WPGDPRC\Includes\Helper;
|
6 |
+
use WPGDPRC\Includes\Integration;
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Class CF7
|
10 |
+
* @package WPGDPRC\Includes\Extensions
|
11 |
+
*/
|
12 |
+
class CF7 {
|
13 |
+
const ID = 'contact-form-7';
|
14 |
+
const SUPPORTED_VERSION = '4.6';
|
15 |
+
/** @var null */
|
16 |
+
private static $instance = null;
|
17 |
+
|
18 |
+
public function processIntegration() {
|
19 |
+
$this->removeFormTagFromForms();
|
20 |
+
$this->removeAcceptedDateFromForms();
|
21 |
+
if (Helper::isEnabled(self::ID)) {
|
22 |
+
$this->addFormTagToForms();
|
23 |
+
$this->addAcceptedDateToForms();
|
24 |
+
}
|
25 |
+
}
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Add [wpgdprc] string to enabled forms
|
29 |
+
*/
|
30 |
+
public function addFormTagToForms() {
|
31 |
+
foreach ($this->getEnabledForms() as $formId) {
|
32 |
+
$tag = '[wpgdprc "' . $this->getCheckboxText($formId) . '"]';
|
33 |
+
$output = get_post_meta($formId, '_form', true);
|
34 |
+
preg_match('/(\[wpgdprc?.*\])/', $output, $matches);
|
35 |
+
if (!empty($matches)) {
|
36 |
+
$output = str_replace($matches[0], $tag, $output);
|
37 |
+
} else {
|
38 |
+
$pattern = '/(\[submit?.*\])/';
|
39 |
+
preg_match($pattern, $output, $matches);
|
40 |
+
if (!empty($matches)) {
|
41 |
+
$output = preg_replace($pattern, "$tag\n\n" . $matches[0], $output);
|
42 |
+
} else {
|
43 |
+
$output = $output . "\n\n$tag";
|
44 |
+
}
|
45 |
+
}
|
46 |
+
update_post_meta($formId, '_form', $output);
|
47 |
+
}
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Add [wpgdprc] string to enabled forms
|
52 |
+
*/
|
53 |
+
public function addAcceptedDateToForms() {
|
54 |
+
foreach ($this->getEnabledForms() as $formId) {
|
55 |
+
$output = get_post_meta($formId, '_mail', true);
|
56 |
+
if (!empty($output)) {
|
57 |
+
$tag = '[wpgdprc]';
|
58 |
+
$body = $output['body'];
|
59 |
+
preg_match('/(\[wpgdprc\])/', $body, $matches);
|
60 |
+
if (empty($matches)) {
|
61 |
+
$pattern = '/(--)/';
|
62 |
+
preg_match($pattern, $body, $matches);
|
63 |
+
if (!empty($matches)) {
|
64 |
+
$body = preg_replace($pattern, "$tag\n\n" . $matches[0], $body);
|
65 |
+
} else {
|
66 |
+
$body = $body . "\n\n$tag";
|
67 |
+
}
|
68 |
+
}
|
69 |
+
$output['body'] = $body;
|
70 |
+
update_post_meta($formId, '_mail', $output);
|
71 |
+
}
|
72 |
+
}
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Remove [wpgdprc] string from disabled forms
|
77 |
+
*/
|
78 |
+
public function removeFormTagFromForms() {
|
79 |
+
foreach (CF7::getInstance()->getForms() as $formId) {
|
80 |
+
$output = get_post_meta($formId, '_form', true);
|
81 |
+
$pattern = '/(\n\n\[wpgdprc?.*\])/';
|
82 |
+
preg_match($pattern, $output, $matches);
|
83 |
+
if (!empty($matches)) {
|
84 |
+
$output = preg_replace($pattern, '', $output);
|
85 |
+
update_post_meta($formId, '_form', $output);
|
86 |
+
}
|
87 |
+
}
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Remove [wpgdprc] string from disabled forms
|
92 |
+
*/
|
93 |
+
public function removeAcceptedDateFromForms() {
|
94 |
+
foreach (CF7::getInstance()->getForms() as $formId) {
|
95 |
+
$output = get_post_meta($formId, '_mail', true);
|
96 |
+
$pattern = '/(\n\n\[wpgdprc\])/';
|
97 |
+
preg_match($pattern, $output['body'], $matches);
|
98 |
+
if (!empty($matches)) {
|
99 |
+
$output['body'] = preg_replace($pattern, '', $output['body']);
|
100 |
+
update_post_meta($formId, '_mail', $output);
|
101 |
+
}
|
102 |
+
}
|
103 |
+
}
|
104 |
+
|
105 |
+
public function addFormTagSupport() {
|
106 |
+
wpcf7_add_form_tag('wpgdprc', array($this, 'addFormTagHandler'));
|
107 |
+
}
|
108 |
+
|
109 |
+
/**
|
110 |
+
* @param \WPCF7_FormTag|array $tag
|
111 |
+
* @return string
|
112 |
+
*/
|
113 |
+
public function addFormTagHandler($tag) {
|
114 |
+
$tag = (is_array($tag)) ? new \WPCF7_FormTag($tag) : $tag;
|
115 |
+
$output = '';
|
116 |
+
switch ($tag->type) {
|
117 |
+
case 'wpgdprc' :
|
118 |
+
$tag->name = 'wpgdprc';
|
119 |
+
$label = (!empty($tag->labels[0])) ? esc_html($tag->labels[0]) : self::getCheckboxText();
|
120 |
+
$class = wpcf7_form_controls_class($tag->type, 'wpcf7-validates-as-required');
|
121 |
+
$validation_error = wpcf7_get_validation_error($tag->name);
|
122 |
+
if ($validation_error) {
|
123 |
+
$class .= ' wpcf7-not-valid';
|
124 |
+
}
|
125 |
+
$label_first = $tag->has_option('label_first');
|
126 |
+
$use_label_element = $tag->has_option('use_label_element');
|
127 |
+
$atts = wpcf7_format_atts(array(
|
128 |
+
'class' => $tag->get_class_option($class),
|
129 |
+
'id' => $tag->get_id_option(),
|
130 |
+
));
|
131 |
+
$item_atts = wpcf7_format_atts(array(
|
132 |
+
'type' => 'checkbox',
|
133 |
+
'name' => $tag->name,
|
134 |
+
'value' => 1,
|
135 |
+
'tabindex' => $tag->get_option('tabindex', 'signed_int', true),
|
136 |
+
'aria-required' => 'true',
|
137 |
+
'aria-invalid' => ($validation_error) ? 'true' : 'false',
|
138 |
+
));
|
139 |
+
|
140 |
+
if ($label_first) { // put label first, input last
|
141 |
+
$output = sprintf(
|
142 |
+
'<span class="wpcf7-list-item-label">%1$s</span><input %2$s />',
|
143 |
+
esc_html($label),
|
144 |
+
$item_atts
|
145 |
+
);
|
146 |
+
} else {
|
147 |
+
$output = sprintf(
|
148 |
+
'<input %2$s /><span class="wpcf7-list-item-label">%1$s</span>',
|
149 |
+
esc_html($label),
|
150 |
+
$item_atts
|
151 |
+
);
|
152 |
+
}
|
153 |
+
|
154 |
+
if ($use_label_element) {
|
155 |
+
$output = '<label>' . $output . '</label>';
|
156 |
+
}
|
157 |
+
|
158 |
+
$output = '<span class="wpcf7-list-item">' . $output . '</span>';
|
159 |
+
$output = sprintf(
|
160 |
+
'<span class="wpcf7-form-control-wrap %1$s"><span %2$s>%3$s</span>%4$s</span>',
|
161 |
+
sanitize_html_class($tag->name),
|
162 |
+
$atts,
|
163 |
+
$output,
|
164 |
+
$validation_error
|
165 |
+
);
|
166 |
+
break;
|
167 |
+
}
|
168 |
+
return $output;
|
169 |
+
}
|
170 |
+
|
171 |
+
/**
|
172 |
+
* @param \WPCF7_ContactForm $contactForm
|
173 |
+
* @return \WPCF7_ContactForm
|
174 |
+
*/
|
175 |
+
public function changeMailBodyOutput(\WPCF7_ContactForm $contactForm) {
|
176 |
+
$mail = $contactForm->prop('mail');
|
177 |
+
if (!empty($mail['body'])) {
|
178 |
+
$submission = \WPCF7_Submission::get_instance();
|
179 |
+
if (!empty($submission)) {
|
180 |
+
$data = $submission->get_posted_data();
|
181 |
+
if (isset($data['wpgdprc']) && $data['wpgdprc'] == 1) {
|
182 |
+
$value = Helper::localDateFormat(get_option('date_format') . ' ' . get_option('time_format'), time());
|
183 |
+
} else {
|
184 |
+
$value = __('Not accepted.', WP_GDPR_C_SLUG);
|
185 |
+
}
|
186 |
+
$output = apply_filters(
|
187 |
+
'wpgdprc_cf7_mail_body_output',
|
188 |
+
__('GDPR accepted on:', WP_GDPR_C_SLUG) . "\n$value",
|
189 |
+
$data,
|
190 |
+
$submission
|
191 |
+
);
|
192 |
+
$mail['body'] = str_replace('[wpgdprc]', $output, $mail['body']);
|
193 |
+
$contactForm->set_properties(array('mail' => $mail));
|
194 |
+
}
|
195 |
+
}
|
196 |
+
return $contactForm;
|
197 |
+
}
|
198 |
+
|
199 |
+
/**
|
200 |
+
* @param \WPCF7_Validation $result
|
201 |
+
* @param \WPCF7_FormTag|array $tag
|
202 |
+
* @return \WPCF7_Validation
|
203 |
+
*/
|
204 |
+
public function validateField(\WPCF7_Validation $result, $tag) {
|
205 |
+
$tag = (gettype($tag) == 'array') ? new \WPCF7_FormTag($tag) : $tag;
|
206 |
+
$formId = (isset($_POST['_wpcf7']) && is_numeric($_POST['_wpcf7'])) ? (int)$_POST['_wpcf7'] : 0;
|
207 |
+
switch ($tag->type) {
|
208 |
+
case 'wpgdprc' :
|
209 |
+
$tag->name = 'wpgdprc';
|
210 |
+
$name = $tag->name;
|
211 |
+
$value = (isset($_POST[$name])) ? filter_var($_POST[$name], FILTER_VALIDATE_BOOLEAN) : false;
|
212 |
+
if ($value === false) {
|
213 |
+
$result->invalidate($tag, self::getErrorMessage($formId));
|
214 |
+
}
|
215 |
+
break;
|
216 |
+
}
|
217 |
+
return $result;
|
218 |
+
}
|
219 |
+
|
220 |
+
/**
|
221 |
+
* @return array
|
222 |
+
*/
|
223 |
+
public function getForms() {
|
224 |
+
return get_posts(array(
|
225 |
+
'post_type' => 'wpcf7_contact_form',
|
226 |
+
'posts_per_page' => -1,
|
227 |
+
'fields' => 'ids'
|
228 |
+
));
|
229 |
+
}
|
230 |
+
|
231 |
+
/**
|
232 |
+
* @return array
|
233 |
+
*/
|
234 |
+
public function getEnabledForms() {
|
235 |
+
return (array)get_option(WP_GDPR_C_PREFIX . '_integrations_' . self::ID . '_forms', array());
|
236 |
+
}
|
237 |
+
|
238 |
+
/**
|
239 |
+
* @return array
|
240 |
+
*/
|
241 |
+
public function getFormTexts() {
|
242 |
+
return (array)get_option(WP_GDPR_C_PREFIX . '_integrations_' . self::ID . '_form_text', array());
|
243 |
+
}
|
244 |
+
|
245 |
+
/**
|
246 |
+
* @return array
|
247 |
+
*/
|
248 |
+
public function getFormErrorMessages() {
|
249 |
+
return (array)get_option(WP_GDPR_C_PREFIX . '_integrations_' . self::ID . '_error_message', array());
|
250 |
+
}
|
251 |
+
|
252 |
+
/**
|
253 |
+
* @param int $formId
|
254 |
+
* @param bool $insertPrivacyPolicyLink
|
255 |
+
* @return string
|
256 |
+
*/
|
257 |
+
public function getCheckboxText($formId = 0, $insertPrivacyPolicyLink = true) {
|
258 |
+
if (!empty($formId)) {
|
259 |
+
$texts = $this->getFormTexts();
|
260 |
+
if (!empty($texts[$formId])) {
|
261 |
+
$result = esc_html($texts[$formId]);
|
262 |
+
$result = ($insertPrivacyPolicyLink === true) ? Integration::insertPrivacyPolicyLink($result) : $result;
|
263 |
+
return apply_filters('wpgdprc_cf7_checkbox_text', $result, $formId);
|
264 |
+
}
|
265 |
+
}
|
266 |
+
return Integration::getCheckboxText();
|
267 |
+
}
|
268 |
+
|
269 |
+
/**
|
270 |
+
* @param int $formId
|
271 |
+
* @return string
|
272 |
+
*/
|
273 |
+
public function getErrorMessage($formId = 0) {
|
274 |
+
if (!empty($formId)) {
|
275 |
+
$errors = $this->getFormErrorMessages();
|
276 |
+
if (!empty($errors[$formId])) {
|
277 |
+
$result = esc_html($errors[$formId]);
|
278 |
+
return apply_filters('wpgdprc_cf7_error_message', $result, $formId);
|
279 |
+
}
|
280 |
+
}
|
281 |
+
return Integration::getErrorMessage();
|
282 |
+
}
|
283 |
+
|
284 |
+
/**
|
285 |
+
* @return null|CF7
|
286 |
+
*/
|
287 |
+
public static function getInstance() {
|
288 |
+
if (!isset(self::$instance)) {
|
289 |
+
self::$instance = new self();
|
290 |
+
}
|
291 |
+
return self::$instance;
|
292 |
+
}
|
293 |
}
|
Includes/Extensions/GForms.php
CHANGED
@@ -1,288 +1,288 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WPGDPRC\Includes\Extensions;
|
4 |
-
|
5 |
-
use WPGDPRC\Includes\Helper;
|
6 |
-
use WPGDPRC\Includes\Integration;
|
7 |
-
|
8 |
-
/**
|
9 |
-
* Class GForms
|
10 |
-
* @package WPGDPRC\Includes\Extensions
|
11 |
-
*/
|
12 |
-
class GForms {
|
13 |
-
const ID = 'gravity-forms';
|
14 |
-
const SUPPORTED_VERSION = '1.9';
|
15 |
-
/** @var null */
|
16 |
-
private static $instance = null;
|
17 |
-
|
18 |
-
public function processIntegration() {
|
19 |
-
if (!class_exists('\GFAPI')) {
|
20 |
-
return;
|
21 |
-
}
|
22 |
-
foreach (self::getForms() as $form) {
|
23 |
-
if (in_array($form['id'], self::getEnabledForms()) && Helper::isEnabled(self::ID)) {
|
24 |
-
self::addField($form);
|
25 |
-
} else {
|
26 |
-
self::removeField($form);
|
27 |
-
}
|
28 |
-
}
|
29 |
-
}
|
30 |
-
|
31 |
-
/**
|
32 |
-
* @param array $form
|
33 |
-
*/
|
34 |
-
public function addField($form = array()) {
|
35 |
-
$isUpdated = false;
|
36 |
-
$lastFieldId = 0;
|
37 |
-
$choices = array(
|
38 |
-
array(
|
39 |
-
'text' => self::getCheckboxText($form['id']) . ' <abbr class="wpgdprc-required" title="' . self::getRequiredMessage($form['id']) . '">*</abbr>',
|
40 |
-
'value' => 'true',
|
41 |
-
'isSelected' => false
|
42 |
-
)
|
43 |
-
);
|
44 |
-
foreach ($form['fields'] as &$field) {
|
45 |
-
if ($field->id > $lastFieldId) {
|
46 |
-
$lastFieldId = intval($field->id);
|
47 |
-
}
|
48 |
-
if (isset($field->wpgdprc) && $field->wpgdprc === true) {
|
49 |
-
$field['choices'] = $choices;
|
50 |
-
$isUpdated = true;
|
51 |
-
}
|
52 |
-
}
|
53 |
-
if (!$isUpdated) {
|
54 |
-
$id = ((int)$lastFieldId > 0) ? $lastFieldId + 1 : 99;
|
55 |
-
$args = array(
|
56 |
-
'id' => $id,
|
57 |
-
'type' => 'checkbox',
|
58 |
-
'label' => __('Privacy', WP_GDPR_C_SLUG),
|
59 |
-
'labelPlacement' => 'hidden_label',
|
60 |
-
'isRequired' => true,
|
61 |
-
'enableChoiceValue' => true,
|
62 |
-
'choices' => $choices,
|
63 |
-
'inputs' => array(
|
64 |
-
array(
|
65 |
-
'id' => $id . '.1',
|
66 |
-
'label' => self::getCheckboxText($form['id']),
|
67 |
-
'name' => 'wpgdprc'
|
68 |
-
)
|
69 |
-
),
|
70 |
-
'wpgdprc' => true
|
71 |
-
);
|
72 |
-
$form['fields'][] = apply_filters('wpgdprc_gforms_field_args', $args, $form);
|
73 |
-
}
|
74 |
-
\GFAPI::update_form($form, $form['id']);
|
75 |
-
}
|
76 |
-
|
77 |
-
/**
|
78 |
-
* @param array $form
|
79 |
-
*/
|
80 |
-
public function removeField($form = array()) {
|
81 |
-
foreach ($form['fields'] as $index => $field) {
|
82 |
-
if (isset($field['wpgdprc']) && $field['wpgdprc'] === true) {
|
83 |
-
unset($form['fields'][$index]);
|
84 |
-
}
|
85 |
-
}
|
86 |
-
\GFAPI::update_form($form, $form['id']);
|
87 |
-
}
|
88 |
-
|
89 |
-
/**
|
90 |
-
* @param array $columns
|
91 |
-
* @param int $formId
|
92 |
-
* @return array
|
93 |
-
*/
|
94 |
-
public function displayAcceptedDateColumnInEntryOverview($columns = array(), $formId = 0) {
|
95 |
-
$key = array_search(self::getCheckboxText($formId), $columns);
|
96 |
-
if (!empty($key) && isset($columns[$key])) {
|
97 |
-
$columns[$key] = apply_filters('wpgdprc_gforms_accepted_date_column_in_entry_overview', __('Privacy', WP_GDPR_C_SLUG), $columns[$key], $formId);
|
98 |
-
}
|
99 |
-
return $columns;
|
100 |
-
}
|
101 |
-
|
102 |
-
/**
|
103 |
-
* @param string $value
|
104 |
-
* @param int $formId
|
105 |
-
* @param int $fieldId
|
106 |
-
* @param array $entry
|
107 |
-
* @return string
|
108 |
-
*/
|
109 |
-
public function displayAcceptedDateInEntryOverview($value = '', $formId = 0, $fieldId = 0, $entry = array()) {
|
110 |
-
if (empty($value)) {
|
111 |
-
$id = self::getFieldIdByFormId($formId);
|
112 |
-
if (!empty($id) && $fieldId === $id) {
|
113 |
-
$value = (!empty($entry[$fieldId])) ? $entry[$fieldId] : __('Not accepted.', WP_GDPR_C_SLUG);
|
114 |
-
$value = apply_filters('wpgdprc_gforms_accepted_date_in_entry_overview', $value, $fieldId, $formId, $entry);
|
115 |
-
}
|
116 |
-
}
|
117 |
-
return $value;
|
118 |
-
}
|
119 |
-
|
120 |
-
/**
|
121 |
-
* @param mixed $value
|
122 |
-
* @param array $entry
|
123 |
-
* @return string
|
124 |
-
*/
|
125 |
-
public function displayAcceptedDateInEntry($value, $entry = array()) {
|
126 |
-
$fieldId = self::getFieldIdByFormId($entry['form_id']);
|
127 |
-
if (!empty($fieldId) && isset($value[$fieldId])) {
|
128 |
-
if (empty($value[$fieldId])) {
|
129 |
-
$value = __('Not accepted.', WP_GDPR_C_SLUG);
|
130 |
-
}
|
131 |
-
$value = apply_filters('wpgdprc_gforms_accepted_date_in_entry', $value, $fieldId, $entry);
|
132 |
-
}
|
133 |
-
return $value;
|
134 |
-
}
|
135 |
-
|
136 |
-
/**
|
137 |
-
* @param string $value
|
138 |
-
* @param array $lead
|
139 |
-
* @param mixed $field
|
140 |
-
* @return string
|
141 |
-
*/
|
142 |
-
public function addAcceptedDateToEntry($value = '', $lead = array(), $field) {
|
143 |
-
if ($field instanceof \GF_Field) {
|
144 |
-
if (isset($field['wpgdprc']) && $field['wpgdprc'] === true) {
|
145 |
-
if (!empty($value)) {
|
146 |
-
$date = Helper::localDateFormat(get_option('date_format') . ' ' . get_option('time_format'), time());
|
147 |
-
$value = sprintf(__('Accepted on %s.', WP_GDPR_C_SLUG), $date);
|
148 |
-
} else {
|
149 |
-
$value = __('Not accepted.', WP_GDPR_C_SLUG);
|
150 |
-
}
|
151 |
-
$value = apply_filters('wpgdprc_gforms_accepted_date_to_entry', $value, $field, $lead);
|
152 |
-
}
|
153 |
-
}
|
154 |
-
return $value;
|
155 |
-
}
|
156 |
-
|
157 |
-
/**
|
158 |
-
* @param array $validation_result
|
159 |
-
* @return array
|
160 |
-
*/
|
161 |
-
public function overwriteValidationMessage($validation_result = array()) {
|
162 |
-
$form = $validation_result['form'];
|
163 |
-
foreach ($form['fields'] as &$field) {
|
164 |
-
if (isset($field['wpgdprc']) && $field['wpgdprc'] === true) {
|
165 |
-
if (isset($field['failed_validation']) && $field['failed_validation'] === true) {
|
166 |
-
$field['validation_message'] = apply_filters('wpgdprc_gforms_validation_message', self::getErrorMessage($form['id']), $field, $form);
|
167 |
-
}
|
168 |
-
}
|
169 |
-
}
|
170 |
-
$validation_result['form'] = $form;
|
171 |
-
return $validation_result;
|
172 |
-
}
|
173 |
-
|
174 |
-
/**
|
175 |
-
* @return array
|
176 |
-
*/
|
177 |
-
public function getForms() {
|
178 |
-
$output = array();
|
179 |
-
if (class_exists('\GFAPI')) {
|
180 |
-
$forms = \GFAPI::get_forms();
|
181 |
-
foreach ($forms as $form) {
|
182 |
-
$output[] = $form;
|
183 |
-
}
|
184 |
-
}
|
185 |
-
return $output;
|
186 |
-
}
|
187 |
-
|
188 |
-
/**
|
189 |
-
* @return array
|
190 |
-
*/
|
191 |
-
public function getEnabledForms() {
|
192 |
-
return (array)get_option(WP_GDPR_C_PREFIX . '_integrations_' . self::ID . '_forms', array());
|
193 |
-
}
|
194 |
-
|
195 |
-
/**
|
196 |
-
* @return array
|
197 |
-
*/
|
198 |
-
public function getFormTexts() {
|
199 |
-
return (array)get_option(WP_GDPR_C_PREFIX . '_integrations_' . self::ID . '_form_text', array());
|
200 |
-
}
|
201 |
-
|
202 |
-
/**
|
203 |
-
* @return array
|
204 |
-
*/
|
205 |
-
public function getFormErrorMessages() {
|
206 |
-
return (array)get_option(WP_GDPR_C_PREFIX . '_integrations_' . self::ID . '_error_message', array());
|
207 |
-
}
|
208 |
-
|
209 |
-
/**
|
210 |
-
* @return array
|
211 |
-
*/
|
212 |
-
public function getFormRequiredMessages() {
|
213 |
-
return (array)get_option(WP_GDPR_C_PREFIX . '_integrations_' . self::ID . '_required_message', array());
|
214 |
-
}
|
215 |
-
|
216 |
-
/**
|
217 |
-
* @param int $formId
|
218 |
-
* @param bool $insertPrivacyPolicyLink
|
219 |
-
* @return string
|
220 |
-
*/
|
221 |
-
public function getCheckboxText($formId = 0, $insertPrivacyPolicyLink = true) {
|
222 |
-
if (!empty($formId)) {
|
223 |
-
$texts = $this->getFormTexts();
|
224 |
-
if (!empty($texts[$formId])) {
|
225 |
-
$result = wp_kses($texts[$formId], Helper::getAllowedHTMLTags(self::ID));
|
226 |
-
$result = ($insertPrivacyPolicyLink === true) ? Integration::insertPrivacyPolicyLink($result) : $result;
|
227 |
-
return apply_filters('wpgdprc_gforms_checkbox_text', $result, $formId);
|
228 |
-
}
|
229 |
-
}
|
230 |
-
return Integration::getCheckboxText();
|
231 |
-
}
|
232 |
-
|
233 |
-
/**
|
234 |
-
* @param int $formId
|
235 |
-
* @return string
|
236 |
-
*/
|
237 |
-
public function getErrorMessage($formId = 0) {
|
238 |
-
if (!empty($formId)) {
|
239 |
-
$errors = $this->getFormErrorMessages();
|
240 |
-
if (!empty($errors[$formId])) {
|
241 |
-
$result = wp_kses($errors[$formId], Helper::getAllowedHTMLTags(self::ID));
|
242 |
-
return apply_filters('wpgdprc_gforms_error_message', $result, $formId);
|
243 |
-
}
|
244 |
-
}
|
245 |
-
return Integration::getErrorMessage();
|
246 |
-
}
|
247 |
-
|
248 |
-
/**
|
249 |
-
* @param int $formId
|
250 |
-
* @return string
|
251 |
-
*/
|
252 |
-
public function getRequiredMessage($formId = 0) {
|
253 |
-
if (!empty($formId)) {
|
254 |
-
$errors = $this->getFormRequiredMessages();
|
255 |
-
if (!empty($errors[$formId])) {
|
256 |
-
$result = esc_attr($errors[$formId]);
|
257 |
-
return apply_filters('wpgdprc_gforms_required_message', $result, $formId);
|
258 |
-
}
|
259 |
-
}
|
260 |
-
return Integration::getRequiredMessage();
|
261 |
-
}
|
262 |
-
|
263 |
-
/**
|
264 |
-
* @param int $formId
|
265 |
-
* @return int
|
266 |
-
*/
|
267 |
-
private static function getFieldIdByFormId($formId = 0) {
|
268 |
-
$form = \GFFormsModel::get_form_meta($formId);
|
269 |
-
foreach ($form['fields'] as $field) {
|
270 |
-
if (isset($field['wpgdprc']) && $field['wpgdprc'] === true) {
|
271 |
-
if (isset($field['inputs'][0]['id'])) {
|
272 |
-
return $field['inputs'][0]['id'];
|
273 |
-
}
|
274 |
-
}
|
275 |
-
}
|
276 |
-
return 0;
|
277 |
-
}
|
278 |
-
|
279 |
-
/**
|
280 |
-
* @return null|GForms
|
281 |
-
*/
|
282 |
-
public static function getInstance() {
|
283 |
-
if (!isset(self::$instance)) {
|
284 |
-
self::$instance = new self();
|
285 |
-
}
|
286 |
-
return self::$instance;
|
287 |
-
}
|
288 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WPGDPRC\Includes\Extensions;
|
4 |
+
|
5 |
+
use WPGDPRC\Includes\Helper;
|
6 |
+
use WPGDPRC\Includes\Integration;
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Class GForms
|
10 |
+
* @package WPGDPRC\Includes\Extensions
|
11 |
+
*/
|
12 |
+
class GForms {
|
13 |
+
const ID = 'gravity-forms';
|
14 |
+
const SUPPORTED_VERSION = '1.9';
|
15 |
+
/** @var null */
|
16 |
+
private static $instance = null;
|
17 |
+
|
18 |
+
public function processIntegration() {
|
19 |
+
if (!class_exists('\GFAPI')) {
|
20 |
+
return;
|
21 |
+
}
|
22 |
+
foreach (self::getForms() as $form) {
|
23 |
+
if (in_array($form['id'], self::getEnabledForms()) && Helper::isEnabled(self::ID)) {
|
24 |
+
self::addField($form);
|
25 |
+
} else {
|
26 |
+
self::removeField($form);
|
27 |
+
}
|
28 |
+
}
|
29 |
+
}
|
30 |
+
|
31 |
+
/**
|
32 |
+
* @param array $form
|
33 |
+
*/
|
34 |
+
public function addField($form = array()) {
|
35 |
+
$isUpdated = false;
|
36 |
+
$lastFieldId = 0;
|
37 |
+
$choices = array(
|
38 |
+
array(
|
39 |
+
'text' => self::getCheckboxText($form['id']) . ' <abbr class="wpgdprc-required" title="' . self::getRequiredMessage($form['id']) . '">*</abbr>',
|
40 |
+
'value' => 'true',
|
41 |
+
'isSelected' => false
|
42 |
+
)
|
43 |
+
);
|
44 |
+
foreach ($form['fields'] as &$field) {
|
45 |
+
if ($field->id > $lastFieldId) {
|
46 |
+
$lastFieldId = intval($field->id);
|
47 |
+
}
|
48 |
+
if (isset($field->wpgdprc) && $field->wpgdprc === true) {
|
49 |
+
$field['choices'] = $choices;
|
50 |
+
$isUpdated = true;
|
51 |
+
}
|
52 |
+
}
|
53 |
+
if (!$isUpdated) {
|
54 |
+
$id = ((int)$lastFieldId > 0) ? $lastFieldId + 1 : 99;
|
55 |
+
$args = array(
|
56 |
+
'id' => $id,
|
57 |
+
'type' => 'checkbox',
|
58 |
+
'label' => __('Privacy', WP_GDPR_C_SLUG),
|
59 |
+
'labelPlacement' => 'hidden_label',
|
60 |
+
'isRequired' => true,
|
61 |
+
'enableChoiceValue' => true,
|
62 |
+
'choices' => $choices,
|
63 |
+
'inputs' => array(
|
64 |
+
array(
|
65 |
+
'id' => $id . '.1',
|
66 |
+
'label' => self::getCheckboxText($form['id']),
|
67 |
+
'name' => 'wpgdprc'
|
68 |
+
)
|
69 |
+
),
|
70 |
+
'wpgdprc' => true
|
71 |
+
);
|
72 |
+
$form['fields'][] = apply_filters('wpgdprc_gforms_field_args', $args, $form);
|
73 |
+
}
|
74 |
+
\GFAPI::update_form($form, $form['id']);
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
* @param array $form
|
79 |
+
*/
|
80 |
+
public function removeField($form = array()) {
|
81 |
+
foreach ($form['fields'] as $index => $field) {
|
82 |
+
if (isset($field['wpgdprc']) && $field['wpgdprc'] === true) {
|
83 |
+
unset($form['fields'][$index]);
|
84 |
+
}
|
85 |
+
}
|
86 |
+
\GFAPI::update_form($form, $form['id']);
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* @param array $columns
|
91 |
+
* @param int $formId
|
92 |
+
* @return array
|
93 |
+
*/
|
94 |
+
public function displayAcceptedDateColumnInEntryOverview($columns = array(), $formId = 0) {
|
95 |
+
$key = array_search(self::getCheckboxText($formId), $columns);
|
96 |
+
if (!empty($key) && isset($columns[$key])) {
|
97 |
+
$columns[$key] = apply_filters('wpgdprc_gforms_accepted_date_column_in_entry_overview', __('Privacy', WP_GDPR_C_SLUG), $columns[$key], $formId);
|
98 |
+
}
|
99 |
+
return $columns;
|
100 |
+
}
|
101 |
+
|
102 |
+
/**
|
103 |
+
* @param string $value
|
104 |
+
* @param int $formId
|
105 |
+
* @param int $fieldId
|
106 |
+
* @param array $entry
|
107 |
+
* @return string
|
108 |
+
*/
|
109 |
+
public function displayAcceptedDateInEntryOverview($value = '', $formId = 0, $fieldId = 0, $entry = array()) {
|
110 |
+
if (empty($value)) {
|
111 |
+
$id = self::getFieldIdByFormId($formId);
|
112 |
+
if (!empty($id) && $fieldId === $id) {
|
113 |
+
$value = (!empty($entry[$fieldId])) ? $entry[$fieldId] : __('Not accepted.', WP_GDPR_C_SLUG);
|
114 |
+
$value = apply_filters('wpgdprc_gforms_accepted_date_in_entry_overview', $value, $fieldId, $formId, $entry);
|
115 |
+
}
|
116 |
+
}
|
117 |
+
return $value;
|
118 |
+
}
|
119 |
+
|
120 |
+
/**
|
121 |
+
* @param mixed $value
|
122 |
+
* @param array $entry
|
123 |
+
* @return string
|
124 |
+
*/
|
125 |
+
public function displayAcceptedDateInEntry($value, $entry = array()) {
|
126 |
+
$fieldId = self::getFieldIdByFormId($entry['form_id']);
|
127 |
+
if (!empty($fieldId) && isset($value[$fieldId])) {
|
128 |
+
if (empty($value[$fieldId])) {
|
129 |
+
$value = __('Not accepted.', WP_GDPR_C_SLUG);
|
130 |
+
}
|
131 |
+
$value = apply_filters('wpgdprc_gforms_accepted_date_in_entry', $value, $fieldId, $entry);
|
132 |
+
}
|
133 |
+
return $value;
|
134 |
+
}
|
135 |
+
|
136 |
+
/**
|
137 |
+
* @param string $value
|
138 |
+
* @param array $lead
|
139 |
+
* @param mixed $field
|
140 |
+
* @return string
|
141 |
+
*/
|
142 |
+
public function addAcceptedDateToEntry($value = '', $lead = array(), $field) {
|
143 |
+
if ($field instanceof \GF_Field) {
|
144 |
+
if (isset($field['wpgdprc']) && $field['wpgdprc'] === true) {
|
145 |
+
if (!empty($value)) {
|
146 |
+
$date = Helper::localDateFormat(get_option('date_format') . ' ' . get_option('time_format'), time());
|
147 |
+
$value = sprintf(__('Accepted on %s.', WP_GDPR_C_SLUG), $date);
|
148 |
+
} else {
|
149 |
+
$value = __('Not accepted.', WP_GDPR_C_SLUG);
|
150 |
+
}
|
151 |
+
$value = apply_filters('wpgdprc_gforms_accepted_date_to_entry', $value, $field, $lead);
|
152 |
+
}
|
153 |
+
}
|
154 |
+
return $value;
|
155 |
+
}
|
156 |
+
|
157 |
+
/**
|
158 |
+
* @param array $validation_result
|
159 |
+
* @return array
|
160 |
+
*/
|
161 |
+
public function overwriteValidationMessage($validation_result = array()) {
|
162 |
+
$form = $validation_result['form'];
|
163 |
+
foreach ($form['fields'] as &$field) {
|
164 |
+
if (isset($field['wpgdprc']) && $field['wpgdprc'] === true) {
|
165 |
+
if (isset($field['failed_validation']) && $field['failed_validation'] === true) {
|
166 |
+
$field['validation_message'] = apply_filters('wpgdprc_gforms_validation_message', self::getErrorMessage($form['id']), $field, $form);
|
167 |
+
}
|
168 |
+
}
|
169 |
+
}
|
170 |
+
$validation_result['form'] = $form;
|
171 |
+
return $validation_result;
|
172 |
+
}
|
173 |
+
|
174 |
+
/**
|
175 |
+
* @return array
|
176 |
+
*/
|
177 |
+
public function getForms() {
|
178 |
+
$output = array();
|
179 |
+
if (class_exists('\GFAPI')) {
|
180 |
+
$forms = \GFAPI::get_forms();
|
181 |
+
foreach ($forms as $form) {
|
182 |
+
$output[] = $form;
|
183 |
+
}
|
184 |
+
}
|
185 |
+
return $output;
|
186 |
+
}
|
187 |
+
|
188 |
+
/**
|
189 |
+
* @return array
|
190 |
+
*/
|
191 |
+
public function getEnabledForms() {
|
192 |
+
return (array)get_option(WP_GDPR_C_PREFIX . '_integrations_' . self::ID . '_forms', array());
|
193 |
+
}
|
194 |
+
|
195 |
+
/**
|
196 |
+
* @return array
|
197 |
+
*/
|
198 |
+
public function getFormTexts() {
|
199 |
+
return (array)get_option(WP_GDPR_C_PREFIX . '_integrations_' . self::ID . '_form_text', array());
|
200 |
+
}
|
201 |
+
|
202 |
+
/**
|
203 |
+
* @return array
|
204 |
+
*/
|
205 |
+
public function getFormErrorMessages() {
|
206 |
+
return (array)get_option(WP_GDPR_C_PREFIX . '_integrations_' . self::ID . '_error_message', array());
|
207 |
+
}
|
208 |
+
|
209 |
+
/**
|
210 |
+
* @return array
|
211 |
+
*/
|
212 |
+
public function getFormRequiredMessages() {
|
213 |
+
return (array)get_option(WP_GDPR_C_PREFIX . '_integrations_' . self::ID . '_required_message', array());
|
214 |
+
}
|
215 |
+
|
216 |
+
/**
|
217 |
+
* @param int $formId
|
218 |
+
* @param bool $insertPrivacyPolicyLink
|
219 |
+
* @return string
|
220 |
+
*/
|
221 |
+
public function getCheckboxText($formId = 0, $insertPrivacyPolicyLink = true) {
|
222 |
+
if (!empty($formId)) {
|
223 |
+
$texts = $this->getFormTexts();
|
224 |
+
if (!empty($texts[$formId])) {
|
225 |
+
$result = wp_kses($texts[$formId], Helper::getAllowedHTMLTags(self::ID));
|
226 |
+
$result = ($insertPrivacyPolicyLink === true) ? Integration::insertPrivacyPolicyLink($result) : $result;
|
227 |
+
return apply_filters('wpgdprc_gforms_checkbox_text', $result, $formId);
|
228 |
+
}
|
229 |
+
}
|
230 |
+
return Integration::getCheckboxText();
|
231 |
+
}
|
232 |
+
|
233 |
+
/**
|
234 |
+
* @param int $formId
|
235 |
+
* @return string
|
236 |
+
*/
|
237 |
+
public function getErrorMessage($formId = 0) {
|
238 |
+
if (!empty($formId)) {
|
239 |
+
$errors = $this->getFormErrorMessages();
|
240 |
+
if (!empty($errors[$formId])) {
|
241 |
+
$result = wp_kses($errors[$formId], Helper::getAllowedHTMLTags(self::ID));
|
242 |
+
return apply_filters('wpgdprc_gforms_error_message', $result, $formId);
|
243 |
+
}
|
244 |
+
}
|
245 |
+
return Integration::getErrorMessage();
|
246 |
+
}
|
247 |
+
|
248 |
+
/**
|
249 |
+
* @param int $formId
|
250 |
+
* @return string
|
251 |
+
*/
|
252 |
+
public function getRequiredMessage($formId = 0) {
|
253 |
+
if (!empty($formId)) {
|
254 |
+
$errors = $this->getFormRequiredMessages();
|
255 |
+
if (!empty($errors[$formId])) {
|
256 |
+
$result = esc_attr($errors[$formId]);
|
257 |
+
return apply_filters('wpgdprc_gforms_required_message', $result, $formId);
|
258 |
+
}
|
259 |
+
}
|
260 |
+
return Integration::getRequiredMessage();
|
261 |
+
}
|
262 |
+
|
263 |
+
/**
|
264 |
+
* @param int $formId
|
265 |
+
* @return int
|
266 |
+
*/
|
267 |
+
private static function getFieldIdByFormId($formId = 0) {
|
268 |
+
$form = \GFFormsModel::get_form_meta($formId);
|
269 |
+
foreach ($form['fields'] as $field) {
|
270 |
+
if (isset($field['wpgdprc']) && $field['wpgdprc'] === true) {
|
271 |
+
if (isset($field['inputs'][0]['id'])) {
|
272 |
+
return $field['inputs'][0]['id'];
|
273 |
+
}
|
274 |
+
}
|
275 |
+
}
|
276 |
+
return 0;
|
277 |
+
}
|
278 |
+
|
279 |
+
/**
|
280 |
+
* @return null|GForms
|
281 |
+
*/
|
282 |
+
public static function getInstance() {
|
283 |
+
if (!isset(self::$instance)) {
|
284 |
+
self::$instance = new self();
|
285 |
+
}
|
286 |
+
return self::$instance;
|
287 |
+
}
|
288 |
}
|
Includes/Extensions/WC.php
CHANGED
@@ -1,111 +1,111 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WPGDPRC\Includes\Extensions;
|
4 |
-
|
5 |
-
use WPGDPRC\Includes\Helper;
|
6 |
-
use WPGDPRC\Includes\Integration;
|
7 |
-
|
8 |
-
/**
|
9 |
-
* Class WC
|
10 |
-
* @package WPGDPRC\Includes\Extensions
|
11 |
-
*/
|
12 |
-
class WC {
|
13 |
-
const ID = 'woocommerce';
|
14 |
-
const SUPPORTED_VERSION = '2.5.0';
|
15 |
-
/** @var null */
|
16 |
-
private static $instance = null;
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Add WP GDPR field before submit button
|
20 |
-
*/
|
21 |
-
public function addField() {
|
22 |
-
$args = array(
|
23 |
-
'type' => 'checkbox',
|
24 |
-
'class' => array('wpgdprc-checkbox'),
|
25 |
-
'label' => Integration::getCheckboxText(self::ID) . ' <abbr class="wpgdprc-required required" title="' . Integration::getRequiredMessage(self::ID) . '">*</abbr>',
|
26 |
-
'required' => true
|
27 |
-
);
|
28 |
-
woocommerce_form_field('wpgdprc', apply_filters('wpgdprc_woocommerce_field_args', $args));
|
29 |
-
}
|
30 |
-
|
31 |
-
/**
|
32 |
-
* Check if WP GDPR checkbox is checked
|
33 |
-
*/
|
34 |
-
public function checkPostCheckoutForm() {
|
35 |
-
if (!isset($_POST['wpgdprc'])) {
|
36 |
-
wc_add_notice(Integration::getErrorMessage(self::ID), 'error');
|
37 |
-
}
|
38 |
-
}
|
39 |
-
|
40 |
-
/**
|
41 |
-
* Check if WP GDPR checkbox is checked on register
|
42 |
-
*
|
43 |
-
* @param string $username
|
44 |
-
* @param string $emailAddress
|
45 |
-
* @param \WP_Error $errors
|
46 |
-
*/
|
47 |
-
public function checkPostRegisterForm($username = '', $emailAddress = '', \WP_Error $errors) {
|
48 |
-
if (!isset($_POST['wpgdprc'])) {
|
49 |
-
$errors->add('wpgdprc_error', Integration::getErrorMessage(self::ID));
|
50 |
-
}
|
51 |
-
}
|
52 |
-
|
53 |
-
/**
|
54 |
-
* @param int $orderId
|
55 |
-
*/
|
56 |
-
public function addAcceptedDateToOrderMeta($orderId = 0) {
|
57 |
-
if (isset($_POST['wpgdprc']) && !empty($orderId)) {
|
58 |
-
update_post_meta($orderId, '_wpgdprc', time());
|
59 |
-
}
|
60 |
-
}
|
61 |
-
|
62 |
-
/**
|
63 |
-
* @param \WC_Order $order
|
64 |
-
*/
|
65 |
-
public function displayAcceptedDateInOrderData(\WC_Order $order) {
|
66 |
-
$orderId = (method_exists($order, 'get_id')) ? $order->get_id() : $order->id;
|
67 |
-
$label = __('GDPR accepted on:', WP_GDPR_C_SLUG);
|
68 |
-
$date = get_post_meta($orderId, '_wpgdprc', true);
|
69 |
-
$value = (!empty($date)) ? Helper::localDateFormat(get_option('date_format') . ' ' . get_option('time_format'), $date) : __('Not accepted.', WP_GDPR_C_SLUG);
|
70 |
-
echo apply_filters(
|
71 |
-
'wpgdprc_woocommerce_accepted_date_in_order_data',
|
72 |
-
sprintf('<p class="form-field form-field-wide wpgdprc-accepted-date"><strong>%s</strong><br />%s</p>', $label, $value),
|
73 |
-
$label,
|
74 |
-
$value,
|
75 |
-
$order
|
76 |
-
);
|
77 |
-
}
|
78 |
-
|
79 |
-
/**
|
80 |
-
* @param array $columns
|
81 |
-
* @return array
|
82 |
-
*/
|
83 |
-
public function displayAcceptedDateColumnInOrderOverview($columns = array()) {
|
84 |
-
$columns['wpgdprc-privacy'] = apply_filters('wpgdprc_accepted_date_column_in_woocommerce_order_overview', __('Privacy', WP_GDPR_C_SLUG));
|
85 |
-
return $columns;
|
86 |
-
}
|
87 |
-
|
88 |
-
/**
|
89 |
-
* @param string $column
|
90 |
-
* @param int $orderId
|
91 |
-
* @return string
|
92 |
-
*/
|
93 |
-
public function displayAcceptedDateInOrderOverview($column = '', $orderId = 0) {
|
94 |
-
if ($column === 'wpgdprc-privacy') {
|
95 |
-
$date = get_post_meta($orderId, '_wpgdprc', true);
|
96 |
-
$value = (!empty($date)) ? Helper::localDateFormat(get_option('date_format') . ' ' . get_option('time_format'), $date) : __('Not accepted.', WP_GDPR_C_SLUG);
|
97 |
-
echo apply_filters('wpgdprc_accepted_date_in_woocommerce_order_overview', $value, $orderId);
|
98 |
-
}
|
99 |
-
return $column;
|
100 |
-
}
|
101 |
-
|
102 |
-
/**
|
103 |
-
* @return null|WC
|
104 |
-
*/
|
105 |
-
public static function getInstance() {
|
106 |
-
if (!isset(self::$instance)) {
|
107 |
-
self::$instance = new self();
|
108 |
-
}
|
109 |
-
return self::$instance;
|
110 |
-
}
|
111 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WPGDPRC\Includes\Extensions;
|
4 |
+
|
5 |
+
use WPGDPRC\Includes\Helper;
|
6 |
+
use WPGDPRC\Includes\Integration;
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Class WC
|
10 |
+
* @package WPGDPRC\Includes\Extensions
|
11 |
+
*/
|
12 |
+
class WC {
|
13 |
+
const ID = 'woocommerce';
|
14 |
+
const SUPPORTED_VERSION = '2.5.0';
|
15 |
+
/** @var null */
|
16 |
+
private static $instance = null;
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Add WP GDPR field before submit button
|
20 |
+
*/
|
21 |
+
public function addField() {
|
22 |
+
$args = array(
|
23 |
+
'type' => 'checkbox',
|
24 |
+
'class' => array('wpgdprc-checkbox'),
|
25 |
+
'label' => Integration::getCheckboxText(self::ID) . ' <abbr class="wpgdprc-required required" title="' . Integration::getRequiredMessage(self::ID) . '">*</abbr>',
|
26 |
+
'required' => true
|
27 |
+
);
|
28 |
+
woocommerce_form_field('wpgdprc', apply_filters('wpgdprc_woocommerce_field_args', $args));
|
29 |
+
}
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Check if WP GDPR checkbox is checked
|
33 |
+
*/
|
34 |
+
public function checkPostCheckoutForm() {
|
35 |
+
if (!isset($_POST['wpgdprc'])) {
|
36 |
+
wc_add_notice(Integration::getErrorMessage(self::ID), 'error');
|
37 |
+
}
|
38 |
+
}
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Check if WP GDPR checkbox is checked on register
|
42 |
+
*
|
43 |
+
* @param string $username
|
44 |
+
* @param string $emailAddress
|
45 |
+
* @param \WP_Error $errors
|
46 |
+
*/
|
47 |
+
public function checkPostRegisterForm($username = '', $emailAddress = '', \WP_Error $errors) {
|
48 |
+
if (!isset($_POST['wpgdprc'])) {
|
49 |
+
$errors->add('wpgdprc_error', Integration::getErrorMessage(self::ID));
|
50 |
+
}
|
51 |
+
}
|
52 |
+
|
53 |
+
/**
|
54 |
+
* @param int $orderId
|
55 |
+
*/
|
56 |
+
public function addAcceptedDateToOrderMeta($orderId = 0) {
|
57 |
+
if (isset($_POST['wpgdprc']) && !empty($orderId)) {
|
58 |
+
update_post_meta($orderId, '_wpgdprc', time());
|
59 |
+
}
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* @param \WC_Order $order
|
64 |
+
*/
|
65 |
+
public function displayAcceptedDateInOrderData(\WC_Order $order) {
|
66 |
+
$orderId = (method_exists($order, 'get_id')) ? $order->get_id() : $order->id;
|
67 |
+
$label = __('GDPR accepted on:', WP_GDPR_C_SLUG);
|
68 |
+
$date = get_post_meta($orderId, '_wpgdprc', true);
|
69 |
+
$value = (!empty($date)) ? Helper::localDateFormat(get_option('date_format') . ' ' . get_option('time_format'), $date) : __('Not accepted.', WP_GDPR_C_SLUG);
|
70 |
+
echo apply_filters(
|
71 |
+
'wpgdprc_woocommerce_accepted_date_in_order_data',
|
72 |
+
sprintf('<p class="form-field form-field-wide wpgdprc-accepted-date"><strong>%s</strong><br />%s</p>', $label, $value),
|
73 |
+
$label,
|
74 |
+
$value,
|
75 |
+
$order
|
76 |
+
);
|
77 |
+
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* @param array $columns
|
81 |
+
* @return array
|
82 |
+
*/
|
83 |
+
public function displayAcceptedDateColumnInOrderOverview($columns = array()) {
|
84 |
+
$columns['wpgdprc-privacy'] = apply_filters('wpgdprc_accepted_date_column_in_woocommerce_order_overview', __('Privacy', WP_GDPR_C_SLUG));
|
85 |
+
return $columns;
|
86 |
+
}
|
87 |
+
|
88 |
+
/**
|
89 |
+
* @param string $column
|
90 |
+
* @param int $orderId
|
91 |
+
* @return string
|
92 |
+
*/
|
93 |
+
public function displayAcceptedDateInOrderOverview($column = '', $orderId = 0) {
|
94 |
+
if ($column === 'wpgdprc-privacy') {
|
95 |
+
$date = get_post_meta($orderId, '_wpgdprc', true);
|
96 |
+
$value = (!empty($date)) ? Helper::localDateFormat(get_option('date_format') . ' ' . get_option('time_format'), $date) : __('Not accepted.', WP_GDPR_C_SLUG);
|
97 |
+
echo apply_filters('wpgdprc_accepted_date_in_woocommerce_order_overview', $value, $orderId);
|
98 |
+
}
|
99 |
+
return $column;
|
100 |
+
}
|
101 |
+
|
102 |
+
/**
|
103 |
+
* @return null|WC
|
104 |
+
*/
|
105 |
+
public static function getInstance() {
|
106 |
+
if (!isset(self::$instance)) {
|
107 |
+
self::$instance = new self();
|
108 |
+
}
|
109 |
+
return self::$instance;
|
110 |
+
}
|
111 |
+
}
|
Includes/Extensions/WP.php
CHANGED
@@ -1,94 +1,94 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WPGDPRC\Includes\Extensions;
|
4 |
-
|
5 |
-
use WPGDPRC\Includes\Helper;
|
6 |
-
use WPGDPRC\Includes\Integration;
|
7 |
-
|
8 |
-
/**
|
9 |
-
* Class WP
|
10 |
-
* @package WPGDPRC\Includes\Extensions
|
11 |
-
*/
|
12 |
-
class WP {
|
13 |
-
const ID = 'wordpress';
|
14 |
-
/** @var null */
|
15 |
-
private static $instance = null;
|
16 |
-
|
17 |
-
/**
|
18 |
-
* @param string $submitField
|
19 |
-
* @return string
|
20 |
-
*/
|
21 |
-
public function addField($submitField = '') {
|
22 |
-
$field = apply_filters(
|
23 |
-
'wpgdprc_wordpress_field',
|
24 |
-
'<p class="wpgdprc-checkbox"><label><input type="checkbox" name="wpgdprc" id="wpgdprc" value="1" /> ' . Integration::getCheckboxText(self::ID) . ' <abbr class="wpgdprc-required" title="' . Integration::getRequiredMessage(self::ID) . '">*</abbr></label></p>',
|
25 |
-
$submitField
|
26 |
-
);
|
27 |
-
return $field . $submitField;
|
28 |
-
}
|
29 |
-
|
30 |
-
public function addFieldForAdmin($submitField = '') {
|
31 |
-
$field = apply_filters(
|
32 |
-
'wpgdprc_wordpress_field',
|
33 |
-
'<label style="font-size: 14px;"><i>' . __('This checkbox is checked because you are an admin',WP_GDPR_C_SLUG) . '</i></label>' .
|
34 |
-
'<p class="wpgdprc-checkbox"><label><input type="checkbox" name="wpgdprc" id="wpgdprc" value="1" checked="checked" /> ' . Integration::getCheckboxText(self::ID) . ' <abbr class="required" title="' . esc_attr__('required', WP_GDPR_C_SLUG) . '">*</abbr></label></p>',
|
35 |
-
$submitField
|
36 |
-
);
|
37 |
-
return $field . $submitField;
|
38 |
-
}
|
39 |
-
|
40 |
-
public function checkPost() {
|
41 |
-
if (!isset($_POST['wpgdprc'])) {
|
42 |
-
wp_die(
|
43 |
-
'<p>' . sprintf(
|
44 |
-
__('<strong>ERROR</strong>: %s', WP_GDPR_C_SLUG),
|
45 |
-
Integration::getErrorMessage(self::ID)
|
46 |
-
) . '</p>',
|
47 |
-
__('Comment Submission Failure'),
|
48 |
-
array('back_link' => true)
|
49 |
-
);
|
50 |
-
}
|
51 |
-
}
|
52 |
-
|
53 |
-
/**
|
54 |
-
* @param int $commentId
|
55 |
-
*/
|
56 |
-
public function addAcceptedDateToCommentMeta($commentId = 0) {
|
57 |
-
if (isset($_POST['wpgdprc']) && !empty($commentId)) {
|
58 |
-
add_comment_meta($commentId, '_wpgdprc', time());
|
59 |
-
}
|
60 |
-
}
|
61 |
-
|
62 |
-
/**
|
63 |
-
* @param array $columns
|
64 |
-
* @return array
|
65 |
-
*/
|
66 |
-
public function displayAcceptedDateColumnInCommentOverview($columns = array()) {
|
67 |
-
$columns['wpgdprc-date'] = apply_filters('wpgdprc_accepted_date_column_in_comment_overview', __('GDPR Accepted On', WP_GDPR_C_SLUG));
|
68 |
-
return $columns;
|
69 |
-
}
|
70 |
-
|
71 |
-
/**
|
72 |
-
* @param string $column
|
73 |
-
* @param int $commentId
|
74 |
-
* @return string
|
75 |
-
*/
|
76 |
-
public function displayAcceptedDateInCommentOverview($column = '', $commentId = 0) {
|
77 |
-
if ($column === 'wpgdprc-date') {
|
78 |
-
$date = get_comment_meta($commentId, '_wpgdprc', true);
|
79 |
-
$value = (!empty($date)) ? Helper::localDateFormat(get_option('date_format') . ' ' . get_option('time_format'), $date) : __('Not accepted.', WP_GDPR_C_SLUG);
|
80 |
-
echo apply_filters('wpgdprc_accepted_date_in_comment_overview', $value, $commentId);
|
81 |
-
}
|
82 |
-
return $column;
|
83 |
-
}
|
84 |
-
|
85 |
-
/**
|
86 |
-
* @return null|WP
|
87 |
-
*/
|
88 |
-
public static function getInstance() {
|
89 |
-
if (!isset(self::$instance)) {
|
90 |
-
self::$instance = new self();
|
91 |
-
}
|
92 |
-
return self::$instance;
|
93 |
-
}
|
94 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WPGDPRC\Includes\Extensions;
|
4 |
+
|
5 |
+
use WPGDPRC\Includes\Helper;
|
6 |
+
use WPGDPRC\Includes\Integration;
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Class WP
|
10 |
+
* @package WPGDPRC\Includes\Extensions
|
11 |
+
*/
|
12 |
+
class WP {
|
13 |
+
const ID = 'wordpress';
|
14 |
+
/** @var null */
|
15 |
+
private static $instance = null;
|
16 |
+
|
17 |
+
/**
|
18 |
+
* @param string $submitField
|
19 |
+
* @return string
|
20 |
+
*/
|
21 |
+
public function addField($submitField = '') {
|
22 |
+
$field = apply_filters(
|
23 |
+
'wpgdprc_wordpress_field',
|
24 |
+
'<p class="wpgdprc-checkbox"><label><input type="checkbox" name="wpgdprc" id="wpgdprc" value="1" /> ' . Integration::getCheckboxText(self::ID) . ' <abbr class="wpgdprc-required" title="' . Integration::getRequiredMessage(self::ID) . '">*</abbr></label></p>',
|
25 |
+
$submitField
|
26 |
+
);
|
27 |
+
return $field . $submitField;
|
28 |
+
}
|
29 |
+
|
30 |
+
public function addFieldForAdmin($submitField = '') {
|
31 |
+
$field = apply_filters(
|
32 |
+
'wpgdprc_wordpress_field',
|
33 |
+
'<label style="font-size: 14px;"><i>' . __('This checkbox is checked because you are an admin',WP_GDPR_C_SLUG) . '</i></label>' .
|
34 |
+
'<p class="wpgdprc-checkbox"><label><input type="checkbox" name="wpgdprc" id="wpgdprc" value="1" checked="checked" /> ' . Integration::getCheckboxText(self::ID) . ' <abbr class="required" title="' . esc_attr__('required', WP_GDPR_C_SLUG) . '">*</abbr></label></p>',
|
35 |
+
$submitField
|
36 |
+
);
|
37 |
+
return $field . $submitField;
|
38 |
+
}
|
39 |
+
|
40 |
+
public function checkPost() {
|
41 |
+
if (!isset($_POST['wpgdprc'])) {
|
42 |
+
wp_die(
|
43 |
+
'<p>' . sprintf(
|
44 |
+
__('<strong>ERROR</strong>: %s', WP_GDPR_C_SLUG),
|
45 |
+
Integration::getErrorMessage(self::ID)
|
46 |
+
) . '</p>',
|
47 |
+
__('Comment Submission Failure'),
|
48 |
+
array('back_link' => true)
|
49 |
+
);
|
50 |
+
}
|
51 |
+
}
|
52 |
+
|
53 |
+
/**
|
54 |
+
* @param int $commentId
|
55 |
+
*/
|
56 |
+
public function addAcceptedDateToCommentMeta($commentId = 0) {
|
57 |
+
if (isset($_POST['wpgdprc']) && !empty($commentId)) {
|
58 |
+
add_comment_meta($commentId, '_wpgdprc', time());
|
59 |
+
}
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* @param array $columns
|
64 |
+
* @return array
|
65 |
+
*/
|
66 |
+
public function displayAcceptedDateColumnInCommentOverview($columns = array()) {
|
67 |
+
$columns['wpgdprc-date'] = apply_filters('wpgdprc_accepted_date_column_in_comment_overview', __('GDPR Accepted On', WP_GDPR_C_SLUG));
|
68 |
+
return $columns;
|
69 |
+
}
|
70 |
+
|
71 |
+
/**
|
72 |
+
* @param string $column
|
73 |
+
* @param int $commentId
|
74 |
+
* @return string
|
75 |
+
*/
|
76 |
+
public function displayAcceptedDateInCommentOverview($column = '', $commentId = 0) {
|
77 |
+
if ($column === 'wpgdprc-date') {
|
78 |
+
$date = get_comment_meta($commentId, '_wpgdprc', true);
|
79 |
+
$value = (!empty($date)) ? Helper::localDateFormat(get_option('date_format') . ' ' . get_option('time_format'), $date) : __('Not accepted.', WP_GDPR_C_SLUG);
|
80 |
+
echo apply_filters('wpgdprc_accepted_date_in_comment_overview', $value, $commentId);
|
81 |
+
}
|
82 |
+
return $column;
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* @return null|WP
|
87 |
+
*/
|
88 |
+
public static function getInstance() {
|
89 |
+
if (!isset(self::$instance)) {
|
90 |
+
self::$instance = new self();
|
91 |
+
}
|
92 |
+
return self::$instance;
|
93 |
+
}
|
94 |
}
|
Includes/Extensions/WPRegistration.php
CHANGED
@@ -1,71 +1,71 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WPGDPRC\Includes\Extensions;
|
4 |
-
|
5 |
-
use WPGDPRC\Includes\Helper;
|
6 |
-
use WPGDPRC\Includes\Integration;
|
7 |
-
|
8 |
-
|
9 |
-
class WPRegistration {
|
10 |
-
|
11 |
-
const ID = 'wp_registration';
|
12 |
-
/** @var null */
|
13 |
-
private static $instance = null;
|
14 |
-
|
15 |
-
public function addField() { ?>
|
16 |
-
<p>
|
17 |
-
<label><input type="checkbox" name="wpgdprc_consent"
|
18 |
-
value="1"/> <?php echo Integration::getCheckboxText( self::ID ) ?><abbr class="wpgdprc-required" title=" <?php echo Integration::getRequiredMessage(self::ID) ?> ">*</abbr></label></p>
|
19 |
-
</p><br>
|
20 |
-
<?php
|
21 |
-
|
22 |
-
}
|
23 |
-
|
24 |
-
/**
|
25 |
-
* @param $errors
|
26 |
-
* @param $sanitized_user_login
|
27 |
-
* @param $user_email
|
28 |
-
*
|
29 |
-
* @return mixed
|
30 |
-
*/
|
31 |
-
public function validateGDPRCheckbox( $errors, $sanitized_user_login, $user_email ) {
|
32 |
-
if ( ! isset( $_POST['wpgdprc_consent'] ) ) {
|
33 |
-
$errors->add( 'gdpr_consent_error', '<strong>ERROR</strong>: ' . Integration::getErrorMessage( self::ID ) );
|
34 |
-
}
|
35 |
-
return $errors;
|
36 |
-
}
|
37 |
-
|
38 |
-
/**
|
39 |
-
*
|
40 |
-
*/
|
41 |
-
public function logGivenGDPRConsent() {
|
42 |
-
|
43 |
-
if ( isset( $_POST['user_email'] ) ) {
|
44 |
-
|
45 |
-
global $wpdb;
|
46 |
-
|
47 |
-
$wpdb->insert( $wpdb->prefix . 'wpgdprc_log', array(
|
48 |
-
'plugin_id' => self::ID,
|
49 |
-
'user' => Helper::anonymizeEmail( $_POST['user_email'] ),
|
50 |
-
'ip_address' => Helper::anonymizeIP( Helper::getClientIpAddress() ),
|
51 |
-
'date_created' => Helper::localDateTime(time())->format('Y-m-d H:i:s'),
|
52 |
-
'log' => 'user has given consent when registering',
|
53 |
-
'consent_text' => Integration::getCheckboxText( self::ID )
|
54 |
-
) );
|
55 |
-
}
|
56 |
-
|
57 |
-
}
|
58 |
-
|
59 |
-
|
60 |
-
/**
|
61 |
-
* @return null|WPRegistration
|
62 |
-
*/
|
63 |
-
public static function getInstance() {
|
64 |
-
if ( ! isset( self::$instance ) ) {
|
65 |
-
self::$instance = new self();
|
66 |
-
}
|
67 |
-
|
68 |
-
return self::$instance;
|
69 |
-
}
|
70 |
-
|
71 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WPGDPRC\Includes\Extensions;
|
4 |
+
|
5 |
+
use WPGDPRC\Includes\Helper;
|
6 |
+
use WPGDPRC\Includes\Integration;
|
7 |
+
|
8 |
+
|
9 |
+
class WPRegistration {
|
10 |
+
|
11 |
+
const ID = 'wp_registration';
|
12 |
+
/** @var null */
|
13 |
+
private static $instance = null;
|
14 |
+
|
15 |
+
public function addField() { ?>
|
16 |
+
<p>
|
17 |
+
<label><input type="checkbox" name="wpgdprc_consent"
|
18 |
+
value="1"/> <?php echo Integration::getCheckboxText( self::ID ) ?><abbr class="wpgdprc-required" title=" <?php echo Integration::getRequiredMessage(self::ID) ?> ">*</abbr></label></p>
|
19 |
+
</p><br>
|
20 |
+
<?php
|
21 |
+
|
22 |
+
}
|
23 |
+
|
24 |
+
/**
|
25 |
+
* @param $errors
|
26 |
+
* @param $sanitized_user_login
|
27 |
+
* @param $user_email
|
28 |
+
*
|
29 |
+
* @return mixed
|
30 |
+
*/
|
31 |
+
public function validateGDPRCheckbox( $errors, $sanitized_user_login, $user_email ) {
|
32 |
+
if ( ! isset( $_POST['wpgdprc_consent'] ) ) {
|
33 |
+
$errors->add( 'gdpr_consent_error', '<strong>ERROR</strong>: ' . Integration::getErrorMessage( self::ID ) );
|
34 |
+
}
|
35 |
+
return $errors;
|
36 |
+
}
|
37 |
+
|
38 |
+
/**
|
39 |
+
*
|
40 |
+
*/
|
41 |
+
public function logGivenGDPRConsent() {
|
42 |
+
|
43 |
+
if ( isset( $_POST['user_email'] ) ) {
|
44 |
+
|
45 |
+
global $wpdb;
|
46 |
+
|
47 |
+
$wpdb->insert( $wpdb->prefix . 'wpgdprc_log', array(
|
48 |
+
'plugin_id' => self::ID,
|
49 |
+
'user' => Helper::anonymizeEmail( $_POST['user_email'] ),
|
50 |
+
'ip_address' => Helper::anonymizeIP( Helper::getClientIpAddress() ),
|
51 |
+
'date_created' => Helper::localDateTime(time())->format('Y-m-d H:i:s'),
|
52 |
+
'log' => 'user has given consent when registering',
|
53 |
+
'consent_text' => Integration::getCheckboxText( self::ID )
|
54 |
+
) );
|
55 |
+
}
|
56 |
+
|
57 |
+
}
|
58 |
+
|
59 |
+
|
60 |
+
/**
|
61 |
+
* @return null|WPRegistration
|
62 |
+
*/
|
63 |
+
public static function getInstance() {
|
64 |
+
if ( ! isset( self::$instance ) ) {
|
65 |
+
self::$instance = new self();
|
66 |
+
}
|
67 |
+
|
68 |
+
return self::$instance;
|
69 |
+
}
|
70 |
+
|
71 |
}
|
Includes/Filter.php
CHANGED
@@ -1,22 +1,22 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WPGDPRC\Includes;
|
4 |
-
|
5 |
-
/**
|
6 |
-
* Class Filter
|
7 |
-
* @package WPGDPRC\Includes
|
8 |
-
*/
|
9 |
-
class Filter {
|
10 |
-
/** @var null */
|
11 |
-
private static $instance = null;
|
12 |
-
|
13 |
-
/**
|
14 |
-
* @return null|Filter
|
15 |
-
*/
|
16 |
-
public static function getInstance() {
|
17 |
-
if (!isset(self::$instance)) {
|
18 |
-
self::$instance = new self();
|
19 |
-
}
|
20 |
-
return self::$instance;
|
21 |
-
}
|
22 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WPGDPRC\Includes;
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Class Filter
|
7 |
+
* @package WPGDPRC\Includes
|
8 |
+
*/
|
9 |
+
class Filter {
|
10 |
+
/** @var null */
|
11 |
+
private static $instance = null;
|
12 |
+
|
13 |
+
/**
|
14 |
+
* @return null|Filter
|
15 |
+
*/
|
16 |
+
public static function getInstance() {
|
17 |
+
if (!isset(self::$instance)) {
|
18 |
+
self::$instance = new self();
|
19 |
+
}
|
20 |
+
return self::$instance;
|
21 |
+
}
|
22 |
}
|
Includes/Helper.php
CHANGED
@@ -1,784 +1,784 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WPGDPRC\Includes;
|
4 |
-
|
5 |
-
use WPGDPRC\Includes\Extensions\CF7;
|
6 |
-
|
7 |
-
/**
|
8 |
-
* Class Helper
|
9 |
-
* @package WPGDPRC\Includes
|
10 |
-
*/
|
11 |
-
class Helper {
|
12 |
-
/** @var null */
|
13 |
-
private static $instance = null;
|
14 |
-
|
15 |
-
/**
|
16 |
-
* @return array
|
17 |
-
*/
|
18 |
-
public static function getPluginData() {
|
19 |
-
return get_plugin_data(WP_GDPR_C_ROOT_FILE);
|
20 |
-
}
|
21 |
-
|
22 |
-
/**
|
23 |
-
* @param string $type
|
24 |
-
* @param array $additionalArgs
|
25 |
-
* @return string
|
26 |
-
*/
|
27 |
-
public static function getPluginAdminUrl($type = '', $additionalArgs = array()) {
|
28 |
-
$args = array(
|
29 |
-
'page' => str_replace('-', '_', WP_GDPR_C_SLUG)
|
30 |
-
);
|
31 |
-
if (!empty($type)) {
|
32 |
-
$args['type'] = esc_html($type);
|
33 |
-
}
|
34 |
-
if (!empty($additionalArgs)) {
|
35 |
-
$args = array_merge($args, $additionalArgs);
|
36 |
-
}
|
37 |
-
$url = add_query_arg($args,
|
38 |
-
admin_url('tools.php')
|
39 |
-
);
|
40 |
-
return $url;
|
41 |
-
}
|
42 |
-
|
43 |
-
/**
|
44 |
-
* @param string $action
|
45 |
-
*/
|
46 |
-
public static function doAction($action = '') {
|
47 |
-
if (!empty($action)) {
|
48 |
-
switch ($action) {
|
49 |
-
case 'create_request_tables' :
|
50 |
-
Helper::createUserRequestDataTables();
|
51 |
-
wp_safe_redirect(Helper::getPluginAdminUrl());
|
52 |
-
die();
|
53 |
-
break;
|
54 |
-
}
|
55 |
-
}
|
56 |
-
}
|
57 |
-
|
58 |
-
/**
|
59 |
-
* @param string $plugin
|
60 |
-
* @return mixed
|
61 |
-
*/
|
62 |
-
public static function getAllowedHTMLTags($plugin = '') {
|
63 |
-
switch ($plugin) {
|
64 |
-
case CF7::ID :
|
65 |
-
$output = '';
|
66 |
-
break;
|
67 |
-
default :
|
68 |
-
$output = array(
|
69 |
-
'a' => array(
|
70 |
-
'class' => array(),
|
71 |
-
'href' => array(),
|
72 |
-
'hreflang' => array(),
|
73 |
-
'title' => array(),
|
74 |
-
'target' => array(),
|
75 |
-
'rel' => array(),
|
76 |
-
),
|
77 |
-
'br' => array(),
|
78 |
-
'em' => array(),
|
79 |
-
'strong' => array(),
|
80 |
-
'u' => array(),
|
81 |
-
'strike' => array(),
|
82 |
-
'span' => array(
|
83 |
-
'class' => array(),
|
84 |
-
),
|
85 |
-
);
|
86 |
-
break;
|
87 |
-
}
|
88 |
-
return apply_filters('wpgdprc_allowed_html_tags', $output, $plugin);
|
89 |
-
}
|
90 |
-
|
91 |
-
/**
|
92 |
-
* @param string $plugin
|
93 |
-
* @return string
|
94 |
-
*/
|
95 |
-
public static function getAllowedHTMLTagsOutput($plugin = '') {
|
96 |
-
$allowedTags = self::getAllowedHTMLTags($plugin);
|
97 |
-
$output = '<div class="wpgdprc-information">';
|
98 |
-
if (!empty($allowedTags)) {
|
99 |
-
$tags = '%privacy_policy%';
|
100 |
-
foreach ($allowedTags as $tag => $attributes) {
|
101 |
-
$tags .= ' <' . $tag;
|
102 |
-
if (!empty($attributes)) {
|
103 |
-
foreach ($attributes as $attribute => $data) {
|
104 |
-
$tags .= ' ' . $attribute . '=""';
|
105 |
-
}
|
106 |
-
}
|
107 |
-
$tags .= '>';
|
108 |
-
}
|
109 |
-
$output .= sprintf(
|
110 |
-
__('You can use: %s', WP_GDPR_C_SLUG),
|
111 |
-
sprintf('<pre>%s</pre>', esc_html($tags))
|
112 |
-
);
|
113 |
-
} else {
|
114 |
-
$output .= sprintf(
|
115 |
-
'<strong>%s:</strong> %s',
|
116 |
-
strtoupper(__('Note', WP_GDPR_C_SLUG)),
|
117 |
-
__('No HTML allowed due to plugin limitations.', WP_GDPR_C_SLUG)
|
118 |
-
);
|
119 |
-
}
|
120 |
-
$output .= '</div>';
|
121 |
-
return $output;
|
122 |
-
}
|
123 |
-
|
124 |
-
/**
|
125 |
-
* @param string $notice
|
126 |
-
*/
|
127 |
-
public static function showAdminNotice($notice = '') {
|
128 |
-
if (!empty($notice)) {
|
129 |
-
$type = 'success';
|
130 |
-
$dismissible = true;
|
131 |
-
$message = '';
|
132 |
-
switch ($notice) {
|
133 |
-
case 'wpgdprc-consent-updated' :
|
134 |
-
$message = __('Consent has been updated successfully.', WP_GDPR_C_SLUG);
|
135 |
-
break;
|
136 |
-
case 'wpgdprc-consent-added' :
|
137 |
-
$message = __('Consent has been added successfully.', WP_GDPR_C_SLUG);
|
138 |
-
break;
|
139 |
-
case 'wpgdprc-consent-removed' :
|
140 |
-
$message = __('Consent has been removed successfully.', WP_GDPR_C_SLUG);
|
141 |
-
break;
|
142 |
-
case 'wpgdprc-consent-not-found' :
|
143 |
-
$type = 'error';
|
144 |
-
$message = __('Couldn\'t find this consent.', WP_GDPR_C_SLUG);
|
145 |
-
break;
|
146 |
-
case 'wpgdprc-cookie-bar-reset' :
|
147 |
-
$message = __('The cookie bar has been reset', WP_GDPR_C_SLUG);
|
148 |
-
break;
|
149 |
-
}
|
150 |
-
if (!empty($message)) {
|
151 |
-
printf(
|
152 |
-
'<div class="notice notice-%s %s"><p>%s</p></div>',
|
153 |
-
$type,
|
154 |
-
(($dismissible) ? 'is-dismissible' : ''),
|
155 |
-
$message
|
156 |
-
);
|
157 |
-
}
|
158 |
-
}
|
159 |
-
}
|
160 |
-
|
161 |
-
/**
|
162 |
-
* @param string $plugin
|
163 |
-
* @return string
|
164 |
-
*/
|
165 |
-
public static function getNotices($plugin = '') {
|
166 |
-
$output = '';
|
167 |
-
switch ($plugin) {
|
168 |
-
case 'wordpress' :
|
169 |
-
if (self::isPluginEnabled('jetpack/jetpack.php')) {
|
170 |
-
$activeModules = (array)get_option('jetpack_active_modules');
|
171 |
-
if (in_array('comments', $activeModules)) {
|
172 |
-
$output .= sprintf(
|
173 |
-
'<strong>%s:</strong> %s',
|
174 |
-
strtoupper(__('Note', WP_GDPR_C_SLUG)),
|
175 |
-
__('Please disable the custom comments form in Jetpack to make your WordPress Comments GDPR compliant.', WP_GDPR_C_SLUG)
|
176 |
-
);
|
177 |
-
}
|
178 |
-
}
|
179 |
-
break;
|
180 |
-
}
|
181 |
-
return $output;
|
182 |
-
}
|
183 |
-
|
184 |
-
/**
|
185 |
-
* @return array
|
186 |
-
*/
|
187 |
-
public static function getCheckList() {
|
188 |
-
return array(
|
189 |
-
'contact_form' => array(
|
190 |
-
'label' => __('Do you have a contact form?', WP_GDPR_C_SLUG),
|
191 |
-
'description' => __('Make sure you add a checkbox specifically asking the user of the form if they consent to you storing and using their personal information to get back in touch with them. The checkbox must be unchecked by default. Also mention if you will send or share the data with any 3rd-parties and which.', WP_GDPR_C_SLUG),
|
192 |
-
),
|
193 |
-
'comments' => array(
|
194 |
-
'label' => __('Can visitors comment anywhere on your website?', WP_GDPR_C_SLUG),
|
195 |
-
'description' => __('Make sure you add a checkbox specifically asking the user of the comment section if they consent to storing their message attached to the e-mail address they\'ve used to comment. The checkbox must be unchecked by default. Also mention if you will send or share the data with any 3rd-parties and which.', WP_GDPR_C_SLUG),
|
196 |
-
),
|
197 |
-
'webshop' => array(
|
198 |
-
'label' => __('Is there an order form on your website or webshop present?', WP_GDPR_C_SLUG),
|
199 |
-
'description' => __('Make sure you add a checkbox specifically asking the user of the form if they consent to you storing and using their personal information to ship the order. This cannot be the same checkbox as the Privacy Policy checkbox you should already have in place. The checkbox must be unchecked by default. Also mention if you will send or share the data with any 3rd-parties and which.', WP_GDPR_C_SLUG),
|
200 |
-
),
|
201 |
-
'forum' => array(
|
202 |
-
'label' => __('Do you provide a forum or message board?', WP_GDPR_C_SLUG),
|
203 |
-
'description' => __('Make sure you add a checkbox specifically asking forum / board users if they consent to you storing and using their personal information and messages. The checkbox must be unchecked by default. Also mention if you will send or share the data with any 3rd-parties and which.', WP_GDPR_C_SLUG),
|
204 |
-
),
|
205 |
-
'chat' => array(
|
206 |
-
'label' => __('Can visitors chat with your company directly?', WP_GDPR_C_SLUG),
|
207 |
-
'description' => __('Make sure you add a checkbox specifically asking chat users if they consent to you storing and using their personal information and messages. The checkbox must be unchecked by default. We recommend also mentioning for how long you will store chat messages or deleting them all within 24 hours. Also mention if you will send or share the data with any 3rd-parties and which.', WP_GDPR_C_SLUG),
|
208 |
-
),
|
209 |
-
);
|
210 |
-
}
|
211 |
-
|
212 |
-
/**
|
213 |
-
* @param string $plugin
|
214 |
-
* @return bool
|
215 |
-
*/
|
216 |
-
public static function isPluginEnabled($plugin = '') {
|
217 |
-
$activatePlugins = (array)self::getActivePlugins();
|
218 |
-
return (in_array($plugin, $activatePlugins));
|
219 |
-
}
|
220 |
-
|
221 |
-
/**
|
222 |
-
* @param string $option
|
223 |
-
* @param string $type
|
224 |
-
* @return bool
|
225 |
-
*/
|
226 |
-
public static function isEnabled($option = '', $type = 'integrations') {
|
227 |
-
return filter_var(get_option(WP_GDPR_C_PREFIX . '_' . $type . '_' . $option, false), FILTER_VALIDATE_BOOLEAN);
|
228 |
-
}
|
229 |
-
|
230 |
-
/**
|
231 |
-
* @param bool $showPluginData
|
232 |
-
* @return array
|
233 |
-
*/
|
234 |
-
public static function getActivePlugins($showPluginData = false) {
|
235 |
-
$activePlugins = (array)get_option('active_plugins', array());
|
236 |
-
$activeNetworkPlugins = (is_multisite()) ? (array)get_site_option('active_sitewide_plugins', array()) : array();
|
237 |
-
if (!empty($activeNetworkPlugins)) {
|
238 |
-
foreach ($activeNetworkPlugins as $file => $timestamp) {
|
239 |
-
if (!in_array($file, $activePlugins)) {
|
240 |
-
$activePlugins[] = $file;
|
241 |
-
}
|
242 |
-
}
|
243 |
-
}
|
244 |
-
|
245 |
-
// Remove this plugin from array
|
246 |
-
$key = array_search(WP_GDPR_C_BASENAME, $activePlugins);
|
247 |
-
if ($key !== false) {
|
248 |
-
unset($activePlugins[$key]);
|
249 |
-
}
|
250 |
-
|
251 |
-
if ($showPluginData) {
|
252 |
-
foreach ($activePlugins as $key => $file) {
|
253 |
-
$pluginData = get_plugin_data(WP_PLUGIN_DIR . '/' . $file);
|
254 |
-
$data = array(
|
255 |
-
'basename' => plugin_basename($file)
|
256 |
-
);
|
257 |
-
if (isset($pluginData['Name'])) {
|
258 |
-
$data['slug'] = sanitize_title($pluginData['Name']);
|
259 |
-
$data['name'] = $pluginData['Name'];
|
260 |
-
}
|
261 |
-
if (isset($pluginData['Description'])) {
|
262 |
-
$data['description'] = $pluginData['Description'];
|
263 |
-
}
|
264 |
-
$activePlugins[$key] = $data;
|
265 |
-
}
|
266 |
-
}
|
267 |
-
|
268 |
-
return $activePlugins;
|
269 |
-
}
|
270 |
-
|
271 |
-
/**
|
272 |
-
* @return array
|
273 |
-
*/
|
274 |
-
public static function getActivatedPlugins() {
|
275 |
-
$output = array();
|
276 |
-
$activePlugins = self::getActivePlugins();
|
277 |
-
// Loop through supported plugins
|
278 |
-
foreach (Integration::getSupportedPlugins() as $plugin) {
|
279 |
-
if (in_array($plugin['file'], $activePlugins)) {
|
280 |
-
if (is_admin()) {
|
281 |
-
$plugin['supported'] = true;
|
282 |
-
if (isset($plugin['supported_version'])) {
|
283 |
-
$pluginData = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin['file']);
|
284 |
-
if (!empty($pluginData['Version']) && $pluginData['Version'] < $plugin['supported_version']) {
|
285 |
-
$plugin['supported'] = false;
|
286 |
-
}
|
287 |
-
}
|
288 |
-
}
|
289 |
-
$output[] = $plugin;
|
290 |
-
}
|
291 |
-
}
|
292 |
-
|
293 |
-
// Loop through supported WordPress functionality
|
294 |
-
foreach (Integration::getSupportedWordPressFunctionality() as $wp) {
|
295 |
-
$wp['supported'] = true;
|
296 |
-
$output[] = $wp;
|
297 |
-
}
|
298 |
-
|
299 |
-
return $output;
|
300 |
-
}
|
301 |
-
|
302 |
-
/**
|
303 |
-
* @return array
|
304 |
-
*/
|
305 |
-
public static function getEnabledPlugins() {
|
306 |
-
$output = array();
|
307 |
-
foreach (self::getActivatedPlugins() as $plugin) {
|
308 |
-
if (self::isEnabled($plugin['id'])) {
|
309 |
-
$output[] = $plugin;
|
310 |
-
}
|
311 |
-
}
|
312 |
-
return $output;
|
313 |
-
}
|
314 |
-
|
315 |
-
/**
|
316 |
-
* @return bool
|
317 |
-
*/
|
318 |
-
public static function hasMailPluginInstalled() {
|
319 |
-
foreach(self::getActivePlugins() as $activePlugin) {
|
320 |
-
if(strpos(strtolower($activePlugin), 'mail') !== false) {
|
321 |
-
return true;
|
322 |
-
}
|
323 |
-
}
|
324 |
-
return false;
|
325 |
-
}
|
326 |
-
|
327 |
-
/**
|
328 |
-
* @param $data
|
329 |
-
* @return string
|
330 |
-
*/
|
331 |
-
public function sanitizeData($data) {
|
332 |
-
if (is_array($data)) {
|
333 |
-
foreach ($data as &$value) {
|
334 |
-
$value = sanitize_text_field($value);
|
335 |
-
}
|
336 |
-
} else {
|
337 |
-
$data = sanitize_text_field($data);
|
338 |
-
}
|
339 |
-
return $data;
|
340 |
-
}
|
341 |
-
|
342 |
-
/**
|
343 |
-
* @param int $timestamp
|
344 |
-
* @return \DateTime
|
345 |
-
*/
|
346 |
-
public static function localDateTime($timestamp = 0) {
|
347 |
-
$gmtOffset = get_option('gmt_offset', '');
|
348 |
-
if ($gmtOffset !== '') {
|
349 |
-
$negative = ($gmtOffset < 0);
|
350 |
-
$gmtOffset = str_replace('-', '', $gmtOffset);
|
351 |
-
$hour = floor($gmtOffset);
|
352 |
-
$minutes = ($gmtOffset - $hour) * 60;
|
353 |
-
if ($negative) {
|
354 |
-
$hour = '-' . $hour;
|
355 |
-
$minutes = '-' . $minutes;
|
356 |
-
}
|
357 |
-
$date = new \DateTime(null, new \DateTimeZone('UTC'));
|
358 |
-
$date->setTimestamp($timestamp);
|
359 |
-
$date->modify($hour . ' hour');
|
360 |
-
$date->modify($minutes . ' minutes');
|
361 |
-
} else {
|
362 |
-
$date = new \DateTime(null, new \DateTimeZone(get_option('timezone_string', 'UTC')));
|
363 |
-
$date->setTimestamp($timestamp);
|
364 |
-
}
|
365 |
-
return new \DateTime($date->format('Y-m-d H:i:s'), new \DateTimeZone('UTC'));
|
366 |
-
}
|
367 |
-
|
368 |
-
/**
|
369 |
-
* @param string $format
|
370 |
-
* @param int $timestamp
|
371 |
-
* @return string
|
372 |
-
*/
|
373 |
-
public static function localDateFormat($format = '', $timestamp = 0) {
|
374 |
-
$date = self::localDateTime($timestamp);
|
375 |
-
return date_i18n($format, $date->getTimestamp(), true);
|
376 |
-
}
|
377 |
-
|
378 |
-
/**
|
379 |
-
* @param string $string
|
380 |
-
* @param int $length
|
381 |
-
* @param string $more
|
382 |
-
* @return string
|
383 |
-
*/
|
384 |
-
public static function shortenStringByWords($string = '', $length = 20, $more = '...') {
|
385 |
-
$words = preg_split("/[\n\r\t ]+/", $string, $length + 1, PREG_SPLIT_NO_EMPTY);
|
386 |
-
if (count($words) > $length) {
|
387 |
-
array_pop($words);
|
388 |
-
$output = implode(' ', $words) . $more;
|
389 |
-
} else {
|
390 |
-
$output = implode(' ', $words);
|
391 |
-
}
|
392 |
-
return $output;
|
393 |
-
}
|
394 |
-
|
395 |
-
/**
|
396 |
-
* Ensures an ip address is both a valid IP and does not fall within
|
397 |
-
* a private network range.
|
398 |
-
*
|
399 |
-
* @param string $ipAddress
|
400 |
-
* @return bool
|
401 |
-
*/
|
402 |
-
public static function validateIpAddress($ipAddress = '') {
|
403 |
-
if (strtolower($ipAddress) === 'unknown') {
|
404 |
-
return false;
|
405 |
-
}
|
406 |
-
// Generate ipv4 network address
|
407 |
-
$ipAddress = ip2long($ipAddress);
|
408 |
-
// If the ip is set and not equivalent to 255.255.255.255
|
409 |
-
if ($ipAddress !== false && $ipAddress !== -1) {
|
410 |
-
/**
|
411 |
-
* Make sure to get unsigned long representation of ip
|
412 |
-
* due to discrepancies between 32 and 64 bit OSes and
|
413 |
-
* signed numbers (ints default to signed in PHP)
|
414 |
-
*/
|
415 |
-
$ipAddress = sprintf('%u', $ipAddress);
|
416 |
-
// Do private network range checking
|
417 |
-
if ($ipAddress >= 0 && $ipAddress <= 50331647) return false;
|
418 |
-
if ($ipAddress >= 167772160 && $ipAddress <= 184549375) return false;
|
419 |
-
if ($ipAddress >= 2130706432 && $ipAddress <= 2147483647) return false;
|
420 |
-
if ($ipAddress >= 2851995648 && $ipAddress <= 2852061183) return false;
|
421 |
-
if ($ipAddress >= 2886729728 && $ipAddress <= 2887778303) return false;
|
422 |
-
if ($ipAddress >= 3221225984 && $ipAddress <= 3221226239) return false;
|
423 |
-
if ($ipAddress >= 3232235520 && $ipAddress <= 3232301055) return false;
|
424 |
-
if ($ipAddress >= 4294967040) return false;
|
425 |
-
}
|
426 |
-
return true;
|
427 |
-
}
|
428 |
-
|
429 |
-
/**
|
430 |
-
* @return string
|
431 |
-
*/
|
432 |
-
public static function getClientIpAddress() {
|
433 |
-
// Check for shared internet/ISP IP
|
434 |
-
if (!empty($_SERVER['HTTP_CLIENT_IP']) && self::validateIpAddress($_SERVER['HTTP_CLIENT_IP'])) {
|
435 |
-
return $_SERVER['HTTP_CLIENT_IP'];
|
436 |
-
}
|
437 |
-
// Check for IPs passing through proxies
|
438 |
-
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
439 |
-
// Check if multiple ips exist in var
|
440 |
-
if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',') !== false) {
|
441 |
-
$listOfIpAddresses = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
|
442 |
-
foreach ($listOfIpAddresses as $ipAddress) {
|
443 |
-
$ipAddress = trim($ipAddress);
|
444 |
-
if (self::validateIpAddress($ipAddress)) {
|
445 |
-
return $ipAddress;
|
446 |
-
}
|
447 |
-
}
|
448 |
-
} else {
|
449 |
-
if (self::validateIpAddress($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
450 |
-
return $_SERVER['HTTP_X_FORWARDED_FOR'];
|
451 |
-
}
|
452 |
-
}
|
453 |
-
}
|
454 |
-
if (!empty($_SERVER['HTTP_X_FORWARDED']) && self::validateIpAddress($_SERVER['HTTP_X_FORWARDED'])) {
|
455 |
-
return $_SERVER['HTTP_X_FORWARDED'];
|
456 |
-
}
|
457 |
-
if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && self::validateIpAddress($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) {
|
458 |
-
return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
|
459 |
-
}
|
460 |
-
if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && self::validateIpAddress($_SERVER['HTTP_FORWARDED_FOR'])) {
|
461 |
-
return $_SERVER['HTTP_FORWARDED_FOR'];
|
462 |
-
}
|
463 |
-
if (!empty($_SERVER['HTTP_FORWARDED']) && self::validateIpAddress($_SERVER['HTTP_FORWARDED'])) {
|
464 |
-
return $_SERVER['HTTP_FORWARDED'];
|
465 |
-
}
|
466 |
-
// Return unreliable ip since all else failed
|
467 |
-
return $_SERVER['REMOTE_ADDR'];
|
468 |
-
}
|
469 |
-
|
470 |
-
/**
|
471 |
-
* @param string $ipAddress
|
472 |
-
* @return bool
|
473 |
-
*/
|
474 |
-
public static function checkIpAddress($ipAddress = '') {
|
475 |
-
return self::getClientIpAddress() === $ipAddress;
|
476 |
-
}
|
477 |
-
|
478 |
-
/**
|
479 |
-
* @param string $type
|
480 |
-
* @param int $siteId
|
481 |
-
* @return string
|
482 |
-
*/
|
483 |
-
public static function getSiteData($type = '', $siteId = 0) {
|
484 |
-
$output = '';
|
485 |
-
if (!empty($type)) {
|
486 |
-
$output = (!empty($siteId) && is_multisite()) ? get_blog_option($siteId, $type) : get_option($type);
|
487 |
-
}
|
488 |
-
return $output;
|
489 |
-
}
|
490 |
-
|
491 |
-
/**
|
492 |
-
* This function returns all available options used by the WPGDPRC plugin.
|
493 |
-
* NOTE: Keep this list updated in case of newly added/updated options.
|
494 |
-
*
|
495 |
-
* @return array
|
496 |
-
*/
|
497 |
-
public static function getAvailableOptions() {
|
498 |
-
$output = array();
|
499 |
-
|
500 |
-
// Settings for activated plugins
|
501 |
-
$activatedPlugins = Helper::getActivatedPlugins();
|
502 |
-
foreach ($activatedPlugins as $plugin) {
|
503 |
-
$output[] = WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'];
|
504 |
-
$output[] = WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_form_text';
|
505 |
-
$output[] = WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_error_message';
|
506 |
-
switch ($plugin['id']) {
|
507 |
-
case 'gravity-forms' :
|
508 |
-
case 'contact-form-7' :
|
509 |
-
$output[] = WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_forms';
|
510 |
-
break;
|
511 |
-
}
|
512 |
-
switch ($plugin['id']) {
|
513 |
-
case 'gravity-forms' :
|
514 |
-
case 'woocommerce' :
|
515 |
-
case 'wordpress' :
|
516 |
-
$output[] = WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_required_message';
|
517 |
-
break;
|
518 |
-
}
|
519 |
-
}
|
520 |
-
|
521 |
-
// Settings for the checklist
|
522 |
-
foreach (Helper::getCheckList() as $id => $check) {
|
523 |
-
$output[] = WP_GDPR_C_PREFIX . '_general_' . $id;
|
524 |
-
}
|
525 |
-
|
526 |
-
// Settings for the general things
|
527 |
-
$output[] = WP_GDPR_C_PREFIX . '_settings_privacy_policy_page';
|
528 |
-
$output[] = WP_GDPR_C_PREFIX . '_settings_privacy_policy_text';
|
529 |
-
$output[] = WP_GDPR_C_PREFIX . '_settings_enable_access_request';
|
530 |
-
if (Helper::isEnabled('enable_access_request', 'settings')) {
|
531 |
-
$output[] = WP_GDPR_C_PREFIX . '_settings_access_request_page';
|
532 |
-
$output[] = WP_GDPR_C_PREFIX . '_settings_access_request_form_checkbox_text';
|
533 |
-
$output[] = WP_GDPR_C_PREFIX . '_settings_delete_request_form_explanation_text';
|
534 |
-
}
|
535 |
-
$output[] = WP_GDPR_C_PREFIX . '_settings_consents_modal_title';
|
536 |
-
$output[] = WP_GDPR_C_PREFIX . '_settings_consents_modal_explanation_text';
|
537 |
-
$output[] = WP_GDPR_C_PREFIX . '_settings_consents_bar_explanation_text';
|
538 |
-
|
539 |
-
return $output;
|
540 |
-
}
|
541 |
-
|
542 |
-
/**
|
543 |
-
* @return bool|\WP_Post
|
544 |
-
*/
|
545 |
-
public static function getAccessRequestPage() {
|
546 |
-
$output = false;
|
547 |
-
$option = get_option(WP_GDPR_C_PREFIX . '_settings_access_request_page', 0);
|
548 |
-
if (!empty($option)) {
|
549 |
-
$output = get_post($option);
|
550 |
-
} else {
|
551 |
-
$page = get_pages(array(
|
552 |
-
'post_type' => 'page',
|
553 |
-
'post_status' => 'publish,private,draft',
|
554 |
-
'number' => 1,
|
555 |
-
'meta_key' => '_wpgdprc_access_request',
|
556 |
-
'meta_value' => '1'
|
557 |
-
));
|
558 |
-
if (!empty($page)) {
|
559 |
-
/** @var \WP_Post $output */
|
560 |
-
$output = $page[0];
|
561 |
-
}
|
562 |
-
}
|
563 |
-
return $output;
|
564 |
-
}
|
565 |
-
|
566 |
-
/**
|
567 |
-
* Function resets the cookie bar for all users, this will happen on button trigger & when new Consent has been added.
|
568 |
-
*/
|
569 |
-
public static function resetCookieBar() {
|
570 |
-
$consentVersion = get_option('wpgdprc_consent_version');
|
571 |
-
$consentVersion += 1;
|
572 |
-
update_option('wpgdprc_consent_version', $consentVersion);
|
573 |
-
|
574 |
-
}
|
575 |
-
|
576 |
-
/**
|
577 |
-
* @return array
|
578 |
-
*/
|
579 |
-
public static function getRequiredConsentIds() {
|
580 |
-
$output = array();
|
581 |
-
$requiredConsents = Consent::getInstance()->getList(array(
|
582 |
-
'required' => array(
|
583 |
-
'value' => 1,
|
584 |
-
),
|
585 |
-
'active' => array(
|
586 |
-
'value' => 1
|
587 |
-
),
|
588 |
-
));
|
589 |
-
if (!empty($requiredConsents)) {
|
590 |
-
foreach ($requiredConsents as $requiredConsent) {
|
591 |
-
$output[] = intval($requiredConsent->getId());
|
592 |
-
}
|
593 |
-
}
|
594 |
-
return $output;
|
595 |
-
}
|
596 |
-
|
597 |
-
/**
|
598 |
-
* @return array|bool
|
599 |
-
*/
|
600 |
-
public static function getConsentIdsByCookie() {
|
601 |
-
$output = array();
|
602 |
-
$requiredConsents = Consent::getInstance()->getList(array(
|
603 |
-
'required' => array(
|
604 |
-
'value' => 1
|
605 |
-
),
|
606 |
-
'active' => array(
|
607 |
-
'value' => 1
|
608 |
-
)
|
609 |
-
));
|
610 |
-
$consentVersion = get_option('wpgdprc_consent_version');
|
611 |
-
$consents = (!empty($_COOKIE['wpgdprc-consent-' . $consentVersion])) ? esc_html($_COOKIE['wpgdprc-consent-' . $consentVersion]) : '';
|
612 |
-
if (!empty($requiredConsents)) {
|
613 |
-
foreach ($requiredConsents as $requiredConsent) {
|
614 |
-
$output[] = intval($requiredConsent->getId());
|
615 |
-
}
|
616 |
-
}
|
617 |
-
if (!empty($consents)) {
|
618 |
-
switch ($consents) {
|
619 |
-
case 'decline' :
|
620 |
-
break;
|
621 |
-
case 'accept' :
|
622 |
-
$consents = Consent::getInstance()->getList(array(
|
623 |
-
'required' => array(
|
624 |
-
'value' => 0
|
625 |
-
),
|
626 |
-
'active' => array(
|
627 |
-
'value' => 1
|
628 |
-
)
|
629 |
-
));
|
630 |
-
foreach ($consents as $consent) {
|
631 |
-
$output[] = intval($consent->getId());
|
632 |
-
}
|
633 |
-
break;
|
634 |
-
default :
|
635 |
-
$consents = explode(',', $consents);
|
636 |
-
foreach ($consents as $id) {
|
637 |
-
if (is_numeric($id) && Consent::getInstance()->exists($id)) {
|
638 |
-
$output[] = intval($id);
|
639 |
-
}
|
640 |
-
}
|
641 |
-
break;
|
642 |
-
}
|
643 |
-
}
|
644 |
-
return $output;
|
645 |
-
}
|
646 |
-
|
647 |
-
public static function createUserRequestDataTables() {
|
648 |
-
global $wpdb;
|
649 |
-
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
650 |
-
$charsetCollate = $wpdb->get_charset_collate();
|
651 |
-
$query = "CREATE TABLE IF NOT EXISTS `" . AccessRequest::getDatabaseTableName() . "` (
|
652 |
-
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
|
653 |
-
`site_id` bigint(20) NOT NULL,
|
654 |
-
`email_address` varchar(100) NOT NULL,
|
655 |
-
`session_id` varchar(255) NOT NULL,
|
656 |
-
`ip_address` varchar(100) NOT NULL,
|
657 |
-
`expired` tinyint(1) DEFAULT '0' NOT NULL,
|
658 |
-
`date_created` datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
|
659 |
-
PRIMARY KEY (`ID`)
|
660 |
-
) $charsetCollate;";
|
661 |
-
dbDelta($query);
|
662 |
-
$query = "CREATE TABLE IF NOT EXISTS `" . DeleteRequest::getDatabaseTableName() . "` (
|
663 |
-
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
|
664 |
-
`site_id` bigint(20) NOT NULL,
|
665 |
-
`access_request_id` bigint(20) NOT NULL,
|
666 |
-
`session_id` varchar(255) NOT NULL,
|
667 |
-
`ip_address` varchar(100) NOT NULL,
|
668 |
-
`data_id` bigint(20) NOT NULL,
|
669 |
-
`type` varchar(255) NOT NULL,
|
670 |
-
`processed` tinyint(1) DEFAULT '0' NOT NULL,
|
671 |
-
`date_created` datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
|
672 |
-
PRIMARY KEY (`ID`)
|
673 |
-
) $charsetCollate;";
|
674 |
-
dbDelta($query);
|
675 |
-
}
|
676 |
-
|
677 |
-
/**
|
678 |
-
* @param array $filters
|
679 |
-
* @param bool $grouped
|
680 |
-
* @return string
|
681 |
-
*/
|
682 |
-
public static function getQueryByFilters($filters = array(), $grouped = false) {
|
683 |
-
$output = '';
|
684 |
-
if (!empty($filters)) {
|
685 |
-
$count = 0;
|
686 |
-
foreach ($filters as $column => $filter) {
|
687 |
-
if (isset($filter['columns'])) {
|
688 |
-
$output .= " AND ( ";
|
689 |
-
$output .= trim(self::getQueryByFilters($filter['columns'], true));
|
690 |
-
$output .= " )";
|
691 |
-
} else {
|
692 |
-
$value = (isset($filter['value'])) ? $filter['value'] : false;
|
693 |
-
if ($value !== false) {
|
694 |
-
$or = (isset($filter['or']) && filter_var($filter['or'], FILTER_VALIDATE_BOOLEAN)) ? 'OR' : 'AND';
|
695 |
-
$or = ($grouped === true && $count === 0) ? '' : $or;
|
696 |
-
$compare = (isset($filter['compare'])) ? $filter['compare'] : '=';
|
697 |
-
$wildcard = (isset($filter['wildcard']) && filter_var($filter['wildcard'], FILTER_VALIDATE_BOOLEAN)) ? '%' : '';
|
698 |
-
if (($compare === 'IN' || $compare === 'NOT IN') && is_array($value)) {
|
699 |
-
$in = '';
|
700 |
-
foreach ($value as $key => $data) {
|
701 |
-
$in .= ($key !== 0) ? ', ' : '';
|
702 |
-
$in .= (is_numeric($data)) ? $data : "'" . $data . "'";
|
703 |
-
}
|
704 |
-
$value = '(' . $in . ')';
|
705 |
-
$output .= " $or `$column` $compare $wildcard$value$wildcard";
|
706 |
-
} else {
|
707 |
-
$output .= " $or `$column` $compare '$wildcard$value$wildcard'";
|
708 |
-
}
|
709 |
-
}
|
710 |
-
}
|
711 |
-
$count++;
|
712 |
-
}
|
713 |
-
}
|
714 |
-
return $output;
|
715 |
-
}
|
716 |
-
|
717 |
-
/**
|
718 |
-
* @param $email
|
719 |
-
*
|
720 |
-
* @return null|string
|
721 |
-
*/
|
722 |
-
public static function anonymizeEmail($email) {
|
723 |
-
|
724 |
-
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
725 |
-
|
726 |
-
$emailParts = explode('@', $email);
|
727 |
-
$localPart = $emailParts[0];
|
728 |
-
if (strlen($localPart) > 1 && strlen($localPart) < 4) {
|
729 |
-
$localPart = substr_replace($localPart, '*', strlen($localPart) - 1);
|
730 |
-
} else if (strlen($localPart) > 3 && strlen($localPart) < 6) {
|
731 |
-
$localPart = substr_replace($localPart, '**', strlen($localPart) - 2);
|
732 |
-
} else if (strlen($localPart) > 5) {
|
733 |
-
$localPart = substr_replace($localPart, '***', strlen($localPart) - 3);
|
734 |
-
} else {
|
735 |
-
$domain = $emailParts[1];
|
736 |
-
$domainName = explode('.', $domain);
|
737 |
-
$anonymisedDomain = str_replace($domainName[0], '***', $domainName[0]);
|
738 |
-
}
|
739 |
-
|
740 |
-
if (isset($domainName) && isset($anonymisedDomain)) {
|
741 |
-
return $localPart . '@' . $anonymisedDomain . '.' . $domainName[1];
|
742 |
-
} else {
|
743 |
-
return $localPart . '@' . $emailParts[1];
|
744 |
-
}
|
745 |
-
} else {
|
746 |
-
return NULL;
|
747 |
-
}
|
748 |
-
|
749 |
-
}
|
750 |
-
|
751 |
-
/**
|
752 |
-
* @param $ip
|
753 |
-
*
|
754 |
-
* @return null|string
|
755 |
-
*/
|
756 |
-
public static function anonymizeIP($ip) {
|
757 |
-
|
758 |
-
if (filter_var($ip, FILTER_VALIDATE_IP)) {
|
759 |
-
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
|
760 |
-
$lastDot = strrpos($ip, '.') + 1;
|
761 |
-
return substr($ip, 0, $lastDot)
|
762 |
-
. str_repeat('*', strlen($ip) - $lastDot);
|
763 |
-
} else if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
|
764 |
-
$lastColon = strrpos($ip, ':') + 1;
|
765 |
-
return substr($ip, 0, $lastColon)
|
766 |
-
. str_repeat('*', strlen($ip) - $lastColon);
|
767 |
-
} else {
|
768 |
-
return NULL;
|
769 |
-
}
|
770 |
-
} else {
|
771 |
-
return NULL;
|
772 |
-
}
|
773 |
-
}
|
774 |
-
|
775 |
-
/**
|
776 |
-
* @return null|Helper
|
777 |
-
*/
|
778 |
-
public static function getInstance() {
|
779 |
-
if (!isset(self::$instance)) {
|
780 |
-
self::$instance = new self();
|
781 |
-
}
|
782 |
-
return self::$instance;
|
783 |
-
}
|
784 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WPGDPRC\Includes;
|
4 |
+
|
5 |
+
use WPGDPRC\Includes\Extensions\CF7;
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Class Helper
|
9 |
+
* @package WPGDPRC\Includes
|
10 |
+
*/
|
11 |
+
class Helper {
|
12 |
+
/** @var null */
|
13 |
+
private static $instance = null;
|
14 |
+
|
15 |
+
/**
|
16 |
+
* @return array
|
17 |
+
*/
|
18 |
+
public static function getPluginData() {
|
19 |
+
return get_plugin_data(WP_GDPR_C_ROOT_FILE);
|
20 |
+
}
|
21 |
+
|
22 |
+
/**
|
23 |
+
* @param string $type
|
24 |
+
* @param array $additionalArgs
|
25 |
+
* @return string
|
26 |
+
*/
|
27 |
+
public static function getPluginAdminUrl($type = '', $additionalArgs = array()) {
|
28 |
+
$args = array(
|
29 |
+
'page' => str_replace('-', '_', WP_GDPR_C_SLUG)
|
30 |
+
);
|
31 |
+
if (!empty($type)) {
|
32 |
+
$args['type'] = esc_html($type);
|
33 |
+
}
|
34 |
+
if (!empty($additionalArgs)) {
|
35 |
+
$args = array_merge($args, $additionalArgs);
|
36 |
+
}
|
37 |
+
$url = add_query_arg($args,
|
38 |
+
admin_url('tools.php')
|
39 |
+
);
|
40 |
+
return $url;
|
41 |
+
}
|
42 |
+
|
43 |
+
/**
|
44 |
+
* @param string $action
|
45 |
+
*/
|
46 |
+
public static function doAction($action = '') {
|
47 |
+
if (!empty($action)) {
|
48 |
+
switch ($action) {
|
49 |
+
case 'create_request_tables' :
|
50 |
+
Helper::createUserRequestDataTables();
|
51 |
+
wp_safe_redirect(Helper::getPluginAdminUrl());
|
52 |
+
die();
|
53 |
+
break;
|
54 |
+
}
|
55 |
+
}
|
56 |
+
}
|
57 |
+
|
58 |
+
/**
|
59 |
+
* @param string $plugin
|
60 |
+
* @return mixed
|
61 |
+
*/
|
62 |
+
public static function getAllowedHTMLTags($plugin = '') {
|
63 |
+
switch ($plugin) {
|
64 |
+
case CF7::ID :
|
65 |
+
$output = '';
|
66 |
+
break;
|
67 |
+
default :
|
68 |
+
$output = array(
|
69 |
+
'a' => array(
|
70 |
+
'class' => array(),
|
71 |
+
'href' => array(),
|
72 |
+
'hreflang' => array(),
|
73 |
+
'title' => array(),
|
74 |
+
'target' => array(),
|
75 |
+
'rel' => array(),
|
76 |
+
),
|
77 |
+
'br' => array(),
|
78 |
+
'em' => array(),
|
79 |
+
'strong' => array(),
|
80 |
+
'u' => array(),
|
81 |
+
'strike' => array(),
|
82 |
+
'span' => array(
|
83 |
+
'class' => array(),
|
84 |
+
),
|
85 |
+
);
|
86 |
+
break;
|
87 |
+
}
|
88 |
+
return apply_filters('wpgdprc_allowed_html_tags', $output, $plugin);
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* @param string $plugin
|
93 |
+
* @return string
|
94 |
+
*/
|
95 |
+
public static function getAllowedHTMLTagsOutput($plugin = '') {
|
96 |
+
$allowedTags = self::getAllowedHTMLTags($plugin);
|
97 |
+
$output = '<div class="wpgdprc-information">';
|
98 |
+
if (!empty($allowedTags)) {
|
99 |
+
$tags = '%privacy_policy%';
|
100 |
+
foreach ($allowedTags as $tag => $attributes) {
|
101 |
+
$tags .= ' <' . $tag;
|
102 |
+
if (!empty($attributes)) {
|
103 |
+
foreach ($attributes as $attribute => $data) {
|
104 |
+
$tags .= ' ' . $attribute . '=""';
|
105 |
+
}
|
106 |
+
}
|
107 |
+
$tags .= '>';
|
108 |
+
}
|
109 |
+
$output .= sprintf(
|
110 |
+
__('You can use: %s', WP_GDPR_C_SLUG),
|
111 |
+
sprintf('<pre>%s</pre>', esc_html($tags))
|
112 |
+
);
|
113 |
+
} else {
|
114 |
+
$output .= sprintf(
|
115 |
+
'<strong>%s:</strong> %s',
|
116 |
+
strtoupper(__('Note', WP_GDPR_C_SLUG)),
|
117 |
+
__('No HTML allowed due to plugin limitations.', WP_GDPR_C_SLUG)
|
118 |
+
);
|
119 |
+
}
|
120 |
+
$output .= '</div>';
|
121 |
+
return $output;
|
122 |
+
}
|
123 |
+
|
124 |
+
/**
|
125 |
+
* @param string $notice
|
126 |
+
*/
|
127 |
+
public static function showAdminNotice($notice = '') {
|
128 |
+
if (!empty($notice)) {
|
129 |
+
$type = 'success';
|
130 |
+
$dismissible = true;
|
131 |
+
$message = '';
|
132 |
+
switch ($notice) {
|
133 |
+
case 'wpgdprc-consent-updated' :
|
134 |
+
$message = __('Consent has been updated successfully.', WP_GDPR_C_SLUG);
|
135 |
+
break;
|
136 |
+
case 'wpgdprc-consent-added' :
|
137 |
+
$message = __('Consent has been added successfully.', WP_GDPR_C_SLUG);
|
138 |
+
break;
|
139 |
+
case 'wpgdprc-consent-removed' :
|
140 |
+
$message = __('Consent has been removed successfully.', WP_GDPR_C_SLUG);
|
141 |
+
break;
|
142 |
+
case 'wpgdprc-consent-not-found' :
|
143 |
+
$type = 'error';
|
144 |
+
$message = __('Couldn\'t find this consent.', WP_GDPR_C_SLUG);
|
145 |
+
break;
|
146 |
+
case 'wpgdprc-cookie-bar-reset' :
|
147 |
+
$message = __('The cookie bar has been reset', WP_GDPR_C_SLUG);
|
148 |
+
break;
|
149 |
+
}
|
150 |
+
if (!empty($message)) {
|
151 |
+
printf(
|
152 |
+
'<div class="notice notice-%s %s"><p>%s</p></div>',
|
153 |
+
$type,
|
154 |
+
(($dismissible) ? 'is-dismissible' : ''),
|
155 |
+
$message
|
156 |
+
);
|
157 |
+
}
|
158 |
+
}
|
159 |
+
}
|
160 |
+
|
161 |
+
/**
|
162 |
+
* @param string $plugin
|
163 |
+
* @return string
|
164 |
+
*/
|
165 |
+
public static function getNotices($plugin = '') {
|
166 |
+
$output = '';
|
167 |
+
switch ($plugin) {
|
168 |
+
case 'wordpress' :
|
169 |
+
if (self::isPluginEnabled('jetpack/jetpack.php')) {
|
170 |
+
$activeModules = (array)get_option('jetpack_active_modules');
|
171 |
+
if (in_array('comments', $activeModules)) {
|
172 |
+
$output .= sprintf(
|
173 |
+
'<strong>%s:</strong> %s',
|
174 |
+
strtoupper(__('Note', WP_GDPR_C_SLUG)),
|
175 |
+
__('Please disable the custom comments form in Jetpack to make your WordPress Comments GDPR compliant.', WP_GDPR_C_SLUG)
|
176 |
+
);
|
177 |
+
}
|
178 |
+
}
|
179 |
+
break;
|
180 |
+
}
|
181 |
+
return $output;
|
182 |
+
}
|
183 |
+
|
184 |
+
/**
|
185 |
+
* @return array
|
186 |
+
*/
|
187 |
+
public static function getCheckList() {
|
188 |
+
return array(
|
189 |
+
'contact_form' => array(
|
190 |
+
'label' => __('Do you have a contact form?', WP_GDPR_C_SLUG),
|
191 |
+
'description' => __('Make sure you add a checkbox specifically asking the user of the form if they consent to you storing and using their personal information to get back in touch with them. The checkbox must be unchecked by default. Also mention if you will send or share the data with any 3rd-parties and which.', WP_GDPR_C_SLUG),
|
192 |
+
),
|
193 |
+
'comments' => array(
|
194 |
+
'label' => __('Can visitors comment anywhere on your website?', WP_GDPR_C_SLUG),
|
195 |
+
'description' => __('Make sure you add a checkbox specifically asking the user of the comment section if they consent to storing their message attached to the e-mail address they\'ve used to comment. The checkbox must be unchecked by default. Also mention if you will send or share the data with any 3rd-parties and which.', WP_GDPR_C_SLUG),
|
196 |
+
),
|
197 |
+
'webshop' => array(
|
198 |
+
'label' => __('Is there an order form on your website or webshop present?', WP_GDPR_C_SLUG),
|
199 |
+
'description' => __('Make sure you add a checkbox specifically asking the user of the form if they consent to you storing and using their personal information to ship the order. This cannot be the same checkbox as the Privacy Policy checkbox you should already have in place. The checkbox must be unchecked by default. Also mention if you will send or share the data with any 3rd-parties and which.', WP_GDPR_C_SLUG),
|
200 |
+
),
|
201 |
+
'forum' => array(
|
202 |
+
'label' => __('Do you provide a forum or message board?', WP_GDPR_C_SLUG),
|
203 |
+
'description' => __('Make sure you add a checkbox specifically asking forum / board users if they consent to you storing and using their personal information and messages. The checkbox must be unchecked by default. Also mention if you will send or share the data with any 3rd-parties and which.', WP_GDPR_C_SLUG),
|
204 |
+
),
|
205 |
+
'chat' => array(
|
206 |
+
'label' => __('Can visitors chat with your company directly?', WP_GDPR_C_SLUG),
|
207 |
+
'description' => __('Make sure you add a checkbox specifically asking chat users if they consent to you storing and using their personal information and messages. The checkbox must be unchecked by default. We recommend also mentioning for how long you will store chat messages or deleting them all within 24 hours. Also mention if you will send or share the data with any 3rd-parties and which.', WP_GDPR_C_SLUG),
|
208 |
+
),
|
209 |
+
);
|
210 |
+
}
|
211 |
+
|
212 |
+
/**
|
213 |
+
* @param string $plugin
|
214 |
+
* @return bool
|
215 |
+
*/
|
216 |
+
public static function isPluginEnabled($plugin = '') {
|
217 |
+
$activatePlugins = (array)self::getActivePlugins();
|
218 |
+
return (in_array($plugin, $activatePlugins));
|
219 |
+
}
|
220 |
+
|
221 |
+
/**
|
222 |
+
* @param string $option
|
223 |
+
* @param string $type
|
224 |
+
* @return bool
|
225 |
+
*/
|
226 |
+
public static function isEnabled($option = '', $type = 'integrations') {
|
227 |
+
return filter_var(get_option(WP_GDPR_C_PREFIX . '_' . $type . '_' . $option, false), FILTER_VALIDATE_BOOLEAN);
|
228 |
+
}
|
229 |
+
|
230 |
+
/**
|
231 |
+
* @param bool $showPluginData
|
232 |
+
* @return array
|
233 |
+
*/
|
234 |
+
public static function getActivePlugins($showPluginData = false) {
|
235 |
+
$activePlugins = (array)get_option('active_plugins', array());
|
236 |
+
$activeNetworkPlugins = (is_multisite()) ? (array)get_site_option('active_sitewide_plugins', array()) : array();
|
237 |
+
if (!empty($activeNetworkPlugins)) {
|
238 |
+
foreach ($activeNetworkPlugins as $file => $timestamp) {
|
239 |
+
if (!in_array($file, $activePlugins)) {
|
240 |
+
$activePlugins[] = $file;
|
241 |
+
}
|
242 |
+
}
|
243 |
+
}
|
244 |
+
|
245 |
+
// Remove this plugin from array
|
246 |
+
$key = array_search(WP_GDPR_C_BASENAME, $activePlugins);
|
247 |
+
if ($key !== false) {
|
248 |
+
unset($activePlugins[$key]);
|
249 |
+
}
|
250 |
+
|
251 |
+
if ($showPluginData) {
|
252 |
+
foreach ($activePlugins as $key => $file) {
|
253 |
+
$pluginData = get_plugin_data(WP_PLUGIN_DIR . '/' . $file);
|
254 |
+
$data = array(
|
255 |
+
'basename' => plugin_basename($file)
|
256 |
+
);
|
257 |
+
if (isset($pluginData['Name'])) {
|
258 |
+
$data['slug'] = sanitize_title($pluginData['Name']);
|
259 |
+
$data['name'] = $pluginData['Name'];
|
260 |
+
}
|
261 |
+
if (isset($pluginData['Description'])) {
|
262 |
+
$data['description'] = $pluginData['Description'];
|
263 |
+
}
|
264 |
+
$activePlugins[$key] = $data;
|
265 |
+
}
|
266 |
+
}
|
267 |
+
|
268 |
+
return $activePlugins;
|
269 |
+
}
|
270 |
+
|
271 |
+
/**
|
272 |
+
* @return array
|
273 |
+
*/
|
274 |
+
public static function getActivatedPlugins() {
|
275 |
+
$output = array();
|
276 |
+
$activePlugins = self::getActivePlugins();
|
277 |
+
// Loop through supported plugins
|
278 |
+
foreach (Integration::getSupportedPlugins() as $plugin) {
|
279 |
+
if (in_array($plugin['file'], $activePlugins)) {
|
280 |
+
if (is_admin()) {
|
281 |
+
$plugin['supported'] = true;
|
282 |
+
if (isset($plugin['supported_version'])) {
|
283 |
+
$pluginData = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin['file']);
|
284 |
+
if (!empty($pluginData['Version']) && $pluginData['Version'] < $plugin['supported_version']) {
|
285 |
+
$plugin['supported'] = false;
|
286 |
+
}
|
287 |
+
}
|
288 |
+
}
|
289 |
+
$output[] = $plugin;
|
290 |
+
}
|
291 |
+
}
|
292 |
+
|
293 |
+
// Loop through supported WordPress functionality
|
294 |
+
foreach (Integration::getSupportedWordPressFunctionality() as $wp) {
|
295 |
+
$wp['supported'] = true;
|
296 |
+
$output[] = $wp;
|
297 |
+
}
|
298 |
+
|
299 |
+
return $output;
|
300 |
+
}
|
301 |
+
|
302 |
+
/**
|
303 |
+
* @return array
|
304 |
+
*/
|
305 |
+
public static function getEnabledPlugins() {
|
306 |
+
$output = array();
|
307 |
+
foreach (self::getActivatedPlugins() as $plugin) {
|
308 |
+
if (self::isEnabled($plugin['id'])) {
|
309 |
+
$output[] = $plugin;
|
310 |
+
}
|
311 |
+
}
|
312 |
+
return $output;
|
313 |
+
}
|
314 |
+
|
315 |
+
/**
|
316 |
+
* @return bool
|
317 |
+
*/
|
318 |
+
public static function hasMailPluginInstalled() {
|
319 |
+
foreach(self::getActivePlugins() as $activePlugin) {
|
320 |
+
if(strpos(strtolower($activePlugin), 'mail') !== false) {
|
321 |
+
return true;
|
322 |
+
}
|
323 |
+
}
|
324 |
+
return false;
|
325 |
+
}
|
326 |
+
|
327 |
+
/**
|
328 |
+
* @param $data
|
329 |
+
* @return string
|
330 |
+
*/
|
331 |
+
public function sanitizeData($data) {
|
332 |
+
if (is_array($data)) {
|
333 |
+
foreach ($data as &$value) {
|
334 |
+
$value = sanitize_text_field($value);
|
335 |
+
}
|
336 |
+
} else {
|
337 |
+
$data = sanitize_text_field($data);
|
338 |
+
}
|
339 |
+
return $data;
|
340 |
+
}
|
341 |
+
|
342 |
+
/**
|
343 |
+
* @param int $timestamp
|
344 |
+
* @return \DateTime
|
345 |
+
*/
|
346 |
+
public static function localDateTime($timestamp = 0) {
|
347 |
+
$gmtOffset = get_option('gmt_offset', '');
|
348 |
+
if ($gmtOffset !== '') {
|
349 |
+
$negative = ($gmtOffset < 0);
|
350 |
+
$gmtOffset = str_replace('-', '', $gmtOffset);
|
351 |
+
$hour = floor($gmtOffset);
|
352 |
+
$minutes = ($gmtOffset - $hour) * 60;
|
353 |
+
if ($negative) {
|
354 |
+
$hour = '-' . $hour;
|
355 |
+
$minutes = '-' . $minutes;
|
356 |
+
}
|
357 |
+
$date = new \DateTime(null, new \DateTimeZone('UTC'));
|
358 |
+
$date->setTimestamp($timestamp);
|
359 |
+
$date->modify($hour . ' hour');
|
360 |
+
$date->modify($minutes . ' minutes');
|
361 |
+
} else {
|
362 |
+
$date = new \DateTime(null, new \DateTimeZone(get_option('timezone_string', 'UTC')));
|
363 |
+
$date->setTimestamp($timestamp);
|
364 |
+
}
|
365 |
+
return new \DateTime($date->format('Y-m-d H:i:s'), new \DateTimeZone('UTC'));
|
366 |
+
}
|
367 |
+
|
368 |
+
/**
|
369 |
+
* @param string $format
|
370 |
+
* @param int $timestamp
|
371 |
+
* @return string
|
372 |
+
*/
|
373 |
+
public static function localDateFormat($format = '', $timestamp = 0) {
|
374 |
+
$date = self::localDateTime($timestamp);
|
375 |
+
return date_i18n($format, $date->getTimestamp(), true);
|
376 |
+
}
|
377 |
+
|
378 |
+
/**
|
379 |
+
* @param string $string
|
380 |
+
* @param int $length
|
381 |
+
* @param string $more
|
382 |
+
* @return string
|
383 |
+
*/
|
384 |
+
public static function shortenStringByWords($string = '', $length = 20, $more = '...') {
|
385 |
+
$words = preg_split("/[\n\r\t ]+/", $string, $length + 1, PREG_SPLIT_NO_EMPTY);
|
386 |
+
if (count($words) > $length) {
|
387 |
+
array_pop($words);
|
388 |
+
$output = implode(' ', $words) . $more;
|
389 |
+
} else {
|
390 |
+
$output = implode(' ', $words);
|
391 |
+
}
|
392 |
+
return $output;
|
393 |
+
}
|
394 |
+
|
395 |
+
/**
|
396 |
+
* Ensures an ip address is both a valid IP and does not fall within
|
397 |
+
* a private network range.
|
398 |
+
*
|
399 |
+
* @param string $ipAddress
|
400 |
+
* @return bool
|
401 |
+
*/
|
402 |
+
public static function validateIpAddress($ipAddress = '') {
|
403 |
+
if (strtolower($ipAddress) === 'unknown') {
|
404 |
+
return false;
|
405 |
+
}
|
406 |
+
// Generate ipv4 network address
|
407 |
+
$ipAddress = ip2long($ipAddress);
|
408 |
+
// If the ip is set and not equivalent to 255.255.255.255
|
409 |
+
if ($ipAddress !== false && $ipAddress !== -1) {
|
410 |
+
/**
|
411 |
+
* Make sure to get unsigned long representation of ip
|
412 |
+
* due to discrepancies between 32 and 64 bit OSes and
|
413 |
+
* signed numbers (ints default to signed in PHP)
|
414 |
+
*/
|
415 |
+
$ipAddress = sprintf('%u', $ipAddress);
|
416 |
+
// Do private network range checking
|
417 |
+
if ($ipAddress >= 0 && $ipAddress <= 50331647) return false;
|
418 |
+
if ($ipAddress >= 167772160 && $ipAddress <= 184549375) return false;
|
419 |
+
if ($ipAddress >= 2130706432 && $ipAddress <= 2147483647) return false;
|
420 |
+
if ($ipAddress >= 2851995648 && $ipAddress <= 2852061183) return false;
|
421 |
+
if ($ipAddress >= 2886729728 && $ipAddress <= 2887778303) return false;
|
422 |
+
if ($ipAddress >= 3221225984 && $ipAddress <= 3221226239) return false;
|
423 |
+
if ($ipAddress >= 3232235520 && $ipAddress <= 3232301055) return false;
|
424 |
+
if ($ipAddress >= 4294967040) return false;
|
425 |
+
}
|
426 |
+
return true;
|
427 |
+
}
|
428 |
+
|
429 |
+
/**
|
430 |
+
* @return string
|
431 |
+
*/
|
432 |
+
public static function getClientIpAddress() {
|
433 |
+
// Check for shared internet/ISP IP
|
434 |
+
if (!empty($_SERVER['HTTP_CLIENT_IP']) && self::validateIpAddress($_SERVER['HTTP_CLIENT_IP'])) {
|
435 |
+
return $_SERVER['HTTP_CLIENT_IP'];
|
436 |
+
}
|
437 |
+
// Check for IPs passing through proxies
|
438 |
+
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
439 |
+
// Check if multiple ips exist in var
|
440 |
+
if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',') !== false) {
|
441 |
+
$listOfIpAddresses = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
|
442 |
+
foreach ($listOfIpAddresses as $ipAddress) {
|
443 |
+
$ipAddress = trim($ipAddress);
|
444 |
+
if (self::validateIpAddress($ipAddress)) {
|
445 |
+
return $ipAddress;
|
446 |
+
}
|
447 |
+
}
|
448 |
+
} else {
|
449 |
+
if (self::validateIpAddress($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
450 |
+
return $_SERVER['HTTP_X_FORWARDED_FOR'];
|
451 |
+
}
|
452 |
+
}
|
453 |
+
}
|
454 |
+
if (!empty($_SERVER['HTTP_X_FORWARDED']) && self::validateIpAddress($_SERVER['HTTP_X_FORWARDED'])) {
|
455 |
+
return $_SERVER['HTTP_X_FORWARDED'];
|
456 |
+
}
|
457 |
+
if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && self::validateIpAddress($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) {
|
458 |
+
return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
|
459 |
+
}
|
460 |
+
if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && self::validateIpAddress($_SERVER['HTTP_FORWARDED_FOR'])) {
|
461 |
+
return $_SERVER['HTTP_FORWARDED_FOR'];
|
462 |
+
}
|
463 |
+
if (!empty($_SERVER['HTTP_FORWARDED']) && self::validateIpAddress($_SERVER['HTTP_FORWARDED'])) {
|
464 |
+
return $_SERVER['HTTP_FORWARDED'];
|
465 |
+
}
|
466 |
+
// Return unreliable ip since all else failed
|
467 |
+
return $_SERVER['REMOTE_ADDR'];
|
468 |
+
}
|
469 |
+
|
470 |
+
/**
|
471 |
+
* @param string $ipAddress
|
472 |
+
* @return bool
|
473 |
+
*/
|
474 |
+
public static function checkIpAddress($ipAddress = '') {
|
475 |
+
return self::getClientIpAddress() === $ipAddress;
|
476 |
+
}
|
477 |
+
|
478 |
+
/**
|
479 |
+
* @param string $type
|
480 |
+
* @param int $siteId
|
481 |
+
* @return string
|
482 |
+
*/
|
483 |
+
public static function getSiteData($type = '', $siteId = 0) {
|
484 |
+
$output = '';
|
485 |
+
if (!empty($type)) {
|
486 |
+
$output = (!empty($siteId) && is_multisite()) ? get_blog_option($siteId, $type) : get_option($type);
|
487 |
+
}
|
488 |
+
return $output;
|
489 |
+
}
|
490 |
+
|
491 |
+
/**
|
492 |
+
* This function returns all available options used by the WPGDPRC plugin.
|
493 |
+
* NOTE: Keep this list updated in case of newly added/updated options.
|
494 |
+
*
|
495 |
+
* @return array
|
496 |
+
*/
|
497 |
+
public static function getAvailableOptions() {
|
498 |
+
$output = array();
|
499 |
+
|
500 |
+
// Settings for activated plugins
|
501 |
+
$activatedPlugins = Helper::getActivatedPlugins();
|
502 |
+
foreach ($activatedPlugins as $plugin) {
|
503 |
+
$output[] = WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'];
|
504 |
+
$output[] = WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_form_text';
|
505 |
+
$output[] = WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_error_message';
|
506 |
+
switch ($plugin['id']) {
|
507 |
+
case 'gravity-forms' :
|
508 |
+
case 'contact-form-7' :
|
509 |
+
$output[] = WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_forms';
|
510 |
+
break;
|
511 |
+
}
|
512 |
+
switch ($plugin['id']) {
|
513 |
+
case 'gravity-forms' :
|
514 |
+
case 'woocommerce' :
|
515 |
+
case 'wordpress' :
|
516 |
+
$output[] = WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_required_message';
|
517 |
+
break;
|
518 |
+
}
|
519 |
+
}
|
520 |
+
|
521 |
+
// Settings for the checklist
|
522 |
+
foreach (Helper::getCheckList() as $id => $check) {
|
523 |
+
$output[] = WP_GDPR_C_PREFIX . '_general_' . $id;
|
524 |
+
}
|
525 |
+
|
526 |
+
// Settings for the general things
|
527 |
+
$output[] = WP_GDPR_C_PREFIX . '_settings_privacy_policy_page';
|
528 |
+
$output[] = WP_GDPR_C_PREFIX . '_settings_privacy_policy_text';
|
529 |
+
$output[] = WP_GDPR_C_PREFIX . '_settings_enable_access_request';
|
530 |
+
if (Helper::isEnabled('enable_access_request', 'settings')) {
|
531 |
+
$output[] = WP_GDPR_C_PREFIX . '_settings_access_request_page';
|
532 |
+
$output[] = WP_GDPR_C_PREFIX . '_settings_access_request_form_checkbox_text';
|
533 |
+
$output[] = WP_GDPR_C_PREFIX . '_settings_delete_request_form_explanation_text';
|
534 |
+
}
|
535 |
+
$output[] = WP_GDPR_C_PREFIX . '_settings_consents_modal_title';
|
536 |
+
$output[] = WP_GDPR_C_PREFIX . '_settings_consents_modal_explanation_text';
|
537 |
+
$output[] = WP_GDPR_C_PREFIX . '_settings_consents_bar_explanation_text';
|
538 |
+
|
539 |
+
return $output;
|
540 |
+
}
|
541 |
+
|
542 |
+
/**
|
543 |
+
* @return bool|\WP_Post
|
544 |
+
*/
|
545 |
+
public static function getAccessRequestPage() {
|
546 |
+
$output = false;
|
547 |
+
$option = get_option(WP_GDPR_C_PREFIX . '_settings_access_request_page', 0);
|
548 |
+
if (!empty($option)) {
|
549 |
+
$output = get_post($option);
|
550 |
+
} else {
|
551 |
+
$page = get_pages(array(
|
552 |
+
'post_type' => 'page',
|
553 |
+
'post_status' => 'publish,private,draft',
|
554 |
+
'number' => 1,
|
555 |
+
'meta_key' => '_wpgdprc_access_request',
|
556 |
+
'meta_value' => '1'
|
557 |
+
));
|
558 |
+
if (!empty($page)) {
|
559 |
+
/** @var \WP_Post $output */
|
560 |
+
$output = $page[0];
|
561 |
+
}
|
562 |
+
}
|
563 |
+
return $output;
|
564 |
+
}
|
565 |
+
|
566 |
+
/**
|
567 |
+
* Function resets the cookie bar for all users, this will happen on button trigger & when new Consent has been added.
|
568 |
+
*/
|
569 |
+
public static function resetCookieBar() {
|
570 |
+
$consentVersion = get_option('wpgdprc_consent_version');
|
571 |
+
$consentVersion += 1;
|
572 |
+
update_option('wpgdprc_consent_version', $consentVersion);
|
573 |
+
|
574 |
+
}
|
575 |
+
|
576 |
+
/**
|
577 |
+
* @return array
|
578 |
+
*/
|
579 |
+
public static function getRequiredConsentIds() {
|
580 |
+
$output = array();
|
581 |
+
$requiredConsents = Consent::getInstance()->getList(array(
|
582 |
+
'required' => array(
|
583 |
+
'value' => 1,
|
584 |
+
),
|
585 |
+
'active' => array(
|
586 |
+
'value' => 1
|
587 |
+
),
|
588 |
+
));
|
589 |
+
if (!empty($requiredConsents)) {
|
590 |
+
foreach ($requiredConsents as $requiredConsent) {
|
591 |
+
$output[] = intval($requiredConsent->getId());
|
592 |
+
}
|
593 |
+
}
|
594 |
+
return $output;
|
595 |
+
}
|
596 |
+
|
597 |
+
/**
|
598 |
+
* @return array|bool
|
599 |
+
*/
|
600 |
+
public static function getConsentIdsByCookie() {
|
601 |
+
$output = array();
|
602 |
+
$requiredConsents = Consent::getInstance()->getList(array(
|
603 |
+
'required' => array(
|
604 |
+
'value' => 1
|
605 |
+
),
|
606 |
+
'active' => array(
|
607 |
+
'value' => 1
|
608 |
+
)
|
609 |
+
));
|
610 |
+
$consentVersion = get_option('wpgdprc_consent_version');
|
611 |
+
$consents = (!empty($_COOKIE['wpgdprc-consent-' . $consentVersion])) ? esc_html($_COOKIE['wpgdprc-consent-' . $consentVersion]) : '';
|
612 |
+
if (!empty($requiredConsents)) {
|
613 |
+
foreach ($requiredConsents as $requiredConsent) {
|
614 |
+
$output[] = intval($requiredConsent->getId());
|
615 |
+
}
|
616 |
+
}
|
617 |
+
if (!empty($consents)) {
|
618 |
+
switch ($consents) {
|
619 |
+
case 'decline' :
|
620 |
+
break;
|
621 |
+
case 'accept' :
|
622 |
+
$consents = Consent::getInstance()->getList(array(
|
623 |
+
'required' => array(
|
624 |
+
'value' => 0
|
625 |
+
),
|
626 |
+
'active' => array(
|
627 |
+
'value' => 1
|
628 |
+
)
|
629 |
+
));
|
630 |
+
foreach ($consents as $consent) {
|
631 |
+
$output[] = intval($consent->getId());
|
632 |
+
}
|
633 |
+
break;
|
634 |
+
default :
|
635 |
+
$consents = explode(',', $consents);
|
636 |
+
foreach ($consents as $id) {
|
637 |
+
if (is_numeric($id) && Consent::getInstance()->exists($id)) {
|
638 |
+
$output[] = intval($id);
|
639 |
+
}
|
640 |
+
}
|
641 |
+
break;
|
642 |
+
}
|
643 |
+
}
|
644 |
+
return $output;
|
645 |
+
}
|
646 |
+
|
647 |
+
public static function createUserRequestDataTables() {
|
648 |
+
global $wpdb;
|
649 |
+
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
650 |
+
$charsetCollate = $wpdb->get_charset_collate();
|
651 |
+
$query = "CREATE TABLE IF NOT EXISTS `" . AccessRequest::getDatabaseTableName() . "` (
|
652 |
+
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
|
653 |
+
`site_id` bigint(20) NOT NULL,
|
654 |
+
`email_address` varchar(100) NOT NULL,
|
655 |
+
`session_id` varchar(255) NOT NULL,
|
656 |
+
`ip_address` varchar(100) NOT NULL,
|
657 |
+
`expired` tinyint(1) DEFAULT '0' NOT NULL,
|
658 |
+
`date_created` datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
|
659 |
+
PRIMARY KEY (`ID`)
|
660 |
+
) $charsetCollate;";
|
661 |
+
dbDelta($query);
|
662 |
+
$query = "CREATE TABLE IF NOT EXISTS `" . DeleteRequest::getDatabaseTableName() . "` (
|
663 |
+
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
|
664 |
+
`site_id` bigint(20) NOT NULL,
|
665 |
+
`access_request_id` bigint(20) NOT NULL,
|
666 |
+
`session_id` varchar(255) NOT NULL,
|
667 |
+
`ip_address` varchar(100) NOT NULL,
|
668 |
+
`data_id` bigint(20) NOT NULL,
|
669 |
+
`type` varchar(255) NOT NULL,
|
670 |
+
`processed` tinyint(1) DEFAULT '0' NOT NULL,
|
671 |
+
`date_created` datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
|
672 |
+
PRIMARY KEY (`ID`)
|
673 |
+
) $charsetCollate;";
|
674 |
+
dbDelta($query);
|
675 |
+
}
|
676 |
+
|
677 |
+
/**
|
678 |
+
* @param array $filters
|
679 |
+
* @param bool $grouped
|
680 |
+
* @return string
|
681 |
+
*/
|
682 |
+
public static function getQueryByFilters($filters = array(), $grouped = false) {
|
683 |
+
$output = '';
|
684 |
+
if (!empty($filters)) {
|
685 |
+
$count = 0;
|
686 |
+
foreach ($filters as $column => $filter) {
|
687 |
+
if (isset($filter['columns'])) {
|
688 |
+
$output .= " AND ( ";
|
689 |
+
$output .= trim(self::getQueryByFilters($filter['columns'], true));
|
690 |
+
$output .= " )";
|
691 |
+
} else {
|
692 |
+
$value = (isset($filter['value'])) ? $filter['value'] : false;
|
693 |
+
if ($value !== false) {
|
694 |
+
$or = (isset($filter['or']) && filter_var($filter['or'], FILTER_VALIDATE_BOOLEAN)) ? 'OR' : 'AND';
|
695 |
+
$or = ($grouped === true && $count === 0) ? '' : $or;
|
696 |
+
$compare = (isset($filter['compare'])) ? $filter['compare'] : '=';
|
697 |
+
$wildcard = (isset($filter['wildcard']) && filter_var($filter['wildcard'], FILTER_VALIDATE_BOOLEAN)) ? '%' : '';
|
698 |
+
if (($compare === 'IN' || $compare === 'NOT IN') && is_array($value)) {
|
699 |
+
$in = '';
|
700 |
+
foreach ($value as $key => $data) {
|
701 |
+
$in .= ($key !== 0) ? ', ' : '';
|
702 |
+
$in .= (is_numeric($data)) ? $data : "'" . $data . "'";
|
703 |
+
}
|
704 |
+
$value = '(' . $in . ')';
|
705 |
+
$output .= " $or `$column` $compare $wildcard$value$wildcard";
|
706 |
+
} else {
|
707 |
+
$output .= " $or `$column` $compare '$wildcard$value$wildcard'";
|
708 |
+
}
|
709 |
+
}
|
710 |
+
}
|
711 |
+
$count++;
|
712 |
+
}
|
713 |
+
}
|
714 |
+
return $output;
|
715 |
+
}
|
716 |
+
|
717 |
+
/**
|
718 |
+
* @param $email
|
719 |
+
*
|
720 |
+
* @return null|string
|
721 |
+
*/
|
722 |
+
public static function anonymizeEmail($email) {
|
723 |
+
|
724 |
+
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
725 |
+
|
726 |
+
$emailParts = explode('@', $email);
|
727 |
+
$localPart = $emailParts[0];
|
728 |
+
if (strlen($localPart) > 1 && strlen($localPart) < 4) {
|
729 |
+
$localPart = substr_replace($localPart, '*', strlen($localPart) - 1);
|
730 |
+
} else if (strlen($localPart) > 3 && strlen($localPart) < 6) {
|
731 |
+
$localPart = substr_replace($localPart, '**', strlen($localPart) - 2);
|
732 |
+
} else if (strlen($localPart) > 5) {
|
733 |
+
$localPart = substr_replace($localPart, '***', strlen($localPart) - 3);
|
734 |
+
} else {
|
735 |
+
$domain = $emailParts[1];
|
736 |
+
$domainName = explode('.', $domain);
|
737 |
+
$anonymisedDomain = str_replace($domainName[0], '***', $domainName[0]);
|
738 |
+
}
|
739 |
+
|
740 |
+
if (isset($domainName) && isset($anonymisedDomain)) {
|
741 |
+
return $localPart . '@' . $anonymisedDomain . '.' . $domainName[1];
|
742 |
+
} else {
|
743 |
+
return $localPart . '@' . $emailParts[1];
|
744 |
+
}
|
745 |
+
} else {
|
746 |
+
return NULL;
|
747 |
+
}
|
748 |
+
|
749 |
+
}
|
750 |
+
|
751 |
+
/**
|
752 |
+
* @param $ip
|
753 |
+
*
|
754 |
+
* @return null|string
|
755 |
+
*/
|
756 |
+
public static function anonymizeIP($ip) {
|
757 |
+
|
758 |
+
if (filter_var($ip, FILTER_VALIDATE_IP)) {
|
759 |
+
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
|
760 |
+
$lastDot = strrpos($ip, '.') + 1;
|
761 |
+
return substr($ip, 0, $lastDot)
|
762 |
+
. str_repeat('*', strlen($ip) - $lastDot);
|
763 |
+
} else if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
|
764 |
+
$lastColon = strrpos($ip, ':') + 1;
|
765 |
+
return substr($ip, 0, $lastColon)
|
766 |
+
. str_repeat('*', strlen($ip) - $lastColon);
|
767 |
+
} else {
|
768 |
+
return NULL;
|
769 |
+
}
|
770 |
+
} else {
|
771 |
+
return NULL;
|
772 |
+
}
|
773 |
+
}
|
774 |
+
|
775 |
+
/**
|
776 |
+
* @return null|Helper
|
777 |
+
*/
|
778 |
+
public static function getInstance() {
|
779 |
+
if (!isset(self::$instance)) {
|
780 |
+
self::$instance = new self();
|
781 |
+
}
|
782 |
+
return self::$instance;
|
783 |
+
}
|
784 |
}
|
Includes/Integration.php
CHANGED
@@ -1,440 +1,440 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WPGDPRC\Includes;
|
4 |
-
|
5 |
-
use WPGDPRC\Includes\Extensions\CF7;
|
6 |
-
use WPGDPRC\Includes\Extensions\GForms;
|
7 |
-
use WPGDPRC\Includes\Extensions\WC;
|
8 |
-
use WPGDPRC\Includes\Extensions\WP;
|
9 |
-
use WPGDPRC\Includes\Extensions\WPRegistration;
|
10 |
-
|
11 |
-
/**
|
12 |
-
* Class Integration
|
13 |
-
* @package WPGDPRC\Includes
|
14 |
-
*/
|
15 |
-
class Integration {
|
16 |
-
/** @var null */
|
17 |
-
private static $instance = null;
|
18 |
-
|
19 |
-
/**
|
20 |
-
* Integration constructor.
|
21 |
-
*/
|
22 |
-
public function __construct() {
|
23 |
-
add_action('admin_init', array($this, 'registerSettings'));
|
24 |
-
foreach (Helper::getEnabledPlugins() as $plugin) {
|
25 |
-
switch ($plugin['id']) {
|
26 |
-
case WP::ID :
|
27 |
-
if (current_user_can('administrator')) {
|
28 |
-
add_filter('comment_form_submit_field', array(WP::getInstance(), 'addFieldForAdmin'), 999);
|
29 |
-
} else {
|
30 |
-
add_filter('comment_form_submit_field', array(WP::getInstance(), 'addField'), 999);
|
31 |
-
}
|
32 |
-
add_action('pre_comment_on_post', array(WP::getInstance(), 'checkPost'));
|
33 |
-
add_action('comment_post', array(WP::getInstance(), 'addAcceptedDateToCommentMeta'));
|
34 |
-
add_filter('manage_edit-comments_columns', array(WP::getInstance(), 'displayAcceptedDateColumnInCommentOverview'));
|
35 |
-
add_action('manage_comments_custom_column', array(WP::getInstance(), 'displayAcceptedDateInCommentOverview'), 10, 2);
|
36 |
-
break;
|
37 |
-
case CF7::ID :
|
38 |
-
add_action('update_option_' . WP_GDPR_C_PREFIX . '_integrations_' . CF7::ID . '_forms', array(CF7::getInstance(), 'processIntegration'));
|
39 |
-
add_action('update_option_' . WP_GDPR_C_PREFIX . '_integrations_' . CF7::ID . '_form_text', array(CF7::getInstance(), 'processIntegration'));
|
40 |
-
add_action('update_option_' . WP_GDPR_C_PREFIX . '_integrations_' . CF7::ID . '_error_message', array(CF7::getInstance(), 'processIntegration'));
|
41 |
-
add_action('wpcf7_init', array(CF7::getInstance(), 'addFormTagSupport'));
|
42 |
-
add_filter('wpcf7_before_send_mail', array(CF7::getInstance(), 'changeMailBodyOutput'), 999);
|
43 |
-
add_filter('wpcf7_validate_wpgdprc', array(CF7::getInstance(), 'validateField'), 10, 2);
|
44 |
-
break;
|
45 |
-
case WPRegistration::ID :
|
46 |
-
$users_can_register = get_option('users_can_register');
|
47 |
-
if ($users_can_register) {
|
48 |
-
add_action('register_form', array(WPRegistration::getInstance(), 'addField'), 999);
|
49 |
-
add_filter('registration_errors', array(WPRegistration::getInstance(), 'validateGDPRCheckbox'), 10, 3);
|
50 |
-
add_action('user_register', array(WPRegistration::getInstance(), 'logGivenGDPRConsent'), 10, 1);
|
51 |
-
}
|
52 |
-
break;
|
53 |
-
case WC::ID :
|
54 |
-
add_action('woocommerce_checkout_process', array(WC::getInstance(), 'checkPostCheckoutForm'));
|
55 |
-
add_action('woocommerce_register_post', array(WC::getInstance(), 'checkPostRegisterForm'), 10, 3);
|
56 |
-
add_action('woocommerce_review_order_before_submit', array(WC::getInstance(), 'addField'), 999);
|
57 |
-
add_action('woocommerce_register_form', array(WC::getInstance(), 'addField'), 999);
|
58 |
-
add_action('woocommerce_checkout_update_order_meta', array(WC::getInstance(), 'addAcceptedDateToOrderMeta'));
|
59 |
-
add_action('woocommerce_admin_order_data_after_order_details', array(WC::getInstance(), 'displayAcceptedDateInOrderData'));
|
60 |
-
add_filter('manage_edit-shop_order_columns', array(WC::getInstance(), 'displayAcceptedDateColumnInOrderOverview'));
|
61 |
-
add_action('manage_shop_order_posts_custom_column', array(WC::getInstance(), 'displayAcceptedDateInOrderOverview'), 10, 2);
|
62 |
-
break;
|
63 |
-
case GForms::ID :
|
64 |
-
add_action('update_option_' . WP_GDPR_C_PREFIX . '_integrations_' . GForms::ID . '_forms', array(GForms::getInstance(), 'processIntegration'));
|
65 |
-
add_action('update_option_' . WP_GDPR_C_PREFIX . '_integrations_' . GForms::ID . '_form_text', array(GForms::getInstance(), 'processIntegration'));
|
66 |
-
add_action('update_option_' . WP_GDPR_C_PREFIX . '_integrations_' . GForms::ID . '_error_message', array(GForms::getInstance(), 'processIntegration'));
|
67 |
-
add_filter('gform_entries_field_value', array(GForms::getInstance(), 'displayAcceptedDateInEntryOverview'), 10, 4);
|
68 |
-
add_filter('gform_get_field_value', array(GForms::getInstance(), 'displayAcceptedDateInEntry'), 10, 2);
|
69 |
-
foreach (GForms::getInstance()->getEnabledForms() as $formId) {
|
70 |
-
add_filter('gform_entry_list_columns_' . $formId, array(GForms::getInstance(), 'displayAcceptedDateColumnInEntryOverview'), 10, 2);
|
71 |
-
add_filter('gform_save_field_value_' . $formId, array(GForms::getInstance(), 'addAcceptedDateToEntry'), 10, 3);
|
72 |
-
add_action('gform_validation_' . $formId, array(GForms::getInstance(), 'overwriteValidationMessage'));
|
73 |
-
}
|
74 |
-
break;
|
75 |
-
}
|
76 |
-
}
|
77 |
-
}
|
78 |
-
|
79 |
-
public function registerSettings() {
|
80 |
-
foreach (self::getSupportedIntegrations() as $plugin) {
|
81 |
-
register_setting(WP_GDPR_C_SLUG . '_integrations', WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'], 'intval');
|
82 |
-
switch ($plugin['id']) {
|
83 |
-
case CF7::ID :
|
84 |
-
add_action('update_option_' . WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'], array(CF7::getInstance(), 'processIntegration'));
|
85 |
-
register_setting(WP_GDPR_C_SLUG . '_integrations', WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_forms');
|
86 |
-
register_setting(WP_GDPR_C_SLUG . '_integrations', WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_form_text', array('sanitize_callback' => array(Helper::getInstance(), 'sanitizeData')));
|
87 |
-
register_setting(WP_GDPR_C_SLUG . '_integrations', WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_error_message', array('sanitize_callback' => array(Helper::getInstance(), 'sanitizeData')));
|
88 |
-
break;
|
89 |
-
case GForms::ID :
|
90 |
-
add_action('update_option_' . WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'], array(GForms::getInstance(), 'processIntegration'));
|
91 |
-
register_setting(WP_GDPR_C_SLUG . '_integrations', WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_forms');
|
92 |
-
register_setting(WP_GDPR_C_SLUG . '_integrations', WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_form_text');
|
93 |
-
register_setting(WP_GDPR_C_SLUG . '_integrations', WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_error_message');
|
94 |
-
register_setting(WP_GDPR_C_SLUG . '_integrations', WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_required_message');
|
95 |
-
break;
|
96 |
-
default :
|
97 |
-
register_setting(WP_GDPR_C_SLUG . '_integrations', WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_text');
|
98 |
-
register_setting(WP_GDPR_C_SLUG . '_integrations', WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_error_message');
|
99 |
-
register_setting(WP_GDPR_C_SLUG . '_integrations', WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_required_message');
|
100 |
-
break;
|
101 |
-
}
|
102 |
-
}
|
103 |
-
}
|
104 |
-
|
105 |
-
/**
|
106 |
-
* @param string $plugin
|
107 |
-
* @return string
|
108 |
-
*/
|
109 |
-
public static function getSupportedPluginOptions($plugin = '') {
|
110 |
-
$output = '';
|
111 |
-
switch ($plugin) {
|
112 |
-
case CF7::ID :
|
113 |
-
$forms = CF7::getInstance()->getForms();
|
114 |
-
if (!empty($forms)) {
|
115 |
-
$optionNameForms = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_forms';
|
116 |
-
$optionNameFormText = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_form_text';
|
117 |
-
$optionNameErrorMessage = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_error_message';
|
118 |
-
$enabledForms = CF7::getInstance()->getEnabledForms();
|
119 |
-
$output .= '<ul class="wpgdprc-checklist-options">';
|
120 |
-
foreach ($forms as $form) {
|
121 |
-
$formSettingId = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_form_' . $form;
|
122 |
-
$textSettingId = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_form_text_' . $form;
|
123 |
-
$errorSettingId = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_error_message_' . $form;
|
124 |
-
$enabled = in_array($form, $enabledForms);
|
125 |
-
$text = CF7::getInstance()->getCheckboxText($form, false);
|
126 |
-
$errorMessage = CF7::getInstance()->getErrorMessage($form);
|
127 |
-
$output .= '<li class="wpgdprc-clearfix">';
|
128 |
-
$output .= '<div class="wpgdprc-checkbox">';
|
129 |
-
$output .= '<input type="checkbox" name="' . $optionNameForms . '[]" id="' . $formSettingId . '" value="' . $form . '" tabindex="1" data-option="' . $optionNameForms . '" data-append="1" ' . checked(true, $enabled, false) . ' />';
|
130 |
-
$output .= '<label for="' . $formSettingId . '"><strong>' . sprintf(__('Form: %s', WP_GDPR_C_SLUG), get_the_title($form)) . '</strong></label>';
|
131 |
-
$output .= '<span class="wpgdprc-instructions">' . __('Activate for this form:', WP_GDPR_C_SLUG) . '</span>';
|
132 |
-
$output .= '</div>';
|
133 |
-
$output .= '<div class="wpgdprc-setting">';
|
134 |
-
$output .= '<label for="' . $textSettingId . '">' . __('Checkbox text', WP_GDPR_C_SLUG) . '</label>';
|
135 |
-
$output .= '<div class="wpgdprc-options">';
|
136 |
-
$output .= '<textarea name="' . $optionNameFormText . '[' . $form . ']' . '" class="regular-text" id="' . $textSettingId . '" placeholder="' . $text . '">' . $text . '</textarea>';
|
137 |
-
$output .= '</div>';
|
138 |
-
$output .= '</div>';
|
139 |
-
$output .= '<div class="wpgdprc-setting">';
|
140 |
-
$output .= '<label for="' . $errorSettingId . '">' . __('Error message', WP_GDPR_C_SLUG) . '</label>';
|
141 |
-
$output .= '<div class="wpgdprc-options">';
|
142 |
-
$output .= '<input type="text" name="' . $optionNameErrorMessage . '[' . $form . ']' . '" class="regular-text" id="' . $errorSettingId . '" placeholder="' . $errorMessage . '" value="' . $errorMessage . '" />';
|
143 |
-
$output .= '</div>';
|
144 |
-
$output .= '</div>';
|
145 |
-
$output .= Helper::getAllowedHTMLTagsOutput($plugin);
|
146 |
-
$output .= '</li>';
|
147 |
-
}
|
148 |
-
$output .= '</ul>';
|
149 |
-
} else {
|
150 |
-
$output = '<p>' . __('No forms found.', WP_GDPR_C_SLUG) . '</p>';
|
151 |
-
}
|
152 |
-
break;
|
153 |
-
case GForms::ID :
|
154 |
-
$forms = GForms::getInstance()->getForms();
|
155 |
-
if (!empty($forms)) {
|
156 |
-
$optionNameForms = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_forms';
|
157 |
-
$optionNameFormText = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_form_text';
|
158 |
-
$optionNameErrorMessage = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_error_message';
|
159 |
-
$optionNameRequiredMessage = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_required_message';
|
160 |
-
$enabledForms = GForms::getInstance()->getEnabledForms();
|
161 |
-
$output .= '<ul class="wpgdprc-checklist-options">';
|
162 |
-
foreach ($forms as $form) {
|
163 |
-
$formSettingId = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_form_' . $form['id'];
|
164 |
-
$textSettingId = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_form_text_' . $form['id'];
|
165 |
-
$errorSettingId = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_error_message_' . $form['id'];
|
166 |
-
$requiredSettingId = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_required_message_' . $form['id'];
|
167 |
-
$enabled = in_array($form['id'], $enabledForms);
|
168 |
-
$text = esc_html(GForms::getInstance()->getCheckboxText($form['id'], false));
|
169 |
-
$errorMessage = esc_html(GForms::getInstance()->getErrorMessage($form['id']));
|
170 |
-
$requiredMessage = esc_html(GForms::getInstance()->getRequiredMessage($form['id']));
|
171 |
-
$output .= '<li class="wpgdprc-clearfix">';
|
172 |
-
$output .= '<div class="wpgdprc-checkbox">';
|
173 |
-
$output .= '<input type="checkbox" name="' . $optionNameForms . '[]" id="' . $formSettingId . '" value="' . $form['id'] . '" tabindex="1" data-option="' . $optionNameForms . '" data-append="1" ' . checked(true, $enabled, false) . ' />';
|
174 |
-
$output .= '<label for="' . $formSettingId . '"><strong>' . sprintf(__('Form: %s', WP_GDPR_C_SLUG), $form['title']) . '</strong></label>';
|
175 |
-
$output .= '<span class="wpgdprc-instructions">' . __('Activate for this form:', WP_GDPR_C_SLUG) . '</span>';
|
176 |
-
$output .= '</div>';
|
177 |
-
$output .= '<div class="wpgdprc-setting">';
|
178 |
-
$output .= '<label for="' . $textSettingId . '">' . __('Checkbox text', WP_GDPR_C_SLUG) . '</label>';
|
179 |
-
$output .= '<div class="wpgdprc-options">';
|
180 |
-
$output .= '<textarea name="' . $optionNameFormText . '[' . $form['id'] . ']' . '" class="regular-text" id="' . $textSettingId . '" placeholder="' . $text . '">' . $text . '</textarea>';
|
181 |
-
$output .= '</div>';
|
182 |
-
$output .= '</div>';
|
183 |
-
$output .= '<div class="wpgdprc-setting">';
|
184 |
-
$output .= '<label for="' . $errorSettingId . '">' . __('Error message', WP_GDPR_C_SLUG) . '</label>';
|
185 |
-
$output .= '<div class="wpgdprc-options">';
|
186 |
-
$output .= '<input type="text" name="' . $optionNameErrorMessage . '[' . $form['id'] . ']' . '" class="regular-text" id="' . $errorSettingId . '" placeholder="' . $errorMessage . '" value="' . $errorMessage . '" />';
|
187 |
-
$output .= '</div>';
|
188 |
-
$output .= '</div>';
|
189 |
-
$output .= '<div class="wpgdprc-setting">';
|
190 |
-
$output .= '<label for="' . $requiredSettingId . '">' . __('Required message', WP_GDPR_C_SLUG) . '</label>';
|
191 |
-
$output .= '<div class="wpgdprc-options">';
|
192 |
-
$output .= '<input type="text" name="' . $optionNameRequiredMessage . '[' . $form['id'] . ']' . '" class="regular-text" id="' . $requiredSettingId . '" placeholder="' . $requiredMessage . '" value="' . $requiredMessage . '" />';
|
193 |
-
$output .= '</div>';
|
194 |
-
$output .= '</div>';
|
195 |
-
$output .= Helper::getAllowedHTMLTagsOutput($plugin);
|
196 |
-
$output .= '</li>';
|
197 |
-
}
|
198 |
-
$output .= '</ul>';
|
199 |
-
} else {
|
200 |
-
$output = '<p>' . __('No forms found.', WP_GDPR_C_SLUG) . '</p>';
|
201 |
-
}
|
202 |
-
break;
|
203 |
-
default :
|
204 |
-
$optionNameText = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_text';
|
205 |
-
$optionNameErrorMessage = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_error_message';
|
206 |
-
$text = esc_html(self::getCheckboxText($plugin, false));
|
207 |
-
$errorMessage = esc_html(self::getErrorMessage($plugin));
|
208 |
-
$optionNameRequiredMessage = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_required_message';
|
209 |
-
$requiredMessage = esc_html(self::getRequiredMessage($plugin));
|
210 |
-
$output .= '<ul class="wpgdprc-checklist-options">';
|
211 |
-
$output .= '<li class="wpgdprc-clearfix">';
|
212 |
-
$output .= '<div class="wpgdprc-setting">';
|
213 |
-
$output .= '<label for="' . $optionNameText . '">' . __('Checkbox text', WP_GDPR_C_SLUG) . '</label>';
|
214 |
-
$output .= '<div class="wpgdprc-options">';
|
215 |
-
$output .= '<textarea name="' . $optionNameText . '" class="regular-text" id="' . $optionNameText . '" placeholder="' . $text . '">' . $text . '</textarea>';
|
216 |
-
$output .= '</div>';
|
217 |
-
$output .= '</div>';
|
218 |
-
$output .= '<div class="wpgdprc-setting">';
|
219 |
-
$output .= '<label for="' . $optionNameErrorMessage . '">' . __('Error message', WP_GDPR_C_SLUG) . '</label>';
|
220 |
-
$output .= '<div class="wpgdprc-options">';
|
221 |
-
$output .= '<input type="text" name="' . $optionNameErrorMessage . '" class="regular-text" id="' . $optionNameErrorMessage . '" placeholder="' . $errorMessage . '" value="' . $errorMessage . '" />';
|
222 |
-
$output .= '</div>';
|
223 |
-
$output .= '</div>';
|
224 |
-
$output .= '<div class="wpgdprc-setting">';
|
225 |
-
$output .= '<label for="' . $optionNameRequiredMessage . '">' . __('Required message', WP_GDPR_C_SLUG) . '</label>';
|
226 |
-
$output .= '<div class="wpgdprc-options">';
|
227 |
-
$output .= '<input type="text" name="' . $optionNameRequiredMessage . '" class="regular-text" id="' . $optionNameRequiredMessage . '" placeholder="' . $requiredMessage . '" value="' . $requiredMessage . '" />';
|
228 |
-
$output .= '</div>';
|
229 |
-
$output .= '</div>';
|
230 |
-
$output .= Helper::getAllowedHTMLTagsOutput($plugin);
|
231 |
-
$output .= '</li>';
|
232 |
-
$output .= '</ul>';
|
233 |
-
break;
|
234 |
-
}
|
235 |
-
return $output;
|
236 |
-
}
|
237 |
-
|
238 |
-
/**
|
239 |
-
* @param string $plugin
|
240 |
-
* @param bool $insertPrivacyPolicyLink
|
241 |
-
* @return string
|
242 |
-
*/
|
243 |
-
public static function getCheckboxText($plugin = '', $insertPrivacyPolicyLink = true) {
|
244 |
-
$output = '';
|
245 |
-
if (!empty($plugin)) {
|
246 |
-
$output = get_option(WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_text');
|
247 |
-
$output = ($insertPrivacyPolicyLink === true) ? self::insertPrivacyPolicyLink($output) : $output;
|
248 |
-
$output = apply_filters('wpgdprc_' . $plugin . '_checkbox_text', $output);
|
249 |
-
}
|
250 |
-
if (empty($output)) {
|
251 |
-
$output = __('By using this form you agree with the storage and handling of your data by this website.', WP_GDPR_C_SLUG);
|
252 |
-
}
|
253 |
-
$output = wp_kses($output, Helper::getAllowedHTMLTags($plugin));
|
254 |
-
return apply_filters('wpgdprc_checkbox_text', $output);
|
255 |
-
}
|
256 |
-
|
257 |
-
/**
|
258 |
-
* @param string $plugin
|
259 |
-
* @return mixed
|
260 |
-
*/
|
261 |
-
public static function getErrorMessage($plugin = '') {
|
262 |
-
$output = '';
|
263 |
-
if (!empty($plugin)) {
|
264 |
-
$output = get_option(WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_error_message');
|
265 |
-
$output = apply_filters('wpgdprc_' . $plugin . '_error_message', $output);
|
266 |
-
}
|
267 |
-
if (empty($output)) {
|
268 |
-
$output = __('Please accept the privacy checkbox.', WP_GDPR_C_SLUG);
|
269 |
-
}
|
270 |
-
return apply_filters('wpgdprc_error_message', wp_kses($output, Helper::getAllowedHTMLTags($plugin)));
|
271 |
-
}
|
272 |
-
|
273 |
-
/**
|
274 |
-
* @param string $plugin
|
275 |
-
* @return mixed
|
276 |
-
*/
|
277 |
-
public static function getRequiredMessage($plugin = '') {
|
278 |
-
$output = '';
|
279 |
-
if (!empty($plugin)) {
|
280 |
-
$output = get_option(WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_required_message');
|
281 |
-
$output = apply_filters('wpgdprc_' . $plugin . '_required_message', $output);
|
282 |
-
}
|
283 |
-
if (empty($output)) {
|
284 |
-
$output = __('You need to accept this checkbox.', WP_GDPR_C_SLUG);
|
285 |
-
}
|
286 |
-
return apply_filters('wpgdprc_required_message', esc_attr($output));
|
287 |
-
}
|
288 |
-
|
289 |
-
/**
|
290 |
-
* @return mixed
|
291 |
-
*/
|
292 |
-
public static function getPrivacyPolicyText() {
|
293 |
-
$output = get_option(WP_GDPR_C_PREFIX . '_settings_privacy_policy_text');
|
294 |
-
if (empty($output)) {
|
295 |
-
$output = __('Privacy Policy', WP_GDPR_C_SLUG);
|
296 |
-
}
|
297 |
-
return apply_filters('wpgdprc_privacy_policy_text', $output);
|
298 |
-
}
|
299 |
-
|
300 |
-
public static function getPrivacyPolicyLink() {
|
301 |
-
$output = get_option(WP_GDPR_C_PREFIX . '_settings_privacy_policy_link');
|
302 |
-
if (empty($output)) {
|
303 |
-
$output = __('http://www.example.com', WP_GDPR_C_SLUG);
|
304 |
-
}
|
305 |
-
return apply_filters('wpgdprc_privacy_policy_link', $output);
|
306 |
-
}
|
307 |
-
|
308 |
-
/**
|
309 |
-
* @param bool $insertPrivacyPolicyLink
|
310 |
-
* @return mixed
|
311 |
-
*/
|
312 |
-
public static function getAccessRequestFormCheckboxText($insertPrivacyPolicyLink = true) {
|
313 |
-
$output = get_option(WP_GDPR_C_PREFIX . '_settings_access_request_form_checkbox_text');
|
314 |
-
if (empty($output)) {
|
315 |
-
$output = __('By using this form you agree with the storage and handling of your data by this website.', WP_GDPR_C_SLUG);
|
316 |
-
}
|
317 |
-
$output = ($insertPrivacyPolicyLink === true) ? self::insertPrivacyPolicyLink($output) : $output;
|
318 |
-
return apply_filters('wpgdprc_access_request_form_checkbox_text', wp_kses($output, Helper::getAllowedHTMLTags()));
|
319 |
-
}
|
320 |
-
|
321 |
-
/**
|
322 |
-
* @param bool $insertPrivacyPolicyLink
|
323 |
-
* @return mixed
|
324 |
-
*/
|
325 |
-
public static function getDeleteRequestFormExplanationText($insertPrivacyPolicyLink = true) {
|
326 |
-
$output = get_option(WP_GDPR_C_PREFIX . '_settings_delete_request_form_explanation_text');
|
327 |
-
if (empty($output)) {
|
328 |
-
$output = sprintf(
|
329 |
-
__('Below we show you all of the data stored by %s on %s. Select the data you wish the site owner to anonymise so it cannot be linked to your email address any longer. It is the site\'s owner responsibility to act upon your request. When your data is anonymised you will receive an email confirmation.', WP_GDPR_C_SLUG),
|
330 |
-
get_option('blogname'),
|
331 |
-
get_option('siteurl')
|
332 |
-
);
|
333 |
-
}
|
334 |
-
$output = ($insertPrivacyPolicyLink === true) ? self::insertPrivacyPolicyLink($output) : $output;
|
335 |
-
return apply_filters('wpgdprc_delete_request_form_explanation_text', wp_kses($output, Helper::getAllowedHTMLTags()));
|
336 |
-
}
|
337 |
-
|
338 |
-
/**
|
339 |
-
* @param string $content
|
340 |
-
* @return mixed|string
|
341 |
-
*/
|
342 |
-
public static function insertPrivacyPolicyLink($content = '') {
|
343 |
-
if (!Helper::isEnabled('enable_privacy_policy_extern', 'settings')) {
|
344 |
-
$page = get_option(WP_GDPR_C_PREFIX . '_settings_privacy_policy_page');
|
345 |
-
} else {
|
346 |
-
$url = get_option(WP_GDPR_C_PREFIX . '_settings_privacy_policy_link');
|
347 |
-
}
|
348 |
-
$text = Integration::getPrivacyPolicyText();
|
349 |
-
if ((!empty($page) || !empty($url)) && !empty($text)) {
|
350 |
-
$link = apply_filters(
|
351 |
-
'wpgdprc_privacy_policy_link',
|
352 |
-
sprintf(
|
353 |
-
'<a target="_blank" href="%s" rel="noopener noreferrer">%s</a>',
|
354 |
-
(Helper::isEnabled('enable_privacy_policy_extern', 'settings')) ? $url : get_page_link($page),
|
355 |
-
esc_html($text)
|
356 |
-
),
|
357 |
-
(Helper::isEnabled('enable_privacy_policy_extern', 'settings')) ? $url : $page,
|
358 |
-
$text
|
359 |
-
);
|
360 |
-
$content = str_replace('%privacy_policy%', $link, $content);
|
361 |
-
}
|
362 |
-
return $content;
|
363 |
-
}
|
364 |
-
|
365 |
-
/**
|
366 |
-
* @return array
|
367 |
-
*/
|
368 |
-
public static function getSupportedWordPressFunctionality() {
|
369 |
-
return array(
|
370 |
-
array(
|
371 |
-
'id' => 'wordpress',
|
372 |
-
'name' => __('WordPress Comments', WP_GDPR_C_SLUG),
|
373 |
-
'description' => __('When activated the GDPR checkbox will be added automatically just above the submit button.', WP_GDPR_C_SLUG),
|
374 |
-
),
|
375 |
-
array(
|
376 |
-
'id' => WPRegistration::ID,
|
377 |
-
'name' => __('Wordpress Registration', WP_GDPR_C_SLUG),
|
378 |
-
'description' => __('When activated the GDPR checkbox will be added automatically just above the register button.', WP_GDPR_C_SLUG),
|
379 |
-
)
|
380 |
-
);
|
381 |
-
}
|
382 |
-
|
383 |
-
/**
|
384 |
-
* @return array
|
385 |
-
*/
|
386 |
-
public static function getSupportedPlugins() {
|
387 |
-
return array(
|
388 |
-
array(
|
389 |
-
'id' => CF7::ID,
|
390 |
-
'supported_version' => CF7::SUPPORTED_VERSION,
|
391 |
-
'file' => 'contact-form-7/wp-contact-form-7.php',
|
392 |
-
'name' => __('Contact Form 7', WP_GDPR_C_SLUG),
|
393 |
-
'description' => __('A GDPR form tag will be automatically added to every form you activate.', WP_GDPR_C_SLUG),
|
394 |
-
),
|
395 |
-
array(
|
396 |
-
'id' => GForms::ID,
|
397 |
-
'supported_version' => GForms::SUPPORTED_VERSION,
|
398 |
-
'file' => 'gravityforms/gravityforms.php',
|
399 |
-
'name' => __('Gravity Forms', WP_GDPR_C_SLUG),
|
400 |
-
'description' => __('A GDPR form tag will be automatically added to every form you activate.', WP_GDPR_C_SLUG),
|
401 |
-
),
|
402 |
-
array(
|
403 |
-
'id' => WC::ID,
|
404 |
-
'supported_version' => WC::SUPPORTED_VERSION,
|
405 |
-
'file' => 'woocommerce/woocommerce.php',
|
406 |
-
'name' => __('WooCommerce', WP_GDPR_C_SLUG),
|
407 |
-
'description' => __('The GDPR checkbox will be added automatically at the end of your checkout page.', WP_GDPR_C_SLUG),
|
408 |
-
)
|
409 |
-
);
|
410 |
-
}
|
411 |
-
|
412 |
-
/**
|
413 |
-
* @return array
|
414 |
-
*/
|
415 |
-
public static function getSupportedIntegrations() {
|
416 |
-
return array_merge(self::getSupportedPlugins(), self::getSupportedWordPressFunctionality());
|
417 |
-
}
|
418 |
-
|
419 |
-
/**
|
420 |
-
* @return array
|
421 |
-
*/
|
422 |
-
public static function getSupportedIntegrationsLabels() {
|
423 |
-
$output = array();
|
424 |
-
$supportedIntegrations = self::getSupportedIntegrations();
|
425 |
-
foreach ($supportedIntegrations as $supportedIntegration) {
|
426 |
-
$output[] = $supportedIntegration['name'];
|
427 |
-
}
|
428 |
-
return $output;
|
429 |
-
}
|
430 |
-
|
431 |
-
/**
|
432 |
-
* @return null|Integration
|
433 |
-
*/
|
434 |
-
public static function getInstance() {
|
435 |
-
if (!isset(self::$instance)) {
|
436 |
-
self::$instance = new self();
|
437 |
-
}
|
438 |
-
return self::$instance;
|
439 |
-
}
|
440 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WPGDPRC\Includes;
|
4 |
+
|
5 |
+
use WPGDPRC\Includes\Extensions\CF7;
|
6 |
+
use WPGDPRC\Includes\Extensions\GForms;
|
7 |
+
use WPGDPRC\Includes\Extensions\WC;
|
8 |
+
use WPGDPRC\Includes\Extensions\WP;
|
9 |
+
use WPGDPRC\Includes\Extensions\WPRegistration;
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Class Integration
|
13 |
+
* @package WPGDPRC\Includes
|
14 |
+
*/
|
15 |
+
class Integration {
|
16 |
+
/** @var null */
|
17 |
+
private static $instance = null;
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Integration constructor.
|
21 |
+
*/
|
22 |
+
public function __construct() {
|
23 |
+
add_action('admin_init', array($this, 'registerSettings'));
|
24 |
+
foreach (Helper::getEnabledPlugins() as $plugin) {
|
25 |
+
switch ($plugin['id']) {
|
26 |
+
case WP::ID :
|
27 |
+
if (current_user_can('administrator')) {
|
28 |
+
add_filter('comment_form_submit_field', array(WP::getInstance(), 'addFieldForAdmin'), 999);
|
29 |
+
} else {
|
30 |
+
add_filter('comment_form_submit_field', array(WP::getInstance(), 'addField'), 999);
|
31 |
+
}
|
32 |
+
add_action('pre_comment_on_post', array(WP::getInstance(), 'checkPost'));
|
33 |
+
add_action('comment_post', array(WP::getInstance(), 'addAcceptedDateToCommentMeta'));
|
34 |
+
add_filter('manage_edit-comments_columns', array(WP::getInstance(), 'displayAcceptedDateColumnInCommentOverview'));
|
35 |
+
add_action('manage_comments_custom_column', array(WP::getInstance(), 'displayAcceptedDateInCommentOverview'), 10, 2);
|
36 |
+
break;
|
37 |
+
case CF7::ID :
|
38 |
+
add_action('update_option_' . WP_GDPR_C_PREFIX . '_integrations_' . CF7::ID . '_forms', array(CF7::getInstance(), 'processIntegration'));
|
39 |
+
add_action('update_option_' . WP_GDPR_C_PREFIX . '_integrations_' . CF7::ID . '_form_text', array(CF7::getInstance(), 'processIntegration'));
|
40 |
+
add_action('update_option_' . WP_GDPR_C_PREFIX . '_integrations_' . CF7::ID . '_error_message', array(CF7::getInstance(), 'processIntegration'));
|
41 |
+
add_action('wpcf7_init', array(CF7::getInstance(), 'addFormTagSupport'));
|
42 |
+
add_filter('wpcf7_before_send_mail', array(CF7::getInstance(), 'changeMailBodyOutput'), 999);
|
43 |
+
add_filter('wpcf7_validate_wpgdprc', array(CF7::getInstance(), 'validateField'), 10, 2);
|
44 |
+
break;
|
45 |
+
case WPRegistration::ID :
|
46 |
+
$users_can_register = get_option('users_can_register');
|
47 |
+
if ($users_can_register) {
|
48 |
+
add_action('register_form', array(WPRegistration::getInstance(), 'addField'), 999);
|
49 |
+
add_filter('registration_errors', array(WPRegistration::getInstance(), 'validateGDPRCheckbox'), 10, 3);
|
50 |
+
add_action('user_register', array(WPRegistration::getInstance(), 'logGivenGDPRConsent'), 10, 1);
|
51 |
+
}
|
52 |
+
break;
|
53 |
+
case WC::ID :
|
54 |
+
add_action('woocommerce_checkout_process', array(WC::getInstance(), 'checkPostCheckoutForm'));
|
55 |
+
add_action('woocommerce_register_post', array(WC::getInstance(), 'checkPostRegisterForm'), 10, 3);
|
56 |
+
add_action('woocommerce_review_order_before_submit', array(WC::getInstance(), 'addField'), 999);
|
57 |
+
add_action('woocommerce_register_form', array(WC::getInstance(), 'addField'), 999);
|
58 |
+
add_action('woocommerce_checkout_update_order_meta', array(WC::getInstance(), 'addAcceptedDateToOrderMeta'));
|
59 |
+
add_action('woocommerce_admin_order_data_after_order_details', array(WC::getInstance(), 'displayAcceptedDateInOrderData'));
|
60 |
+
add_filter('manage_edit-shop_order_columns', array(WC::getInstance(), 'displayAcceptedDateColumnInOrderOverview'));
|
61 |
+
add_action('manage_shop_order_posts_custom_column', array(WC::getInstance(), 'displayAcceptedDateInOrderOverview'), 10, 2);
|
62 |
+
break;
|
63 |
+
case GForms::ID :
|
64 |
+
add_action('update_option_' . WP_GDPR_C_PREFIX . '_integrations_' . GForms::ID . '_forms', array(GForms::getInstance(), 'processIntegration'));
|
65 |
+
add_action('update_option_' . WP_GDPR_C_PREFIX . '_integrations_' . GForms::ID . '_form_text', array(GForms::getInstance(), 'processIntegration'));
|
66 |
+
add_action('update_option_' . WP_GDPR_C_PREFIX . '_integrations_' . GForms::ID . '_error_message', array(GForms::getInstance(), 'processIntegration'));
|
67 |
+
add_filter('gform_entries_field_value', array(GForms::getInstance(), 'displayAcceptedDateInEntryOverview'), 10, 4);
|
68 |
+
add_filter('gform_get_field_value', array(GForms::getInstance(), 'displayAcceptedDateInEntry'), 10, 2);
|
69 |
+
foreach (GForms::getInstance()->getEnabledForms() as $formId) {
|
70 |
+
add_filter('gform_entry_list_columns_' . $formId, array(GForms::getInstance(), 'displayAcceptedDateColumnInEntryOverview'), 10, 2);
|
71 |
+
add_filter('gform_save_field_value_' . $formId, array(GForms::getInstance(), 'addAcceptedDateToEntry'), 10, 3);
|
72 |
+
add_action('gform_validation_' . $formId, array(GForms::getInstance(), 'overwriteValidationMessage'));
|
73 |
+
}
|
74 |
+
break;
|
75 |
+
}
|
76 |
+
}
|
77 |
+
}
|
78 |
+
|
79 |
+
public function registerSettings() {
|
80 |
+
foreach (self::getSupportedIntegrations() as $plugin) {
|
81 |
+
register_setting(WP_GDPR_C_SLUG . '_integrations', WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'], 'intval');
|
82 |
+
switch ($plugin['id']) {
|
83 |
+
case CF7::ID :
|
84 |
+
add_action('update_option_' . WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'], array(CF7::getInstance(), 'processIntegration'));
|
85 |
+
register_setting(WP_GDPR_C_SLUG . '_integrations', WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_forms');
|
86 |
+
register_setting(WP_GDPR_C_SLUG . '_integrations', WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_form_text', array('sanitize_callback' => array(Helper::getInstance(), 'sanitizeData')));
|
87 |
+
register_setting(WP_GDPR_C_SLUG . '_integrations', WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_error_message', array('sanitize_callback' => array(Helper::getInstance(), 'sanitizeData')));
|
88 |
+
break;
|
89 |
+
case GForms::ID :
|
90 |
+
add_action('update_option_' . WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'], array(GForms::getInstance(), 'processIntegration'));
|
91 |
+
register_setting(WP_GDPR_C_SLUG . '_integrations', WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_forms');
|
92 |
+
register_setting(WP_GDPR_C_SLUG . '_integrations', WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_form_text');
|
93 |
+
register_setting(WP_GDPR_C_SLUG . '_integrations', WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_error_message');
|
94 |
+
register_setting(WP_GDPR_C_SLUG . '_integrations', WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_required_message');
|
95 |
+
break;
|
96 |
+
default :
|
97 |
+
register_setting(WP_GDPR_C_SLUG . '_integrations', WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_text');
|
98 |
+
register_setting(WP_GDPR_C_SLUG . '_integrations', WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_error_message');
|
99 |
+
register_setting(WP_GDPR_C_SLUG . '_integrations', WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'] . '_required_message');
|
100 |
+
break;
|
101 |
+
}
|
102 |
+
}
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* @param string $plugin
|
107 |
+
* @return string
|
108 |
+
*/
|
109 |
+
public static function getSupportedPluginOptions($plugin = '') {
|
110 |
+
$output = '';
|
111 |
+
switch ($plugin) {
|
112 |
+
case CF7::ID :
|
113 |
+
$forms = CF7::getInstance()->getForms();
|
114 |
+
if (!empty($forms)) {
|
115 |
+
$optionNameForms = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_forms';
|
116 |
+
$optionNameFormText = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_form_text';
|
117 |
+
$optionNameErrorMessage = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_error_message';
|
118 |
+
$enabledForms = CF7::getInstance()->getEnabledForms();
|
119 |
+
$output .= '<ul class="wpgdprc-checklist-options">';
|
120 |
+
foreach ($forms as $form) {
|
121 |
+
$formSettingId = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_form_' . $form;
|
122 |
+
$textSettingId = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_form_text_' . $form;
|
123 |
+
$errorSettingId = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_error_message_' . $form;
|
124 |
+
$enabled = in_array($form, $enabledForms);
|
125 |
+
$text = CF7::getInstance()->getCheckboxText($form, false);
|
126 |
+
$errorMessage = CF7::getInstance()->getErrorMessage($form);
|
127 |
+
$output .= '<li class="wpgdprc-clearfix">';
|
128 |
+
$output .= '<div class="wpgdprc-checkbox">';
|
129 |
+
$output .= '<input type="checkbox" name="' . $optionNameForms . '[]" id="' . $formSettingId . '" value="' . $form . '" tabindex="1" data-option="' . $optionNameForms . '" data-append="1" ' . checked(true, $enabled, false) . ' />';
|
130 |
+
$output .= '<label for="' . $formSettingId . '"><strong>' . sprintf(__('Form: %s', WP_GDPR_C_SLUG), get_the_title($form)) . '</strong></label>';
|
131 |
+
$output .= '<span class="wpgdprc-instructions">' . __('Activate for this form:', WP_GDPR_C_SLUG) . '</span>';
|
132 |
+
$output .= '</div>';
|
133 |
+
$output .= '<div class="wpgdprc-setting">';
|
134 |
+
$output .= '<label for="' . $textSettingId . '">' . __('Checkbox text', WP_GDPR_C_SLUG) . '</label>';
|
135 |
+
$output .= '<div class="wpgdprc-options">';
|
136 |
+
$output .= '<textarea name="' . $optionNameFormText . '[' . $form . ']' . '" class="regular-text" id="' . $textSettingId . '" placeholder="' . $text . '">' . $text . '</textarea>';
|
137 |
+
$output .= '</div>';
|
138 |
+
$output .= '</div>';
|
139 |
+
$output .= '<div class="wpgdprc-setting">';
|
140 |
+
$output .= '<label for="' . $errorSettingId . '">' . __('Error message', WP_GDPR_C_SLUG) . '</label>';
|
141 |
+
$output .= '<div class="wpgdprc-options">';
|
142 |
+
$output .= '<input type="text" name="' . $optionNameErrorMessage . '[' . $form . ']' . '" class="regular-text" id="' . $errorSettingId . '" placeholder="' . $errorMessage . '" value="' . $errorMessage . '" />';
|
143 |
+
$output .= '</div>';
|
144 |
+
$output .= '</div>';
|
145 |
+
$output .= Helper::getAllowedHTMLTagsOutput($plugin);
|
146 |
+
$output .= '</li>';
|
147 |
+
}
|
148 |
+
$output .= '</ul>';
|
149 |
+
} else {
|
150 |
+
$output = '<p>' . __('No forms found.', WP_GDPR_C_SLUG) . '</p>';
|
151 |
+
}
|
152 |
+
break;
|
153 |
+
case GForms::ID :
|
154 |
+
$forms = GForms::getInstance()->getForms();
|
155 |
+
if (!empty($forms)) {
|
156 |
+
$optionNameForms = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_forms';
|
157 |
+
$optionNameFormText = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_form_text';
|
158 |
+
$optionNameErrorMessage = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_error_message';
|
159 |
+
$optionNameRequiredMessage = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_required_message';
|
160 |
+
$enabledForms = GForms::getInstance()->getEnabledForms();
|
161 |
+
$output .= '<ul class="wpgdprc-checklist-options">';
|
162 |
+
foreach ($forms as $form) {
|
163 |
+
$formSettingId = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_form_' . $form['id'];
|
164 |
+
$textSettingId = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_form_text_' . $form['id'];
|
165 |
+
$errorSettingId = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_error_message_' . $form['id'];
|
166 |
+
$requiredSettingId = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_required_message_' . $form['id'];
|
167 |
+
$enabled = in_array($form['id'], $enabledForms);
|
168 |
+
$text = esc_html(GForms::getInstance()->getCheckboxText($form['id'], false));
|
169 |
+
$errorMessage = esc_html(GForms::getInstance()->getErrorMessage($form['id']));
|
170 |
+
$requiredMessage = esc_html(GForms::getInstance()->getRequiredMessage($form['id']));
|
171 |
+
$output .= '<li class="wpgdprc-clearfix">';
|
172 |
+
$output .= '<div class="wpgdprc-checkbox">';
|
173 |
+
$output .= '<input type="checkbox" name="' . $optionNameForms . '[]" id="' . $formSettingId . '" value="' . $form['id'] . '" tabindex="1" data-option="' . $optionNameForms . '" data-append="1" ' . checked(true, $enabled, false) . ' />';
|
174 |
+
$output .= '<label for="' . $formSettingId . '"><strong>' . sprintf(__('Form: %s', WP_GDPR_C_SLUG), $form['title']) . '</strong></label>';
|
175 |
+
$output .= '<span class="wpgdprc-instructions">' . __('Activate for this form:', WP_GDPR_C_SLUG) . '</span>';
|
176 |
+
$output .= '</div>';
|
177 |
+
$output .= '<div class="wpgdprc-setting">';
|
178 |
+
$output .= '<label for="' . $textSettingId . '">' . __('Checkbox text', WP_GDPR_C_SLUG) . '</label>';
|
179 |
+
$output .= '<div class="wpgdprc-options">';
|
180 |
+
$output .= '<textarea name="' . $optionNameFormText . '[' . $form['id'] . ']' . '" class="regular-text" id="' . $textSettingId . '" placeholder="' . $text . '">' . $text . '</textarea>';
|
181 |
+
$output .= '</div>';
|
182 |
+
$output .= '</div>';
|
183 |
+
$output .= '<div class="wpgdprc-setting">';
|
184 |
+
$output .= '<label for="' . $errorSettingId . '">' . __('Error message', WP_GDPR_C_SLUG) . '</label>';
|
185 |
+
$output .= '<div class="wpgdprc-options">';
|
186 |
+
$output .= '<input type="text" name="' . $optionNameErrorMessage . '[' . $form['id'] . ']' . '" class="regular-text" id="' . $errorSettingId . '" placeholder="' . $errorMessage . '" value="' . $errorMessage . '" />';
|
187 |
+
$output .= '</div>';
|
188 |
+
$output .= '</div>';
|
189 |
+
$output .= '<div class="wpgdprc-setting">';
|
190 |
+
$output .= '<label for="' . $requiredSettingId . '">' . __('Required message', WP_GDPR_C_SLUG) . '</label>';
|
191 |
+
$output .= '<div class="wpgdprc-options">';
|
192 |
+
$output .= '<input type="text" name="' . $optionNameRequiredMessage . '[' . $form['id'] . ']' . '" class="regular-text" id="' . $requiredSettingId . '" placeholder="' . $requiredMessage . '" value="' . $requiredMessage . '" />';
|
193 |
+
$output .= '</div>';
|
194 |
+
$output .= '</div>';
|
195 |
+
$output .= Helper::getAllowedHTMLTagsOutput($plugin);
|
196 |
+
$output .= '</li>';
|
197 |
+
}
|
198 |
+
$output .= '</ul>';
|
199 |
+
} else {
|
200 |
+
$output = '<p>' . __('No forms found.', WP_GDPR_C_SLUG) . '</p>';
|
201 |
+
}
|
202 |
+
break;
|
203 |
+
default :
|
204 |
+
$optionNameText = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_text';
|
205 |
+
$optionNameErrorMessage = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_error_message';
|
206 |
+
$text = esc_html(self::getCheckboxText($plugin, false));
|
207 |
+
$errorMessage = esc_html(self::getErrorMessage($plugin));
|
208 |
+
$optionNameRequiredMessage = WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_required_message';
|
209 |
+
$requiredMessage = esc_html(self::getRequiredMessage($plugin));
|
210 |
+
$output .= '<ul class="wpgdprc-checklist-options">';
|
211 |
+
$output .= '<li class="wpgdprc-clearfix">';
|
212 |
+
$output .= '<div class="wpgdprc-setting">';
|
213 |
+
$output .= '<label for="' . $optionNameText . '">' . __('Checkbox text', WP_GDPR_C_SLUG) . '</label>';
|
214 |
+
$output .= '<div class="wpgdprc-options">';
|
215 |
+
$output .= '<textarea name="' . $optionNameText . '" class="regular-text" id="' . $optionNameText . '" placeholder="' . $text . '">' . $text . '</textarea>';
|
216 |
+
$output .= '</div>';
|
217 |
+
$output .= '</div>';
|
218 |
+
$output .= '<div class="wpgdprc-setting">';
|
219 |
+
$output .= '<label for="' . $optionNameErrorMessage . '">' . __('Error message', WP_GDPR_C_SLUG) . '</label>';
|
220 |
+
$output .= '<div class="wpgdprc-options">';
|
221 |
+
$output .= '<input type="text" name="' . $optionNameErrorMessage . '" class="regular-text" id="' . $optionNameErrorMessage . '" placeholder="' . $errorMessage . '" value="' . $errorMessage . '" />';
|
222 |
+
$output .= '</div>';
|
223 |
+
$output .= '</div>';
|
224 |
+
$output .= '<div class="wpgdprc-setting">';
|
225 |
+
$output .= '<label for="' . $optionNameRequiredMessage . '">' . __('Required message', WP_GDPR_C_SLUG) . '</label>';
|
226 |
+
$output .= '<div class="wpgdprc-options">';
|
227 |
+
$output .= '<input type="text" name="' . $optionNameRequiredMessage . '" class="regular-text" id="' . $optionNameRequiredMessage . '" placeholder="' . $requiredMessage . '" value="' . $requiredMessage . '" />';
|
228 |
+
$output .= '</div>';
|
229 |
+
$output .= '</div>';
|
230 |
+
$output .= Helper::getAllowedHTMLTagsOutput($plugin);
|
231 |
+
$output .= '</li>';
|
232 |
+
$output .= '</ul>';
|
233 |
+
break;
|
234 |
+
}
|
235 |
+
return $output;
|
236 |
+
}
|
237 |
+
|
238 |
+
/**
|
239 |
+
* @param string $plugin
|
240 |
+
* @param bool $insertPrivacyPolicyLink
|
241 |
+
* @return string
|
242 |
+
*/
|
243 |
+
public static function getCheckboxText($plugin = '', $insertPrivacyPolicyLink = true) {
|
244 |
+
$output = '';
|
245 |
+
if (!empty($plugin)) {
|
246 |
+
$output = get_option(WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_text');
|
247 |
+
$output = ($insertPrivacyPolicyLink === true) ? self::insertPrivacyPolicyLink($output) : $output;
|
248 |
+
$output = apply_filters('wpgdprc_' . $plugin . '_checkbox_text', $output);
|
249 |
+
}
|
250 |
+
if (empty($output)) {
|
251 |
+
$output = __('By using this form you agree with the storage and handling of your data by this website.', WP_GDPR_C_SLUG);
|
252 |
+
}
|
253 |
+
$output = wp_kses($output, Helper::getAllowedHTMLTags($plugin));
|
254 |
+
return apply_filters('wpgdprc_checkbox_text', $output);
|
255 |
+
}
|
256 |
+
|
257 |
+
/**
|
258 |
+
* @param string $plugin
|
259 |
+
* @return mixed
|
260 |
+
*/
|
261 |
+
public static function getErrorMessage($plugin = '') {
|
262 |
+
$output = '';
|
263 |
+
if (!empty($plugin)) {
|
264 |
+
$output = get_option(WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_error_message');
|
265 |
+
$output = apply_filters('wpgdprc_' . $plugin . '_error_message', $output);
|
266 |
+
}
|
267 |
+
if (empty($output)) {
|
268 |
+
$output = __('Please accept the privacy checkbox.', WP_GDPR_C_SLUG);
|
269 |
+
}
|
270 |
+
return apply_filters('wpgdprc_error_message', wp_kses($output, Helper::getAllowedHTMLTags($plugin)));
|
271 |
+
}
|
272 |
+
|
273 |
+
/**
|
274 |
+
* @param string $plugin
|
275 |
+
* @return mixed
|
276 |
+
*/
|
277 |
+
public static function getRequiredMessage($plugin = '') {
|
278 |
+
$output = '';
|
279 |
+
if (!empty($plugin)) {
|
280 |
+
$output = get_option(WP_GDPR_C_PREFIX . '_integrations_' . $plugin . '_required_message');
|
281 |
+
$output = apply_filters('wpgdprc_' . $plugin . '_required_message', $output);
|
282 |
+
}
|
283 |
+
if (empty($output)) {
|
284 |
+
$output = __('You need to accept this checkbox.', WP_GDPR_C_SLUG);
|
285 |
+
}
|
286 |
+
return apply_filters('wpgdprc_required_message', esc_attr($output));
|
287 |
+
}
|
288 |
+
|
289 |
+
/**
|
290 |
+
* @return mixed
|
291 |
+
*/
|
292 |
+
public static function getPrivacyPolicyText() {
|
293 |
+
$output = get_option(WP_GDPR_C_PREFIX . '_settings_privacy_policy_text');
|
294 |
+
if (empty($output)) {
|
295 |
+
$output = __('Privacy Policy', WP_GDPR_C_SLUG);
|
296 |
+
}
|
297 |
+
return apply_filters('wpgdprc_privacy_policy_text', $output);
|
298 |
+
}
|
299 |
+
|
300 |
+
public static function getPrivacyPolicyLink() {
|
301 |
+
$output = get_option(WP_GDPR_C_PREFIX . '_settings_privacy_policy_link');
|
302 |
+
if (empty($output)) {
|
303 |
+
$output = __('http://www.example.com', WP_GDPR_C_SLUG);
|
304 |
+
}
|
305 |
+
return apply_filters('wpgdprc_privacy_policy_link', $output);
|
306 |
+
}
|
307 |
+
|
308 |
+
/**
|
309 |
+
* @param bool $insertPrivacyPolicyLink
|
310 |
+
* @return mixed
|
311 |
+
*/
|
312 |
+
public static function getAccessRequestFormCheckboxText($insertPrivacyPolicyLink = true) {
|
313 |
+
$output = get_option(WP_GDPR_C_PREFIX . '_settings_access_request_form_checkbox_text');
|
314 |
+
if (empty($output)) {
|
315 |
+
$output = __('By using this form you agree with the storage and handling of your data by this website.', WP_GDPR_C_SLUG);
|
316 |
+
}
|
317 |
+
$output = ($insertPrivacyPolicyLink === true) ? self::insertPrivacyPolicyLink($output) : $output;
|
318 |
+
return apply_filters('wpgdprc_access_request_form_checkbox_text', wp_kses($output, Helper::getAllowedHTMLTags()));
|
319 |
+
}
|
320 |
+
|
321 |
+
/**
|
322 |
+
* @param bool $insertPrivacyPolicyLink
|
323 |
+
* @return mixed
|
324 |
+
*/
|
325 |
+
public static function getDeleteRequestFormExplanationText($insertPrivacyPolicyLink = true) {
|
326 |
+
$output = get_option(WP_GDPR_C_PREFIX . '_settings_delete_request_form_explanation_text');
|
327 |
+
if (empty($output)) {
|
328 |
+
$output = sprintf(
|
329 |
+
__('Below we show you all of the data stored by %s on %s. Select the data you wish the site owner to anonymise so it cannot be linked to your email address any longer. It is the site\'s owner responsibility to act upon your request. When your data is anonymised you will receive an email confirmation.', WP_GDPR_C_SLUG),
|
330 |
+
get_option('blogname'),
|
331 |
+
get_option('siteurl')
|
332 |
+
);
|
333 |
+
}
|
334 |
+
$output = ($insertPrivacyPolicyLink === true) ? self::insertPrivacyPolicyLink($output) : $output;
|
335 |
+
return apply_filters('wpgdprc_delete_request_form_explanation_text', wp_kses($output, Helper::getAllowedHTMLTags()));
|
336 |
+
}
|
337 |
+
|
338 |
+
/**
|
339 |
+
* @param string $content
|
340 |
+
* @return mixed|string
|
341 |
+
*/
|
342 |
+
public static function insertPrivacyPolicyLink($content = '') {
|
343 |
+
if (!Helper::isEnabled('enable_privacy_policy_extern', 'settings')) {
|
344 |
+
$page = get_option(WP_GDPR_C_PREFIX . '_settings_privacy_policy_page');
|
345 |
+
} else {
|
346 |
+
$url = get_option(WP_GDPR_C_PREFIX . '_settings_privacy_policy_link');
|
347 |
+
}
|
348 |
+
$text = Integration::getPrivacyPolicyText();
|
349 |
+
if ((!empty($page) || !empty($url)) && !empty($text)) {
|
350 |
+
$link = apply_filters(
|
351 |
+
'wpgdprc_privacy_policy_link',
|
352 |
+
sprintf(
|
353 |
+
'<a target="_blank" href="%s" rel="noopener noreferrer">%s</a>',
|
354 |
+
(Helper::isEnabled('enable_privacy_policy_extern', 'settings')) ? $url : get_page_link($page),
|
355 |
+
esc_html($text)
|
356 |
+
),
|
357 |
+
(Helper::isEnabled('enable_privacy_policy_extern', 'settings')) ? $url : $page,
|
358 |
+
$text
|
359 |
+
);
|
360 |
+
$content = str_replace('%privacy_policy%', $link, $content);
|
361 |
+
}
|
362 |
+
return $content;
|
363 |
+
}
|
364 |
+
|
365 |
+
/**
|
366 |
+
* @return array
|
367 |
+
*/
|
368 |
+
public static function getSupportedWordPressFunctionality() {
|
369 |
+
return array(
|
370 |
+
array(
|
371 |
+
'id' => 'wordpress',
|
372 |
+
'name' => __('WordPress Comments', WP_GDPR_C_SLUG),
|
373 |
+
'description' => __('When activated the GDPR checkbox will be added automatically just above the submit button.', WP_GDPR_C_SLUG),
|
374 |
+
),
|
375 |
+
array(
|
376 |
+
'id' => WPRegistration::ID,
|
377 |
+
'name' => __('Wordpress Registration', WP_GDPR_C_SLUG),
|
378 |
+
'description' => __('When activated the GDPR checkbox will be added automatically just above the register button.', WP_GDPR_C_SLUG),
|
379 |
+
)
|
380 |
+
);
|
381 |
+
}
|
382 |
+
|
383 |
+
/**
|
384 |
+
* @return array
|
385 |
+
*/
|
386 |
+
public static function getSupportedPlugins() {
|
387 |
+
return array(
|
388 |
+
array(
|
389 |
+
'id' => CF7::ID,
|
390 |
+
'supported_version' => CF7::SUPPORTED_VERSION,
|
391 |
+
'file' => 'contact-form-7/wp-contact-form-7.php',
|
392 |
+
'name' => __('Contact Form 7', WP_GDPR_C_SLUG),
|
393 |
+
'description' => __('A GDPR form tag will be automatically added to every form you activate.', WP_GDPR_C_SLUG),
|
394 |
+
),
|
395 |
+
array(
|
396 |
+
'id' => GForms::ID,
|
397 |
+
'supported_version' => GForms::SUPPORTED_VERSION,
|
398 |
+
'file' => 'gravityforms/gravityforms.php',
|
399 |
+
'name' => __('Gravity Forms', WP_GDPR_C_SLUG),
|
400 |
+
'description' => __('A GDPR form tag will be automatically added to every form you activate.', WP_GDPR_C_SLUG),
|
401 |
+
),
|
402 |
+
array(
|
403 |
+
'id' => WC::ID,
|
404 |
+
'supported_version' => WC::SUPPORTED_VERSION,
|
405 |
+
'file' => 'woocommerce/woocommerce.php',
|
406 |
+
'name' => __('WooCommerce', WP_GDPR_C_SLUG),
|
407 |
+
'description' => __('The GDPR checkbox will be added automatically at the end of your checkout page.', WP_GDPR_C_SLUG),
|
408 |
+
)
|
409 |
+
);
|
410 |
+
}
|
411 |
+
|
412 |
+
/**
|
413 |
+
* @return array
|
414 |
+
*/
|
415 |
+
public static function getSupportedIntegrations() {
|
416 |
+
return array_merge(self::getSupportedPlugins(), self::getSupportedWordPressFunctionality());
|
417 |
+
}
|
418 |
+
|
419 |
+
/**
|
420 |
+
* @return array
|
421 |
+
*/
|
422 |
+
public static function getSupportedIntegrationsLabels() {
|
423 |
+
$output = array();
|
424 |
+
$supportedIntegrations = self::getSupportedIntegrations();
|
425 |
+
foreach ($supportedIntegrations as $supportedIntegration) {
|
426 |
+
$output[] = $supportedIntegration['name'];
|
427 |
+
}
|
428 |
+
return $output;
|
429 |
+
}
|
430 |
+
|
431 |
+
/**
|
432 |
+
* @return null|Integration
|
433 |
+
*/
|
434 |
+
public static function getInstance() {
|
435 |
+
if (!isset(self::$instance)) {
|
436 |
+
self::$instance = new self();
|
437 |
+
}
|
438 |
+
return self::$instance;
|
439 |
+
}
|
440 |
}
|
Includes/Page.php
CHANGED
@@ -1,926 +1,962 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WPGDPRC\Includes;
|
4 |
-
|
5 |
-
/**
|
6 |
-
* Class Page
|
7 |
-
* @package WPGDPRC\Includes
|
8 |
-
*/
|
9 |
-
class Page {
|
10 |
-
/** @var null */
|
11 |
-
private static $instance = null;
|
12 |
-
|
13 |
-
public function registerSettings() {
|
14 |
-
foreach (Helper::getCheckList() as $id => $check) {
|
15 |
-
register_setting(WP_GDPR_C_SLUG . '_general', WP_GDPR_C_PREFIX . '_general_' . $id, 'intval');
|
16 |
-
}
|
17 |
-
if (!Helper::isEnabled('enable_privacy_policy_extern', 'settings')) {
|
18 |
-
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_privacy_policy_page', 'intval');
|
19 |
-
}
|
20 |
-
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_privacy_policy_text', array('sanitize_callback' => array(Helper::getInstance(), 'sanitizeData')));
|
21 |
-
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_enable_privacy_policy_extern', 'intval');
|
22 |
-
if (Helper::isEnabled('enable_privacy_policy_extern', 'settings')) {
|
23 |
-
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_privacy_policy_link', array('sanitize_callback' => array(Helper::getInstance(), 'sanitizeData')));
|
24 |
-
}
|
25 |
-
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_enable_access_request', 'intval');
|
26 |
-
if (Helper::isEnabled('enable_access_request', 'settings')) {
|
27 |
-
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_access_request_page', 'intval');
|
28 |
-
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_access_request_form_checkbox_text');
|
29 |
-
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_delete_request_form_explanation_text');
|
30 |
-
}
|
31 |
-
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_consents_modal_title');
|
32 |
-
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_consents_modal_explanation_text');
|
33 |
-
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_consents_bar_explanation_text');
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
<
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
'
|
72 |
-
'value' => 0
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
<?php
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
<
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
$
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
<?php
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
$
|
296 |
-
$
|
297 |
-
$
|
298 |
-
$
|
299 |
-
$
|
300 |
-
$
|
301 |
-
$
|
302 |
-
$
|
303 |
-
$
|
304 |
-
$
|
305 |
-
$
|
306 |
-
$
|
307 |
-
$
|
308 |
-
$
|
309 |
-
$
|
310 |
-
$
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
<?php
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
</div>
|
469 |
-
</div>
|
470 |
-
<div class="wpgdprc-setting">
|
471 |
-
<label for="<?php echo htmlspecialchars($
|
472 |
-
<div class="wpgdprc-options">
|
473 |
-
<textarea name="<?php echo htmlspecialchars($
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
<
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
'
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
'
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
926 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WPGDPRC\Includes;
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Class Page
|
7 |
+
* @package WPGDPRC\Includes
|
8 |
+
*/
|
9 |
+
class Page {
|
10 |
+
/** @var null */
|
11 |
+
private static $instance = null;
|
12 |
+
|
13 |
+
public function registerSettings() {
|
14 |
+
foreach (Helper::getCheckList() as $id => $check) {
|
15 |
+
register_setting(WP_GDPR_C_SLUG . '_general', WP_GDPR_C_PREFIX . '_general_' . $id, 'intval');
|
16 |
+
}
|
17 |
+
if (!Helper::isEnabled('enable_privacy_policy_extern', 'settings')) {
|
18 |
+
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_privacy_policy_page', 'intval');
|
19 |
+
}
|
20 |
+
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_privacy_policy_text', array('sanitize_callback' => array(Helper::getInstance(), 'sanitizeData')));
|
21 |
+
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_enable_privacy_policy_extern', 'intval');
|
22 |
+
if (Helper::isEnabled('enable_privacy_policy_extern', 'settings')) {
|
23 |
+
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_privacy_policy_link', array('sanitize_callback' => array(Helper::getInstance(), 'sanitizeData')));
|
24 |
+
}
|
25 |
+
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_enable_access_request', 'intval');
|
26 |
+
if (Helper::isEnabled('enable_access_request', 'settings')) {
|
27 |
+
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_access_request_page', 'intval');
|
28 |
+
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_access_request_form_checkbox_text');
|
29 |
+
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_delete_request_form_explanation_text');
|
30 |
+
}
|
31 |
+
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_consents_modal_title');
|
32 |
+
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_consents_modal_explanation_text');
|
33 |
+
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_consents_bar_explanation_text');
|
34 |
+
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_consents_bar_color', array('default' => '#000000'));
|
35 |
+
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_consents_bar_text_color', array('default' => '#FFFFFF'));
|
36 |
+
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_consents_bar_button_color_primary', array('default' => '#FFFFFF'));
|
37 |
+
register_setting(WP_GDPR_C_SLUG . '_settings', WP_GDPR_C_PREFIX . '_settings_consents_bar_button_color_secondary', array('default' => '#000000'));
|
38 |
+
}
|
39 |
+
|
40 |
+
public function addAdminMenu() {
|
41 |
+
$pluginData = Helper::getPluginData();
|
42 |
+
add_submenu_page(
|
43 |
+
'tools.php',
|
44 |
+
$pluginData['Name'],
|
45 |
+
$pluginData['Name'],
|
46 |
+
'manage_options',
|
47 |
+
str_replace('-', '_', WP_GDPR_C_SLUG),
|
48 |
+
array($this, 'generatePage')
|
49 |
+
);
|
50 |
+
}
|
51 |
+
|
52 |
+
public function generatePage() {
|
53 |
+
$type = (isset($_REQUEST['type'])) ? esc_html($_REQUEST['type']) : false;
|
54 |
+
$pluginData = Helper::getPluginData();
|
55 |
+
$enableAccessRequest = Helper::isEnabled('enable_access_request', 'settings');
|
56 |
+
$adminUrl = Helper::getPluginAdminUrl();
|
57 |
+
?>
|
58 |
+
<div class="wrap">
|
59 |
+
<div class="wpgdprc">
|
60 |
+
<div class="wpgdprc-contents">
|
61 |
+
<h1 class="wpgdprc-title"><?php echo $pluginData['Name']; ?> <span><?php printf('v%s', $pluginData['Version']); ?></span></h1>
|
62 |
+
|
63 |
+
<?php settings_errors(); ?>
|
64 |
+
|
65 |
+
<div class="wpgdprc-navigation wpgdprc-clearfix">
|
66 |
+
<a class="<?php echo (empty($type)) ? 'wpgdprc-active' : ''; ?>" href="<?php echo $adminUrl; ?>"><?php _e('Integrations', WP_GDPR_C_SLUG); ?></a>
|
67 |
+
<a class="<?php echo checked('consents', $type, false) ? 'wpgdprc-active' : ''; ?>" href="<?php echo $adminUrl; ?>&type=consents"><?php _e('Consents', WP_GDPR_C_SLUG); ?></a>
|
68 |
+
<?php
|
69 |
+
if ($enableAccessRequest) :
|
70 |
+
$totalDeleteRequests = DeleteRequest::getInstance()->getTotal(array(
|
71 |
+
'ip_address' => array(
|
72 |
+
'value' => '127.0.0.1',
|
73 |
+
'compare' => '!='
|
74 |
+
),
|
75 |
+
'processed' => array(
|
76 |
+
'value' => 0
|
77 |
+
)
|
78 |
+
));
|
79 |
+
?>
|
80 |
+
<a class="<?php echo checked('requests', $type, false) ? 'wpgdprc-active' : ''; ?>" href="<?php echo $adminUrl; ?>&type=requests">
|
81 |
+
<?php _e('Requests', WP_GDPR_C_SLUG); ?>
|
82 |
+
<?php
|
83 |
+
if ($totalDeleteRequests > 1) {
|
84 |
+
printf('<span class="wpgdprc-badge">%d</span>', $totalDeleteRequests);
|
85 |
+
}
|
86 |
+
?>
|
87 |
+
</a>
|
88 |
+
<?php
|
89 |
+
endif;
|
90 |
+
?>
|
91 |
+
<a class="<?php echo checked('checklist', $type, false) ? 'wpgdprc-active' : ''; ?>" href="<?php echo $adminUrl; ?>&type=checklist"><?php _e('Checklist', WP_GDPR_C_SLUG); ?></a>
|
92 |
+
<a class="<?php echo checked('settings', $type, false) ? 'wpgdprc-active' : ''; ?>" href="<?php echo $adminUrl; ?>&type=settings"><?php _e('Settings', WP_GDPR_C_SLUG); ?></a>
|
93 |
+
</div>
|
94 |
+
|
95 |
+
<div class="wpgdprc-content wpgdprc-clearfix">
|
96 |
+
<?php
|
97 |
+
switch ($type) {
|
98 |
+
case 'consents' :
|
99 |
+
$action = (isset($_REQUEST['action'])) ? esc_html($_REQUEST['action']) : false;
|
100 |
+
switch ($action) {
|
101 |
+
case 'manage' :
|
102 |
+
$id = (isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) ? intval($_REQUEST['id']) : 0;
|
103 |
+
self::renderManageConsentPage($id);
|
104 |
+
break;
|
105 |
+
default :
|
106 |
+
self::renderConsentsPage();
|
107 |
+
break;
|
108 |
+
}
|
109 |
+
break;
|
110 |
+
case 'requests' :
|
111 |
+
$id = (isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) ? intval($_REQUEST['id']) : 0;
|
112 |
+
if (!empty($id) && AccessRequest::getInstance()->exists($id)) {
|
113 |
+
self::renderManageRequestPage($id);
|
114 |
+
} else {
|
115 |
+
self::renderRequestsPage();
|
116 |
+
}
|
117 |
+
break;
|
118 |
+
case 'checklist' :
|
119 |
+
self::renderChecklistPage();
|
120 |
+
break;
|
121 |
+
case 'settings' :
|
122 |
+
self::renderSettingsPage();
|
123 |
+
break;
|
124 |
+
default :
|
125 |
+
self::renderIntegrationsPage();
|
126 |
+
break;
|
127 |
+
}
|
128 |
+
?>
|
129 |
+
</div>
|
130 |
+
|
131 |
+
<div class="wpgdprc-description">
|
132 |
+
<p><?php _e('This plugin assists website and webshop owners to comply with European privacy regulations known as GDPR. By May 25th, 2018 your site or shop has to comply.', WP_GDPR_C_SLUG); ?></p>
|
133 |
+
<p><?php
|
134 |
+
printf(
|
135 |
+
__('%s currently supports %s. Please visit %s for frequently asked questions and our development roadmap.', WP_GDPR_C_SLUG),
|
136 |
+
$pluginData['Name'],
|
137 |
+
implode(', ', Integration::getSupportedIntegrationsLabels()),
|
138 |
+
sprintf('<a target="_blank" href="%s">%s</a>', '//www.wpgdprc.com/', 'www.wpgdprc.com')
|
139 |
+
);
|
140 |
+
?></p>
|
141 |
+
<p class="wpgdprc-disclaimer"><?php _e('Disclaimer: The creators of this plugin do not have a legal background please contact a law firm for rock solid legal advice.', WP_GDPR_C_SLUG); ?></p>
|
142 |
+
</div>
|
143 |
+
</div>
|
144 |
+
|
145 |
+
<div class="wpgdprc-sidebar">
|
146 |
+
<div class="wpgdprc-sidebar-block">
|
147 |
+
<h3><?php _e('Rate us', WP_GDPR_C_SLUG); ?></h3>
|
148 |
+
<div class="wpgdprc-stars"></div>
|
149 |
+
<p><?php echo sprintf(__('Did %s help you out? Please leave a 5-star review. Thank you!', WP_GDPR_C_SLUG), $pluginData['Name']); ?></p>
|
150 |
+
<a target="_blank" href="//wordpress.org/support/plugin/wp-gdpr-compliance/reviews/#new-post" class="button button-primary" rel="noopener noreferrer"><?php _e('Write a review', WP_GDPR_C_SLUG); ?></a>
|
151 |
+
</div>
|
152 |
+
|
153 |
+
<div class="wpgdprc-sidebar-block">
|
154 |
+
<h3><?php _e('Support', WP_GDPR_C_SLUG); ?></h3>
|
155 |
+
<p><?php echo sprintf(
|
156 |
+
__('Need a helping hand? Please ask for help on the %s. Be sure to mention your WordPress version and give as much additional information as possible.', WP_GDPR_C_SLUG),
|
157 |
+
sprintf('<a target="_blank" href="//wordpress.org/support/plugin/wp-gdpr-compliance#new-post" rel="noopener noreferrer">%s</a>', __('Support forum', WP_GDPR_C_SLUG))
|
158 |
+
); ?></p>
|
159 |
+
</div>
|
160 |
+
</div>
|
161 |
+
|
162 |
+
<div class="wpgdprc-background"><?php include(WP_GDPR_C_DIR_SVG . '/inline-waves.svg.php'); ?></div>
|
163 |
+
</div>
|
164 |
+
</div>
|
165 |
+
<?php
|
166 |
+
}
|
167 |
+
|
168 |
+
private static function renderIntegrationsPage() {
|
169 |
+
$pluginData = Helper::getPluginData();
|
170 |
+
$activatedPlugins = Helper::getActivatedPlugins();
|
171 |
+
?>
|
172 |
+
<form method="post" action="<?php echo admin_url('options.php'); ?>" novalidate="novalidate">
|
173 |
+
<?php settings_fields(WP_GDPR_C_SLUG . '_integrations'); ?>
|
174 |
+
<?php if (!empty($activatedPlugins)) : ?>
|
175 |
+
<ul class="wpgdprc-list">
|
176 |
+
<?php
|
177 |
+
foreach ($activatedPlugins as $key => $plugin) :
|
178 |
+
$optionName = WP_GDPR_C_PREFIX . '_integrations_' . $plugin['id'];
|
179 |
+
$checked = Helper::isEnabled($plugin['id']);
|
180 |
+
$description = (!empty($plugin['description'])) ? apply_filters('wpgdprc_the_content', $plugin['description']) : '';
|
181 |
+
$notices = Helper::getNotices($plugin['id']);
|
182 |
+
$options = Integration::getSupportedPluginOptions($plugin['id']);
|
183 |
+
?>
|
184 |
+
<li class="wpgdprc-clearfix">
|
185 |
+
<?php if ($plugin['supported']) : ?>
|
186 |
+
<?php if (empty($notices)) : ?>
|
187 |
+
<div class="wpgdprc-checkbox">
|
188 |
+
<input type="checkbox" name="<?php echo $optionName; ?>" id="<?php echo $optionName; ?>" value="1" tabindex="1" data-option="<?php echo $optionName; ?>" <?php checked(true, $checked); ?> />
|
189 |
+
<label for="<?php echo $optionName; ?>"><?php echo $plugin['name']; ?></label>
|
190 |
+
<span class="wpgdprc-instructions"><?php _e('Enable:', WP_GDPR_C_SLUG); ?></span>
|
191 |
+
<div class="wpgdprc-switch" aria-hidden="true">
|
192 |
+
<div class="wpgdprc-switch-label">
|
193 |
+
<div class="wpgdprc-switch-inner"></div>
|
194 |
+
<div class="wpgdprc-switch-switch"></div>
|
195 |
+
</div>
|
196 |
+
</div>
|
197 |
+
</div>
|
198 |
+
|
199 |
+
<div class="wpgdprc-checkbox-data" <?php if (!$checked) : ?>style="display: none;"<?php endif; ?>>
|
200 |
+
<?php if (!empty($description)) : ?>
|
201 |
+
<div class="wpgdprc-checklist-description">
|
202 |
+
<?php echo $description; ?>
|
203 |
+
</div>
|
204 |
+
<?php endif; ?>
|
205 |
+
<?php echo $options; ?>
|
206 |
+
</div>
|
207 |
+
<?php else : ?>
|
208 |
+
<div class="wpgdprc-message wpgdprc-message--notice">
|
209 |
+
<strong><?php echo $plugin['name']; ?></strong><br />
|
210 |
+
<?php echo $notices; ?>
|
211 |
+
</div>
|
212 |
+
<?php endif; ?>
|
213 |
+
<?php else : ?>
|
214 |
+
<div class="wpgdprc-message wpgdprc-message--error">
|
215 |
+
<strong><?php echo $plugin['name']; ?></strong><br />
|
216 |
+
<?php printf(__('This plugin is outdated. %s supports version %s and up.', WP_GDPR_C_SLUG), $pluginData['Name'], '<strong>' . $plugin['supported_version'] . '</strong>'); ?>
|
217 |
+
</div>
|
218 |
+
<?php endif; ?>
|
219 |
+
</li>
|
220 |
+
<?php
|
221 |
+
endforeach;
|
222 |
+
?>
|
223 |
+
</ul>
|
224 |
+
<?php else : ?>
|
225 |
+
<p><strong><?php _e('Couldn\'t find any supported plugins installed.', WP_GDPR_C_SLUG); ?></strong></p>
|
226 |
+
<p><?php _e('The following plugins are supported as of now:', WP_GDPR_C_SLUG); ?></p>
|
227 |
+
<ul class="ul-square">
|
228 |
+
<?php foreach (Integration::getSupportedPlugins() as $plugin) : ?>
|
229 |
+
<li><?php echo $plugin['name']; ?></li>
|
230 |
+
<?php endforeach; ?>
|
231 |
+
</ul>
|
232 |
+
<p><?php _e('More plugins will be added in the future.', WP_GDPR_C_SLUG); ?></p>
|
233 |
+
<?php endif; ?>
|
234 |
+
<?php submit_button(); ?>
|
235 |
+
</form>
|
236 |
+
<?php
|
237 |
+
}
|
238 |
+
|
239 |
+
/**
|
240 |
+
* Page: Checklist
|
241 |
+
*/
|
242 |
+
private static function renderChecklistPage() {
|
243 |
+
?>
|
244 |
+
<?php if(Helper::hasMailPluginInstalled()) : ?>
|
245 |
+
<div class="wpgdprc-message wpgdprc-message--notice">
|
246 |
+
<?php
|
247 |
+
printf(
|
248 |
+
'<p><strong>%s:</strong> %s</p>',
|
249 |
+
strtoupper(__('Note', WP_GDPR_C_SLUG)),
|
250 |
+
__('We think you might have a mail plugin installed.', WP_GDPR_C_SLUG)
|
251 |
+
);
|
252 |
+
?>
|
253 |
+
<p><?php _e('Do you know where you got your email database from? Did you ask all the people on your newsletter(s) if they consent to receiving it? GDPR requires that all of the people in your email software has given you explicit permission to mail them.', WP_GDPR_C_SLUG); ?></p>
|
254 |
+
</div>
|
255 |
+
<?php endif; ?>
|
256 |
+
<p><?php _e('Below we ask you what private data you currently collect and provide you with tips to comply.', WP_GDPR_C_SLUG); ?></p>
|
257 |
+
<ul class="wpgdprc-list">
|
258 |
+
<?php
|
259 |
+
foreach (Helper::getCheckList() as $id => $check) :
|
260 |
+
$optionName = WP_GDPR_C_PREFIX . '_general_' . $id;
|
261 |
+
$checked = Helper::isEnabled($id, 'general');
|
262 |
+
$description = (!empty($check['description'])) ? esc_html($check['description']) : '';
|
263 |
+
?>
|
264 |
+
<li class="wpgdprc-clearfix">
|
265 |
+
<div class="wpgdprc-checkbox">
|
266 |
+
<input type="checkbox" name="<?php echo $optionName; ?>" id="<?php echo $id; ?>" value="1" tabindex="1" data-option="<?php echo $optionName; ?>" <?php checked(true, $checked); ?> />
|
267 |
+
<label for="<?php echo $id; ?>"><?php echo $check['label']; ?></label>
|
268 |
+
<div class="wpgdprc-switch wpgdprc-switch--reverse" aria-hidden="true">
|
269 |
+
<div class="wpgdprc-switch-label">
|
270 |
+
<div class="wpgdprc-switch-inner"></div>
|
271 |
+
<div class="wpgdprc-switch-switch"></div>
|
272 |
+
</div>
|
273 |
+
</div>
|
274 |
+
</div>
|
275 |
+
|
276 |
+
<?php if (!empty($description)) : ?>
|
277 |
+
<div class="wpgdprc-checkbox-data" <?php if (!$checked) : ?>style="display: none;"<?php endif; ?>>
|
278 |
+
<div class="wpgdprc-checklist-description">
|
279 |
+
<?php echo $description; ?>
|
280 |
+
</div>
|
281 |
+
</div>
|
282 |
+
<?php endif; ?>
|
283 |
+
</li>
|
284 |
+
<?php
|
285 |
+
endforeach;
|
286 |
+
?>
|
287 |
+
</ul>
|
288 |
+
<?php
|
289 |
+
}
|
290 |
+
|
291 |
+
/**
|
292 |
+
* Page: Settings
|
293 |
+
*/
|
294 |
+
private static function renderSettingsPage() {
|
295 |
+
$optionNamePrivacyPolicyPage = WP_GDPR_C_PREFIX . '_settings_privacy_policy_page';
|
296 |
+
$optionNamePrivacyPolicyText = WP_GDPR_C_PREFIX . '_settings_privacy_policy_text';
|
297 |
+
$optionNameEnablePrivacyPolicyExternal = WP_GDPR_C_PREFIX . '_settings_enable_privacy_policy_extern';
|
298 |
+
$optionNamePrivacyPolicyLink = WP_GDPR_C_PREFIX . '_settings_privacy_policy_link';
|
299 |
+
$optionNameEnableAccessRequest = WP_GDPR_C_PREFIX . '_settings_enable_access_request';
|
300 |
+
$optionNameAccessRequestPage = WP_GDPR_C_PREFIX . '_settings_access_request_page';
|
301 |
+
$optionNameAccessRequestFormCheckboxText = WP_GDPR_C_PREFIX . '_settings_access_request_form_checkbox_text';
|
302 |
+
$optionNameDeleteRequestFormExplanationText = WP_GDPR_C_PREFIX . '_settings_delete_request_form_explanation_text';
|
303 |
+
$optionNameConsentsBarExplanationText = WP_GDPR_C_PREFIX . '_settings_consents_bar_explanation_text';
|
304 |
+
$optionNameConsentsModalTitle = WP_GDPR_C_PREFIX . '_settings_consents_modal_title';
|
305 |
+
$optionNameConsentsModalExplanationText = WP_GDPR_C_PREFIX . '_settings_consents_modal_explanation_text';
|
306 |
+
$optionNameBarColor = WP_GDPR_C_PREFIX . '_settings_consents_bar_color';
|
307 |
+
$optionNameBarTextColor = WP_GDPR_C_PREFIX . '_settings_consents_bar_text_color';
|
308 |
+
$optionNameBarButtonColorPrimary = WP_GDPR_C_PREFIX . '_settings_consents_bar_button_color_primary';
|
309 |
+
$optionNameBarButtonColorSecondary = WP_GDPR_C_PREFIX . '_settings_consents_bar_button_color_secondary';
|
310 |
+
$barColor = get_option($optionNameBarColor);
|
311 |
+
$barTextColor = get_option($optionNameBarTextColor);
|
312 |
+
$barButtonColorPrimary = get_option($optionNameBarButtonColorPrimary);
|
313 |
+
$barButtonColorSecondary = get_option($optionNameBarButtonColorSecondary);
|
314 |
+
$privacyPolicyPage = get_option($optionNamePrivacyPolicyPage);
|
315 |
+
$privacyPolicyText = esc_html(Integration::getPrivacyPolicyText());
|
316 |
+
$enablePrivacyPolicyExternal = Helper::isEnabled('enable_privacy_policy_extern', 'settings');
|
317 |
+
$privacyPolicyLink = esc_html(Integration::getPrivacyPolicyLink());
|
318 |
+
$enableAccessRequest = Helper::isEnabled('enable_access_request', 'settings');
|
319 |
+
$accessRequestPage = get_option($optionNameAccessRequestPage);
|
320 |
+
$accessRequestFormCheckboxText = Integration::getAccessRequestFormCheckboxText(false);
|
321 |
+
$deleteRequestFormExplanationText = Integration::getDeleteRequestFormExplanationText(false);
|
322 |
+
$consentsBarExplanationText = Consent::getBarExplanationText();
|
323 |
+
$consentsModalTitle = Consent::getModalTitle();
|
324 |
+
$consentsModalExplanationText = Consent::getModalExplanationText();
|
325 |
+
?>
|
326 |
+
<form method="post" action="<?php echo admin_url('options.php'); ?>" novalidate="novalidate">
|
327 |
+
<?php settings_fields(WP_GDPR_C_SLUG . '_settings'); ?>
|
328 |
+
<p><strong><?php _e('Privacy Policy', WP_GDPR_C_SLUG); ?></strong></p>
|
329 |
+
<div class="wpgdprc-setting">
|
330 |
+
<label for="<?php echo $optionNameEnablePrivacyPolicyExternal; ?>"><?php _e('Activate', WP_GDPR_C_SLUG); ?></label>
|
331 |
+
<div class="wpgdprc-options">
|
332 |
+
<label><input type="checkbox" name="<?php echo $optionNameEnablePrivacyPolicyExternal; ?>" id="<?php echo $optionNameEnablePrivacyPolicyExternal; ?>" value="1" tabindex="1" <?php checked(true, $enablePrivacyPolicyExternal); ?> /> <?php _e('Activate external links', WP_GDPR_C_SLUG); ?></label>
|
333 |
+
<div class="wpgdprc-information">
|
334 |
+
<div class="wpgdprc-message wpgdprc-message--notice">
|
335 |
+
<?php
|
336 |
+
printf(
|
337 |
+
'<p><strong>%s:</strong> %s</p>',
|
338 |
+
strtoupper(__('Note', WP_GDPR_C_SLUG)),
|
339 |
+
sprintf(
|
340 |
+
__('Enabling this will allow you to use external Privacy Policy instances', WP_GDPR_C_SLUG)
|
341 |
+
)
|
342 |
+
);
|
343 |
+
?>
|
344 |
+
</div>
|
345 |
+
<?php
|
346 |
+
if ( $enablePrivacyPolicyExternal !== true ) {
|
347 |
+
if ( empty( $privacyPolicyPage ) || $privacyPolicyPage === '' || $privacyPolicyPage < 1 ) { ?>
|
348 |
+
<br>
|
349 |
+
<div class="wpgdprc-message wpgdprc-message--notice">
|
350 |
+
<?php
|
351 |
+
printf(
|
352 |
+
'<p><strong>%s:</strong> %s</p>',
|
353 |
+
strtoupper( __( 'Note', WP_GDPR_C_SLUG ) ),
|
354 |
+
sprintf(
|
355 |
+
__( 'Currently you do not have a privacy policy page selected', WP_GDPR_C_SLUG )
|
356 |
+
)
|
357 |
+
);
|
358 |
+
?>
|
359 |
+
</div>
|
360 |
+
<?php }
|
361 |
+
}?>
|
362 |
+
</div>
|
363 |
+
</div>
|
364 |
+
</div>
|
365 |
+
<?php if ($enablePrivacyPolicyExternal) : ?>
|
366 |
+
<div class="wpgdprc-setting">
|
367 |
+
<label for="<?php echo $optionNamePrivacyPolicyLink; ?>"><?php _e('External Privacy Policy Link', WP_GDPR_C_SLUG); ?></label>
|
368 |
+
<div class="wpgdprc-options">
|
369 |
+
<input type="url" name="<?php echo $optionNamePrivacyPolicyLink; ?>" class="regular-text" id="<?php echo $optionNamePrivacyPolicyLink; ?>" placeholder="<?php echo $privacyPolicyLink; ?>" value="<?php echo $privacyPolicyLink; ?>" />
|
370 |
+
</div>
|
371 |
+
</div>
|
372 |
+
<?php else: ?>
|
373 |
+
<div class="wpgdprc-setting">
|
374 |
+
<label for="<?php echo $optionNamePrivacyPolicyPage; ?>"><?php _e('Privacy Policy', WP_GDPR_C_SLUG); ?></label>
|
375 |
+
<div class="wpgdprc-options">
|
376 |
+
<?php
|
377 |
+
wp_dropdown_pages(array(
|
378 |
+
'post_status' => 'publish,private,draft',
|
379 |
+
'show_option_none' => __('Select an option', WP_GDPR_C_SLUG),
|
380 |
+
'name' => $optionNamePrivacyPolicyPage,
|
381 |
+
'selected' => $privacyPolicyPage
|
382 |
+
));
|
383 |
+
?>
|
384 |
+
</div>
|
385 |
+
</div>
|
386 |
+
<?php endif; ?>
|
387 |
+
<div class="wpgdprc-setting">
|
388 |
+
<label for="<?php echo $optionNamePrivacyPolicyText; ?>"><?php _e('Link text', WP_GDPR_C_SLUG); ?></label>
|
389 |
+
<div class="wpgdprc-options">
|
390 |
+
<input type="text" name="<?php echo $optionNamePrivacyPolicyText; ?>" class="regular-text" id="<?php echo $optionNamePrivacyPolicyText; ?>" placeholder="<?php echo $privacyPolicyText; ?>" value="<?php echo $privacyPolicyText; ?>" />
|
391 |
+
</div>
|
392 |
+
</div>
|
393 |
+
<p><strong><?php _e('Request User Data', WP_GDPR_C_SLUG); ?></strong></p>
|
394 |
+
<div class="wpgdprc-information">
|
395 |
+
<p><?php _e('Allow your site\'s visitors to request their data stored in the WordPress database (comments, WooCommerce orders etc.). Data found is send to their email address and allows them to put in an additional request to have the data anonymised.', WP_GDPR_C_SLUG); ?></p>
|
396 |
+
</div>
|
397 |
+
<div class="wpgdprc-setting">
|
398 |
+
<label for="<?php echo $optionNameEnableAccessRequest; ?>"><?php _e('Activate', WP_GDPR_C_SLUG); ?></label>
|
399 |
+
<div class="wpgdprc-options">
|
400 |
+
<label><input type="checkbox" name="<?php echo $optionNameEnableAccessRequest; ?>" id="<?php echo $optionNameEnableAccessRequest; ?>" value="1" tabindex="1" <?php checked(true, $enableAccessRequest); ?> /> <?php _e('Activate page', WP_GDPR_C_SLUG); ?></label>
|
401 |
+
<div class="wpgdprc-information">
|
402 |
+
<div class="wpgdprc-message wpgdprc-message--notice">
|
403 |
+
<?php
|
404 |
+
printf(
|
405 |
+
'<p><strong>%s:</strong> %s</p>',
|
406 |
+
strtoupper(__('Note', WP_GDPR_C_SLUG)),
|
407 |
+
sprintf(
|
408 |
+
__('Enabling this will create one private page containing the necessary shortcode: %s. You can determine when and how to publish this page yourself.', WP_GDPR_C_SLUG),
|
409 |
+
'<span class="wpgdprc-pre"><strong>[wpgdprc_access_request_form]</strong></span>'
|
410 |
+
)
|
411 |
+
);
|
412 |
+
?>
|
413 |
+
</div>
|
414 |
+
</div>
|
415 |
+
</div>
|
416 |
+
</div>
|
417 |
+
<?php if ($enableAccessRequest) : ?>
|
418 |
+
<div class="wpgdprc-setting">
|
419 |
+
<label for="<?php echo $optionNameAccessRequestPage; ?>"><?php _e('Page', WP_GDPR_C_SLUG); ?></label>
|
420 |
+
<div class="wpgdprc-options">
|
421 |
+
<?php
|
422 |
+
wp_dropdown_pages(array(
|
423 |
+
'post_status' => 'publish,private,draft',
|
424 |
+
'show_option_none' => __('Select an option', WP_GDPR_C_SLUG),
|
425 |
+
'name' => $optionNameAccessRequestPage,
|
426 |
+
'selected' => $accessRequestPage
|
427 |
+
));
|
428 |
+
?>
|
429 |
+
<?php if (!empty($accessRequestPage)) : ?>
|
430 |
+
<div class="wpgdprc-information">
|
431 |
+
<?php printf('<p><a href="%s">%s</a></p>', get_edit_post_link($accessRequestPage), __('Click here to edit this page', WP_GDPR_C_SLUG)); ?>
|
432 |
+
</div>
|
433 |
+
<?php endif; ?>
|
434 |
+
</div>
|
435 |
+
</div>
|
436 |
+
<div class="wpgdprc-setting">
|
437 |
+
<label for="<?php echo $optionNameAccessRequestFormCheckboxText; ?>"><?php _e('Checkbox text', WP_GDPR_C_SLUG); ?></label>
|
438 |
+
<div class="wpgdprc-options">
|
439 |
+
<input type="text" name="<?php echo $optionNameAccessRequestFormCheckboxText; ?>" class="regular-text" id="<?php echo $optionNameAccessRequestFormCheckboxText; ?>" placeholder="<?php echo $accessRequestFormCheckboxText; ?>" value="<?php echo $accessRequestFormCheckboxText; ?>" />
|
440 |
+
</div>
|
441 |
+
</div>
|
442 |
+
<div class="wpgdprc-setting">
|
443 |
+
<label for="<?php echo $optionNameDeleteRequestFormExplanationText; ?>"><?php _e('Anonymise request explanation', WP_GDPR_C_SLUG); ?></label>
|
444 |
+
<div class="wpgdprc-options">
|
445 |
+
<textarea name="<?php echo $optionNameDeleteRequestFormExplanationText; ?>" rows="5" id="<?php echo $optionNameAccessRequestFormCheckboxText; ?>" placeholder="<?php echo $deleteRequestFormExplanationText; ?>"><?php echo $deleteRequestFormExplanationText; ?></textarea>
|
446 |
+
<?php echo Helper::getAllowedHTMLTagsOutput(); ?>
|
447 |
+
</div>
|
448 |
+
</div>
|
449 |
+
<?php endif; ?>
|
450 |
+
<p><strong><?php _e('Consents', WP_GDPR_C_SLUG); ?></strong></p>
|
451 |
+
<div class="wpgdprc-information">
|
452 |
+
<p><?php _e('Your visitors can give permission to all of the created Consents (scripts) through a Consent bar at the bottom of their screen. There they can also access their personal settings to give or deny permission to individual Consents. Once their settings are saved the bar disappears for 365 days.', WP_GDPR_C_SLUG); ?></p>
|
453 |
+
<div class="wpgdprc-message wpgdprc-message--notice">
|
454 |
+
<?php
|
455 |
+
printf(
|
456 |
+
'<p><strong>%s:</strong> %s</p>',
|
457 |
+
strtoupper(__('Note', WP_GDPR_C_SLUG)),
|
458 |
+
sprintf(
|
459 |
+
__('Let your visitors re-access their settings by placing a link to the modal with the shortcode %s or add the "%s" class to a menu item.', WP_GDPR_C_SLUG),
|
460 |
+
sprintf(
|
461 |
+
'<span class="wpgdprc-pre"><strong>[wpgdprc_consents_settings_link]<em>%s</em>[/wpgdprc_consents_settings_link]</strong></span>',
|
462 |
+
__('My settings', WP_GDPR_C_SLUG)
|
463 |
+
),
|
464 |
+
'<span class="wpgdprc-pre"><strong>wpgdprc-consents-settings-link</strong></span>'
|
465 |
+
)
|
466 |
+
);
|
467 |
+
?>
|
468 |
+
</div>
|
469 |
+
</div>
|
470 |
+
<div class="wpgdprc-setting">
|
471 |
+
<label for="<?php echo htmlspecialchars($optionNameConsentsBarExplanationText); ?>"><?php _e('Bar: Explanation', WP_GDPR_C_SLUG); ?></label>
|
472 |
+
<div class="wpgdprc-options">
|
473 |
+
<textarea name="<?php echo htmlspecialchars($optionNameConsentsBarExplanationText); ?>" rows="2" id="<?php echo htmlspecialchars($optionNameConsentsBarExplanationText); ?>" placeholder="<?php echo htmlspecialchars($consentsBarExplanationText); ?>"><?php echo htmlspecialchars($consentsBarExplanationText); ?></textarea>
|
474 |
+
</div>
|
475 |
+
</div>
|
476 |
+
<div class="wpgdprc-setting">
|
477 |
+
<label for="<?php echo $optionNameBarColor; ?>"><?php _e('Bar Color', WP_GDPR_C_SLUG); ?></label>
|
478 |
+
<div class="wpgdprc-options">
|
479 |
+
<input type="color" name="<?php echo $optionNameBarColor; ?>" id="<?php echo $optionNameBarColor; ?>" value="<?php echo $barColor; ?>">
|
480 |
+
</div>
|
481 |
+
</div>
|
482 |
+
<div class="wpgdprc-setting">
|
483 |
+
<label for="<?php echo $optionNameBarTextColor; ?>"><?php _e('Bar Text Color', WP_GDPR_C_SLUG); ?></label>
|
484 |
+
<div class="wpgdprc-options">
|
485 |
+
<input type="color" name="<?php echo $optionNameBarTextColor; ?>" id="<?php echo $optionNameBarTextColor; ?>" value="<?php echo $barTextColor; ?>">
|
486 |
+
</div>
|
487 |
+
</div>
|
488 |
+
<div class="wpgdprc-setting">
|
489 |
+
<label for="<?php echo $optionNameBarButtonColorPrimary; ?>"><?php _e('Button Color Primary', WP_GDPR_C_SLUG); ?></label>
|
490 |
+
<div class="wpgdprc-options">
|
491 |
+
<input type="color" name="<?php echo $optionNameBarButtonColorPrimary; ?>" id="<?php echo $optionNameBarButtonColorPrimary; ?>" value="<?php echo $barButtonColorPrimary; ?>">
|
492 |
+
</div>
|
493 |
+
</div>
|
494 |
+
<div class="wpgdprc-setting">
|
495 |
+
<label for="<?php echo $optionNameBarButtonColorSecondary; ?>"><?php _e('Button Color Secondary', WP_GDPR_C_SLUG); ?></label>
|
496 |
+
<div class="wpgdprc-options">
|
497 |
+
<input type="color" name="<?php echo $optionNameBarButtonColorSecondary; ?>" id="<?php echo $optionNameBarButtonColorSecondary; ?>" value="<?php echo $barButtonColorSecondary; ?>">
|
498 |
+
</div>
|
499 |
+
</div>
|
500 |
+
<div class="wpgdprc-setting">
|
501 |
+
<label for="<?php echo htmlspecialchars($optionNameConsentsModalTitle); ?>"><?php _e('Modal: Title', WP_GDPR_C_SLUG); ?></label>
|
502 |
+
<div class="wpgdprc-options">
|
503 |
+
<input type="text" name="<?php echo htmlspecialchars($optionNameConsentsModalTitle); ?>" class="regular-text" id="<?php echo htmlspecialchars($optionNameConsentsModalTitle); ?>" placeholder="<?php echo htmlspecialchars($consentsModalTitle); ?>" value="<?php echo htmlspecialchars($consentsModalTitle); ?>" />
|
504 |
+
</div>
|
505 |
+
</div>
|
506 |
+
<div class="wpgdprc-setting">
|
507 |
+
<label for="<?php echo htmlspecialchars($optionNameConsentsModalExplanationText); ?>"><?php _e('Modal: Explanation', WP_GDPR_C_SLUG); ?></label>
|
508 |
+
<div class="wpgdprc-options">
|
509 |
+
<textarea name="<?php echo htmlspecialchars($optionNameConsentsModalExplanationText); ?>" rows="5" id="<?php echo htmlspecialchars($optionNameConsentsModalExplanationText); ?>" placeholder="<?php echo htmlspecialchars($consentsModalExplanationText); ?>"><?php echo htmlspecialchars($consentsModalExplanationText); ?></textarea>
|
510 |
+
<?php echo Helper::getAllowedHTMLTagsOutput(); ?>
|
511 |
+
</div>
|
512 |
+
</div>
|
513 |
+
<?php submit_button(); ?>
|
514 |
+
</form>
|
515 |
+
<?php
|
516 |
+
}
|
517 |
+
|
518 |
+
/**
|
519 |
+
* @param int $consentId
|
520 |
+
*/
|
521 |
+
private static function renderManageConsentPage($consentId = 0) {
|
522 |
+
wp_enqueue_style('wpgdprc.admin.codemirror.css');
|
523 |
+
wp_enqueue_script('wpgdprc.admin.codemirror.additional.js');
|
524 |
+
$consent = new Consent($consentId);
|
525 |
+
if (isset($_POST['submit']) && check_admin_referer('consent_create_or_update', 'consent_nonce')) {
|
526 |
+
$active = (isset($_POST['active'])) ? 1 : 0;
|
527 |
+
$title = (isset($_POST['title'])) ? stripslashes(esc_html($_POST['title'])) : $consent->getTitle();
|
528 |
+
$description = (isset($_POST['description'])) ? stripslashes(wp_kses($_POST['description'], Helper::getAllowedHTMLTags(''))) : $consent->getDescription();
|
529 |
+
$snippet = (isset($_POST['snippet'])) ? stripslashes($_POST['snippet']) : $consent->getSnippet();
|
530 |
+
$wrap = (isset($_POST['wrap']) && array_key_exists($_POST['wrap'], Consent::getPossibleCodeWraps())) ? esc_html($_POST['wrap']) : $consent->getWrap();
|
531 |
+
$placement = (isset($_POST['placement']) && array_key_exists($_POST['placement'], Consent::getPossiblePlacements())) ? esc_html($_POST['placement']) : $consent->getPlacement();
|
532 |
+
$required = (isset($_POST['required'])) ? 1 : 0;
|
533 |
+
$consent->setTitle($title);
|
534 |
+
$consent->setDescription($description);
|
535 |
+
$consent->setSnippet($snippet);
|
536 |
+
$consent->setWrap($wrap);
|
537 |
+
$consent->setPlacement($placement);
|
538 |
+
$consent->setRequired($required);
|
539 |
+
$consent->setActive($active);
|
540 |
+
$id = $consent->save();
|
541 |
+
if (!empty($id)) {
|
542 |
+
Helper::showAdminNotice('wpgdprc-consent-updated');
|
543 |
+
}
|
544 |
+
}
|
545 |
+
?>
|
546 |
+
<form method="post" action="">
|
547 |
+
<?php wp_nonce_field('consent_create_or_update', 'consent_nonce'); ?>
|
548 |
+
<p><strong><?php _e('Add New Consent', WP_GDPR_C_SLUG); ?></strong></p>
|
549 |
+
<div class="wpgdprc-setting">
|
550 |
+
<label for="wpgdprc_active"><?php _e('Active', WP_GDPR_C_SLUG); ?></label>
|
551 |
+
<div class="wpgdprc-options">
|
552 |
+
<label><input type="checkbox" name="active" id="wpgdprc_active" value="1" <?php checked(1, $consent->getActive()); ?> /> <?php _e('Yes', WP_GDPR_C_SLUG); ?></label>
|
553 |
+
</div>
|
554 |
+
</div>
|
555 |
+
<div class="wpgdprc-setting">
|
556 |
+
<label for="wpgdprc_title"><?php _e('Title', WP_GDPR_C_SLUG); ?></label>
|
557 |
+
<div class="wpgdprc-options">
|
558 |
+
<input type="text" name="title" class="regular-text" id="wpgdprc_title" value="<?php echo $consent->getTitle(); ?>" required="required" />
|
559 |
+
<div class="wpgdprc-information">
|
560 |
+
<p><?php _e('e.g. "Google Analytics" or "Advertising"', WP_GDPR_C_SLUG); ?></p>
|
561 |
+
</div>
|
562 |
+
</div>
|
563 |
+
</div>
|
564 |
+
<div class="wpgdprc-setting">
|
565 |
+
<label for="wpgdprc_description"><?php _e('Description', WP_GDPR_C_SLUG); ?></label>
|
566 |
+
<div class="wpgdprc-options">
|
567 |
+
<textarea name="description" id="wpgdprc_description" rows="5" autocomplete="false" autocorrect="false" autocapitalize="false" spellcheck="false"><?php echo $consent->getDescription(); ?></textarea>
|
568 |
+
<div class="wpgdprc-information">
|
569 |
+
<p><?php _e('Describe your consent script as thoroughly as possible. %privacy_policy% will not work.', WP_GDPR_C_SLUG); ?></p>
|
570 |
+
</div>
|
571 |
+
</div>
|
572 |
+
</div>
|
573 |
+
<div class="wpgdprc-setting">
|
574 |
+
<label for="wpgdprc_snippet"><?php _e('Code Snippet', WP_GDPR_C_SLUG); ?></label>
|
575 |
+
<div class="wpgdprc-options">
|
576 |
+
<textarea name="snippet" id="wpgdprc_snippet" rows="10" autocomplete="false" autocorrect="false" autocapitalize="false" spellcheck="false"><?php echo htmlspecialchars($consent->getSnippet(), ENT_QUOTES, get_option('blog_charset')); ?></textarea>
|
577 |
+
<div class="wpgdprc-information">
|
578 |
+
<p><?php _e('Code snippets for Google Analytics, Facebook Pixel, etc.', WP_GDPR_C_SLUG); ?></p>
|
579 |
+
</div>
|
580 |
+
</div>
|
581 |
+
</div>
|
582 |
+
<div class="wpgdprc-setting">
|
583 |
+
<label for="wpgdprc_code_wrap"><?php _e('Code Wrap', WP_GDPR_C_SLUG); ?></label>
|
584 |
+
<div class="wpgdprc-options">
|
585 |
+
<select name="wrap" id="wpgdprc_code_wrap">
|
586 |
+
<?php
|
587 |
+
foreach (Consent::getPossibleCodeWraps() as $value => $label) {
|
588 |
+
printf(
|
589 |
+
'<option value="%s" %s>%s</option>',
|
590 |
+
$value,
|
591 |
+
selected($value, $consent->getWrap(), false),
|
592 |
+
$label
|
593 |
+
);
|
594 |
+
}
|
595 |
+
?>
|
596 |
+
</select>
|
597 |
+
</div>
|
598 |
+
</div>
|
599 |
+
<div class="wpgdprc-setting">
|
600 |
+
<label for="wpgdprc_placement"><?php _e('Placement', WP_GDPR_C_SLUG); ?></label>
|
601 |
+
<div class="wpgdprc-options">
|
602 |
+
<select name="placement" id="wpgdprc_placement">
|
603 |
+
<?php
|
604 |
+
foreach (Consent::getPossiblePlacements() as $value => $label) {
|
605 |
+
printf(
|
606 |
+
'<option value="%s" %s>%s</option>',
|
607 |
+
$value,
|
608 |
+
selected($value, $consent->getPlacement(), false),
|
609 |
+
$label
|
610 |
+
);
|
611 |
+
}
|
612 |
+
?>
|
613 |
+
</select>
|
614 |
+
<div class="wpgdprc-information">
|
615 |
+
<?php
|
616 |
+
printf(
|
617 |
+
'<strong>%s:</strong> %s<br />',
|
618 |
+
strtoupper(__('Head', WP_GDPR_C_SLUG)),
|
619 |
+
__('Snippet will be added to the HEAD section.', WP_GDPR_C_SLUG)
|
620 |
+
);
|
621 |
+
printf(
|
622 |
+
'<strong>%s:</strong> %s',
|
623 |
+
strtoupper(__('Footer', WP_GDPR_C_SLUG)),
|
624 |
+
__('Snippet will be added to the FOOTER section.', WP_GDPR_C_SLUG)
|
625 |
+
);
|
626 |
+
?>
|
627 |
+
</div>
|
628 |
+
</div>
|
629 |
+
</div>
|
630 |
+
<div class="wpgdprc-setting">
|
631 |
+
<label for="wpgdprc_active"><?php _e('Required', WP_GDPR_C_SLUG); ?></label>
|
632 |
+
<div class="wpgdprc-options">
|
633 |
+
<label><input type="checkbox" name="required" id="wpgdprc-required" value="1" <?php checked(1, $consent->getRequired()); ?> /> <?php _e('Yes', WP_GDPR_C_SLUG); ?></label>
|
634 |
+
<div class="wpgdprc-information">
|
635 |
+
<p><?php _e('Ticking this checkbox means this Consent will always be triggered so users cannot opt-in or opt-out.', WP_GDPR_C_SLUG); ?></p>
|
636 |
+
</div>
|
637 |
+
</div>
|
638 |
+
</div>
|
639 |
+
<p class="submit">
|
640 |
+
<?php submit_button((!empty($consentId) ? __('Update', WP_GDPR_C_SLUG) : __('Add', WP_GDPR_C_SLUG)), 'primary', 'submit', false); ?>
|
641 |
+
<a class="button button-secondary" href="<?php echo Helper::getPluginAdminUrl('consents'); ?>"><?php _e('Back to overview', WP_GDPR_C_SLUG); ?></a>
|
642 |
+
</p>
|
643 |
+
</form>
|
644 |
+
<?php
|
645 |
+
}
|
646 |
+
|
647 |
+
private static function renderConsentsPage() {
|
648 |
+
if (isset($_POST['reset-cookie-bar'])) {
|
649 |
+
Helper::resetCookieBar();
|
650 |
+
Helper::showAdminNotice('wpgdprc-cookie-bar-reset');
|
651 |
+
}
|
652 |
+
$paged = (isset($_REQUEST['paged'])) ? absint($_REQUEST['paged']) : 1;
|
653 |
+
$limit = 20;
|
654 |
+
$offset = ($paged - 1) * $limit;
|
655 |
+
$total = Consent::getInstance()->getTotal();
|
656 |
+
$numberOfPages = ceil($total / $limit);
|
657 |
+
$consents = Consent::getInstance()->getList(array(), $limit, $offset);
|
658 |
+
?>
|
659 |
+
<div class="wpgdprc-message wpgdprc-message--notice">
|
660 |
+
<p><?php _e('Ask your visitors for permission to enable certain scripts for tracking or advertising purposes. Add a Consent for each type of script you are requesting permission for. Scripts will only be activated when permission is given.', WP_GDPR_C_SLUG); ?></p>
|
661 |
+
<p><a class="button button-primary" href="<?php echo Helper::getPluginAdminUrl('consents', array('action' => 'create')); ?>"><?php _ex('Add New', 'consent', WP_GDPR_C_SLUG); ?></a></p>
|
662 |
+
</div>
|
663 |
+
<div class="wpgdprc-message wpgdprc-message--notice">
|
664 |
+
<p><?php _e('Click this button if you want to reset the consent bar, this means that the consent bar will appear again for all users.', WP_GDPR_C_SLUG); ?></p>
|
665 |
+
<form method="post"><button type="submit" class="button button-primary" name="reset-cookie-bar">Reset Consent Bar</button></form>
|
666 |
+
</div>
|
667 |
+
<?php if (!empty($consents)) : ?>
|
668 |
+
<table class="wpgdprc-table">
|
669 |
+
<thead>
|
670 |
+
<tr>
|
671 |
+
<th scope="col" width="10%"><?php _e('Consent', WP_GDPR_C_SLUG); ?></th>
|
672 |
+
<th scope="col" width="16%"><?php _e('Title', WP_GDPR_C_SLUG); ?></th>
|
673 |
+
<th scope="col" width="12%"><?php _e('Required', WP_GDPR_C_SLUG); ?></th>
|
674 |
+
<th scope="col" width="20%"><?php _e('Modified at', WP_GDPR_C_SLUG); ?></th>
|
675 |
+
<th scope="col" width="20%"><?php _e('Created at', WP_GDPR_C_SLUG); ?></th>
|
676 |
+
<th scope="col" width="14%"><?php _e('Action', WP_GDPR_C_SLUG); ?></th>
|
677 |
+
<th scope="col" width="8%"><?php _e('Active', WP_GDPR_C_SLUG); ?></th>
|
678 |
+
</tr>
|
679 |
+
</thead>
|
680 |
+
<tbody>
|
681 |
+
<?php
|
682 |
+
foreach ($consents as $consent) :
|
683 |
+
$title = $consent->getTitle();
|
684 |
+
?>
|
685 |
+
<tr class="wpgdprc-table__row <?php echo (!$consent->getActive()) ? 'wpgdprc-table__row--expired' : ''; ?>">
|
686 |
+
<td><?php printf('#%d', $consent->getId()); ?></td>
|
687 |
+
<td>
|
688 |
+
<?php
|
689 |
+
printf(
|
690 |
+
'<a href="%s">%s</a>',
|
691 |
+
Consent::getActionUrl($consent->getId()),
|
692 |
+
((!empty($title)) ? $title : __('(no title)', WP_GDPR_C_SLUG))
|
693 |
+
);
|
694 |
+
?>
|
695 |
+
</td>
|
696 |
+
<td><?php echo ($consent->getRequired()) ? __('Yes', WP_GDPR_C_SLUG) : __('No', WP_GDPR_C_SLUG); ?></td>
|
697 |
+
<td><?php echo $consent->getDateModified(); ?></td>
|
698 |
+
<td><?php echo $consent->getDateCreated(); ?></td>
|
699 |
+
<td>
|
700 |
+
<?php
|
701 |
+
printf(
|
702 |
+
'%s | %s',
|
703 |
+
sprintf(
|
704 |
+
'<a href="%s">%s</a>',
|
705 |
+
Consent::getActionUrl($consent->getId()),
|
706 |
+
__('Edit', WP_GDPR_C_SLUG)
|
707 |
+
),
|
708 |
+
sprintf(
|
709 |
+
'<a href="%s">%s</a>',
|
710 |
+
Consent::getActionUrl($consent->getId(), 'delete'),
|
711 |
+
__('Remove', WP_GDPR_C_SLUG)
|
712 |
+
)
|
713 |
+
);
|
714 |
+
?>
|
715 |
+
</td>
|
716 |
+
<td><?php echo ($consent->getActive()) ? __('Yes', WP_GDPR_C_SLUG) : __('No', WP_GDPR_C_SLUG); ?></td>
|
717 |
+
</tr>
|
718 |
+
<?php
|
719 |
+
endforeach;
|
720 |
+
?>
|
721 |
+
</tbody>
|
722 |
+
</table>
|
723 |
+
<div class="wpgdprc-pagination">
|
724 |
+
<?php
|
725 |
+
echo paginate_links(array(
|
726 |
+
'base' => str_replace(
|
727 |
+
999999999,
|
728 |
+
'%#%',
|
729 |
+
Helper::getPluginAdminUrl('consents', array('paged' => 999999999))
|
730 |
+
),
|
731 |
+
'format' => '?paged=%#%',
|
732 |
+
'current' => max(1, $paged),
|
733 |
+
'total' => $numberOfPages,
|
734 |
+
'prev_text' => '‹',
|
735 |
+
'next_text' => '›',
|
736 |
+
'before_page_number' => '<span>',
|
737 |
+
'after_page_number' => '</span>'
|
738 |
+
));
|
739 |
+
printf('<span class="wpgdprc-pagination__results">%s</span>', sprintf(__('%d of %d results found', WP_GDPR_C_SLUG), count($consents), $total));
|
740 |
+
?>
|
741 |
+
</div>
|
742 |
+
<?php else : ?>
|
743 |
+
<p><strong><?php _e('No consents found.', WP_GDPR_C_SLUG); ?></strong></p>
|
744 |
+
<?php endif; ?>
|
745 |
+
<?php
|
746 |
+
}
|
747 |
+
|
748 |
+
/**
|
749 |
+
* @param int $requestId
|
750 |
+
*/
|
751 |
+
private static function renderManageRequestPage($requestId = 0) {
|
752 |
+
$accessRequest = new AccessRequest($requestId);
|
753 |
+
$filters = array(
|
754 |
+
'access_request_id' => array(
|
755 |
+
'value' => $accessRequest->getId(),
|
756 |
+
),
|
757 |
+
);
|
758 |
+
$paged = (isset($_REQUEST['paged'])) ? absint($_REQUEST['paged']) : 1;
|
759 |
+
$limit = 20;
|
760 |
+
$offset = ($paged - 1) * $limit;
|
761 |
+
$total = DeleteRequest::getInstance()->getTotal($filters);
|
762 |
+
$numberOfPages = ceil($total / $limit);
|
763 |
+
$requests = DeleteRequest::getInstance()->getList($filters, $limit, $offset);
|
764 |
+
if (!empty($requests)) :
|
765 |
+
?>
|
766 |
+
<div class="wpgdprc-message wpgdprc-message--notice">
|
767 |
+
<p><?php _e('Anonymise a request by ticking the checkbox and clicking on the green anonymise button below.', WP_GDPR_C_SLUG); ?></p>
|
768 |
+
<p>
|
769 |
+
<?php printf('<strong>%s:</strong> %s', __('WordPress Users', WP_GDPR_C_SLUG), 'Anonymises first and last name, display name, nickname and email address.', WP_GDPR_C_SLUG); ?><br />
|
770 |
+
<?php printf('<strong>%s:</strong> %s', __('WordPress Comments', WP_GDPR_C_SLUG), 'Anonymises author name, email address and IP address.', WP_GDPR_C_SLUG); ?><br />
|
771 |
+
<?php printf('<strong>%s:</strong> %s', __('WooCommerce', WP_GDPR_C_SLUG), 'Anonymises billing and shipping details per order.', WP_GDPR_C_SLUG); ?>
|
772 |
+
</p>
|
773 |
+
<?php
|
774 |
+
printf(
|
775 |
+
'<p><strong>%s:</strong> %s</p>',
|
776 |
+
strtoupper(__('Note', WP_GDPR_C_SLUG)),
|
777 |
+
sprintf(__('Requests are automatically anonymised after %d days.', WP_GDPR_C_SLUG), 30)
|
778 |
+
);
|
779 |
+
?>
|
780 |
+
</div>
|
781 |
+
|
782 |
+
<form class="wpgdprc-form wpgdprc-form--process-delete-requests" method="POST" novalidate="novalidate">
|
783 |
+
<div class="wpgdprc-message" style="display: none;"></div>
|
784 |
+
<table class="wpgdprc-table">
|
785 |
+
<thead>
|
786 |
+
<tr>
|
787 |
+
<th scope="col" width="10%"><?php _e('Request', WP_GDPR_C_SLUG); ?></th>
|
788 |
+
<th scope="col" width="22%"><?php _e('Type', WP_GDPR_C_SLUG); ?></th>
|
789 |
+
<th scope="col" width="18%"><?php _e('IP Address', WP_GDPR_C_SLUG); ?></th>
|
790 |
+
<th scope="col" width="22%"><?php _e('Date', WP_GDPR_C_SLUG); ?></th>
|
791 |
+
<th scope="col" width="12%"><?php _e('Processed', WP_GDPR_C_SLUG); ?></th>
|
792 |
+
<th scope="col" width="10%"><?php _e('Action', WP_GDPR_C_SLUG); ?></th>
|
793 |
+
<th scope="col" width="6%"><input type="checkbox" class="wpgdprc-select-all" /></th>
|
794 |
+
</tr>
|
795 |
+
</thead>
|
796 |
+
<tbody>
|
797 |
+
<?php
|
798 |
+
/** @var DeleteRequest $request */
|
799 |
+
foreach ($requests as $request) :
|
800 |
+
?>
|
801 |
+
<tr class="wpgdprc-table__row <?php echo ($request->isAnonymised()) ? 'wpgdprc-table__row--expired' : ''; ?>" data-id="<?php echo $request->getId(); ?>">
|
802 |
+
<td><?php printf('#%d', $request->getId()); ?></td>
|
803 |
+
<td><?php echo $request->getNiceTypeLabel(); ?></td>
|
804 |
+
<td><?php echo $request->getIpAddress(); ?></td>
|
805 |
+
<td><?php echo $request->getDateCreated(); ?></td>
|
806 |
+
<td><span class="dashicons dashicons-<?php echo ($request->getProcessed()) ? 'yes' : 'no'; ?>"></span></td>
|
807 |
+
<td>
|
808 |
+
<?php
|
809 |
+
if ($request->getDataId() !== 0 && !$request->isAnonymised()) {
|
810 |
+
printf('<a target="_blank" href="%s">%s</a>', $request->getManageUrl(), __('View', WP_GDPR_C_SLUG));
|
811 |
+
} else {
|
812 |
+
_e('N/A', WP_GDPR_C_SLUG);
|
813 |
+
}
|
814 |
+
?>
|
815 |
+
</td>
|
816 |
+
<td>
|
817 |
+
<?php
|
818 |
+
if (!$request->getProcessed() && !$request->isAnonymised()) {
|
819 |
+
printf('<input type="checkbox" class="wpgdprc-checkbox" value="%d" />', $request->getId());
|
820 |
+
} else {
|
821 |
+
echo ' ';
|
822 |
+
}
|
823 |
+
?>
|
824 |
+
</td>
|
825 |
+
</tr>
|
826 |
+
<?php
|
827 |
+
endforeach;
|
828 |
+
?>
|
829 |
+
</tbody>
|
830 |
+
</table>
|
831 |
+
<?php submit_button(__('Anonymise selected request(s)', WP_GDPR_C_SLUG), 'primary wpgdprc-remove'); ?>
|
832 |
+
</form>
|
833 |
+
|
834 |
+
<div class="wpgdprc-pagination">
|
835 |
+
<?php
|
836 |
+
echo paginate_links(array(
|
837 |
+
'base' => str_replace(
|
838 |
+
999999999,
|
839 |
+
'%#%',
|
840 |
+
Helper::getPluginAdminUrl('requests', array('paged' => 999999999))
|
841 |
+
),
|
842 |
+
'format' => '?paged=%#%',
|
843 |
+
'current' => max(1, $paged),
|
844 |
+
'total' => $numberOfPages,
|
845 |
+
'prev_text' => '‹',
|
846 |
+
'next_text' => '›',
|
847 |
+
'before_page_number' => '<span>',
|
848 |
+
'after_page_number' => '</span>'
|
849 |
+
));
|
850 |
+
printf('<span class="wpgdprc-pagination__results">%s</span>', sprintf(__('%d of %d results found', WP_GDPR_C_SLUG), count($requests), $total));
|
851 |
+
?>
|
852 |
+
</div>
|
853 |
+
<?php
|
854 |
+
else :
|
855 |
+
?>
|
856 |
+
<p><strong><?php _e('No requests found.', WP_GDPR_C_SLUG); ?></strong></p>
|
857 |
+
<?php
|
858 |
+
endif;
|
859 |
+
?>
|
860 |
+
<?php
|
861 |
+
}
|
862 |
+
|
863 |
+
/**
|
864 |
+
* Page: Requests
|
865 |
+
*/
|
866 |
+
private static function renderRequestsPage() {
|
867 |
+
$paged = (isset($_REQUEST['paged'])) ? absint($_REQUEST['paged']) : 1;
|
868 |
+
$limit = 20;
|
869 |
+
$offset = ($paged - 1) * $limit;
|
870 |
+
$total = AccessRequest::getInstance()->getTotal();
|
871 |
+
$numberOfPages = ceil($total / $limit);
|
872 |
+
$requests = AccessRequest::getInstance()->getList(array(), $limit, $offset);
|
873 |
+
if (!empty($requests)) :
|
874 |
+
?>
|
875 |
+
<div class="wpgdprc-message wpgdprc-message--notice">
|
876 |
+
<?php
|
877 |
+
printf(
|
878 |
+
'<p><strong>%s:</strong> %s</p>',
|
879 |
+
strtoupper(__('Note', WP_GDPR_C_SLUG)),
|
880 |
+
sprintf(__('Requests are automatically anonymised after %d days.', WP_GDPR_C_SLUG), 30)
|
881 |
+
);
|
882 |
+
?>
|
883 |
+
</div>
|
884 |
+
<table class="wpgdprc-table">
|
885 |
+
<thead>
|
886 |
+
<tr>
|
887 |
+
<th scope="col" width="10%"><?php _e('ID', WP_GDPR_C_SLUG); ?></th>
|
888 |
+
<th scope="col" width="20%"><?php _e('Requests to Process', WP_GDPR_C_SLUG); ?></th>
|
889 |
+
<th scope="col" width="22%"><?php _e('Email Address', WP_GDPR_C_SLUG); ?></th>
|
890 |
+
<th scope="col" width="18%"><?php _e('IP Address', WP_GDPR_C_SLUG); ?></th>
|
891 |
+
<th scope="col" width="22%"><?php _e('Date', WP_GDPR_C_SLUG); ?></th>
|
892 |
+
<th scope="col" width="8%"><?php _e('Status', WP_GDPR_C_SLUG); ?></th>
|
893 |
+
</tr>
|
894 |
+
</thead>
|
895 |
+
<tbody>
|
896 |
+
<?php
|
897 |
+
/** @var AccessRequest $request */
|
898 |
+
foreach ($requests as $request) :
|
899 |
+
$amountOfNonAnonymisedDeleteRequests = DeleteRequest::getInstance()->getAmountByAccessRequestId($request->getId(), false);
|
900 |
+
$amountOfDeleteRequests = DeleteRequest::getInstance()->getAmountByAccessRequestId($request->getId());
|
901 |
+
?>
|
902 |
+
<tr class="wpgdprc-table__row <?php echo ($request->getExpired() || $request->isAnonymised()) ? 'wpgdprc-table__row--expired' : ''; ?>">
|
903 |
+
<td><?php printf('#%d', $request->getId()); ?></td>
|
904 |
+
<td>
|
905 |
+
<?php printf('%d', $amountOfNonAnonymisedDeleteRequests); ?>
|
906 |
+
<?php
|
907 |
+
if ($amountOfDeleteRequests > 0) {
|
908 |
+
printf(
|
909 |
+
'<a href="%s">%s</a>',
|
910 |
+
Helper::getPluginAdminUrl('requests', array('id' => $request->getId())),
|
911 |
+
__('Manage', WP_GDPR_C_SLUG)
|
912 |
+
);
|
913 |
+
}
|
914 |
+
?>
|
915 |
+
</td>
|
916 |
+
<td><?php echo $request->getEmailAddress(); ?></td>
|
917 |
+
<td><?php echo $request->getIpAddress(); ?></td>
|
918 |
+
<td><?php echo $request->getDateCreated(); ?></td>
|
919 |
+
<td><?php echo ($request->getExpired()) ? __('Expired', WP_GDPR_C_SLUG) : __('Active', WP_GDPR_C_SLUG); ?></td>
|
920 |
+
</tr>
|
921 |
+
<?php
|
922 |
+
endforeach;
|
923 |
+
?>
|
924 |
+
</tbody>
|
925 |
+
</table>
|
926 |
+
<div class="wpgdprc-pagination">
|
927 |
+
<?php
|
928 |
+
echo paginate_links(array(
|
929 |
+
'base' => str_replace(
|
930 |
+
999999999,
|
931 |
+
'%#%',
|
932 |
+
Helper::getPluginAdminUrl('requests', array('paged' => 999999999))
|
933 |
+
),
|
934 |
+
'format' => '?paged=%#%',
|
935 |
+
'current' => max(1, $paged),
|
936 |
+
'total' => $numberOfPages,
|
937 |
+
'prev_text' => '‹',
|
938 |
+
'next_text' => '›',
|
939 |
+
'before_page_number' => '<span>',
|
940 |
+
'after_page_number' => '</span>'
|
941 |
+
));
|
942 |
+
printf('<span class="wpgdprc-pagination__results">%s</span>', sprintf(__('%d of %d results found', WP_GDPR_C_SLUG), count($requests), $total));
|
943 |
+
?>
|
944 |
+
</div>
|
945 |
+
<?php
|
946 |
+
else :
|
947 |
+
?>
|
948 |
+
<p><strong><?php _e('No requests found.', WP_GDPR_C_SLUG); ?></strong></p>
|
949 |
+
<?php
|
950 |
+
endif;
|
951 |
+
}
|
952 |
+
|
953 |
+
/**
|
954 |
+
* @return null|Page
|
955 |
+
*/
|
956 |
+
public static function getInstance() {
|
957 |
+
if (!isset(self::$instance)) {
|
958 |
+
self::$instance = new self();
|
959 |
+
}
|
960 |
+
return self::$instance;
|
961 |
+
}
|
962 |
}
|
Includes/SessionHelper.php
CHANGED
@@ -1,52 +1,52 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WPGDPRC\Includes;
|
4 |
-
|
5 |
-
/**
|
6 |
-
* Class SessionHelper
|
7 |
-
* @package WPGDPRC\Includes
|
8 |
-
*/
|
9 |
-
class SessionHelper {
|
10 |
-
/**
|
11 |
-
* @return string
|
12 |
-
*/
|
13 |
-
public static function getSessionId() {
|
14 |
-
self::startSession();
|
15 |
-
return session_id();
|
16 |
-
}
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Start the session if it has not started yet
|
20 |
-
*/
|
21 |
-
public static function startSession() {
|
22 |
-
if (!session_id()) {
|
23 |
-
session_start();
|
24 |
-
}
|
25 |
-
}
|
26 |
-
|
27 |
-
/**
|
28 |
-
* @param string $sessionId
|
29 |
-
* @return bool
|
30 |
-
*/
|
31 |
-
public static function checkSession($sessionId = '') {
|
32 |
-
return self::getSessionId() === $sessionId;
|
33 |
-
}
|
34 |
-
|
35 |
-
/**
|
36 |
-
* @param string $variable
|
37 |
-
* @param string $value
|
38 |
-
*/
|
39 |
-
public static function setSessionVariable($variable = '', $value = '') {
|
40 |
-
self::startSession();
|
41 |
-
$_SESSION[$variable] = $value;
|
42 |
-
}
|
43 |
-
|
44 |
-
/**
|
45 |
-
* @param string $variable
|
46 |
-
* @return bool
|
47 |
-
*/
|
48 |
-
public static function getSessionVariable($variable = '') {
|
49 |
-
self::startSession();
|
50 |
-
return (isset($_SESSION[$variable])) ? $_SESSION[$variable] : false;
|
51 |
-
}
|
52 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WPGDPRC\Includes;
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Class SessionHelper
|
7 |
+
* @package WPGDPRC\Includes
|
8 |
+
*/
|
9 |
+
class SessionHelper {
|
10 |
+
/**
|
11 |
+
* @return string
|
12 |
+
*/
|
13 |
+
public static function getSessionId() {
|
14 |
+
self::startSession();
|
15 |
+
return session_id();
|
16 |
+
}
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Start the session if it has not started yet
|
20 |
+
*/
|
21 |
+
public static function startSession() {
|
22 |
+
if (!session_id()) {
|
23 |
+
session_start();
|
24 |
+
}
|
25 |
+
}
|
26 |
+
|
27 |
+
/**
|
28 |
+
* @param string $sessionId
|
29 |
+
* @return bool
|
30 |
+
*/
|
31 |
+
public static function checkSession($sessionId = '') {
|
32 |
+
return self::getSessionId() === $sessionId;
|
33 |
+
}
|
34 |
+
|
35 |
+
/**
|
36 |
+
* @param string $variable
|
37 |
+
* @param string $value
|
38 |
+
*/
|
39 |
+
public static function setSessionVariable($variable = '', $value = '') {
|
40 |
+
self::startSession();
|
41 |
+
$_SESSION[$variable] = $value;
|
42 |
+
}
|
43 |
+
|
44 |
+
/**
|
45 |
+
* @param string $variable
|
46 |
+
* @return bool
|
47 |
+
*/
|
48 |
+
public static function getSessionVariable($variable = '') {
|
49 |
+
self::startSession();
|
50 |
+
return (isset($_SESSION[$variable])) ? $_SESSION[$variable] : false;
|
51 |
+
}
|
52 |
}
|
Includes/Shortcode.php
CHANGED
@@ -1,181 +1,181 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WPGDPRC\Includes;
|
4 |
-
|
5 |
-
/**
|
6 |
-
* Class Shortcode
|
7 |
-
* @package WPGDPRC\Includes
|
8 |
-
*/
|
9 |
-
class Shortcode {
|
10 |
-
/** @var null */
|
11 |
-
private static $instance = null;
|
12 |
-
|
13 |
-
/**
|
14 |
-
* @return string
|
15 |
-
*/
|
16 |
-
private static function getAccessRequestData() {
|
17 |
-
$output = '';
|
18 |
-
$token = (isset($_REQUEST['wpgdprc'])) ? esc_html(urldecode($_REQUEST['wpgdprc'])) : false;
|
19 |
-
$request = ($token !== false) ? AccessRequest::getInstance()->getByToken($token) : false;
|
20 |
-
if ($request !== false) {
|
21 |
-
if (
|
22 |
-
SessionHelper::checkSession($request->getSessionId()) &&
|
23 |
-
Helper::checkIpAddress($request->getIpAddress())
|
24 |
-
) {
|
25 |
-
$data = new Data($request->getEmailAddress());
|
26 |
-
$users = Data::getOutput($data->getUsers(), 'user', $request->getId());
|
27 |
-
$comments = Data::getOutput($data->getComments(), 'comment', $request->getId());
|
28 |
-
|
29 |
-
$output .= sprintf(
|
30 |
-
'<div class="wpgdprc-message wpgdprc-message--notice">%s</div>',
|
31 |
-
apply_filters('wpgdprc_the_content', Integration::getDeleteRequestFormExplanationText())
|
32 |
-
);
|
33 |
-
|
34 |
-
// WordPress Users
|
35 |
-
$output .= sprintf('<h2 class="wpgdprc-title">%s</h2>', __('Users', WP_GDPR_C_SLUG));
|
36 |
-
if (!empty($users)) {
|
37 |
-
$output .= $users;
|
38 |
-
} else {
|
39 |
-
$output .= sprintf(
|
40 |
-
'<div class="wpgdprc-message wpgdprc-message--notice">%s</div>',
|
41 |
-
sprintf(
|
42 |
-
__('No users found with email address %s.', WP_GDPR_C_SLUG),
|
43 |
-
sprintf('<strong>%s</strong>', $request->getEmailAddress())
|
44 |
-
)
|
45 |
-
);
|
46 |
-
}
|
47 |
-
|
48 |
-
// WordPress Comments
|
49 |
-
$output .= sprintf('<h2 class="wpgdprc-title">%s</h2>', __('Comments', WP_GDPR_C_SLUG));
|
50 |
-
if (!empty($comments)) {
|
51 |
-
$output .= $comments;
|
52 |
-
} else {
|
53 |
-
$output .= sprintf(
|
54 |
-
'<div class="wpgdprc-message wpgdprc-message--notice">%s</div>',
|
55 |
-
sprintf(
|
56 |
-
__('No comments found with email address %s.', WP_GDPR_C_SLUG),
|
57 |
-
sprintf('<strong>%s</strong>', $request->getEmailAddress())
|
58 |
-
)
|
59 |
-
);
|
60 |
-
}
|
61 |
-
|
62 |
-
// WooCommerce Orders
|
63 |
-
if (in_array('woocommerce/woocommerce.php', Helper::getActivePlugins())) {
|
64 |
-
$woocommerceOrders = Data::getOutput($data->getWooCommerceOrders(), 'woocommerce_order', $request->getId());
|
65 |
-
$output .= sprintf('<h2 class="wpgdprc-title">%s</h2>', __('WooCommerce Orders', WP_GDPR_C_SLUG));
|
66 |
-
if (!empty($woocommerceOrders)) {
|
67 |
-
$output .= $woocommerceOrders;
|
68 |
-
} else {
|
69 |
-
$output .= sprintf(
|
70 |
-
'<div class="wpgdprc-message wpgdprc-message--notice">%s</div>',
|
71 |
-
sprintf(
|
72 |
-
__('No WooCommerce orders found with email address %s.', WP_GDPR_C_SLUG),
|
73 |
-
sprintf('<strong>%s</strong>', $request->getEmailAddress())
|
74 |
-
)
|
75 |
-
);
|
76 |
-
}
|
77 |
-
}
|
78 |
-
|
79 |
-
$output = apply_filters('wpgdprc_request_data', $output, $data, $request);
|
80 |
-
} else {
|
81 |
-
$accessRequestPage = Helper::getAccessRequestPage();
|
82 |
-
$output .= sprintf(
|
83 |
-
'<div class="wpgdprc-message wpgdprc-message--error"><p>%s</p></div>',
|
84 |
-
sprintf(
|
85 |
-
__('<strong>ERROR</strong>: %s', WP_GDPR_C_SLUG),
|
86 |
-
sprintf(
|
87 |
-
'%s<br /><br />%s',
|
88 |
-
__('You are only able to view your data when visiting this page on the same device with the same IP and in the same browser session as when you performed your request. This is an extra security measure to keep your data safe.', WP_GDPR_C_SLUG),
|
89 |
-
sprintf(
|
90 |
-
__('If needed you can put in a new request after 24 hours here: %s.', WP_GDPR_C_SLUG),
|
91 |
-
sprintf(
|
92 |
-
'<a target="_blank" href="%s">%s</a>',
|
93 |
-
get_permalink($accessRequestPage),
|
94 |
-
get_the_title($accessRequestPage)
|
95 |
-
)
|
96 |
-
)
|
97 |
-
)
|
98 |
-
)
|
99 |
-
);
|
100 |
-
}
|
101 |
-
} else {
|
102 |
-
$output .= sprintf(
|
103 |
-
'<div class="wpgdprc-message wpgdprc-message--error"><p>%s</p></div>',
|
104 |
-
sprintf(
|
105 |
-
__('<strong>ERROR</strong>: %s', WP_GDPR_C_SLUG),
|
106 |
-
__('This request is expired or doesn\'t exist.', WP_GDPR_C_SLUG)
|
107 |
-
)
|
108 |
-
);
|
109 |
-
}
|
110 |
-
return $output;
|
111 |
-
}
|
112 |
-
|
113 |
-
/**
|
114 |
-
* @return string
|
115 |
-
*/
|
116 |
-
public function accessRequestForm() {
|
117 |
-
$output = '<div class="wpgdprc">';
|
118 |
-
if (isset($_REQUEST['wpgdprc'])) {
|
119 |
-
$output .= self::getAccessRequestData();
|
120 |
-
} else {
|
121 |
-
$output .= '<form class="wpgdprc-form wpgdprc-form--access-request" name="wpgdprc_form" method="POST">';
|
122 |
-
$output .= apply_filters(
|
123 |
-
'wpgdprc_request_form_email_field',
|
124 |
-
sprintf(
|
125 |
-
'<p><input type="email" name="wpgdprc_email" id="wpgdprc-form__email" placeholder="%s" required /></p>',
|
126 |
-
apply_filters('wpgdprc_request_form_email_label', esc_attr__('Your Email Address', WP_GDPR_C_SLUG))
|
127 |
-
)
|
128 |
-
);
|
129 |
-
$output .= apply_filters(
|
130 |
-
'wpgdprc_request_form_consent_field',
|
131 |
-
sprintf(
|
132 |
-
'<p><label><input type="checkbox" name="wpgdprc_consent" id="wpgdprc-form__consent" value="1" required /> %s</label></p>',
|
133 |
-
Integration::getAccessRequestFormCheckboxText()
|
134 |
-
)
|
135 |
-
);
|
136 |
-
$output .= apply_filters(
|
137 |
-
'wpgdprc_request_form_submit_field',
|
138 |
-
sprintf(
|
139 |
-
'<p><input type="submit" name="wpgdprc_submit" value="%s" /></p>',
|
140 |
-
apply_filters('wpgdprc_request_form_submit_label', esc_attr__('Send', WP_GDPR_C_SLUG))
|
141 |
-
)
|
142 |
-
);
|
143 |
-
$output .= '<div class="wpgdprc-message" style="display: none;"></div>';
|
144 |
-
$output .= '</form>';
|
145 |
-
$output = apply_filters('wpgdprc_request_form', $output);
|
146 |
-
}
|
147 |
-
$output .= '</div>';
|
148 |
-
return $output;
|
149 |
-
}
|
150 |
-
|
151 |
-
/**
|
152 |
-
* @param $attributes
|
153 |
-
* @param string $label
|
154 |
-
* @return string
|
155 |
-
*/
|
156 |
-
public function consentsSettingsLink($attributes, $label = '') {
|
157 |
-
$attributes = shortcode_atts(array(
|
158 |
-
'class' => '',
|
159 |
-
), $attributes, 'wpgdprc_consents_settings_link');
|
160 |
-
$label = (!empty($label)) ? esc_html($label) : __('My settings', WP_GDPR_C_SLUG);
|
161 |
-
$classes = explode(',', $attributes['class']);
|
162 |
-
$classes[] = 'wpgdprc-consents-settings-link';
|
163 |
-
$classes = implode(' ', $classes);
|
164 |
-
$output = sprintf(
|
165 |
-
'<a class="%s" href="javascript:void(0);" data-micromodal-trigger="wpgdprc-consent-modal">%s</a>',
|
166 |
-
esc_attr($classes),
|
167 |
-
$label
|
168 |
-
);
|
169 |
-
return $output;
|
170 |
-
}
|
171 |
-
|
172 |
-
/**
|
173 |
-
* @return null|Shortcode
|
174 |
-
*/
|
175 |
-
public static function getInstance() {
|
176 |
-
if (!isset(self::$instance)) {
|
177 |
-
self::$instance = new self();
|
178 |
-
}
|
179 |
-
return self::$instance;
|
180 |
-
}
|
181 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WPGDPRC\Includes;
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Class Shortcode
|
7 |
+
* @package WPGDPRC\Includes
|
8 |
+
*/
|
9 |
+
class Shortcode {
|
10 |
+
/** @var null */
|
11 |
+
private static $instance = null;
|
12 |
+
|
13 |
+
/**
|
14 |
+
* @return string
|
15 |
+
*/
|
16 |
+
private static function getAccessRequestData() {
|
17 |
+
$output = '';
|
18 |
+
$token = (isset($_REQUEST['wpgdprc'])) ? esc_html(urldecode($_REQUEST['wpgdprc'])) : false;
|
19 |
+
$request = ($token !== false) ? AccessRequest::getInstance()->getByToken($token) : false;
|
20 |
+
if ($request !== false) {
|
21 |
+
if (
|
22 |
+
SessionHelper::checkSession($request->getSessionId()) &&
|
23 |
+
Helper::checkIpAddress($request->getIpAddress())
|
24 |
+
) {
|
25 |
+
$data = new Data($request->getEmailAddress());
|
26 |
+
$users = Data::getOutput($data->getUsers(), 'user', $request->getId());
|
27 |
+
$comments = Data::getOutput($data->getComments(), 'comment', $request->getId());
|
28 |
+
|
29 |
+
$output .= sprintf(
|
30 |
+
'<div class="wpgdprc-message wpgdprc-message--notice">%s</div>',
|
31 |
+
apply_filters('wpgdprc_the_content', Integration::getDeleteRequestFormExplanationText())
|
32 |
+
);
|
33 |
+
|
34 |
+
// WordPress Users
|
35 |
+
$output .= sprintf('<h2 class="wpgdprc-title">%s</h2>', __('Users', WP_GDPR_C_SLUG));
|
36 |
+
if (!empty($users)) {
|
37 |
+
$output .= $users;
|
38 |
+
} else {
|
39 |
+
$output .= sprintf(
|
40 |
+
'<div class="wpgdprc-message wpgdprc-message--notice">%s</div>',
|
41 |
+
sprintf(
|
42 |
+
__('No users found with email address %s.', WP_GDPR_C_SLUG),
|
43 |
+
sprintf('<strong>%s</strong>', $request->getEmailAddress())
|
44 |
+
)
|
45 |
+
);
|
46 |
+
}
|
47 |
+
|
48 |
+
// WordPress Comments
|
49 |
+
$output .= sprintf('<h2 class="wpgdprc-title">%s</h2>', __('Comments', WP_GDPR_C_SLUG));
|
50 |
+
if (!empty($comments)) {
|
51 |
+
$output .= $comments;
|
52 |
+
} else {
|
53 |
+
$output .= sprintf(
|
54 |
+
'<div class="wpgdprc-message wpgdprc-message--notice">%s</div>',
|
55 |
+
sprintf(
|
56 |
+
__('No comments found with email address %s.', WP_GDPR_C_SLUG),
|
57 |
+
sprintf('<strong>%s</strong>', $request->getEmailAddress())
|
58 |
+
)
|
59 |
+
);
|
60 |
+
}
|
61 |
+
|
62 |
+
// WooCommerce Orders
|
63 |
+
if (in_array('woocommerce/woocommerce.php', Helper::getActivePlugins())) {
|
64 |
+
$woocommerceOrders = Data::getOutput($data->getWooCommerceOrders(), 'woocommerce_order', $request->getId());
|
65 |
+
$output .= sprintf('<h2 class="wpgdprc-title">%s</h2>', __('WooCommerce Orders', WP_GDPR_C_SLUG));
|
66 |
+
if (!empty($woocommerceOrders)) {
|
67 |
+
$output .= $woocommerceOrders;
|
68 |
+
} else {
|
69 |
+
$output .= sprintf(
|
70 |
+
'<div class="wpgdprc-message wpgdprc-message--notice">%s</div>',
|
71 |
+
sprintf(
|
72 |
+
__('No WooCommerce orders found with email address %s.', WP_GDPR_C_SLUG),
|
73 |
+
sprintf('<strong>%s</strong>', $request->getEmailAddress())
|
74 |
+
)
|
75 |
+
);
|
76 |
+
}
|
77 |
+
}
|
78 |
+
|
79 |
+
$output = apply_filters('wpgdprc_request_data', $output, $data, $request);
|
80 |
+
} else {
|
81 |
+
$accessRequestPage = Helper::getAccessRequestPage();
|
82 |
+
$output .= sprintf(
|
83 |
+
'<div class="wpgdprc-message wpgdprc-message--error"><p>%s</p></div>',
|
84 |
+
sprintf(
|
85 |
+
__('<strong>ERROR</strong>: %s', WP_GDPR_C_SLUG),
|
86 |
+
sprintf(
|
87 |
+
'%s<br /><br />%s',
|
88 |
+
__('You are only able to view your data when visiting this page on the same device with the same IP and in the same browser session as when you performed your request. This is an extra security measure to keep your data safe.', WP_GDPR_C_SLUG),
|
89 |
+
sprintf(
|
90 |
+
__('If needed you can put in a new request after 24 hours here: %s.', WP_GDPR_C_SLUG),
|
91 |
+
sprintf(
|
92 |
+
'<a target="_blank" href="%s">%s</a>',
|
93 |
+
get_permalink($accessRequestPage),
|
94 |
+
get_the_title($accessRequestPage)
|
95 |
+
)
|
96 |
+
)
|
97 |
+
)
|
98 |
+
)
|
99 |
+
);
|
100 |
+
}
|
101 |
+
} else {
|
102 |
+
$output .= sprintf(
|
103 |
+
'<div class="wpgdprc-message wpgdprc-message--error"><p>%s</p></div>',
|
104 |
+
sprintf(
|
105 |
+
__('<strong>ERROR</strong>: %s', WP_GDPR_C_SLUG),
|
106 |
+
__('This request is expired or doesn\'t exist.', WP_GDPR_C_SLUG)
|
107 |
+
)
|
108 |
+
);
|
109 |
+
}
|
110 |
+
return $output;
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* @return string
|
115 |
+
*/
|
116 |
+
public function accessRequestForm() {
|
117 |
+
$output = '<div class="wpgdprc">';
|
118 |
+
if (isset($_REQUEST['wpgdprc'])) {
|
119 |
+
$output .= self::getAccessRequestData();
|
120 |
+
} else {
|
121 |
+
$output .= '<form class="wpgdprc-form wpgdprc-form--access-request" name="wpgdprc_form" method="POST">';
|
122 |
+
$output .= apply_filters(
|
123 |
+
'wpgdprc_request_form_email_field',
|
124 |
+
sprintf(
|
125 |
+
'<p><input type="email" name="wpgdprc_email" id="wpgdprc-form__email" placeholder="%s" required /></p>',
|
126 |
+
apply_filters('wpgdprc_request_form_email_label', esc_attr__('Your Email Address', WP_GDPR_C_SLUG))
|
127 |
+
)
|
128 |
+
);
|
129 |
+
$output .= apply_filters(
|
130 |
+
'wpgdprc_request_form_consent_field',
|
131 |
+
sprintf(
|
132 |
+
'<p><label><input type="checkbox" name="wpgdprc_consent" id="wpgdprc-form__consent" value="1" required /> %s</label></p>',
|
133 |
+
Integration::getAccessRequestFormCheckboxText()
|
134 |
+
)
|
135 |
+
);
|
136 |
+
$output .= apply_filters(
|
137 |
+
'wpgdprc_request_form_submit_field',
|
138 |
+
sprintf(
|
139 |
+
'<p><input type="submit" name="wpgdprc_submit" value="%s" /></p>',
|
140 |
+
apply_filters('wpgdprc_request_form_submit_label', esc_attr__('Send', WP_GDPR_C_SLUG))
|
141 |
+
)
|
142 |
+
);
|
143 |
+
$output .= '<div class="wpgdprc-message" style="display: none;"></div>';
|
144 |
+
$output .= '</form>';
|
145 |
+
$output = apply_filters('wpgdprc_request_form', $output);
|
146 |
+
}
|
147 |
+
$output .= '</div>';
|
148 |
+
return $output;
|
149 |
+
}
|
150 |
+
|
151 |
+
/**
|
152 |
+
* @param $attributes
|
153 |
+
* @param string $label
|
154 |
+
* @return string
|
155 |
+
*/
|
156 |
+
public function consentsSettingsLink($attributes, $label = '') {
|
157 |
+
$attributes = shortcode_atts(array(
|
158 |
+
'class' => '',
|
159 |
+
), $attributes, 'wpgdprc_consents_settings_link');
|
160 |
+
$label = (!empty($label)) ? esc_html($label) : __('My settings', WP_GDPR_C_SLUG);
|
161 |
+
$classes = explode(',', $attributes['class']);
|
162 |
+
$classes[] = 'wpgdprc-consents-settings-link';
|
163 |
+
$classes = implode(' ', $classes);
|
164 |
+
$output = sprintf(
|
165 |
+
'<a class="%s" href="javascript:void(0);" data-micromodal-trigger="wpgdprc-consent-modal">%s</a>',
|
166 |
+
esc_attr($classes),
|
167 |
+
$label
|
168 |
+
);
|
169 |
+
return $output;
|
170 |
+
}
|
171 |
+
|
172 |
+
/**
|
173 |
+
* @return null|Shortcode
|
174 |
+
*/
|
175 |
+
public static function getInstance() {
|
176 |
+
if (!isset(self::$instance)) {
|
177 |
+
self::$instance = new self();
|
178 |
+
}
|
179 |
+
return self::$instance;
|
180 |
+
}
|
181 |
}
|
assets/css/admin.css
CHANGED
@@ -1,698 +1,698 @@
|
|
1 |
-
@keyframes wpgdprc-stars {
|
2 |
-
1% {
|
3 |
-
background-position: 0;
|
4 |
-
}
|
5 |
-
2% {
|
6 |
-
background-position: 30px;
|
7 |
-
}
|
8 |
-
3% {
|
9 |
-
background-position: 60px;
|
10 |
-
}
|
11 |
-
4% {
|
12 |
-
background-position: 90px;
|
13 |
-
}
|
14 |
-
5% {
|
15 |
-
background-position: 120px;
|
16 |
-
}
|
17 |
-
6% {
|
18 |
-
background-position: 150px;
|
19 |
-
}
|
20 |
-
7% {
|
21 |
-
background-position: 180px;
|
22 |
-
}
|
23 |
-
8% {
|
24 |
-
background-position: 210px;
|
25 |
-
}
|
26 |
-
9% {
|
27 |
-
background-position: 240px;
|
28 |
-
}
|
29 |
-
100% {
|
30 |
-
background-position: 240px;
|
31 |
-
}
|
32 |
-
}
|
33 |
-
|
34 |
-
.wpgdprc-clearfix:before, .wpgdprc-clearfix:after {
|
35 |
-
content: " ";
|
36 |
-
display: table;
|
37 |
-
}
|
38 |
-
|
39 |
-
.wpgdprc-clearfix:after {
|
40 |
-
clear: both;
|
41 |
-
}
|
42 |
-
|
43 |
-
.wpgdprc-clearfix {
|
44 |
-
*zoom: 1;
|
45 |
-
}
|
46 |
-
|
47 |
-
.tools_page_wp_gdpr_compliance {
|
48 |
-
background: #FFFFFF;
|
49 |
-
}
|
50 |
-
|
51 |
-
.tools_page_wp_gdpr_compliance #wpfooter {
|
52 |
-
display: none !important;
|
53 |
-
}
|
54 |
-
|
55 |
-
.wpgdprc *, .wpgdprc *:before, .wpgdprc *:after {
|
56 |
-
-webkit-box-sizing: inherit;
|
57 |
-
-moz-box-sizing: inherit;
|
58 |
-
box-sizing: inherit;
|
59 |
-
}
|
60 |
-
|
61 |
-
.wpgdprc {
|
62 |
-
display: flex;
|
63 |
-
padding: 20px;
|
64 |
-
-webkit-box-sizing: border-box;
|
65 |
-
-moz-box-sizing: border-box;
|
66 |
-
box-sizing: border-box;
|
67 |
-
font-family: "Helvetica Neue", Helvetica, Roboto, Arial, sans-serif;
|
68 |
-
font-weight: normal;
|
69 |
-
font-size: 14px;
|
70 |
-
line-height: 1.4;
|
71 |
-
color: #0A0A0A;
|
72 |
-
flex-direction: row;
|
73 |
-
}
|
74 |
-
|
75 |
-
.wpgdprc h1, .wpgdprc h2, .wpgdprc p {
|
76 |
-
color: inherit;
|
77 |
-
}
|
78 |
-
|
79 |
-
.wpgdprc p {
|
80 |
-
font-size: inherit;
|
81 |
-
line-height: inherit;
|
82 |
-
}
|
83 |
-
|
84 |
-
.wpgdprc a {
|
85 |
-
color: #4AA94F;
|
86 |
-
}
|
87 |
-
|
88 |
-
.wpgdprc pre, .wpgdprc span.wpgdprc-pre {
|
89 |
-
display: inline;
|
90 |
-
white-space: pre-wrap;
|
91 |
-
white-space: -moz-pre-wrap;
|
92 |
-
white-space: -pre-wrap;
|
93 |
-
white-space: -o-pre-wrap;
|
94 |
-
word-wrap: break-word;
|
95 |
-
font-family: monospace;
|
96 |
-
font-style: normal;
|
97 |
-
}
|
98 |
-
|
99 |
-
.wpgdprc .wpgdprc-status--processing,
|
100 |
-
.wpgdprc .wpgdprc-status--removed {
|
101 |
-
pointer-events: none;
|
102 |
-
}
|
103 |
-
|
104 |
-
.wpgdprc .wpgdprc-status--processing {
|
105 |
-
opacity: .5;
|
106 |
-
}
|
107 |
-
|
108 |
-
.wpgdprc .wpgdprc-status--removed {
|
109 |
-
opacity: .2;
|
110 |
-
text-decoration: line-through;
|
111 |
-
}
|
112 |
-
|
113 |
-
.wpgdprc .wpgdprc-status--error {
|
114 |
-
background-color: #F7E4E1;
|
115 |
-
border-color: #CC4B37;
|
116 |
-
color: #CC4B37;
|
117 |
-
}
|
118 |
-
|
119 |
-
div.wpgdprc-information {
|
120 |
-
font-size: 12px;
|
121 |
-
color: #8A8A8A;
|
122 |
-
}
|
123 |
-
|
124 |
-
div.wpgdprc-message {
|
125 |
-
padding: 10px;
|
126 |
-
border: 1px solid transparent;
|
127 |
-
}
|
128 |
-
|
129 |
-
div.wpgdprc-message p:first-child {
|
130 |
-
margin-top: 0;
|
131 |
-
}
|
132 |
-
|
133 |
-
div.wpgdprc-message p:last-child {
|
134 |
-
margin-bottom: 0;
|
135 |
-
}
|
136 |
-
|
137 |
-
div.wpgdprc-message--notice {
|
138 |
-
background: #FFF3D9;
|
139 |
-
border-color: #E7D996;
|
140 |
-
}
|
141 |
-
|
142 |
-
div.wpgdprc-message--error {
|
143 |
-
background: #F7E4E1;
|
144 |
-
border-color: #CC4B37;
|
145 |
-
color: #CC4B37;
|
146 |
-
}
|
147 |
-
|
148 |
-
div.wpgdprc-message--success {
|
149 |
-
background: #E1FAEA;
|
150 |
-
border-color: #5B9C73;
|
151 |
-
color: #5B9C73;
|
152 |
-
}
|
153 |
-
|
154 |
-
div.wpgdprc-message + form.wpgdprc-form {
|
155 |
-
margin-top: 20px;
|
156 |
-
}
|
157 |
-
|
158 |
-
.wpgdprc p.submit {
|
159 |
-
padding-top: 0;
|
160 |
-
padding-bottom: 0;
|
161 |
-
}
|
162 |
-
|
163 |
-
.wpgdprc .button {
|
164 |
-
vertical-align: top;
|
165 |
-
-webkit-box-shadow: none;
|
166 |
-
-moz-box-shadow: none;
|
167 |
-
box-shadow: none;
|
168 |
-
text-shadow: none;
|
169 |
-
font-size: inherit;
|
170 |
-
font-weight: bold;
|
171 |
-
}
|
172 |
-
|
173 |
-
.wpgdprc .button.button-primary {
|
174 |
-
background: #4AA94F;
|
175 |
-
border-top-color: #459D49;
|
176 |
-
border-right-color: #419546;
|
177 |
-
border-bottom-color: #419546;
|
178 |
-
border-left-color: #419546;
|
179 |
-
}
|
180 |
-
|
181 |
-
h1.wpgdprc-title {
|
182 |
-
margin-bottom: 20px;
|
183 |
-
font-weight: 700;
|
184 |
-
font-size: 36px;
|
185 |
-
}
|
186 |
-
|
187 |
-
h1.wpgdprc-title span {
|
188 |
-
font-weight: 400;
|
189 |
-
font-size: 18px;
|
190 |
-
color: #8A8A8A;
|
191 |
-
}
|
192 |
-
|
193 |
-
div.wpgdprc-description {
|
194 |
-
margin-top: 20px;
|
195 |
-
padding: 20px;
|
196 |
-
background: #F3F3F3;
|
197 |
-
border-bottom: 2px solid #DFDFDF;
|
198 |
-
border-radius: 5px;
|
199 |
-
}
|
200 |
-
|
201 |
-
div.wpgdprc-description p {
|
202 |
-
margin-bottom: 0;
|
203 |
-
}
|
204 |
-
|
205 |
-
div.wpgdprc-description p:first-child {
|
206 |
-
margin-top: 0;
|
207 |
-
}
|
208 |
-
|
209 |
-
p.wpgdprc-disclaimer {
|
210 |
-
font-size: small;
|
211 |
-
color: #8A8A8A;
|
212 |
-
}
|
213 |
-
|
214 |
-
div.wpgdprc-message + table.wpgdprc-table {
|
215 |
-
margin-top: 20px;
|
216 |
-
}
|
217 |
-
|
218 |
-
table.wpgdprc-table {
|
219 |
-
width: 100%;
|
220 |
-
border: 1px solid #DBD6D6;
|
221 |
-
table-layout: fixed;
|
222 |
-
}
|
223 |
-
|
224 |
-
table.wpgdprc-table th, table.wpgdprc-table td {
|
225 |
-
padding: 5px;
|
226 |
-
word-break: break-word;
|
227 |
-
-webkit-hyphens: auto;
|
228 |
-
-ms-hyphens: auto;
|
229 |
-
hyphens: auto;
|
230 |
-
}
|
231 |
-
|
232 |
-
table.wpgdprc-table th {
|
233 |
-
background-color: #DBD6D6;
|
234 |
-
text-align: start;
|
235 |
-
}
|
236 |
-
|
237 |
-
table.wpgdprc-table tr:nth-child(even) {
|
238 |
-
background-color: #F1F1F1;
|
239 |
-
}
|
240 |
-
|
241 |
-
table.wpgdprc-table tr.wpgdprc-table__row--expired {
|
242 |
-
opacity: .5;
|
243 |
-
}
|
244 |
-
|
245 |
-
.wpgdprc-background {
|
246 |
-
position: fixed;
|
247 |
-
right: 0;
|
248 |
-
bottom: -10px;
|
249 |
-
left: 0;
|
250 |
-
z-index: -1;
|
251 |
-
}
|
252 |
-
|
253 |
-
.wpgdprc-background g {
|
254 |
-
fill: #4AA94F;
|
255 |
-
}
|
256 |
-
|
257 |
-
.wpgdprc-contents {
|
258 |
-
flex: 11;
|
259 |
-
}
|
260 |
-
|
261 |
-
.wpgdprc-sidebar {
|
262 |
-
padding: 0 20px;
|
263 |
-
flex: 3;
|
264 |
-
align-items: flex-start;
|
265 |
-
align-content: flex-start;
|
266 |
-
}
|
267 |
-
|
268 |
-
.wpgdprc-sidebar-block {
|
269 |
-
margin-bottom: 20px;
|
270 |
-
padding: 20px;
|
271 |
-
background: #F3F3F3;
|
272 |
-
border-bottom: 2px solid #DFDFDF;
|
273 |
-
border-radius: 5px;
|
274 |
-
}
|
275 |
-
|
276 |
-
.wpgdprc-sidebar-block h3 {
|
277 |
-
display: inline-block;
|
278 |
-
margin: 0;
|
279 |
-
}
|
280 |
-
|
281 |
-
.wpgdprc-sidebar-block--no-background {
|
282 |
-
padding: 0;
|
283 |
-
background: none;
|
284 |
-
border: 0;
|
285 |
-
}
|
286 |
-
|
287 |
-
.wpgdprc-sidebar-donate {
|
288 |
-
margin: 5px 0 0 10px;
|
289 |
-
display: inline-block;
|
290 |
-
float: right;
|
291 |
-
}
|
292 |
-
|
293 |
-
.wpgdprc-navigation {
|
294 |
-
border-bottom: 1px solid #DBD6D6;
|
295 |
-
}
|
296 |
-
|
297 |
-
.wpgdprc-navigation > a {
|
298 |
-
position: relative;
|
299 |
-
display: block;
|
300 |
-
float: left;
|
301 |
-
margin-bottom: -1px;
|
302 |
-
padding: 12px 16px;
|
303 |
-
background-color: #E9E9E9;
|
304 |
-
border: 1px solid transparent;
|
305 |
-
border-left-color: #F1F1F1;
|
306 |
-
-webkit-box-shadow: none;
|
307 |
-
-moz-box-shadow: none;
|
308 |
-
box-shadow: none;
|
309 |
-
text-decoration: none;
|
310 |
-
font-weight: 500;
|
311 |
-
line-height: 1;
|
312 |
-
color: inherit;
|
313 |
-
}
|
314 |
-
|
315 |
-
.wpgdprc-navigation > a.wpgdprc-active {
|
316 |
-
background-color: #fff;
|
317 |
-
color: #4AA94F;
|
318 |
-
border-top-color: #DBD6D6;
|
319 |
-
border-right-color: #DBD6D6;
|
320 |
-
border-left-color: #DBD6D6;
|
321 |
-
}
|
322 |
-
|
323 |
-
.wpgdprc-navigation span.wpgdprc-badge {
|
324 |
-
position: absolute;
|
325 |
-
top: -5px;
|
326 |
-
right: -5px;
|
327 |
-
display: block;
|
328 |
-
width: 20px;
|
329 |
-
height: 20px;
|
330 |
-
background-color: #4AA94F;
|
331 |
-
border-radius: 50%;
|
332 |
-
text-align: center;
|
333 |
-
line-height: 20px;
|
334 |
-
font-size: 11px;
|
335 |
-
color: #FFFFFF;
|
336 |
-
z-index: 1;
|
337 |
-
}
|
338 |
-
|
339 |
-
.wpgdprc-content {
|
340 |
-
display: block;
|
341 |
-
background-color: #fff;
|
342 |
-
border: 1px solid #DBD6D6;
|
343 |
-
border-top: none;
|
344 |
-
padding: 20px;
|
345 |
-
}
|
346 |
-
|
347 |
-
.wpgdprc-content > p:first-child {
|
348 |
-
margin-top: 0;
|
349 |
-
}
|
350 |
-
|
351 |
-
.wpgdprc-list {
|
352 |
-
margin: -20px 0;
|
353 |
-
list-style: none;
|
354 |
-
}
|
355 |
-
|
356 |
-
.wpgdprc-list li {
|
357 |
-
margin-bottom: 0;
|
358 |
-
}
|
359 |
-
|
360 |
-
.wpgdprc-list > li {
|
361 |
-
padding: 20px 0;
|
362 |
-
border-top: 2px solid #EDEDED;
|
363 |
-
}
|
364 |
-
|
365 |
-
.wpgdprc-list > li:first-child {
|
366 |
-
border-top: none;
|
367 |
-
}
|
368 |
-
|
369 |
-
.wpgdprc-checkbox {
|
370 |
-
position: relative;
|
371 |
-
}
|
372 |
-
|
373 |
-
.wpgdprc-checkbox input[type="checkbox"] {
|
374 |
-
display: none;
|
375 |
-
}
|
376 |
-
|
377 |
-
.wpgdprc-checkbox input[type="checkbox"]:checked:not(.processing) ~ .wpgdprc-switch .wpgdprc-switch-label .wpgdprc-switch-inner {
|
378 |
-
margin-left: 0;
|
379 |
-
}
|
380 |
-
|
381 |
-
.wpgdprc-checkbox input[type="checkbox"]:checked:not(.processing) ~ .wpgdprc-switch .wpgdprc-switch-label .wpgdprc-switch-switch {
|
382 |
-
right: 1px;
|
383 |
-
}
|
384 |
-
|
385 |
-
.wpgdprc-checkbox input[type="checkbox"].processing ~ label {
|
386 |
-
pointer-events: none;
|
387 |
-
}
|
388 |
-
|
389 |
-
.wpgdprc-checkbox input[type="checkbox"].processing ~ .wpgdprc-switch .wpgdprc-switch-label .wpgdprc-switch-inner {
|
390 |
-
margin-left: -50%;
|
391 |
-
}
|
392 |
-
|
393 |
-
.wpgdprc-checkbox input[type="checkbox"].processing ~ .wpgdprc-switch .wpgdprc-switch-label .wpgdprc-switch-switch {
|
394 |
-
right: 50%;
|
395 |
-
-webkit-transform: translateX(50%);
|
396 |
-
-moz-transform: translateX(50%);
|
397 |
-
-ms-transform: translateX(50%);
|
398 |
-
-o-transform: translateX(50%);
|
399 |
-
transform: translateX(50%);
|
400 |
-
}
|
401 |
-
|
402 |
-
.wpgdprc-checkbox label {
|
403 |
-
display: block;
|
404 |
-
position: relative;
|
405 |
-
user-select: none;
|
406 |
-
z-index: 1;
|
407 |
-
font-weight: bold;
|
408 |
-
}
|
409 |
-
|
410 |
-
span.wpgdprc-instructions {
|
411 |
-
position: absolute;
|
412 |
-
top: 50%;
|
413 |
-
right: 80px;
|
414 |
-
transform: translateY(-50%);
|
415 |
-
font-size: 12px;
|
416 |
-
}
|
417 |
-
|
418 |
-
.wpgdprc-switch {
|
419 |
-
position: absolute;
|
420 |
-
top: 50%;
|
421 |
-
right: 0;
|
422 |
-
transform: translateY(-50%);
|
423 |
-
width: 65px;
|
424 |
-
font-size: 12px;
|
425 |
-
}
|
426 |
-
|
427 |
-
.wpgdprc-switch .wpgdprc-switch-label {
|
428 |
-
display: block;
|
429 |
-
margin: 0;
|
430 |
-
-webkit-border-radius: 30px;
|
431 |
-
-moz-border-radius: 30px;
|
432 |
-
border-radius: 30px;
|
433 |
-
overflow: hidden;
|
434 |
-
cursor: pointer;
|
435 |
-
}
|
436 |
-
|
437 |
-
.wpgdprc-switch .wpgdprc-switch-inner {
|
438 |
-
margin-left: -100%;
|
439 |
-
width: 200%;
|
440 |
-
transition: all 0.15s ease-in-out;
|
441 |
-
}
|
442 |
-
|
443 |
-
.wpgdprc-switch .wpgdprc-switch-inner:before,
|
444 |
-
.wpgdprc-switch .wpgdprc-switch-inner:after {
|
445 |
-
float: left;
|
446 |
-
width: 50%;
|
447 |
-
text-transform: uppercase;
|
448 |
-
line-height: 30px;
|
449 |
-
color: #FFFFFF;
|
450 |
-
content: '';
|
451 |
-
}
|
452 |
-
|
453 |
-
.wpgdprc-switch .wpgdprc-switch-inner:before {
|
454 |
-
padding-left: 10px;
|
455 |
-
background-color: #4AA94F;
|
456 |
-
}
|
457 |
-
|
458 |
-
.wpgdprc-switch .wpgdprc-switch-inner:after {
|
459 |
-
padding-right: 10px;
|
460 |
-
background-color: #0A0A0A;
|
461 |
-
text-align: right;
|
462 |
-
}
|
463 |
-
|
464 |
-
.wpgdprc-switch--reverse .wpgdprc-switch-inner:before {
|
465 |
-
background-color: #FFAE00;
|
466 |
-
}
|
467 |
-
|
468 |
-
.wpgdprc-switch .wpgdprc-switch-switch {
|
469 |
-
position: absolute;
|
470 |
-
top: 1px;
|
471 |
-
right: 36px;
|
472 |
-
bottom: 0;
|
473 |
-
margin: 0;
|
474 |
-
width: 28px;
|
475 |
-
height: 28px;
|
476 |
-
background: #FFFFFF;
|
477 |
-
-webkit-border-radius: 50%;
|
478 |
-
-moz-border-radius: 50%;
|
479 |
-
border-radius: 50%;
|
480 |
-
-webkit-box-shadow: 0 0 3px rgba(0, 0, 0, .3);
|
481 |
-
-moz-box-shadow: 0 0 3px rgba(0, 0, 0, .3);
|
482 |
-
box-shadow: 0 0 3px rgba(0, 0, 0, .3);
|
483 |
-
transition: all 0.15s ease-in-out;
|
484 |
-
}
|
485 |
-
|
486 |
-
.wpgdprc-checkbox-data {
|
487 |
-
margin-top: 10px;
|
488 |
-
}
|
489 |
-
|
490 |
-
.wpgdprc-checkbox-data p:first-child {
|
491 |
-
margin-top: 0;
|
492 |
-
}
|
493 |
-
|
494 |
-
.wpgdprc-checklist-description {
|
495 |
-
color: #8A8A8A;
|
496 |
-
}
|
497 |
-
|
498 |
-
.wpgdprc-checklist-description + .wpgdprc-message {
|
499 |
-
margin-top: 10px;
|
500 |
-
}
|
501 |
-
|
502 |
-
.wpgdprc-checklist-options {
|
503 |
-
margin-top: 10px;
|
504 |
-
}
|
505 |
-
|
506 |
-
.wpgdprc-checklist-options .wpgdprc-checkbox input[type="checkbox"] {
|
507 |
-
display: block;
|
508 |
-
position: absolute;
|
509 |
-
top: 50%;
|
510 |
-
right: 0;
|
511 |
-
margin: 0;
|
512 |
-
transform: translateY(-50%);
|
513 |
-
}
|
514 |
-
|
515 |
-
.wpgdprc-checklist-options span.wpgdprc-instructions {
|
516 |
-
right: 30px;
|
517 |
-
}
|
518 |
-
|
519 |
-
.wpgdprc-checklist-options li {
|
520 |
-
margin-top: 10px;
|
521 |
-
padding: 20px;
|
522 |
-
background-color: #FAFAFA;
|
523 |
-
border: 1px solid #F0F0F0;
|
524 |
-
}
|
525 |
-
|
526 |
-
.wpgdprc-checklist-options li:first-child {
|
527 |
-
margin-top: 0;
|
528 |
-
}
|
529 |
-
|
530 |
-
.wpgdprc-setting {
|
531 |
-
margin: 1em 0;
|
532 |
-
*zoom: 1;
|
533 |
-
}
|
534 |
-
|
535 |
-
.wpgdprc-setting:before, .wpgdprc-setting:after {
|
536 |
-
display: table;
|
537 |
-
content: " ";
|
538 |
-
}
|
539 |
-
|
540 |
-
.wpgdprc-setting:after {
|
541 |
-
clear: both;
|
542 |
-
}
|
543 |
-
|
544 |
-
.wpgdprc-setting:first-child {
|
545 |
-
margin-top: 0;
|
546 |
-
}
|
547 |
-
|
548 |
-
.wpgdprc-setting:last-child {
|
549 |
-
margin-bottom: 0;
|
550 |
-
}
|
551 |
-
|
552 |
-
.wpgdprc-setting label {
|
553 |
-
display: inline-block;
|
554 |
-
vertical-align: top;
|
555 |
-
}
|
556 |
-
|
557 |
-
.wpgdprc-setting label input[type="checkbox"] {
|
558 |
-
margin-top: 0 !important;
|
559 |
-
}
|
560 |
-
|
561 |
-
.wpgdprc-setting input[type="text"], .wpgdprc-setting textarea, .wpgdprc-setting select {
|
562 |
-
display: block;
|
563 |
-
margin: 0;
|
564 |
-
width: 100%;
|
565 |
-
-webkit-box-shadow: none;
|
566 |
-
-moz-box-shadow: none;
|
567 |
-
box-shadow: none;
|
568 |
-
font-size: inherit;
|
569 |
-
}
|
570 |
-
|
571 |
-
.wpgdprc-setting input[type="text"], .wpgdprc-setting textarea {
|
572 |
-
background-color: #FFFFFF;
|
573 |
-
}
|
574 |
-
|
575 |
-
.wpgdprc-setting select {
|
576 |
-
background-color: #FAFAFA;
|
577 |
-
}
|
578 |
-
|
579 |
-
.wpgdprc-setting .wpgdprc-information {
|
580 |
-
margin-top: .5em;
|
581 |
-
}
|
582 |
-
|
583 |
-
.wpgdprc-setting .wpgdprc-information p {
|
584 |
-
margin-top: 0;
|
585 |
-
margin-bottom: .5em;
|
586 |
-
}
|
587 |
-
|
588 |
-
.wpgdprc-setting .wpgdprc-information p:last-child {
|
589 |
-
margin-bottom: 0;
|
590 |
-
}
|
591 |
-
|
592 |
-
.wpgdprc-pagination {
|
593 |
-
margin-top: 20px;
|
594 |
-
line-height: 28px;
|
595 |
-
}
|
596 |
-
|
597 |
-
.wpgdprc-pagination .page-numbers {
|
598 |
-
display: inline-block;
|
599 |
-
vertical-align: top;
|
600 |
-
width: 30px;
|
601 |
-
background-color: #FFFFFF;
|
602 |
-
border: 1px solid #DBD6D6;
|
603 |
-
text-align: center;
|
604 |
-
text-decoration: none;
|
605 |
-
}
|
606 |
-
|
607 |
-
.wpgdprc-pagination .page-numbers + .wpgdprc-pagination__results {
|
608 |
-
margin-left: 10px;
|
609 |
-
}
|
610 |
-
|
611 |
-
.wpgdprc-stars {
|
612 |
-
margin: 15px auto;
|
613 |
-
width: 150px;
|
614 |
-
height: 30px;
|
615 |
-
background: url('../svg/stars.svg');
|
616 |
-
animation: wpgdprc-stars 4.5s steps(1, end) infinite;
|
617 |
-
-webkit-animation: wpgdprc-stars 4.5s steps(1, end) infinite;
|
618 |
-
-moz-animation: wpgdprc-stars 4.5s steps(1, end) infinite;
|
619 |
-
-o-animation: wpgdprc-stars 4.5s steps(1, end) infinite;
|
620 |
-
}
|
621 |
-
|
622 |
-
.CodeMirror {
|
623 |
-
border: 1px solid #DDDDDD;
|
624 |
-
}
|
625 |
-
|
626 |
-
@media screen and (max-width: 639px) {
|
627 |
-
.wpgdprc-instructions {
|
628 |
-
display: none;
|
629 |
-
}
|
630 |
-
}
|
631 |
-
|
632 |
-
@media screen and (max-width: 782px) {
|
633 |
-
.wpgdprc-checklist-options span.wpgdprc-instructions {
|
634 |
-
right: 40px;
|
635 |
-
}
|
636 |
-
}
|
637 |
-
|
638 |
-
@media screen and (min-width: 768px) {
|
639 |
-
.wpgdprc-setting label {
|
640 |
-
width: 100%;
|
641 |
-
max-width: 30%;
|
642 |
-
}
|
643 |
-
|
644 |
-
.wpgdprc-options {
|
645 |
-
float: right;
|
646 |
-
width: 100%;
|
647 |
-
max-width: 70%;
|
648 |
-
}
|
649 |
-
}
|
650 |
-
|
651 |
-
@media screen and (min-width: 783px) {
|
652 |
-
.wpgdprc .button {
|
653 |
-
height: 34px;
|
654 |
-
line-height: 32px;
|
655 |
-
}
|
656 |
-
}
|
657 |
-
|
658 |
-
@media screen and (max-width: 1400px) {
|
659 |
-
.wpgdprc {
|
660 |
-
display: block;
|
661 |
-
}
|
662 |
-
|
663 |
-
.wpgdprc-contents, .wpgdprc-sidebar {
|
664 |
-
display: block;
|
665 |
-
max-width: 100%;
|
666 |
-
width: 100%;
|
667 |
-
}
|
668 |
-
|
669 |
-
.wpgdprc-sidebar {
|
670 |
-
display: flex;
|
671 |
-
margin-top: 30px;
|
672 |
-
padding-right: 0;
|
673 |
-
padding-left: 0;
|
674 |
-
}
|
675 |
-
|
676 |
-
.wpgdprc-sidebar-block {
|
677 |
-
margin-right: 15px;
|
678 |
-
margin-left: 15px;
|
679 |
-
width: 33.33333%;
|
680 |
-
}
|
681 |
-
}
|
682 |
-
|
683 |
-
@media screen and (min-width: 320px) and (max-width: 840px) {
|
684 |
-
.wpgdprc-sidebar {
|
685 |
-
display: block;
|
686 |
-
}
|
687 |
-
|
688 |
-
.wpgdprc-sidebar-block {
|
689 |
-
max-width: 400px;
|
690 |
-
width: 100%;
|
691 |
-
margin-right: auto;
|
692 |
-
margin-left: auto;
|
693 |
-
}
|
694 |
-
|
695 |
-
.wpgdprc .button.button-primary {
|
696 |
-
height: auto;
|
697 |
-
}
|
698 |
}
|
1 |
+
@keyframes wpgdprc-stars {
|
2 |
+
1% {
|
3 |
+
background-position: 0;
|
4 |
+
}
|
5 |
+
2% {
|
6 |
+
background-position: 30px;
|
7 |
+
}
|
8 |
+
3% {
|
9 |
+
background-position: 60px;
|
10 |
+
}
|
11 |
+
4% {
|
12 |
+
background-position: 90px;
|
13 |
+
}
|
14 |
+
5% {
|
15 |
+
background-position: 120px;
|
16 |
+
}
|
17 |
+
6% {
|
18 |
+
background-position: 150px;
|
19 |
+
}
|
20 |
+
7% {
|
21 |
+
background-position: 180px;
|
22 |
+
}
|
23 |
+
8% {
|
24 |
+
background-position: 210px;
|
25 |
+
}
|
26 |
+
9% {
|
27 |
+
background-position: 240px;
|
28 |
+
}
|
29 |
+
100% {
|
30 |
+
background-position: 240px;
|
31 |
+
}
|
32 |
+
}
|
33 |
+
|
34 |
+
.wpgdprc-clearfix:before, .wpgdprc-clearfix:after {
|
35 |
+
content: " ";
|
36 |
+
display: table;
|
37 |
+
}
|
38 |
+
|
39 |
+
.wpgdprc-clearfix:after {
|
40 |
+
clear: both;
|
41 |
+
}
|
42 |
+
|
43 |
+
.wpgdprc-clearfix {
|
44 |
+
*zoom: 1;
|
45 |
+
}
|
46 |
+
|
47 |
+
.tools_page_wp_gdpr_compliance {
|
48 |
+
background: #FFFFFF;
|
49 |
+
}
|
50 |
+
|
51 |
+
.tools_page_wp_gdpr_compliance #wpfooter {
|
52 |
+
display: none !important;
|
53 |
+
}
|
54 |
+
|
55 |
+
.wpgdprc *, .wpgdprc *:before, .wpgdprc *:after {
|
56 |
+
-webkit-box-sizing: inherit;
|
57 |
+
-moz-box-sizing: inherit;
|
58 |
+
box-sizing: inherit;
|
59 |
+
}
|
60 |
+
|
61 |
+
.wpgdprc {
|
62 |
+
display: flex;
|
63 |
+
padding: 20px;
|
64 |
+
-webkit-box-sizing: border-box;
|
65 |
+
-moz-box-sizing: border-box;
|
66 |
+
box-sizing: border-box;
|
67 |
+
font-family: "Helvetica Neue", Helvetica, Roboto, Arial, sans-serif;
|
68 |
+
font-weight: normal;
|
69 |
+
font-size: 14px;
|
70 |
+
line-height: 1.4;
|
71 |
+
color: #0A0A0A;
|
72 |
+
flex-direction: row;
|
73 |
+
}
|
74 |
+
|
75 |
+
.wpgdprc h1, .wpgdprc h2, .wpgdprc p {
|
76 |
+
color: inherit;
|
77 |
+
}
|
78 |
+
|
79 |
+
.wpgdprc p {
|
80 |
+
font-size: inherit;
|
81 |
+
line-height: inherit;
|
82 |
+
}
|
83 |
+
|
84 |
+
.wpgdprc a {
|
85 |
+
color: #4AA94F;
|
86 |
+
}
|
87 |
+
|
88 |
+
.wpgdprc pre, .wpgdprc span.wpgdprc-pre {
|
89 |
+
display: inline;
|
90 |
+
white-space: pre-wrap;
|
91 |
+
white-space: -moz-pre-wrap;
|
92 |
+
white-space: -pre-wrap;
|
93 |
+
white-space: -o-pre-wrap;
|
94 |
+
word-wrap: break-word;
|
95 |
+
font-family: monospace;
|
96 |
+
font-style: normal;
|
97 |
+
}
|
98 |
+
|
99 |
+
.wpgdprc .wpgdprc-status--processing,
|
100 |
+
.wpgdprc .wpgdprc-status--removed {
|
101 |
+
pointer-events: none;
|
102 |
+
}
|
103 |
+
|
104 |
+
.wpgdprc .wpgdprc-status--processing {
|
105 |
+
opacity: .5;
|
106 |
+
}
|
107 |
+
|
108 |
+
.wpgdprc .wpgdprc-status--removed {
|
109 |
+
opacity: .2;
|
110 |
+
text-decoration: line-through;
|
111 |
+
}
|
112 |
+
|
113 |
+
.wpgdprc .wpgdprc-status--error {
|
114 |
+
background-color: #F7E4E1;
|
115 |
+
border-color: #CC4B37;
|
116 |
+
color: #CC4B37;
|
117 |
+
}
|
118 |
+
|
119 |
+
div.wpgdprc-information {
|
120 |
+
font-size: 12px;
|
121 |
+
color: #8A8A8A;
|
122 |
+
}
|
123 |
+
|
124 |
+
div.wpgdprc-message {
|
125 |
+
padding: 10px;
|
126 |
+
border: 1px solid transparent;
|
127 |
+
}
|
128 |
+
|
129 |
+
div.wpgdprc-message p:first-child {
|
130 |
+
margin-top: 0;
|
131 |
+
}
|
132 |
+
|
133 |
+
div.wpgdprc-message p:last-child {
|
134 |
+
margin-bottom: 0;
|
135 |
+
}
|
136 |
+
|
137 |
+
div.wpgdprc-message--notice {
|
138 |
+
background: #FFF3D9;
|
139 |
+
border-color: #E7D996;
|
140 |
+
}
|
141 |
+
|
142 |
+
div.wpgdprc-message--error {
|
143 |
+
background: #F7E4E1;
|
144 |
+
border-color: #CC4B37;
|
145 |
+
color: #CC4B37;
|
146 |
+
}
|
147 |
+
|
148 |
+
div.wpgdprc-message--success {
|
149 |
+
background: #E1FAEA;
|
150 |
+
border-color: #5B9C73;
|
151 |
+
color: #5B9C73;
|
152 |
+
}
|
153 |
+
|
154 |
+
div.wpgdprc-message + form.wpgdprc-form {
|
155 |
+
margin-top: 20px;
|
156 |
+
}
|
157 |
+
|
158 |
+
.wpgdprc p.submit {
|
159 |
+
padding-top: 0;
|
160 |
+
padding-bottom: 0;
|
161 |
+
}
|
162 |
+
|
163 |
+
.wpgdprc .button {
|
164 |
+
vertical-align: top;
|
165 |
+
-webkit-box-shadow: none;
|
166 |
+
-moz-box-shadow: none;
|
167 |
+
box-shadow: none;
|
168 |
+
text-shadow: none;
|
169 |
+
font-size: inherit;
|
170 |
+
font-weight: bold;
|
171 |
+
}
|
172 |
+
|
173 |
+
.wpgdprc .button.button-primary {
|
174 |
+
background: #4AA94F;
|
175 |
+
border-top-color: #459D49;
|
176 |
+
border-right-color: #419546;
|
177 |
+
border-bottom-color: #419546;
|
178 |
+
border-left-color: #419546;
|
179 |
+
}
|
180 |
+
|
181 |
+
h1.wpgdprc-title {
|
182 |
+
margin-bottom: 20px;
|
183 |
+
font-weight: 700;
|
184 |
+
font-size: 36px;
|
185 |
+
}
|
186 |
+
|
187 |
+
h1.wpgdprc-title span {
|
188 |
+
font-weight: 400;
|
189 |
+
font-size: 18px;
|
190 |
+
color: #8A8A8A;
|
191 |
+
}
|
192 |
+
|
193 |
+
div.wpgdprc-description {
|
194 |
+
margin-top: 20px;
|
195 |
+
padding: 20px;
|
196 |
+
background: #F3F3F3;
|
197 |
+
border-bottom: 2px solid #DFDFDF;
|
198 |
+
border-radius: 5px;
|
199 |
+
}
|
200 |
+
|
201 |
+
div.wpgdprc-description p {
|
202 |
+
margin-bottom: 0;
|
203 |
+
}
|
204 |
+
|
205 |
+
div.wpgdprc-description p:first-child {
|
206 |
+
margin-top: 0;
|
207 |
+
}
|
208 |
+
|
209 |
+
p.wpgdprc-disclaimer {
|
210 |
+
font-size: small;
|
211 |
+
color: #8A8A8A;
|
212 |
+
}
|
213 |
+
|
214 |
+
div.wpgdprc-message + table.wpgdprc-table {
|
215 |
+
margin-top: 20px;
|
216 |
+
}
|
217 |
+
|
218 |
+
table.wpgdprc-table {
|
219 |
+
width: 100%;
|
220 |
+
border: 1px solid #DBD6D6;
|
221 |
+
table-layout: fixed;
|
222 |
+
}
|
223 |
+
|
224 |
+
table.wpgdprc-table th, table.wpgdprc-table td {
|
225 |
+
padding: 5px;
|
226 |
+
word-break: break-word;
|
227 |
+
-webkit-hyphens: auto;
|
228 |
+
-ms-hyphens: auto;
|
229 |
+
hyphens: auto;
|
230 |
+
}
|
231 |
+
|
232 |
+
table.wpgdprc-table th {
|
233 |
+
background-color: #DBD6D6;
|
234 |
+
text-align: start;
|
235 |
+
}
|
236 |
+
|
237 |
+
table.wpgdprc-table tr:nth-child(even) {
|
238 |
+
background-color: #F1F1F1;
|
239 |
+
}
|
240 |
+
|
241 |
+
table.wpgdprc-table tr.wpgdprc-table__row--expired {
|
242 |
+
opacity: .5;
|
243 |
+
}
|
244 |
+
|
245 |
+
.wpgdprc-background {
|
246 |
+
position: fixed;
|
247 |
+
right: 0;
|
248 |
+
bottom: -10px;
|
249 |
+
left: 0;
|
250 |
+
z-index: -1;
|
251 |
+
}
|
252 |
+
|
253 |
+
.wpgdprc-background g {
|
254 |
+
fill: #4AA94F;
|
255 |
+
}
|
256 |
+
|
257 |
+
.wpgdprc-contents {
|
258 |
+
flex: 11;
|
259 |
+
}
|
260 |
+
|
261 |
+
.wpgdprc-sidebar {
|
262 |
+
padding: 0 20px;
|
263 |
+
flex: 3;
|
264 |
+
align-items: flex-start;
|
265 |
+
align-content: flex-start;
|
266 |
+
}
|
267 |
+
|
268 |
+
.wpgdprc-sidebar-block {
|
269 |
+
margin-bottom: 20px;
|
270 |
+
padding: 20px;
|
271 |
+
background: #F3F3F3;
|
272 |
+
border-bottom: 2px solid #DFDFDF;
|
273 |
+
border-radius: 5px;
|
274 |
+
}
|
275 |
+
|
276 |
+
.wpgdprc-sidebar-block h3 {
|
277 |
+
display: inline-block;
|
278 |
+
margin: 0;
|
279 |
+
}
|
280 |
+
|
281 |
+
.wpgdprc-sidebar-block--no-background {
|
282 |
+
padding: 0;
|
283 |
+
background: none;
|
284 |
+
border: 0;
|
285 |
+
}
|
286 |
+
|
287 |
+
.wpgdprc-sidebar-donate {
|
288 |
+
margin: 5px 0 0 10px;
|
289 |
+
display: inline-block;
|
290 |
+
float: right;
|
291 |
+
}
|
292 |
+
|
293 |
+
.wpgdprc-navigation {
|
294 |
+
border-bottom: 1px solid #DBD6D6;
|
295 |
+
}
|
296 |
+
|
297 |
+
.wpgdprc-navigation > a {
|
298 |
+
position: relative;
|
299 |
+
display: block;
|
300 |
+
float: left;
|
301 |
+
margin-bottom: -1px;
|
302 |
+
padding: 12px 16px;
|
303 |
+
background-color: #E9E9E9;
|
304 |
+
border: 1px solid transparent;
|
305 |
+
border-left-color: #F1F1F1;
|
306 |
+
-webkit-box-shadow: none;
|
307 |
+
-moz-box-shadow: none;
|
308 |
+
box-shadow: none;
|
309 |
+
text-decoration: none;
|
310 |
+
font-weight: 500;
|
311 |
+
line-height: 1;
|
312 |
+
color: inherit;
|
313 |
+
}
|
314 |
+
|
315 |
+
.wpgdprc-navigation > a.wpgdprc-active {
|
316 |
+
background-color: #fff;
|
317 |
+
color: #4AA94F;
|
318 |
+
border-top-color: #DBD6D6;
|
319 |
+
border-right-color: #DBD6D6;
|
320 |
+
border-left-color: #DBD6D6;
|
321 |
+
}
|
322 |
+
|
323 |
+
.wpgdprc-navigation span.wpgdprc-badge {
|
324 |
+
position: absolute;
|
325 |
+
top: -5px;
|
326 |
+
right: -5px;
|
327 |
+
display: block;
|
328 |
+
width: 20px;
|
329 |
+
height: 20px;
|
330 |
+
background-color: #4AA94F;
|
331 |
+
border-radius: 50%;
|
332 |
+
text-align: center;
|
333 |
+
line-height: 20px;
|
334 |
+
font-size: 11px;
|
335 |
+
color: #FFFFFF;
|
336 |
+
z-index: 1;
|
337 |
+
}
|
338 |
+
|
339 |
+
.wpgdprc-content {
|
340 |
+
display: block;
|
341 |
+
background-color: #fff;
|
342 |
+
border: 1px solid #DBD6D6;
|
343 |
+
border-top: none;
|
344 |
+
padding: 20px;
|
345 |
+
}
|
346 |
+
|
347 |
+
.wpgdprc-content > p:first-child {
|
348 |
+
margin-top: 0;
|
349 |
+
}
|
350 |
+
|
351 |
+
.wpgdprc-list {
|
352 |
+
margin: -20px 0;
|
353 |
+
list-style: none;
|
354 |
+
}
|
355 |
+
|
356 |
+
.wpgdprc-list li {
|
357 |
+
margin-bottom: 0;
|
358 |
+
}
|
359 |
+
|
360 |
+
.wpgdprc-list > li {
|
361 |
+
padding: 20px 0;
|
362 |
+
border-top: 2px solid #EDEDED;
|
363 |
+
}
|
364 |
+
|
365 |
+
.wpgdprc-list > li:first-child {
|
366 |
+
border-top: none;
|
367 |
+
}
|
368 |
+
|
369 |
+
.wpgdprc-checkbox {
|
370 |
+
position: relative;
|
371 |
+
}
|
372 |
+
|
373 |
+
.wpgdprc-checkbox input[type="checkbox"] {
|
374 |
+
display: none;
|
375 |
+
}
|
376 |
+
|
377 |
+
.wpgdprc-checkbox input[type="checkbox"]:checked:not(.processing) ~ .wpgdprc-switch .wpgdprc-switch-label .wpgdprc-switch-inner {
|
378 |
+
margin-left: 0;
|
379 |
+
}
|
380 |
+
|
381 |
+
.wpgdprc-checkbox input[type="checkbox"]:checked:not(.processing) ~ .wpgdprc-switch .wpgdprc-switch-label .wpgdprc-switch-switch {
|
382 |
+
right: 1px;
|
383 |
+
}
|
384 |
+
|
385 |
+
.wpgdprc-checkbox input[type="checkbox"].processing ~ label {
|
386 |
+
pointer-events: none;
|
387 |
+
}
|
388 |
+
|
389 |
+
.wpgdprc-checkbox input[type="checkbox"].processing ~ .wpgdprc-switch .wpgdprc-switch-label .wpgdprc-switch-inner {
|
390 |
+
margin-left: -50%;
|
391 |
+
}
|
392 |
+
|
393 |
+
.wpgdprc-checkbox input[type="checkbox"].processing ~ .wpgdprc-switch .wpgdprc-switch-label .wpgdprc-switch-switch {
|
394 |
+
right: 50%;
|
395 |
+
-webkit-transform: translateX(50%);
|
396 |
+
-moz-transform: translateX(50%);
|
397 |
+
-ms-transform: translateX(50%);
|
398 |
+
-o-transform: translateX(50%);
|
399 |
+
transform: translateX(50%);
|
400 |
+
}
|
401 |
+
|
402 |
+
.wpgdprc-checkbox label {
|
403 |
+
display: block;
|
404 |
+
position: relative;
|
405 |
+
user-select: none;
|
406 |
+
z-index: 1;
|
407 |
+
font-weight: bold;
|
408 |
+
}
|
409 |
+
|
410 |
+
span.wpgdprc-instructions {
|
411 |
+
position: absolute;
|
412 |
+
top: 50%;
|
413 |
+
right: 80px;
|
414 |
+
transform: translateY(-50%);
|
415 |
+
font-size: 12px;
|
416 |
+
}
|
417 |
+
|
418 |
+
.wpgdprc-switch {
|
419 |
+
position: absolute;
|
420 |
+
top: 50%;
|
421 |
+
right: 0;
|
422 |
+
transform: translateY(-50%);
|
423 |
+
width: 65px;
|
424 |
+
font-size: 12px;
|
425 |
+
}
|
426 |
+
|
427 |
+
.wpgdprc-switch .wpgdprc-switch-label {
|
428 |
+
display: block;
|
429 |
+
margin: 0;
|
430 |
+
-webkit-border-radius: 30px;
|
431 |
+
-moz-border-radius: 30px;
|
432 |
+
border-radius: 30px;
|
433 |
+
overflow: hidden;
|
434 |
+
cursor: pointer;
|
435 |
+
}
|
436 |
+
|
437 |
+
.wpgdprc-switch .wpgdprc-switch-inner {
|
438 |
+
margin-left: -100%;
|
439 |
+
width: 200%;
|
440 |
+
transition: all 0.15s ease-in-out;
|
441 |
+
}
|
442 |
+
|
443 |
+
.wpgdprc-switch .wpgdprc-switch-inner:before,
|
444 |
+
.wpgdprc-switch .wpgdprc-switch-inner:after {
|
445 |
+
float: left;
|
446 |
+
width: 50%;
|
447 |
+
text-transform: uppercase;
|
448 |
+
line-height: 30px;
|
449 |
+
color: #FFFFFF;
|
450 |
+
content: '';
|
451 |
+
}
|
452 |
+
|
453 |
+
.wpgdprc-switch .wpgdprc-switch-inner:before {
|
454 |
+
padding-left: 10px;
|
455 |
+
background-color: #4AA94F;
|
456 |
+
}
|
457 |
+
|
458 |
+
.wpgdprc-switch .wpgdprc-switch-inner:after {
|
459 |
+
padding-right: 10px;
|
460 |
+
background-color: #0A0A0A;
|
461 |
+
text-align: right;
|
462 |
+
}
|
463 |
+
|
464 |
+
.wpgdprc-switch--reverse .wpgdprc-switch-inner:before {
|
465 |
+
background-color: #FFAE00;
|
466 |
+
}
|
467 |
+
|
468 |
+
.wpgdprc-switch .wpgdprc-switch-switch {
|
469 |
+
position: absolute;
|
470 |
+
top: 1px;
|
471 |
+
right: 36px;
|
472 |
+
bottom: 0;
|
473 |
+
margin: 0;
|
474 |
+
width: 28px;
|
475 |
+
height: 28px;
|
476 |
+
background: #FFFFFF;
|
477 |
+
-webkit-border-radius: 50%;
|
478 |
+
-moz-border-radius: 50%;
|
479 |
+
border-radius: 50%;
|
480 |
+
-webkit-box-shadow: 0 0 3px rgba(0, 0, 0, .3);
|
481 |
+
-moz-box-shadow: 0 0 3px rgba(0, 0, 0, .3);
|
482 |
+
box-shadow: 0 0 3px rgba(0, 0, 0, .3);
|
483 |
+
transition: all 0.15s ease-in-out;
|
484 |
+
}
|
485 |
+
|
486 |
+
.wpgdprc-checkbox-data {
|
487 |
+
margin-top: 10px;
|
488 |
+
}
|
489 |
+
|
490 |
+
.wpgdprc-checkbox-data p:first-child {
|
491 |
+
margin-top: 0;
|
492 |
+
}
|
493 |
+
|
494 |
+
.wpgdprc-checklist-description {
|
495 |
+
color: #8A8A8A;
|
496 |
+
}
|
497 |
+
|
498 |
+
.wpgdprc-checklist-description + .wpgdprc-message {
|
499 |
+
margin-top: 10px;
|
500 |
+
}
|
501 |
+
|
502 |
+
.wpgdprc-checklist-options {
|
503 |
+
margin-top: 10px;
|
504 |
+
}
|
505 |
+
|
506 |
+
.wpgdprc-checklist-options .wpgdprc-checkbox input[type="checkbox"] {
|
507 |
+
display: block;
|
508 |
+
position: absolute;
|
509 |
+
top: 50%;
|
510 |
+
right: 0;
|
511 |
+
margin: 0;
|
512 |
+
transform: translateY(-50%);
|
513 |
+
}
|
514 |
+
|
515 |
+
.wpgdprc-checklist-options span.wpgdprc-instructions {
|
516 |
+
right: 30px;
|
517 |
+
}
|
518 |
+
|
519 |
+
.wpgdprc-checklist-options li {
|
520 |
+
margin-top: 10px;
|
521 |
+
padding: 20px;
|
522 |
+
background-color: #FAFAFA;
|
523 |
+
border: 1px solid #F0F0F0;
|
524 |
+
}
|
525 |
+
|
526 |
+
.wpgdprc-checklist-options li:first-child {
|
527 |
+
margin-top: 0;
|
528 |
+
}
|
529 |
+
|
530 |
+
.wpgdprc-setting {
|
531 |
+
margin: 1em 0;
|
532 |
+
*zoom: 1;
|
533 |
+
}
|
534 |
+
|
535 |
+
.wpgdprc-setting:before, .wpgdprc-setting:after {
|
536 |
+
display: table;
|
537 |
+
content: " ";
|
538 |
+
}
|
539 |
+
|
540 |
+
.wpgdprc-setting:after {
|
541 |
+
clear: both;
|
542 |
+
}
|
543 |
+
|
544 |
+
.wpgdprc-setting:first-child {
|
545 |
+
margin-top: 0;
|
546 |
+
}
|
547 |
+
|
548 |
+
.wpgdprc-setting:last-child {
|
549 |
+
margin-bottom: 0;
|
550 |
+
}
|
551 |
+
|
552 |
+
.wpgdprc-setting label {
|
553 |
+
display: inline-block;
|
554 |
+
vertical-align: top;
|
555 |
+
}
|
556 |
+
|
557 |
+
.wpgdprc-setting label input[type="checkbox"] {
|
558 |
+
margin-top: 0 !important;
|
559 |
+
}
|
560 |
+
|
561 |
+
.wpgdprc-setting input[type="text"], .wpgdprc-setting textarea, .wpgdprc-setting select {
|
562 |
+
display: block;
|
563 |
+
margin: 0;
|
564 |
+
width: 100%;
|
565 |
+
-webkit-box-shadow: none;
|
566 |
+
-moz-box-shadow: none;
|
567 |
+
box-shadow: none;
|
568 |
+
font-size: inherit;
|
569 |
+
}
|
570 |
+
|
571 |
+
.wpgdprc-setting input[type="text"], .wpgdprc-setting textarea {
|
572 |
+
background-color: #FFFFFF;
|
573 |
+
}
|
574 |
+
|
575 |
+
.wpgdprc-setting select {
|
576 |
+
background-color: #FAFAFA;
|
577 |
+
}
|
578 |
+
|
579 |
+
.wpgdprc-setting .wpgdprc-information {
|
580 |
+
margin-top: .5em;
|
581 |
+
}
|
582 |
+
|
583 |
+
.wpgdprc-setting .wpgdprc-information p {
|
584 |
+
margin-top: 0;
|
585 |
+
margin-bottom: .5em;
|
586 |
+
}
|
587 |
+
|
588 |
+
.wpgdprc-setting .wpgdprc-information p:last-child {
|
589 |
+
margin-bottom: 0;
|
590 |
+
}
|
591 |
+
|
592 |
+
.wpgdprc-pagination {
|
593 |
+
margin-top: 20px;
|
594 |
+
line-height: 28px;
|
595 |
+
}
|
596 |
+
|
597 |
+
.wpgdprc-pagination .page-numbers {
|
598 |
+
display: inline-block;
|
599 |
+
vertical-align: top;
|
600 |
+
width: 30px;
|
601 |
+
background-color: #FFFFFF;
|
602 |
+
border: 1px solid #DBD6D6;
|
603 |
+
text-align: center;
|
604 |
+
text-decoration: none;
|
605 |
+
}
|
606 |
+
|
607 |
+
.wpgdprc-pagination .page-numbers + .wpgdprc-pagination__results {
|
608 |
+
margin-left: 10px;
|
609 |
+
}
|
610 |
+
|
611 |
+
.wpgdprc-stars {
|
612 |
+
margin: 15px auto;
|
613 |
+
width: 150px;
|
614 |
+
height: 30px;
|
615 |
+
background: url('../svg/stars.svg');
|
616 |
+
animation: wpgdprc-stars 4.5s steps(1, end) infinite;
|
617 |
+
-webkit-animation: wpgdprc-stars 4.5s steps(1, end) infinite;
|
618 |
+
-moz-animation: wpgdprc-stars 4.5s steps(1, end) infinite;
|
619 |
+
-o-animation: wpgdprc-stars 4.5s steps(1, end) infinite;
|
620 |
+
}
|
621 |
+
|
622 |
+
.CodeMirror {
|
623 |
+
border: 1px solid #DDDDDD;
|
624 |
+
}
|
625 |
+
|
626 |
+
@media screen and (max-width: 639px) {
|
627 |
+
.wpgdprc-instructions {
|
628 |
+
display: none;
|
629 |
+
}
|
630 |
+
}
|
631 |
+
|
632 |
+
@media screen and (max-width: 782px) {
|
633 |
+
.wpgdprc-checklist-options span.wpgdprc-instructions {
|
634 |
+
right: 40px;
|
635 |
+
}
|
636 |
+
}
|
637 |
+
|
638 |
+
@media screen and (min-width: 768px) {
|
639 |
+
.wpgdprc-setting label {
|
640 |
+
width: 100%;
|
641 |
+
max-width: 30%;
|
642 |
+
}
|
643 |
+
|
644 |
+
.wpgdprc-options {
|
645 |
+
float: right;
|
646 |
+
width: 100%;
|
647 |
+
max-width: 70%;
|
648 |
+
}
|
649 |
+
}
|
650 |
+
|
651 |
+
@media screen and (min-width: 783px) {
|
652 |
+
.wpgdprc .button {
|
653 |
+
height: 34px;
|
654 |
+
line-height: 32px;
|
655 |
+
}
|
656 |
+
}
|
657 |
+
|
658 |
+
@media screen and (max-width: 1400px) {
|
659 |
+
.wpgdprc {
|
660 |
+
display: block;
|
661 |
+
}
|
662 |
+
|
663 |
+
.wpgdprc-contents, .wpgdprc-sidebar {
|
664 |
+
display: block;
|
665 |
+
max-width: 100%;
|
666 |
+
width: 100%;
|
667 |
+
}
|
668 |
+
|
669 |
+
.wpgdprc-sidebar {
|
670 |
+
display: flex;
|
671 |
+
margin-top: 30px;
|
672 |
+
padding-right: 0;
|
673 |
+
padding-left: 0;
|
674 |
+
}
|
675 |
+
|
676 |
+
.wpgdprc-sidebar-block {
|
677 |
+
margin-right: 15px;
|
678 |
+
margin-left: 15px;
|
679 |
+
width: 33.33333%;
|
680 |
+
}
|
681 |
+
}
|
682 |
+
|
683 |
+
@media screen and (min-width: 320px) and (max-width: 840px) {
|
684 |
+
.wpgdprc-sidebar {
|
685 |
+
display: block;
|
686 |
+
}
|
687 |
+
|
688 |
+
.wpgdprc-sidebar-block {
|
689 |
+
max-width: 400px;
|
690 |
+
width: 100%;
|
691 |
+
margin-right: auto;
|
692 |
+
margin-left: auto;
|
693 |
+
}
|
694 |
+
|
695 |
+
.wpgdprc .button.button-primary {
|
696 |
+
height: auto;
|
697 |
+
}
|
698 |
}
|
assets/css/front.css
CHANGED
@@ -1,434 +1,434 @@
|
|
1 |
-
html.lity-active {
|
2 |
-
overflow: hidden;
|
3 |
-
}
|
4 |
-
|
5 |
-
div.wpgdprc {
|
6 |
-
-webkit-box-sizing: border-box;
|
7 |
-
-moz-box-sizing: border-box;
|
8 |
-
box-sizing: border-box;
|
9 |
-
font-family: Verdana, Geneva, sans-serif;
|
10 |
-
font-style: normal;
|
11 |
-
font-variant: normal;
|
12 |
-
font-weight: 400;
|
13 |
-
font-size: 14px;
|
14 |
-
}
|
15 |
-
|
16 |
-
div.wpgdprc *,
|
17 |
-
div.wpgdprc *:before,
|
18 |
-
div.wpgdprc *:after {
|
19 |
-
-webkit-box-sizing: inherit;
|
20 |
-
-moz-box-sizing: inherit;
|
21 |
-
box-sizing: inherit;
|
22 |
-
-webkit-border-radius: 0;
|
23 |
-
-moz-border-radius: 0;
|
24 |
-
border-radius: 0;
|
25 |
-
}
|
26 |
-
|
27 |
-
div.wpgdprc a,
|
28 |
-
div.wpgdprc a:hover,
|
29 |
-
div.wpgdprc a:focus {
|
30 |
-
text-decoration: underline;
|
31 |
-
color: inherit;
|
32 |
-
}
|
33 |
-
|
34 |
-
div.wpgdprc p {
|
35 |
-
font: inherit;
|
36 |
-
color: inherit;
|
37 |
-
}
|
38 |
-
|
39 |
-
div.wpgdprc button {
|
40 |
-
cursor: pointer;
|
41 |
-
}
|
42 |
-
|
43 |
-
div.wpgdprc .wpgdprc-button {
|
44 |
-
display: inline-block;
|
45 |
-
padding: 10px;
|
46 |
-
border: 1px solid #DBD6D6;
|
47 |
-
font-weight: bold;
|
48 |
-
}
|
49 |
-
|
50 |
-
div.wpgdprc .wpgdprc-button,
|
51 |
-
div.wpgdprc .wpgdprc-button:hover,
|
52 |
-
div.wpgdprc .wpgdprc-button:focus {
|
53 |
-
background: #FFFFFF;
|
54 |
-
text-decoration: none;
|
55 |
-
color: #000000;
|
56 |
-
}
|
57 |
-
|
58 |
-
div.wpgdprc .wpgdprc-button.wpgdprc-button--active,
|
59 |
-
div.wpgdprc .wpgdprc-button.wpgdprc-button--active:hover,
|
60 |
-
div.wpgdprc .wpgdprc-button.wpgdprc-button--active:focus {
|
61 |
-
background: #F3F3F3;
|
62 |
-
}
|
63 |
-
|
64 |
-
div.wpgdprc .wpgdprc-button--secondary,
|
65 |
-
div.wpgdprc .wpgdprc-button--secondary:hover,
|
66 |
-
div.wpgdprc .wpgdprc-button--secondary:focus {
|
67 |
-
background: #000000;
|
68 |
-
border-color: transparent;
|
69 |
-
color: #FFFFFF;
|
70 |
-
}
|
71 |
-
|
72 |
-
div.wpgdprc div.wpgdprc-message {
|
73 |
-
padding: 10px;
|
74 |
-
border: 1px solid transparent;
|
75 |
-
}
|
76 |
-
|
77 |
-
div.wpgdprc div.wpgdprc-message p:first-child {
|
78 |
-
margin-top: 0;
|
79 |
-
}
|
80 |
-
|
81 |
-
div.wpgdprc div.wpgdprc-message p:last-child {
|
82 |
-
margin-bottom: 0;
|
83 |
-
}
|
84 |
-
|
85 |
-
div.wpgdprc div.wpgdprc-message--notice {
|
86 |
-
background: #FFF3D9;
|
87 |
-
border-color: #E7D996;
|
88 |
-
}
|
89 |
-
|
90 |
-
div.wpgdprc div.wpgdprc-message--error {
|
91 |
-
background: #F7E4E1;
|
92 |
-
border-color: #CC4B37;
|
93 |
-
color: #CC4B37;
|
94 |
-
}
|
95 |
-
|
96 |
-
div.wpgdprc div.wpgdprc-message--success {
|
97 |
-
background: #E1FAEA;
|
98 |
-
border-color: #5B9C73;
|
99 |
-
color: #5B9C73;
|
100 |
-
}
|
101 |
-
|
102 |
-
div.wpgdprc .wpgdprc-status--processing,
|
103 |
-
div.wpgdprc .wpgdprc-status--removed {
|
104 |
-
pointer-events: none;
|
105 |
-
}
|
106 |
-
|
107 |
-
div.wpgdprc .wpgdprc-status--processing {
|
108 |
-
opacity: .5;
|
109 |
-
}
|
110 |
-
|
111 |
-
div.wpgdprc .wpgdprc-status--removed {
|
112 |
-
opacity: .2;
|
113 |
-
text-decoration: line-through;
|
114 |
-
}
|
115 |
-
|
116 |
-
div.wpgdprc .wpgdprc-status--error {
|
117 |
-
background-color: #F7E4E1;
|
118 |
-
border-color: #CC4B37;
|
119 |
-
color: #CC4B37;
|
120 |
-
}
|
121 |
-
|
122 |
-
div.wpgdprc .wpgdprc-checkbox {
|
123 |
-
position: relative;
|
124 |
-
}
|
125 |
-
|
126 |
-
div.wpgdprc .wpgdprc-checkbox input[type="checkbox"] {
|
127 |
-
display: none;
|
128 |
-
}
|
129 |
-
|
130 |
-
div.wpgdprc .wpgdprc-checkbox input[type="checkbox"]:checked ~ .wpgdprc-switch .wpgdprc-switch-label .wpgdprc-switch-inner {
|
131 |
-
margin-left: 0;
|
132 |
-
}
|
133 |
-
|
134 |
-
div.wpgdprc .wpgdprc-checkbox input[type="checkbox"]:checked ~ .wpgdprc-switch .wpgdprc-switch-label .wpgdprc-switch-switch {
|
135 |
-
right: 1px;
|
136 |
-
margin-right: 0;
|
137 |
-
}
|
138 |
-
|
139 |
-
div.wpgdprc .wpgdprc-checkbox label {
|
140 |
-
display: inline-block;
|
141 |
-
vertical-align: middle;
|
142 |
-
position: relative;
|
143 |
-
user-select: none;
|
144 |
-
z-index: 1;
|
145 |
-
font-weight: bold;
|
146 |
-
cursor: pointer;
|
147 |
-
color: #000000;
|
148 |
-
}
|
149 |
-
|
150 |
-
div.wpgdprc .wpgdprc-switch {
|
151 |
-
display: inline-block;
|
152 |
-
vertical-align: middle;
|
153 |
-
position: relative;
|
154 |
-
margin-right: 10px;
|
155 |
-
min-width: 65px;
|
156 |
-
}
|
157 |
-
|
158 |
-
div.wpgdprc .wpgdprc-switch .wpgdprc-switch-label {
|
159 |
-
display: block;
|
160 |
-
margin: 0;
|
161 |
-
-webkit-border-radius: 30px;
|
162 |
-
-moz-border-radius: 30px;
|
163 |
-
border-radius: 30px;
|
164 |
-
overflow: hidden;
|
165 |
-
cursor: pointer;
|
166 |
-
}
|
167 |
-
|
168 |
-
div.wpgdprc .wpgdprc-switch .wpgdprc-switch-inner {
|
169 |
-
display: block;
|
170 |
-
margin-left: -100%;
|
171 |
-
width: 200%;
|
172 |
-
transition: all 0.15s ease-in-out;
|
173 |
-
}
|
174 |
-
|
175 |
-
div.wpgdprc .wpgdprc-switch .wpgdprc-switch-inner:before,
|
176 |
-
div.wpgdprc .wpgdprc-switch .wpgdprc-switch-inner:after {
|
177 |
-
float: left;
|
178 |
-
width: 50%;
|
179 |
-
text-transform: uppercase;
|
180 |
-
line-height: 30px;
|
181 |
-
font-size: 12px;
|
182 |
-
color: #FFFFFF;
|
183 |
-
content: '';
|
184 |
-
}
|
185 |
-
|
186 |
-
div.wpgdprc .wpgdprc-switch .wpgdprc-switch-inner:before {
|
187 |
-
padding-left: 10px;
|
188 |
-
background-color: #4AA94F;
|
189 |
-
}
|
190 |
-
|
191 |
-
div.wpgdprc .wpgdprc-switch .wpgdprc-switch-inner:after {
|
192 |
-
padding-right: 10px;
|
193 |
-
background-color: #0A0A0A;
|
194 |
-
text-align: right;
|
195 |
-
}
|
196 |
-
|
197 |
-
div.wpgdprc .wpgdprc-switch--reverse .wpgdprc-switch-inner:before {
|
198 |
-
background-color: #FFAE00;
|
199 |
-
}
|
200 |
-
|
201 |
-
div.wpgdprc .wpgdprc-switch .wpgdprc-switch-switch {
|
202 |
-
position: absolute;
|
203 |
-
top: 1px;
|
204 |
-
right: 100%;
|
205 |
-
bottom: 0;
|
206 |
-
margin: 0 -29px 0 0;
|
207 |
-
width: 28px;
|
208 |
-
height: 28px;
|
209 |
-
background: #FFFFFF;
|
210 |
-
-webkit-border-radius: 50%;
|
211 |
-
-moz-border-radius: 50%;
|
212 |
-
border-radius: 50%;
|
213 |
-
-webkit-box-shadow: 0 0 3px rgba(0, 0, 0, .3);
|
214 |
-
-moz-box-shadow: 0 0 3px rgba(0, 0, 0, .3);
|
215 |
-
box-shadow: 0 0 3px rgba(0, 0, 0, .3);
|
216 |
-
transition: all 0.15s ease-in-out;
|
217 |
-
}
|
218 |
-
|
219 |
-
/**
|
220 |
-
* CONSENT: Bar
|
221 |
-
* ----------------------------------------------------------------------------
|
222 |
-
*/
|
223 |
-
|
224 |
-
div.wpgdprc-consent-bar {
|
225 |
-
position: fixed;
|
226 |
-
bottom: 0;
|
227 |
-
right: 0;
|
228 |
-
left: 0;
|
229 |
-
padding: 10px 0;
|
230 |
-
background: #000000;
|
231 |
-
text-align: center;
|
232 |
-
z-index: 999;
|
233 |
-
animation: wpgdprcFadeIn .3s cubic-bezier(0.0, 0.0, 0.2, 1);
|
234 |
-
}
|
235 |
-
|
236 |
-
div.wpgdprc-consent-bar *,
|
237 |
-
div.wpgdprc-consent-bar *:before,
|
238 |
-
div.wpgdprc-consent-bar *:after {
|
239 |
-
margin: 0;
|
240 |
-
font: inherit;
|
241 |
-
color: inherit;
|
242 |
-
}
|
243 |
-
|
244 |
-
div.wpgdprc-consent-bar div.wpgdprc-consent-bar__container {
|
245 |
-
display: inline-block;
|
246 |
-
vertical-align: top;
|
247 |
-
position: relative;
|
248 |
-
}
|
249 |
-
|
250 |
-
div.wpgdprc-consent-bar div.wpgdprc-consent-bar__column {
|
251 |
-
padding: 0 10px;
|
252 |
-
}
|
253 |
-
|
254 |
-
div.wpgdprc-consent-bar div.wpgdprc-consent-bar__content {
|
255 |
-
display: -webkit-box;
|
256 |
-
display: -ms-flexbox;
|
257 |
-
display: flex;
|
258 |
-
-webkit-box-align: center;
|
259 |
-
-ms-flex-align: center;
|
260 |
-
align-items: center;
|
261 |
-
width: 100%;
|
262 |
-
text-align: left;
|
263 |
-
color: #FFFFFF;
|
264 |
-
}
|
265 |
-
|
266 |
-
div.wpgdprc-consent-bar div.wpgdprc-consent-bar__notice {
|
267 |
-
max-width: 600px;
|
268 |
-
}
|
269 |
-
|
270 |
-
div.wpgdprc-consent-bar .wpgdprc-consent-bar__button {
|
271 |
-
padding: 5px 10px;
|
272 |
-
border: none;
|
273 |
-
}
|
274 |
-
|
275 |
-
/**
|
276 |
-
* CONSENT: Modal
|
277 |
-
* ----------------------------------------------------------------------------
|
278 |
-
*/
|
279 |
-
|
280 |
-
div.wpgdprc-consent-modal {
|
281 |
-
display: none;
|
282 |
-
}
|
283 |
-
|
284 |
-
div.wpgdprc-consent-modal.is-open {
|
285 |
-
display: block !important;
|
286 |
-
}
|
287 |
-
|
288 |
-
div.wpgdprc-consent-modal[aria-hidden="false"] div.wpgdprc-consent-modal__overlay {
|
289 |
-
animation: wpgdprcFadeIn .3s cubic-bezier(0.0, 0.0, 0.2, 1);
|
290 |
-
}
|
291 |
-
|
292 |
-
div.wpgdprc-consent-modal[aria-hidden="true"] div.wpgdprc-consent-modal__overlay {
|
293 |
-
animation: wpgdprcFadeOut .3s cubic-bezier(0.0, 0.0, 0.2, 1);
|
294 |
-
}
|
295 |
-
|
296 |
-
div.wpgdprc-consent-modal h3.wpgdprc-consent-modal__title {
|
297 |
-
margin-top: 0;
|
298 |
-
margin-bottom: 1em;
|
299 |
-
font-size: 16px;
|
300 |
-
font-weight: bold;
|
301 |
-
color: #000000;
|
302 |
-
}
|
303 |
-
|
304 |
-
div.wpgdprc-consent-modal div.wpgdprc-consent-modal__description {
|
305 |
-
color: #8A8A8A;
|
306 |
-
}
|
307 |
-
|
308 |
-
div.wpgdprc-consent-modal div.wpgdprc-consent-modal__overlay {
|
309 |
-
will-change: transform;
|
310 |
-
display: -webkit-box;
|
311 |
-
display: -ms-flexbox;
|
312 |
-
display: flex;
|
313 |
-
position: fixed;
|
314 |
-
top: 0;
|
315 |
-
right: 0;
|
316 |
-
bottom: 0;
|
317 |
-
left: 0;
|
318 |
-
background: #000000;
|
319 |
-
background: rgba(0, 0, 0, 0.6);
|
320 |
-
justify-content: center;
|
321 |
-
-webkit-box-align: center;
|
322 |
-
-ms-flex-align: center;
|
323 |
-
align-items: center;
|
324 |
-
z-index: 999999;
|
325 |
-
}
|
326 |
-
|
327 |
-
div.wpgdprc-consent-modal div.wpgdprc-consent-modal__container {
|
328 |
-
position: relative;
|
329 |
-
width: 80%;
|
330 |
-
width: 80vw;
|
331 |
-
height: 80%;
|
332 |
-
height: 80vh;
|
333 |
-
max-width: 800px;
|
334 |
-
background: #FFFFFF;
|
335 |
-
border-top: 10px solid #DBD6D6;
|
336 |
-
overflow-y: auto;
|
337 |
-
}
|
338 |
-
|
339 |
-
div.wpgdprc-consent-modal button.wpgdprc-consent-modal__close {
|
340 |
-
position: absolute;
|
341 |
-
top: 0;
|
342 |
-
right: 0;
|
343 |
-
margin: 0;
|
344 |
-
padding: 0;
|
345 |
-
width: 40px;
|
346 |
-
height: 40px;
|
347 |
-
font-size: 21px;
|
348 |
-
line-height: 40px;
|
349 |
-
}
|
350 |
-
|
351 |
-
div.wpgdprc-consent-modal button.wpgdprc-consent-modal__close,
|
352 |
-
div.wpgdprc-consent-modal button.wpgdprc-consent-modal__close:hover,
|
353 |
-
div.wpgdprc-consent-modal button.wpgdprc-consent-modal__close:focus {
|
354 |
-
background: #FFFFFF;
|
355 |
-
border: none;
|
356 |
-
color: inherit;
|
357 |
-
}
|
358 |
-
|
359 |
-
div.wpgdprc-consent-modal nav.wpgdprc-consent-modal__navigation,
|
360 |
-
div.wpgdprc-consent-modal div.wpgdprc-consent-modal__information {
|
361 |
-
position: relative;
|
362 |
-
padding: 30px;
|
363 |
-
}
|
364 |
-
|
365 |
-
div.wpgdprc-consent-modal nav.wpgdprc-consent-modal__navigation {
|
366 |
-
border-bottom: 1px solid #DBD6D6;
|
367 |
-
}
|
368 |
-
|
369 |
-
div.wpgdprc-consent-modal nav.wpgdprc-consent-modal__navigation > a {
|
370 |
-
display: block;
|
371 |
-
margin-top: 10px;
|
372 |
-
}
|
373 |
-
|
374 |
-
div.wpgdprc-consent-modal nav.wpgdprc-consent-modal__navigation > a:first-child {
|
375 |
-
margin-top: 0;
|
376 |
-
}
|
377 |
-
|
378 |
-
div.wpgdprc-consent-modal div.wpgdprc-consent-modal__information {
|
379 |
-
padding-bottom: 110px;
|
380 |
-
}
|
381 |
-
|
382 |
-
div.wpgdprc-consent-modal footer.wpgdprc-consent-modal__footer {
|
383 |
-
display: -webkit-box;
|
384 |
-
display: -ms-flexbox;
|
385 |
-
display: flex;
|
386 |
-
-webkit-box-align: center;
|
387 |
-
-ms-flex-align: center;
|
388 |
-
align-items: center;
|
389 |
-
position: absolute;
|
390 |
-
right: 0;
|
391 |
-
bottom: 0;
|
392 |
-
left: 0;
|
393 |
-
padding: 0 30px;
|
394 |
-
height: 80px;
|
395 |
-
border-top: 1px solid #DBD6D6;
|
396 |
-
}
|
397 |
-
|
398 |
-
@media only screen and (min-width: 768px) {
|
399 |
-
div.wpgdprc-consent-modal nav.wpgdprc-consent-modal__navigation,
|
400 |
-
div.wpgdprc-consent-modal div.wpgdprc-consent-modal__information {
|
401 |
-
float: left;
|
402 |
-
min-height: 100%;
|
403 |
-
}
|
404 |
-
div.wpgdprc-consent-modal nav.wpgdprc-consent-modal__navigation {
|
405 |
-
width: 40%;
|
406 |
-
border-right: 1px solid #DBD6D6;
|
407 |
-
border-bottom: none;
|
408 |
-
}
|
409 |
-
div.wpgdprc-consent-modal div.wpgdprc-consent-modal__information {
|
410 |
-
width: 60%;
|
411 |
-
}
|
412 |
-
}
|
413 |
-
|
414 |
-
abbr.wpgdprc-required + abbr.required {
|
415 |
-
display: none !important;
|
416 |
-
}
|
417 |
-
|
418 |
-
@keyframes wpgdprcFadeIn {
|
419 |
-
from {
|
420 |
-
opacity: 0;
|
421 |
-
}
|
422 |
-
to {
|
423 |
-
opacity: 1;
|
424 |
-
}
|
425 |
-
}
|
426 |
-
|
427 |
-
@keyframes wpgdprcFadeOut {
|
428 |
-
from {
|
429 |
-
opacity: 1;
|
430 |
-
}
|
431 |
-
to {
|
432 |
-
opacity: 0;
|
433 |
-
}
|
434 |
}
|
1 |
+
html.lity-active {
|
2 |
+
overflow: hidden;
|
3 |
+
}
|
4 |
+
|
5 |
+
div.wpgdprc {
|
6 |
+
-webkit-box-sizing: border-box;
|
7 |
+
-moz-box-sizing: border-box;
|
8 |
+
box-sizing: border-box;
|
9 |
+
font-family: Verdana, Geneva, sans-serif;
|
10 |
+
font-style: normal;
|
11 |
+
font-variant: normal;
|
12 |
+
font-weight: 400;
|
13 |
+
font-size: 14px;
|
14 |
+
}
|
15 |
+
|
16 |
+
div.wpgdprc *,
|
17 |
+
div.wpgdprc *:before,
|
18 |
+
div.wpgdprc *:after {
|
19 |
+
-webkit-box-sizing: inherit;
|
20 |
+
-moz-box-sizing: inherit;
|
21 |
+
box-sizing: inherit;
|
22 |
+
-webkit-border-radius: 0;
|
23 |
+
-moz-border-radius: 0;
|
24 |
+
border-radius: 0;
|
25 |
+
}
|
26 |
+
|
27 |
+
div.wpgdprc a,
|
28 |
+
div.wpgdprc a:hover,
|
29 |
+
div.wpgdprc a:focus {
|
30 |
+
text-decoration: underline;
|
31 |
+
color: inherit;
|
32 |
+
}
|
33 |
+
|
34 |
+
div.wpgdprc p {
|
35 |
+
font: inherit;
|
36 |
+
color: inherit;
|
37 |
+
}
|
38 |
+
|
39 |
+
div.wpgdprc button {
|
40 |
+
cursor: pointer;
|
41 |
+
}
|
42 |
+
|
43 |
+
div.wpgdprc .wpgdprc-button {
|
44 |
+
display: inline-block;
|
45 |
+
padding: 10px;
|
46 |
+
border: 1px solid #DBD6D6;
|
47 |
+
font-weight: bold;
|
48 |
+
}
|
49 |
+
|
50 |
+
div.wpgdprc .wpgdprc-button,
|
51 |
+
div.wpgdprc .wpgdprc-button:hover,
|
52 |
+
div.wpgdprc .wpgdprc-button:focus {
|
53 |
+
background: #FFFFFF;
|
54 |
+
text-decoration: none;
|
55 |
+
color: #000000;
|
56 |
+
}
|
57 |
+
|
58 |
+
div.wpgdprc .wpgdprc-button.wpgdprc-button--active,
|
59 |
+
div.wpgdprc .wpgdprc-button.wpgdprc-button--active:hover,
|
60 |
+
div.wpgdprc .wpgdprc-button.wpgdprc-button--active:focus {
|
61 |
+
background: #F3F3F3;
|
62 |
+
}
|
63 |
+
|
64 |
+
div.wpgdprc .wpgdprc-button--secondary,
|
65 |
+
div.wpgdprc .wpgdprc-button--secondary:hover,
|
66 |
+
div.wpgdprc .wpgdprc-button--secondary:focus {
|
67 |
+
background: #000000;
|
68 |
+
border-color: transparent;
|
69 |
+
color: #FFFFFF;
|
70 |
+
}
|
71 |
+
|
72 |
+
div.wpgdprc div.wpgdprc-message {
|
73 |
+
padding: 10px;
|
74 |
+
border: 1px solid transparent;
|
75 |
+
}
|
76 |
+
|
77 |
+
div.wpgdprc div.wpgdprc-message p:first-child {
|
78 |
+
margin-top: 0;
|
79 |
+
}
|
80 |
+
|
81 |
+
div.wpgdprc div.wpgdprc-message p:last-child {
|
82 |
+
margin-bottom: 0;
|
83 |
+
}
|
84 |
+
|
85 |
+
div.wpgdprc div.wpgdprc-message--notice {
|
86 |
+
background: #FFF3D9;
|
87 |
+
border-color: #E7D996;
|
88 |
+
}
|
89 |
+
|
90 |
+
div.wpgdprc div.wpgdprc-message--error {
|
91 |
+
background: #F7E4E1;
|
92 |
+
border-color: #CC4B37;
|
93 |
+
color: #CC4B37;
|
94 |
+
}
|
95 |
+
|
96 |
+
div.wpgdprc div.wpgdprc-message--success {
|
97 |
+
background: #E1FAEA;
|
98 |
+
border-color: #5B9C73;
|
99 |
+
color: #5B9C73;
|
100 |
+
}
|
101 |
+
|
102 |
+
div.wpgdprc .wpgdprc-status--processing,
|
103 |
+
div.wpgdprc .wpgdprc-status--removed {
|
104 |
+
pointer-events: none;
|
105 |
+
}
|
106 |
+
|
107 |
+
div.wpgdprc .wpgdprc-status--processing {
|
108 |
+
opacity: .5;
|
109 |
+
}
|
110 |
+
|
111 |
+
div.wpgdprc .wpgdprc-status--removed {
|
112 |
+
opacity: .2;
|
113 |
+
text-decoration: line-through;
|
114 |
+
}
|
115 |
+
|
116 |
+
div.wpgdprc .wpgdprc-status--error {
|
117 |
+
background-color: #F7E4E1;
|
118 |
+
border-color: #CC4B37;
|
119 |
+
color: #CC4B37;
|
120 |
+
}
|
121 |
+
|
122 |
+
div.wpgdprc .wpgdprc-checkbox {
|
123 |
+
position: relative;
|
124 |
+
}
|
125 |
+
|
126 |
+
div.wpgdprc .wpgdprc-checkbox input[type="checkbox"] {
|
127 |
+
display: none;
|
128 |
+
}
|
129 |
+
|
130 |
+
div.wpgdprc .wpgdprc-checkbox input[type="checkbox"]:checked ~ .wpgdprc-switch .wpgdprc-switch-label .wpgdprc-switch-inner {
|
131 |
+
margin-left: 0;
|
132 |
+
}
|
133 |
+
|
134 |
+
div.wpgdprc .wpgdprc-checkbox input[type="checkbox"]:checked ~ .wpgdprc-switch .wpgdprc-switch-label .wpgdprc-switch-switch {
|
135 |
+
right: 1px;
|
136 |
+
margin-right: 0;
|
137 |
+
}
|
138 |
+
|
139 |
+
div.wpgdprc .wpgdprc-checkbox label {
|
140 |
+
display: inline-block;
|
141 |
+
vertical-align: middle;
|
142 |
+
position: relative;
|
143 |
+
user-select: none;
|
144 |
+
z-index: 1;
|
145 |
+
font-weight: bold;
|
146 |
+
cursor: pointer;
|
147 |
+
color: #000000;
|
148 |
+
}
|
149 |
+
|
150 |
+
div.wpgdprc .wpgdprc-switch {
|
151 |
+
display: inline-block;
|
152 |
+
vertical-align: middle;
|
153 |
+
position: relative;
|
154 |
+
margin-right: 10px;
|
155 |
+
min-width: 65px;
|
156 |
+
}
|
157 |
+
|
158 |
+
div.wpgdprc .wpgdprc-switch .wpgdprc-switch-label {
|
159 |
+
display: block;
|
160 |
+
margin: 0;
|
161 |
+
-webkit-border-radius: 30px;
|
162 |
+
-moz-border-radius: 30px;
|
163 |
+
border-radius: 30px;
|
164 |
+
overflow: hidden;
|
165 |
+
cursor: pointer;
|
166 |
+
}
|
167 |
+
|
168 |
+
div.wpgdprc .wpgdprc-switch .wpgdprc-switch-inner {
|
169 |
+
display: block;
|
170 |
+
margin-left: -100%;
|
171 |
+
width: 200%;
|
172 |
+
transition: all 0.15s ease-in-out;
|
173 |
+
}
|
174 |
+
|
175 |
+
div.wpgdprc .wpgdprc-switch .wpgdprc-switch-inner:before,
|
176 |
+
div.wpgdprc .wpgdprc-switch .wpgdprc-switch-inner:after {
|
177 |
+
float: left;
|
178 |
+
width: 50%;
|
179 |
+
text-transform: uppercase;
|
180 |
+
line-height: 30px;
|
181 |
+
font-size: 12px;
|
182 |
+
color: #FFFFFF;
|
183 |
+
content: '';
|
184 |
+
}
|
185 |
+
|
186 |
+
div.wpgdprc .wpgdprc-switch .wpgdprc-switch-inner:before {
|
187 |
+
padding-left: 10px;
|
188 |
+
background-color: #4AA94F;
|
189 |
+
}
|
190 |
+
|
191 |
+
div.wpgdprc .wpgdprc-switch .wpgdprc-switch-inner:after {
|
192 |
+
padding-right: 10px;
|
193 |
+
background-color: #0A0A0A;
|
194 |
+
text-align: right;
|
195 |
+
}
|
196 |
+
|
197 |
+
div.wpgdprc .wpgdprc-switch--reverse .wpgdprc-switch-inner:before {
|
198 |
+
background-color: #FFAE00;
|
199 |
+
}
|
200 |
+
|
201 |
+
div.wpgdprc .wpgdprc-switch .wpgdprc-switch-switch {
|
202 |
+
position: absolute;
|
203 |
+
top: 1px;
|
204 |
+
right: 100%;
|
205 |
+
bottom: 0;
|
206 |
+
margin: 0 -29px 0 0;
|
207 |
+
width: 28px;
|
208 |
+
height: 28px;
|
209 |
+
background: #FFFFFF;
|
210 |
+
-webkit-border-radius: 50%;
|
211 |
+
-moz-border-radius: 50%;
|
212 |
+
border-radius: 50%;
|
213 |
+
-webkit-box-shadow: 0 0 3px rgba(0, 0, 0, .3);
|
214 |
+
-moz-box-shadow: 0 0 3px rgba(0, 0, 0, .3);
|
215 |
+
box-shadow: 0 0 3px rgba(0, 0, 0, .3);
|
216 |
+
transition: all 0.15s ease-in-out;
|
217 |
+
}
|
218 |
+
|
219 |
+
/**
|
220 |
+
* CONSENT: Bar
|
221 |
+
* ----------------------------------------------------------------------------
|
222 |
+
*/
|
223 |
+
|
224 |
+
div.wpgdprc-consent-bar {
|
225 |
+
position: fixed;
|
226 |
+
bottom: 0;
|
227 |
+
right: 0;
|
228 |
+
left: 0;
|
229 |
+
padding: 10px 0;
|
230 |
+
background: #000000;
|
231 |
+
text-align: center;
|
232 |
+
z-index: 999;
|
233 |
+
animation: wpgdprcFadeIn .3s cubic-bezier(0.0, 0.0, 0.2, 1);
|
234 |
+
}
|
235 |
+
|
236 |
+
div.wpgdprc-consent-bar *,
|
237 |
+
div.wpgdprc-consent-bar *:before,
|
238 |
+
div.wpgdprc-consent-bar *:after {
|
239 |
+
margin: 0;
|
240 |
+
font: inherit;
|
241 |
+
color: inherit;
|
242 |
+
}
|
243 |
+
|
244 |
+
div.wpgdprc-consent-bar div.wpgdprc-consent-bar__container {
|
245 |
+
display: inline-block;
|
246 |
+
vertical-align: top;
|
247 |
+
position: relative;
|
248 |
+
}
|
249 |
+
|
250 |
+
div.wpgdprc-consent-bar div.wpgdprc-consent-bar__column {
|
251 |
+
padding: 0 10px;
|
252 |
+
}
|
253 |
+
|
254 |
+
div.wpgdprc-consent-bar div.wpgdprc-consent-bar__content {
|
255 |
+
display: -webkit-box;
|
256 |
+
display: -ms-flexbox;
|
257 |
+
display: flex;
|
258 |
+
-webkit-box-align: center;
|
259 |
+
-ms-flex-align: center;
|
260 |
+
align-items: center;
|
261 |
+
width: 100%;
|
262 |
+
text-align: left;
|
263 |
+
color: #FFFFFF;
|
264 |
+
}
|
265 |
+
|
266 |
+
div.wpgdprc-consent-bar div.wpgdprc-consent-bar__notice {
|
267 |
+
max-width: 600px;
|
268 |
+
}
|
269 |
+
|
270 |
+
div.wpgdprc-consent-bar .wpgdprc-consent-bar__button {
|
271 |
+
padding: 5px 10px;
|
272 |
+
border: none;
|
273 |
+
}
|
274 |
+
|
275 |
+
/**
|
276 |
+
* CONSENT: Modal
|
277 |
+
* ----------------------------------------------------------------------------
|
278 |
+
*/
|
279 |
+
|
280 |
+
div.wpgdprc-consent-modal {
|
281 |
+
display: none;
|
282 |
+
}
|
283 |
+
|
284 |
+
div.wpgdprc-consent-modal.is-open {
|
285 |
+
display: block !important;
|
286 |
+
}
|
287 |
+
|
288 |
+
div.wpgdprc-consent-modal[aria-hidden="false"] div.wpgdprc-consent-modal__overlay {
|
289 |
+
animation: wpgdprcFadeIn .3s cubic-bezier(0.0, 0.0, 0.2, 1);
|
290 |
+
}
|
291 |
+
|
292 |
+
div.wpgdprc-consent-modal[aria-hidden="true"] div.wpgdprc-consent-modal__overlay {
|
293 |
+
animation: wpgdprcFadeOut .3s cubic-bezier(0.0, 0.0, 0.2, 1);
|
294 |
+
}
|
295 |
+
|
296 |
+
div.wpgdprc-consent-modal h3.wpgdprc-consent-modal__title {
|
297 |
+
margin-top: 0;
|
298 |
+
margin-bottom: 1em;
|
299 |
+
font-size: 16px;
|
300 |
+
font-weight: bold;
|
301 |
+
color: #000000;
|
302 |
+
}
|
303 |
+
|
304 |
+
div.wpgdprc-consent-modal div.wpgdprc-consent-modal__description {
|
305 |
+
color: #8A8A8A;
|
306 |
+
}
|
307 |
+
|
308 |
+
div.wpgdprc-consent-modal div.wpgdprc-consent-modal__overlay {
|
309 |
+
will-change: transform;
|
310 |
+
display: -webkit-box;
|
311 |
+
display: -ms-flexbox;
|
312 |
+
display: flex;
|
313 |
+
position: fixed;
|
314 |
+
top: 0;
|
315 |
+
right: 0;
|
316 |
+
bottom: 0;
|
317 |
+
left: 0;
|
318 |
+
background: #000000;
|
319 |
+
background: rgba(0, 0, 0, 0.6);
|
320 |
+
justify-content: center;
|
321 |
+
-webkit-box-align: center;
|
322 |
+
-ms-flex-align: center;
|
323 |
+
align-items: center;
|
324 |
+
z-index: 999999;
|
325 |
+
}
|
326 |
+
|
327 |
+
div.wpgdprc-consent-modal div.wpgdprc-consent-modal__container {
|
328 |
+
position: relative;
|
329 |
+
width: 80%;
|
330 |
+
width: 80vw;
|
331 |
+
height: 80%;
|
332 |
+
height: 80vh;
|
333 |
+
max-width: 800px;
|
334 |
+
background: #FFFFFF;
|
335 |
+
border-top: 10px solid #DBD6D6;
|
336 |
+
overflow-y: auto;
|
337 |
+
}
|
338 |
+
|
339 |
+
div.wpgdprc-consent-modal button.wpgdprc-consent-modal__close {
|
340 |
+
position: absolute;
|
341 |
+
top: 0;
|
342 |
+
right: 0;
|
343 |
+
margin: 0;
|
344 |
+
padding: 0;
|
345 |
+
width: 40px;
|
346 |
+
height: 40px;
|
347 |
+
font-size: 21px;
|
348 |
+
line-height: 40px;
|
349 |
+
}
|
350 |
+
|
351 |
+
div.wpgdprc-consent-modal button.wpgdprc-consent-modal__close,
|
352 |
+
div.wpgdprc-consent-modal button.wpgdprc-consent-modal__close:hover,
|
353 |
+
div.wpgdprc-consent-modal button.wpgdprc-consent-modal__close:focus {
|
354 |
+
background: #FFFFFF;
|
355 |
+
border: none;
|
356 |
+
color: inherit;
|
357 |
+
}
|
358 |
+
|
359 |
+
div.wpgdprc-consent-modal nav.wpgdprc-consent-modal__navigation,
|
360 |
+
div.wpgdprc-consent-modal div.wpgdprc-consent-modal__information {
|
361 |
+
position: relative;
|
362 |
+
padding: 30px;
|
363 |
+
}
|
364 |
+
|
365 |
+
div.wpgdprc-consent-modal nav.wpgdprc-consent-modal__navigation {
|
366 |
+
border-bottom: 1px solid #DBD6D6;
|
367 |
+
}
|
368 |
+
|
369 |
+
div.wpgdprc-consent-modal nav.wpgdprc-consent-modal__navigation > a {
|
370 |
+
display: block;
|
371 |
+
margin-top: 10px;
|
372 |
+
}
|
373 |
+
|
374 |
+
div.wpgdprc-consent-modal nav.wpgdprc-consent-modal__navigation > a:first-child {
|
375 |
+
margin-top: 0;
|
376 |
+
}
|
377 |
+
|
378 |
+
div.wpgdprc-consent-modal div.wpgdprc-consent-modal__information {
|
379 |
+
padding-bottom: 110px;
|
380 |
+
}
|
381 |
+
|
382 |
+
div.wpgdprc-consent-modal footer.wpgdprc-consent-modal__footer {
|
383 |
+
display: -webkit-box;
|
384 |
+
display: -ms-flexbox;
|
385 |
+
display: flex;
|
386 |
+
-webkit-box-align: center;
|
387 |
+
-ms-flex-align: center;
|
388 |
+
align-items: center;
|
389 |
+
position: absolute;
|
390 |
+
right: 0;
|
391 |
+
bottom: 0;
|
392 |
+
left: 0;
|
393 |
+
padding: 0 30px;
|
394 |
+
height: 80px;
|
395 |
+
border-top: 1px solid #DBD6D6;
|
396 |
+
}
|
397 |
+
|
398 |
+
@media only screen and (min-width: 768px) {
|
399 |
+
div.wpgdprc-consent-modal nav.wpgdprc-consent-modal__navigation,
|
400 |
+
div.wpgdprc-consent-modal div.wpgdprc-consent-modal__information {
|
401 |
+
float: left;
|
402 |
+
min-height: 100%;
|
403 |
+
}
|
404 |
+
div.wpgdprc-consent-modal nav.wpgdprc-consent-modal__navigation {
|
405 |
+
width: 40%;
|
406 |
+
border-right: 1px solid #DBD6D6;
|
407 |
+
border-bottom: none;
|
408 |
+
}
|
409 |
+
div.wpgdprc-consent-modal div.wpgdprc-consent-modal__information {
|
410 |
+
width: 60%;
|
411 |
+
}
|
412 |
+
}
|
413 |
+
|
414 |
+
abbr.wpgdprc-required + abbr.required {
|
415 |
+
display: none !important;
|
416 |
+
}
|
417 |
+
|
418 |
+
@keyframes wpgdprcFadeIn {
|
419 |
+
from {
|
420 |
+
opacity: 0;
|
421 |
+
}
|
422 |
+
to {
|
423 |
+
opacity: 1;
|
424 |
+
}
|
425 |
+
}
|
426 |
+
|
427 |
+
@keyframes wpgdprcFadeOut {
|
428 |
+
from {
|
429 |
+
opacity: 1;
|
430 |
+
}
|
431 |
+
to {
|
432 |
+
opacity: 0;
|
433 |
+
}
|
434 |
}
|
assets/js/admin.js
CHANGED
@@ -1,196 +1,196 @@
|
|
1 |
-
(function ($, window, document, undefined) {
|
2 |
-
'use strict';
|
3 |
-
|
4 |
-
var ajaxURL = wpgdprcData.ajaxURL,
|
5 |
-
ajaxSecurity = wpgdprcData.ajaxSecurity,
|
6 |
-
delay = (function () {
|
7 |
-
var timer = 0;
|
8 |
-
return function (callback, ms) {
|
9 |
-
clearTimeout(timer);
|
10 |
-
timer = setTimeout(callback, ms);
|
11 |
-
};
|
12 |
-
})(),
|
13 |
-
$wpgdprc = $('.wpgdprc'),
|
14 |
-
$checkbox = $('input[type="checkbox"]', $('.wpgdprc-checkbox, .wpgdprc-setting', $wpgdprc)),
|
15 |
-
$selectAll = $('.wpgdprc-select-all', $wpgdprc),
|
16 |
-
$formProcessDeleteRequests = $('.wpgdprc-form--process-delete-requests'),
|
17 |
-
/**
|
18 |
-
* @param $checkboxes
|
19 |
-
* @returns {Array}
|
20 |
-
* @private
|
21 |
-
*/
|
22 |
-
_getValuesByCheckedBoxes = function ($checkboxes) {
|
23 |
-
var output = [];
|
24 |
-
if ($checkboxes.length) {
|
25 |
-
$checkboxes.each(function () {
|
26 |
-
var $this = $(this),
|
27 |
-
value = $this.val();
|
28 |
-
if ($this.is(':checked') && value > 0) {
|
29 |
-
output.push(value);
|
30 |
-
}
|
31 |
-
});
|
32 |
-
}
|
33 |
-
return output;
|
34 |
-
},
|
35 |
-
/**
|
36 |
-
* @param $element
|
37 |
-
* @returns {*}
|
38 |
-
* @private
|
39 |
-
*/
|
40 |
-
_getElementAjaxData = function ($element) {
|
41 |
-
var data = $element.data();
|
42 |
-
if (!data.option) {
|
43 |
-
data.option = $element.attr('name');
|
44 |
-
}
|
45 |
-
if ($element.is('input')) {
|
46 |
-
data.value = $element.val();
|
47 |
-
if ($element.is('input[type="checkbox"]')) {
|
48 |
-
data.enabled = ($element.is(':checked'));
|
49 |
-
}
|
50 |
-
}
|
51 |
-
return data;
|
52 |
-
},
|
53 |
-
/**
|
54 |
-
* @param $element
|
55 |
-
* @private
|
56 |
-
*/
|
57 |
-
_doProcessSettings = function ($element) {
|
58 |
-
$element.addClass('processing');
|
59 |
-
var $checkboxContainer = $element.closest('.wpgdprc-checkbox'),
|
60 |
-
$checkboxData = ($checkboxContainer.length) ? $checkboxContainer.next('.wpgdprc-checkbox-data') : false;
|
61 |
-
$.ajax({
|
62 |
-
url: ajaxURL,
|
63 |
-
type: 'POST',
|
64 |
-
dataType: 'JSON',
|
65 |
-
data: {
|
66 |
-
action: 'wpgdprc_process_settings',
|
67 |
-
security: ajaxSecurity,
|
68 |
-
data: _getElementAjaxData($element)
|
69 |
-
},
|
70 |
-
success: function (response) {
|
71 |
-
if (response) {
|
72 |
-
if (response.error) {
|
73 |
-
if ($element.is(':checked')) {
|
74 |
-
$element.prop('checked', false);
|
75 |
-
}
|
76 |
-
$element.addClass('alert');
|
77 |
-
} else {
|
78 |
-
if ($checkboxData.length) {
|
79 |
-
if ($element.is(':checked')) {
|
80 |
-
$checkboxData.stop(true, true).slideDown('fast');
|
81 |
-
} else {
|
82 |
-
$checkboxData.stop(true, true).slideUp('fast');
|
83 |
-
}
|
84 |
-
}
|
85 |
-
if (response.redirect) {
|
86 |
-
document.location.href = currentPage;
|
87 |
-
}
|
88 |
-
}
|
89 |
-
}
|
90 |
-
},
|
91 |
-
complete: function () {
|
92 |
-
$element.removeClass('processing');
|
93 |
-
delay(function () {
|
94 |
-
$element.removeClass('alert');
|
95 |
-
}, 2000);
|
96 |
-
}
|
97 |
-
});
|
98 |
-
},
|
99 |
-
_ajax = function (values, $form, delay) {
|
100 |
-
var value = values.slice(0, 1);
|
101 |
-
if (value.length > 0) {
|
102 |
-
var $feedback = $('.wpgdprc-message', $form),
|
103 |
-
$row = $('tr[data-id="' + value[0] + '"]', $form);
|
104 |
-
$row.removeClass('wpgdprc-status--error');
|
105 |
-
$row.addClass('wpgdprc-status--processing');
|
106 |
-
$feedback.attr('style', 'display: none;');
|
107 |
-
$feedback.removeClass('wpgdprc-message--error');
|
108 |
-
$feedback.empty();
|
109 |
-
setTimeout(function () {
|
110 |
-
$.ajax({
|
111 |
-
url: ajaxURL,
|
112 |
-
type: 'POST',
|
113 |
-
dataType: 'JSON',
|
114 |
-
data: {
|
115 |
-
action: 'wpgdprc_process_delete_request',
|
116 |
-
security: ajaxSecurity,
|
117 |
-
data: {
|
118 |
-
id: value[0]
|
119 |
-
}
|
120 |
-
},
|
121 |
-
success: function (response) {
|
122 |
-
if (response) {
|
123 |
-
$row.removeClass('wpgdprc-status--processing');
|
124 |
-
if (response.error) {
|
125 |
-
$row.addClass('wpgdprc-status--error');
|
126 |
-
$feedback.html(response.error);
|
127 |
-
$feedback.addClass('wpgdprc-message--error');
|
128 |
-
$feedback.removeAttr('style');
|
129 |
-
} else {
|
130 |
-
values.splice(0, 1);
|
131 |
-
$('input[type="checkbox"]', $row).remove();
|
132 |
-
$row.addClass('wpgdprc-status--removed');
|
133 |
-
$('.dashicons-no', $row).removeClass('dashicons-no').addClass('dashicons-yes');
|
134 |
-
_ajax(values, $form, 500);
|
135 |
-
|
136 |
-
}
|
137 |
-
}
|
138 |
-
}
|
139 |
-
});
|
140 |
-
}, (delay || 0));
|
141 |
-
}
|
142 |
-
},
|
143 |
-
initCheckboxes = function () {
|
144 |
-
if (!$checkbox.length) {
|
145 |
-
return;
|
146 |
-
}
|
147 |
-
$checkbox.on('change', function (e) {
|
148 |
-
if ($(this).data('option')) {
|
149 |
-
e.preventDefault();
|
150 |
-
_doProcessSettings($(this));
|
151 |
-
}
|
152 |
-
});
|
153 |
-
},
|
154 |
-
initSelectAll = function () {
|
155 |
-
if (!$selectAll.length) {
|
156 |
-
return;
|
157 |
-
}
|
158 |
-
$selectAll.on('change', function () {
|
159 |
-
var $this = $(this),
|
160 |
-
checked = $this.is(':checked'),
|
161 |
-
$checkboxes = $('tbody input[type="checkbox"]', $this.closest('table'));
|
162 |
-
$checkboxes.prop('checked', checked);
|
163 |
-
});
|
164 |
-
},
|
165 |
-
initProcessDeleteRequests = function () {
|
166 |
-
if (!$formProcessDeleteRequests.length) {
|
167 |
-
return;
|
168 |
-
}
|
169 |
-
$formProcessDeleteRequests.on('submit', function (e) {
|
170 |
-
e.preventDefault();
|
171 |
-
var $this = $(this),
|
172 |
-
$checkboxes = $('.wpgdprc-checkbox', $this);
|
173 |
-
$selectAll.prop('checked', false);
|
174 |
-
_ajax(_getValuesByCheckedBoxes($checkboxes), $this);
|
175 |
-
});
|
176 |
-
};
|
177 |
-
|
178 |
-
$(function () {
|
179 |
-
if (!$wpgdprc.length) {
|
180 |
-
return;
|
181 |
-
}
|
182 |
-
initCheckboxes();
|
183 |
-
initSelectAll();
|
184 |
-
initProcessDeleteRequests();
|
185 |
-
|
186 |
-
var $snippet = document.getElementById('wpgdprc_snippet');
|
187 |
-
if ($snippet !== null) {
|
188 |
-
var editor = CodeMirror.fromTextArea($snippet, {
|
189 |
-
mode: 'text/html',
|
190 |
-
lineNumbers: true,
|
191 |
-
matchBrackets: true,
|
192 |
-
indentUnit: 4
|
193 |
-
});
|
194 |
-
}
|
195 |
-
});
|
196 |
})(jQuery, window, document);
|
1 |
+
(function ($, window, document, undefined) {
|
2 |
+
'use strict';
|
3 |
+
|
4 |
+
var ajaxURL = wpgdprcData.ajaxURL,
|
5 |
+
ajaxSecurity = wpgdprcData.ajaxSecurity,
|
6 |
+
delay = (function () {
|
7 |
+
var timer = 0;
|
8 |
+
return function (callback, ms) {
|
9 |
+
clearTimeout(timer);
|
10 |
+
timer = setTimeout(callback, ms);
|
11 |
+
};
|
12 |
+
})(),
|
13 |
+
$wpgdprc = $('.wpgdprc'),
|
14 |
+
$checkbox = $('input[type="checkbox"]', $('.wpgdprc-checkbox, .wpgdprc-setting', $wpgdprc)),
|
15 |
+
$selectAll = $('.wpgdprc-select-all', $wpgdprc),
|
16 |
+
$formProcessDeleteRequests = $('.wpgdprc-form--process-delete-requests'),
|
17 |
+
/**
|
18 |
+
* @param $checkboxes
|
19 |
+
* @returns {Array}
|
20 |
+
* @private
|
21 |
+
*/
|
22 |
+
_getValuesByCheckedBoxes = function ($checkboxes) {
|
23 |
+
var output = [];
|
24 |
+
if ($checkboxes.length) {
|
25 |
+
$checkboxes.each(function () {
|
26 |
+
var $this = $(this),
|
27 |
+
value = $this.val();
|
28 |
+
if ($this.is(':checked') && value > 0) {
|
29 |
+
output.push(value);
|
30 |
+
}
|
31 |
+
});
|
32 |
+
}
|
33 |
+
return output;
|
34 |
+
},
|
35 |
+
/**
|
36 |
+
* @param $element
|
37 |
+
* @returns {*}
|
38 |
+
* @private
|
39 |
+
*/
|
40 |
+
_getElementAjaxData = function ($element) {
|
41 |
+
var data = $element.data();
|
42 |
+
if (!data.option) {
|
43 |
+
data.option = $element.attr('name');
|
44 |
+
}
|
45 |
+
if ($element.is('input')) {
|
46 |
+
data.value = $element.val();
|
47 |
+
if ($element.is('input[type="checkbox"]')) {
|
48 |
+
data.enabled = ($element.is(':checked'));
|
49 |
+
}
|
50 |
+
}
|
51 |
+
return data;
|
52 |
+
},
|
53 |
+
/**
|
54 |
+
* @param $element
|
55 |
+
* @private
|
56 |
+
*/
|
57 |
+
_doProcessSettings = function ($element) {
|
58 |
+
$element.addClass('processing');
|
59 |
+
var $checkboxContainer = $element.closest('.wpgdprc-checkbox'),
|
60 |
+
$checkboxData = ($checkboxContainer.length) ? $checkboxContainer.next('.wpgdprc-checkbox-data') : false;
|
61 |
+
$.ajax({
|
62 |
+
url: ajaxURL,
|
63 |
+
type: 'POST',
|
64 |
+
dataType: 'JSON',
|
65 |
+
data: {
|
66 |
+
action: 'wpgdprc_process_settings',
|
67 |
+
security: ajaxSecurity,
|
68 |
+
data: _getElementAjaxData($element)
|
69 |
+
},
|
70 |
+
success: function (response) {
|
71 |
+
if (response) {
|
72 |
+
if (response.error) {
|
73 |
+
if ($element.is(':checked')) {
|
74 |
+
$element.prop('checked', false);
|
75 |
+
}
|
76 |
+
$element.addClass('alert');
|
77 |
+
} else {
|
78 |
+
if ($checkboxData.length) {
|
79 |
+
if ($element.is(':checked')) {
|
80 |
+
$checkboxData.stop(true, true).slideDown('fast');
|
81 |
+
} else {
|
82 |
+
$checkboxData.stop(true, true).slideUp('fast');
|
83 |
+
}
|
84 |
+
}
|
85 |
+
if (response.redirect) {
|
86 |
+
document.location.href = currentPage;
|
87 |
+
}
|
88 |
+
}
|
89 |
+
}
|
90 |
+
},
|
91 |
+
complete: function () {
|
92 |
+
$element.removeClass('processing');
|
93 |
+
delay(function () {
|
94 |
+
$element.removeClass('alert');
|
95 |
+
}, 2000);
|
96 |
+
}
|
97 |
+
});
|
98 |
+
},
|
99 |
+
_ajax = function (values, $form, delay) {
|
100 |
+
var value = values.slice(0, 1);
|
101 |
+
if (value.length > 0) {
|
102 |
+
var $feedback = $('.wpgdprc-message', $form),
|
103 |
+
$row = $('tr[data-id="' + value[0] + '"]', $form);
|
104 |
+
$row.removeClass('wpgdprc-status--error');
|
105 |
+
$row.addClass('wpgdprc-status--processing');
|
106 |
+
$feedback.attr('style', 'display: none;');
|
107 |
+
$feedback.removeClass('wpgdprc-message--error');
|
108 |
+
$feedback.empty();
|
109 |
+
setTimeout(function () {
|
110 |
+
$.ajax({
|
111 |
+
url: ajaxURL,
|
112 |
+
type: 'POST',
|
113 |
+
dataType: 'JSON',
|
114 |
+
data: {
|
115 |
+
action: 'wpgdprc_process_delete_request',
|
116 |
+
security: ajaxSecurity,
|
117 |
+
data: {
|
118 |
+
id: value[0]
|
119 |
+
}
|
120 |
+
},
|
121 |
+
success: function (response) {
|
122 |
+
if (response) {
|
123 |
+
$row.removeClass('wpgdprc-status--processing');
|
124 |
+
if (response.error) {
|
125 |
+
$row.addClass('wpgdprc-status--error');
|
126 |
+
$feedback.html(response.error);
|
127 |
+
$feedback.addClass('wpgdprc-message--error');
|
128 |
+
$feedback.removeAttr('style');
|
129 |
+
} else {
|
130 |
+
values.splice(0, 1);
|
131 |
+
$('input[type="checkbox"]', $row).remove();
|
132 |
+
$row.addClass('wpgdprc-status--removed');
|
133 |
+
$('.dashicons-no', $row).removeClass('dashicons-no').addClass('dashicons-yes');
|
134 |
+
_ajax(values, $form, 500);
|
135 |
+
|
136 |
+
}
|
137 |
+
}
|
138 |
+
}
|
139 |
+
});
|
140 |
+
}, (delay || 0));
|
141 |
+
}
|
142 |
+
},
|
143 |
+
initCheckboxes = function () {
|
144 |
+
if (!$checkbox.length) {
|
145 |
+
return;
|
146 |
+
}
|
147 |
+
$checkbox.on('change', function (e) {
|
148 |
+
if ($(this).data('option')) {
|
149 |
+
e.preventDefault();
|
150 |
+
_doProcessSettings($(this));
|
151 |
+
}
|
152 |
+
});
|
153 |
+
},
|
154 |
+
initSelectAll = function () {
|
155 |
+
if (!$selectAll.length) {
|
156 |
+
return;
|
157 |
+
}
|
158 |
+
$selectAll.on('change', function () {
|
159 |
+
var $this = $(this),
|
160 |
+
checked = $this.is(':checked'),
|
161 |
+
$checkboxes = $('tbody input[type="checkbox"]', $this.closest('table'));
|
162 |
+
$checkboxes.prop('checked', checked);
|
163 |
+
});
|
164 |
+
},
|
165 |
+
initProcessDeleteRequests = function () {
|
166 |
+
if (!$formProcessDeleteRequests.length) {
|
167 |
+
return;
|
168 |
+
}
|
169 |
+
$formProcessDeleteRequests.on('submit', function (e) {
|
170 |
+
e.preventDefault();
|
171 |
+
var $this = $(this),
|
172 |
+
$checkboxes = $('.wpgdprc-checkbox', $this);
|
173 |
+
$selectAll.prop('checked', false);
|
174 |
+
_ajax(_getValuesByCheckedBoxes($checkboxes), $this);
|
175 |
+
});
|
176 |
+
};
|
177 |
+
|
178 |
+
$(function () {
|
179 |
+
if (!$wpgdprc.length) {
|
180 |
+
return;
|
181 |
+
}
|
182 |
+
initCheckboxes();
|
183 |
+
initSelectAll();
|
184 |
+
initProcessDeleteRequests();
|
185 |
+
|
186 |
+
var $snippet = document.getElementById('wpgdprc_snippet');
|
187 |
+
if ($snippet !== null) {
|
188 |
+
var editor = CodeMirror.fromTextArea($snippet, {
|
189 |
+
mode: 'text/html',
|
190 |
+
lineNumbers: true,
|
191 |
+
matchBrackets: true,
|
192 |
+
indentUnit: 4
|
193 |
+
});
|
194 |
+
}
|
195 |
+
});
|
196 |
})(jQuery, window, document);
|
assets/js/front.js
CHANGED
@@ -1,317 +1,317 @@
|
|
1 |
-
(function (window, document, undefined) {
|
2 |
-
'use strict';
|
3 |
-
|
4 |
-
/**
|
5 |
-
* @param data
|
6 |
-
* @returns {string}
|
7 |
-
* @private
|
8 |
-
*/
|
9 |
-
var ajaxLoading = false,
|
10 |
-
ajaxURL = wpgdprcData.ajaxURL,
|
11 |
-
ajaxSecurity = wpgdprcData.ajaxSecurity,
|
12 |
-
_objectToParametersString = function (data) {
|
13 |
-
return Object.keys(data).map(function (key) {
|
14 |
-
var value = data[key];
|
15 |
-
if (typeof value === 'object') {
|
16 |
-
value = JSON.stringify(value);
|
17 |
-
}
|
18 |
-
return key + '=' + value;
|
19 |
-
}).join('&');
|
20 |
-
},
|
21 |
-
/**
|
22 |
-
* @param $checkboxes
|
23 |
-
* @returns {Array}
|
24 |
-
* @private
|
25 |
-
*/
|
26 |
-
_getValuesByCheckedBoxes = function ($checkboxes) {
|
27 |
-
var output = [];
|
28 |
-
if ($checkboxes.length) {
|
29 |
-
$checkboxes.forEach(function (e) {
|
30 |
-
var value = parseInt(e.value);
|
31 |
-
if (e.checked && value > 0) {
|
32 |
-
output.push(value);
|
33 |
-
}
|
34 |
-
});
|
35 |
-
}
|
36 |
-
return output;
|
37 |
-
},
|
38 |
-
/**
|
39 |
-
* @param data
|
40 |
-
* @param values
|
41 |
-
* @param $form
|
42 |
-
* @param delay
|
43 |
-
* @private
|
44 |
-
*/
|
45 |
-
_doAjax = function (data, values, $form, delay) {
|
46 |
-
var $feedback = $form.querySelector('.wpgdprc-message'),
|
47 |
-
value = values.slice(0, 1);
|
48 |
-
if (value.length > 0) {
|
49 |
-
var $row = $form.querySelector('tr[data-id="' + value[0] + '"]');
|
50 |
-
$row.classList.remove('wpgdprc-status--error');
|
51 |
-
$row.classList.add('wpgdprc-status--processing');
|
52 |
-
$feedback.setAttribute('style', 'display: none;');
|
53 |
-
$feedback.classList.remove('wpgdprc-message--error');
|
54 |
-
$feedback.innerHTML = '';
|
55 |
-
setTimeout(function () {
|
56 |
-
var request = new XMLHttpRequest();
|
57 |
-
data.data.value = value[0];
|
58 |
-
request.open('POST', ajaxURL);
|
59 |
-
request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded; charset=UTF-8');
|
60 |
-
request.send(_objectToParametersString(data));
|
61 |
-
request.addEventListener('load', function () {
|
62 |
-
if (request.response) {
|
63 |
-
var response = JSON.parse(request.response);
|
64 |
-
$row.classList.remove('wpgdprc-status--processing');
|
65 |
-
if (response.error) {
|
66 |
-
$row.classList.add('wpgdprc-status--error');
|
67 |
-
$feedback.innerHTML = response.error;
|
68 |
-
$feedback.classList.add('wpgdprc-message--error');
|
69 |
-
$feedback.removeAttribute('style');
|
70 |
-
} else {
|
71 |
-
values.splice(0, 1);
|
72 |
-
$row.querySelector('input[type="checkbox"]').remove();
|
73 |
-
$row.classList.add('wpgdprc-status--removed');
|
74 |
-
_doAjax(data, values, $form, 500);
|
75 |
-
}
|
76 |
-
}
|
77 |
-
});
|
78 |
-
}, (delay || 0));
|
79 |
-
}
|
80 |
-
},
|
81 |
-
/**
|
82 |
-
* @param data
|
83 |
-
* @param days
|
84 |
-
* @private
|
85 |
-
*/
|
86 |
-
_saveCookie = function (data, days) {
|
87 |
-
data = (data) ? data : '';
|
88 |
-
days = (days) ? days : 365;
|
89 |
-
var date = new Date();
|
90 |
-
date.setTime(date.getTime() + 24 * days * 60 * 60 * 1e3);
|
91 |
-
document.cookie = 'wpgdprc-consent-' + wpgdprcData.consentVersion +'=' + encodeURIComponent(data) + '; expires=' + date.toGMTString() + '; path=/';
|
92 |
-
},
|
93 |
-
/**
|
94 |
-
* @param name
|
95 |
-
* @returns {*}
|
96 |
-
* @private
|
97 |
-
*/
|
98 |
-
_readCookie = function (name) {
|
99 |
-
if (name) {
|
100 |
-
for (var e = encodeURIComponent(name) + "=", o = document.cookie.split(";"), r = 0; r < o.length; r++) {
|
101 |
-
for (var n = o[r]; " " === n.charAt(0);) {
|
102 |
-
n = n.substring(1, n.length);
|
103 |
-
}
|
104 |
-
if (n.indexOf(e) === 0) {
|
105 |
-
return decodeURIComponent(n.substring(e.length, n.length));
|
106 |
-
}
|
107 |
-
}
|
108 |
-
}
|
109 |
-
return null;
|
110 |
-
},
|
111 |
-
initConsentBar = function () {
|
112 |
-
var $consentBar = document.querySelector('.wpgdprc-consent-bar');
|
113 |
-
if ($consentBar === null) {
|
114 |
-
return;
|
115 |
-
}
|
116 |
-
|
117 |
-
$consentBar.style.display = 'block';
|
118 |
-
|
119 |
-
var $button = $consentBar.querySelector('.wpgdprc-consent-bar__button');
|
120 |
-
if ($button !== null) {
|
121 |
-
$button.addEventListener('click', function (e) {
|
122 |
-
e.preventDefault();
|
123 |
-
_saveCookie('accept');
|
124 |
-
window.location.reload(true);
|
125 |
-
});
|
126 |
-
}
|
127 |
-
},
|
128 |
-
initConsentModal = function () {
|
129 |
-
var $consentModal = document.querySelector('#wpgdprc-consent-modal');
|
130 |
-
if ($consentModal === null) {
|
131 |
-
return;
|
132 |
-
}
|
133 |
-
|
134 |
-
MicroModal.init({
|
135 |
-
disableScroll: true,
|
136 |
-
disableFocus: true,
|
137 |
-
onClose: function ($consentModal) {
|
138 |
-
var $descriptions = $consentModal.querySelectorAll('.wpgdprc-consent-modal__description'),
|
139 |
-
$buttons = $consentModal.querySelectorAll('.wpgdprc-consent-modal__navigation > a'),
|
140 |
-
$checkboxes = $consentModal.querySelectorAll('input[type="checkbox"]');
|
141 |
-
|
142 |
-
if ($descriptions.length > 0) {
|
143 |
-
for (var i = 0; i < $descriptions.length; i++) {
|
144 |
-
$descriptions[i].style.display = ((i === 0) ? 'block' : 'none');
|
145 |
-
}
|
146 |
-
}
|
147 |
-
if ($buttons.length > 0) {
|
148 |
-
for (var i = 0; i < $buttons.length; i++) {
|
149 |
-
$buttons[i].classList.remove('wpgdprc-button--active');
|
150 |
-
}
|
151 |
-
}
|
152 |
-
if ($checkboxes.length > 0) {
|
153 |
-
for (var i = 0; i < $checkboxes.length; i++) {
|
154 |
-
$checkboxes[i].checked = false;
|
155 |
-
}
|
156 |
-
}
|
157 |
-
}
|
158 |
-
});
|
159 |
-
|
160 |
-
var $settingsLink = document.querySelector('.wpgdprc-consents-settings-link');
|
161 |
-
if ($settingsLink !== null) {
|
162 |
-
$settingsLink.addEventListener('click', function (e) {
|
163 |
-
e.preventDefault();
|
164 |
-
MicroModal.show('wpgdprc-consent-modal');
|
165 |
-
});
|
166 |
-
}
|
167 |
-
|
168 |
-
var $buttons = $consentModal.querySelectorAll('.wpgdprc-consent-modal__navigation > a');
|
169 |
-
if ($buttons.length > 0) {
|
170 |
-
var $descriptions = $consentModal.querySelectorAll('.wpgdprc-consent-modal__description');
|
171 |
-
for (var i = 0; i < $buttons.length; i++) {
|
172 |
-
$buttons[i].addEventListener('click', function (e) {
|
173 |
-
e.preventDefault();
|
174 |
-
var $target = $consentModal.querySelector('.wpgdprc-consent-modal__description[data-target="' + this.dataset.target + '"]');
|
175 |
-
if ($target !== null) {
|
176 |
-
for (var i = 0; i < $buttons.length; i++) {
|
177 |
-
$buttons[i].classList.remove('wpgdprc-button--active');
|
178 |
-
}
|
179 |
-
this.classList.add('wpgdprc-button--active');
|
180 |
-
for (var i = 0; i < $descriptions.length; i++) {
|
181 |
-
$descriptions[i].style.display = 'none';
|
182 |
-
}
|
183 |
-
$target.style.display = 'block';
|
184 |
-
}
|
185 |
-
});
|
186 |
-
}
|
187 |
-
}
|
188 |
-
|
189 |
-
var $buttonSave = $consentModal.querySelector('.wpgdprc-button--secondary');
|
190 |
-
if ($buttonSave !== null) {
|
191 |
-
$buttonSave.addEventListener('click', function (e) {
|
192 |
-
e.preventDefault();
|
193 |
-
var $checkboxes = $consentModal.querySelectorAll('input[type="checkbox"]'),
|
194 |
-
checked = [];
|
195 |
-
|
196 |
-
if ($checkboxes.length > 0) {
|
197 |
-
for (var i = 0; i < $checkboxes.length; i++) {
|
198 |
-
var $checkbox = $checkboxes[i],
|
199 |
-
value = $checkbox.value;
|
200 |
-
if ($checkbox.checked === true && !isNaN(value)) {
|
201 |
-
checked.push(parseInt(value));
|
202 |
-
}
|
203 |
-
}
|
204 |
-
if (checked.length > 0) {
|
205 |
-
_saveCookie(checked);
|
206 |
-
} else {
|
207 |
-
_saveCookie('decline');
|
208 |
-
}
|
209 |
-
}
|
210 |
-
|
211 |
-
window.location.reload(true);
|
212 |
-
});
|
213 |
-
}
|
214 |
-
},
|
215 |
-
initFormAccessRequest = function () {
|
216 |
-
var $formAccessRequest = document.querySelector('.wpgdprc-form--access-request');
|
217 |
-
if ($formAccessRequest === null) {
|
218 |
-
return;
|
219 |
-
}
|
220 |
-
|
221 |
-
var $feedback = $formAccessRequest.querySelector('.wpgdprc-message'),
|
222 |
-
$emailAddress = $formAccessRequest.querySelector('#wpgdprc-form__email'),
|
223 |
-
$consent = $formAccessRequest.querySelector('#wpgdprc-form__consent');
|
224 |
-
|
225 |
-
$formAccessRequest.addEventListener('submit', function (e) {
|
226 |
-
e.preventDefault();
|
227 |
-
if (!ajaxLoading) {
|
228 |
-
ajaxLoading = true;
|
229 |
-
$feedback.style.display = 'none';
|
230 |
-
$feedback.classList.remove('wpgdprc-message--success', 'wpgdprc-message--error');
|
231 |
-
$feedback.innerHTML = '';
|
232 |
-
|
233 |
-
var data = {
|
234 |
-
action: 'wpgdprc_process_action',
|
235 |
-
security: ajaxSecurity,
|
236 |
-
data: {
|
237 |
-
type: 'access_request',
|
238 |
-
email: $emailAddress.value,
|
239 |
-
consent: $consent.checked
|
240 |
-
}
|
241 |
-
},
|
242 |
-
request = new XMLHttpRequest();
|
243 |
-
|
244 |
-
data = _objectToParametersString(data);
|
245 |
-
request.open('POST', ajaxURL, true);
|
246 |
-
request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded; charset=UTF-8');
|
247 |
-
request.send(data);
|
248 |
-
request.addEventListener('load', function () {
|
249 |
-
if (request.response) {
|
250 |
-
var response = JSON.parse(request.response);
|
251 |
-
if (response.message) {
|
252 |
-
$formAccessRequest.reset();
|
253 |
-
$emailAddress.blur();
|
254 |
-
$feedback.innerHTML = response.message;
|
255 |
-
$feedback.classList.add('wpgdprc-message--success');
|
256 |
-
$feedback.removeAttribute('style');
|
257 |
-
}
|
258 |
-
if (response.error) {
|
259 |
-
$emailAddress.focus();
|
260 |
-
$feedback.innerHTML = response.error;
|
261 |
-
$feedback.classList.add('wpgdprc-message--error');
|
262 |
-
$feedback.removeAttribute('style');
|
263 |
-
}
|
264 |
-
}
|
265 |
-
ajaxLoading = false;
|
266 |
-
});
|
267 |
-
}
|
268 |
-
});
|
269 |
-
},
|
270 |
-
initFormDeleteRequest = function () {
|
271 |
-
var $formDeleteRequest = document.querySelectorAll('.wpgdprc-form--delete-request');
|
272 |
-
if ($formDeleteRequest.length < 1) {
|
273 |
-
return;
|
274 |
-
}
|
275 |
-
|
276 |
-
$formDeleteRequest.forEach(function ($form) {
|
277 |
-
var $selectAll = $form.querySelector('.wpgdprc-select-all');
|
278 |
-
|
279 |
-
$form.addEventListener('submit', function (e) {
|
280 |
-
e.preventDefault();
|
281 |
-
var $this = e.target,
|
282 |
-
$checkboxes = $this.querySelectorAll('.wpgdprc-checkbox'),
|
283 |
-
data = {
|
284 |
-
action: 'wpgdprc_process_action',
|
285 |
-
security: ajaxSecurity,
|
286 |
-
data: {
|
287 |
-
type: 'delete_request',
|
288 |
-
token: wpgdprcData.token,
|
289 |
-
settings: JSON.parse($this.dataset.wpgdprc)
|
290 |
-
}
|
291 |
-
};
|
292 |
-
$selectAll.checked = false;
|
293 |
-
_doAjax(data, _getValuesByCheckedBoxes($checkboxes), $this);
|
294 |
-
});
|
295 |
-
|
296 |
-
if ($selectAll !== null) {
|
297 |
-
$selectAll.addEventListener('change', function (e) {
|
298 |
-
var $this = e.target,
|
299 |
-
checked = $this.checked,
|
300 |
-
$checkboxes = $form.querySelectorAll('.wpgdprc-checkbox');
|
301 |
-
$checkboxes.forEach(function (e) {
|
302 |
-
e.checked = checked;
|
303 |
-
});
|
304 |
-
});
|
305 |
-
}
|
306 |
-
});
|
307 |
-
};
|
308 |
-
|
309 |
-
document.addEventListener('DOMContentLoaded', function () {
|
310 |
-
if (_readCookie('wpgdprc-consent-' + wpgdprcData.consentVersion) === null) {
|
311 |
-
initConsentBar();
|
312 |
-
}
|
313 |
-
initConsentModal();
|
314 |
-
initFormAccessRequest();
|
315 |
-
initFormDeleteRequest();
|
316 |
-
});
|
317 |
})(window, document);
|
1 |
+
(function (window, document, undefined) {
|
2 |
+
'use strict';
|
3 |
+
|
4 |
+
/**
|
5 |
+
* @param data
|
6 |
+
* @returns {string}
|
7 |
+
* @private
|
8 |
+
*/
|
9 |
+
var ajaxLoading = false,
|
10 |
+
ajaxURL = wpgdprcData.ajaxURL,
|
11 |
+
ajaxSecurity = wpgdprcData.ajaxSecurity,
|
12 |
+
_objectToParametersString = function (data) {
|
13 |
+
return Object.keys(data).map(function (key) {
|
14 |
+
var value = data[key];
|
15 |
+
if (typeof value === 'object') {
|
16 |
+
value = JSON.stringify(value);
|
17 |
+
}
|
18 |
+
return key + '=' + value;
|
19 |
+
}).join('&');
|
20 |
+
},
|
21 |
+
/**
|
22 |
+
* @param $checkboxes
|
23 |
+
* @returns {Array}
|
24 |
+
* @private
|
25 |
+
*/
|
26 |
+
_getValuesByCheckedBoxes = function ($checkboxes) {
|
27 |
+
var output = [];
|
28 |
+
if ($checkboxes.length) {
|
29 |
+
$checkboxes.forEach(function (e) {
|
30 |
+
var value = parseInt(e.value);
|
31 |
+
if (e.checked && value > 0) {
|
32 |
+
output.push(value);
|
33 |
+
}
|
34 |
+
});
|
35 |
+
}
|
36 |
+
return output;
|
37 |
+
},
|
38 |
+
/**
|
39 |
+
* @param data
|
40 |
+
* @param values
|
41 |
+
* @param $form
|
42 |
+
* @param delay
|
43 |
+
* @private
|
44 |
+
*/
|
45 |
+
_doAjax = function (data, values, $form, delay) {
|
46 |
+
var $feedback = $form.querySelector('.wpgdprc-message'),
|
47 |
+
value = values.slice(0, 1);
|
48 |
+
if (value.length > 0) {
|
49 |
+
var $row = $form.querySelector('tr[data-id="' + value[0] + '"]');
|
50 |
+
$row.classList.remove('wpgdprc-status--error');
|
51 |
+
$row.classList.add('wpgdprc-status--processing');
|
52 |
+
$feedback.setAttribute('style', 'display: none;');
|
53 |
+
$feedback.classList.remove('wpgdprc-message--error');
|
54 |
+
$feedback.innerHTML = '';
|
55 |
+
setTimeout(function () {
|
56 |
+
var request = new XMLHttpRequest();
|
57 |
+
data.data.value = value[0];
|
58 |
+
request.open('POST', ajaxURL);
|
59 |
+
request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded; charset=UTF-8');
|
60 |
+
request.send(_objectToParametersString(data));
|
61 |
+
request.addEventListener('load', function () {
|
62 |
+
if (request.response) {
|
63 |
+
var response = JSON.parse(request.response);
|
64 |
+
$row.classList.remove('wpgdprc-status--processing');
|
65 |
+
if (response.error) {
|
66 |
+
$row.classList.add('wpgdprc-status--error');
|
67 |
+
$feedback.innerHTML = response.error;
|
68 |
+
$feedback.classList.add('wpgdprc-message--error');
|
69 |
+
$feedback.removeAttribute('style');
|
70 |
+
} else {
|
71 |
+
values.splice(0, 1);
|
72 |
+
$row.querySelector('input[type="checkbox"]').remove();
|
73 |
+
$row.classList.add('wpgdprc-status--removed');
|
74 |
+
_doAjax(data, values, $form, 500);
|
75 |
+
}
|
76 |
+
}
|
77 |
+
});
|
78 |
+
}, (delay || 0));
|
79 |
+
}
|
80 |
+
},
|
81 |
+
/**
|
82 |
+
* @param data
|
83 |
+
* @param days
|
84 |
+
* @private
|
85 |
+
*/
|
86 |
+
_saveCookie = function (data, days) {
|
87 |
+
data = (data) ? data : '';
|
88 |
+
days = (days) ? days : 365;
|
89 |
+
var date = new Date();
|
90 |
+
date.setTime(date.getTime() + 24 * days * 60 * 60 * 1e3);
|
91 |
+
document.cookie = 'wpgdprc-consent-' + wpgdprcData.consentVersion +'=' + encodeURIComponent(data) + '; expires=' + date.toGMTString() + '; path=/';
|
92 |
+
},
|
93 |
+
/**
|
94 |
+
* @param name
|
95 |
+
* @returns {*}
|
96 |
+
* @private
|
97 |
+
*/
|
98 |
+
_readCookie = function (name) {
|
99 |
+
if (name) {
|
100 |
+
for (var e = encodeURIComponent(name) + "=", o = document.cookie.split(";"), r = 0; r < o.length; r++) {
|
101 |
+
for (var n = o[r]; " " === n.charAt(0);) {
|
102 |
+
n = n.substring(1, n.length);
|
103 |
+
}
|
104 |
+
if (n.indexOf(e) === 0) {
|
105 |
+
return decodeURIComponent(n.substring(e.length, n.length));
|
106 |
+
}
|
107 |
+
}
|
108 |
+
}
|
109 |
+
return null;
|
110 |
+
},
|
111 |
+
initConsentBar = function () {
|
112 |
+
var $consentBar = document.querySelector('.wpgdprc-consent-bar');
|
113 |
+
if ($consentBar === null) {
|
114 |
+
return;
|
115 |
+
}
|
116 |
+
|
117 |
+
$consentBar.style.display = 'block';
|
118 |
+
|
119 |
+
var $button = $consentBar.querySelector('.wpgdprc-consent-bar__button');
|
120 |
+
if ($button !== null) {
|
121 |
+
$button.addEventListener('click', function (e) {
|
122 |
+
e.preventDefault();
|
123 |
+
_saveCookie('accept');
|
124 |
+
window.location.reload(true);
|
125 |
+
});
|
126 |
+
}
|
127 |
+
},
|
128 |
+
initConsentModal = function () {
|
129 |
+
var $consentModal = document.querySelector('#wpgdprc-consent-modal');
|
130 |
+
if ($consentModal === null) {
|
131 |
+
return;
|
132 |
+
}
|
133 |
+
|
134 |
+
MicroModal.init({
|
135 |
+
disableScroll: true,
|
136 |
+
disableFocus: true,
|
137 |
+
onClose: function ($consentModal) {
|
138 |
+
var $descriptions = $consentModal.querySelectorAll('.wpgdprc-consent-modal__description'),
|
139 |
+
$buttons = $consentModal.querySelectorAll('.wpgdprc-consent-modal__navigation > a'),
|
140 |
+
$checkboxes = $consentModal.querySelectorAll('input[type="checkbox"]');
|
141 |
+
|
142 |
+
if ($descriptions.length > 0) {
|
143 |
+
for (var i = 0; i < $descriptions.length; i++) {
|
144 |
+
$descriptions[i].style.display = ((i === 0) ? 'block' : 'none');
|
145 |
+
}
|
146 |
+
}
|
147 |
+
if ($buttons.length > 0) {
|
148 |
+
for (var i = 0; i < $buttons.length; i++) {
|
149 |
+
$buttons[i].classList.remove('wpgdprc-button--active');
|
150 |
+
}
|
151 |
+
}
|
152 |
+
if ($checkboxes.length > 0) {
|
153 |
+
for (var i = 0; i < $checkboxes.length; i++) {
|
154 |
+
$checkboxes[i].checked = false;
|
155 |
+
}
|
156 |
+
}
|
157 |
+
}
|
158 |
+
});
|
159 |
+
|
160 |
+
var $settingsLink = document.querySelector('.wpgdprc-consents-settings-link');
|
161 |
+
if ($settingsLink !== null) {
|
162 |
+
$settingsLink.addEventListener('click', function (e) {
|
163 |
+
e.preventDefault();
|
164 |
+
MicroModal.show('wpgdprc-consent-modal');
|
165 |
+
});
|
166 |
+
}
|
167 |
+
|
168 |
+
var $buttons = $consentModal.querySelectorAll('.wpgdprc-consent-modal__navigation > a');
|
169 |
+
if ($buttons.length > 0) {
|
170 |
+
var $descriptions = $consentModal.querySelectorAll('.wpgdprc-consent-modal__description');
|
171 |
+
for (var i = 0; i < $buttons.length; i++) {
|
172 |
+
$buttons[i].addEventListener('click', function (e) {
|
173 |
+
e.preventDefault();
|
174 |
+
var $target = $consentModal.querySelector('.wpgdprc-consent-modal__description[data-target="' + this.dataset.target + '"]');
|
175 |
+
if ($target !== null) {
|
176 |
+
for (var i = 0; i < $buttons.length; i++) {
|
177 |
+
$buttons[i].classList.remove('wpgdprc-button--active');
|
178 |
+
}
|
179 |
+
this.classList.add('wpgdprc-button--active');
|
180 |
+
for (var i = 0; i < $descriptions.length; i++) {
|
181 |
+
$descriptions[i].style.display = 'none';
|
182 |
+
}
|
183 |
+
$target.style.display = 'block';
|
184 |
+
}
|
185 |
+
});
|
186 |
+
}
|
187 |
+
}
|
188 |
+
|
189 |
+
var $buttonSave = $consentModal.querySelector('.wpgdprc-button--secondary');
|
190 |
+
if ($buttonSave !== null) {
|
191 |
+
$buttonSave.addEventListener('click', function (e) {
|
192 |
+
e.preventDefault();
|
193 |
+
var $checkboxes = $consentModal.querySelectorAll('input[type="checkbox"]'),
|
194 |
+
checked = [];
|
195 |
+
|
196 |
+
if ($checkboxes.length > 0) {
|
197 |
+
for (var i = 0; i < $checkboxes.length; i++) {
|
198 |
+
var $checkbox = $checkboxes[i],
|
199 |
+
value = $checkbox.value;
|
200 |
+
if ($checkbox.checked === true && !isNaN(value)) {
|
201 |
+
checked.push(parseInt(value));
|
202 |
+
}
|
203 |
+
}
|
204 |
+
if (checked.length > 0) {
|
205 |
+
_saveCookie(checked);
|
206 |
+
} else {
|
207 |
+
_saveCookie('decline');
|
208 |
+
}
|
209 |
+
}
|
210 |
+
|
211 |
+
window.location.reload(true);
|
212 |
+
});
|
213 |
+
}
|
214 |
+
},
|
215 |
+
initFormAccessRequest = function () {
|
216 |
+
var $formAccessRequest = document.querySelector('.wpgdprc-form--access-request');
|
217 |
+
if ($formAccessRequest === null) {
|
218 |
+
return;
|
219 |
+
}
|
220 |
+
|
221 |
+
var $feedback = $formAccessRequest.querySelector('.wpgdprc-message'),
|
222 |
+
$emailAddress = $formAccessRequest.querySelector('#wpgdprc-form__email'),
|
223 |
+
$consent = $formAccessRequest.querySelector('#wpgdprc-form__consent');
|
224 |
+
|
225 |
+
$formAccessRequest.addEventListener('submit', function (e) {
|
226 |
+
e.preventDefault();
|
227 |
+
if (!ajaxLoading) {
|
228 |
+
ajaxLoading = true;
|
229 |
+
$feedback.style.display = 'none';
|
230 |
+
$feedback.classList.remove('wpgdprc-message--success', 'wpgdprc-message--error');
|
231 |
+
$feedback.innerHTML = '';
|
232 |
+
|
233 |
+
var data = {
|
234 |
+
action: 'wpgdprc_process_action',
|
235 |
+
security: ajaxSecurity,
|
236 |
+
data: {
|
237 |
+
type: 'access_request',
|
238 |
+
email: $emailAddress.value,
|
239 |
+
consent: $consent.checked
|
240 |
+
}
|
241 |
+
},
|
242 |
+
request = new XMLHttpRequest();
|
243 |
+
|
244 |
+
data = _objectToParametersString(data);
|
245 |
+
request.open('POST', ajaxURL, true);
|
246 |
+
request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded; charset=UTF-8');
|
247 |
+
request.send(data);
|
248 |
+
request.addEventListener('load', function () {
|
249 |
+
if (request.response) {
|
250 |
+
var response = JSON.parse(request.response);
|
251 |
+
if (response.message) {
|
252 |
+
$formAccessRequest.reset();
|
253 |
+
$emailAddress.blur();
|
254 |
+
$feedback.innerHTML = response.message;
|
255 |
+
$feedback.classList.add('wpgdprc-message--success');
|
256 |
+
$feedback.removeAttribute('style');
|
257 |
+
}
|
258 |
+
if (response.error) {
|
259 |
+
$emailAddress.focus();
|
260 |
+
$feedback.innerHTML = response.error;
|
261 |
+
$feedback.classList.add('wpgdprc-message--error');
|
262 |
+
$feedback.removeAttribute('style');
|
263 |
+
}
|
264 |
+
}
|
265 |
+
ajaxLoading = false;
|
266 |
+
});
|
267 |
+
}
|
268 |
+
});
|
269 |
+
},
|
270 |
+
initFormDeleteRequest = function () {
|
271 |
+
var $formDeleteRequest = document.querySelectorAll('.wpgdprc-form--delete-request');
|
272 |
+
if ($formDeleteRequest.length < 1) {
|
273 |
+
return;
|
274 |
+
}
|
275 |
+
|
276 |
+
$formDeleteRequest.forEach(function ($form) {
|
277 |
+
var $selectAll = $form.querySelector('.wpgdprc-select-all');
|
278 |
+
|
279 |
+
$form.addEventListener('submit', function (e) {
|
280 |
+
e.preventDefault();
|
281 |
+
var $this = e.target,
|
282 |
+
$checkboxes = $this.querySelectorAll('.wpgdprc-checkbox'),
|
283 |
+
data = {
|
284 |
+
action: 'wpgdprc_process_action',
|
285 |
+
security: ajaxSecurity,
|
286 |
+
data: {
|
287 |
+
type: 'delete_request',
|
288 |
+
token: wpgdprcData.token,
|
289 |
+
settings: JSON.parse($this.dataset.wpgdprc)
|
290 |
+
}
|
291 |
+
};
|
292 |
+
$selectAll.checked = false;
|
293 |
+
_doAjax(data, _getValuesByCheckedBoxes($checkboxes), $this);
|
294 |
+
});
|
295 |
+
|
296 |
+
if ($selectAll !== null) {
|
297 |
+
$selectAll.addEventListener('change', function (e) {
|
298 |
+
var $this = e.target,
|
299 |
+
checked = $this.checked,
|
300 |
+
$checkboxes = $form.querySelectorAll('.wpgdprc-checkbox');
|
301 |
+
$checkboxes.forEach(function (e) {
|
302 |
+
e.checked = checked;
|
303 |
+
});
|
304 |
+
});
|
305 |
+
}
|
306 |
+
});
|
307 |
+
};
|
308 |
+
|
309 |
+
document.addEventListener('DOMContentLoaded', function () {
|
310 |
+
if (_readCookie('wpgdprc-consent-' + wpgdprcData.consentVersion) === null) {
|
311 |
+
initConsentBar();
|
312 |
+
}
|
313 |
+
initConsentModal();
|
314 |
+
initFormAccessRequest();
|
315 |
+
initFormDeleteRequest();
|
316 |
+
});
|
317 |
})(window, document);
|
assets/svg/stars.svg
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
-
<svg xmlns="http://www.w3.org/2000/svg" width="240" height="30" viewBox="0 0 240 30">
|
2 |
-
<g fill="none" fill-rule="evenodd">
|
3 |
-
<path d="M0 0h30v30H0zM30 0h30v30H30zM60 0h30v30H60zM90 0h30v30H90zM120 0h30v30h-30zM180 0h30v30h-30zM150 0h30v30h-30zM210 0h30v30h-30z"/>
|
4 |
-
<path fill="#4AA94F" d="M14.362 5.703c.157-.312.386-.52.687-.625.3-.104.601-.104.902 0 .301.104.53.313.687.625l2.551 5.156 5.73.82c.34.053.609.209.805.47a1.3 1.3 0 0 1 .275.859 1.196 1.196 0 0 1-.373.82l-4.16 4.024.98 5.703c.053.312-.006.605-.176.879-.17.273-.412.449-.726.527-.314.078-.615.039-.903-.117L15.5 22.187l-5.141 2.657a1.216 1.216 0 0 1-.903.117 1.152 1.152 0 0 1-.726-.527 1.229 1.229 0 0 1-.177-.88l.981-5.702-4.16-4.024a1.196 1.196 0 0 1-.373-.82 1.3 1.3 0 0 1 .275-.86c.196-.26.464-.416.805-.468l5.73-.82 2.55-5.157zM44.362 5.703c.157-.312.386-.52.687-.625.3-.104.601-.104.902 0 .301.104.53.313.687.625l2.551 5.156 5.73.82c.34.053.609.209.805.47a1.3 1.3 0 0 1 .275.859 1.196 1.196 0 0 1-.373.82l-4.16 4.024.98 5.703c.053.312-.006.605-.176.879-.17.273-.412.449-.726.527-.314.078-.615.039-.903-.117L45.5 22.187l-5.141 2.657a1.216 1.216 0 0 1-.903.117 1.152 1.152 0 0 1-.726-.527 1.229 1.229 0 0 1-.177-.88l.981-5.702-4.16-4.024a1.196 1.196 0 0 1-.373-.82 1.3 1.3 0 0 1 .275-.86c.196-.26.464-.416.805-.468l5.73-.82 2.55-5.157zM74.362 5.703c.157-.312.386-.52.687-.625.3-.104.601-.104.902 0 .301.104.53.313.687.625l2.551 5.156 5.73.82c.34.053.609.209.805.47a1.3 1.3 0 0 1 .275.859 1.196 1.196 0 0 1-.373.82l-4.16 4.024.98 5.703c.053.312-.006.605-.176.879-.17.273-.412.449-.726.527-.314.078-.615.039-.903-.117L75.5 22.187l-5.141 2.657a1.216 1.216 0 0 1-.903.117 1.152 1.152 0 0 1-.726-.527 1.229 1.229 0 0 1-.177-.88l.981-5.702-4.16-4.024a1.196 1.196 0 0 1-.373-.82 1.3 1.3 0 0 1 .275-.86c.196-.26.464-.416.805-.468l5.73-.82 2.55-5.157zM104.362 5.703c.157-.312.386-.52.687-.625.3-.104.601-.104.902 0 .301.104.53.313.687.625l2.551 5.156 5.73.82c.34.053.609.209.805.47a1.3 1.3 0 0 1 .275.859 1.196 1.196 0 0 1-.373.82l-4.16 4.024.98 5.703c.053.312-.006.605-.176.879-.17.273-.412.449-.726.527-.314.078-.615.039-.903-.117l-5.141-2.657-5.141 2.657a1.216 1.216 0 0 1-.903.117 1.152 1.152 0 0 1-.726-.527 1.229 1.229 0 0 1-.177-.88l.981-5.702-4.16-4.024a1.196 1.196 0 0 1-.373-.82 1.3 1.3 0 0 1 .275-.86c.196-.26.464-.416.805-.468l5.73-.82 2.55-5.157zM134.362 5.703c.157-.312.386-.52.687-.625.3-.104.601-.104.902 0 .301.104.53.313.687.625l2.551 5.156 5.73.82c.34.053.609.209.805.47a1.3 1.3 0 0 1 .275.859 1.196 1.196 0 0 1-.373.82l-4.16 4.024.98 5.703c.053.312-.006.605-.176.879-.17.273-.412.449-.726.527-.314.078-.615.039-.903-.117l-5.141-2.657-5.141 2.657a1.216 1.216 0 0 1-.903.117 1.152 1.152 0 0 1-.726-.527 1.229 1.229 0 0 1-.177-.88l.981-5.702-4.16-4.024a1.196 1.196 0 0 1-.373-.82 1.3 1.3 0 0 1 .275-.86c.196-.26.464-.416.805-.468l5.73-.82 2.55-5.157z"/>
|
5 |
-
<path fill="#57B75C" d="M164.064 5.006c.169-.336.415-.56.738-.672.324-.112.647-.112.97 0 .324.112.57.336.739.672l2.742 5.543 6.16.882c.366.056.654.224.865.504.211.28.31.587.296.923-.014.336-.148.63-.401.882l-4.472 4.325 1.054 6.131c.057.336-.007.651-.19.945a1.238 1.238 0 0 1-.78.567 1.307 1.307 0 0 1-.97-.126l-5.528-2.855-5.527 2.855c-.309.168-.632.21-.97.126a1.238 1.238 0 0 1-.78-.567 1.321 1.321 0 0 1-.19-.945l1.054-6.13-4.472-4.326a1.286 1.286 0 0 1-.4-.882 1.398 1.398 0 0 1 .295-.923c.21-.28.499-.448.865-.504l6.16-.882 2.742-5.543zM224.064 5.006c.169-.336.415-.56.738-.672.324-.112.647-.112.97 0 .324.112.57.336.739.672l2.742 5.543 6.16.882c.366.056.654.224.865.504.211.28.31.587.296.923-.014.336-.148.63-.401.882l-4.472 4.325 1.054 6.131c.057.336-.007.651-.19.945a1.238 1.238 0 0 1-.78.567 1.307 1.307 0 0 1-.97-.126l-5.528-2.855-5.527 2.855c-.309.168-.632.21-.97.126a1.238 1.238 0 0 1-.78-.567 1.321 1.321 0 0 1-.19-.945l1.054-6.13-4.472-4.326a1.286 1.286 0 0 1-.4-.882 1.398 1.398 0 0 1 .295-.923c.21-.28.499-.448.865-.504l6.16-.882 2.742-5.543z"/>
|
6 |
-
<path fill="#61C166" d="M193.7 3.809c.179-.36.44-.6.784-.72.344-.119.688-.119 1.032 0 .344.12.605.36.785.72l2.915 5.93 6.55.943c.388.06.694.24.919.539.224.3.329.629.314.988a1.38 1.38 0 0 1-.427.943l-4.754 4.627 1.121 6.559c.06.36-.007.696-.202 1.01a1.317 1.317 0 0 1-.83.607c-.358.09-.702.045-1.031-.135L195 22.766l-5.876 3.054c-.329.18-.673.225-1.032.135a1.317 1.317 0 0 1-.83-.606 1.42 1.42 0 0 1-.201-1.011l1.121-6.559-4.754-4.627a1.38 1.38 0 0 1-.427-.943c-.015-.36.09-.689.314-.988.225-.3.531-.48.92-.54l6.549-.943 2.915-5.93z"/>
|
7 |
-
</g>
|
8 |
-
</svg>
|
1 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="240" height="30" viewBox="0 0 240 30">
|
2 |
+
<g fill="none" fill-rule="evenodd">
|
3 |
+
<path d="M0 0h30v30H0zM30 0h30v30H30zM60 0h30v30H60zM90 0h30v30H90zM120 0h30v30h-30zM180 0h30v30h-30zM150 0h30v30h-30zM210 0h30v30h-30z"/>
|
4 |
+
<path fill="#4AA94F" d="M14.362 5.703c.157-.312.386-.52.687-.625.3-.104.601-.104.902 0 .301.104.53.313.687.625l2.551 5.156 5.73.82c.34.053.609.209.805.47a1.3 1.3 0 0 1 .275.859 1.196 1.196 0 0 1-.373.82l-4.16 4.024.98 5.703c.053.312-.006.605-.176.879-.17.273-.412.449-.726.527-.314.078-.615.039-.903-.117L15.5 22.187l-5.141 2.657a1.216 1.216 0 0 1-.903.117 1.152 1.152 0 0 1-.726-.527 1.229 1.229 0 0 1-.177-.88l.981-5.702-4.16-4.024a1.196 1.196 0 0 1-.373-.82 1.3 1.3 0 0 1 .275-.86c.196-.26.464-.416.805-.468l5.73-.82 2.55-5.157zM44.362 5.703c.157-.312.386-.52.687-.625.3-.104.601-.104.902 0 .301.104.53.313.687.625l2.551 5.156 5.73.82c.34.053.609.209.805.47a1.3 1.3 0 0 1 .275.859 1.196 1.196 0 0 1-.373.82l-4.16 4.024.98 5.703c.053.312-.006.605-.176.879-.17.273-.412.449-.726.527-.314.078-.615.039-.903-.117L45.5 22.187l-5.141 2.657a1.216 1.216 0 0 1-.903.117 1.152 1.152 0 0 1-.726-.527 1.229 1.229 0 0 1-.177-.88l.981-5.702-4.16-4.024a1.196 1.196 0 0 1-.373-.82 1.3 1.3 0 0 1 .275-.86c.196-.26.464-.416.805-.468l5.73-.82 2.55-5.157zM74.362 5.703c.157-.312.386-.52.687-.625.3-.104.601-.104.902 0 .301.104.53.313.687.625l2.551 5.156 5.73.82c.34.053.609.209.805.47a1.3 1.3 0 0 1 .275.859 1.196 1.196 0 0 1-.373.82l-4.16 4.024.98 5.703c.053.312-.006.605-.176.879-.17.273-.412.449-.726.527-.314.078-.615.039-.903-.117L75.5 22.187l-5.141 2.657a1.216 1.216 0 0 1-.903.117 1.152 1.152 0 0 1-.726-.527 1.229 1.229 0 0 1-.177-.88l.981-5.702-4.16-4.024a1.196 1.196 0 0 1-.373-.82 1.3 1.3 0 0 1 .275-.86c.196-.26.464-.416.805-.468l5.73-.82 2.55-5.157zM104.362 5.703c.157-.312.386-.52.687-.625.3-.104.601-.104.902 0 .301.104.53.313.687.625l2.551 5.156 5.73.82c.34.053.609.209.805.47a1.3 1.3 0 0 1 .275.859 1.196 1.196 0 0 1-.373.82l-4.16 4.024.98 5.703c.053.312-.006.605-.176.879-.17.273-.412.449-.726.527-.314.078-.615.039-.903-.117l-5.141-2.657-5.141 2.657a1.216 1.216 0 0 1-.903.117 1.152 1.152 0 0 1-.726-.527 1.229 1.229 0 0 1-.177-.88l.981-5.702-4.16-4.024a1.196 1.196 0 0 1-.373-.82 1.3 1.3 0 0 1 .275-.86c.196-.26.464-.416.805-.468l5.73-.82 2.55-5.157zM134.362 5.703c.157-.312.386-.52.687-.625.3-.104.601-.104.902 0 .301.104.53.313.687.625l2.551 5.156 5.73.82c.34.053.609.209.805.47a1.3 1.3 0 0 1 .275.859 1.196 1.196 0 0 1-.373.82l-4.16 4.024.98 5.703c.053.312-.006.605-.176.879-.17.273-.412.449-.726.527-.314.078-.615.039-.903-.117l-5.141-2.657-5.141 2.657a1.216 1.216 0 0 1-.903.117 1.152 1.152 0 0 1-.726-.527 1.229 1.229 0 0 1-.177-.88l.981-5.702-4.16-4.024a1.196 1.196 0 0 1-.373-.82 1.3 1.3 0 0 1 .275-.86c.196-.26.464-.416.805-.468l5.73-.82 2.55-5.157z"/>
|
5 |
+
<path fill="#57B75C" d="M164.064 5.006c.169-.336.415-.56.738-.672.324-.112.647-.112.97 0 .324.112.57.336.739.672l2.742 5.543 6.16.882c.366.056.654.224.865.504.211.28.31.587.296.923-.014.336-.148.63-.401.882l-4.472 4.325 1.054 6.131c.057.336-.007.651-.19.945a1.238 1.238 0 0 1-.78.567 1.307 1.307 0 0 1-.97-.126l-5.528-2.855-5.527 2.855c-.309.168-.632.21-.97.126a1.238 1.238 0 0 1-.78-.567 1.321 1.321 0 0 1-.19-.945l1.054-6.13-4.472-4.326a1.286 1.286 0 0 1-.4-.882 1.398 1.398 0 0 1 .295-.923c.21-.28.499-.448.865-.504l6.16-.882 2.742-5.543zM224.064 5.006c.169-.336.415-.56.738-.672.324-.112.647-.112.97 0 .324.112.57.336.739.672l2.742 5.543 6.16.882c.366.056.654.224.865.504.211.28.31.587.296.923-.014.336-.148.63-.401.882l-4.472 4.325 1.054 6.131c.057.336-.007.651-.19.945a1.238 1.238 0 0 1-.78.567 1.307 1.307 0 0 1-.97-.126l-5.528-2.855-5.527 2.855c-.309.168-.632.21-.97.126a1.238 1.238 0 0 1-.78-.567 1.321 1.321 0 0 1-.19-.945l1.054-6.13-4.472-4.326a1.286 1.286 0 0 1-.4-.882 1.398 1.398 0 0 1 .295-.923c.21-.28.499-.448.865-.504l6.16-.882 2.742-5.543z"/>
|
6 |
+
<path fill="#61C166" d="M193.7 3.809c.179-.36.44-.6.784-.72.344-.119.688-.119 1.032 0 .344.12.605.36.785.72l2.915 5.93 6.55.943c.388.06.694.24.919.539.224.3.329.629.314.988a1.38 1.38 0 0 1-.427.943l-4.754 4.627 1.121 6.559c.06.36-.007.696-.202 1.01a1.317 1.317 0 0 1-.83.607c-.358.09-.702.045-1.031-.135L195 22.766l-5.876 3.054c-.329.18-.673.225-1.032.135a1.317 1.317 0 0 1-.83-.606 1.42 1.42 0 0 1-.201-1.011l1.121-6.559-4.754-4.627a1.38 1.38 0 0 1-.427-.943c-.015-.36.09-.689.314-.988.225-.3.531-.48.92-.54l6.549-.943 2.915-5.93z"/>
|
7 |
+
</g>
|
8 |
+
</svg>
|
assets/vendor/codemirror/codemirror.css
CHANGED
@@ -1,346 +1,346 @@
|
|
1 |
-
/* BASICS */
|
2 |
-
|
3 |
-
.CodeMirror {
|
4 |
-
/* Set height, width, borders, and global font properties here */
|
5 |
-
font-family: monospace;
|
6 |
-
height: 300px;
|
7 |
-
color: black;
|
8 |
-
direction: ltr;
|
9 |
-
}
|
10 |
-
|
11 |
-
/* PADDING */
|
12 |
-
|
13 |
-
.CodeMirror-lines {
|
14 |
-
padding: 4px 0; /* Vertical padding around content */
|
15 |
-
}
|
16 |
-
.CodeMirror pre {
|
17 |
-
padding: 0 4px; /* Horizontal padding of content */
|
18 |
-
}
|
19 |
-
|
20 |
-
.CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
|
21 |
-
background-color: white; /* The little square between H and V scrollbars */
|
22 |
-
}
|
23 |
-
|
24 |
-
/* GUTTER */
|
25 |
-
|
26 |
-
.CodeMirror-gutters {
|
27 |
-
border-right: 1px solid #ddd;
|
28 |
-
background-color: #f7f7f7;
|
29 |
-
white-space: nowrap;
|
30 |
-
}
|
31 |
-
.CodeMirror-linenumbers {}
|
32 |
-
.CodeMirror-linenumber {
|
33 |
-
padding: 0 3px 0 5px;
|
34 |
-
min-width: 20px;
|
35 |
-
text-align: right;
|
36 |
-
color: #999;
|
37 |
-
white-space: nowrap;
|
38 |
-
}
|
39 |
-
|
40 |
-
.CodeMirror-guttermarker { color: black; }
|
41 |
-
.CodeMirror-guttermarker-subtle { color: #999; }
|
42 |
-
|
43 |
-
/* CURSOR */
|
44 |
-
|
45 |
-
.CodeMirror-cursor {
|
46 |
-
border-left: 1px solid black;
|
47 |
-
border-right: none;
|
48 |
-
width: 0;
|
49 |
-
}
|
50 |
-
/* Shown when moving in bi-directional text */
|
51 |
-
.CodeMirror div.CodeMirror-secondarycursor {
|
52 |
-
border-left: 1px solid silver;
|
53 |
-
}
|
54 |
-
.cm-fat-cursor .CodeMirror-cursor {
|
55 |
-
width: auto;
|
56 |
-
border: 0 !important;
|
57 |
-
background: #7e7;
|
58 |
-
}
|
59 |
-
.cm-fat-cursor div.CodeMirror-cursors {
|
60 |
-
z-index: 1;
|
61 |
-
}
|
62 |
-
.cm-fat-cursor-mark {
|
63 |
-
background-color: rgba(20, 255, 20, 0.5);
|
64 |
-
-webkit-animation: blink 1.06s steps(1) infinite;
|
65 |
-
-moz-animation: blink 1.06s steps(1) infinite;
|
66 |
-
animation: blink 1.06s steps(1) infinite;
|
67 |
-
}
|
68 |
-
.cm-animate-fat-cursor {
|
69 |
-
width: auto;
|
70 |
-
border: 0;
|
71 |
-
-webkit-animation: blink 1.06s steps(1) infinite;
|
72 |
-
-moz-animation: blink 1.06s steps(1) infinite;
|
73 |
-
animation: blink 1.06s steps(1) infinite;
|
74 |
-
background-color: #7e7;
|
75 |
-
}
|
76 |
-
@-moz-keyframes blink {
|
77 |
-
0% {}
|
78 |
-
50% { background-color: transparent; }
|
79 |
-
100% {}
|
80 |
-
}
|
81 |
-
@-webkit-keyframes blink {
|
82 |
-
0% {}
|
83 |
-
50% { background-color: transparent; }
|
84 |
-
100% {}
|
85 |
-
}
|
86 |
-
@keyframes blink {
|
87 |
-
0% {}
|
88 |
-
50% { background-color: transparent; }
|
89 |
-
100% {}
|
90 |
-
}
|
91 |
-
|
92 |
-
/* Can style cursor different in overwrite (non-insert) mode */
|
93 |
-
.CodeMirror-overwrite .CodeMirror-cursor {}
|
94 |
-
|
95 |
-
.cm-tab { display: inline-block; text-decoration: inherit; }
|
96 |
-
|
97 |
-
.CodeMirror-rulers {
|
98 |
-
position: absolute;
|
99 |
-
left: 0; right: 0; top: -50px; bottom: -20px;
|
100 |
-
overflow: hidden;
|
101 |
-
}
|
102 |
-
.CodeMirror-ruler {
|
103 |
-
border-left: 1px solid #ccc;
|
104 |
-
top: 0; bottom: 0;
|
105 |
-
position: absolute;
|
106 |
-
}
|
107 |
-
|
108 |
-
/* DEFAULT THEME */
|
109 |
-
|
110 |
-
.cm-s-default .cm-header {color: blue;}
|
111 |
-
.cm-s-default .cm-quote {color: #090;}
|
112 |
-
.cm-negative {color: #d44;}
|
113 |
-
.cm-positive {color: #292;}
|
114 |
-
.cm-header, .cm-strong {font-weight: bold;}
|
115 |
-
.cm-em {font-style: italic;}
|
116 |
-
.cm-link {text-decoration: underline;}
|
117 |
-
.cm-strikethrough {text-decoration: line-through;}
|
118 |
-
|
119 |
-
.cm-s-default .cm-keyword {color: #708;}
|
120 |
-
.cm-s-default .cm-atom {color: #219;}
|
121 |
-
.cm-s-default .cm-number {color: #164;}
|
122 |
-
.cm-s-default .cm-def {color: #00f;}
|
123 |
-
.cm-s-default .cm-variable,
|
124 |
-
.cm-s-default .cm-punctuation,
|
125 |
-
.cm-s-default .cm-property,
|
126 |
-
.cm-s-default .cm-operator {}
|
127 |
-
.cm-s-default .cm-variable-2 {color: #05a;}
|
128 |
-
.cm-s-default .cm-variable-3, .cm-s-default .cm-type {color: #085;}
|
129 |
-
.cm-s-default .cm-comment {color: #a50;}
|
130 |
-
.cm-s-default .cm-string {color: #a11;}
|
131 |
-
.cm-s-default .cm-string-2 {color: #f50;}
|
132 |
-
.cm-s-default .cm-meta {color: #555;}
|
133 |
-
.cm-s-default .cm-qualifier {color: #555;}
|
134 |
-
.cm-s-default .cm-builtin {color: #30a;}
|
135 |
-
.cm-s-default .cm-bracket {color: #997;}
|
136 |
-
.cm-s-default .cm-tag {color: #170;}
|
137 |
-
.cm-s-default .cm-attribute {color: #00c;}
|
138 |
-
.cm-s-default .cm-hr {color: #999;}
|
139 |
-
.cm-s-default .cm-link {color: #00c;}
|
140 |
-
|
141 |
-
.cm-s-default .cm-error {color: #f00;}
|
142 |
-
.cm-invalidchar {color: #f00;}
|
143 |
-
|
144 |
-
.CodeMirror-composing { border-bottom: 2px solid; }
|
145 |
-
|
146 |
-
/* Default styles for common addons */
|
147 |
-
|
148 |
-
div.CodeMirror span.CodeMirror-matchingbracket {color: #0b0;}
|
149 |
-
div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #a22;}
|
150 |
-
.CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); }
|
151 |
-
.CodeMirror-activeline-background {background: #e8f2ff;}
|
152 |
-
|
153 |
-
/* STOP */
|
154 |
-
|
155 |
-
/* The rest of this file contains styles related to the mechanics of
|
156 |
-
the editor. You probably shouldn't touch them. */
|
157 |
-
|
158 |
-
.CodeMirror {
|
159 |
-
position: relative;
|
160 |
-
overflow: hidden;
|
161 |
-
background: white;
|
162 |
-
}
|
163 |
-
|
164 |
-
.CodeMirror-scroll {
|
165 |
-
overflow: scroll !important; /* Things will break if this is overridden */
|
166 |
-
/* 30px is the magic margin used to hide the element's real scrollbars */
|
167 |
-
/* See overflow: hidden in .CodeMirror */
|
168 |
-
margin-bottom: -30px; margin-right: -30px;
|
169 |
-
padding-bottom: 30px;
|
170 |
-
height: 100%;
|
171 |
-
outline: none; /* Prevent dragging from highlighting the element */
|
172 |
-
position: relative;
|
173 |
-
}
|
174 |
-
.CodeMirror-sizer {
|
175 |
-
position: relative;
|
176 |
-
border-right: 30px solid transparent;
|
177 |
-
}
|
178 |
-
|
179 |
-
/* The fake, visible scrollbars. Used to force redraw during scrolling
|
180 |
-
before actual scrolling happens, thus preventing shaking and
|
181 |
-
flickering artifacts. */
|
182 |
-
.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
|
183 |
-
position: absolute;
|
184 |
-
z-index: 6;
|
185 |
-
display: none;
|
186 |
-
}
|
187 |
-
.CodeMirror-vscrollbar {
|
188 |
-
right: 0; top: 0;
|
189 |
-
overflow-x: hidden;
|
190 |
-
overflow-y: scroll;
|
191 |
-
}
|
192 |
-
.CodeMirror-hscrollbar {
|
193 |
-
bottom: 0; left: 0;
|
194 |
-
overflow-y: hidden;
|
195 |
-
overflow-x: scroll;
|
196 |
-
}
|
197 |
-
.CodeMirror-scrollbar-filler {
|
198 |
-
right: 0; bottom: 0;
|
199 |
-
}
|
200 |
-
.CodeMirror-gutter-filler {
|
201 |
-
left: 0; bottom: 0;
|
202 |
-
}
|
203 |
-
|
204 |
-
.CodeMirror-gutters {
|
205 |
-
position: absolute; left: 0; top: 0;
|
206 |
-
min-height: 100%;
|
207 |
-
z-index: 3;
|
208 |
-
}
|
209 |
-
.CodeMirror-gutter {
|
210 |
-
white-space: normal;
|
211 |
-
height: 100%;
|
212 |
-
display: inline-block;
|
213 |
-
vertical-align: top;
|
214 |
-
margin-bottom: -30px;
|
215 |
-
}
|
216 |
-
.CodeMirror-gutter-wrapper {
|
217 |
-
position: absolute;
|
218 |
-
z-index: 4;
|
219 |
-
background: none !important;
|
220 |
-
border: none !important;
|
221 |
-
}
|
222 |
-
.CodeMirror-gutter-background {
|
223 |
-
position: absolute;
|
224 |
-
top: 0; bottom: 0;
|
225 |
-
z-index: 4;
|
226 |
-
}
|
227 |
-
.CodeMirror-gutter-elt {
|
228 |
-
position: absolute;
|
229 |
-
cursor: default;
|
230 |
-
z-index: 4;
|
231 |
-
}
|
232 |
-
.CodeMirror-gutter-wrapper ::selection { background-color: transparent }
|
233 |
-
.CodeMirror-gutter-wrapper ::-moz-selection { background-color: transparent }
|
234 |
-
|
235 |
-
.CodeMirror-lines {
|
236 |
-
cursor: text;
|
237 |
-
min-height: 1px; /* prevents collapsing before first draw */
|
238 |
-
}
|
239 |
-
.CodeMirror pre {
|
240 |
-
/* Reset some styles that the rest of the page might have set */
|
241 |
-
-moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
|
242 |
-
border-width: 0;
|
243 |
-
background: transparent;
|
244 |
-
font-family: inherit;
|
245 |
-
font-size: inherit;
|
246 |
-
margin: 0;
|
247 |
-
white-space: pre;
|
248 |
-
word-wrap: normal;
|
249 |
-
line-height: inherit;
|
250 |
-
color: inherit;
|
251 |
-
z-index: 2;
|
252 |
-
position: relative;
|
253 |
-
overflow: visible;
|
254 |
-
-webkit-tap-highlight-color: transparent;
|
255 |
-
-webkit-font-variant-ligatures: contextual;
|
256 |
-
font-variant-ligatures: contextual;
|
257 |
-
}
|
258 |
-
.CodeMirror-wrap pre {
|
259 |
-
word-wrap: break-word;
|
260 |
-
white-space: pre-wrap;
|
261 |
-
word-break: normal;
|
262 |
-
}
|
263 |
-
|
264 |
-
.CodeMirror-linebackground {
|
265 |
-
position: absolute;
|
266 |
-
left: 0; right: 0; top: 0; bottom: 0;
|
267 |
-
z-index: 0;
|
268 |
-
}
|
269 |
-
|
270 |
-
.CodeMirror-linewidget {
|
271 |
-
position: relative;
|
272 |
-
z-index: 2;
|
273 |
-
padding: 0.1px; /* Force widget margins to stay inside of the container */
|
274 |
-
}
|
275 |
-
|
276 |
-
.CodeMirror-widget {}
|
277 |
-
|
278 |
-
.CodeMirror-rtl pre { direction: rtl; }
|
279 |
-
|
280 |
-
.CodeMirror-code {
|
281 |
-
outline: none;
|
282 |
-
}
|
283 |
-
|
284 |
-
/* Force content-box sizing for the elements where we expect it */
|
285 |
-
.CodeMirror-scroll,
|
286 |
-
.CodeMirror-sizer,
|
287 |
-
.CodeMirror-gutter,
|
288 |
-
.CodeMirror-gutters,
|
289 |
-
.CodeMirror-linenumber {
|
290 |
-
-moz-box-sizing: content-box;
|
291 |
-
box-sizing: content-box;
|
292 |
-
}
|
293 |
-
|
294 |
-
.CodeMirror-measure {
|
295 |
-
position: absolute;
|
296 |
-
width: 100%;
|
297 |
-
height: 0;
|
298 |
-
overflow: hidden;
|
299 |
-
visibility: hidden;
|
300 |
-
}
|
301 |
-
|
302 |
-
.CodeMirror-cursor {
|
303 |
-
position: absolute;
|
304 |
-
pointer-events: none;
|
305 |
-
}
|
306 |
-
.CodeMirror-measure pre { position: static; }
|
307 |
-
|
308 |
-
div.CodeMirror-cursors {
|
309 |
-
visibility: hidden;
|
310 |
-
position: relative;
|
311 |
-
z-index: 3;
|
312 |
-
}
|
313 |
-
div.CodeMirror-dragcursors {
|
314 |
-
visibility: visible;
|
315 |
-
}
|
316 |
-
|
317 |
-
.CodeMirror-focused div.CodeMirror-cursors {
|
318 |
-
visibility: visible;
|
319 |
-
}
|
320 |
-
|
321 |
-
.CodeMirror-selected { background: #d9d9d9; }
|
322 |
-
.CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
|
323 |
-
.CodeMirror-crosshair { cursor: crosshair; }
|
324 |
-
.CodeMirror-line::selection, .CodeMirror-line > span::selection, .CodeMirror-line > span > span::selection { background: #d7d4f0; }
|
325 |
-
.CodeMirror-line::-moz-selection, .CodeMirror-line > span::-moz-selection, .CodeMirror-line > span > span::-moz-selection { background: #d7d4f0; }
|
326 |
-
|
327 |
-
.cm-searching {
|
328 |
-
background-color: #ffa;
|
329 |
-
background-color: rgba(255, 255, 0, .4);
|
330 |
-
}
|
331 |
-
|
332 |
-
/* Used to force a border model for a node */
|
333 |
-
.cm-force-border { padding-right: .1px; }
|
334 |
-
|
335 |
-
@media print {
|
336 |
-
/* Hide the cursor when printing */
|
337 |
-
.CodeMirror div.CodeMirror-cursors {
|
338 |
-
visibility: hidden;
|
339 |
-
}
|
340 |
-
}
|
341 |
-
|
342 |
-
/* See issue #2901 */
|
343 |
-
.cm-tab-wrap-hack:after { content: ''; }
|
344 |
-
|
345 |
-
/* Help users use markselection to safely style text background */
|
346 |
-
span.CodeMirror-selectedtext { background: none; }
|
1 |
+
/* BASICS */
|
2 |
+
|
3 |
+
.CodeMirror {
|
4 |
+
/* Set height, width, borders, and global font properties here */
|
5 |
+
font-family: monospace;
|
6 |
+
height: 300px;
|
7 |
+
color: black;
|
8 |
+
direction: ltr;
|
9 |
+
}
|
10 |
+
|
11 |
+
/* PADDING */
|
12 |
+
|
13 |
+
.CodeMirror-lines {
|
14 |
+
padding: 4px 0; /* Vertical padding around content */
|
15 |
+
}
|
16 |
+
.CodeMirror pre {
|
17 |
+
padding: 0 4px; /* Horizontal padding of content */
|
18 |
+
}
|
19 |
+
|
20 |
+
.CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
|
21 |
+
background-color: white; /* The little square between H and V scrollbars */
|
22 |
+
}
|
23 |
+
|
24 |
+
/* GUTTER */
|
25 |
+
|
26 |
+
.CodeMirror-gutters {
|
27 |
+
border-right: 1px solid #ddd;
|
28 |
+
background-color: #f7f7f7;
|
29 |
+
white-space: nowrap;
|
30 |
+
}
|
31 |
+
.CodeMirror-linenumbers {}
|
32 |
+
.CodeMirror-linenumber {
|
33 |
+
padding: 0 3px 0 5px;
|
34 |
+
min-width: 20px;
|
35 |
+
text-align: right;
|
36 |
+
color: #999;
|
37 |
+
white-space: nowrap;
|
38 |
+
}
|
39 |
+
|
40 |
+
.CodeMirror-guttermarker { color: black; }
|
41 |
+
.CodeMirror-guttermarker-subtle { color: #999; }
|
42 |
+
|
43 |
+
/* CURSOR */
|
44 |
+
|
45 |
+
.CodeMirror-cursor {
|
46 |
+
border-left: 1px solid black;
|
47 |
+
border-right: none;
|
48 |
+
width: 0;
|
49 |
+
}
|
50 |
+
/* Shown when moving in bi-directional text */
|
51 |
+
.CodeMirror div.CodeMirror-secondarycursor {
|
52 |
+
border-left: 1px solid silver;
|
53 |
+
}
|
54 |
+
.cm-fat-cursor .CodeMirror-cursor {
|
55 |
+
width: auto;
|
56 |
+
border: 0 !important;
|
57 |
+
background: #7e7;
|
58 |
+
}
|
59 |
+
.cm-fat-cursor div.CodeMirror-cursors {
|
60 |
+
z-index: 1;
|
61 |
+
}
|
62 |
+
.cm-fat-cursor-mark {
|
63 |
+
background-color: rgba(20, 255, 20, 0.5);
|
64 |
+
-webkit-animation: blink 1.06s steps(1) infinite;
|
65 |
+
-moz-animation: blink 1.06s steps(1) infinite;
|
66 |
+
animation: blink 1.06s steps(1) infinite;
|
67 |
+
}
|
68 |
+
.cm-animate-fat-cursor {
|
69 |
+
width: auto;
|
70 |
+
border: 0;
|
71 |
+
-webkit-animation: blink 1.06s steps(1) infinite;
|
72 |
+
-moz-animation: blink 1.06s steps(1) infinite;
|
73 |
+
animation: blink 1.06s steps(1) infinite;
|
74 |
+
background-color: #7e7;
|
75 |
+
}
|
76 |
+
@-moz-keyframes blink {
|
77 |
+
0% {}
|
78 |
+
50% { background-color: transparent; }
|
79 |
+
100% {}
|
80 |
+
}
|
81 |
+
@-webkit-keyframes blink {
|
82 |
+
0% {}
|
83 |
+
50% { background-color: transparent; }
|
84 |
+
100% {}
|
85 |
+
}
|
86 |
+
@keyframes blink {
|
87 |
+
0% {}
|
88 |
+
50% { background-color: transparent; }
|
89 |
+
100% {}
|
90 |
+
}
|
91 |
+
|
92 |
+
/* Can style cursor different in overwrite (non-insert) mode */
|
93 |
+
.CodeMirror-overwrite .CodeMirror-cursor {}
|
94 |
+
|
95 |
+
.cm-tab { display: inline-block; text-decoration: inherit; }
|
96 |
+
|
97 |
+
.CodeMirror-rulers {
|
98 |
+
position: absolute;
|
99 |
+
left: 0; right: 0; top: -50px; bottom: -20px;
|
100 |
+
overflow: hidden;
|
101 |
+
}
|
102 |
+
.CodeMirror-ruler {
|
103 |
+
border-left: 1px solid #ccc;
|
104 |
+
top: 0; bottom: 0;
|
105 |
+
position: absolute;
|
106 |
+
}
|
107 |
+
|
108 |
+
/* DEFAULT THEME */
|
109 |
+
|
110 |
+
.cm-s-default .cm-header {color: blue;}
|
111 |
+
.cm-s-default .cm-quote {color: #090;}
|
112 |
+
.cm-negative {color: #d44;}
|
113 |
+
.cm-positive {color: #292;}
|
114 |
+
.cm-header, .cm-strong {font-weight: bold;}
|
115 |
+
.cm-em {font-style: italic;}
|
116 |
+
.cm-link {text-decoration: underline;}
|
117 |
+
.cm-strikethrough {text-decoration: line-through;}
|
118 |
+
|
119 |
+
.cm-s-default .cm-keyword {color: #708;}
|
120 |
+
.cm-s-default .cm-atom {color: #219;}
|
121 |
+
.cm-s-default .cm-number {color: #164;}
|
122 |
+
.cm-s-default .cm-def {color: #00f;}
|
123 |
+
.cm-s-default .cm-variable,
|
124 |
+
.cm-s-default .cm-punctuation,
|
125 |
+
.cm-s-default .cm-property,
|
126 |
+
.cm-s-default .cm-operator {}
|
127 |
+
.cm-s-default .cm-variable-2 {color: #05a;}
|
128 |
+
.cm-s-default .cm-variable-3, .cm-s-default .cm-type {color: #085;}
|
129 |
+
.cm-s-default .cm-comment {color: #a50;}
|
130 |
+
.cm-s-default .cm-string {color: #a11;}
|
131 |
+
.cm-s-default .cm-string-2 {color: #f50;}
|
132 |
+
.cm-s-default .cm-meta {color: #555;}
|
133 |
+
.cm-s-default .cm-qualifier {color: #555;}
|
134 |
+
.cm-s-default .cm-builtin {color: #30a;}
|
135 |
+
.cm-s-default .cm-bracket {color: #997;}
|
136 |
+
.cm-s-default .cm-tag {color: #170;}
|
137 |
+
.cm-s-default .cm-attribute {color: #00c;}
|
138 |
+
.cm-s-default .cm-hr {color: #999;}
|
139 |
+
.cm-s-default .cm-link {color: #00c;}
|
140 |
+
|
141 |
+
.cm-s-default .cm-error {color: #f00;}
|
142 |
+
.cm-invalidchar {color: #f00;}
|
143 |
+
|
144 |
+
.CodeMirror-composing { border-bottom: 2px solid; }
|
145 |
+
|
146 |
+
/* Default styles for common addons */
|
147 |
+
|
148 |
+
div.CodeMirror span.CodeMirror-matchingbracket {color: #0b0;}
|
149 |
+
div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #a22;}
|
150 |
+
.CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); }
|
151 |
+
.CodeMirror-activeline-background {background: #e8f2ff;}
|
152 |
+
|
153 |
+
/* STOP */
|
154 |
+
|
155 |
+
/* The rest of this file contains styles related to the mechanics of
|
156 |
+
the editor. You probably shouldn't touch them. */
|
157 |
+
|
158 |
+
.CodeMirror {
|
159 |
+
position: relative;
|
160 |
+
overflow: hidden;
|
161 |
+
background: white;
|
162 |
+
}
|
163 |
+
|
164 |
+
.CodeMirror-scroll {
|
165 |
+
overflow: scroll !important; /* Things will break if this is overridden */
|
166 |
+
/* 30px is the magic margin used to hide the element's real scrollbars */
|
167 |
+
/* See overflow: hidden in .CodeMirror */
|
168 |
+
margin-bottom: -30px; margin-right: -30px;
|
169 |
+
padding-bottom: 30px;
|
170 |
+
height: 100%;
|
171 |
+
outline: none; /* Prevent dragging from highlighting the element */
|
172 |
+
position: relative;
|
173 |
+
}
|
174 |
+
.CodeMirror-sizer {
|
175 |
+
position: relative;
|
176 |
+
border-right: 30px solid transparent;
|
177 |
+
}
|
178 |
+
|
179 |
+
/* The fake, visible scrollbars. Used to force redraw during scrolling
|
180 |
+
before actual scrolling happens, thus preventing shaking and
|
181 |
+
flickering artifacts. */
|
182 |
+
.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
|
183 |
+
position: absolute;
|
184 |
+
z-index: 6;
|
185 |
+
display: none;
|
186 |
+
}
|
187 |
+
.CodeMirror-vscrollbar {
|
188 |
+
right: 0; top: 0;
|
189 |
+
overflow-x: hidden;
|
190 |
+
overflow-y: scroll;
|
191 |
+
}
|
192 |
+
.CodeMirror-hscrollbar {
|
193 |
+
bottom: 0; left: 0;
|
194 |
+
overflow-y: hidden;
|
195 |
+
overflow-x: scroll;
|
196 |
+
}
|
197 |
+
.CodeMirror-scrollbar-filler {
|
198 |
+
right: 0; bottom: 0;
|
199 |
+
}
|
200 |
+
.CodeMirror-gutter-filler {
|
201 |
+
left: 0; bottom: 0;
|
202 |
+
}
|
203 |
+
|
204 |
+
.CodeMirror-gutters {
|
205 |
+
position: absolute; left: 0; top: 0;
|
206 |
+
min-height: 100%;
|
207 |
+
z-index: 3;
|
208 |
+
}
|
209 |
+
.CodeMirror-gutter {
|
210 |
+
white-space: normal;
|
211 |
+
height: 100%;
|
212 |
+
display: inline-block;
|
213 |
+
vertical-align: top;
|
214 |
+
margin-bottom: -30px;
|
215 |
+
}
|
216 |
+
.CodeMirror-gutter-wrapper {
|
217 |
+
position: absolute;
|
218 |
+
z-index: 4;
|
219 |
+
background: none !important;
|
220 |
+
border: none !important;
|
221 |
+
}
|
222 |
+
.CodeMirror-gutter-background {
|
223 |
+
position: absolute;
|
224 |
+
top: 0; bottom: 0;
|
225 |
+
z-index: 4;
|
226 |
+
}
|
227 |
+
.CodeMirror-gutter-elt {
|
228 |
+
position: absolute;
|
229 |
+
cursor: default;
|
230 |
+
z-index: 4;
|
231 |
+
}
|
232 |
+
.CodeMirror-gutter-wrapper ::selection { background-color: transparent }
|
233 |
+
.CodeMirror-gutter-wrapper ::-moz-selection { background-color: transparent }
|
234 |
+
|
235 |
+
.CodeMirror-lines {
|
236 |
+
cursor: text;
|
237 |
+
min-height: 1px; /* prevents collapsing before first draw */
|
238 |
+
}
|
239 |
+
.CodeMirror pre {
|
240 |
+
/* Reset some styles that the rest of the page might have set */
|
241 |
+
-moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
|
242 |
+
border-width: 0;
|
243 |
+
background: transparent;
|
244 |
+
font-family: inherit;
|
245 |
+
font-size: inherit;
|
246 |
+
margin: 0;
|
247 |
+
white-space: pre;
|
248 |
+
word-wrap: normal;
|
249 |
+
line-height: inherit;
|
250 |
+
color: inherit;
|
251 |
+
z-index: 2;
|
252 |
+
position: relative;
|
253 |
+
overflow: visible;
|
254 |
+
-webkit-tap-highlight-color: transparent;
|
255 |
+
-webkit-font-variant-ligatures: contextual;
|
256 |
+
font-variant-ligatures: contextual;
|
257 |
+
}
|
258 |
+
.CodeMirror-wrap pre {
|
259 |
+
word-wrap: break-word;
|
260 |
+
white-space: pre-wrap;
|
261 |
+
word-break: normal;
|
262 |
+
}
|
263 |
+
|
264 |
+
.CodeMirror-linebackground {
|
265 |
+
position: absolute;
|
266 |
+
left: 0; right: 0; top: 0; bottom: 0;
|
267 |
+
z-index: 0;
|
268 |
+
}
|
269 |
+
|
270 |
+
.CodeMirror-linewidget {
|
271 |
+
position: relative;
|
272 |
+
z-index: 2;
|
273 |
+
padding: 0.1px; /* Force widget margins to stay inside of the container */
|
274 |
+
}
|
275 |
+
|
276 |
+
.CodeMirror-widget {}
|
277 |
+
|
278 |
+
.CodeMirror-rtl pre { direction: rtl; }
|
279 |
+
|
280 |
+
.CodeMirror-code {
|
281 |
+
outline: none;
|
282 |
+
}
|
283 |
+
|
284 |
+
/* Force content-box sizing for the elements where we expect it */
|
285 |
+
.CodeMirror-scroll,
|
286 |
+
.CodeMirror-sizer,
|
287 |
+
.CodeMirror-gutter,
|
288 |
+
.CodeMirror-gutters,
|
289 |
+
.CodeMirror-linenumber {
|
290 |
+
-moz-box-sizing: content-box;
|
291 |
+
box-sizing: content-box;
|
292 |
+
}
|
293 |
+
|
294 |
+
.CodeMirror-measure {
|
295 |
+
position: absolute;
|
296 |
+
width: 100%;
|
297 |
+
height: 0;
|
298 |
+
overflow: hidden;
|
299 |
+
visibility: hidden;
|
300 |
+
}
|
301 |
+
|
302 |
+
.CodeMirror-cursor {
|
303 |
+
position: absolute;
|
304 |
+
pointer-events: none;
|
305 |
+
}
|
306 |
+
.CodeMirror-measure pre { position: static; }
|
307 |
+
|
308 |
+
div.CodeMirror-cursors {
|
309 |
+
visibility: hidden;
|
310 |
+
position: relative;
|
311 |
+
z-index: 3;
|
312 |
+
}
|
313 |
+
div.CodeMirror-dragcursors {
|
314 |
+
visibility: visible;
|
315 |
+
}
|
316 |
+
|
317 |
+
.CodeMirror-focused div.CodeMirror-cursors {
|
318 |
+
visibility: visible;
|
319 |
+
}
|
320 |
+
|
321 |
+
.CodeMirror-selected { background: #d9d9d9; }
|
322 |
+
.CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
|
323 |
+
.CodeMirror-crosshair { cursor: crosshair; }
|
324 |
+
.CodeMirror-line::selection, .CodeMirror-line > span::selection, .CodeMirror-line > span > span::selection { background: #d7d4f0; }
|
325 |
+
.CodeMirror-line::-moz-selection, .CodeMirror-line > span::-moz-selection, .CodeMirror-line > span > span::-moz-selection { background: #d7d4f0; }
|
326 |
+
|
327 |
+
.cm-searching {
|
328 |
+
background-color: #ffa;
|
329 |
+
background-color: rgba(255, 255, 0, .4);
|
330 |
+
}
|
331 |
+
|
332 |
+
/* Used to force a border model for a node */
|
333 |
+
.cm-force-border { padding-right: .1px; }
|
334 |
+
|
335 |
+
@media print {
|
336 |
+
/* Hide the cursor when printing */
|
337 |
+
.CodeMirror div.CodeMirror-cursors {
|
338 |
+
visibility: hidden;
|
339 |
+
}
|
340 |
+
}
|
341 |
+
|
342 |
+
/* See issue #2901 */
|
343 |
+
.cm-tab-wrap-hack:after { content: ''; }
|
344 |
+
|
345 |
+
/* Help users use markselection to safely style text background */
|
346 |
+
span.CodeMirror-selectedtext { background: none; }
|
assets/vendor/codemirror/codemirror.js
CHANGED
@@ -1,9685 +1,9685 @@
|
|
1 |
-
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
2 |
-
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
3 |
-
|
4 |
-
// This is CodeMirror (http://codemirror.net), a code editor
|
5 |
-
// implemented in JavaScript on top of the browser's DOM.
|
6 |
-
//
|
7 |
-
// You can find some technical background for some of the code below
|
8 |
-
// at http://marijnhaverbeke.nl/blog/#cm-internals .
|
9 |
-
|
10 |
-
(function (global, factory) {
|
11 |
-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
12 |
-
typeof define === 'function' && define.amd ? define(factory) :
|
13 |
-
(global.CodeMirror = factory());
|
14 |
-
}(this, (function () { 'use strict';
|
15 |
-
|
16 |
-
// Kludges for bugs and behavior differences that can't be feature
|
17 |
-
// detected are enabled based on userAgent etc sniffing.
|
18 |
-
var userAgent = navigator.userAgent
|
19 |
-
var platform = navigator.platform
|
20 |
-
|
21 |
-
var gecko = /gecko\/\d/i.test(userAgent)
|
22 |
-
var ie_upto10 = /MSIE \d/.test(userAgent)
|
23 |
-
var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(userAgent)
|
24 |
-
var edge = /Edge\/(\d+)/.exec(userAgent)
|
25 |
-
var ie = ie_upto10 || ie_11up || edge
|
26 |
-
var ie_version = ie && (ie_upto10 ? document.documentMode || 6 : +(edge || ie_11up)[1])
|
27 |
-
var webkit = !edge && /WebKit\//.test(userAgent)
|
28 |
-
var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(userAgent)
|
29 |
-
var chrome = !edge && /Chrome\//.test(userAgent)
|
30 |
-
var presto = /Opera\//.test(userAgent)
|
31 |
-
var safari = /Apple Computer/.test(navigator.vendor)
|
32 |
-
var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(userAgent)
|
33 |
-
var phantom = /PhantomJS/.test(userAgent)
|
34 |
-
|
35 |
-
var ios = !edge && /AppleWebKit/.test(userAgent) && /Mobile\/\w+/.test(userAgent)
|
36 |
-
var android = /Android/.test(userAgent)
|
37 |
-
// This is woefully incomplete. Suggestions for alternative methods welcome.
|
38 |
-
var mobile = ios || android || /webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(userAgent)
|
39 |
-
var mac = ios || /Mac/.test(platform)
|
40 |
-
var chromeOS = /\bCrOS\b/.test(userAgent)
|
41 |
-
var windows = /win/i.test(platform)
|
42 |
-
|
43 |
-
var presto_version = presto && userAgent.match(/Version\/(\d*\.\d*)/)
|
44 |
-
if (presto_version) { presto_version = Number(presto_version[1]) }
|
45 |
-
if (presto_version && presto_version >= 15) { presto = false; webkit = true }
|
46 |
-
// Some browsers use the wrong event properties to signal cmd/ctrl on OS X
|
47 |
-
var flipCtrlCmd = mac && (qtwebkit || presto && (presto_version == null || presto_version < 12.11))
|
48 |
-
var captureRightClick = gecko || (ie && ie_version >= 9)
|
49 |
-
|
50 |
-
function classTest(cls) { return new RegExp("(^|\\s)" + cls + "(?:$|\\s)\\s*") }
|
51 |
-
|
52 |
-
var rmClass = function(node, cls) {
|
53 |
-
var current = node.className
|
54 |
-
var match = classTest(cls).exec(current)
|
55 |
-
if (match) {
|
56 |
-
var after = current.slice(match.index + match[0].length)
|
57 |
-
node.className = current.slice(0, match.index) + (after ? match[1] + after : "")
|
58 |
-
}
|
59 |
-
}
|
60 |
-
|
61 |
-
function removeChildren(e) {
|
62 |
-
for (var count = e.childNodes.length; count > 0; --count)
|
63 |
-
{ e.removeChild(e.firstChild) }
|
64 |
-
return e
|
65 |
-
}
|
66 |
-
|
67 |
-
function removeChildrenAndAdd(parent, e) {
|
68 |
-
return removeChildren(parent).appendChild(e)
|
69 |
-
}
|
70 |
-
|
71 |
-
function elt(tag, content, className, style) {
|
72 |
-
var e = document.createElement(tag)
|
73 |
-
if (className) { e.className = className }
|
74 |
-
if (style) { e.style.cssText = style }
|
75 |
-
if (typeof content == "string") { e.appendChild(document.createTextNode(content)) }
|
76 |
-
else if (content) { for (var i = 0; i < content.length; ++i) { e.appendChild(content[i]) } }
|
77 |
-
return e
|
78 |
-
}
|
79 |
-
// wrapper for elt, which removes the elt from the accessibility tree
|
80 |
-
function eltP(tag, content, className, style) {
|
81 |
-
var e = elt(tag, content, className, style)
|
82 |
-
e.setAttribute("role", "presentation")
|
83 |
-
return e
|
84 |
-
}
|
85 |
-
|
86 |
-
var range
|
87 |
-
if (document.createRange) { range = function(node, start, end, endNode) {
|
88 |
-
var r = document.createRange()
|
89 |
-
r.setEnd(endNode || node, end)
|
90 |
-
r.setStart(node, start)
|
91 |
-
return r
|
92 |
-
} }
|
93 |
-
else { range = function(node, start, end) {
|
94 |
-
var r = document.body.createTextRange()
|
95 |
-
try { r.moveToElementText(node.parentNode) }
|
96 |
-
catch(e) { return r }
|
97 |
-
r.collapse(true)
|
98 |
-
r.moveEnd("character", end)
|
99 |
-
r.moveStart("character", start)
|
100 |
-
return r
|
101 |
-
} }
|
102 |
-
|
103 |
-
function contains(parent, child) {
|
104 |
-
if (child.nodeType == 3) // Android browser always returns false when child is a textnode
|
105 |
-
{ child = child.parentNode }
|
106 |
-
if (parent.contains)
|
107 |
-
{ return parent.contains(child) }
|
108 |
-
do {
|
109 |
-
if (child.nodeType == 11) { child = child.host }
|
110 |
-
if (child == parent) { return true }
|
111 |
-
} while (child = child.parentNode)
|
112 |
-
}
|
113 |
-
|
114 |
-
function activeElt() {
|
115 |
-
// IE and Edge may throw an "Unspecified Error" when accessing document.activeElement.
|
116 |
-
// IE < 10 will throw when accessed while the page is loading or in an iframe.
|
117 |
-
// IE > 9 and Edge will throw when accessed in an iframe if document.body is unavailable.
|
118 |
-
var activeElement
|
119 |
-
try {
|
120 |
-
activeElement = document.activeElement
|
121 |
-
} catch(e) {
|
122 |
-
activeElement = document.body || null
|
123 |
-
}
|
124 |
-
while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot.activeElement)
|
125 |
-
{ activeElement = activeElement.shadowRoot.activeElement }
|
126 |
-
return activeElement
|
127 |
-
}
|
128 |
-
|
129 |
-
function addClass(node, cls) {
|
130 |
-
var current = node.className
|
131 |
-
if (!classTest(cls).test(current)) { node.className += (current ? " " : "") + cls }
|
132 |
-
}
|
133 |
-
function joinClasses(a, b) {
|
134 |
-
var as = a.split(" ")
|
135 |
-
for (var i = 0; i < as.length; i++)
|
136 |
-
{ if (as[i] && !classTest(as[i]).test(b)) { b += " " + as[i] } }
|
137 |
-
return b
|
138 |
-
}
|
139 |
-
|
140 |
-
var selectInput = function(node) { node.select() }
|
141 |
-
if (ios) // Mobile Safari apparently has a bug where select() is broken.
|
142 |
-
{ selectInput = function(node) { node.selectionStart = 0; node.selectionEnd = node.value.length } }
|
143 |
-
else if (ie) // Suppress mysterious IE10 errors
|
144 |
-
{ selectInput = function(node) { try { node.select() } catch(_e) {} } }
|
145 |
-
|
146 |
-
function bind(f) {
|
147 |
-
var args = Array.prototype.slice.call(arguments, 1)
|
148 |
-
return function(){return f.apply(null, args)}
|
149 |
-
}
|
150 |
-
|
151 |
-
function copyObj(obj, target, overwrite) {
|
152 |
-
if (!target) { target = {} }
|
153 |
-
for (var prop in obj)
|
154 |
-
{ if (obj.hasOwnProperty(prop) && (overwrite !== false || !target.hasOwnProperty(prop)))
|
155 |
-
{ target[prop] = obj[prop] } }
|
156 |
-
return target
|
157 |
-
}
|
158 |
-
|
159 |
-
// Counts the column offset in a string, taking tabs into account.
|
160 |
-
// Used mostly to find indentation.
|
161 |
-
function countColumn(string, end, tabSize, startIndex, startValue) {
|
162 |
-
if (end == null) {
|
163 |
-
end = string.search(/[^\s\u00a0]/)
|
164 |
-
if (end == -1) { end = string.length }
|
165 |
-
}
|
166 |
-
for (var i = startIndex || 0, n = startValue || 0;;) {
|
167 |
-
var nextTab = string.indexOf("\t", i)
|
168 |
-
if (nextTab < 0 || nextTab >= end)
|
169 |
-
{ return n + (end - i) }
|
170 |
-
n += nextTab - i
|
171 |
-
n += tabSize - (n % tabSize)
|
172 |
-
i = nextTab + 1
|
173 |
-
}
|
174 |
-
}
|
175 |
-
|
176 |
-
var Delayed = function() {this.id = null};
|
177 |
-
Delayed.prototype.set = function (ms, f) {
|
178 |
-
clearTimeout(this.id)
|
179 |
-
this.id = setTimeout(f, ms)
|
180 |
-
};
|
181 |
-
|
182 |
-
function indexOf(array, elt) {
|
183 |
-
for (var i = 0; i < array.length; ++i)
|
184 |
-
{ if (array[i] == elt) { return i } }
|
185 |
-
return -1
|
186 |
-
}
|
187 |
-
|
188 |
-
// Number of pixels added to scroller and sizer to hide scrollbar
|
189 |
-
var scrollerGap = 30
|
190 |
-
|
191 |
-
// Returned or thrown by various protocols to signal 'I'm not
|
192 |
-
// handling this'.
|
193 |
-
var Pass = {toString: function(){return "CodeMirror.Pass"}}
|
194 |
-
|
195 |
-
// Reused option objects for setSelection & friends
|
196 |
-
var sel_dontScroll = {scroll: false};
|
197 |
-
var sel_mouse = {origin: "*mouse"};
|
198 |
-
var sel_move = {origin: "+move"};
|
199 |
-
// The inverse of countColumn -- find the offset that corresponds to
|
200 |
-
// a particular column.
|
201 |
-
function findColumn(string, goal, tabSize) {
|
202 |
-
for (var pos = 0, col = 0;;) {
|
203 |
-
var nextTab = string.indexOf("\t", pos)
|
204 |
-
if (nextTab == -1) { nextTab = string.length }
|
205 |
-
var skipped = nextTab - pos
|
206 |
-
if (nextTab == string.length || col + skipped >= goal)
|
207 |
-
{ return pos + Math.min(skipped, goal - col) }
|
208 |
-
col += nextTab - pos
|
209 |
-
col += tabSize - (col % tabSize)
|
210 |
-
pos = nextTab + 1
|
211 |
-
if (col >= goal) { return pos }
|
212 |
-
}
|
213 |
-
}
|
214 |
-
|
215 |
-
var spaceStrs = [""]
|
216 |
-
function spaceStr(n) {
|
217 |
-
while (spaceStrs.length <= n)
|
218 |
-
{ spaceStrs.push(lst(spaceStrs) + " ") }
|
219 |
-
return spaceStrs[n]
|
220 |
-
}
|
221 |
-
|
222 |
-
function lst(arr) { return arr[arr.length-1] }
|
223 |
-
|
224 |
-
function map(array, f) {
|
225 |
-
var out = []
|
226 |
-
for (var i = 0; i < array.length; i++) { out[i] = f(array[i], i) }
|
227 |
-
return out
|
228 |
-
}
|
229 |
-
|
230 |
-
function insertSorted(array, value, score) {
|
231 |
-
var pos = 0, priority = score(value)
|
232 |
-
while (pos < array.length && score(array[pos]) <= priority) { pos++ }
|
233 |
-
array.splice(pos, 0, value)
|
234 |
-
}
|
235 |
-
|
236 |
-
function nothing() {}
|
237 |
-
|
238 |
-
function createObj(base, props) {
|
239 |
-
var inst
|
240 |
-
if (Object.create) {
|
241 |
-
inst = Object.create(base)
|
242 |
-
} else {
|
243 |
-
nothing.prototype = base
|
244 |
-
inst = new nothing()
|
245 |
-
}
|
246 |
-
if (props) { copyObj(props, inst) }
|
247 |
-
return inst
|
248 |
-
}
|
249 |
-
|
250 |
-
var nonASCIISingleCaseWordChar = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/
|
251 |
-
function isWordCharBasic(ch) {
|
252 |
-
return /\w/.test(ch) || ch > "\x80" &&
|
253 |
-
(ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch))
|
254 |
-
}
|
255 |
-
function isWordChar(ch, helper) {
|
256 |
-
if (!helper) { return isWordCharBasic(ch) }
|
257 |
-
if (helper.source.indexOf("\\w") > -1 && isWordCharBasic(ch)) { return true }
|
258 |
-
return helper.test(ch)
|
259 |
-
}
|
260 |
-
|
261 |
-
function isEmpty(obj) {
|
262 |
-
for (var n in obj) { if (obj.hasOwnProperty(n) && obj[n]) { return false } }
|
263 |
-
return true
|
264 |
-
}
|
265 |
-
|
266 |
-
// Extending unicode characters. A series of a non-extending char +
|
267 |
-
// any number of extending chars is treated as a single unit as far
|
268 |
-
// as editing and measuring is concerned. This is not fully correct,
|
269 |
-
// since some scripts/fonts/browsers also treat other configurations
|
270 |
-
// of code points as a group.
|
271 |
-
var extendingChars = /[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/
|
272 |
-
function isExtendingChar(ch) { return ch.charCodeAt(0) >= 768 && extendingChars.test(ch) }
|
273 |
-
|
274 |
-
// Returns a number from the range [`0`; `str.length`] unless `pos` is outside that range.
|
275 |
-
function skipExtendingChars(str, pos, dir) {
|
276 |
-
while ((dir < 0 ? pos > 0 : pos < str.length) && isExtendingChar(str.charAt(pos))) { pos += dir }
|
277 |
-
return pos
|
278 |
-
}
|
279 |
-
|
280 |
-
// Returns the value from the range [`from`; `to`] that satisfies
|
281 |
-
// `pred` and is closest to `from`. Assumes that at least `to`
|
282 |
-
// satisfies `pred`. Supports `from` being greater than `to`.
|
283 |
-
function findFirst(pred, from, to) {
|
284 |
-
// At any point we are certain `to` satisfies `pred`, don't know
|
285 |
-
// whether `from` does.
|
286 |
-
var dir = from > to ? -1 : 1
|
287 |
-
for (;;) {
|
288 |
-
if (from == to) { return from }
|
289 |
-
var midF = (from + to) / 2, mid = dir < 0 ? Math.ceil(midF) : Math.floor(midF)
|
290 |
-
if (mid == from) { return pred(mid) ? from : to }
|
291 |
-
if (pred(mid)) { to = mid }
|
292 |
-
else { from = mid + dir }
|
293 |
-
}
|
294 |
-
}
|
295 |
-
|
296 |
-
// The display handles the DOM integration, both for input reading
|
297 |
-
// and content drawing. It holds references to DOM nodes and
|
298 |
-
// display-related state.
|
299 |
-
|
300 |
-
function Display(place, doc, input) {
|
301 |
-
var d = this
|
302 |
-
this.input = input
|
303 |
-
|
304 |
-
// Covers bottom-right square when both scrollbars are present.
|
305 |
-
d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler")
|
306 |
-
d.scrollbarFiller.setAttribute("cm-not-content", "true")
|
307 |
-
// Covers bottom of gutter when coverGutterNextToScrollbar is on
|
308 |
-
// and h scrollbar is present.
|
309 |
-
d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler")
|
310 |
-
d.gutterFiller.setAttribute("cm-not-content", "true")
|
311 |
-
// Will contain the actual code, positioned to cover the viewport.
|
312 |
-
d.lineDiv = eltP("div", null, "CodeMirror-code")
|
313 |
-
// Elements are added to these to represent selection and cursors.
|
314 |
-
d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1")
|
315 |
-
d.cursorDiv = elt("div", null, "CodeMirror-cursors")
|
316 |
-
// A visibility: hidden element used to find the size of things.
|
317 |
-
d.measure = elt("div", null, "CodeMirror-measure")
|
318 |
-
// When lines outside of the viewport are measured, they are drawn in this.
|
319 |
-
d.lineMeasure = elt("div", null, "CodeMirror-measure")
|
320 |
-
// Wraps everything that needs to exist inside the vertically-padded coordinate system
|
321 |
-
d.lineSpace = eltP("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv],
|
322 |
-
null, "position: relative; outline: none")
|
323 |
-
var lines = eltP("div", [d.lineSpace], "CodeMirror-lines")
|
324 |
-
// Moved around its parent to cover visible view.
|
325 |
-
d.mover = elt("div", [lines], null, "position: relative")
|
326 |
-
// Set to the height of the document, allowing scrolling.
|
327 |
-
d.sizer = elt("div", [d.mover], "CodeMirror-sizer")
|
328 |
-
d.sizerWidth = null
|
329 |
-
// Behavior of elts with overflow: auto and padding is
|
330 |
-
// inconsistent across browsers. This is used to ensure the
|
331 |
-
// scrollable area is big enough.
|
332 |
-
d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerGap + "px; width: 1px;")
|
333 |
-
// Will contain the gutters, if any.
|
334 |
-
d.gutters = elt("div", null, "CodeMirror-gutters")
|
335 |
-
d.lineGutter = null
|
336 |
-
// Actual scrollable element.
|
337 |
-
d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll")
|
338 |
-
d.scroller.setAttribute("tabIndex", "-1")
|
339 |
-
// The element in which the editor lives.
|
340 |
-
d.wrapper = elt("div", [d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror")
|
341 |
-
|
342 |
-
// Work around IE7 z-index bug (not perfect, hence IE7 not really being supported)
|
343 |
-
if (ie && ie_version < 8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0 }
|
344 |
-
if (!webkit && !(gecko && mobile)) { d.scroller.draggable = true }
|
345 |
-
|
346 |
-
if (place) {
|
347 |
-
if (place.appendChild) { place.appendChild(d.wrapper) }
|
348 |
-
else { place(d.wrapper) }
|
349 |
-
}
|
350 |
-
|
351 |
-
// Current rendered range (may be bigger than the view window).
|
352 |
-
d.viewFrom = d.viewTo = doc.first
|
353 |
-
d.reportedViewFrom = d.reportedViewTo = doc.first
|
354 |
-
// Information about the rendered lines.
|
355 |
-
d.view = []
|
356 |
-
d.renderedView = null
|
357 |
-
// Holds info about a single rendered line when it was rendered
|
358 |
-
// for measurement, while not in view.
|
359 |
-
d.externalMeasured = null
|
360 |
-
// Empty space (in pixels) above the view
|
361 |
-
d.viewOffset = 0
|
362 |
-
d.lastWrapHeight = d.lastWrapWidth = 0
|
363 |
-
d.updateLineNumbers = null
|
364 |
-
|
365 |
-
d.nativeBarWidth = d.barHeight = d.barWidth = 0
|
366 |
-
d.scrollbarsClipped = false
|
367 |
-
|
368 |
-
// Used to only resize the line number gutter when necessary (when
|
369 |
-
// the amount of lines crosses a boundary that makes its width change)
|
370 |
-
d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null
|
371 |
-
// Set to true when a non-horizontal-scrolling line widget is
|
372 |
-
// added. As an optimization, line widget aligning is skipped when
|
373 |
-
// this is false.
|
374 |
-
d.alignWidgets = false
|
375 |
-
|
376 |
-
d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null
|
377 |
-
|
378 |
-
// Tracks the maximum line length so that the horizontal scrollbar
|
379 |
-
// can be kept static when scrolling.
|
380 |
-
d.maxLine = null
|
381 |
-
d.maxLineLength = 0
|
382 |
-
d.maxLineChanged = false
|
383 |
-
|
384 |
-
// Used for measuring wheel scrolling granularity
|
385 |
-
d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null
|
386 |
-
|
387 |
-
// True when shift is held down.
|
388 |
-
d.shift = false
|
389 |
-
|
390 |
-
// Used to track whether anything happened since the context menu
|
391 |
-
// was opened.
|
392 |
-
d.selForContextMenu = null
|
393 |
-
|
394 |
-
d.activeTouch = null
|
395 |
-
|
396 |
-
input.init(d)
|
397 |
-
}
|
398 |
-
|
399 |
-
// Find the line object corresponding to the given line number.
|
400 |
-
function getLine(doc, n) {
|
401 |
-
n -= doc.first
|
402 |
-
if (n < 0 || n >= doc.size) { throw new Error("There is no line " + (n + doc.first) + " in the document.") }
|
403 |
-
var chunk = doc
|
404 |
-
while (!chunk.lines) {
|
405 |
-
for (var i = 0;; ++i) {
|
406 |
-
var child = chunk.children[i], sz = child.chunkSize()
|
407 |
-
if (n < sz) { chunk = child; break }
|
408 |
-
n -= sz
|
409 |
-
}
|
410 |
-
}
|
411 |
-
return chunk.lines[n]
|
412 |
-
}
|
413 |
-
|
414 |
-
// Get the part of a document between two positions, as an array of
|
415 |
-
// strings.
|
416 |
-
function getBetween(doc, start, end) {
|
417 |
-
var out = [], n = start.line
|
418 |
-
doc.iter(start.line, end.line + 1, function (line) {
|
419 |
-
var text = line.text
|
420 |
-
if (n == end.line) { text = text.slice(0, end.ch) }
|
421 |
-
if (n == start.line) { text = text.slice(start.ch) }
|
422 |
-
out.push(text)
|
423 |
-
++n
|
424 |
-
})
|
425 |
-
return out
|
426 |
-
}
|
427 |
-
// Get the lines between from and to, as array of strings.
|
428 |
-
function getLines(doc, from, to) {
|
429 |
-
var out = []
|
430 |
-
doc.iter(from, to, function (line) { out.push(line.text) }) // iter aborts when callback returns truthy value
|
431 |
-
return out
|
432 |
-
}
|
433 |
-
|
434 |
-
// Update the height of a line, propagating the height change
|
435 |
-
// upwards to parent nodes.
|
436 |
-
function updateLineHeight(line, height) {
|
437 |
-
var diff = height - line.height
|
438 |
-
if (diff) { for (var n = line; n; n = n.parent) { n.height += diff } }
|
439 |
-
}
|
440 |
-
|
441 |
-
// Given a line object, find its line number by walking up through
|
442 |
-
// its parent links.
|
443 |
-
function lineNo(line) {
|
444 |
-
if (line.parent == null) { return null }
|
445 |
-
var cur = line.parent, no = indexOf(cur.lines, line)
|
446 |
-
for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
|
447 |
-
for (var i = 0;; ++i) {
|
448 |
-
if (chunk.children[i] == cur) { break }
|
449 |
-
no += chunk.children[i].chunkSize()
|
450 |
-
}
|
451 |
-
}
|
452 |
-
return no + cur.first
|
453 |
-
}
|
454 |
-
|
455 |
-
// Find the line at the given vertical position, using the height
|
456 |
-
// information in the document tree.
|
457 |
-
function lineAtHeight(chunk, h) {
|
458 |
-
var n = chunk.first
|
459 |
-
outer: do {
|
460 |
-
for (var i$1 = 0; i$1 < chunk.children.length; ++i$1) {
|
461 |
-
var child = chunk.children[i$1], ch = child.height
|
462 |
-
if (h < ch) { chunk = child; continue outer }
|
463 |
-
h -= ch
|
464 |
-
n += child.chunkSize()
|
465 |
-
}
|
466 |
-
return n
|
467 |
-
} while (!chunk.lines)
|
468 |
-
var i = 0
|
469 |
-
for (; i < chunk.lines.length; ++i) {
|
470 |
-
var line = chunk.lines[i], lh = line.height
|
471 |
-
if (h < lh) { break }
|
472 |
-
h -= lh
|
473 |
-
}
|
474 |
-
return n + i
|
475 |
-
}
|
476 |
-
|
477 |
-
function isLine(doc, l) {return l >= doc.first && l < doc.first + doc.size}
|
478 |
-
|
479 |
-
function lineNumberFor(options, i) {
|
480 |
-
return String(options.lineNumberFormatter(i + options.firstLineNumber))
|
481 |
-
}
|
482 |
-
|
483 |
-
// A Pos instance represents a position within the text.
|
484 |
-
function Pos(line, ch, sticky) {
|
485 |
-
if ( sticky === void 0 ) sticky = null;
|
486 |
-
|
487 |
-
if (!(this instanceof Pos)) { return new Pos(line, ch, sticky) }
|
488 |
-
this.line = line
|
489 |
-
this.ch = ch
|
490 |
-
this.sticky = sticky
|
491 |
-
}
|
492 |
-
|
493 |
-
// Compare two positions, return 0 if they are the same, a negative
|
494 |
-
// number when a is less, and a positive number otherwise.
|
495 |
-
function cmp(a, b) { return a.line - b.line || a.ch - b.ch }
|
496 |
-
|
497 |
-
function equalCursorPos(a, b) { return a.sticky == b.sticky && cmp(a, b) == 0 }
|
498 |
-
|
499 |
-
function copyPos(x) {return Pos(x.line, x.ch)}
|
500 |
-
function maxPos(a, b) { return cmp(a, b) < 0 ? b : a }
|
501 |
-
function minPos(a, b) { return cmp(a, b) < 0 ? a : b }
|
502 |
-
|
503 |
-
// Most of the external API clips given positions to make sure they
|
504 |
-
// actually exist within the document.
|
505 |
-
function clipLine(doc, n) {return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1))}
|
506 |
-
function clipPos(doc, pos) {
|
507 |
-
if (pos.line < doc.first) { return Pos(doc.first, 0) }
|
508 |
-
var last = doc.first + doc.size - 1
|
509 |
-
if (pos.line > last) { return Pos(last, getLine(doc, last).text.length) }
|
510 |
-
return clipToLen(pos, getLine(doc, pos.line).text.length)
|
511 |
-
}
|
512 |
-
function clipToLen(pos, linelen) {
|
513 |
-
var ch = pos.ch
|
514 |
-
if (ch == null || ch > linelen) { return Pos(pos.line, linelen) }
|
515 |
-
else if (ch < 0) { return Pos(pos.line, 0) }
|
516 |
-
else { return pos }
|
517 |
-
}
|
518 |
-
function clipPosArray(doc, array) {
|
519 |
-
var out = []
|
520 |
-
for (var i = 0; i < array.length; i++) { out[i] = clipPos(doc, array[i]) }
|
521 |
-
return out
|
522 |
-
}
|
523 |
-
|
524 |
-
// Optimize some code when these features are not used.
|
525 |
-
var sawReadOnlySpans = false;
|
526 |
-
var sawCollapsedSpans = false;
|
527 |
-
function seeReadOnlySpans() {
|
528 |
-
sawReadOnlySpans = true
|
529 |
-
}
|
530 |
-
|
531 |
-
function seeCollapsedSpans() {
|
532 |
-
sawCollapsedSpans = true
|
533 |
-
}
|
534 |
-
|
535 |
-
// TEXTMARKER SPANS
|
536 |
-
|
537 |
-
function MarkedSpan(marker, from, to) {
|
538 |
-
this.marker = marker
|
539 |
-
this.from = from; this.to = to
|
540 |
-
}
|
541 |
-
|
542 |
-
// Search an array of spans for a span matching the given marker.
|
543 |
-
function getMarkedSpanFor(spans, marker) {
|
544 |
-
if (spans) { for (var i = 0; i < spans.length; ++i) {
|
545 |
-
var span = spans[i]
|
546 |
-
if (span.marker == marker) { return span }
|
547 |
-
} }
|
548 |
-
}
|
549 |
-
// Remove a span from an array, returning undefined if no spans are
|
550 |
-
// left (we don't store arrays for lines without spans).
|
551 |
-
function removeMarkedSpan(spans, span) {
|
552 |
-
var r
|
553 |
-
for (var i = 0; i < spans.length; ++i)
|
554 |
-
{ if (spans[i] != span) { (r || (r = [])).push(spans[i]) } }
|
555 |
-
return r
|
556 |
-
}
|
557 |
-
// Add a span to a line.
|
558 |
-
function addMarkedSpan(line, span) {
|
559 |
-
line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span]
|
560 |
-
span.marker.attachLine(line)
|
561 |
-
}
|
562 |
-
|
563 |
-
// Used for the algorithm that adjusts markers for a change in the
|
564 |
-
// document. These functions cut an array of spans at a given
|
565 |
-
// character position, returning an array of remaining chunks (or
|
566 |
-
// undefined if nothing remains).
|
567 |
-
function markedSpansBefore(old, startCh, isInsert) {
|
568 |
-
var nw
|
569 |
-
if (old) { for (var i = 0; i < old.length; ++i) {
|
570 |
-
var span = old[i], marker = span.marker
|
571 |
-
var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh)
|
572 |
-
if (startsBefore || span.from == startCh && marker.type == "bookmark" && (!isInsert || !span.marker.insertLeft)) {
|
573 |
-
var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh)
|
574 |
-
;(nw || (nw = [])).push(new MarkedSpan(marker, span.from, endsAfter ? null : span.to))
|
575 |
-
}
|
576 |
-
} }
|
577 |
-
return nw
|
578 |
-
}
|
579 |
-
function markedSpansAfter(old, endCh, isInsert) {
|
580 |
-
var nw
|
581 |
-
if (old) { for (var i = 0; i < old.length; ++i) {
|
582 |
-
var span = old[i], marker = span.marker
|
583 |
-
var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh)
|
584 |
-
if (endsAfter || span.from == endCh && marker.type == "bookmark" && (!isInsert || span.marker.insertLeft)) {
|
585 |
-
var startsBefore = span.from == null || (
|
586 |
-
;(nw || (nw = [])).push(new MarkedSpan(marker, startsBefore ? null : span.from - endCh,
|
587 |
-
span.to == null ? null : span.to - endCh))
|
588 |
-
}
|
589 |
-
} }
|
590 |
-
return nw
|
591 |
-
}
|
592 |
-
|
593 |
-
// Given a change object, compute the new set of marker spans that
|
594 |
-
// cover the line in which the change took place. Removes spans
|
595 |
-
// entirely within the change, reconnects spans belonging to the
|
596 |
-
// same marker that appear on both sides of the change, and cuts off
|
597 |
-
// spans partially within the change. Returns an array of span
|
598 |
-
// arrays with one element for each line in (after) the change.
|
599 |
-
function stretchSpansOverChange(doc, change) {
|
600 |
-
if (change.full) { return null }
|
601 |
-
var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans
|
602 |
-
var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans
|
603 |
-
if (!oldFirst && !oldLast) { return null }
|
604 |
-
|
605 |
-
var startCh = change.from.ch, endCh = change.to.ch, isInsert = cmp(change.from, change.to) == 0
|
606 |
-
// Get the spans that 'stick out' on both sides
|
607 |
-
var first = markedSpansBefore(oldFirst, startCh, isInsert)
|
608 |
-
var last = markedSpansAfter(oldLast, endCh, isInsert)
|
609 |
-
|
610 |
-
// Next, merge those two ends
|
611 |
-
var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0)
|
612 |
-
if (first) {
|
613 |
-
// Fix up .to properties of first
|
614 |
-
for (var i = 0; i < first.length; ++i) {
|
615 |
-
var span = first[i]
|
616 |
-
if (span.to == null) {
|
617 |
-
var found = getMarkedSpanFor(last, span.marker)
|
618 |
-
if (!found) { span.to = startCh }
|
619 |
-
else if (sameLine) { span.to = found.to == null ? null : found.to + offset }
|
620 |
-
}
|
621 |
-
}
|
622 |
-
}
|
623 |
-
if (last) {
|
624 |
-
// Fix up .from in last (or move them into first in case of sameLine)
|
625 |
-
for (var i$1 = 0; i$1 < last.length; ++i$1) {
|
626 |
-
var span$1 = last[i$1]
|
627 |
-
if (span$1.to != null) { span$1.to += offset }
|
628 |
-
if (span$1.from == null) {
|
629 |
-
var found$1 = getMarkedSpanFor(first, span$1.marker)
|
630 |
-
if (!found$1) {
|
631 |
-
span$1.from = offset
|
632 |
-
if (sameLine) { (first || (first = [])).push(span$1) }
|
633 |
-
}
|
634 |
-
} else {
|
635 |
-
span$1.from += offset
|
636 |
-
if (sameLine) { (first || (first = [])).push(span$1) }
|
637 |
-
}
|
638 |
-
}
|
639 |
-
}
|
640 |
-
// Make sure we didn't create any zero-length spans
|
641 |
-
if (first) { first = clearEmptySpans(first) }
|
642 |
-
if (last && last != first) { last = clearEmptySpans(last) }
|
643 |
-
|
644 |
-
var newMarkers = [first]
|
645 |
-
if (!sameLine) {
|
646 |
-
// Fill gap with whole-line-spans
|
647 |
-
var gap = change.text.length - 2, gapMarkers
|
648 |
-
if (gap > 0 && first)
|
649 |
-
{ for (var i$2 = 0; i$2 < first.length; ++i$2)
|
650 |
-
{ if (first[i$2].to == null)
|
651 |
-
{ (gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i$2].marker, null, null)) } } }
|
652 |
-
for (var i$3 = 0; i$3 < gap; ++i$3)
|
653 |
-
{ newMarkers.push(gapMarkers) }
|
654 |
-
newMarkers.push(last)
|
655 |
-
}
|
656 |
-
return newMarkers
|
657 |
-
}
|
658 |
-
|
659 |
-
// Remove spans that are empty and don't have a clearWhenEmpty
|
660 |
-
// option of false.
|
661 |
-
function clearEmptySpans(spans) {
|
662 |
-
for (var i = 0; i < spans.length; ++i) {
|
663 |
-
var span = spans[i]
|
664 |
-
if (span.from != null && span.from == span.to && span.marker.clearWhenEmpty !== false)
|
665 |
-
{ spans.splice(i--, 1) }
|
666 |
-
}
|
667 |
-
if (!spans.length) { return null }
|
668 |
-
return spans
|
669 |
-
}
|
670 |
-
|
671 |
-
// Used to 'clip' out readOnly ranges when making a change.
|
672 |
-
function removeReadOnlyRanges(doc, from, to) {
|
673 |
-
var markers = null
|
674 |
-
doc.iter(from.line, to.line + 1, function (line) {
|
675 |
-
if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) {
|
676 |
-
var mark = line.markedSpans[i].marker
|
677 |
-
if (mark.readOnly && (!markers || indexOf(markers, mark) == -1))
|
678 |
-
{ (markers || (markers = [])).push(mark) }
|
679 |
-
} }
|
680 |
-
})
|
681 |
-
if (!markers) { return null }
|
682 |
-
var parts = [{from: from, to: to}]
|
683 |
-
for (var i = 0; i < markers.length; ++i) {
|
684 |
-
var mk = markers[i], m = mk.find(0)
|
685 |
-
for (var j = 0; j < parts.length; ++j) {
|
686 |
-
var p = parts[j]
|
687 |
-
if (cmp(p.to, m.from) < 0 || cmp(p.from, m.to) > 0) { continue }
|
688 |
-
var newParts = [j, 1], dfrom = cmp(p.from, m.from), dto = cmp(p.to, m.to)
|
689 |
-
if (dfrom < 0 || !mk.inclusiveLeft && !dfrom)
|
690 |
-
{ newParts.push({from: p.from, to: m.from}) }
|
691 |
-
if (dto > 0 || !mk.inclusiveRight && !dto)
|
692 |
-
{ newParts.push({from: m.to, to: p.to}) }
|
693 |
-
parts.splice.apply(parts, newParts)
|
694 |
-
j += newParts.length - 3
|
695 |
-
}
|
696 |
-
}
|
697 |
-
return parts
|
698 |
-
}
|
699 |
-
|
700 |
-
// Connect or disconnect spans from a line.
|
701 |
-
function detachMarkedSpans(line) {
|
702 |
-
var spans = line.markedSpans
|
703 |
-
if (!spans) { return }
|
704 |
-
for (var i = 0; i < spans.length; ++i)
|
705 |
-
{ spans[i].marker.detachLine(line) }
|
706 |
-
line.markedSpans = null
|
707 |
-
}
|
708 |
-
function attachMarkedSpans(line, spans) {
|
709 |
-
if (!spans) { return }
|
710 |
-
for (var i = 0; i < spans.length; ++i)
|
711 |
-
{ spans[i].marker.attachLine(line) }
|
712 |
-
line.markedSpans = spans
|
713 |
-
}
|
714 |
-
|
715 |
-
// Helpers used when computing which overlapping collapsed span
|
716 |
-
// counts as the larger one.
|
717 |
-
function extraLeft(marker) { return marker.inclusiveLeft ? -1 : 0 }
|
718 |
-
function extraRight(marker) { return marker.inclusiveRight ? 1 : 0 }
|
719 |
-
|
720 |
-
// Returns a number indicating which of two overlapping collapsed
|
721 |
-
// spans is larger (and thus includes the other). Falls back to
|
722 |
-
// comparing ids when the spans cover exactly the same range.
|
723 |
-
function compareCollapsedMarkers(a, b) {
|
724 |
-
var lenDiff = a.lines.length - b.lines.length
|
725 |
-
if (lenDiff != 0) { return lenDiff }
|
726 |
-
var aPos = a.find(), bPos = b.find()
|
727 |
-
var fromCmp = cmp(aPos.from, bPos.from) || extraLeft(a) - extraLeft(b)
|
728 |
-
if (fromCmp) { return -fromCmp }
|
729 |
-
var toCmp = cmp(aPos.to, bPos.to) || extraRight(a) - extraRight(b)
|
730 |
-
if (toCmp) { return toCmp }
|
731 |
-
return b.id - a.id
|
732 |
-
}
|
733 |
-
|
734 |
-
// Find out whether a line ends or starts in a collapsed span. If
|
735 |
-
// so, return the marker for that span.
|
736 |
-
function collapsedSpanAtSide(line, start) {
|
737 |
-
var sps = sawCollapsedSpans && line.markedSpans, found
|
738 |
-
if (sps) { for (var sp = (void 0), i = 0; i < sps.length; ++i) {
|
739 |
-
sp = sps[i]
|
740 |
-
if (sp.marker.collapsed && (start ? sp.from : sp.to) == null &&
|
741 |
-
(!found || compareCollapsedMarkers(found, sp.marker) < 0))
|
742 |
-
{ found = sp.marker }
|
743 |
-
} }
|
744 |
-
return found
|
745 |
-
}
|
746 |
-
function collapsedSpanAtStart(line) { return collapsedSpanAtSide(line, true) }
|
747 |
-
function collapsedSpanAtEnd(line) { return collapsedSpanAtSide(line, false) }
|
748 |
-
|
749 |
-
function collapsedSpanAround(line, ch) {
|
750 |
-
var sps = sawCollapsedSpans && line.markedSpans, found
|
751 |
-
if (sps) { for (var i = 0; i < sps.length; ++i) {
|
752 |
-
var sp = sps[i]
|
753 |
-
if (sp.marker.collapsed && (sp.from == null || sp.from < ch) && (sp.to == null || sp.to > ch) &&
|
754 |
-
(!found || compareCollapsedMarkers(found, sp.marker) < 0)) { found = sp.marker }
|
755 |
-
} }
|
756 |
-
return found
|
757 |
-
}
|
758 |
-
|
759 |
-
// Test whether there exists a collapsed span that partially
|
760 |
-
// overlaps (covers the start or end, but not both) of a new span.
|
761 |
-
// Such overlap is not allowed.
|
762 |
-
function conflictingCollapsedRange(doc, lineNo, from, to, marker) {
|
763 |
-
var line = getLine(doc, lineNo)
|
764 |
-
var sps = sawCollapsedSpans && line.markedSpans
|
765 |
-
if (sps) { for (var i = 0; i < sps.length; ++i) {
|
766 |
-
var sp = sps[i]
|
767 |
-
if (!sp.marker.collapsed) { continue }
|
768 |
-
var found = sp.marker.find(0)
|
769 |
-
var fromCmp = cmp(found.from, from) || extraLeft(sp.marker) - extraLeft(marker)
|
770 |
-
var toCmp = cmp(found.to, to) || extraRight(sp.marker) - extraRight(marker)
|
771 |
-
if (fromCmp >= 0 && toCmp <= 0 || fromCmp <= 0 && toCmp >= 0) { continue }
|
772 |
-
if (fromCmp <= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.to, from) >= 0 : cmp(found.to, from) > 0) ||
|
773 |
-
fromCmp >= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.from, to) <= 0 : cmp(found.from, to) < 0))
|
774 |
-
{ return true }
|
775 |
-
} }
|
776 |
-
}
|
777 |
-
|
778 |
-
// A visual line is a line as drawn on the screen. Folding, for
|
779 |
-
// example, can cause multiple logical lines to appear on the same
|
780 |
-
// visual line. This finds the start of the visual line that the
|
781 |
-
// given line is part of (usually that is the line itself).
|
782 |
-
function visualLine(line) {
|
783 |
-
var merged
|
784 |
-
while (merged = collapsedSpanAtStart(line))
|
785 |
-
{ line = merged.find(-1, true).line }
|
786 |
-
return line
|
787 |
-
}
|
788 |
-
|
789 |
-
function visualLineEnd(line) {
|
790 |
-
var merged
|
791 |
-
while (merged = collapsedSpanAtEnd(line))
|
792 |
-
{ line = merged.find(1, true).line }
|
793 |
-
return line
|
794 |
-
}
|
795 |
-
|
796 |
-
// Returns an array of logical lines that continue the visual line
|
797 |
-
// started by the argument, or undefined if there are no such lines.
|
798 |
-
function visualLineContinued(line) {
|
799 |
-
var merged, lines
|
800 |
-
while (merged = collapsedSpanAtEnd(line)) {
|
801 |
-
line = merged.find(1, true).line
|
802 |
-
;(lines || (lines = [])).push(line)
|
803 |
-
}
|
804 |
-
return lines
|
805 |
-
}
|
806 |
-
|
807 |
-
// Get the line number of the start of the visual line that the
|
808 |
-
// given line number is part of.
|
809 |
-
function visualLineNo(doc, lineN) {
|
810 |
-
var line = getLine(doc, lineN), vis = visualLine(line)
|
811 |
-
if (line == vis) { return lineN }
|
812 |
-
return lineNo(vis)
|
813 |
-
}
|
814 |
-
|
815 |
-
// Get the line number of the start of the next visual line after
|
816 |
-
// the given line.
|
817 |
-
function visualLineEndNo(doc, lineN) {
|
818 |
-
if (lineN > doc.lastLine()) { return lineN }
|
819 |
-
var line = getLine(doc, lineN), merged
|
820 |
-
if (!lineIsHidden(doc, line)) { return lineN }
|
821 |
-
while (merged = collapsedSpanAtEnd(line))
|
822 |
-
{ line = merged.find(1, true).line }
|
823 |
-
return lineNo(line) + 1
|
824 |
-
}
|
825 |
-
|
826 |
-
// Compute whether a line is hidden. Lines count as hidden when they
|
827 |
-
// are part of a visual line that starts with another line, or when
|
828 |
-
// they are entirely covered by collapsed, non-widget span.
|
829 |
-
function lineIsHidden(doc, line) {
|
830 |
-
var sps = sawCollapsedSpans && line.markedSpans
|
831 |
-
if (sps) { for (var sp = (void 0), i = 0; i < sps.length; ++i) {
|
832 |
-
sp = sps[i]
|
833 |
-
if (!sp.marker.collapsed) { continue }
|
834 |
-
if (sp.from == null) { return true }
|
835 |
-
if (sp.marker.widgetNode) { continue }
|
836 |
-
if (sp.from == 0 && sp.marker.inclusiveLeft && lineIsHiddenInner(doc, line, sp))
|
837 |
-
{ return true }
|
838 |
-
} }
|
839 |
-
}
|
840 |
-
function lineIsHiddenInner(doc, line, span) {
|
841 |
-
if (span.to == null) {
|
842 |
-
var end = span.marker.find(1, true)
|
843 |
-
return lineIsHiddenInner(doc, end.line, getMarkedSpanFor(end.line.markedSpans, span.marker))
|
844 |
-
}
|
845 |
-
if (span.marker.inclusiveRight && span.to == line.text.length)
|
846 |
-
{ return true }
|
847 |
-
for (var sp = (void 0), i = 0; i < line.markedSpans.length; ++i) {
|
848 |
-
sp = line.markedSpans[i]
|
849 |
-
if (sp.marker.collapsed && !sp.marker.widgetNode && sp.from == span.to &&
|
850 |
-
(sp.to == null || sp.to != span.from) &&
|
851 |
-
(sp.marker.inclusiveLeft || span.marker.inclusiveRight) &&
|
852 |
-
lineIsHiddenInner(doc, line, sp)) { return true }
|
853 |
-
}
|
854 |
-
}
|
855 |
-
|
856 |
-
// Find the height above the given line.
|
857 |
-
function heightAtLine(lineObj) {
|
858 |
-
lineObj = visualLine(lineObj)
|
859 |
-
|
860 |
-
var h = 0, chunk = lineObj.parent
|
861 |
-
for (var i = 0; i < chunk.lines.length; ++i) {
|
862 |
-
var line = chunk.lines[i]
|
863 |
-
if (line == lineObj) { break }
|
864 |
-
else { h += line.height }
|
865 |
-
}
|
866 |
-
for (var p = chunk.parent; p; chunk = p, p = chunk.parent) {
|
867 |
-
for (var i$1 = 0; i$1 < p.children.length; ++i$1) {
|
868 |
-
var cur = p.children[i$1]
|
869 |
-
if (cur == chunk) { break }
|
870 |
-
else { h += cur.height }
|
871 |
-
}
|
872 |
-
}
|
873 |
-
return h
|
874 |
-
}
|
875 |
-
|
876 |
-
// Compute the character length of a line, taking into account
|
877 |
-
// collapsed ranges (see markText) that might hide parts, and join
|
878 |
-
// other lines onto it.
|
879 |
-
function lineLength(line) {
|
880 |
-
if (line.height == 0) { return 0 }
|
881 |
-
var len = line.text.length, merged, cur = line
|
882 |
-
while (merged = collapsedSpanAtStart(cur)) {
|
883 |
-
var found = merged.find(0, true)
|
884 |
-
cur = found.from.line
|
885 |
-
len += found.from.ch - found.to.ch
|
886 |
-
}
|
887 |
-
cur = line
|
888 |
-
while (merged = collapsedSpanAtEnd(cur)) {
|
889 |
-
var found$1 = merged.find(0, true)
|
890 |
-
len -= cur.text.length - found$1.from.ch
|
891 |
-
cur = found$1.to.line
|
892 |
-
len += cur.text.length - found$1.to.ch
|
893 |
-
}
|
894 |
-
return len
|
895 |
-
}
|
896 |
-
|
897 |
-
// Find the longest line in the document.
|
898 |
-
function findMaxLine(cm) {
|
899 |
-
var d = cm.display, doc = cm.doc
|
900 |
-
d.maxLine = getLine(doc, doc.first)
|
901 |
-
d.maxLineLength = lineLength(d.maxLine)
|
902 |
-
d.maxLineChanged = true
|
903 |
-
doc.iter(function (line) {
|
904 |
-
var len = lineLength(line)
|
905 |
-
if (len > d.maxLineLength) {
|
906 |
-
d.maxLineLength = len
|
907 |
-
d.maxLine = line
|
908 |
-
}
|
909 |
-
})
|
910 |
-
}
|
911 |
-
|
912 |
-
// BIDI HELPERS
|
913 |
-
|
914 |
-
function iterateBidiSections(order, from, to, f) {
|
915 |
-
if (!order) { return f(from, to, "ltr", 0) }
|
916 |
-
var found = false
|
917 |
-
for (var i = 0; i < order.length; ++i) {
|
918 |
-
var part = order[i]
|
919 |
-
if (part.from < to && part.to > from || from == to && part.to == from) {
|
920 |
-
f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr", i)
|
921 |
-
found = true
|
922 |
-
}
|
923 |
-
}
|
924 |
-
if (!found) { f(from, to, "ltr") }
|
925 |
-
}
|
926 |
-
|
927 |
-
var bidiOther = null
|
928 |
-
function getBidiPartAt(order, ch, sticky) {
|
929 |
-
var found
|
930 |
-
bidiOther = null
|
931 |
-
for (var i = 0; i < order.length; ++i) {
|
932 |
-
var cur = order[i]
|
933 |
-
if (cur.from < ch && cur.to > ch) { return i }
|
934 |
-
if (cur.to == ch) {
|
935 |
-
if (cur.from != cur.to && sticky == "before") { found = i }
|
936 |
-
else { bidiOther = i }
|
937 |
-
}
|
938 |
-
if (cur.from == ch) {
|
939 |
-
if (cur.from != cur.to && sticky != "before") { found = i }
|
940 |
-
else { bidiOther = i }
|
941 |
-
}
|
942 |
-
}
|
943 |
-
return found != null ? found : bidiOther
|
944 |
-
}
|
945 |
-
|
946 |
-
// Bidirectional ordering algorithm
|
947 |
-
// See http://unicode.org/reports/tr9/tr9-13.html for the algorithm
|
948 |
-
// that this (partially) implements.
|
949 |
-
|
950 |
-
// One-char codes used for character types:
|
951 |
-
// L (L): Left-to-Right
|
952 |
-
// R (R): Right-to-Left
|
953 |
-
// r (AL): Right-to-Left Arabic
|
954 |
-
// 1 (EN): European Number
|
955 |
-
// + (ES): European Number Separator
|
956 |
-
// % (ET): European Number Terminator
|
957 |
-
// n (AN): Arabic Number
|
958 |
-
// , (CS): Common Number Separator
|
959 |
-
// m (NSM): Non-Spacing Mark
|
960 |
-
// b (BN): Boundary Neutral
|
961 |
-
// s (B): Paragraph Separator
|
962 |
-
// t (S): Segment Separator
|
963 |
-
// w (WS): Whitespace
|
964 |
-
// N (ON): Other Neutrals
|
965 |
-
|
966 |
-
// Returns null if characters are ordered as they appear
|
967 |
-
// (left-to-right), or an array of sections ({from, to, level}
|
968 |
-
// objects) in the order in which they occur visually.
|
969 |
-
var bidiOrdering = (function() {
|
970 |
-
// Character types for codepoints 0 to 0xff
|
971 |
-
var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN"
|
972 |
-
// Character types for codepoints 0x600 to 0x6f9
|
973 |
-
var arabicTypes = "nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111"
|
974 |
-
function charType(code) {
|
975 |
-
if (code <= 0xf7) { return lowTypes.charAt(code) }
|
976 |
-
else if (0x590 <= code && code <= 0x5f4) { return "R" }
|
977 |
-
else if (0x600 <= code && code <= 0x6f9) { return arabicTypes.charAt(code - 0x600) }
|
978 |
-
else if (0x6ee <= code && code <= 0x8ac) { return "r" }
|
979 |
-
else if (0x2000 <= code && code <= 0x200b) { return "w" }
|
980 |
-
else if (code == 0x200c) { return "b" }
|
981 |
-
else { return "L" }
|
982 |
-
}
|
983 |
-
|
984 |
-
var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/
|
985 |
-
var isNeutral = /[stwN]/, isStrong = /[LRr]/, countsAsLeft = /[Lb1n]/, countsAsNum = /[1n]/
|
986 |
-
|
987 |
-
function BidiSpan(level, from, to) {
|
988 |
-
this.level = level
|
989 |
-
this.from = from; this.to = to
|
990 |
-
}
|
991 |
-
|
992 |
-
return function(str, direction) {
|
993 |
-
var outerType = direction == "ltr" ? "L" : "R"
|
994 |
-
|
995 |
-
if (str.length == 0 || direction == "ltr" && !bidiRE.test(str)) { return false }
|
996 |
-
var len = str.length, types = []
|
997 |
-
for (var i = 0; i < len; ++i)
|
998 |
-
{ types.push(charType(str.charCodeAt(i))) }
|
999 |
-
|
1000 |
-
// W1. Examine each non-spacing mark (NSM) in the level run, and
|
1001 |
-
// change the type of the NSM to the type of the previous
|
1002 |
-
// character. If the NSM is at the start of the level run, it will
|
1003 |
-
// get the type of sor.
|
1004 |
-
for (var i$1 = 0, prev = outerType; i$1 < len; ++i$1) {
|
1005 |
-
var type = types[i$1]
|
1006 |
-
if (type == "m") { types[i$1] = prev }
|
1007 |
-
else { prev = type }
|
1008 |
-
}
|
1009 |
-
|
1010 |
-
// W2. Search backwards from each instance of a European number
|
1011 |
-
// until the first strong type (R, L, AL, or sor) is found. If an
|
1012 |
-
// AL is found, change the type of the European number to Arabic
|
1013 |
-
// number.
|
1014 |
-
// W3. Change all ALs to R.
|
1015 |
-
for (var i$2 = 0, cur = outerType; i$2 < len; ++i$2) {
|
1016 |
-
var type$1 = types[i$2]
|
1017 |
-
if (type$1 == "1" && cur == "r") { types[i$2] = "n" }
|
1018 |
-
else if (isStrong.test(type$1)) { cur = type$1; if (type$1 == "r") { types[i$2] = "R" } }
|
1019 |
-
}
|
1020 |
-
|
1021 |
-
// W4. A single European separator between two European numbers
|
1022 |
-
// changes to a European number. A single common separator between
|
1023 |
-
// two numbers of the same type changes to that type.
|
1024 |
-
for (var i$3 = 1, prev$1 = types[0]; i$3 < len - 1; ++i$3) {
|
1025 |
-
var type$2 = types[i$3]
|
1026 |
-
if (type$2 == "+" && prev$1 == "1" && types[i$3+1] == "1") { types[i$3] = "1" }
|
1027 |
-
else if (type$2 == "," && prev$1 == types[i$3+1] &&
|
1028 |
-
(prev$1 == "1" || prev$1 == "n")) { types[i$3] = prev$1 }
|
1029 |
-
prev$1 = type$2
|
1030 |
-
}
|
1031 |
-
|
1032 |
-
// W5. A sequence of European terminators adjacent to European
|
1033 |
-
// numbers changes to all European numbers.
|
1034 |
-
// W6. Otherwise, separators and terminators change to Other
|
1035 |
-
// Neutral.
|
1036 |
-
for (var i$4 = 0; i$4 < len; ++i$4) {
|
1037 |
-
var type$3 = types[i$4]
|
1038 |
-
if (type$3 == ",") { types[i$4] = "N" }
|
1039 |
-
else if (type$3 == "%") {
|
1040 |
-
var end = (void 0)
|
1041 |
-
for (end = i$4 + 1; end < len && types[end] == "%"; ++end) {}
|
1042 |
-
var replace = (i$4 && types[i$4-1] == "!") || (end < len && types[end] == "1") ? "1" : "N"
|
1043 |
-
for (var j = i$4; j < end; ++j) { types[j] = replace }
|
1044 |
-
i$4 = end - 1
|
1045 |
-
}
|
1046 |
-
}
|
1047 |
-
|
1048 |
-
// W7. Search backwards from each instance of a European number
|
1049 |
-
// until the first strong type (R, L, or sor) is found. If an L is
|
1050 |
-
// found, then change the type of the European number to L.
|
1051 |
-
for (var i$5 = 0, cur$1 = outerType; i$5 < len; ++i$5) {
|
1052 |
-
var type$4 = types[i$5]
|
1053 |
-
if (cur$1 == "L" && type$4 == "1") { types[i$5] = "L" }
|
1054 |
-
else if (isStrong.test(type$4)) { cur$1 = type$4 }
|
1055 |
-
}
|
1056 |
-
|
1057 |
-
// N1. A sequence of neutrals takes the direction of the
|
1058 |
-
// surrounding strong text if the text on both sides has the same
|
1059 |
-
// direction. European and Arabic numbers act as if they were R in
|
1060 |
-
// terms of their influence on neutrals. Start-of-level-run (sor)
|
1061 |
-
// and end-of-level-run (eor) are used at level run boundaries.
|
1062 |
-
// N2. Any remaining neutrals take the embedding direction.
|
1063 |
-
for (var i$6 = 0; i$6 < len; ++i$6) {
|
1064 |
-
if (isNeutral.test(types[i$6])) {
|
1065 |
-
var end$1 = (void 0)
|
1066 |
-
for (end$1 = i$6 + 1; end$1 < len && isNeutral.test(types[end$1]); ++end$1) {}
|
1067 |
-
var before = (i$6 ? types[i$6-1] : outerType) == "L"
|
1068 |
-
var after = (end$1 < len ? types[end$1] : outerType) == "L"
|
1069 |
-
var replace$1 = before == after ? (before ? "L" : "R") : outerType
|
1070 |
-
for (var j$1 = i$6; j$1 < end$1; ++j$1) { types[j$1] = replace$1 }
|
1071 |
-
i$6 = end$1 - 1
|
1072 |
-
}
|
1073 |
-
}
|
1074 |
-
|
1075 |
-
// Here we depart from the documented algorithm, in order to avoid
|
1076 |
-
// building up an actual levels array. Since there are only three
|
1077 |
-
// levels (0, 1, 2) in an implementation that doesn't take
|
1078 |
-
// explicit embedding into account, we can build up the order on
|
1079 |
-
// the fly, without following the level-based algorithm.
|
1080 |
-
var order = [], m
|
1081 |
-
for (var i$7 = 0; i$7 < len;) {
|
1082 |
-
if (countsAsLeft.test(types[i$7])) {
|
1083 |
-
var start = i$7
|
1084 |
-
for (++i$7; i$7 < len && countsAsLeft.test(types[i$7]); ++i$7) {}
|
1085 |
-
order.push(new BidiSpan(0, start, i$7))
|
1086 |
-
} else {
|
1087 |
-
var pos = i$7, at = order.length
|
1088 |
-
for (++i$7; i$7 < len && types[i$7] != "L"; ++i$7) {}
|
1089 |
-
for (var j$2 = pos; j$2 < i$7;) {
|
1090 |
-
if (countsAsNum.test(types[j$2])) {
|
1091 |
-
if (pos < j$2) { order.splice(at, 0, new BidiSpan(1, pos, j$2)) }
|
1092 |
-
var nstart = j$2
|
1093 |
-
for (++j$2; j$2 < i$7 && countsAsNum.test(types[j$2]); ++j$2) {}
|
1094 |
-
order.splice(at, 0, new BidiSpan(2, nstart, j$2))
|
1095 |
-
pos = j$2
|
1096 |
-
} else { ++j$2 }
|
1097 |
-
}
|
1098 |
-
if (pos < i$7) { order.splice(at, 0, new BidiSpan(1, pos, i$7)) }
|
1099 |
-
}
|
1100 |
-
}
|
1101 |
-
if (direction == "ltr") {
|
1102 |
-
if (order[0].level == 1 && (m = str.match(/^\s+/))) {
|
1103 |
-
order[0].from = m[0].length
|
1104 |
-
order.unshift(new BidiSpan(0, 0, m[0].length))
|
1105 |
-
}
|
1106 |
-
if (lst(order).level == 1 && (m = str.match(/\s+$/))) {
|
1107 |
-
lst(order).to -= m[0].length
|
1108 |
-
order.push(new BidiSpan(0, len - m[0].length, len))
|
1109 |
-
}
|
1110 |
-
}
|
1111 |
-
|
1112 |
-
return direction == "rtl" ? order.reverse() : order
|
1113 |
-
}
|
1114 |
-
})()
|
1115 |
-
|
1116 |
-
// Get the bidi ordering for the given line (and cache it). Returns
|
1117 |
-
// false for lines that are fully left-to-right, and an array of
|
1118 |
-
// BidiSpan objects otherwise.
|
1119 |
-
function getOrder(line, direction) {
|
1120 |
-
var order = line.order
|
1121 |
-
if (order == null) { order = line.order = bidiOrdering(line.text, direction) }
|
1122 |
-
return order
|
1123 |
-
}
|
1124 |
-
|
1125 |
-
// EVENT HANDLING
|
1126 |
-
|
1127 |
-
// Lightweight event framework. on/off also work on DOM nodes,
|
1128 |
-
// registering native DOM handlers.
|
1129 |
-
|
1130 |
-
var noHandlers = []
|
1131 |
-
|
1132 |
-
var on = function(emitter, type, f) {
|
1133 |
-
if (emitter.addEventListener) {
|
1134 |
-
emitter.addEventListener(type, f, false)
|
1135 |
-
} else if (emitter.attachEvent) {
|
1136 |
-
emitter.attachEvent("on" + type, f)
|
1137 |
-
} else {
|
1138 |
-
var map = emitter._handlers || (emitter._handlers = {})
|
1139 |
-
map[type] = (map[type] || noHandlers).concat(f)
|
1140 |
-
}
|
1141 |
-
}
|
1142 |
-
|
1143 |
-
function getHandlers(emitter, type) {
|
1144 |
-
return emitter._handlers && emitter._handlers[type] || noHandlers
|
1145 |
-
}
|
1146 |
-
|
1147 |
-
function off(emitter, type, f) {
|
1148 |
-
if (emitter.removeEventListener) {
|
1149 |
-
emitter.removeEventListener(type, f, false)
|
1150 |
-
} else if (emitter.detachEvent) {
|
1151 |
-
emitter.detachEvent("on" + type, f)
|
1152 |
-
} else {
|
1153 |
-
var map = emitter._handlers, arr = map && map[type]
|
1154 |
-
if (arr) {
|
1155 |
-
var index = indexOf(arr, f)
|
1156 |
-
if (index > -1)
|
1157 |
-
{ map[type] = arr.slice(0, index).concat(arr.slice(index + 1)) }
|
1158 |
-
}
|
1159 |
-
}
|
1160 |
-
}
|
1161 |
-
|
1162 |
-
function signal(emitter, type /*, values...*/) {
|
1163 |
-
var handlers = getHandlers(emitter, type)
|
1164 |
-
if (!handlers.length) { return }
|
1165 |
-
var args = Array.prototype.slice.call(arguments, 2)
|
1166 |
-
for (var i = 0; i < handlers.length; ++i) { handlers[i].apply(null, args) }
|
1167 |
-
}
|
1168 |
-
|
1169 |
-
// The DOM events that CodeMirror handles can be overridden by
|
1170 |
-
// registering a (non-DOM) handler on the editor for the event name,
|
1171 |
-
// and preventDefault-ing the event in that handler.
|
1172 |
-
function signalDOMEvent(cm, e, override) {
|
1173 |
-
if (typeof e == "string")
|
1174 |
-
{ e = {type: e, preventDefault: function() { this.defaultPrevented = true }} }
|
1175 |
-
signal(cm, override || e.type, cm, e)
|
1176 |
-
return e_defaultPrevented(e) || e.codemirrorIgnore
|
1177 |
-
}
|
1178 |
-
|
1179 |
-
function signalCursorActivity(cm) {
|
1180 |
-
var arr = cm._handlers && cm._handlers.cursorActivity
|
1181 |
-
if (!arr) { return }
|
1182 |
-
var set = cm.curOp.cursorActivityHandlers || (cm.curOp.cursorActivityHandlers = [])
|
1183 |
-
for (var i = 0; i < arr.length; ++i) { if (indexOf(set, arr[i]) == -1)
|
1184 |
-
{ set.push(arr[i]) } }
|
1185 |
-
}
|
1186 |
-
|
1187 |
-
function hasHandler(emitter, type) {
|
1188 |
-
return getHandlers(emitter, type).length > 0
|
1189 |
-
}
|
1190 |
-
|
1191 |
-
// Add on and off methods to a constructor's prototype, to make
|
1192 |
-
// registering events on such objects more convenient.
|
1193 |
-
function eventMixin(ctor) {
|
1194 |
-
ctor.prototype.on = function(type, f) {on(this, type, f)}
|
1195 |
-
ctor.prototype.off = function(type, f) {off(this, type, f)}
|
1196 |
-
}
|
1197 |
-
|
1198 |
-
// Due to the fact that we still support jurassic IE versions, some
|
1199 |
-
// compatibility wrappers are needed.
|
1200 |
-
|
1201 |
-
function e_preventDefault(e) {
|
1202 |
-
if (e.preventDefault) { e.preventDefault() }
|
1203 |
-
else { e.returnValue = false }
|
1204 |
-
}
|
1205 |
-
function e_stopPropagation(e) {
|
1206 |
-
if (e.stopPropagation) { e.stopPropagation() }
|
1207 |
-
else { e.cancelBubble = true }
|
1208 |
-
}
|
1209 |
-
function e_defaultPrevented(e) {
|
1210 |
-
return e.defaultPrevented != null ? e.defaultPrevented : e.returnValue == false
|
1211 |
-
}
|
1212 |
-
function e_stop(e) {e_preventDefault(e); e_stopPropagation(e)}
|
1213 |
-
|
1214 |
-
function e_target(e) {return e.target || e.srcElement}
|
1215 |
-
function e_button(e) {
|
1216 |
-
var b = e.which
|
1217 |
-
if (b == null) {
|
1218 |
-
if (e.button & 1) { b = 1 }
|
1219 |
-
else if (e.button & 2) { b = 3 }
|
1220 |
-
else if (e.button & 4) { b = 2 }
|
1221 |
-
}
|
1222 |
-
if (mac && e.ctrlKey && b == 1) { b = 3 }
|
1223 |
-
return b
|
1224 |
-
}
|
1225 |
-
|
1226 |
-
// Detect drag-and-drop
|
1227 |
-
var dragAndDrop = function() {
|
1228 |
-
// There is *some* kind of drag-and-drop support in IE6-8, but I
|
1229 |
-
// couldn't get it to work yet.
|
1230 |
-
if (ie && ie_version < 9) { return false }
|
1231 |
-
var div = elt('div')
|
1232 |
-
return "draggable" in div || "dragDrop" in div
|
1233 |
-
}()
|
1234 |
-
|
1235 |
-
var zwspSupported
|
1236 |
-
function zeroWidthElement(measure) {
|
1237 |
-
if (zwspSupported == null) {
|
1238 |
-
var test = elt("span", "\u200b")
|
1239 |
-
removeChildrenAndAdd(measure, elt("span", [test, document.createTextNode("x")]))
|
1240 |
-
if (measure.firstChild.offsetHeight != 0)
|
1241 |
-
{ zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !(ie && ie_version < 8) }
|
1242 |
-
}
|
1243 |
-
var node = zwspSupported ? elt("span", "\u200b") :
|
1244 |
-
elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px")
|
1245 |
-
node.setAttribute("cm-text", "")
|
1246 |
-
return node
|
1247 |
-
}
|
1248 |
-
|
1249 |
-
// Feature-detect IE's crummy client rect reporting for bidi text
|
1250 |
-
var badBidiRects
|
1251 |
-
function hasBadBidiRects(measure) {
|
1252 |
-
if (badBidiRects != null) { return badBidiRects }
|
1253 |
-
var txt = removeChildrenAndAdd(measure, document.createTextNode("A\u062eA"))
|
1254 |
-
var r0 = range(txt, 0, 1).getBoundingClientRect()
|
1255 |
-
var r1 = range(txt, 1, 2).getBoundingClientRect()
|
1256 |
-
removeChildren(measure)
|
1257 |
-
if (!r0 || r0.left == r0.right) { return false } // Safari returns null in some cases (#2780)
|
1258 |
-
return badBidiRects = (r1.right - r0.right < 3)
|
1259 |
-
}
|
1260 |
-
|
1261 |
-
// See if "".split is the broken IE version, if so, provide an
|
1262 |
-
// alternative way to split lines.
|
1263 |
-
var splitLinesAuto = "\n\nb".split(/\n/).length != 3 ? function (string) {
|
1264 |
-
var pos = 0, result = [], l = string.length
|
1265 |
-
while (pos <= l) {
|
1266 |
-
var nl = string.indexOf("\n", pos)
|
1267 |
-
if (nl == -1) { nl = string.length }
|
1268 |
-
var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl)
|
1269 |
-
var rt = line.indexOf("\r")
|
1270 |
-
if (rt != -1) {
|
1271 |
-
result.push(line.slice(0, rt))
|
1272 |
-
pos += rt + 1
|
1273 |
-
} else {
|
1274 |
-
result.push(line)
|
1275 |
-
pos = nl + 1
|
1276 |
-
}
|
1277 |
-
}
|
1278 |
-
return result
|
1279 |
-
} : function (string) { return string.split(/\r\n?|\n/); }
|
1280 |
-
|
1281 |
-
var hasSelection = window.getSelection ? function (te) {
|
1282 |
-
try { return te.selectionStart != te.selectionEnd }
|
1283 |
-
catch(e) { return false }
|
1284 |
-
} : function (te) {
|
1285 |
-
var range
|
1286 |
-
try {range = te.ownerDocument.selection.createRange()}
|
1287 |
-
catch(e) {}
|
1288 |
-
if (!range || range.parentElement() != te) { return false }
|
1289 |
-
return range.compareEndPoints("StartToEnd", range) != 0
|
1290 |
-
}
|
1291 |
-
|
1292 |
-
var hasCopyEvent = (function () {
|
1293 |
-
var e = elt("div")
|
1294 |
-
if ("oncopy" in e) { return true }
|
1295 |
-
e.setAttribute("oncopy", "return;")
|
1296 |
-
return typeof e.oncopy == "function"
|
1297 |
-
})()
|
1298 |
-
|
1299 |
-
var badZoomedRects = null
|
1300 |
-
function hasBadZoomedRects(measure) {
|
1301 |
-
if (badZoomedRects != null) { return badZoomedRects }
|
1302 |
-
var node = removeChildrenAndAdd(measure, elt("span", "x"))
|
1303 |
-
var normal = node.getBoundingClientRect()
|
1304 |
-
var fromRange = range(node, 0, 1).getBoundingClientRect()
|
1305 |
-
return badZoomedRects = Math.abs(normal.left - fromRange.left) > 1
|
1306 |
-
}
|
1307 |
-
|
1308 |
-
var modes = {};
|
1309 |
-
var mimeModes = {};
|
1310 |
-
// Extra arguments are stored as the mode's dependencies, which is
|
1311 |
-
// used by (legacy) mechanisms like loadmode.js to automatically
|
1312 |
-
// load a mode. (Preferred mechanism is the require/define calls.)
|
1313 |
-
function defineMode(name, mode) {
|
1314 |
-
if (arguments.length > 2)
|
1315 |
-
{ mode.dependencies = Array.prototype.slice.call(arguments, 2) }
|
1316 |
-
modes[name] = mode
|
1317 |
-
}
|
1318 |
-
|
1319 |
-
function defineMIME(mime, spec) {
|
1320 |
-
mimeModes[mime] = spec
|
1321 |
-
}
|
1322 |
-
|
1323 |
-
// Given a MIME type, a {name, ...options} config object, or a name
|
1324 |
-
// string, return a mode config object.
|
1325 |
-
function resolveMode(spec) {
|
1326 |
-
if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {
|
1327 |
-
spec = mimeModes[spec]
|
1328 |
-
} else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {
|
1329 |
-
var found = mimeModes[spec.name]
|
1330 |
-
if (typeof found == "string") { found = {name: found} }
|
1331 |
-
spec = createObj(found, spec)
|
1332 |
-
spec.name = found.name
|
1333 |
-
} else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {
|
1334 |
-
return resolveMode("application/xml")
|
1335 |
-
} else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+json$/.test(spec)) {
|
1336 |
-
return resolveMode("application/json")
|
1337 |
-
}
|
1338 |
-
if (typeof spec == "string") { return {name: spec} }
|
1339 |
-
else { return spec || {name: "null"} }
|
1340 |
-
}
|
1341 |
-
|
1342 |
-
// Given a mode spec (anything that resolveMode accepts), find and
|
1343 |
-
// initialize an actual mode object.
|
1344 |
-
function getMode(options, spec) {
|
1345 |
-
spec = resolveMode(spec)
|
1346 |
-
var mfactory = modes[spec.name]
|
1347 |
-
if (!mfactory) { return getMode(options, "text/plain") }
|
1348 |
-
var modeObj = mfactory(options, spec)
|
1349 |
-
if (modeExtensions.hasOwnProperty(spec.name)) {
|
1350 |
-
var exts = modeExtensions[spec.name]
|
1351 |
-
for (var prop in exts) {
|
1352 |
-
if (!exts.hasOwnProperty(prop)) { continue }
|
1353 |
-
if (modeObj.hasOwnProperty(prop)) { modeObj["_" + prop] = modeObj[prop] }
|
1354 |
-
modeObj[prop] = exts[prop]
|
1355 |
-
}
|
1356 |
-
}
|
1357 |
-
modeObj.name = spec.name
|
1358 |
-
if (spec.helperType) { modeObj.helperType = spec.helperType }
|
1359 |
-
if (spec.modeProps) { for (var prop$1 in spec.modeProps)
|
1360 |
-
{ modeObj[prop$1] = spec.modeProps[prop$1] } }
|
1361 |
-
|
1362 |
-
return modeObj
|
1363 |
-
}
|
1364 |
-
|
1365 |
-
// This can be used to attach properties to mode objects from
|
1366 |
-
// outside the actual mode definition.
|
1367 |
-
var modeExtensions = {}
|
1368 |
-
function extendMode(mode, properties) {
|
1369 |
-
var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {})
|
1370 |
-
copyObj(properties, exts)
|
1371 |
-
}
|
1372 |
-
|
1373 |
-
function copyState(mode, state) {
|
1374 |
-
if (state === true) { return state }
|
1375 |
-
if (mode.copyState) { return mode.copyState(state) }
|
1376 |
-
var nstate = {}
|
1377 |
-
for (var n in state) {
|
1378 |
-
var val = state[n]
|
1379 |
-
if (val instanceof Array) { val = val.concat([]) }
|
1380 |
-
nstate[n] = val
|
1381 |
-
}
|
1382 |
-
return nstate
|
1383 |
-
}
|
1384 |
-
|
1385 |
-
// Given a mode and a state (for that mode), find the inner mode and
|
1386 |
-
// state at the position that the state refers to.
|
1387 |
-
function innerMode(mode, state) {
|
1388 |
-
var info
|
1389 |
-
while (mode.innerMode) {
|
1390 |
-
info = mode.innerMode(state)
|
1391 |
-
if (!info || info.mode == mode) { break }
|
1392 |
-
state = info.state
|
1393 |
-
mode = info.mode
|
1394 |
-
}
|
1395 |
-
return info || {mode: mode, state: state}
|
1396 |
-
}
|
1397 |
-
|
1398 |
-
function startState(mode, a1, a2) {
|
1399 |
-
return mode.startState ? mode.startState(a1, a2) : true
|
1400 |
-
}
|
1401 |
-
|
1402 |
-
// STRING STREAM
|
1403 |
-
|
1404 |
-
// Fed to the mode parsers, provides helper functions to make
|
1405 |
-
// parsers more succinct.
|
1406 |
-
|
1407 |
-
var StringStream = function(string, tabSize, lineOracle) {
|
1408 |
-
this.pos = this.start = 0
|
1409 |
-
this.string = string
|
1410 |
-
this.tabSize = tabSize || 8
|
1411 |
-
this.lastColumnPos = this.lastColumnValue = 0
|
1412 |
-
this.lineStart = 0
|
1413 |
-
this.lineOracle = lineOracle
|
1414 |
-
};
|
1415 |
-
|
1416 |
-
StringStream.prototype.eol = function () {return this.pos >= this.string.length};
|
1417 |
-
StringStream.prototype.sol = function () {return this.pos == this.lineStart};
|
1418 |
-
StringStream.prototype.peek = function () {return this.string.charAt(this.pos) || undefined};
|
1419 |
-
StringStream.prototype.next = function () {
|
1420 |
-
if (this.pos < this.string.length)
|
1421 |
-
{ return this.string.charAt(this.pos++) }
|
1422 |
-
};
|
1423 |
-
StringStream.prototype.eat = function (match) {
|
1424 |
-
var ch = this.string.charAt(this.pos)
|
1425 |
-
var ok
|
1426 |
-
if (typeof match == "string") { ok = ch == match }
|
1427 |
-
else { ok = ch && (match.test ? match.test(ch) : match(ch)) }
|
1428 |
-
if (ok) {++this.pos; return ch}
|
1429 |
-
};
|
1430 |
-
StringStream.prototype.eatWhile = function (match) {
|
1431 |
-
var start = this.pos
|
1432 |
-
while (this.eat(match)){}
|
1433 |
-
return this.pos > start
|
1434 |
-
};
|
1435 |
-
StringStream.prototype.eatSpace = function () {
|
1436 |
-
var this$1 = this;
|
1437 |
-
|
1438 |
-
var start = this.pos
|
1439 |
-
while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) { ++this$1.pos }
|
1440 |
-
return this.pos > start
|
1441 |
-
};
|
1442 |
-
StringStream.prototype.skipToEnd = function () {this.pos = this.string.length};
|
1443 |
-
StringStream.prototype.skipTo = function (ch) {
|
1444 |
-
var found = this.string.indexOf(ch, this.pos)
|
1445 |
-
if (found > -1) {this.pos = found; return true}
|
1446 |
-
};
|
1447 |
-
StringStream.prototype.backUp = function (n) {this.pos -= n};
|
1448 |
-
StringStream.prototype.column = function () {
|
1449 |
-
if (this.lastColumnPos < this.start) {
|
1450 |
-
this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue)
|
1451 |
-
this.lastColumnPos = this.start
|
1452 |
-
}
|
1453 |
-
return this.lastColumnValue - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)
|
1454 |
-
};
|
1455 |
-
StringStream.prototype.indentation = function () {
|
1456 |
-
return countColumn(this.string, null, this.tabSize) -
|
1457 |
-
(this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)
|
1458 |
-
};
|
1459 |
-
StringStream.prototype.match = function (pattern, consume, caseInsensitive) {
|
1460 |
-
if (typeof pattern == "string") {
|
1461 |
-
var cased = function (str) { return caseInsensitive ? str.toLowerCase() : str; }
|
1462 |
-
var substr = this.string.substr(this.pos, pattern.length)
|
1463 |
-
if (cased(substr) == cased(pattern)) {
|
1464 |
-
if (consume !== false) { this.pos += pattern.length }
|
1465 |
-
return true
|
1466 |
-
}
|
1467 |
-
} else {
|
1468 |
-
var match = this.string.slice(this.pos).match(pattern)
|
1469 |
-
if (match && match.index > 0) { return null }
|
1470 |
-
if (match && consume !== false) { this.pos += match[0].length }
|
1471 |
-
return match
|
1472 |
-
}
|
1473 |
-
};
|
1474 |
-
StringStream.prototype.current = function (){return this.string.slice(this.start, this.pos)};
|
1475 |
-
StringStream.prototype.hideFirstChars = function (n, inner) {
|
1476 |
-
this.lineStart += n
|
1477 |
-
try { return inner() }
|
1478 |
-
finally { this.lineStart -= n }
|
1479 |
-
};
|
1480 |
-
StringStream.prototype.lookAhead = function (n) {
|
1481 |
-
var oracle = this.lineOracle
|
1482 |
-
return oracle && oracle.lookAhead(n)
|
1483 |
-
};
|
1484 |
-
StringStream.prototype.baseToken = function () {
|
1485 |
-
var oracle = this.lineOracle
|
1486 |
-
return oracle && oracle.baseToken(this.pos)
|
1487 |
-
};
|
1488 |
-
|
1489 |
-
var SavedContext = function(state, lookAhead) {
|
1490 |
-
this.state = state
|
1491 |
-
this.lookAhead = lookAhead
|
1492 |
-
};
|
1493 |
-
|
1494 |
-
var Context = function(doc, state, line, lookAhead) {
|
1495 |
-
this.state = state
|
1496 |
-
this.doc = doc
|
1497 |
-
this.line = line
|
1498 |
-
this.maxLookAhead = lookAhead || 0
|
1499 |
-
this.baseTokens = null
|
1500 |
-
this.baseTokenPos = 1
|
1501 |
-
};
|
1502 |
-
|
1503 |
-
Context.prototype.lookAhead = function (n) {
|
1504 |
-
var line = this.doc.getLine(this.line + n)
|
1505 |
-
if (line != null && n > this.maxLookAhead) { this.maxLookAhead = n }
|
1506 |
-
return line
|
1507 |
-
};
|
1508 |
-
|
1509 |
-
Context.prototype.baseToken = function (n) {
|
1510 |
-
var this$1 = this;
|
1511 |
-
|
1512 |
-
if (!this.baseTokens) { return null }
|
1513 |
-
while (this.baseTokens[this.baseTokenPos] <= n)
|
1514 |
-
{ this$1.baseTokenPos += 2 }
|
1515 |
-
var type = this.baseTokens[this.baseTokenPos + 1]
|
1516 |
-
return {type: type && type.replace(/( |^)overlay .*/, ""),
|
1517 |
-
size: this.baseTokens[this.baseTokenPos] - n}
|
1518 |
-
};
|
1519 |
-
|
1520 |
-
Context.prototype.nextLine = function () {
|
1521 |
-
this.line++
|
1522 |
-
if (this.maxLookAhead > 0) { this.maxLookAhead-- }
|
1523 |
-
};
|
1524 |
-
|
1525 |
-
Context.fromSaved = function (doc, saved, line) {
|
1526 |
-
if (saved instanceof SavedContext)
|
1527 |
-
{ return new Context(doc, copyState(doc.mode, saved.state), line, saved.lookAhead) }
|
1528 |
-
else
|
1529 |
-
{ return new Context(doc, copyState(doc.mode, saved), line) }
|
1530 |
-
};
|
1531 |
-
|
1532 |
-
Context.prototype.save = function (copy) {
|
1533 |
-
var state = copy !== false ? copyState(this.doc.mode, this.state) : this.state
|
1534 |
-
return this.maxLookAhead > 0 ? new SavedContext(state, this.maxLookAhead) : state
|
1535 |
-
};
|
1536 |
-
|
1537 |
-
|
1538 |
-
// Compute a style array (an array starting with a mode generation
|
1539 |
-
// -- for invalidation -- followed by pairs of end positions and
|
1540 |
-
// style strings), which is used to highlight the tokens on the
|
1541 |
-
// line.
|
1542 |
-
function highlightLine(cm, line, context, forceToEnd) {
|
1543 |
-
// A styles array always starts with a number identifying the
|
1544 |
-
// mode/overlays that it is based on (for easy invalidation).
|
1545 |
-
var st = [cm.state.modeGen], lineClasses = {}
|
1546 |
-
// Compute the base array of styles
|
1547 |
-
runMode(cm, line.text, cm.doc.mode, context, function (end, style) { return st.push(end, style); },
|
1548 |
-
lineClasses, forceToEnd)
|
1549 |
-
var state = context.state
|
1550 |
-
|
1551 |
-
// Run overlays, adjust style array.
|
1552 |
-
var loop = function ( o ) {
|
1553 |
-
context.baseTokens = st
|
1554 |
-
var overlay = cm.state.overlays[o], i = 1, at = 0
|
1555 |
-
context.state = true
|
1556 |
-
runMode(cm, line.text, overlay.mode, context, function (end, style) {
|
1557 |
-
var start = i
|
1558 |
-
// Ensure there's a token end at the current position, and that i points at it
|
1559 |
-
while (at < end) {
|
1560 |
-
var i_end = st[i]
|
1561 |
-
if (i_end > end)
|
1562 |
-
{ st.splice(i, 1, end, st[i+1], i_end) }
|
1563 |
-
i += 2
|
1564 |
-
at = Math.min(end, i_end)
|
1565 |
-
}
|
1566 |
-
if (!style) { return }
|
1567 |
-
if (overlay.opaque) {
|
1568 |
-
st.splice(start, i - start, end, "overlay " + style)
|
1569 |
-
i = start + 2
|
1570 |
-
} else {
|
1571 |
-
for (; start < i; start += 2) {
|
1572 |
-
var cur = st[start+1]
|
1573 |
-
st[start+1] = (cur ? cur + " " : "") + "overlay " + style
|
1574 |
-
}
|
1575 |
-
}
|
1576 |
-
}, lineClasses)
|
1577 |
-
context.state = state
|
1578 |
-
context.baseTokens = null
|
1579 |
-
context.baseTokenPos = 1
|
1580 |
-
};
|
1581 |
-
|
1582 |
-
for (var o = 0; o < cm.state.overlays.length; ++o) loop( o );
|
1583 |
-
|
1584 |
-
return {styles: st, classes: lineClasses.bgClass || lineClasses.textClass ? lineClasses : null}
|
1585 |
-
}
|
1586 |
-
|
1587 |
-
function getLineStyles(cm, line, updateFrontier) {
|
1588 |
-
if (!line.styles || line.styles[0] != cm.state.modeGen) {
|
1589 |
-
var context = getContextBefore(cm, lineNo(line))
|
1590 |
-
var resetState = line.text.length > cm.options.maxHighlightLength && copyState(cm.doc.mode, context.state)
|
1591 |
-
var result = highlightLine(cm, line, context)
|
1592 |
-
if (resetState) { context.state = resetState }
|
1593 |
-
line.stateAfter = context.save(!resetState)
|
1594 |
-
line.styles = result.styles
|
1595 |
-
if (result.classes) { line.styleClasses = result.classes }
|
1596 |
-
else if (line.styleClasses) { line.styleClasses = null }
|
1597 |
-
if (updateFrontier === cm.doc.highlightFrontier)
|
1598 |
-
{ cm.doc.modeFrontier = Math.max(cm.doc.modeFrontier, ++cm.doc.highlightFrontier) }
|
1599 |
-
}
|
1600 |
-
return line.styles
|
1601 |
-
}
|
1602 |
-
|
1603 |
-
function getContextBefore(cm, n, precise) {
|
1604 |
-
var doc = cm.doc, display = cm.display
|
1605 |
-
if (!doc.mode.startState) { return new Context(doc, true, n) }
|
1606 |
-
var start = findStartLine(cm, n, precise)
|
1607 |
-
var saved = start > doc.first && getLine(doc, start - 1).stateAfter
|
1608 |
-
var context = saved ? Context.fromSaved(doc, saved, start) : new Context(doc, startState(doc.mode), start)
|
1609 |
-
|
1610 |
-
doc.iter(start, n, function (line) {
|
1611 |
-
processLine(cm, line.text, context)
|
1612 |
-
var pos = context.line
|
1613 |
-
line.stateAfter = pos == n - 1 || pos % 5 == 0 || pos >= display.viewFrom && pos < display.viewTo ? context.save() : null
|
1614 |
-
context.nextLine()
|
1615 |
-
})
|
1616 |
-
if (precise) { doc.modeFrontier = context.line }
|
1617 |
-
return context
|
1618 |
-
}
|
1619 |
-
|
1620 |
-
// Lightweight form of highlight -- proceed over this line and
|
1621 |
-
// update state, but don't save a style array. Used for lines that
|
1622 |
-
// aren't currently visible.
|
1623 |
-
function processLine(cm, text, context, startAt) {
|
1624 |
-
var mode = cm.doc.mode
|
1625 |
-
var stream = new StringStream(text, cm.options.tabSize, context)
|
1626 |
-
stream.start = stream.pos = startAt || 0
|
1627 |
-
if (text == "") { callBlankLine(mode, context.state) }
|
1628 |
-
while (!stream.eol()) {
|
1629 |
-
readToken(mode, stream, context.state)
|
1630 |
-
stream.start = stream.pos
|
1631 |
-
}
|
1632 |
-
}
|
1633 |
-
|
1634 |
-
function callBlankLine(mode, state) {
|
1635 |
-
if (mode.blankLine) { return mode.blankLine(state) }
|
1636 |
-
if (!mode.innerMode) { return }
|
1637 |
-
var inner = innerMode(mode, state)
|
1638 |
-
if (inner.mode.blankLine) { return inner.mode.blankLine(inner.state) }
|
1639 |
-
}
|
1640 |
-
|
1641 |
-
function readToken(mode, stream, state, inner) {
|
1642 |
-
for (var i = 0; i < 10; i++) {
|
1643 |
-
if (inner) { inner[0] = innerMode(mode, state).mode }
|
1644 |
-
var style = mode.token(stream, state)
|
1645 |
-
if (stream.pos > stream.start) { return style }
|
1646 |
-
}
|
1647 |
-
throw new Error("Mode " + mode.name + " failed to advance stream.")
|
1648 |
-
}
|
1649 |
-
|
1650 |
-
var Token = function(stream, type, state) {
|
1651 |
-
this.start = stream.start; this.end = stream.pos
|
1652 |
-
this.string = stream.current()
|
1653 |
-
this.type = type || null
|
1654 |
-
this.state = state
|
1655 |
-
};
|
1656 |
-
|
1657 |
-
// Utility for getTokenAt and getLineTokens
|
1658 |
-
function takeToken(cm, pos, precise, asArray) {
|
1659 |
-
var doc = cm.doc, mode = doc.mode, style
|
1660 |
-
pos = clipPos(doc, pos)
|
1661 |
-
var line = getLine(doc, pos.line), context = getContextBefore(cm, pos.line, precise)
|
1662 |
-
var stream = new StringStream(line.text, cm.options.tabSize, context), tokens
|
1663 |
-
if (asArray) { tokens = [] }
|
1664 |
-
while ((asArray || stream.pos < pos.ch) && !stream.eol()) {
|
1665 |
-
stream.start = stream.pos
|
1666 |
-
style = readToken(mode, stream, context.state)
|
1667 |
-
if (asArray) { tokens.push(new Token(stream, style, copyState(doc.mode, context.state))) }
|
1668 |
-
}
|
1669 |
-
return asArray ? tokens : new Token(stream, style, context.state)
|
1670 |
-
}
|
1671 |
-
|
1672 |
-
function extractLineClasses(type, output) {
|
1673 |
-
if (type) { for (;;) {
|
1674 |
-
var lineClass = type.match(/(?:^|\s+)line-(background-)?(\S+)/)
|
1675 |
-
if (!lineClass) { break }
|
1676 |
-
type = type.slice(0, lineClass.index) + type.slice(lineClass.index + lineClass[0].length)
|
1677 |
-
var prop = lineClass[1] ? "bgClass" : "textClass"
|
1678 |
-
if (output[prop] == null)
|
1679 |
-
{ output[prop] = lineClass[2] }
|
1680 |
-
else if (!(new RegExp("(?:^|\s)" + lineClass[2] + "(?:$|\s)")).test(output[prop]))
|
1681 |
-
{ output[prop] += " " + lineClass[2] }
|
1682 |
-
} }
|
1683 |
-
return type
|
1684 |
-
}
|
1685 |
-
|
1686 |
-
// Run the given mode's parser over a line, calling f for each token.
|
1687 |
-
function runMode(cm, text, mode, context, f, lineClasses, forceToEnd) {
|
1688 |
-
var flattenSpans = mode.flattenSpans
|
1689 |
-
if (flattenSpans == null) { flattenSpans = cm.options.flattenSpans }
|
1690 |
-
var curStart = 0, curStyle = null
|
1691 |
-
var stream = new StringStream(text, cm.options.tabSize, context), style
|
1692 |
-
var inner = cm.options.addModeClass && [null]
|
1693 |
-
if (text == "") { extractLineClasses(callBlankLine(mode, context.state), lineClasses) }
|
1694 |
-
while (!stream.eol()) {
|
1695 |
-
if (stream.pos > cm.options.maxHighlightLength) {
|
1696 |
-
flattenSpans = false
|
1697 |
-
if (forceToEnd) { processLine(cm, text, context, stream.pos) }
|
1698 |
-
stream.pos = text.length
|
1699 |
-
style = null
|
1700 |
-
} else {
|
1701 |
-
style = extractLineClasses(readToken(mode, stream, context.state, inner), lineClasses)
|
1702 |
-
}
|
1703 |
-
if (inner) {
|
1704 |
-
var mName = inner[0].name
|
1705 |
-
if (mName) { style = "m-" + (style ? mName + " " + style : mName) }
|
1706 |
-
}
|
1707 |
-
if (!flattenSpans || curStyle != style) {
|
1708 |
-
while (curStart < stream.start) {
|
1709 |
-
curStart = Math.min(stream.start, curStart + 5000)
|
1710 |
-
f(curStart, curStyle)
|
1711 |
-
}
|
1712 |
-
curStyle = style
|
1713 |
-
}
|
1714 |
-
stream.start = stream.pos
|
1715 |
-
}
|
1716 |
-
while (curStart < stream.pos) {
|
1717 |
-
// Webkit seems to refuse to render text nodes longer than 57444
|
1718 |
-
// characters, and returns inaccurate measurements in nodes
|
1719 |
-
// starting around 5000 chars.
|
1720 |
-
var pos = Math.min(stream.pos, curStart + 5000)
|
1721 |
-
f(pos, curStyle)
|
1722 |
-
curStart = pos
|
1723 |
-
}
|
1724 |
-
}
|
1725 |
-
|
1726 |
-
// Finds the line to start with when starting a parse. Tries to
|
1727 |
-
// find a line with a stateAfter, so that it can start with a
|
1728 |
-
// valid state. If that fails, it returns the line with the
|
1729 |
-
// smallest indentation, which tends to need the least context to
|
1730 |
-
// parse correctly.
|
1731 |
-
function findStartLine(cm, n, precise) {
|
1732 |
-
var minindent, minline, doc = cm.doc
|
1733 |
-
var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100)
|
1734 |
-
for (var search = n; search > lim; --search) {
|
1735 |
-
if (search <= doc.first) { return doc.first }
|
1736 |
-
var line = getLine(doc, search - 1), after = line.stateAfter
|
1737 |
-
if (after && (!precise || search + (after instanceof SavedContext ? after.lookAhead : 0) <= doc.modeFrontier))
|
1738 |
-
{ return search }
|
1739 |
-
var indented = countColumn(line.text, null, cm.options.tabSize)
|
1740 |
-
if (minline == null || minindent > indented) {
|
1741 |
-
minline = search - 1
|
1742 |
-
minindent = indented
|
1743 |
-
}
|
1744 |
-
}
|
1745 |
-
return minline
|
1746 |
-
}
|
1747 |
-
|
1748 |
-
function retreatFrontier(doc, n) {
|
1749 |
-
doc.modeFrontier = Math.min(doc.modeFrontier, n)
|
1750 |
-
if (doc.highlightFrontier < n - 10) { return }
|
1751 |
-
var start = doc.first
|
1752 |
-
for (var line = n - 1; line > start; line--) {
|
1753 |
-
var saved = getLine(doc, line).stateAfter
|
1754 |
-
// change is on 3
|
1755 |
-
// state on line 1 looked ahead 2 -- so saw 3
|
1756 |
-
// test 1 + 2 < 3 should cover this
|
1757 |
-
if (saved && (!(saved instanceof SavedContext) || line + saved.lookAhead < n)) {
|
1758 |
-
start = line + 1
|
1759 |
-
break
|
1760 |
-
}
|
1761 |
-
}
|
1762 |
-
doc.highlightFrontier = Math.min(doc.highlightFrontier, start)
|
1763 |
-
}
|
1764 |
-
|
1765 |
-
// LINE DATA STRUCTURE
|
1766 |
-
|
1767 |
-
// Line objects. These hold state related to a line, including
|
1768 |
-
// highlighting info (the styles array).
|
1769 |
-
var Line = function(text, markedSpans, estimateHeight) {
|
1770 |
-
this.text = text
|
1771 |
-
attachMarkedSpans(this, markedSpans)
|
1772 |
-
this.height = estimateHeight ? estimateHeight(this) : 1
|
1773 |
-
};
|
1774 |
-
|
1775 |
-
Line.prototype.lineNo = function () { return lineNo(this) };
|
1776 |
-
eventMixin(Line)
|
1777 |
-
|
1778 |
-
// Change the content (text, markers) of a line. Automatically
|
1779 |
-
// invalidates cached information and tries to re-estimate the
|
1780 |
-
// line's height.
|
1781 |
-
function updateLine(line, text, markedSpans, estimateHeight) {
|
1782 |
-
line.text = text
|
1783 |
-
if (line.stateAfter) { line.stateAfter = null }
|
1784 |
-
if (line.styles) { line.styles = null }
|
1785 |
-
if (line.order != null) { line.order = null }
|
1786 |
-
detachMarkedSpans(line)
|
1787 |
-
attachMarkedSpans(line, markedSpans)
|
1788 |
-
var estHeight = estimateHeight ? estimateHeight(line) : 1
|
1789 |
-
if (estHeight != line.height) { updateLineHeight(line, estHeight) }
|
1790 |
-
}
|
1791 |
-
|
1792 |
-
// Detach a line from the document tree and its markers.
|
1793 |
-
function cleanUpLine(line) {
|
1794 |
-
line.parent = null
|
1795 |
-
detachMarkedSpans(line)
|
1796 |
-
}
|
1797 |
-
|
1798 |
-
// Convert a style as returned by a mode (either null, or a string
|
1799 |
-
// containing one or more styles) to a CSS style. This is cached,
|
1800 |
-
// and also looks for line-wide styles.
|
1801 |
-
var styleToClassCache = {};
|
1802 |
-
var styleToClassCacheWithMode = {};
|
1803 |
-
function interpretTokenStyle(style, options) {
|
1804 |
-
if (!style || /^\s*$/.test(style)) { return null }
|
1805 |
-
var cache = options.addModeClass ? styleToClassCacheWithMode : styleToClassCache
|
1806 |
-
return cache[style] ||
|
1807 |
-
(cache[style] = style.replace(/\S+/g, "cm-$&"))
|
1808 |
-
}
|
1809 |
-
|
1810 |
-
// Render the DOM representation of the text of a line. Also builds
|
1811 |
-
// up a 'line map', which points at the DOM nodes that represent
|
1812 |
-
// specific stretches of text, and is used by the measuring code.
|
1813 |
-
// The returned object contains the DOM node, this map, and
|
1814 |
-
// information about line-wide styles that were set by the mode.
|
1815 |
-
function buildLineContent(cm, lineView) {
|
1816 |
-
// The padding-right forces the element to have a 'border', which
|
1817 |
-
// is needed on Webkit to be able to get line-level bounding
|
1818 |
-
// rectangles for it (in measureChar).
|
1819 |
-
var content = eltP("span", null, null, webkit ? "padding-right: .1px" : null)
|
1820 |
-
var builder = {pre: eltP("pre", [content], "CodeMirror-line"), content: content,
|
1821 |
-
col: 0, pos: 0, cm: cm,
|
1822 |
-
trailingSpace: false,
|
1823 |
-
splitSpaces: (ie || webkit) && cm.getOption("lineWrapping")}
|
1824 |
-
lineView.measure = {}
|
1825 |
-
|
1826 |
-
// Iterate over the logical lines that make up this visual line.
|
1827 |
-
for (var i = 0; i <= (lineView.rest ? lineView.rest.length : 0); i++) {
|
1828 |
-
var line = i ? lineView.rest[i - 1] : lineView.line, order = (void 0)
|
1829 |
-
builder.pos = 0
|
1830 |
-
builder.addToken = buildToken
|
1831 |
-
// Optionally wire in some hacks into the token-rendering
|
1832 |
-
// algorithm, to deal with browser quirks.
|
1833 |
-
if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line, cm.doc.direction)))
|
1834 |
-
{ builder.addToken = buildTokenBadBidi(builder.addToken, order) }
|
1835 |
-
builder.map = []
|
1836 |
-
var allowFrontierUpdate = lineView != cm.display.externalMeasured && lineNo(line)
|
1837 |
-
insertLineContent(line, builder, getLineStyles(cm, line, allowFrontierUpdate))
|
1838 |
-
if (line.styleClasses) {
|
1839 |
-
if (line.styleClasses.bgClass)
|
1840 |
-
{ builder.bgClass = joinClasses(line.styleClasses.bgClass, builder.bgClass || "") }
|
1841 |
-
if (line.styleClasses.textClass)
|
1842 |
-
{ builder.textClass = joinClasses(line.styleClasses.textClass, builder.textClass || "") }
|
1843 |
-
}
|
1844 |
-
|
1845 |
-
// Ensure at least a single node is present, for measuring.
|
1846 |
-
if (builder.map.length == 0)
|
1847 |
-
{ builder.map.push(0, 0, builder.content.appendChild(zeroWidthElement(cm.display.measure))) }
|
1848 |
-
|
1849 |
-
// Store the map and a cache object for the current logical line
|
1850 |
-
if (i == 0) {
|
1851 |
-
lineView.measure.map = builder.map
|
1852 |
-
lineView.measure.cache = {}
|
1853 |
-
} else {
|
1854 |
-
;(lineView.measure.maps || (lineView.measure.maps = [])).push(builder.map)
|
1855 |
-
;(lineView.measure.caches || (lineView.measure.caches = [])).push({})
|
1856 |
-
}
|
1857 |
-
}
|
1858 |
-
|
1859 |
-
// See issue #2901
|
1860 |
-
if (webkit) {
|
1861 |
-
var last = builder.content.lastChild
|
1862 |
-
if (/\bcm-tab\b/.test(last.className) || (last.querySelector && last.querySelector(".cm-tab")))
|
1863 |
-
{ builder.content.className = "cm-tab-wrap-hack" }
|
1864 |
-
}
|
1865 |
-
|
1866 |
-
signal(cm, "renderLine", cm, lineView.line, builder.pre)
|
1867 |
-
if (builder.pre.className)
|
1868 |
-
{ builder.textClass = joinClasses(builder.pre.className, builder.textClass || "") }
|
1869 |
-
|
1870 |
-
return builder
|
1871 |
-
}
|
1872 |
-
|
1873 |
-
function defaultSpecialCharPlaceholder(ch) {
|
1874 |
-
var token = elt("span", "\u2022", "cm-invalidchar")
|
1875 |
-
token.title = "\\u" + ch.charCodeAt(0).toString(16)
|
1876 |
-
token.setAttribute("aria-label", token.title)
|
1877 |
-
return token
|
1878 |
-
}
|
1879 |
-
|
1880 |
-
// Build up the DOM representation for a single token, and add it to
|
1881 |
-
// the line map. Takes care to render special characters separately.
|
1882 |
-
function buildToken(builder, text, style, startStyle, endStyle, title, css) {
|
1883 |
-
if (!text) { return }
|
1884 |
-
var displayText = builder.splitSpaces ? splitSpaces(text, builder.trailingSpace) : text
|
1885 |
-
var special = builder.cm.state.specialChars, mustWrap = false
|
1886 |
-
var content
|
1887 |
-
if (!special.test(text)) {
|
1888 |
-
builder.col += text.length
|
1889 |
-
content = document.createTextNode(displayText)
|
1890 |
-
builder.map.push(builder.pos, builder.pos + text.length, content)
|
1891 |
-
if (ie && ie_version < 9) { mustWrap = true }
|
1892 |
-
builder.pos += text.length
|
1893 |
-
} else {
|
1894 |
-
content = document.createDocumentFragment()
|
1895 |
-
var pos = 0
|
1896 |
-
while (true) {
|
1897 |
-
special.lastIndex = pos
|
1898 |
-
var m = special.exec(text)
|
1899 |
-
var skipped = m ? m.index - pos : text.length - pos
|
1900 |
-
if (skipped) {
|
1901 |
-
var txt = document.createTextNode(displayText.slice(pos, pos + skipped))
|
1902 |
-
if (ie && ie_version < 9) { content.appendChild(elt("span", [txt])) }
|
1903 |
-
else { content.appendChild(txt) }
|
1904 |
-
builder.map.push(builder.pos, builder.pos + skipped, txt)
|
1905 |
-
builder.col += skipped
|
1906 |
-
builder.pos += skipped
|
1907 |
-
}
|
1908 |
-
if (!m) { break }
|
1909 |
-
pos += skipped + 1
|
1910 |
-
var txt$1 = (void 0)
|
1911 |
-
if (m[0] == "\t") {
|
1912 |
-
var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize
|
1913 |
-
txt$1 = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"))
|
1914 |
-
txt$1.setAttribute("role", "presentation")
|
1915 |
-
txt$1.setAttribute("cm-text", "\t")
|
1916 |
-
builder.col += tabWidth
|
1917 |
-
} else if (m[0] == "\r" || m[0] == "\n") {
|
1918 |
-
txt$1 = content.appendChild(elt("span", m[0] == "\r" ? "\u240d" : "\u2424", "cm-invalidchar"))
|
1919 |
-
txt$1.setAttribute("cm-text", m[0])
|
1920 |
-
builder.col += 1
|
1921 |
-
} else {
|
1922 |
-
txt$1 = builder.cm.options.specialCharPlaceholder(m[0])
|
1923 |
-
txt$1.setAttribute("cm-text", m[0])
|
1924 |
-
if (ie && ie_version < 9) { content.appendChild(elt("span", [txt$1])) }
|
1925 |
-
else { content.appendChild(txt$1) }
|
1926 |
-
builder.col += 1
|
1927 |
-
}
|
1928 |
-
builder.map.push(builder.pos, builder.pos + 1, txt$1)
|
1929 |
-
builder.pos++
|
1930 |
-
}
|
1931 |
-
}
|
1932 |
-
builder.trailingSpace = displayText.charCodeAt(text.length - 1) == 32
|
1933 |
-
if (style || startStyle || endStyle || mustWrap || css) {
|
1934 |
-
var fullStyle = style || ""
|
1935 |
-
if (startStyle) { fullStyle += startStyle }
|
1936 |
-
if (endStyle) { fullStyle += endStyle }
|
1937 |
-
var token = elt("span", [content], fullStyle, css)
|
1938 |
-
if (title) { token.title = title }
|
1939 |
-
return builder.content.appendChild(token)
|
1940 |
-
}
|
1941 |
-
builder.content.appendChild(content)
|
1942 |
-
}
|
1943 |
-
|
1944 |
-
function splitSpaces(text, trailingBefore) {
|
1945 |
-
if (text.length > 1 && !/ /.test(text)) { return text }
|
1946 |
-
var spaceBefore = trailingBefore, result = ""
|
1947 |
-
for (var i = 0; i < text.length; i++) {
|
1948 |
-
var ch = text.charAt(i)
|
1949 |
-
if (ch == " " && spaceBefore && (i == text.length - 1 || text.charCodeAt(i + 1) == 32))
|
1950 |
-
{ ch = "\u00a0" }
|
1951 |
-
result += ch
|
1952 |
-
spaceBefore = ch == " "
|
1953 |
-
}
|
1954 |
-
return result
|
1955 |
-
}
|
1956 |
-
|
1957 |
-
// Work around nonsense dimensions being reported for stretches of
|
1958 |
-
// right-to-left text.
|
1959 |
-
function buildTokenBadBidi(inner, order) {
|
1960 |
-
return function (builder, text, style, startStyle, endStyle, title, css) {
|
1961 |
-
style = style ? style + " cm-force-border" : "cm-force-border"
|
1962 |
-
var start = builder.pos, end = start + text.length
|
1963 |
-
for (;;) {
|
1964 |
-
// Find the part that overlaps with the start of this text
|
1965 |
-
var part = (void 0)
|
1966 |
-
for (var i = 0; i < order.length; i++) {
|
1967 |
-
part = order[i]
|
1968 |
-
if (part.to > start && part.from <= start) { break }
|
1969 |
-
}
|
1970 |
-
if (part.to >= end) { return inner(builder, text, style, startStyle, endStyle, title, css) }
|
1971 |
-
inner(builder, text.slice(0, part.to - start), style, startStyle, null, title, css)
|
1972 |
-
startStyle = null
|
1973 |
-
text = text.slice(part.to - start)
|
1974 |
-
start = part.to
|
1975 |
-
}
|
1976 |
-
}
|
1977 |
-
}
|
1978 |
-
|
1979 |
-
function buildCollapsedSpan(builder, size, marker, ignoreWidget) {
|
1980 |
-
var widget = !ignoreWidget && marker.widgetNode
|
1981 |
-
if (widget) { builder.map.push(builder.pos, builder.pos + size, widget) }
|
1982 |
-
if (!ignoreWidget && builder.cm.display.input.needsContentAttribute) {
|
1983 |
-
if (!widget)
|
1984 |
-
{ widget = builder.content.appendChild(document.createElement("span")) }
|
1985 |
-
widget.setAttribute("cm-marker", marker.id)
|
1986 |
-
}
|
1987 |
-
if (widget) {
|
1988 |
-
builder.cm.display.input.setUneditable(widget)
|
1989 |
-
builder.content.appendChild(widget)
|
1990 |
-
}
|
1991 |
-
builder.pos += size
|
1992 |
-
builder.trailingSpace = false
|
1993 |
-
}
|
1994 |
-
|
1995 |
-
// Outputs a number of spans to make up a line, taking highlighting
|
1996 |
-
// and marked text into account.
|
1997 |
-
function insertLineContent(line, builder, styles) {
|
1998 |
-
var spans = line.markedSpans, allText = line.text, at = 0
|
1999 |
-
if (!spans) {
|
2000 |
-
for (var i$1 = 1; i$1 < styles.length; i$1+=2)
|
2001 |
-
{ builder.addToken(builder, allText.slice(at, at = styles[i$1]), interpretTokenStyle(styles[i$1+1], builder.cm.options)) }
|
2002 |
-
return
|
2003 |
-
}
|
2004 |
-
|
2005 |
-
var len = allText.length, pos = 0, i = 1, text = "", style, css
|
2006 |
-
var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, title, collapsed
|
2007 |
-
for (;;) {
|
2008 |
-
if (nextChange == pos) { // Update current marker set
|
2009 |
-
spanStyle = spanEndStyle = spanStartStyle = title = css = ""
|
2010 |
-
collapsed = null; nextChange = Infinity
|
2011 |
-
var foundBookmarks = [], endStyles = (void 0)
|
2012 |
-
for (var j = 0; j < spans.length; ++j) {
|
2013 |
-
var sp = spans[j], m = sp.marker
|
2014 |
-
if (m.type == "bookmark" && sp.from == pos && m.widgetNode) {
|
2015 |
-
foundBookmarks.push(m)
|
2016 |
-
} else if (sp.from <= pos && (sp.to == null || sp.to > pos || m.collapsed && sp.to == pos && sp.from == pos)) {
|
2017 |
-
if (sp.to != null && sp.to != pos && nextChange > sp.to) {
|
2018 |
-
nextChange = sp.to
|
2019 |
-
spanEndStyle = ""
|
2020 |
-
}
|
2021 |
-
if (m.className) { spanStyle += " " + m.className }
|
2022 |
-
if (m.css) { css = (css ? css + ";" : "") + m.css }
|
2023 |
-
if (m.startStyle && sp.from == pos) { spanStartStyle += " " + m.startStyle }
|
2024 |
-
if (m.endStyle && sp.to == nextChange) { (endStyles || (endStyles = [])).push(m.endStyle, sp.to) }
|
2025 |
-
if (m.title && !title) { title = m.title }
|
2026 |
-
if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0))
|
2027 |
-
{ collapsed = sp }
|
2028 |
-
} else if (sp.from > pos && nextChange > sp.from) {
|
2029 |
-
nextChange = sp.from
|
2030 |
-
}
|
2031 |
-
}
|
2032 |
-
if (endStyles) { for (var j$1 = 0; j$1 < endStyles.length; j$1 += 2)
|
2033 |
-
{ if (endStyles[j$1 + 1] == nextChange) { spanEndStyle += " " + endStyles[j$1] } } }
|
2034 |
-
|
2035 |
-
if (!collapsed || collapsed.from == pos) { for (var j$2 = 0; j$2 < foundBookmarks.length; ++j$2)
|
2036 |
-
{ buildCollapsedSpan(builder, 0, foundBookmarks[j$2]) } }
|
2037 |
-
if (collapsed && (collapsed.from || 0) == pos) {
|
2038 |
-
buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos,
|
2039 |
-
collapsed.marker, collapsed.from == null)
|
2040 |
-
if (collapsed.to == null) { return }
|
2041 |
-
if (collapsed.to == pos) { collapsed = false }
|
2042 |
-
}
|
2043 |
-
}
|
2044 |
-
if (pos >= len) { break }
|
2045 |
-
|
2046 |
-
var upto = Math.min(len, nextChange)
|
2047 |
-
while (true) {
|
2048 |
-
if (text) {
|
2049 |
-
var end = pos + text.length
|
2050 |
-
if (!collapsed) {
|
2051 |
-
var tokenText = end > upto ? text.slice(0, upto - pos) : text
|
2052 |
-
builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle,
|
2053 |
-
spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", title, css)
|
2054 |
-
}
|
2055 |
-
if (end >= upto) {text = text.slice(upto - pos); pos = upto; break}
|
2056 |
-
pos = end
|
2057 |
-
spanStartStyle = ""
|
2058 |
-
}
|
2059 |
-
text = allText.slice(at, at = styles[i++])
|
2060 |
-
style = interpretTokenStyle(styles[i++], builder.cm.options)
|
2061 |
-
}
|
2062 |
-
}
|
2063 |
-
}
|
2064 |
-
|
2065 |
-
|
2066 |
-
// These objects are used to represent the visible (currently drawn)
|
2067 |
-
// part of the document. A LineView may correspond to multiple
|
2068 |
-
// logical lines, if those are connected by collapsed ranges.
|
2069 |
-
function LineView(doc, line, lineN) {
|
2070 |
-
// The starting line
|
2071 |
-
this.line = line
|
2072 |
-
// Continuing lines, if any
|
2073 |
-
this.rest = visualLineContinued(line)
|
2074 |
-
// Number of logical lines in this visual line
|
2075 |
-
this.size = this.rest ? lineNo(lst(this.rest)) - lineN + 1 : 1
|
2076 |
-
this.node = this.text = null
|
2077 |
-
this.hidden = lineIsHidden(doc, line)
|
2078 |
-
}
|
2079 |
-
|
2080 |
-
// Create a range of LineView objects for the given lines.
|
2081 |
-
function buildViewArray(cm, from, to) {
|
2082 |
-
var array = [], nextPos
|
2083 |
-
for (var pos = from; pos < to; pos = nextPos) {
|
2084 |
-
var view = new LineView(cm.doc, getLine(cm.doc, pos), pos)
|
2085 |
-
nextPos = pos + view.size
|
2086 |
-
array.push(view)
|
2087 |
-
}
|
2088 |
-
return array
|
2089 |
-
}
|
2090 |
-
|
2091 |
-
var operationGroup = null
|
2092 |
-
|
2093 |
-
function pushOperation(op) {
|
2094 |
-
if (operationGroup) {
|
2095 |
-
operationGroup.ops.push(op)
|
2096 |
-
} else {
|
2097 |
-
op.ownsGroup = operationGroup = {
|
2098 |
-
ops: [op],
|
2099 |
-
delayedCallbacks: []
|
2100 |
-
}
|
2101 |
-
}
|
2102 |
-
}
|
2103 |
-
|
2104 |
-
function fireCallbacksForOps(group) {
|
2105 |
-
// Calls delayed callbacks and cursorActivity handlers until no
|
2106 |
-
// new ones appear
|
2107 |
-
var callbacks = group.delayedCallbacks, i = 0
|
2108 |
-
do {
|
2109 |
-
for (; i < callbacks.length; i++)
|
2110 |
-
{ callbacks[i].call(null) }
|
2111 |
-
for (var j = 0; j < group.ops.length; j++) {
|
2112 |
-
var op = group.ops[j]
|
2113 |
-
if (op.cursorActivityHandlers)
|
2114 |
-
{ while (op.cursorActivityCalled < op.cursorActivityHandlers.length)
|
2115 |
-
{ op.cursorActivityHandlers[op.cursorActivityCalled++].call(null, op.cm) } }
|
2116 |
-
}
|
2117 |
-
} while (i < callbacks.length)
|
2118 |
-
}
|
2119 |
-
|
2120 |
-
function finishOperation(op, endCb) {
|
2121 |
-
var group = op.ownsGroup
|
2122 |
-
if (!group) { return }
|
2123 |
-
|
2124 |
-
try { fireCallbacksForOps(group) }
|
2125 |
-
finally {
|
2126 |
-
operationGroup = null
|
2127 |
-
endCb(group)
|
2128 |
-
}
|
2129 |
-
}
|
2130 |
-
|
2131 |
-
var orphanDelayedCallbacks = null
|
2132 |
-
|
2133 |
-
// Often, we want to signal events at a point where we are in the
|
2134 |
-
// middle of some work, but don't want the handler to start calling
|
2135 |
-
// other methods on the editor, which might be in an inconsistent
|
2136 |
-
// state or simply not expect any other events to happen.
|
2137 |
-
// signalLater looks whether there are any handlers, and schedules
|
2138 |
-
// them to be executed when the last operation ends, or, if no
|
2139 |
-
// operation is active, when a timeout fires.
|
2140 |
-
function signalLater(emitter, type /*, values...*/) {
|
2141 |
-
var arr = getHandlers(emitter, type)
|
2142 |
-
if (!arr.length) { return }
|
2143 |
-
var args = Array.prototype.slice.call(arguments, 2), list
|
2144 |
-
if (operationGroup) {
|
2145 |
-
list = operationGroup.delayedCallbacks
|
2146 |
-
} else if (orphanDelayedCallbacks) {
|
2147 |
-
list = orphanDelayedCallbacks
|
2148 |
-
} else {
|
2149 |
-
list = orphanDelayedCallbacks = []
|
2150 |
-
setTimeout(fireOrphanDelayed, 0)
|
2151 |
-
}
|
2152 |
-
var loop = function ( i ) {
|
2153 |
-
list.push(function () { return arr[i].apply(null, args); })
|
2154 |
-
};
|
2155 |
-
|
2156 |
-
for (var i = 0; i < arr.length; ++i)
|
2157 |
-
loop( i );
|
2158 |
-
}
|
2159 |
-
|
2160 |
-
function fireOrphanDelayed() {
|
2161 |
-
var delayed = orphanDelayedCallbacks
|
2162 |
-
orphanDelayedCallbacks = null
|
2163 |
-
for (var i = 0; i < delayed.length; ++i) { delayed[i]() }
|
2164 |
-
}
|
2165 |
-
|
2166 |
-
// When an aspect of a line changes, a string is added to
|
2167 |
-
// lineView.changes. This updates the relevant part of the line's
|
2168 |
-
// DOM structure.
|
2169 |
-
function updateLineForChanges(cm, lineView, lineN, dims) {
|
2170 |
-
for (var j = 0; j < lineView.changes.length; j++) {
|
2171 |
-
var type = lineView.changes[j]
|
2172 |
-
if (type == "text") { updateLineText(cm, lineView) }
|
2173 |
-
else if (type == "gutter") { updateLineGutter(cm, lineView, lineN, dims) }
|
2174 |
-
else if (type == "class") { updateLineClasses(cm, lineView) }
|
2175 |
-
else if (type == "widget") { updateLineWidgets(cm, lineView, dims) }
|
2176 |
-
}
|
2177 |
-
lineView.changes = null
|
2178 |
-
}
|
2179 |
-
|
2180 |
-
// Lines with gutter elements, widgets or a background class need to
|
2181 |
-
// be wrapped, and have the extra elements added to the wrapper div
|
2182 |
-
function ensureLineWrapped(lineView) {
|
2183 |
-
if (lineView.node == lineView.text) {
|
2184 |
-
lineView.node = elt("div", null, null, "position: relative")
|
2185 |
-
if (lineView.text.parentNode)
|
2186 |
-
{ lineView.text.parentNode.replaceChild(lineView.node, lineView.text) }
|
2187 |
-
lineView.node.appendChild(lineView.text)
|
2188 |
-
if (ie && ie_version < 8) { lineView.node.style.zIndex = 2 }
|
2189 |
-
}
|
2190 |
-
return lineView.node
|
2191 |
-
}
|
2192 |
-
|
2193 |
-
function updateLineBackground(cm, lineView) {
|
2194 |
-
var cls = lineView.bgClass ? lineView.bgClass + " " + (lineView.line.bgClass || "") : lineView.line.bgClass
|
2195 |
-
if (cls) { cls += " CodeMirror-linebackground" }
|
2196 |
-
if (lineView.background) {
|
2197 |
-
if (cls) { lineView.background.className = cls }
|
2198 |
-
else { lineView.background.parentNode.removeChild(lineView.background); lineView.background = null }
|
2199 |
-
} else if (cls) {
|
2200 |
-
var wrap = ensureLineWrapped(lineView)
|
2201 |
-
lineView.background = wrap.insertBefore(elt("div", null, cls), wrap.firstChild)
|
2202 |
-
cm.display.input.setUneditable(lineView.background)
|
2203 |
-
}
|
2204 |
-
}
|
2205 |
-
|
2206 |
-
// Wrapper around buildLineContent which will reuse the structure
|
2207 |
-
// in display.externalMeasured when possible.
|
2208 |
-
function getLineContent(cm, lineView) {
|
2209 |
-
var ext = cm.display.externalMeasured
|
2210 |
-
if (ext && ext.line == lineView.line) {
|
2211 |
-
cm.display.externalMeasured = null
|
2212 |
-
lineView.measure = ext.measure
|
2213 |
-
return ext.built
|
2214 |
-
}
|
2215 |
-
return buildLineContent(cm, lineView)
|
2216 |
-
}
|
2217 |
-
|
2218 |
-
// Redraw the line's text. Interacts with the background and text
|
2219 |
-
// classes because the mode may output tokens that influence these
|
2220 |
-
// classes.
|
2221 |
-
function updateLineText(cm, lineView) {
|
2222 |
-
var cls = lineView.text.className
|
2223 |
-
var built = getLineContent(cm, lineView)
|
2224 |
-
if (lineView.text == lineView.node) { lineView.node = built.pre }
|
2225 |
-
lineView.text.parentNode.replaceChild(built.pre, lineView.text)
|
2226 |
-
lineView.text = built.pre
|
2227 |
-
if (built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) {
|
2228 |
-
lineView.bgClass = built.bgClass
|
2229 |
-
lineView.textClass = built.textClass
|
2230 |
-
updateLineClasses(cm, lineView)
|
2231 |
-
} else if (cls) {
|
2232 |
-
lineView.text.className = cls
|
2233 |
-
}
|
2234 |
-
}
|
2235 |
-
|
2236 |
-
function updateLineClasses(cm, lineView) {
|
2237 |
-
updateLineBackground(cm, lineView)
|
2238 |
-
if (lineView.line.wrapClass)
|
2239 |
-
{ ensureLineWrapped(lineView).className = lineView.line.wrapClass }
|
2240 |
-
else if (lineView.node != lineView.text)
|
2241 |
-
{ lineView.node.className = "" }
|
2242 |
-
var textClass = lineView.textClass ? lineView.textClass + " " + (lineView.line.textClass || "") : lineView.line.textClass
|
2243 |
-
lineView.text.className = textClass || ""
|
2244 |
-
}
|
2245 |
-
|
2246 |
-
function updateLineGutter(cm, lineView, lineN, dims) {
|
2247 |
-
if (lineView.gutter) {
|
2248 |
-
lineView.node.removeChild(lineView.gutter)
|
2249 |
-
lineView.gutter = null
|
2250 |
-
}
|
2251 |
-
if (lineView.gutterBackground) {
|
2252 |
-
lineView.node.removeChild(lineView.gutterBackground)
|
2253 |
-
lineView.gutterBackground = null
|
2254 |
-
}
|
2255 |
-
if (lineView.line.gutterClass) {
|
2256 |
-
var wrap = ensureLineWrapped(lineView)
|
2257 |
-
lineView.gutterBackground = elt("div", null, "CodeMirror-gutter-background " + lineView.line.gutterClass,
|
2258 |
-
("left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px; width: " + (dims.gutterTotalWidth) + "px"))
|
2259 |
-
cm.display.input.setUneditable(lineView.gutterBackground)
|
2260 |
-
wrap.insertBefore(lineView.gutterBackground, lineView.text)
|
2261 |
-
}
|
2262 |
-
var markers = lineView.line.gutterMarkers
|
2263 |
-
if (cm.options.lineNumbers || markers) {
|
2264 |
-
var wrap$1 = ensureLineWrapped(lineView)
|
2265 |
-
var gutterWrap = lineView.gutter = elt("div", null, "CodeMirror-gutter-wrapper", ("left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px"))
|
2266 |
-
cm.display.input.setUneditable(gutterWrap)
|
2267 |
-
wrap$1.insertBefore(gutterWrap, lineView.text)
|
2268 |
-
if (lineView.line.gutterClass)
|
2269 |
-
{ gutterWrap.className += " " + lineView.line.gutterClass }
|
2270 |
-
if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
|
2271 |
-
{ lineView.lineNumber = gutterWrap.appendChild(
|
2272 |
-
elt("div", lineNumberFor(cm.options, lineN),
|
2273 |
-
"CodeMirror-linenumber CodeMirror-gutter-elt",
|
2274 |
-
("left: " + (dims.gutterLeft["CodeMirror-linenumbers"]) + "px; width: " + (cm.display.lineNumInnerWidth) + "px"))) }
|
2275 |
-
if (markers) { for (var k = 0; k < cm.options.gutters.length; ++k) {
|
2276 |
-
var id = cm.options.gutters[k], found = markers.hasOwnProperty(id) && markers[id]
|
2277 |
-
if (found)
|
2278 |
-
{ gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt",
|
2279 |
-
("left: " + (dims.gutterLeft[id]) + "px; width: " + (dims.gutterWidth[id]) + "px"))) }
|
2280 |
-
} }
|
2281 |
-
}
|
2282 |
-
}
|
2283 |
-
|
2284 |
-
function updateLineWidgets(cm, lineView, dims) {
|
2285 |
-
if (lineView.alignable) { lineView.alignable = null }
|
2286 |
-
for (var node = lineView.node.firstChild, next = (void 0); node; node = next) {
|
2287 |
-
next = node.nextSibling
|
2288 |
-
if (node.className == "CodeMirror-linewidget")
|
2289 |
-
{ lineView.node.removeChild(node) }
|
2290 |
-
}
|
2291 |
-
insertLineWidgets(cm, lineView, dims)
|
2292 |
-
}
|
2293 |
-
|
2294 |
-
// Build a line's DOM representation from scratch
|
2295 |
-
function buildLineElement(cm, lineView, lineN, dims) {
|
2296 |
-
var built = getLineContent(cm, lineView)
|
2297 |
-
lineView.text = lineView.node = built.pre
|
2298 |
-
if (built.bgClass) { lineView.bgClass = built.bgClass }
|
2299 |
-
if (built.textClass) { lineView.textClass = built.textClass }
|
2300 |
-
|
2301 |
-
updateLineClasses(cm, lineView)
|
2302 |
-
updateLineGutter(cm, lineView, lineN, dims)
|
2303 |
-
insertLineWidgets(cm, lineView, dims)
|
2304 |
-
return lineView.node
|
2305 |
-
}
|
2306 |
-
|
2307 |
-
// A lineView may contain multiple logical lines (when merged by
|
2308 |
-
// collapsed spans). The widgets for all of them need to be drawn.
|
2309 |
-
function insertLineWidgets(cm, lineView, dims) {
|
2310 |
-
insertLineWidgetsFor(cm, lineView.line, lineView, dims, true)
|
2311 |
-
if (lineView.rest) { for (var i = 0; i < lineView.rest.length; i++)
|
2312 |
-
{ insertLineWidgetsFor(cm, lineView.rest[i], lineView, dims, false) } }
|
2313 |
-
}
|
2314 |
-
|
2315 |
-
function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) {
|
2316 |
-
if (!line.widgets) { return }
|
2317 |
-
var wrap = ensureLineWrapped(lineView)
|
2318 |
-
for (var i = 0, ws = line.widgets; i < ws.length; ++i) {
|
2319 |
-
var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget")
|
2320 |
-
if (!widget.handleMouseEvents) { node.setAttribute("cm-ignore-events", "true") }
|
2321 |
-
positionLineWidget(widget, node, lineView, dims)
|
2322 |
-
cm.display.input.setUneditable(node)
|
2323 |
-
if (allowAbove && widget.above)
|
2324 |
-
{ wrap.insertBefore(node, lineView.gutter || lineView.text) }
|
2325 |
-
else
|
2326 |
-
{ wrap.appendChild(node) }
|
2327 |
-
signalLater(widget, "redraw")
|
2328 |
-
}
|
2329 |
-
}
|
2330 |
-
|
2331 |
-
function positionLineWidget(widget, node, lineView, dims) {
|
2332 |
-
if (widget.noHScroll) {
|
2333 |
-
;(lineView.alignable || (lineView.alignable = [])).push(node)
|
2334 |
-
var width = dims.wrapperWidth
|
2335 |
-
node.style.left = dims.fixedPos + "px"
|
2336 |
-
if (!widget.coverGutter) {
|
2337 |
-
width -= dims.gutterTotalWidth
|
2338 |
-
node.style.paddingLeft = dims.gutterTotalWidth + "px"
|
2339 |
-
}
|
2340 |
-
node.style.width = width + "px"
|
2341 |
-
}
|
2342 |
-
if (widget.coverGutter) {
|
2343 |
-
node.style.zIndex = 5
|
2344 |
-
node.style.position = "relative"
|
2345 |
-
if (!widget.noHScroll) { node.style.marginLeft = -dims.gutterTotalWidth + "px" }
|
2346 |
-
}
|
2347 |
-
}
|
2348 |
-
|
2349 |
-
function widgetHeight(widget) {
|
2350 |
-
if (widget.height != null) { return widget.height }
|
2351 |
-
var cm = widget.doc.cm
|
2352 |
-
if (!cm) { return 0 }
|
2353 |
-
if (!contains(document.body, widget.node)) {
|
2354 |
-
var parentStyle = "position: relative;"
|
2355 |
-
if (widget.coverGutter)
|
2356 |
-
{ parentStyle += "margin-left: -" + cm.display.gutters.offsetWidth + "px;" }
|
2357 |
-
if (widget.noHScroll)
|
2358 |
-
{ parentStyle += "width: " + cm.display.wrapper.clientWidth + "px;" }
|
2359 |
-
removeChildrenAndAdd(cm.display.measure, elt("div", [widget.node], null, parentStyle))
|
2360 |
-
}
|
2361 |
-
return widget.height = widget.node.parentNode.offsetHeight
|
2362 |
-
}
|
2363 |
-
|
2364 |
-
// Return true when the given mouse event happened in a widget
|
2365 |
-
function eventInWidget(display, e) {
|
2366 |
-
for (var n = e_target(e); n != display.wrapper; n = n.parentNode) {
|
2367 |
-
if (!n || (n.nodeType == 1 && n.getAttribute("cm-ignore-events") == "true") ||
|
2368 |
-
(n.parentNode == display.sizer && n != display.mover))
|
2369 |
-
{ return true }
|
2370 |
-
}
|
2371 |
-
}
|
2372 |
-
|
2373 |
-
// POSITION MEASUREMENT
|
2374 |
-
|
2375 |
-
function paddingTop(display) {return display.lineSpace.offsetTop}
|
2376 |
-
function paddingVert(display) {return display.mover.offsetHeight - display.lineSpace.offsetHeight}
|
2377 |
-
function paddingH(display) {
|
2378 |
-
if (display.cachedPaddingH) { return display.cachedPaddingH }
|
2379 |
-
var e = removeChildrenAndAdd(display.measure, elt("pre", "x"))
|
2380 |
-
var style = window.getComputedStyle ? window.getComputedStyle(e) : e.currentStyle
|
2381 |
-
var data = {left: parseInt(style.paddingLeft), right: parseInt(style.paddingRight)}
|
2382 |
-
if (!isNaN(data.left) && !isNaN(data.right)) { display.cachedPaddingH = data }
|
2383 |
-
return data
|
2384 |
-
}
|
2385 |
-
|
2386 |
-
function scrollGap(cm) { return scrollerGap - cm.display.nativeBarWidth }
|
2387 |
-
function displayWidth(cm) {
|
2388 |
-
return cm.display.scroller.clientWidth - scrollGap(cm) - cm.display.barWidth
|
2389 |
-
}
|
2390 |
-
function displayHeight(cm) {
|
2391 |
-
return cm.display.scroller.clientHeight - scrollGap(cm) - cm.display.barHeight
|
2392 |
-
}
|
2393 |
-
|
2394 |
-
// Ensure the lineView.wrapping.heights array is populated. This is
|
2395 |
-
// an array of bottom offsets for the lines that make up a drawn
|
2396 |
-
// line. When lineWrapping is on, there might be more than one
|
2397 |
-
// height.
|
2398 |
-
function ensureLineHeights(cm, lineView, rect) {
|
2399 |
-
var wrapping = cm.options.lineWrapping
|
2400 |
-
var curWidth = wrapping && displayWidth(cm)
|
2401 |
-
if (!lineView.measure.heights || wrapping && lineView.measure.width != curWidth) {
|
2402 |
-
var heights = lineView.measure.heights = []
|
2403 |
-
if (wrapping) {
|
2404 |
-
lineView.measure.width = curWidth
|
2405 |
-
var rects = lineView.text.firstChild.getClientRects()
|
2406 |
-
for (var i = 0; i < rects.length - 1; i++) {
|
2407 |
-
var cur = rects[i], next = rects[i + 1]
|
2408 |
-
if (Math.abs(cur.bottom - next.bottom) > 2)
|
2409 |
-
{ heights.push((cur.bottom + next.top) / 2 - rect.top) }
|
2410 |
-
}
|
2411 |
-
}
|
2412 |
-
heights.push(rect.bottom - rect.top)
|
2413 |
-
}
|
2414 |
-
}
|
2415 |
-
|
2416 |
-
// Find a line map (mapping character offsets to text nodes) and a
|
2417 |
-
// measurement cache for the given line number. (A line view might
|
2418 |
-
// contain multiple lines when collapsed ranges are present.)
|
2419 |
-
function mapFromLineView(lineView, line, lineN) {
|
2420 |
-
if (lineView.line == line)
|
2421 |
-
{ return {map: lineView.measure.map, cache: lineView.measure.cache} }
|
2422 |
-
for (var i = 0; i < lineView.rest.length; i++)
|
2423 |
-
{ if (lineView.rest[i] == line)
|
2424 |
-
{ return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i]} } }
|
2425 |
-
for (var i$1 = 0; i$1 < lineView.rest.length; i$1++)
|
2426 |
-
{ if (lineNo(lineView.rest[i$1]) > lineN)
|
2427 |
-
{ return {map: lineView.measure.maps[i$1], cache: lineView.measure.caches[i$1], before: true} } }
|
2428 |
-
}
|
2429 |
-
|
2430 |
-
// Render a line into the hidden node display.externalMeasured. Used
|
2431 |
-
// when measurement is needed for a line that's not in the viewport.
|
2432 |
-
function updateExternalMeasurement(cm, line) {
|
2433 |
-
line = visualLine(line)
|
2434 |
-
var lineN = lineNo(line)
|
2435 |
-
var view = cm.display.externalMeasured = new LineView(cm.doc, line, lineN)
|
2436 |
-
view.lineN = lineN
|
2437 |
-
var built = view.built = buildLineContent(cm, view)
|
2438 |
-
view.text = built.pre
|
2439 |
-
removeChildrenAndAdd(cm.display.lineMeasure, built.pre)
|
2440 |
-
return view
|
2441 |
-
}
|
2442 |
-
|
2443 |
-
// Get a {top, bottom, left, right} box (in line-local coordinates)
|
2444 |
-
// for a given character.
|
2445 |
-
function measureChar(cm, line, ch, bias) {
|
2446 |
-
return measureCharPrepared(cm, prepareMeasureForLine(cm, line), ch, bias)
|
2447 |
-
}
|
2448 |
-
|
2449 |
-
// Find a line view that corresponds to the given line number.
|
2450 |
-
function findViewForLine(cm, lineN) {
|
2451 |
-
if (lineN >= cm.display.viewFrom && lineN < cm.display.viewTo)
|
2452 |
-
{ return cm.display.view[findViewIndex(cm, lineN)] }
|
2453 |
-
var ext = cm.display.externalMeasured
|
2454 |
-
if (ext && lineN >= ext.lineN && lineN < ext.lineN + ext.size)
|
2455 |
-
{ return ext }
|
2456 |
-
}
|
2457 |
-
|
2458 |
-
// Measurement can be split in two steps, the set-up work that
|
2459 |
-
// applies to the whole line, and the measurement of the actual
|
2460 |
-
// character. Functions like coordsChar, that need to do a lot of
|
2461 |
-
// measurements in a row, can thus ensure that the set-up work is
|
2462 |
-
// only done once.
|
2463 |
-
function prepareMeasureForLine(cm, line) {
|
2464 |
-
var lineN = lineNo(line)
|
2465 |
-
var view = findViewForLine(cm, lineN)
|
2466 |
-
if (view && !view.text) {
|
2467 |
-
view = null
|
2468 |
-
} else if (view && view.changes) {
|
2469 |
-
updateLineForChanges(cm, view, lineN, getDimensions(cm))
|
2470 |
-
cm.curOp.forceUpdate = true
|
2471 |
-
}
|
2472 |
-
if (!view)
|
2473 |
-
{ view = updateExternalMeasurement(cm, line) }
|
2474 |
-
|
2475 |
-
var info = mapFromLineView(view, line, lineN)
|
2476 |
-
return {
|
2477 |
-
line: line, view: view, rect: null,
|
2478 |
-
map: info.map, cache: info.cache, before: info.before,
|
2479 |
-
hasHeights: false
|
2480 |
-
}
|
2481 |
-
}
|
2482 |
-
|
2483 |
-
// Given a prepared measurement object, measures the position of an
|
2484 |
-
// actual character (or fetches it from the cache).
|
2485 |
-
function measureCharPrepared(cm, prepared, ch, bias, varHeight) {
|
2486 |
-
if (prepared.before) { ch = -1 }
|
2487 |
-
var key = ch + (bias || ""), found
|
2488 |
-
if (prepared.cache.hasOwnProperty(key)) {
|
2489 |
-
found = prepared.cache[key]
|
2490 |
-
} else {
|
2491 |
-
if (!prepared.rect)
|
2492 |
-
{ prepared.rect = prepared.view.text.getBoundingClientRect() }
|
2493 |
-
if (!prepared.hasHeights) {
|
2494 |
-
ensureLineHeights(cm, prepared.view, prepared.rect)
|
2495 |
-
prepared.hasHeights = true
|
2496 |
-
}
|
2497 |
-
found = measureCharInner(cm, prepared, ch, bias)
|
2498 |
-
if (!found.bogus) { prepared.cache[key] = found }
|
2499 |
-
}
|
2500 |
-
return {left: found.left, right: found.right,
|
2501 |
-
top: varHeight ? found.rtop : found.top,
|
2502 |
-
bottom: varHeight ? found.rbottom : found.bottom}
|
2503 |
-
}
|
2504 |
-
|
2505 |
-
var nullRect = {left: 0, right: 0, top: 0, bottom: 0}
|
2506 |
-
|
2507 |
-
function nodeAndOffsetInLineMap(map, ch, bias) {
|
2508 |
-
var node, start, end, collapse, mStart, mEnd
|
2509 |
-
// First, search the line map for the text node corresponding to,
|
2510 |
-
// or closest to, the target character.
|
2511 |
-
for (var i = 0; i < map.length; i += 3) {
|
2512 |
-
mStart = map[i]
|
2513 |
-
mEnd = map[i + 1]
|
2514 |
-
if (ch < mStart) {
|
2515 |
-
start = 0; end = 1
|
2516 |
-
collapse = "left"
|
2517 |
-
} else if (ch < mEnd) {
|
2518 |
-
start = ch - mStart
|
2519 |
-
end = start + 1
|
2520 |
-
} else if (i == map.length - 3 || ch == mEnd && map[i + 3] > ch) {
|
2521 |
-
end = mEnd - mStart
|
2522 |
-
start = end - 1
|
2523 |
-
if (ch >= mEnd) { collapse = "right" }
|
2524 |
-
}
|
2525 |
-
if (start != null) {
|
2526 |
-
node = map[i + 2]
|
2527 |
-
if (mStart == mEnd && bias == (node.insertLeft ? "left" : "right"))
|
2528 |
-
{ collapse = bias }
|
2529 |
-
if (bias == "left" && start == 0)
|
2530 |
-
{ while (i && map[i - 2] == map[i - 3] && map[i - 1].insertLeft) {
|
2531 |
-
node = map[(i -= 3) + 2]
|
2532 |
-
collapse = "left"
|
2533 |
-
} }
|
2534 |
-
if (bias == "right" && start == mEnd - mStart)
|
2535 |
-
{ while (i < map.length - 3 && map[i + 3] == map[i + 4] && !map[i + 5].insertLeft) {
|
2536 |
-
node = map[(i += 3) + 2]
|
2537 |
-
collapse = "right"
|
2538 |
-
} }
|
2539 |
-
break
|
2540 |
-
}
|
2541 |
-
}
|
2542 |
-
return {node: node, start: start, end: end, collapse: collapse, coverStart: mStart, coverEnd: mEnd}
|
2543 |
-
}
|
2544 |
-
|
2545 |
-
function getUsefulRect(rects, bias) {
|
2546 |
-
var rect = nullRect
|
2547 |
-
if (bias == "left") { for (var i = 0; i < rects.length; i++) {
|
2548 |
-
if ((rect = rects[i]).left != rect.right) { break }
|
2549 |
-
} } else { for (var i$1 = rects.length - 1; i$1 >= 0; i$1--) {
|
2550 |
-
if ((rect = rects[i$1]).left != rect.right) { break }
|
2551 |
-
} }
|
2552 |
-
return rect
|
2553 |
-
}
|
2554 |
-
|
2555 |
-
function measureCharInner(cm, prepared, ch, bias) {
|
2556 |
-
var place = nodeAndOffsetInLineMap(prepared.map, ch, bias)
|
2557 |
-
var node = place.node, start = place.start, end = place.end, collapse = place.collapse
|
2558 |
-
|
2559 |
-
var rect
|
2560 |
-
if (node.nodeType == 3) { // If it is a text node, use a range to retrieve the coordinates.
|
2561 |
-
for (var i$1 = 0; i$1 < 4; i$1++) { // Retry a maximum of 4 times when nonsense rectangles are returned
|
2562 |
-
while (start && isExtendingChar(prepared.line.text.charAt(place.coverStart + start))) { --start }
|
2563 |
-
while (place.coverStart + end < place.coverEnd && isExtendingChar(prepared.line.text.charAt(place.coverStart + end))) { ++end }
|
2564 |
-
if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart)
|
2565 |
-
{ rect = node.parentNode.getBoundingClientRect() }
|
2566 |
-
else
|
2567 |
-
{ rect = getUsefulRect(range(node, start, end).getClientRects(), bias) }
|
2568 |
-
if (rect.left || rect.right || start == 0) { break }
|
2569 |
-
end = start
|
2570 |
-
start = start - 1
|
2571 |
-
collapse = "right"
|
2572 |
-
}
|
2573 |
-
if (ie && ie_version < 11) { rect = maybeUpdateRectForZooming(cm.display.measure, rect) }
|
2574 |
-
} else { // If it is a widget, simply get the box for the whole widget.
|
2575 |
-
if (start > 0) { collapse = bias = "right" }
|
2576 |
-
var rects
|
2577 |
-
if (cm.options.lineWrapping && (rects = node.getClientRects()).length > 1)
|
2578 |
-
{ rect = rects[bias == "right" ? rects.length - 1 : 0] }
|
2579 |
-
else
|
2580 |
-
{ rect = node.getBoundingClientRect() }
|
2581 |
-
}
|
2582 |
-
if (ie && ie_version < 9 && !start && (!rect || !rect.left && !rect.right)) {
|
2583 |
-
var rSpan = node.parentNode.getClientRects()[0]
|
2584 |
-
if (rSpan)
|
2585 |
-
{ rect = {left: rSpan.left, right: rSpan.left + charWidth(cm.display), top: rSpan.top, bottom: rSpan.bottom} }
|
2586 |
-
else
|
2587 |
-
{ rect = nullRect }
|
2588 |
-
}
|
2589 |
-
|
2590 |
-
var rtop = rect.top - prepared.rect.top, rbot = rect.bottom - prepared.rect.top
|
2591 |
-
var mid = (rtop + rbot) / 2
|
2592 |
-
var heights = prepared.view.measure.heights
|
2593 |
-
var i = 0
|
2594 |
-
for (; i < heights.length - 1; i++)
|
2595 |
-
{ if (mid < heights[i]) { break } }
|
2596 |
-
var top = i ? heights[i - 1] : 0, bot = heights[i]
|
2597 |
-
var result = {left: (collapse == "right" ? rect.right : rect.left) - prepared.rect.left,
|
2598 |
-
right: (collapse == "left" ? rect.left : rect.right) - prepared.rect.left,
|
2599 |
-
top: top, bottom: bot}
|
2600 |
-
if (!rect.left && !rect.right) { result.bogus = true }
|
2601 |
-
if (!cm.options.singleCursorHeightPerLine) { result.rtop = rtop; result.rbottom = rbot }
|
2602 |
-
|
2603 |
-
return result
|
2604 |
-
}
|
2605 |
-
|
2606 |
-
// Work around problem with bounding client rects on ranges being
|
2607 |
-
// returned incorrectly when zoomed on IE10 and below.
|
2608 |
-
function maybeUpdateRectForZooming(measure, rect) {
|
2609 |
-
if (!window.screen || screen.logicalXDPI == null ||
|
2610 |
-
screen.logicalXDPI == screen.deviceXDPI || !hasBadZoomedRects(measure))
|
2611 |
-
{ return rect }
|
2612 |
-
var scaleX = screen.logicalXDPI / screen.deviceXDPI
|
2613 |
-
var scaleY = screen.logicalYDPI / screen.deviceYDPI
|
2614 |
-
return {left: rect.left * scaleX, right: rect.right * scaleX,
|
2615 |
-
top: rect.top * scaleY, bottom: rect.bottom * scaleY}
|
2616 |
-
}
|
2617 |
-
|
2618 |
-
function clearLineMeasurementCacheFor(lineView) {
|
2619 |
-
if (lineView.measure) {
|
2620 |
-
lineView.measure.cache = {}
|
2621 |
-
lineView.measure.heights = null
|
2622 |
-
if (lineView.rest) { for (var i = 0; i < lineView.rest.length; i++)
|
2623 |
-
{ lineView.measure.caches[i] = {} } }
|
2624 |
-
}
|
2625 |
-
}
|
2626 |
-
|
2627 |
-
function clearLineMeasurementCache(cm) {
|
2628 |
-
cm.display.externalMeasure = null
|
2629 |
-
removeChildren(cm.display.lineMeasure)
|
2630 |
-
for (var i = 0; i < cm.display.view.length; i++)
|
2631 |
-
{ clearLineMeasurementCacheFor(cm.display.view[i]) }
|
2632 |
-
}
|
2633 |
-
|
2634 |
-
function clearCaches(cm) {
|
2635 |
-
clearLineMeasurementCache(cm)
|
2636 |
-
cm.display.cachedCharWidth = cm.display.cachedTextHeight = cm.display.cachedPaddingH = null
|
2637 |
-
if (!cm.options.lineWrapping) { cm.display.maxLineChanged = true }
|
2638 |
-
cm.display.lineNumChars = null
|
2639 |
-
}
|
2640 |
-
|
2641 |
-
function pageScrollX() {
|
2642 |
-
// Work around https://bugs.chromium.org/p/chromium/issues/detail?id=489206
|
2643 |
-
// which causes page_Offset and bounding client rects to use
|
2644 |
-
// different reference viewports and invalidate our calculations.
|
2645 |
-
if (chrome && android) { return -(document.body.getBoundingClientRect().left - parseInt(getComputedStyle(document.body).marginLeft)) }
|
2646 |
-
return window.pageXOffset || (document.documentElement || document.body).scrollLeft
|
2647 |
-
}
|
2648 |
-
function pageScrollY() {
|
2649 |
-
if (chrome && android) { return -(document.body.getBoundingClientRect().top - parseInt(getComputedStyle(document.body).marginTop)) }
|
2650 |
-
return window.pageYOffset || (document.documentElement || document.body).scrollTop
|
2651 |
-
}
|
2652 |
-
|
2653 |
-
function widgetTopHeight(lineObj) {
|
2654 |
-
var height = 0
|
2655 |
-
if (lineObj.widgets) { for (var i = 0; i < lineObj.widgets.length; ++i) { if (lineObj.widgets[i].above)
|
2656 |
-
{ height += widgetHeight(lineObj.widgets[i]) } } }
|
2657 |
-
return height
|
2658 |
-
}
|
2659 |
-
|
2660 |
-
// Converts a {top, bottom, left, right} box from line-local
|
2661 |
-
// coordinates into another coordinate system. Context may be one of
|
2662 |
-
// "line", "div" (display.lineDiv), "local"./null (editor), "window",
|
2663 |
-
// or "page".
|
2664 |
-
function intoCoordSystem(cm, lineObj, rect, context, includeWidgets) {
|
2665 |
-
if (!includeWidgets) {
|
2666 |
-
var height = widgetTopHeight(lineObj)
|
2667 |
-
rect.top += height; rect.bottom += height
|
2668 |
-
}
|
2669 |
-
if (context == "line") { return rect }
|
2670 |
-
if (!context) { context = "local" }
|
2671 |
-
var yOff = heightAtLine(lineObj)
|
2672 |
-
if (context == "local") { yOff += paddingTop(cm.display) }
|
2673 |
-
else { yOff -= cm.display.viewOffset }
|
2674 |
-
if (context == "page" || context == "window") {
|
2675 |
-
var lOff = cm.display.lineSpace.getBoundingClientRect()
|
2676 |
-
yOff += lOff.top + (context == "window" ? 0 : pageScrollY())
|
2677 |
-
var xOff = lOff.left + (context == "window" ? 0 : pageScrollX())
|
2678 |
-
rect.left += xOff; rect.right += xOff
|
2679 |
-
}
|
2680 |
-
rect.top += yOff; rect.bottom += yOff
|
2681 |
-
return rect
|
2682 |
-
}
|
2683 |
-
|
2684 |
-
// Coverts a box from "div" coords to another coordinate system.
|
2685 |
-
// Context may be "window", "page", "div", or "local"./null.
|
2686 |
-
function fromCoordSystem(cm, coords, context) {
|
2687 |
-
if (context == "div") { return coords }
|
2688 |
-
var left = coords.left, top = coords.top
|
2689 |
-
// First move into "page" coordinate system
|
2690 |
-
if (context == "page") {
|
2691 |
-
left -= pageScrollX()
|
2692 |
-
top -= pageScrollY()
|
2693 |
-
} else if (context == "local" || !context) {
|
2694 |
-
var localBox = cm.display.sizer.getBoundingClientRect()
|
2695 |
-
left += localBox.left
|
2696 |
-
top += localBox.top
|
2697 |
-
}
|
2698 |
-
|
2699 |
-
var lineSpaceBox = cm.display.lineSpace.getBoundingClientRect()
|
2700 |
-
return {left: left - lineSpaceBox.left, top: top - lineSpaceBox.top}
|
2701 |
-
}
|
2702 |
-
|
2703 |
-
function charCoords(cm, pos, context, lineObj, bias) {
|
2704 |
-
if (!lineObj) { lineObj = getLine(cm.doc, pos.line) }
|
2705 |
-
return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch, bias), context)
|
2706 |
-
}
|
2707 |
-
|
2708 |
-
// Returns a box for a given cursor position, which may have an
|
2709 |
-
// 'other' property containing the position of the secondary cursor
|
2710 |
-
// on a bidi boundary.
|
2711 |
-
// A cursor Pos(line, char, "before") is on the same visual line as `char - 1`
|
2712 |
-
// and after `char - 1` in writing order of `char - 1`
|
2713 |
-
// A cursor Pos(line, char, "after") is on the same visual line as `char`
|
2714 |
-
// and before `char` in writing order of `char`
|
2715 |
-
// Examples (upper-case letters are RTL, lower-case are LTR):
|
2716 |
-
// Pos(0, 1, ...)
|
2717 |
-
// before after
|
2718 |
-
// ab a|b a|b
|
2719 |
-
// aB a|B aB|
|
2720 |
-
// Ab |Ab A|b
|
2721 |
-
// AB B|A B|A
|
2722 |
-
// Every position after the last character on a line is considered to stick
|
2723 |
-
// to the last character on the line.
|
2724 |
-
function cursorCoords(cm, pos, context, lineObj, preparedMeasure, varHeight) {
|
2725 |
-
lineObj = lineObj || getLine(cm.doc, pos.line)
|
2726 |
-
if (!preparedMeasure) { preparedMeasure = prepareMeasureForLine(cm, lineObj) }
|
2727 |
-
function get(ch, right) {
|
2728 |
-
var m = measureCharPrepared(cm, preparedMeasure, ch, right ? "right" : "left", varHeight)
|
2729 |
-
if (right) { m.left = m.right; } else { m.right = m.left }
|
2730 |
-
return intoCoordSystem(cm, lineObj, m, context)
|
2731 |
-
}
|
2732 |
-
var order = getOrder(lineObj, cm.doc.direction), ch = pos.ch, sticky = pos.sticky
|
2733 |
-
if (ch >= lineObj.text.length) {
|
2734 |
-
ch = lineObj.text.length
|
2735 |
-
sticky = "before"
|
2736 |
-
} else if (ch <= 0) {
|
2737 |
-
ch = 0
|
2738 |
-
sticky = "after"
|
2739 |
-
}
|
2740 |
-
if (!order) { return get(sticky == "before" ? ch - 1 : ch, sticky == "before") }
|
2741 |
-
|
2742 |
-
function getBidi(ch, partPos, invert) {
|
2743 |
-
var part = order[partPos], right = part.level == 1
|
2744 |
-
return get(invert ? ch - 1 : ch, right != invert)
|
2745 |
-
}
|
2746 |
-
var partPos = getBidiPartAt(order, ch, sticky)
|
2747 |
-
var other = bidiOther
|
2748 |
-
var val = getBidi(ch, partPos, sticky == "before")
|
2749 |
-
if (other != null) { val.other = getBidi(ch, other, sticky != "before") }
|
2750 |
-
return val
|
2751 |
-
}
|
2752 |
-
|
2753 |
-
// Used to cheaply estimate the coordinates for a position. Used for
|
2754 |
-
// intermediate scroll updates.
|
2755 |
-
function estimateCoords(cm, pos) {
|
2756 |
-
var left = 0
|
2757 |
-
pos = clipPos(cm.doc, pos)
|
2758 |
-
if (!cm.options.lineWrapping) { left = charWidth(cm.display) * pos.ch }
|
2759 |
-
var lineObj = getLine(cm.doc, pos.line)
|
2760 |
-
var top = heightAtLine(lineObj) + paddingTop(cm.display)
|
2761 |
-
return {left: left, right: left, top: top, bottom: top + lineObj.height}
|
2762 |
-
}
|
2763 |
-
|
2764 |
-
// Positions returned by coordsChar contain some extra information.
|
2765 |
-
// xRel is the relative x position of the input coordinates compared
|
2766 |
-
// to the found position (so xRel > 0 means the coordinates are to
|
2767 |
-
// the right of the character position, for example). When outside
|
2768 |
-
// is true, that means the coordinates lie outside the line's
|
2769 |
-
// vertical range.
|
2770 |
-
function PosWithInfo(line, ch, sticky, outside, xRel) {
|
2771 |
-
var pos = Pos(line, ch, sticky)
|
2772 |
-
pos.xRel = xRel
|
2773 |
-
if (outside) { pos.outside = true }
|
2774 |
-
return pos
|
2775 |
-
}
|
2776 |
-
|
2777 |
-
// Compute the character position closest to the given coordinates.
|
2778 |
-
// Input must be lineSpace-local ("div" coordinate system).
|
2779 |
-
function coordsChar(cm, x, y) {
|
2780 |
-
var doc = cm.doc
|
2781 |
-
y += cm.display.viewOffset
|
2782 |
-
if (y < 0) { return PosWithInfo(doc.first, 0, null, true, -1) }
|
2783 |
-
var lineN = lineAtHeight(doc, y), last = doc.first + doc.size - 1
|
2784 |
-
if (lineN > last)
|
2785 |
-
{ return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, null, true, 1) }
|
2786 |
-
if (x < 0) { x = 0 }
|
2787 |
-
|
2788 |
-
var lineObj = getLine(doc, lineN)
|
2789 |
-
for (;;) {
|
2790 |
-
var found = coordsCharInner(cm, lineObj, lineN, x, y)
|
2791 |
-
var collapsed = collapsedSpanAround(lineObj, found.ch + (found.xRel > 0 ? 1 : 0))
|
2792 |
-
if (!collapsed) { return found }
|
2793 |
-
var rangeEnd = collapsed.find(1)
|
2794 |
-
if (rangeEnd.line == lineN) { return rangeEnd }
|
2795 |
-
lineObj = getLine(doc, lineN = rangeEnd.line)
|
2796 |
-
}
|
2797 |
-
}
|
2798 |
-
|
2799 |
-
function wrappedLineExtent(cm, lineObj, preparedMeasure, y) {
|
2800 |
-
y -= widgetTopHeight(lineObj)
|
2801 |
-
var end = lineObj.text.length
|
2802 |
-
var begin = findFirst(function (ch) { return measureCharPrepared(cm, preparedMeasure, ch - 1).bottom <= y; }, end, 0)
|
2803 |
-
end = findFirst(function (ch) { return measureCharPrepared(cm, preparedMeasure, ch).top > y; }, begin, end)
|
2804 |
-
return {begin: begin, end: end}
|
2805 |
-
}
|
2806 |
-
|
2807 |
-
function wrappedLineExtentChar(cm, lineObj, preparedMeasure, target) {
|
2808 |
-
if (!preparedMeasure) { preparedMeasure = prepareMeasureForLine(cm, lineObj) }
|
2809 |
-
var targetTop = intoCoordSystem(cm, lineObj, measureCharPrepared(cm, preparedMeasure, target), "line").top
|
2810 |
-
return wrappedLineExtent(cm, lineObj, preparedMeasure, targetTop)
|
2811 |
-
}
|
2812 |
-
|
2813 |
-
// Returns true if the given side of a box is after the given
|
2814 |
-
// coordinates, in top-to-bottom, left-to-right order.
|
2815 |
-
function boxIsAfter(box, x, y, left) {
|
2816 |
-
return box.bottom <= y ? false : box.top > y ? true : (left ? box.left : box.right) > x
|
2817 |
-
}
|
2818 |
-
|
2819 |
-
function coordsCharInner(cm, lineObj, lineNo, x, y) {
|
2820 |
-
// Move y into line-local coordinate space
|
2821 |
-
y -= heightAtLine(lineObj)
|
2822 |
-
var preparedMeasure = prepareMeasureForLine(cm, lineObj)
|
2823 |
-
// When directly calling `measureCharPrepared`, we have to adjust
|
2824 |
-
// for the widgets at this line.
|
2825 |
-
var widgetHeight = widgetTopHeight(lineObj)
|
2826 |
-
var begin = 0, end = lineObj.text.length, ltr = true
|
2827 |
-
|
2828 |
-
var order = getOrder(lineObj, cm.doc.direction)
|
2829 |
-
// If the line isn't plain left-to-right text, first figure out
|
2830 |
-
// which bidi section the coordinates fall into.
|
2831 |
-
if (order) {
|
2832 |
-
var part = (cm.options.lineWrapping ? coordsBidiPartWrapped : coordsBidiPart)
|
2833 |
-
(cm, lineObj, lineNo, preparedMeasure, order, x, y)
|
2834 |
-
ltr = part.level != 1
|
2835 |
-
// The awkward -1 offsets are needed because findFirst (called
|
2836 |
-
// on these below) will treat its first bound as inclusive,
|
2837 |
-
// second as exclusive, but we want to actually address the
|
2838 |
-
// characters in the part's range
|
2839 |
-
begin = ltr ? part.from : part.to - 1
|
2840 |
-
end = ltr ? part.to : part.from - 1
|
2841 |
-
}
|
2842 |
-
|
2843 |
-
// A binary search to find the first character whose bounding box
|
2844 |
-
// starts after the coordinates. If we run across any whose box wrap
|
2845 |
-
// the coordinates, store that.
|
2846 |
-
var chAround = null, boxAround = null
|
2847 |
-
var ch = findFirst(function (ch) {
|
2848 |
-
var box = measureCharPrepared(cm, preparedMeasure, ch)
|
2849 |
-
box.top += widgetHeight; box.bottom += widgetHeight
|
2850 |
-
if (!boxIsAfter(box, x, y, false)) { return false }
|
2851 |
-
if (box.top <= y && box.left <= x) {
|
2852 |
-
chAround = ch
|
2853 |
-
boxAround = box
|
2854 |
-
}
|
2855 |
-
return true
|
2856 |
-
}, begin, end)
|
2857 |
-
|
2858 |
-
var baseX, sticky, outside = false
|
2859 |
-
// If a box around the coordinates was found, use that
|
2860 |
-
if (boxAround) {
|
2861 |
-
// Distinguish coordinates nearer to the left or right side of the box
|
2862 |
-
var atLeft = x - boxAround.left < boxAround.right - x, atStart = atLeft == ltr
|
2863 |
-
ch = chAround + (atStart ? 0 : 1)
|
2864 |
-
sticky = atStart ? "after" : "before"
|
2865 |
-
baseX = atLeft ? boxAround.left : boxAround.right
|
2866 |
-
} else {
|
2867 |
-
// (Adjust for extended bound, if necessary.)
|
2868 |
-
if (!ltr && (ch == end || ch == begin)) { ch++ }
|
2869 |
-
// To determine which side to associate with, get the box to the
|
2870 |
-
// left of the character and compare it's vertical position to the
|
2871 |
-
// coordinates
|
2872 |
-
sticky = ch == 0 ? "after" : ch == lineObj.text.length ? "before" :
|
2873 |
-
(measureCharPrepared(cm, preparedMeasure, ch - (ltr ? 1 : 0)).bottom + widgetHeight <= y) == ltr ?
|
2874 |
-
"after" : "before"
|
2875 |
-
// Now get accurate coordinates for this place, in order to get a
|
2876 |
-
// base X position
|
2877 |
-
var coords = cursorCoords(cm, Pos(lineNo, ch, sticky), "line", lineObj, preparedMeasure)
|
2878 |
-
baseX = coords.left
|
2879 |
-
outside = y < coords.top || y >= coords.bottom
|
2880 |
-
}
|
2881 |
-
|
2882 |
-
ch = skipExtendingChars(lineObj.text, ch, 1)
|
2883 |
-
return PosWithInfo(lineNo, ch, sticky, outside, x - baseX)
|
2884 |
-
}
|
2885 |
-
|
2886 |
-
function coordsBidiPart(cm, lineObj, lineNo, preparedMeasure, order, x, y) {
|
2887 |
-
// Bidi parts are sorted left-to-right, and in a non-line-wrapping
|
2888 |
-
// situation, we can take this ordering to correspond to the visual
|
2889 |
-
// ordering. This finds the first part whose end is after the given
|
2890 |
-
// coordinates.
|
2891 |
-
var index = findFirst(function (i) {
|
2892 |
-
var part = order[i], ltr = part.level != 1
|
2893 |
-
return boxIsAfter(cursorCoords(cm, Pos(lineNo, ltr ? part.to : part.from, ltr ? "before" : "after"),
|
2894 |
-
"line", lineObj, preparedMeasure), x, y, true)
|
2895 |
-
}, 0, order.length - 1)
|
2896 |
-
var part = order[index]
|
2897 |
-
// If this isn't the first part, the part's start is also after
|
2898 |
-
// the coordinates, and the coordinates aren't on the same line as
|
2899 |
-
// that start, move one part back.
|
2900 |
-
if (index > 0) {
|
2901 |
-
var ltr = part.level != 1
|
2902 |
-
var start = cursorCoords(cm, Pos(lineNo, ltr ? part.from : part.to, ltr ? "after" : "before"),
|
2903 |
-
"line", lineObj, preparedMeasure)
|
2904 |
-
if (boxIsAfter(start, x, y, true) && start.top > y)
|
2905 |
-
{ part = order[index - 1] }
|
2906 |
-
}
|
2907 |
-
return part
|
2908 |
-
}
|
2909 |
-
|
2910 |
-
function coordsBidiPartWrapped(cm, lineObj, _lineNo, preparedMeasure, order, x, y) {
|
2911 |
-
// In a wrapped line, rtl text on wrapping boundaries can do things
|
2912 |
-
// that don't correspond to the ordering in our `order` array at
|
2913 |
-
// all, so a binary search doesn't work, and we want to return a
|
2914 |
-
// part that only spans one line so that the binary search in
|
2915 |
-
// coordsCharInner is safe. As such, we first find the extent of the
|
2916 |
-
// wrapped line, and then do a flat search in which we discard any
|
2917 |
-
// spans that aren't on the line.
|
2918 |
-
var ref = wrappedLineExtent(cm, lineObj, preparedMeasure, y);
|
2919 |
-
var begin = ref.begin;
|
2920 |
-
var end = ref.end;
|
2921 |
-
if (/\s/.test(lineObj.text.charAt(end - 1))) { end-- }
|
2922 |
-
var part = null, closestDist = null
|
2923 |
-
for (var i = 0; i < order.length; i++) {
|
2924 |
-
var p = order[i]
|
2925 |
-
if (p.from >= end || p.to <= begin) { continue }
|
2926 |
-
var ltr = p.level != 1
|
2927 |
-
var endX = measureCharPrepared(cm, preparedMeasure, ltr ? Math.min(end, p.to) - 1 : Math.max(begin, p.from)).right
|
2928 |
-
// Weigh against spans ending before this, so that they are only
|
2929 |
-
// picked if nothing ends after
|
2930 |
-
var dist = endX < x ? x - endX + 1e9 : endX - x
|
2931 |
-
if (!part || closestDist > dist) {
|
2932 |
-
part = p
|
2933 |
-
closestDist = dist
|
2934 |
-
}
|
2935 |
-
}
|
2936 |
-
if (!part) { part = order[order.length - 1] }
|
2937 |
-
// Clip the part to the wrapped line.
|
2938 |
-
if (part.from < begin) { part = {from: begin, to: part.to, level: part.level} }
|
2939 |
-
if (part.to > end) { part = {from: part.from, to: end, level: part.level} }
|
2940 |
-
return part
|
2941 |
-
}
|
2942 |
-
|
2943 |
-
var measureText
|
2944 |
-
// Compute the default text height.
|
2945 |
-
function textHeight(display) {
|
2946 |
-
if (display.cachedTextHeight != null) { return display.cachedTextHeight }
|
2947 |
-
if (measureText == null) {
|
2948 |
-
measureText = elt("pre")
|
2949 |
-
// Measure a bunch of lines, for browsers that compute
|
2950 |
-
// fractional heights.
|
2951 |
-
for (var i = 0; i < 49; ++i) {
|
2952 |
-
measureText.appendChild(document.createTextNode("x"))
|
2953 |
-
measureText.appendChild(elt("br"))
|
2954 |
-
}
|
2955 |
-
measureText.appendChild(document.createTextNode("x"))
|
2956 |
-
}
|
2957 |
-
removeChildrenAndAdd(display.measure, measureText)
|
2958 |
-
var height = measureText.offsetHeight / 50
|
2959 |
-
if (height > 3) { display.cachedTextHeight = height }
|
2960 |
-
removeChildren(display.measure)
|
2961 |
-
return height || 1
|
2962 |
-
}
|
2963 |
-
|
2964 |
-
// Compute the default character width.
|
2965 |
-
function charWidth(display) {
|
2966 |
-
if (display.cachedCharWidth != null) { return display.cachedCharWidth }
|
2967 |
-
var anchor = elt("span", "xxxxxxxxxx")
|
2968 |
-
var pre = elt("pre", [anchor])
|
2969 |
-
removeChildrenAndAdd(display.measure, pre)
|
2970 |
-
var rect = anchor.getBoundingClientRect(), width = (rect.right - rect.left) / 10
|
2971 |
-
if (width > 2) { display.cachedCharWidth = width }
|
2972 |
-
return width || 10
|
2973 |
-
}
|
2974 |
-
|
2975 |
-
// Do a bulk-read of the DOM positions and sizes needed to draw the
|
2976 |
-
// view, so that we don't interleave reading and writing to the DOM.
|
2977 |
-
function getDimensions(cm) {
|
2978 |
-
var d = cm.display, left = {}, width = {}
|
2979 |
-
var gutterLeft = d.gutters.clientLeft
|
2980 |
-
for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) {
|
2981 |
-
left[cm.options.gutters[i]] = n.offsetLeft + n.clientLeft + gutterLeft
|
2982 |
-
width[cm.options.gutters[i]] = n.clientWidth
|
2983 |
-
}
|
2984 |
-
return {fixedPos: compensateForHScroll(d),
|
2985 |
-
gutterTotalWidth: d.gutters.offsetWidth,
|
2986 |
-
gutterLeft: left,
|
2987 |
-
gutterWidth: width,
|
2988 |
-
wrapperWidth: d.wrapper.clientWidth}
|
2989 |
-
}
|
2990 |
-
|
2991 |
-
// Computes display.scroller.scrollLeft + display.gutters.offsetWidth,
|
2992 |
-
// but using getBoundingClientRect to get a sub-pixel-accurate
|
2993 |
-
// result.
|
2994 |
-
function compensateForHScroll(display) {
|
2995 |
-
return display.scroller.getBoundingClientRect().left - display.sizer.getBoundingClientRect().left
|
2996 |
-
}
|
2997 |
-
|
2998 |
-
// Returns a function that estimates the height of a line, to use as
|
2999 |
-
// first approximation until the line becomes visible (and is thus
|
3000 |
-
// properly measurable).
|
3001 |
-
function estimateHeight(cm) {
|
3002 |
-
var th = textHeight(cm.display), wrapping = cm.options.lineWrapping
|
3003 |
-
var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3)
|
3004 |
-
return function (line) {
|
3005 |
-
if (lineIsHidden(cm.doc, line)) { return 0 }
|
3006 |
-
|
3007 |
-
var widgetsHeight = 0
|
3008 |
-
if (line.widgets) { for (var i = 0; i < line.widgets.length; i++) {
|
3009 |
-
if (line.widgets[i].height) { widgetsHeight += line.widgets[i].height }
|
3010 |
-
} }
|
3011 |
-
|
3012 |
-
if (wrapping)
|
3013 |
-
{ return widgetsHeight + (Math.ceil(line.text.length / perLine) || 1) * th }
|
3014 |
-
else
|
3015 |
-
{ return widgetsHeight + th }
|
3016 |
-
}
|
3017 |
-
}
|
3018 |
-
|
3019 |
-
function estimateLineHeights(cm) {
|
3020 |
-
var doc = cm.doc, est = estimateHeight(cm)
|
3021 |
-
doc.iter(function (line) {
|
3022 |
-
var estHeight = est(line)
|
3023 |
-
if (estHeight != line.height) { updateLineHeight(line, estHeight) }
|
3024 |
-
})
|
3025 |
-
}
|
3026 |
-
|
3027 |
-
// Given a mouse event, find the corresponding position. If liberal
|
3028 |
-
// is false, it checks whether a gutter or scrollbar was clicked,
|
3029 |
-
// and returns null if it was. forRect is used by rectangular
|
3030 |
-
// selections, and tries to estimate a character position even for
|
3031 |
-
// coordinates beyond the right of the text.
|
3032 |
-
function posFromMouse(cm, e, liberal, forRect) {
|
3033 |
-
var display = cm.display
|
3034 |
-
if (!liberal && e_target(e).getAttribute("cm-not-content") == "true") { return null }
|
3035 |
-
|
3036 |
-
var x, y, space = display.lineSpace.getBoundingClientRect()
|
3037 |
-
// Fails unpredictably on IE[67] when mouse is dragged around quickly.
|
3038 |
-
try { x = e.clientX - space.left; y = e.clientY - space.top }
|
3039 |
-
catch (e) { return null }
|
3040 |
-
var coords = coordsChar(cm, x, y), line
|
3041 |
-
if (forRect && coords.xRel == 1 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) {
|
3042 |
-
var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length
|
3043 |
-
coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff))
|
3044 |
-
}
|
3045 |
-
return coords
|
3046 |
-
}
|
3047 |
-
|
3048 |
-
// Find the view element corresponding to a given line. Return null
|
3049 |
-
// when the line isn't visible.
|
3050 |
-
function findViewIndex(cm, n) {
|
3051 |
-
if (n >= cm.display.viewTo) { return null }
|
3052 |
-
n -= cm.display.viewFrom
|
3053 |
-
if (n < 0) { return null }
|
3054 |
-
var view = cm.display.view
|
3055 |
-
for (var i = 0; i < view.length; i++) {
|
3056 |
-
n -= view[i].size
|
3057 |
-
if (n < 0) { return i }
|
3058 |
-
}
|
3059 |
-
}
|
3060 |
-
|
3061 |
-
function updateSelection(cm) {
|
3062 |
-
cm.display.input.showSelection(cm.display.input.prepareSelection())
|
3063 |
-
}
|
3064 |
-
|
3065 |
-
function prepareSelection(cm, primary) {
|
3066 |
-
if ( primary === void 0 ) primary = true;
|
3067 |
-
|
3068 |
-
var doc = cm.doc, result = {}
|
3069 |
-
var curFragment = result.cursors = document.createDocumentFragment()
|
3070 |
-
var selFragment = result.selection = document.createDocumentFragment()
|
3071 |
-
|
3072 |
-
for (var i = 0; i < doc.sel.ranges.length; i++) {
|
3073 |
-
if (!primary && i == doc.sel.primIndex) { continue }
|
3074 |
-
var range = doc.sel.ranges[i]
|
3075 |
-
if (range.from().line >= cm.display.viewTo || range.to().line < cm.display.viewFrom) { continue }
|
3076 |
-
var collapsed = range.empty()
|
3077 |
-
if (collapsed || cm.options.showCursorWhenSelecting)
|
3078 |
-
{ drawSelectionCursor(cm, range.head, curFragment) }
|
3079 |
-
if (!collapsed)
|
3080 |
-
{ drawSelectionRange(cm, range, selFragment) }
|
3081 |
-
}
|
3082 |
-
return result
|
3083 |
-
}
|
3084 |
-
|
3085 |
-
// Draws a cursor for the given range
|
3086 |
-
function drawSelectionCursor(cm, head, output) {
|
3087 |
-
var pos = cursorCoords(cm, head, "div", null, null, !cm.options.singleCursorHeightPerLine)
|
3088 |
-
|
3089 |
-
var cursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor"))
|
3090 |
-
cursor.style.left = pos.left + "px"
|
3091 |
-
cursor.style.top = pos.top + "px"
|
3092 |
-
cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px"
|
3093 |
-
|
3094 |
-
if (pos.other) {
|
3095 |
-
// Secondary cursor, shown when on a 'jump' in bi-directional text
|
3096 |
-
var otherCursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor"))
|
3097 |
-
otherCursor.style.display = ""
|
3098 |
-
otherCursor.style.left = pos.other.left + "px"
|
3099 |
-
otherCursor.style.top = pos.other.top + "px"
|
3100 |
-
otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px"
|
3101 |
-
}
|
3102 |
-
}
|
3103 |
-
|
3104 |
-
function cmpCoords(a, b) { return a.top - b.top || a.left - b.left }
|
3105 |
-
|
3106 |
-
// Draws the given range as a highlighted selection
|
3107 |
-
function drawSelectionRange(cm, range, output) {
|
3108 |
-
var display = cm.display, doc = cm.doc
|
3109 |
-
var fragment = document.createDocumentFragment()
|
3110 |
-
var padding = paddingH(cm.display), leftSide = padding.left
|
3111 |
-
var rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right
|
3112 |
-
var docLTR = doc.direction == "ltr"
|
3113 |
-
|
3114 |
-
function add(left, top, width, bottom) {
|
3115 |
-
if (top < 0) { top = 0 }
|
3116 |
-
top = Math.round(top)
|
3117 |
-
bottom = Math.round(bottom)
|
3118 |
-
fragment.appendChild(elt("div", null, "CodeMirror-selected", ("position: absolute; left: " + left + "px;\n top: " + top + "px; width: " + (width == null ? rightSide - left : width) + "px;\n height: " + (bottom - top) + "px")))
|
3119 |
-
}
|
3120 |
-
|
3121 |
-
function drawForLine(line, fromArg, toArg) {
|
3122 |
-
var lineObj = getLine(doc, line)
|
3123 |
-
var lineLen = lineObj.text.length
|
3124 |
-
var start, end
|
3125 |
-
function coords(ch, bias) {
|
3126 |
-
return charCoords(cm, Pos(line, ch), "div", lineObj, bias)
|
3127 |
-
}
|
3128 |
-
|
3129 |
-
function wrapX(pos, dir, side) {
|
3130 |
-
var extent = wrappedLineExtentChar(cm, lineObj, null, pos)
|
3131 |
-
var prop = (dir == "ltr") == (side == "after") ? "left" : "right"
|
3132 |
-
var ch = side == "after" ? extent.begin : extent.end - (/\s/.test(lineObj.text.charAt(extent.end - 1)) ? 2 : 1)
|
3133 |
-
return coords(ch, prop)[prop]
|
3134 |
-
}
|
3135 |
-
|
3136 |
-
var order = getOrder(lineObj, doc.direction)
|
3137 |
-
iterateBidiSections(order, fromArg || 0, toArg == null ? lineLen : toArg, function (from, to, dir, i) {
|
3138 |
-
var ltr = dir == "ltr"
|
3139 |
-
var fromPos = coords(from, ltr ? "left" : "right")
|
3140 |
-
var toPos = coords(to - 1, ltr ? "right" : "left")
|
3141 |
-
|
3142 |
-
var openStart = fromArg == null && from == 0, openEnd = toArg == null && to == lineLen
|
3143 |
-
var first = i == 0, last = !order || i == order.length - 1
|
3144 |
-
if (toPos.top - fromPos.top <= 3) { // Single line
|
3145 |
-
var openLeft = (docLTR ? openStart : openEnd) && first
|
3146 |
-
var openRight = (docLTR ? openEnd : openStart) && last
|
3147 |
-
var left = openLeft ? leftSide : (ltr ? fromPos : toPos).left
|
3148 |
-
var right = openRight ? rightSide : (ltr ? toPos : fromPos).right
|
3149 |
-
add(left, fromPos.top, right - left, fromPos.bottom)
|
3150 |
-
} else { // Multiple lines
|
3151 |
-
var topLeft, topRight, botLeft, botRight
|
3152 |
-
if (ltr) {
|
3153 |
-
topLeft = docLTR && openStart && first ? leftSide : fromPos.left
|
3154 |
-
topRight = docLTR ? rightSide : wrapX(from, dir, "before")
|
3155 |
-
botLeft = docLTR ? leftSide : wrapX(to, dir, "after")
|
3156 |
-
botRight = docLTR && openEnd && last ? rightSide : toPos.right
|
3157 |
-
} else {
|
3158 |
-
topLeft = !docLTR ? leftSide : wrapX(from, dir, "before")
|
3159 |
-
topRight = !docLTR && openStart && first ? rightSide : fromPos.right
|
3160 |
-
botLeft = !docLTR && openEnd && last ? leftSide : toPos.left
|
3161 |
-
botRight = !docLTR ? rightSide : wrapX(to, dir, "after")
|
3162 |
-
}
|
3163 |
-
add(topLeft, fromPos.top, topRight - topLeft, fromPos.bottom)
|
3164 |
-
if (fromPos.bottom < toPos.top) { add(leftSide, fromPos.bottom, null, toPos.top) }
|
3165 |
-
add(botLeft, toPos.top, botRight - botLeft, toPos.bottom)
|
3166 |
-
}
|
3167 |
-
|
3168 |
-
if (!start || cmpCoords(fromPos, start) < 0) { start = fromPos }
|
3169 |
-
if (cmpCoords(toPos, start) < 0) { start = toPos }
|
3170 |
-
if (!end || cmpCoords(fromPos, end) < 0) { end = fromPos }
|
3171 |
-
if (cmpCoords(toPos, end) < 0) { end = toPos }
|
3172 |
-
})
|
3173 |
-
return {start: start, end: end}
|
3174 |
-
}
|
3175 |
-
|
3176 |
-
var sFrom = range.from(), sTo = range.to()
|
3177 |
-
if (sFrom.line == sTo.line) {
|
3178 |
-
drawForLine(sFrom.line, sFrom.ch, sTo.ch)
|
3179 |
-
} else {
|
3180 |
-
var fromLine = getLine(doc, sFrom.line), toLine = getLine(doc, sTo.line)
|
3181 |
-
var singleVLine = visualLine(fromLine) == visualLine(toLine)
|
3182 |
-
var leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end
|
3183 |
-
var rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start
|
3184 |
-
if (singleVLine) {
|
3185 |
-
if (leftEnd.top < rightStart.top - 2) {
|
3186 |
-
add(leftEnd.right, leftEnd.top, null, leftEnd.bottom)
|
3187 |
-
add(leftSide, rightStart.top, rightStart.left, rightStart.bottom)
|
3188 |
-
} else {
|
3189 |
-
add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom)
|
3190 |
-
}
|
3191 |
-
}
|
3192 |
-
if (leftEnd.bottom < rightStart.top)
|
3193 |
-
{ add(leftSide, leftEnd.bottom, null, rightStart.top) }
|
3194 |
-
}
|
3195 |
-
|
3196 |
-
output.appendChild(fragment)
|
3197 |
-
}
|
3198 |
-
|
3199 |
-
// Cursor-blinking
|
3200 |
-
function restartBlink(cm) {
|
3201 |
-
if (!cm.state.focused) { return }
|
3202 |
-
var display = cm.display
|
3203 |
-
clearInterval(display.blinker)
|
3204 |
-
var on = true
|
3205 |
-
display.cursorDiv.style.visibility = ""
|
3206 |
-
if (cm.options.cursorBlinkRate > 0)
|
3207 |
-
{ display.blinker = setInterval(function () { return display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden"; },
|
3208 |
-
cm.options.cursorBlinkRate) }
|
3209 |
-
else if (cm.options.cursorBlinkRate < 0)
|
3210 |
-
{ display.cursorDiv.style.visibility = "hidden" }
|
3211 |
-
}
|
3212 |
-
|
3213 |
-
function ensureFocus(cm) {
|
3214 |
-
if (!cm.state.focused) { cm.display.input.focus(); onFocus(cm) }
|
3215 |
-
}
|
3216 |
-
|
3217 |
-
function delayBlurEvent(cm) {
|
3218 |
-
cm.state.delayingBlurEvent = true
|
3219 |
-
setTimeout(function () { if (cm.state.delayingBlurEvent) {
|
3220 |
-
cm.state.delayingBlurEvent = false
|
3221 |
-
onBlur(cm)
|
3222 |
-
} }, 100)
|
3223 |
-
}
|
3224 |
-
|
3225 |
-
function onFocus(cm, e) {
|
3226 |
-
if (cm.state.delayingBlurEvent) { cm.state.delayingBlurEvent = false }
|
3227 |
-
|
3228 |
-
if (cm.options.readOnly == "nocursor") { return }
|
3229 |
-
if (!cm.state.focused) {
|
3230 |
-
signal(cm, "focus", cm, e)
|
3231 |
-
cm.state.focused = true
|
3232 |
-
addClass(cm.display.wrapper, "CodeMirror-focused")
|
3233 |
-
// This test prevents this from firing when a context
|
3234 |
-
// menu is closed (since the input reset would kill the
|
3235 |
-
// select-all detection hack)
|
3236 |
-
if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) {
|
3237 |
-
cm.display.input.reset()
|
3238 |
-
if (webkit) { setTimeout(function () { return cm.display.input.reset(true); }, 20) } // Issue #1730
|
3239 |
-
}
|
3240 |
-
cm.display.input.receivedFocus()
|
3241 |
-
}
|
3242 |
-
restartBlink(cm)
|
3243 |
-
}
|
3244 |
-
function onBlur(cm, e) {
|
3245 |
-
if (cm.state.delayingBlurEvent) { return }
|
3246 |
-
|
3247 |
-
if (cm.state.focused) {
|
3248 |
-
signal(cm, "blur", cm, e)
|
3249 |
-
cm.state.focused = false
|
3250 |
-
rmClass(cm.display.wrapper, "CodeMirror-focused")
|
3251 |
-
}
|
3252 |
-
clearInterval(cm.display.blinker)
|
3253 |
-
setTimeout(function () { if (!cm.state.focused) { cm.display.shift = false } }, 150)
|
3254 |
-
}
|
3255 |
-
|
3256 |
-
// Read the actual heights of the rendered lines, and update their
|
3257 |
-
// stored heights to match.
|
3258 |
-
function updateHeightsInViewport(cm) {
|
3259 |
-
var display = cm.display
|
3260 |
-
var prevBottom = display.lineDiv.offsetTop
|
3261 |
-
for (var i = 0; i < display.view.length; i++) {
|
3262 |
-
var cur = display.view[i], height = (void 0)
|
3263 |
-
if (cur.hidden) { continue }
|
3264 |
-
if (ie && ie_version < 8) {
|
3265 |
-
var bot = cur.node.offsetTop + cur.node.offsetHeight
|
3266 |
-
height = bot - prevBottom
|
3267 |
-
prevBottom = bot
|
3268 |
-
} else {
|
3269 |
-
var box = cur.node.getBoundingClientRect()
|
3270 |
-
height = box.bottom - box.top
|
3271 |
-
}
|
3272 |
-
var diff = cur.line.height - height
|
3273 |
-
if (height < 2) { height = textHeight(display) }
|
3274 |
-
if (diff > .005 || diff < -.005) {
|
3275 |
-
updateLineHeight(cur.line, height)
|
3276 |
-
updateWidgetHeight(cur.line)
|
3277 |
-
if (cur.rest) { for (var j = 0; j < cur.rest.length; j++)
|
3278 |
-
{ updateWidgetHeight(cur.rest[j]) } }
|
3279 |
-
}
|
3280 |
-
}
|
3281 |
-
}
|
3282 |
-
|
3283 |
-
// Read and store the height of line widgets associated with the
|
3284 |
-
// given line.
|
3285 |
-
function updateWidgetHeight(line) {
|
3286 |
-
if (line.widgets) { for (var i = 0; i < line.widgets.length; ++i) {
|
3287 |
-
var w = line.widgets[i], parent = w.node.parentNode
|
3288 |
-
if (parent) { w.height = parent.offsetHeight }
|
3289 |
-
} }
|
3290 |
-
}
|
3291 |
-
|
3292 |
-
// Compute the lines that are visible in a given viewport (defaults
|
3293 |
-
// the the current scroll position). viewport may contain top,
|
3294 |
-
// height, and ensure (see op.scrollToPos) properties.
|
3295 |
-
function visibleLines(display, doc, viewport) {
|
3296 |
-
var top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop
|
3297 |
-
top = Math.floor(top - paddingTop(display))
|
3298 |
-
var bottom = viewport && viewport.bottom != null ? viewport.bottom : top + display.wrapper.clientHeight
|
3299 |
-
|
3300 |
-
var from = lineAtHeight(doc, top), to = lineAtHeight(doc, bottom)
|
3301 |
-
// Ensure is a {from: {line, ch}, to: {line, ch}} object, and
|
3302 |
-
// forces those lines into the viewport (if possible).
|
3303 |
-
if (viewport && viewport.ensure) {
|
3304 |
-
var ensureFrom = viewport.ensure.from.line, ensureTo = viewport.ensure.to.line
|
3305 |
-
if (ensureFrom < from) {
|
3306 |
-
from = ensureFrom
|
3307 |
-
to = lineAtHeight(doc, heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight)
|
3308 |
-
} else if (Math.min(ensureTo, doc.lastLine()) >= to) {
|
3309 |
-
from = lineAtHeight(doc, heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight)
|
3310 |
-
to = ensureTo
|
3311 |
-
}
|
3312 |
-
}
|
3313 |
-
return {from: from, to: Math.max(to, from + 1)}
|
3314 |
-
}
|
3315 |
-
|
3316 |
-
// Re-align line numbers and gutter marks to compensate for
|
3317 |
-
// horizontal scrolling.
|
3318 |
-
function alignHorizontally(cm) {
|
3319 |
-
var display = cm.display, view = display.view
|
3320 |
-
if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) { return }
|
3321 |
-
var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft
|
3322 |
-
var gutterW = display.gutters.offsetWidth, left = comp + "px"
|
3323 |
-
for (var i = 0; i < view.length; i++) { if (!view[i].hidden) {
|
3324 |
-
if (cm.options.fixedGutter) {
|
3325 |
-
if (view[i].gutter)
|
3326 |
-
{ view[i].gutter.style.left = left }
|
3327 |
-
if (view[i].gutterBackground)
|
3328 |
-
{ view[i].gutterBackground.style.left = left }
|
3329 |
-
}
|
3330 |
-
var align = view[i].alignable
|
3331 |
-
if (align) { for (var j = 0; j < align.length; j++)
|
3332 |
-
{ align[j].style.left = left } }
|
3333 |
-
} }
|
3334 |
-
if (cm.options.fixedGutter)
|
3335 |
-
{ display.gutters.style.left = (comp + gutterW) + "px" }
|
3336 |
-
}
|
3337 |
-
|
3338 |
-
// Used to ensure that the line number gutter is still the right
|
3339 |
-
// size for the current document size. Returns true when an update
|
3340 |
-
// is needed.
|
3341 |
-
function maybeUpdateLineNumberWidth(cm) {
|
3342 |
-
if (!cm.options.lineNumbers) { return false }
|
3343 |
-
var doc = cm.doc, last = lineNumberFor(cm.options, doc.first + doc.size - 1), display = cm.display
|
3344 |
-
if (last.length != display.lineNumChars) {
|
3345 |
-
var test = display.measure.appendChild(elt("div", [elt("div", last)],
|
3346 |
-
"CodeMirror-linenumber CodeMirror-gutter-elt"))
|
3347 |
-
var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW
|
3348 |
-
display.lineGutter.style.width = ""
|
3349 |
-
display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding) + 1
|
3350 |
-
display.lineNumWidth = display.lineNumInnerWidth + padding
|
3351 |
-
display.lineNumChars = display.lineNumInnerWidth ? last.length : -1
|
3352 |
-
display.lineGutter.style.width = display.lineNumWidth + "px"
|
3353 |
-
updateGutterSpace(cm)
|
3354 |
-
return true
|
3355 |
-
}
|
3356 |
-
return false
|
3357 |
-
}
|
3358 |
-
|
3359 |
-
// SCROLLING THINGS INTO VIEW
|
3360 |
-
|
3361 |
-
// If an editor sits on the top or bottom of the window, partially
|
3362 |
-
// scrolled out of view, this ensures that the cursor is visible.
|
3363 |
-
function maybeScrollWindow(cm, rect) {
|
3364 |
-
if (signalDOMEvent(cm, "scrollCursorIntoView")) { return }
|
3365 |
-
|
3366 |
-
var display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null
|
3367 |
-
if (rect.top + box.top < 0) { doScroll = true }
|
3368 |
-
else if (rect.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) { doScroll = false }
|
3369 |
-
if (doScroll != null && !phantom) {
|
3370 |
-
var scrollNode = elt("div", "\u200b", null, ("position: absolute;\n top: " + (rect.top - display.viewOffset - paddingTop(cm.display)) + "px;\n height: " + (rect.bottom - rect.top + scrollGap(cm) + display.barHeight) + "px;\n left: " + (rect.left) + "px; width: " + (Math.max(2, rect.right - rect.left)) + "px;"))
|
3371 |
-
cm.display.lineSpace.appendChild(scrollNode)
|
3372 |
-
scrollNode.scrollIntoView(doScroll)
|
3373 |
-
cm.display.lineSpace.removeChild(scrollNode)
|
3374 |
-
}
|
3375 |
-
}
|
3376 |
-
|
3377 |
-
// Scroll a given position into view (immediately), verifying that
|
3378 |
-
// it actually became visible (as line heights are accurately
|
3379 |
-
// measured, the position of something may 'drift' during drawing).
|
3380 |
-
function scrollPosIntoView(cm, pos, end, margin) {
|
3381 |
-
if (margin == null) { margin = 0 }
|
3382 |
-
var rect
|
3383 |
-
if (!cm.options.lineWrapping && pos == end) {
|
3384 |
-
// Set pos and end to the cursor positions around the character pos sticks to
|
3385 |
-
// If pos.sticky == "before", that is around pos.ch - 1, otherwise around pos.ch
|
3386 |
-
// If pos == Pos(_, 0, "before"), pos and end are unchanged
|
3387 |
-
pos = pos.ch ? Pos(pos.line, pos.sticky == "before" ? pos.ch - 1 : pos.ch, "after") : pos
|
3388 |
-
end = pos.sticky == "before" ? Pos(pos.line, pos.ch + 1, "before") : pos
|
3389 |
-
}
|
3390 |
-
for (var limit = 0; limit < 5; limit++) {
|
3391 |
-
var changed = false
|
3392 |
-
var coords = cursorCoords(cm, pos)
|
3393 |
-
var endCoords = !end || end == pos ? coords : cursorCoords(cm, end)
|
3394 |
-
rect = {left: Math.min(coords.left, endCoords.left),
|
3395 |
-
top: Math.min(coords.top, endCoords.top) - margin,
|
3396 |
-
right: Math.max(coords.left, endCoords.left),
|
3397 |
-
bottom: Math.max(coords.bottom, endCoords.bottom) + margin}
|
3398 |
-
var scrollPos = calculateScrollPos(cm, rect)
|
3399 |
-
var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft
|
3400 |
-
if (scrollPos.scrollTop != null) {
|
3401 |
-
updateScrollTop(cm, scrollPos.scrollTop)
|
3402 |
-
if (Math.abs(cm.doc.scrollTop - startTop) > 1) { changed = true }
|
3403 |
-
}
|
3404 |
-
if (scrollPos.scrollLeft != null) {
|
3405 |
-
setScrollLeft(cm, scrollPos.scrollLeft)
|
3406 |
-
if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) { changed = true }
|
3407 |
-
}
|
3408 |
-
if (!changed) { break }
|
3409 |
-
}
|
3410 |
-
return rect
|
3411 |
-
}
|
3412 |
-
|
3413 |
-
// Scroll a given set of coordinates into view (immediately).
|
3414 |
-
function scrollIntoView(cm, rect) {
|
3415 |
-
var scrollPos = calculateScrollPos(cm, rect)
|
3416 |
-
if (scrollPos.scrollTop != null) { updateScrollTop(cm, scrollPos.scrollTop) }
|
3417 |
-
if (scrollPos.scrollLeft != null) { setScrollLeft(cm, scrollPos.scrollLeft) }
|
3418 |
-
}
|
3419 |
-
|
3420 |
-
// Calculate a new scroll position needed to scroll the given
|
3421 |
-
// rectangle into view. Returns an object with scrollTop and
|
3422 |
-
// scrollLeft properties. When these are undefined, the
|
3423 |
-
// vertical/horizontal position does not need to be adjusted.
|
3424 |
-
function calculateScrollPos(cm, rect) {
|
3425 |
-
var display = cm.display, snapMargin = textHeight(cm.display)
|
3426 |
-
if (rect.top < 0) { rect.top = 0 }
|
3427 |
-
var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop
|
3428 |
-
var screen = displayHeight(cm), result = {}
|
3429 |
-
if (rect.bottom - rect.top > screen) { rect.bottom = rect.top + screen }
|
3430 |
-
var docBottom = cm.doc.height + paddingVert(display)
|
3431 |
-
var atTop = rect.top < snapMargin, atBottom = rect.bottom > docBottom - snapMargin
|
3432 |
-
if (rect.top < screentop) {
|
3433 |
-
result.scrollTop = atTop ? 0 : rect.top
|
3434 |
-
} else if (rect.bottom > screentop + screen) {
|
3435 |
-
var newTop = Math.min(rect.top, (atBottom ? docBottom : rect.bottom) - screen)
|
3436 |
-
if (newTop != screentop) { result.scrollTop = newTop }
|
3437 |
-
}
|
3438 |
-
|
3439 |
-
var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft
|
3440 |
-
var screenw = displayWidth(cm) - (cm.options.fixedGutter ? display.gutters.offsetWidth : 0)
|
3441 |
-
var tooWide = rect.right - rect.left > screenw
|
3442 |
-
if (tooWide) { rect.right = rect.left + screenw }
|
3443 |
-
if (rect.left < 10)
|
3444 |
-
{ result.scrollLeft = 0 }
|
3445 |
-
else if (rect.left < screenleft)
|
3446 |
-
{ result.scrollLeft = Math.max(0, rect.left - (tooWide ? 0 : 10)) }
|
3447 |
-
else if (rect.right > screenw + screenleft - 3)
|
3448 |
-
{ result.scrollLeft = rect.right + (tooWide ? 0 : 10) - screenw }
|
3449 |
-
return result
|
3450 |
-
}
|
3451 |
-
|
3452 |
-
// Store a relative adjustment to the scroll position in the current
|
3453 |
-
// operation (to be applied when the operation finishes).
|
3454 |
-
function addToScrollTop(cm, top) {
|
3455 |
-
if (top == null) { return }
|
3456 |
-
resolveScrollToPos(cm)
|
3457 |
-
cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top
|
3458 |
-
}
|
3459 |
-
|
3460 |
-
// Make sure that at the end of the operation the current cursor is
|
3461 |
-
// shown.
|
3462 |
-
function ensureCursorVisible(cm) {
|
3463 |
-
resolveScrollToPos(cm)
|
3464 |
-
var cur = cm.getCursor()
|
3465 |
-
cm.curOp.scrollToPos = {from: cur, to: cur, margin: cm.options.cursorScrollMargin}
|
3466 |
-
}
|
3467 |
-
|
3468 |
-
function scrollToCoords(cm, x, y) {
|
3469 |
-
if (x != null || y != null) { resolveScrollToPos(cm) }
|
3470 |
-
if (x != null) { cm.curOp.scrollLeft = x }
|
3471 |
-
if (y != null) { cm.curOp.scrollTop = y }
|
3472 |
-
}
|
3473 |
-
|
3474 |
-
function scrollToRange(cm, range) {
|
3475 |
-
resolveScrollToPos(cm)
|
3476 |
-
cm.curOp.scrollToPos = range
|
3477 |
-
}
|
3478 |
-
|
3479 |
-
// When an operation has its scrollToPos property set, and another
|
3480 |
-
// scroll action is applied before the end of the operation, this
|
3481 |
-
// 'simulates' scrolling that position into view in a cheap way, so
|
3482 |
-
// that the effect of intermediate scroll commands is not ignored.
|
3483 |
-
function resolveScrollToPos(cm) {
|
3484 |
-
var range = cm.curOp.scrollToPos
|
3485 |
-
if (range) {
|
3486 |
-
cm.curOp.scrollToPos = null
|
3487 |
-
var from = estimateCoords(cm, range.from), to = estimateCoords(cm, range.to)
|
3488 |
-
scrollToCoordsRange(cm, from, to, range.margin)
|
3489 |
-
}
|
3490 |
-
}
|
3491 |
-
|
3492 |
-
function scrollToCoordsRange(cm, from, to, margin) {
|
3493 |
-
var sPos = calculateScrollPos(cm, {
|
3494 |
-
left: Math.min(from.left, to.left),
|
3495 |
-
top: Math.min(from.top, to.top) - margin,
|
3496 |
-
right: Math.max(from.right, to.right),
|
3497 |
-
bottom: Math.max(from.bottom, to.bottom) + margin
|
3498 |
-
})
|
3499 |
-
scrollToCoords(cm, sPos.scrollLeft, sPos.scrollTop)
|
3500 |
-
}
|
3501 |
-
|
3502 |
-
// Sync the scrollable area and scrollbars, ensure the viewport
|
3503 |
-
// covers the visible area.
|
3504 |
-
function updateScrollTop(cm, val) {
|
3505 |
-
if (Math.abs(cm.doc.scrollTop - val) < 2) { return }
|
3506 |
-
if (!gecko) { updateDisplaySimple(cm, {top: val}) }
|
3507 |
-
setScrollTop(cm, val, true)
|
3508 |
-
if (gecko) { updateDisplaySimple(cm) }
|
3509 |
-
startWorker(cm, 100)
|
3510 |
-
}
|
3511 |
-
|
3512 |
-
function setScrollTop(cm, val, forceScroll) {
|
3513 |
-
val = Math.min(cm.display.scroller.scrollHeight - cm.display.scroller.clientHeight, val)
|
3514 |
-
if (cm.display.scroller.scrollTop == val && !forceScroll) { return }
|
3515 |
-
cm.doc.scrollTop = val
|
3516 |
-
cm.display.scrollbars.setScrollTop(val)
|
3517 |
-
if (cm.display.scroller.scrollTop != val) { cm.display.scroller.scrollTop = val }
|
3518 |
-
}
|
3519 |
-
|
3520 |
-
// Sync scroller and scrollbar, ensure the gutter elements are
|
3521 |
-
// aligned.
|
3522 |
-
function setScrollLeft(cm, val, isScroller, forceScroll) {
|
3523 |
-
val = Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth)
|
3524 |
-
if ((isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) && !forceScroll) { return }
|
3525 |
-
cm.doc.scrollLeft = val
|
3526 |
-
alignHorizontally(cm)
|
3527 |
-
if (cm.display.scroller.scrollLeft != val) { cm.display.scroller.scrollLeft = val }
|
3528 |
-
cm.display.scrollbars.setScrollLeft(val)
|
3529 |
-
}
|
3530 |
-
|
3531 |
-
// SCROLLBARS
|
3532 |
-
|
3533 |
-
// Prepare DOM reads needed to update the scrollbars. Done in one
|
3534 |
-
// shot to minimize update/measure roundtrips.
|
3535 |
-
function measureForScrollbars(cm) {
|
3536 |
-
var d = cm.display, gutterW = d.gutters.offsetWidth
|
3537 |
-
var docH = Math.round(cm.doc.height + paddingVert(cm.display))
|
3538 |
-
return {
|
3539 |
-
clientHeight: d.scroller.clientHeight,
|
3540 |
-
viewHeight: d.wrapper.clientHeight,
|
3541 |
-
scrollWidth: d.scroller.scrollWidth, clientWidth: d.scroller.clientWidth,
|
3542 |
-
viewWidth: d.wrapper.clientWidth,
|
3543 |
-
barLeft: cm.options.fixedGutter ? gutterW : 0,
|
3544 |
-
docHeight: docH,
|
3545 |
-
scrollHeight: docH + scrollGap(cm) + d.barHeight,
|
3546 |
-
nativeBarWidth: d.nativeBarWidth,
|
3547 |
-
gutterWidth: gutterW
|
3548 |
-
}
|
3549 |
-
}
|
3550 |
-
|
3551 |
-
var NativeScrollbars = function(place, scroll, cm) {
|
3552 |
-
this.cm = cm
|
3553 |
-
var vert = this.vert = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar")
|
3554 |
-
var horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar")
|
3555 |
-
vert.tabIndex = horiz.tabIndex = -1
|
3556 |
-
place(vert); place(horiz)
|
3557 |
-
|
3558 |
-
on(vert, "scroll", function () {
|
3559 |
-
if (vert.clientHeight) { scroll(vert.scrollTop, "vertical") }
|
3560 |
-
})
|
3561 |
-
on(horiz, "scroll", function () {
|
3562 |
-
if (horiz.clientWidth) { scroll(horiz.scrollLeft, "horizontal") }
|
3563 |
-
})
|
3564 |
-
|
3565 |
-
this.checkedZeroWidth = false
|
3566 |
-
// Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
|
3567 |
-
if (ie && ie_version < 8) { this.horiz.style.minHeight = this.vert.style.minWidth = "18px" }
|
3568 |
-
};
|
3569 |
-
|
3570 |
-
NativeScrollbars.prototype.update = function (measure) {
|
3571 |
-
var needsH = measure.scrollWidth > measure.clientWidth + 1
|
3572 |
-
var needsV = measure.scrollHeight > measure.clientHeight + 1
|
3573 |
-
var sWidth = measure.nativeBarWidth
|
3574 |
-
|
3575 |
-
if (needsV) {
|
3576 |
-
this.vert.style.display = "block"
|
3577 |
-
this.vert.style.bottom = needsH ? sWidth + "px" : "0"
|
3578 |
-
var totalHeight = measure.viewHeight - (needsH ? sWidth : 0)
|
3579 |
-
// A bug in IE8 can cause this value to be negative, so guard it.
|
3580 |
-
this.vert.firstChild.style.height =
|
3581 |
-
Math.max(0, measure.scrollHeight - measure.clientHeight + totalHeight) + "px"
|
3582 |
-
} else {
|
3583 |
-
this.vert.style.display = ""
|
3584 |
-
this.vert.firstChild.style.height = "0"
|
3585 |
-
}
|
3586 |
-
|
3587 |
-
if (needsH) {
|
3588 |
-
this.horiz.style.display = "block"
|
3589 |
-
this.horiz.style.right = needsV ? sWidth + "px" : "0"
|
3590 |
-
this.horiz.style.left = measure.barLeft + "px"
|
3591 |
-
var totalWidth = measure.viewWidth - measure.barLeft - (needsV ? sWidth : 0)
|
3592 |
-
this.horiz.firstChild.style.width =
|
3593 |
-
Math.max(0, measure.scrollWidth - measure.clientWidth + totalWidth) + "px"
|
3594 |
-
} else {
|
3595 |
-
this.horiz.style.display = ""
|
3596 |
-
this.horiz.firstChild.style.width = "0"
|
3597 |
-
}
|
3598 |
-
|
3599 |
-
if (!this.checkedZeroWidth && measure.clientHeight > 0) {
|
3600 |
-
if (sWidth == 0) { this.zeroWidthHack() }
|
3601 |
-
this.checkedZeroWidth = true
|
3602 |
-
}
|
3603 |
-
|
3604 |
-
return {right: needsV ? sWidth : 0, bottom: needsH ? sWidth : 0}
|
3605 |
-
};
|
3606 |
-
|
3607 |
-
NativeScrollbars.prototype.setScrollLeft = function (pos) {
|
3608 |
-
if (this.horiz.scrollLeft != pos) { this.horiz.scrollLeft = pos }
|
3609 |
-
if (this.disableHoriz) { this.enableZeroWidthBar(this.horiz, this.disableHoriz, "horiz") }
|
3610 |
-
};
|
3611 |
-
|
3612 |
-
NativeScrollbars.prototype.setScrollTop = function (pos) {
|
3613 |
-
if (this.vert.scrollTop != pos) { this.vert.scrollTop = pos }
|
3614 |
-
if (this.disableVert) { this.enableZeroWidthBar(this.vert, this.disableVert, "vert") }
|
3615 |
-
};
|
3616 |
-
|
3617 |
-
NativeScrollbars.prototype.zeroWidthHack = function () {
|
3618 |
-
var w = mac && !mac_geMountainLion ? "12px" : "18px"
|
3619 |
-
this.horiz.style.height = this.vert.style.width = w
|
3620 |
-
this.horiz.style.pointerEvents = this.vert.style.pointerEvents = "none"
|
3621 |
-
this.disableHoriz = new Delayed
|
3622 |
-
this.disableVert = new Delayed
|
3623 |
-
};
|
3624 |
-
|
3625 |
-
NativeScrollbars.prototype.enableZeroWidthBar = function (bar, delay, type) {
|
3626 |
-
bar.style.pointerEvents = "auto"
|
3627 |
-
function maybeDisable() {
|
3628 |
-
// To find out whether the scrollbar is still visible, we
|
3629 |
-
// check whether the element under the pixel in the bottom
|
3630 |
-
// right corner of the scrollbar box is the scrollbar box
|
3631 |
-
// itself (when the bar is still visible) or its filler child
|
3632 |
-
// (when the bar is hidden). If it is still visible, we keep
|
3633 |
-
// it enabled, if it's hidden, we disable pointer events.
|
3634 |
-
var box = bar.getBoundingClientRect()
|
3635 |
-
var elt = type == "vert" ? document.elementFromPoint(box.right - 1, (box.top + box.bottom) / 2)
|
3636 |
-
: document.elementFromPoint((box.right + box.left) / 2, box.bottom - 1)
|
3637 |
-
if (elt != bar) { bar.style.pointerEvents = "none" }
|
3638 |
-
else { delay.set(1000, maybeDisable) }
|
3639 |
-
}
|
3640 |
-
delay.set(1000, maybeDisable)
|
3641 |
-
};
|
3642 |
-
|
3643 |
-
NativeScrollbars.prototype.clear = function () {
|
3644 |
-
var parent = this.horiz.parentNode
|
3645 |
-
parent.removeChild(this.horiz)
|
3646 |
-
parent.removeChild(this.vert)
|
3647 |
-
};
|
3648 |
-
|
3649 |
-
var NullScrollbars = function () {};
|
3650 |
-
|
3651 |
-
NullScrollbars.prototype.update = function () { return {bottom: 0, right: 0} };
|
3652 |
-
NullScrollbars.prototype.setScrollLeft = function () {};
|
3653 |
-
NullScrollbars.prototype.setScrollTop = function () {};
|
3654 |
-
NullScrollbars.prototype.clear = function () {};
|
3655 |
-
|
3656 |
-
function updateScrollbars(cm, measure) {
|
3657 |
-
if (!measure) { measure = measureForScrollbars(cm) }
|
3658 |
-
var startWidth = cm.display.barWidth, startHeight = cm.display.barHeight
|
3659 |
-
updateScrollbarsInner(cm, measure)
|
3660 |
-
for (var i = 0; i < 4 && startWidth != cm.display.barWidth || startHeight != cm.display.barHeight; i++) {
|
3661 |
-
if (startWidth != cm.display.barWidth && cm.options.lineWrapping)
|
3662 |
-
{ updateHeightsInViewport(cm) }
|
3663 |
-
updateScrollbarsInner(cm, measureForScrollbars(cm))
|
3664 |
-
startWidth = cm.display.barWidth; startHeight = cm.display.barHeight
|
3665 |
-
}
|
3666 |
-
}
|
3667 |
-
|
3668 |
-
// Re-synchronize the fake scrollbars with the actual size of the
|
3669 |
-
// content.
|
3670 |
-
function updateScrollbarsInner(cm, measure) {
|
3671 |
-
var d = cm.display
|
3672 |
-
var sizes = d.scrollbars.update(measure)
|
3673 |
-
|
3674 |
-
d.sizer.style.paddingRight = (d.barWidth = sizes.right) + "px"
|
3675 |
-
d.sizer.style.paddingBottom = (d.barHeight = sizes.bottom) + "px"
|
3676 |
-
d.heightForcer.style.borderBottom = sizes.bottom + "px solid transparent"
|
3677 |
-
|
3678 |
-
if (sizes.right && sizes.bottom) {
|
3679 |
-
d.scrollbarFiller.style.display = "block"
|
3680 |
-
d.scrollbarFiller.style.height = sizes.bottom + "px"
|
3681 |
-
d.scrollbarFiller.style.width = sizes.right + "px"
|
3682 |
-
} else { d.scrollbarFiller.style.display = "" }
|
3683 |
-
if (sizes.bottom && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) {
|
3684 |
-
d.gutterFiller.style.display = "block"
|
3685 |
-
d.gutterFiller.style.height = sizes.bottom + "px"
|
3686 |
-
d.gutterFiller.style.width = measure.gutterWidth + "px"
|
3687 |
-
} else { d.gutterFiller.style.display = "" }
|
3688 |
-
}
|
3689 |
-
|
3690 |
-
var scrollbarModel = {"native": NativeScrollbars, "null": NullScrollbars}
|
3691 |
-
|
3692 |
-
function initScrollbars(cm) {
|
3693 |
-
if (cm.display.scrollbars) {
|
3694 |
-
cm.display.scrollbars.clear()
|
3695 |
-
if (cm.display.scrollbars.addClass)
|
3696 |
-
{ rmClass(cm.display.wrapper, cm.display.scrollbars.addClass) }
|
3697 |
-
}
|
3698 |
-
|
3699 |
-
cm.display.scrollbars = new scrollbarModel[cm.options.scrollbarStyle](function (node) {
|
3700 |
-
cm.display.wrapper.insertBefore(node, cm.display.scrollbarFiller)
|
3701 |
-
// Prevent clicks in the scrollbars from killing focus
|
3702 |
-
on(node, "mousedown", function () {
|
3703 |
-
if (cm.state.focused) { setTimeout(function () { return cm.display.input.focus(); }, 0) }
|
3704 |
-
})
|
3705 |
-
node.setAttribute("cm-not-content", "true")
|
3706 |
-
}, function (pos, axis) {
|
3707 |
-
if (axis == "horizontal") { setScrollLeft(cm, pos) }
|
3708 |
-
else { updateScrollTop(cm, pos) }
|
3709 |
-
}, cm)
|
3710 |
-
if (cm.display.scrollbars.addClass)
|
3711 |
-
{ addClass(cm.display.wrapper, cm.display.scrollbars.addClass) }
|
3712 |
-
}
|
3713 |
-
|
3714 |
-
// Operations are used to wrap a series of changes to the editor
|
3715 |
-
// state in such a way that each change won't have to update the
|
3716 |
-
// cursor and display (which would be awkward, slow, and
|
3717 |
-
// error-prone). Instead, display updates are batched and then all
|
3718 |
-
// combined and executed at once.
|
3719 |
-
|
3720 |
-
var nextOpId = 0
|
3721 |
-
// Start a new operation.
|
3722 |
-
function startOperation(cm) {
|
3723 |
-
cm.curOp = {
|
3724 |
-
cm: cm,
|
3725 |
-
viewChanged: false, // Flag that indicates that lines might need to be redrawn
|
3726 |
-
startHeight: cm.doc.height, // Used to detect need to update scrollbar
|
3727 |
-
forceUpdate: false, // Used to force a redraw
|
3728 |
-
updateInput: null, // Whether to reset the input textarea
|
3729 |
-
typing: false, // Whether this reset should be careful to leave existing text (for compositing)
|
3730 |
-
changeObjs: null, // Accumulated changes, for firing change events
|
3731 |
-
cursorActivityHandlers: null, // Set of handlers to fire cursorActivity on
|
3732 |
-
cursorActivityCalled: 0, // Tracks which cursorActivity handlers have been called already
|
3733 |
-
selectionChanged: false, // Whether the selection needs to be redrawn
|
3734 |
-
updateMaxLine: false, // Set when the widest line needs to be determined anew
|
3735 |
-
scrollLeft: null, scrollTop: null, // Intermediate scroll position, not pushed to DOM yet
|
3736 |
-
scrollToPos: null, // Used to scroll to a specific position
|
3737 |
-
focus: false,
|
3738 |
-
id: ++nextOpId // Unique ID
|
3739 |
-
}
|
3740 |
-
pushOperation(cm.curOp)
|
3741 |
-
}
|
3742 |
-
|
3743 |
-
// Finish an operation, updating the display and signalling delayed events
|
3744 |
-
function endOperation(cm) {
|
3745 |
-
var op = cm.curOp
|
3746 |
-
finishOperation(op, function (group) {
|
3747 |
-
for (var i = 0; i < group.ops.length; i++)
|
3748 |
-
{ group.ops[i].cm.curOp = null }
|
3749 |
-
endOperations(group)
|
3750 |
-
})
|
3751 |
-
}
|
3752 |
-
|
3753 |
-
// The DOM updates done when an operation finishes are batched so
|
3754 |
-
// that the minimum number of relayouts are required.
|
3755 |
-
function endOperations(group) {
|
3756 |
-
var ops = group.ops
|
3757 |
-
for (var i = 0; i < ops.length; i++) // Read DOM
|
3758 |
-
{ endOperation_R1(ops[i]) }
|
3759 |
-
for (var i$1 = 0; i$1 < ops.length; i$1++) // Write DOM (maybe)
|
3760 |
-
{ endOperation_W1(ops[i$1]) }
|
3761 |
-
for (var i$2 = 0; i$2 < ops.length; i$2++) // Read DOM
|
3762 |
-
{ endOperation_R2(ops[i$2]) }
|
3763 |
-
for (var i$3 = 0; i$3 < ops.length; i$3++) // Write DOM (maybe)
|
3764 |
-
{ endOperation_W2(ops[i$3]) }
|
3765 |
-
for (var i$4 = 0; i$4 < ops.length; i$4++) // Read DOM
|
3766 |
-
{ endOperation_finish(ops[i$4]) }
|
3767 |
-
}
|
3768 |
-
|
3769 |
-
function endOperation_R1(op) {
|
3770 |
-
var cm = op.cm, display = cm.display
|
3771 |
-
maybeClipScrollbars(cm)
|
3772 |
-
if (op.updateMaxLine) { findMaxLine(cm) }
|
3773 |
-
|
3774 |
-
op.mustUpdate = op.viewChanged || op.forceUpdate || op.scrollTop != null ||
|
3775 |
-
op.scrollToPos && (op.scrollToPos.from.line < display.viewFrom ||
|
3776 |
-
op.scrollToPos.to.line >= display.viewTo) ||
|
3777 |
-
display.maxLineChanged && cm.options.lineWrapping
|
3778 |
-
op.update = op.mustUpdate &&
|
3779 |
-
new DisplayUpdate(cm, op.mustUpdate && {top: op.scrollTop, ensure: op.scrollToPos}, op.forceUpdate)
|
3780 |
-
}
|
3781 |
-
|
3782 |
-
function endOperation_W1(op) {
|
3783 |
-
op.updatedDisplay = op.mustUpdate && updateDisplayIfNeeded(op.cm, op.update)
|
3784 |
-
}
|
3785 |
-
|
3786 |
-
function endOperation_R2(op) {
|
3787 |
-
var cm = op.cm, display = cm.display
|
3788 |
-
if (op.updatedDisplay) { updateHeightsInViewport(cm) }
|
3789 |
-
|
3790 |
-
op.barMeasure = measureForScrollbars(cm)
|
3791 |
-
|
3792 |
-
// If the max line changed since it was last measured, measure it,
|
3793 |
-
// and ensure the document's width matches it.
|
3794 |
-
// updateDisplay_W2 will use these properties to do the actual resizing
|
3795 |
-
if (display.maxLineChanged && !cm.options.lineWrapping) {
|
3796 |
-
op.adjustWidthTo = measureChar(cm, display.maxLine, display.maxLine.text.length).left + 3
|
3797 |
-
cm.display.sizerWidth = op.adjustWidthTo
|
3798 |
-
op.barMeasure.scrollWidth =
|
3799 |
-
Math.max(display.scroller.clientWidth, display.sizer.offsetLeft + op.adjustWidthTo + scrollGap(cm) + cm.display.barWidth)
|
3800 |
-
op.maxScrollLeft = Math.max(0, display.sizer.offsetLeft + op.adjustWidthTo - displayWidth(cm))
|
3801 |
-
}
|
3802 |
-
|
3803 |
-
if (op.updatedDisplay || op.selectionChanged)
|
3804 |
-
{ op.preparedSelection = display.input.prepareSelection() }
|
3805 |
-
}
|
3806 |
-
|
3807 |
-
function endOperation_W2(op) {
|
3808 |
-
var cm = op.cm
|
3809 |
-
|
3810 |
-
if (op.adjustWidthTo != null) {
|
3811 |
-
cm.display.sizer.style.minWidth = op.adjustWidthTo + "px"
|
3812 |
-
if (op.maxScrollLeft < cm.doc.scrollLeft)
|
3813 |
-
{ setScrollLeft(cm, Math.min(cm.display.scroller.scrollLeft, op.maxScrollLeft), true) }
|
3814 |
-
cm.display.maxLineChanged = false
|
3815 |
-
}
|
3816 |
-
|
3817 |
-
var takeFocus = op.focus && op.focus == activeElt()
|
3818 |
-
if (op.preparedSelection)
|
3819 |
-
{ cm.display.input.showSelection(op.preparedSelection, takeFocus) }
|
3820 |
-
if (op.updatedDisplay || op.startHeight != cm.doc.height)
|
3821 |
-
{ updateScrollbars(cm, op.barMeasure) }
|
3822 |
-
if (op.updatedDisplay)
|
3823 |
-
{ setDocumentHeight(cm, op.barMeasure) }
|
3824 |
-
|
3825 |
-
if (op.selectionChanged) { restartBlink(cm) }
|
3826 |
-
|
3827 |
-
if (cm.state.focused && op.updateInput)
|
3828 |
-
{ cm.display.input.reset(op.typing) }
|
3829 |
-
if (takeFocus) { ensureFocus(op.cm) }
|
3830 |
-
}
|
3831 |
-
|
3832 |
-
function endOperation_finish(op) {
|
3833 |
-
var cm = op.cm, display = cm.display, doc = cm.doc
|
3834 |
-
|
3835 |
-
if (op.updatedDisplay) { postUpdateDisplay(cm, op.update) }
|
3836 |
-
|
3837 |
-
// Abort mouse wheel delta measurement, when scrolling explicitly
|
3838 |
-
if (display.wheelStartX != null && (op.scrollTop != null || op.scrollLeft != null || op.scrollToPos))
|
3839 |
-
{ display.wheelStartX = display.wheelStartY = null }
|
3840 |
-
|
3841 |
-
// Propagate the scroll position to the actual DOM scroller
|
3842 |
-
if (op.scrollTop != null) { setScrollTop(cm, op.scrollTop, op.forceScroll) }
|
3843 |
-
|
3844 |
-
if (op.scrollLeft != null) { setScrollLeft(cm, op.scrollLeft, true, true) }
|
3845 |
-
// If we need to scroll a specific position into view, do so.
|
3846 |
-
if (op.scrollToPos) {
|
3847 |
-
var rect = scrollPosIntoView(cm, clipPos(doc, op.scrollToPos.from),
|
3848 |
-
clipPos(doc, op.scrollToPos.to), op.scrollToPos.margin)
|
3849 |
-
maybeScrollWindow(cm, rect)
|
3850 |
-
}
|
3851 |
-
|
3852 |
-
// Fire events for markers that are hidden/unidden by editing or
|
3853 |
-
// undoing
|
3854 |
-
var hidden = op.maybeHiddenMarkers, unhidden = op.maybeUnhiddenMarkers
|
3855 |
-
if (hidden) { for (var i = 0; i < hidden.length; ++i)
|
3856 |
-
{ if (!hidden[i].lines.length) { signal(hidden[i], "hide") } } }
|
3857 |
-
if (unhidden) { for (var i$1 = 0; i$1 < unhidden.length; ++i$1)
|
3858 |
-
{ if (unhidden[i$1].lines.length) { signal(unhidden[i$1], "unhide") } } }
|
3859 |
-
|
3860 |
-
if (display.wrapper.offsetHeight)
|
3861 |
-
{ doc.scrollTop = cm.display.scroller.scrollTop }
|
3862 |
-
|
3863 |
-
// Fire change events, and delayed event handlers
|
3864 |
-
if (op.changeObjs)
|
3865 |
-
{ signal(cm, "changes", cm, op.changeObjs) }
|
3866 |
-
if (op.update)
|
3867 |
-
{ op.update.finish() }
|
3868 |
-
}
|
3869 |
-
|
3870 |
-
// Run the given function in an operation
|
3871 |
-
function runInOp(cm, f) {
|
3872 |
-
if (cm.curOp) { return f() }
|
3873 |
-
startOperation(cm)
|
3874 |
-
try { return f() }
|
3875 |
-
finally { endOperation(cm) }
|
3876 |
-
}
|
3877 |
-
// Wraps a function in an operation. Returns the wrapped function.
|
3878 |
-
function operation(cm, f) {
|
3879 |
-
return function() {
|
3880 |
-
if (cm.curOp) { return f.apply(cm, arguments) }
|
3881 |
-
startOperation(cm)
|
3882 |
-
try { return f.apply(cm, arguments) }
|
3883 |
-
finally { endOperation(cm) }
|
3884 |
-
}
|
3885 |
-
}
|
3886 |
-
// Used to add methods to editor and doc instances, wrapping them in
|
3887 |
-
// operations.
|
3888 |
-
function methodOp(f) {
|
3889 |
-
return function() {
|
3890 |
-
if (this.curOp) { return f.apply(this, arguments) }
|
3891 |
-
startOperation(this)
|
3892 |
-
try { return f.apply(this, arguments) }
|
3893 |
-
finally { endOperation(this) }
|
3894 |
-
}
|
3895 |
-
}
|
3896 |
-
function docMethodOp(f) {
|
3897 |
-
return function() {
|
3898 |
-
var cm = this.cm
|
3899 |
-
if (!cm || cm.curOp) { return f.apply(this, arguments) }
|
3900 |
-
startOperation(cm)
|
3901 |
-
try { return f.apply(this, arguments) }
|
3902 |
-
finally { endOperation(cm) }
|
3903 |
-
}
|
3904 |
-
}
|
3905 |
-
|
3906 |
-
// Updates the display.view data structure for a given change to the
|
3907 |
-
// document. From and to are in pre-change coordinates. Lendiff is
|
3908 |
-
// the amount of lines added or subtracted by the change. This is
|
3909 |
-
// used for changes that span multiple lines, or change the way
|
3910 |
-
// lines are divided into visual lines. regLineChange (below)
|
3911 |
-
// registers single-line changes.
|
3912 |
-
function regChange(cm, from, to, lendiff) {
|
3913 |
-
if (from == null) { from = cm.doc.first }
|
3914 |
-
if (to == null) { to = cm.doc.first + cm.doc.size }
|
3915 |
-
if (!lendiff) { lendiff = 0 }
|
3916 |
-
|
3917 |
-
var display = cm.display
|
3918 |
-
if (lendiff && to < display.viewTo &&
|
3919 |
-
(display.updateLineNumbers == null || display.updateLineNumbers > from))
|
3920 |
-
{ display.updateLineNumbers = from }
|
3921 |
-
|
3922 |
-
cm.curOp.viewChanged = true
|
3923 |
-
|
3924 |
-
if (from >= display.viewTo) { // Change after
|
3925 |
-
if (sawCollapsedSpans && visualLineNo(cm.doc, from) < display.viewTo)
|
3926 |
-
{ resetView(cm) }
|
3927 |
-
} else if (to <= display.viewFrom) { // Change before
|
3928 |
-
if (sawCollapsedSpans && visualLineEndNo(cm.doc, to + lendiff) > display.viewFrom) {
|
3929 |
-
resetView(cm)
|
3930 |
-
} else {
|
3931 |
-
display.viewFrom += lendiff
|
3932 |
-
display.viewTo += lendiff
|
3933 |
-
}
|
3934 |
-
} else if (from <= display.viewFrom && to >= display.viewTo) { // Full overlap
|
3935 |
-
resetView(cm)
|
3936 |
-
} else if (from <= display.viewFrom) { // Top overlap
|
3937 |
-
var cut = viewCuttingPoint(cm, to, to + lendiff, 1)
|
3938 |
-
if (cut) {
|
3939 |
-
display.view = display.view.slice(cut.index)
|
3940 |
-
display.viewFrom = cut.lineN
|
3941 |
-
display.viewTo += lendiff
|
3942 |
-
} else {
|
3943 |
-
resetView(cm)
|
3944 |
-
}
|
3945 |
-
} else if (to >= display.viewTo) { // Bottom overlap
|
3946 |
-
var cut$1 = viewCuttingPoint(cm, from, from, -1)
|
3947 |
-
if (cut$1) {
|
3948 |
-
display.view = display.view.slice(0, cut$1.index)
|
3949 |
-
display.viewTo = cut$1.lineN
|
3950 |
-
} else {
|
3951 |
-
resetView(cm)
|
3952 |
-
}
|
3953 |
-
} else { // Gap in the middle
|
3954 |
-
var cutTop = viewCuttingPoint(cm, from, from, -1)
|
3955 |
-
var cutBot = viewCuttingPoint(cm, to, to + lendiff, 1)
|
3956 |
-
if (cutTop && cutBot) {
|
3957 |
-
display.view = display.view.slice(0, cutTop.index)
|
3958 |
-
.concat(buildViewArray(cm, cutTop.lineN, cutBot.lineN))
|
3959 |
-
.concat(display.view.slice(cutBot.index))
|
3960 |
-
display.viewTo += lendiff
|
3961 |
-
} else {
|
3962 |
-
resetView(cm)
|
3963 |
-
}
|
3964 |
-
}
|
3965 |
-
|
3966 |
-
var ext = display.externalMeasured
|
3967 |
-
if (ext) {
|
3968 |
-
if (to < ext.lineN)
|
3969 |
-
{ ext.lineN += lendiff }
|
3970 |
-
else if (from < ext.lineN + ext.size)
|
3971 |
-
{ display.externalMeasured = null }
|
3972 |
-
}
|
3973 |
-
}
|
3974 |
-
|
3975 |
-
// Register a change to a single line. Type must be one of "text",
|
3976 |
-
// "gutter", "class", "widget"
|
3977 |
-
function regLineChange(cm, line, type) {
|
3978 |
-
cm.curOp.viewChanged = true
|
3979 |
-
var display = cm.display, ext = cm.display.externalMeasured
|
3980 |
-
if (ext && line >= ext.lineN && line < ext.lineN + ext.size)
|
3981 |
-
{ display.externalMeasured = null }
|
3982 |
-
|
3983 |
-
if (line < display.viewFrom || line >= display.viewTo) { return }
|
3984 |
-
var lineView = display.view[findViewIndex(cm, line)]
|
3985 |
-
if (lineView.node == null) { return }
|
3986 |
-
var arr = lineView.changes || (lineView.changes = [])
|
3987 |
-
if (indexOf(arr, type) == -1) { arr.push(type) }
|
3988 |
-
}
|
3989 |
-
|
3990 |
-
// Clear the view.
|
3991 |
-
function resetView(cm) {
|
3992 |
-
cm.display.viewFrom = cm.display.viewTo = cm.doc.first
|
3993 |
-
cm.display.view = []
|
3994 |
-
cm.display.viewOffset = 0
|
3995 |
-
}
|
3996 |
-
|
3997 |
-
function viewCuttingPoint(cm, oldN, newN, dir) {
|
3998 |
-
var index = findViewIndex(cm, oldN), diff, view = cm.display.view
|
3999 |
-
if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size)
|
4000 |
-
{ return {index: index, lineN: newN} }
|
4001 |
-
var n = cm.display.viewFrom
|
4002 |
-
for (var i = 0; i < index; i++)
|
4003 |
-
{ n += view[i].size }
|
4004 |
-
if (n != oldN) {
|
4005 |
-
if (dir > 0) {
|
4006 |
-
if (index == view.length - 1) { return null }
|
4007 |
-
diff = (n + view[index].size) - oldN
|
4008 |
-
index++
|
4009 |
-
} else {
|
4010 |
-
diff = n - oldN
|
4011 |
-
}
|
4012 |
-
oldN += diff; newN += diff
|
4013 |
-
}
|
4014 |
-
while (visualLineNo(cm.doc, newN) != newN) {
|
4015 |
-
if (index == (dir < 0 ? 0 : view.length - 1)) { return null }
|
4016 |
-
newN += dir * view[index - (dir < 0 ? 1 : 0)].size
|
4017 |
-
index += dir
|
4018 |
-
}
|
4019 |
-
return {index: index, lineN: newN}
|
4020 |
-
}
|
4021 |
-
|
4022 |
-
// Force the view to cover a given range, adding empty view element
|
4023 |
-
// or clipping off existing ones as needed.
|
4024 |
-
function adjustView(cm, from, to) {
|
4025 |
-
var display = cm.display, view = display.view
|
4026 |
-
if (view.length == 0 || from >= display.viewTo || to <= display.viewFrom) {
|
4027 |
-
display.view = buildViewArray(cm, from, to)
|
4028 |
-
display.viewFrom = from
|
4029 |
-
} else {
|
4030 |
-
if (display.viewFrom > from)
|
4031 |
-
{ display.view = buildViewArray(cm, from, display.viewFrom).concat(display.view) }
|
4032 |
-
else if (display.viewFrom < from)
|
4033 |
-
{ display.view = display.view.slice(findViewIndex(cm, from)) }
|
4034 |
-
display.viewFrom = from
|
4035 |
-
if (display.viewTo < to)
|
4036 |
-
{ display.view = display.view.concat(buildViewArray(cm, display.viewTo, to)) }
|
4037 |
-
else if (display.viewTo > to)
|
4038 |
-
{ display.view = display.view.slice(0, findViewIndex(cm, to)) }
|
4039 |
-
}
|
4040 |
-
display.viewTo = to
|
4041 |
-
}
|
4042 |
-
|
4043 |
-
// Count the number of lines in the view whose DOM representation is
|
4044 |
-
// out of date (or nonexistent).
|
4045 |
-
function countDirtyView(cm) {
|
4046 |
-
var view = cm.display.view, dirty = 0
|
4047 |
-
for (var i = 0; i < view.length; i++) {
|
4048 |
-
var lineView = view[i]
|
4049 |
-
if (!lineView.hidden && (!lineView.node || lineView.changes)) { ++dirty }
|
4050 |
-
}
|
4051 |
-
return dirty
|
4052 |
-
}
|
4053 |
-
|
4054 |
-
// HIGHLIGHT WORKER
|
4055 |
-
|
4056 |
-
function startWorker(cm, time) {
|
4057 |
-
if (cm.doc.highlightFrontier < cm.display.viewTo)
|
4058 |
-
{ cm.state.highlight.set(time, bind(highlightWorker, cm)) }
|
4059 |
-
}
|
4060 |
-
|
4061 |
-
function highlightWorker(cm) {
|
4062 |
-
var doc = cm.doc
|
4063 |
-
if (doc.highlightFrontier >= cm.display.viewTo) { return }
|
4064 |
-
var end = +new Date + cm.options.workTime
|
4065 |
-
var context = getContextBefore(cm, doc.highlightFrontier)
|
4066 |
-
var changedLines = []
|
4067 |
-
|
4068 |
-
doc.iter(context.line, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function (line) {
|
4069 |
-
if (context.line >= cm.display.viewFrom) { // Visible
|
4070 |
-
var oldStyles = line.styles
|
4071 |
-
var resetState = line.text.length > cm.options.maxHighlightLength ? copyState(doc.mode, context.state) : null
|
4072 |
-
var highlighted = highlightLine(cm, line, context, true)
|
4073 |
-
if (resetState) { context.state = resetState }
|
4074 |
-
line.styles = highlighted.styles
|
4075 |
-
var oldCls = line.styleClasses, newCls = highlighted.classes
|
4076 |
-
if (newCls) { line.styleClasses = newCls }
|
4077 |
-
else if (oldCls) { line.styleClasses = null }
|
4078 |
-
var ischange = !oldStyles || oldStyles.length != line.styles.length ||
|
4079 |
-
oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass)
|
4080 |
-
for (var i = 0; !ischange && i < oldStyles.length; ++i) { ischange = oldStyles[i] != line.styles[i] }
|
4081 |
-
if (ischange) { changedLines.push(context.line) }
|
4082 |
-
line.stateAfter = context.save()
|
4083 |
-
context.nextLine()
|
4084 |
-
} else {
|
4085 |
-
if (line.text.length <= cm.options.maxHighlightLength)
|
4086 |
-
{ processLine(cm, line.text, context) }
|
4087 |
-
line.stateAfter = context.line % 5 == 0 ? context.save() : null
|
4088 |
-
context.nextLine()
|
4089 |
-
}
|
4090 |
-
if (+new Date > end) {
|
4091 |
-
startWorker(cm, cm.options.workDelay)
|
4092 |
-
return true
|
4093 |
-
}
|
4094 |
-
})
|
4095 |
-
doc.highlightFrontier = context.line
|
4096 |
-
doc.modeFrontier = Math.max(doc.modeFrontier, context.line)
|
4097 |
-
if (changedLines.length) { runInOp(cm, function () {
|
4098 |
-
for (var i = 0; i < changedLines.length; i++)
|
4099 |
-
{ regLineChange(cm, changedLines[i], "text") }
|
4100 |
-
}) }
|
4101 |
-
}
|
4102 |
-
|
4103 |
-
// DISPLAY DRAWING
|
4104 |
-
|
4105 |
-
var DisplayUpdate = function(cm, viewport, force) {
|
4106 |
-
var display = cm.display
|
4107 |
-
|
4108 |
-
this.viewport = viewport
|
4109 |
-
// Store some values that we'll need later (but don't want to force a relayout for)
|
4110 |
-
this.visible = visibleLines(display, cm.doc, viewport)
|
4111 |
-
this.editorIsHidden = !display.wrapper.offsetWidth
|
4112 |
-
this.wrapperHeight = display.wrapper.clientHeight
|
4113 |
-
this.wrapperWidth = display.wrapper.clientWidth
|
4114 |
-
this.oldDisplayWidth = displayWidth(cm)
|
4115 |
-
this.force = force
|
4116 |
-
this.dims = getDimensions(cm)
|
4117 |
-
this.events = []
|
4118 |
-
};
|
4119 |
-
|
4120 |
-
DisplayUpdate.prototype.signal = function (emitter, type) {
|
4121 |
-
if (hasHandler(emitter, type))
|
4122 |
-
{ this.events.push(arguments) }
|
4123 |
-
};
|
4124 |
-
DisplayUpdate.prototype.finish = function () {
|
4125 |
-
var this$1 = this;
|
4126 |
-
|
4127 |
-
for (var i = 0; i < this.events.length; i++)
|
4128 |
-
{ signal.apply(null, this$1.events[i]) }
|
4129 |
-
};
|
4130 |
-
|
4131 |
-
function maybeClipScrollbars(cm) {
|
4132 |
-
var display = cm.display
|
4133 |
-
if (!display.scrollbarsClipped && display.scroller.offsetWidth) {
|
4134 |
-
display.nativeBarWidth = display.scroller.offsetWidth - display.scroller.clientWidth
|
4135 |
-
display.heightForcer.style.height = scrollGap(cm) + "px"
|
4136 |
-
display.sizer.style.marginBottom = -display.nativeBarWidth + "px"
|
4137 |
-
display.sizer.style.borderRightWidth = scrollGap(cm) + "px"
|
4138 |
-
display.scrollbarsClipped = true
|
4139 |
-
}
|
4140 |
-
}
|
4141 |
-
|
4142 |
-
function selectionSnapshot(cm) {
|
4143 |
-
if (cm.hasFocus()) { return null }
|
4144 |
-
var active = activeElt()
|
4145 |
-
if (!active || !contains(cm.display.lineDiv, active)) { return null }
|
4146 |
-
var result = {activeElt: active}
|
4147 |
-
if (window.getSelection) {
|
4148 |
-
var sel = window.getSelection()
|
4149 |
-
if (sel.anchorNode && sel.extend && contains(cm.display.lineDiv, sel.anchorNode)) {
|
4150 |
-
result.anchorNode = sel.anchorNode
|
4151 |
-
result.anchorOffset = sel.anchorOffset
|
4152 |
-
result.focusNode = sel.focusNode
|
4153 |
-
result.focusOffset = sel.focusOffset
|
4154 |
-
}
|
4155 |
-
}
|
4156 |
-
return result
|
4157 |
-
}
|
4158 |
-
|
4159 |
-
function restoreSelection(snapshot) {
|
4160 |
-
if (!snapshot || !snapshot.activeElt || snapshot.activeElt == activeElt()) { return }
|
4161 |
-
snapshot.activeElt.focus()
|
4162 |
-
if (snapshot.anchorNode && contains(document.body, snapshot.anchorNode) && contains(document.body, snapshot.focusNode)) {
|
4163 |
-
var sel = window.getSelection(), range = document.createRange()
|
4164 |
-
range.setEnd(snapshot.anchorNode, snapshot.anchorOffset)
|
4165 |
-
range.collapse(false)
|
4166 |
-
sel.removeAllRanges()
|
4167 |
-
sel.addRange(range)
|
4168 |
-
sel.extend(snapshot.focusNode, snapshot.focusOffset)
|
4169 |
-
}
|
4170 |
-
}
|
4171 |
-
|
4172 |
-
// Does the actual updating of the line display. Bails out
|
4173 |
-
// (returning false) when there is nothing to be done and forced is
|
4174 |
-
// false.
|
4175 |
-
function updateDisplayIfNeeded(cm, update) {
|
4176 |
-
var display = cm.display, doc = cm.doc
|
4177 |
-
|
4178 |
-
if (update.editorIsHidden) {
|
4179 |
-
resetView(cm)
|
4180 |
-
return false
|
4181 |
-
}
|
4182 |
-
|
4183 |
-
// Bail out if the visible area is already rendered and nothing changed.
|
4184 |
-
if (!update.force &&
|
4185 |
-
update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo &&
|
4186 |
-
(display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) &&
|
4187 |
-
display.renderedView == display.view && countDirtyView(cm) == 0)
|
4188 |
-
{ return false }
|
4189 |
-
|
4190 |
-
if (maybeUpdateLineNumberWidth(cm)) {
|
4191 |
-
resetView(cm)
|
4192 |
-
update.dims = getDimensions(cm)
|
4193 |
-
}
|
4194 |
-
|
4195 |
-
// Compute a suitable new viewport (from & to)
|
4196 |
-
var end = doc.first + doc.size
|
4197 |
-
var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first)
|
4198 |
-
var to = Math.min(end, update.visible.to + cm.options.viewportMargin)
|
4199 |
-
if (display.viewFrom < from && from - display.viewFrom < 20) { from = Math.max(doc.first, display.viewFrom) }
|
4200 |
-
if (display.viewTo > to && display.viewTo - to < 20) { to = Math.min(end, display.viewTo) }
|
4201 |
-
if (sawCollapsedSpans) {
|
4202 |
-
from = visualLineNo(cm.doc, from)
|
4203 |
-
to = visualLineEndNo(cm.doc, to)
|
4204 |
-
}
|
4205 |
-
|
4206 |
-
var different = from != display.viewFrom || to != display.viewTo ||
|
4207 |
-
display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth
|
4208 |
-
adjustView(cm, from, to)
|
4209 |
-
|
4210 |
-
display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom))
|
4211 |
-
// Position the mover div to align with the current scroll position
|
4212 |
-
cm.display.mover.style.top = display.viewOffset + "px"
|
4213 |
-
|
4214 |
-
var toUpdate = countDirtyView(cm)
|
4215 |
-
if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view &&
|
4216 |
-
(display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo))
|
4217 |
-
{ return false }
|
4218 |
-
|
4219 |
-
// For big changes, we hide the enclosing element during the
|
4220 |
-
// update, since that speeds up the operations on most browsers.
|
4221 |
-
var selSnapshot = selectionSnapshot(cm)
|
4222 |
-
if (toUpdate > 4) { display.lineDiv.style.display = "none" }
|
4223 |
-
patchDisplay(cm, display.updateLineNumbers, update.dims)
|
4224 |
-
if (toUpdate > 4) { display.lineDiv.style.display = "" }
|
4225 |
-
display.renderedView = display.view
|
4226 |
-
// There might have been a widget with a focused element that got
|
4227 |
-
// hidden or updated, if so re-focus it.
|
4228 |
-
restoreSelection(selSnapshot)
|
4229 |
-
|
4230 |
-
// Prevent selection and cursors from interfering with the scroll
|
4231 |
-
// width and height.
|
4232 |
-
removeChildren(display.cursorDiv)
|
4233 |
-
removeChildren(display.selectionDiv)
|
4234 |
-
display.gutters.style.height = display.sizer.style.minHeight = 0
|
4235 |
-
|
4236 |
-
if (different) {
|
4237 |
-
display.lastWrapHeight = update.wrapperHeight
|
4238 |
-
display.lastWrapWidth = update.wrapperWidth
|
4239 |
-
startWorker(cm, 400)
|
4240 |
-
}
|
4241 |
-
|
4242 |
-
display.updateLineNumbers = null
|
4243 |
-
|
4244 |
-
return true
|
4245 |
-
}
|
4246 |
-
|
4247 |
-
function postUpdateDisplay(cm, update) {
|
4248 |
-
var viewport = update.viewport
|
4249 |
-
|
4250 |
-
for (var first = true;; first = false) {
|
4251 |
-
if (!first || !cm.options.lineWrapping || update.oldDisplayWidth == displayWidth(cm)) {
|
4252 |
-
// Clip forced viewport to actual scrollable area.
|
4253 |
-
if (viewport && viewport.top != null)
|
4254 |
-
{ viewport = {top: Math.min(cm.doc.height + paddingVert(cm.display) - displayHeight(cm), viewport.top)} }
|
4255 |
-
// Updated line heights might result in the drawn area not
|
4256 |
-
// actually covering the viewport. Keep looping until it does.
|
4257 |
-
update.visible = visibleLines(cm.display, cm.doc, viewport)
|
4258 |
-
if (update.visible.from >= cm.display.viewFrom && update.visible.to <= cm.display.viewTo)
|
4259 |
-
{ break }
|
4260 |
-
}
|
4261 |
-
if (!updateDisplayIfNeeded(cm, update)) { break }
|
4262 |
-
updateHeightsInViewport(cm)
|
4263 |
-
var barMeasure = measureForScrollbars(cm)
|
4264 |
-
updateSelection(cm)
|
4265 |
-
updateScrollbars(cm, barMeasure)
|
4266 |
-
setDocumentHeight(cm, barMeasure)
|
4267 |
-
update.force = false
|
4268 |
-
}
|
4269 |
-
|
4270 |
-
update.signal(cm, "update", cm)
|
4271 |
-
if (cm.display.viewFrom != cm.display.reportedViewFrom || cm.display.viewTo != cm.display.reportedViewTo) {
|
4272 |
-
update.signal(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo)
|
4273 |
-
cm.display.reportedViewFrom = cm.display.viewFrom; cm.display.reportedViewTo = cm.display.viewTo
|
4274 |
-
}
|
4275 |
-
}
|
4276 |
-
|
4277 |
-
function updateDisplaySimple(cm, viewport) {
|
4278 |
-
var update = new DisplayUpdate(cm, viewport)
|
4279 |
-
if (updateDisplayIfNeeded(cm, update)) {
|
4280 |
-
updateHeightsInViewport(cm)
|
4281 |
-
postUpdateDisplay(cm, update)
|
4282 |
-
var barMeasure = measureForScrollbars(cm)
|
4283 |
-
updateSelection(cm)
|
4284 |
-
updateScrollbars(cm, barMeasure)
|
4285 |
-
setDocumentHeight(cm, barMeasure)
|
4286 |
-
update.finish()
|
4287 |
-
}
|
4288 |
-
}
|
4289 |
-
|
4290 |
-
// Sync the actual display DOM structure with display.view, removing
|
4291 |
-
// nodes for lines that are no longer in view, and creating the ones
|
4292 |
-
// that are not there yet, and updating the ones that are out of
|
4293 |
-
// date.
|
4294 |
-
function patchDisplay(cm, updateNumbersFrom, dims) {
|
4295 |
-
var display = cm.display, lineNumbers = cm.options.lineNumbers
|
4296 |
-
var container = display.lineDiv, cur = container.firstChild
|
4297 |
-
|
4298 |
-
function rm(node) {
|
4299 |
-
var next = node.nextSibling
|
4300 |
-
// Works around a throw-scroll bug in OS X Webkit
|
4301 |
-
if (webkit && mac && cm.display.currentWheelTarget == node)
|
4302 |
-
{ node.style.display = "none" }
|
4303 |
-
else
|
4304 |
-
{ node.parentNode.removeChild(node) }
|
4305 |
-
return next
|
4306 |
-
}
|
4307 |
-
|
4308 |
-
var view = display.view, lineN = display.viewFrom
|
4309 |
-
// Loop over the elements in the view, syncing cur (the DOM nodes
|
4310 |
-
// in display.lineDiv) with the view as we go.
|
4311 |
-
for (var i = 0; i < view.length; i++) {
|
4312 |
-
var lineView = view[i]
|
4313 |
-
if (lineView.hidden) {
|
4314 |
-
} else if (!lineView.node || lineView.node.parentNode != container) { // Not drawn yet
|
4315 |
-
var node = buildLineElement(cm, lineView, lineN, dims)
|
4316 |
-
container.insertBefore(node, cur)
|
4317 |
-
} else { // Already drawn
|
4318 |
-
while (cur != lineView.node) { cur = rm(cur) }
|
4319 |
-
var updateNumber = lineNumbers && updateNumbersFrom != null &&
|
4320 |
-
updateNumbersFrom <= lineN && lineView.lineNumber
|
4321 |
-
if (lineView.changes) {
|
4322 |
-
if (indexOf(lineView.changes, "gutter") > -1) { updateNumber = false }
|
4323 |
-
updateLineForChanges(cm, lineView, lineN, dims)
|
4324 |
-
}
|
4325 |
-
if (updateNumber) {
|
4326 |
-
removeChildren(lineView.lineNumber)
|
4327 |
-
lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN)))
|
4328 |
-
}
|
4329 |
-
cur = lineView.node.nextSibling
|
4330 |
-
}
|
4331 |
-
lineN += lineView.size
|
4332 |
-
}
|
4333 |
-
while (cur) { cur = rm(cur) }
|
4334 |
-
}
|
4335 |
-
|
4336 |
-
function updateGutterSpace(cm) {
|
4337 |
-
var width = cm.display.gutters.offsetWidth
|
4338 |
-
cm.display.sizer.style.marginLeft = width + "px"
|
4339 |
-
}
|
4340 |
-
|
4341 |
-
function setDocumentHeight(cm, measure) {
|
4342 |
-
cm.display.sizer.style.minHeight = measure.docHeight + "px"
|
4343 |
-
cm.display.heightForcer.style.top = measure.docHeight + "px"
|
4344 |
-
cm.display.gutters.style.height = (measure.docHeight + cm.display.barHeight + scrollGap(cm)) + "px"
|
4345 |
-
}
|
4346 |
-
|
4347 |
-
// Rebuild the gutter elements, ensure the margin to the left of the
|
4348 |
-
// code matches their width.
|
4349 |
-
function updateGutters(cm) {
|
4350 |
-
var gutters = cm.display.gutters, specs = cm.options.gutters
|
4351 |
-
removeChildren(gutters)
|
4352 |
-
var i = 0
|
4353 |
-
for (; i < specs.length; ++i) {
|
4354 |
-
var gutterClass = specs[i]
|
4355 |
-
var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + gutterClass))
|
4356 |
-
if (gutterClass == "CodeMirror-linenumbers") {
|
4357 |
-
cm.display.lineGutter = gElt
|
4358 |
-
gElt.style.width = (cm.display.lineNumWidth || 1) + "px"
|
4359 |
-
}
|
4360 |
-
}
|
4361 |
-
gutters.style.display = i ? "" : "none"
|
4362 |
-
updateGutterSpace(cm)
|
4363 |
-
}
|
4364 |
-
|
4365 |
-
// Make sure the gutters options contains the element
|
4366 |
-
// "CodeMirror-linenumbers" when the lineNumbers option is true.
|
4367 |
-
function setGuttersForLineNumbers(options) {
|
4368 |
-
var found = indexOf(options.gutters, "CodeMirror-linenumbers")
|
4369 |
-
if (found == -1 && options.lineNumbers) {
|
4370 |
-
options.gutters = options.gutters.concat(["CodeMirror-linenumbers"])
|
4371 |
-
} else if (found > -1 && !options.lineNumbers) {
|
4372 |
-
options.gutters = options.gutters.slice(0)
|
4373 |
-
options.gutters.splice(found, 1)
|
4374 |
-
}
|
4375 |
-
}
|
4376 |
-
|
4377 |
-
var wheelSamples = 0;
|
4378 |
-
var wheelPixelsPerUnit = null;
|
4379 |
-
// Fill in a browser-detected starting value on browsers where we
|
4380 |
-
// know one. These don't have to be accurate -- the result of them
|
4381 |
-
// being wrong would just be a slight flicker on the first wheel
|
4382 |
-
// scroll (if it is large enough).
|
4383 |
-
if (ie) { wheelPixelsPerUnit = -.53 }
|
4384 |
-
else if (gecko) { wheelPixelsPerUnit = 15 }
|
4385 |
-
else if (chrome) { wheelPixelsPerUnit = -.7 }
|
4386 |
-
else if (safari) { wheelPixelsPerUnit = -1/3 }
|
4387 |
-
|
4388 |
-
function wheelEventDelta(e) {
|
4389 |
-
var dx = e.wheelDeltaX, dy = e.wheelDeltaY
|
4390 |
-
if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) { dx = e.detail }
|
4391 |
-
if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) { dy = e.detail }
|
4392 |
-
else if (dy == null) { dy = e.wheelDelta }
|
4393 |
-
return {x: dx, y: dy}
|
4394 |
-
}
|
4395 |
-
function wheelEventPixels(e) {
|
4396 |
-
var delta = wheelEventDelta(e)
|
4397 |
-
delta.x *= wheelPixelsPerUnit
|
4398 |
-
delta.y *= wheelPixelsPerUnit
|
4399 |
-
return delta
|
4400 |
-
}
|
4401 |
-
|
4402 |
-
function onScrollWheel(cm, e) {
|
4403 |
-
var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y
|
4404 |
-
|
4405 |
-
var display = cm.display, scroll = display.scroller
|
4406 |
-
// Quit if there's nothing to scroll here
|
4407 |
-
var canScrollX = scroll.scrollWidth > scroll.clientWidth
|
4408 |
-
var canScrollY = scroll.scrollHeight > scroll.clientHeight
|
4409 |
-
if (!(dx && canScrollX || dy && canScrollY)) { return }
|
4410 |
-
|
4411 |
-
// Webkit browsers on OS X abort momentum scrolls when the target
|
4412 |
-
// of the scroll event is removed from the scrollable element.
|
4413 |
-
// This hack (see related code in patchDisplay) makes sure the
|
4414 |
-
// element is kept around.
|
4415 |
-
if (dy && mac && webkit) {
|
4416 |
-
outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) {
|
4417 |
-
for (var i = 0; i < view.length; i++) {
|
4418 |
-
if (view[i].node == cur) {
|
4419 |
-
cm.display.currentWheelTarget = cur
|
4420 |
-
break outer
|
4421 |
-
}
|
4422 |
-
}
|
4423 |
-
}
|
4424 |
-
}
|
4425 |
-
|
4426 |
-
// On some browsers, horizontal scrolling will cause redraws to
|
4427 |
-
// happen before the gutter has been realigned, causing it to
|
4428 |
-
// wriggle around in a most unseemly way. When we have an
|
4429 |
-
// estimated pixels/delta value, we just handle horizontal
|
4430 |
-
// scrolling entirely here. It'll be slightly off from native, but
|
4431 |
-
// better than glitching out.
|
4432 |
-
if (dx && !gecko && !presto && wheelPixelsPerUnit != null) {
|
4433 |
-
if (dy && canScrollY)
|
4434 |
-
{ updateScrollTop(cm, Math.max(0, scroll.scrollTop + dy * wheelPixelsPerUnit)) }
|
4435 |
-
setScrollLeft(cm, Math.max(0, scroll.scrollLeft + dx * wheelPixelsPerUnit))
|
4436 |
-
// Only prevent default scrolling if vertical scrolling is
|
4437 |
-
// actually possible. Otherwise, it causes vertical scroll
|
4438 |
-
// jitter on OSX trackpads when deltaX is small and deltaY
|
4439 |
-
// is large (issue #3579)
|
4440 |
-
if (!dy || (dy && canScrollY))
|
4441 |
-
{ e_preventDefault(e) }
|
4442 |
-
display.wheelStartX = null // Abort measurement, if in progress
|
4443 |
-
return
|
4444 |
-
}
|
4445 |
-
|
4446 |
-
// 'Project' the visible viewport to cover the area that is being
|
4447 |
-
// scrolled into view (if we know enough to estimate it).
|
4448 |
-
if (dy && wheelPixelsPerUnit != null) {
|
4449 |
-
var pixels = dy * wheelPixelsPerUnit
|
4450 |
-
var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight
|
4451 |
-
if (pixels < 0) { top = Math.max(0, top + pixels - 50) }
|
4452 |
-
else { bot = Math.min(cm.doc.height, bot + pixels + 50) }
|
4453 |
-
updateDisplaySimple(cm, {top: top, bottom: bot})
|
4454 |
-
}
|
4455 |
-
|
4456 |
-
if (wheelSamples < 20) {
|
4457 |
-
if (display.wheelStartX == null) {
|
4458 |
-
display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop
|
4459 |
-
display.wheelDX = dx; display.wheelDY = dy
|
4460 |
-
setTimeout(function () {
|
4461 |
-
if (display.wheelStartX == null) { return }
|
4462 |
-
var movedX = scroll.scrollLeft - display.wheelStartX
|
4463 |
-
var movedY = scroll.scrollTop - display.wheelStartY
|
4464 |
-
var sample = (movedY && display.wheelDY && movedY / display.wheelDY) ||
|
4465 |
-
(movedX && display.wheelDX && movedX / display.wheelDX)
|
4466 |
-
display.wheelStartX = display.wheelStartY = null
|
4467 |
-
if (!sample) { return }
|
4468 |
-
wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1)
|
4469 |
-
++wheelSamples
|
4470 |
-
}, 200)
|
4471 |
-
} else {
|
4472 |
-
display.wheelDX += dx; display.wheelDY += dy
|
4473 |
-
}
|
4474 |
-
}
|
4475 |
-
}
|
4476 |
-
|
4477 |
-
// Selection objects are immutable. A new one is created every time
|
4478 |
-
// the selection changes. A selection is one or more non-overlapping
|
4479 |
-
// (and non-touching) ranges, sorted, and an integer that indicates
|
4480 |
-
// which one is the primary selection (the one that's scrolled into
|
4481 |
-
// view, that getCursor returns, etc).
|
4482 |
-
var Selection = function(ranges, primIndex) {
|
4483 |
-
this.ranges = ranges
|
4484 |
-
this.primIndex = primIndex
|
4485 |
-
};
|
4486 |
-
|
4487 |
-
Selection.prototype.primary = function () { return this.ranges[this.primIndex] };
|
4488 |
-
|
4489 |
-
Selection.prototype.equals = function (other) {
|
4490 |
-
var this$1 = this;
|
4491 |
-
|
4492 |
-
if (other == this) { return true }
|
4493 |
-
if (other.primIndex != this.primIndex || other.ranges.length != this.ranges.length) { return false }
|
4494 |
-
for (var i = 0; i < this.ranges.length; i++) {
|
4495 |
-
var here = this$1.ranges[i], there = other.ranges[i]
|
4496 |
-
if (!equalCursorPos(here.anchor, there.anchor) || !equalCursorPos(here.head, there.head)) { return false }
|
4497 |
-
}
|
4498 |
-
return true
|
4499 |
-
};
|
4500 |
-
|
4501 |
-
Selection.prototype.deepCopy = function () {
|
4502 |
-
var this$1 = this;
|
4503 |
-
|
4504 |
-
var out = []
|
4505 |
-
for (var i = 0; i < this.ranges.length; i++)
|
4506 |
-
{ out[i] = new Range(copyPos(this$1.ranges[i].anchor), copyPos(this$1.ranges[i].head)) }
|
4507 |
-
return new Selection(out, this.primIndex)
|
4508 |
-
};
|
4509 |
-
|
4510 |
-
Selection.prototype.somethingSelected = function () {
|
4511 |
-
var this$1 = this;
|
4512 |
-
|
4513 |
-
for (var i = 0; i < this.ranges.length; i++)
|
4514 |
-
{ if (!this$1.ranges[i].empty()) { return true } }
|
4515 |
-
return false
|
4516 |
-
};
|
4517 |
-
|
4518 |
-
Selection.prototype.contains = function (pos, end) {
|
4519 |
-
var this$1 = this;
|
4520 |
-
|
4521 |
-
if (!end) { end = pos }
|
4522 |
-
for (var i = 0; i < this.ranges.length; i++) {
|
4523 |
-
var range = this$1.ranges[i]
|
4524 |
-
if (cmp(end, range.from()) >= 0 && cmp(pos, range.to()) <= 0)
|
4525 |
-
{ return i }
|
4526 |
-
}
|
4527 |
-
return -1
|
4528 |
-
};
|
4529 |
-
|
4530 |
-
var Range = function(anchor, head) {
|
4531 |
-
this.anchor = anchor; this.head = head
|
4532 |
-
};
|
4533 |
-
|
4534 |
-
Range.prototype.from = function () { return minPos(this.anchor, this.head) };
|
4535 |
-
Range.prototype.to = function () { return maxPos(this.anchor, this.head) };
|
4536 |
-
Range.prototype.empty = function () { return this.head.line == this.anchor.line && this.head.ch == this.anchor.ch };
|
4537 |
-
|
4538 |
-
// Take an unsorted, potentially overlapping set of ranges, and
|
4539 |
-
// build a selection out of it. 'Consumes' ranges array (modifying
|
4540 |
-
// it).
|
4541 |
-
function normalizeSelection(ranges, primIndex) {
|
4542 |
-
var prim = ranges[primIndex]
|
4543 |
-
ranges.sort(function (a, b) { return cmp(a.from(), b.from()); })
|
4544 |
-
primIndex = indexOf(ranges, prim)
|
4545 |
-
for (var i = 1; i < ranges.length; i++) {
|
4546 |
-
var cur = ranges[i], prev = ranges[i - 1]
|
4547 |
-
if (cmp(prev.to(), cur.from()) >= 0) {
|
4548 |
-
var from = minPos(prev.from(), cur.from()), to = maxPos(prev.to(), cur.to())
|
4549 |
-
var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head
|
4550 |
-
if (i <= primIndex) { --primIndex }
|
4551 |
-
ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to))
|
4552 |
-
}
|
4553 |
-
}
|
4554 |
-
return new Selection(ranges, primIndex)
|
4555 |
-
}
|
4556 |
-
|
4557 |
-
function simpleSelection(anchor, head) {
|
4558 |
-
return new Selection([new Range(anchor, head || anchor)], 0)
|
4559 |
-
}
|
4560 |
-
|
4561 |
-
// Compute the position of the end of a change (its 'to' property
|
4562 |
-
// refers to the pre-change end).
|
4563 |
-
function changeEnd(change) {
|
4564 |
-
if (!change.text) { return change.to }
|
4565 |
-
return Pos(change.from.line + change.text.length - 1,
|
4566 |
-
lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0))
|
4567 |
-
}
|
4568 |
-
|
4569 |
-
// Adjust a position to refer to the post-change position of the
|
4570 |
-
// same text, or the end of the change if the change covers it.
|
4571 |
-
function adjustForChange(pos, change) {
|
4572 |
-
if (cmp(pos, change.from) < 0) { return pos }
|
4573 |
-
if (cmp(pos, change.to) <= 0) { return changeEnd(change) }
|
4574 |
-
|
4575 |
-
var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1, ch = pos.ch
|
4576 |
-
if (pos.line == change.to.line) { ch += changeEnd(change).ch - change.to.ch }
|
4577 |
-
return Pos(line, ch)
|
4578 |
-
}
|
4579 |
-
|
4580 |
-
function computeSelAfterChange(doc, change) {
|
4581 |
-
var out = []
|
4582 |
-
for (var i = 0; i < doc.sel.ranges.length; i++) {
|
4583 |
-
var range = doc.sel.ranges[i]
|
4584 |
-
out.push(new Range(adjustForChange(range.anchor, change),
|
4585 |
-
adjustForChange(range.head, change)))
|
4586 |
-
}
|
4587 |
-
return normalizeSelection(out, doc.sel.primIndex)
|
4588 |
-
}
|
4589 |
-
|
4590 |
-
function offsetPos(pos, old, nw) {
|
4591 |
-
if (pos.line == old.line)
|
4592 |
-
{ return Pos(nw.line, pos.ch - old.ch + nw.ch) }
|
4593 |
-
else
|
4594 |
-
{ return Pos(nw.line + (pos.line - old.line), pos.ch) }
|
4595 |
-
}
|
4596 |
-
|
4597 |
-
// Used by replaceSelections to allow moving the selection to the
|
4598 |
-
// start or around the replaced test. Hint may be "start" or "around".
|
4599 |
-
function computeReplacedSel(doc, changes, hint) {
|
4600 |
-
var out = []
|
4601 |
-
var oldPrev = Pos(doc.first, 0), newPrev = oldPrev
|
4602 |
-
for (var i = 0; i < changes.length; i++) {
|
4603 |
-
var change = changes[i]
|
4604 |
-
var from = offsetPos(change.from, oldPrev, newPrev)
|
4605 |
-
var to = offsetPos(changeEnd(change), oldPrev, newPrev)
|
4606 |
-
oldPrev = change.to
|
4607 |
-
newPrev = to
|
4608 |
-
if (hint == "around") {
|
4609 |
-
var range = doc.sel.ranges[i], inv = cmp(range.head, range.anchor) < 0
|
4610 |
-
out[i] = new Range(inv ? to : from, inv ? from : to)
|
4611 |
-
} else {
|
4612 |
-
out[i] = new Range(from, from)
|
4613 |
-
}
|
4614 |
-
}
|
4615 |
-
return new Selection(out, doc.sel.primIndex)
|
4616 |
-
}
|
4617 |
-
|
4618 |
-
// Used to get the editor into a consistent state again when options change.
|
4619 |
-
|
4620 |
-
function loadMode(cm) {
|
4621 |
-
cm.doc.mode = getMode(cm.options, cm.doc.modeOption)
|
4622 |
-
resetModeState(cm)
|
4623 |
-
}
|
4624 |
-
|
4625 |
-
function resetModeState(cm) {
|
4626 |
-
cm.doc.iter(function (line) {
|
4627 |
-
if (line.stateAfter) { line.stateAfter = null }
|
4628 |
-
if (line.styles) { line.styles = null }
|
4629 |
-
})
|
4630 |
-
cm.doc.modeFrontier = cm.doc.highlightFrontier = cm.doc.first
|
4631 |
-
startWorker(cm, 100)
|
4632 |
-
cm.state.modeGen++
|
4633 |
-
if (cm.curOp) { regChange(cm) }
|
4634 |
-
}
|
4635 |
-
|
4636 |
-
// DOCUMENT DATA STRUCTURE
|
4637 |
-
|
4638 |
-
// By default, updates that start and end at the beginning of a line
|
4639 |
-
// are treated specially, in order to make the association of line
|
4640 |
-
// widgets and marker elements with the text behave more intuitive.
|
4641 |
-
function isWholeLineUpdate(doc, change) {
|
4642 |
-
return change.from.ch == 0 && change.to.ch == 0 && lst(change.text) == "" &&
|
4643 |
-
(!doc.cm || doc.cm.options.wholeLineUpdateBefore)
|
4644 |
-
}
|
4645 |
-
|
4646 |
-
// Perform a change on the document data structure.
|
4647 |
-
function updateDoc(doc, change, markedSpans, estimateHeight) {
|
4648 |
-
function spansFor(n) {return markedSpans ? markedSpans[n] : null}
|
4649 |
-
function update(line, text, spans) {
|
4650 |
-
updateLine(line, text, spans, estimateHeight)
|
4651 |
-
signalLater(line, "change", line, change)
|
4652 |
-
}
|
4653 |
-
function linesFor(start, end) {
|
4654 |
-
var result = []
|
4655 |
-
for (var i = start; i < end; ++i)
|
4656 |
-
{ result.push(new Line(text[i], spansFor(i), estimateHeight)) }
|
4657 |
-
return result
|
4658 |
-
}
|
4659 |
-
|
4660 |
-
var from = change.from, to = change.to, text = change.text
|
4661 |
-
var firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line)
|
4662 |
-
var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line
|
4663 |
-
|
4664 |
-
// Adjust the line structure
|
4665 |
-
if (change.full) {
|
4666 |
-
doc.insert(0, linesFor(0, text.length))
|
4667 |
-
doc.remove(text.length, doc.size - text.length)
|
4668 |
-
} else if (isWholeLineUpdate(doc, change)) {
|
4669 |
-
// This is a whole-line replace. Treated specially to make
|
4670 |
-
// sure line objects move the way they are supposed to.
|
4671 |
-
var added = linesFor(0, text.length - 1)
|
4672 |
-
update(lastLine, lastLine.text, lastSpans)
|
4673 |
-
if (nlines) { doc.remove(from.line, nlines) }
|
4674 |
-
if (added.length) { doc.insert(from.line, added) }
|
4675 |
-
} else if (firstLine == lastLine) {
|
4676 |
-
if (text.length == 1) {
|
4677 |
-
update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans)
|
4678 |
-
} else {
|
4679 |
-
var added$1 = linesFor(1, text.length - 1)
|
4680 |
-
added$1.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight))
|
4681 |
-
update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0))
|
4682 |
-
doc.insert(from.line + 1, added$1)
|
4683 |
-
}
|
4684 |
-
} else if (text.length == 1) {
|
4685 |
-
update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0))
|
4686 |
-
doc.remove(from.line + 1, nlines)
|
4687 |
-
} else {
|
4688 |
-
update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0))
|
4689 |
-
update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans)
|
4690 |
-
var added$2 = linesFor(1, text.length - 1)
|
4691 |
-
if (nlines > 1) { doc.remove(from.line + 1, nlines - 1) }
|
4692 |
-
doc.insert(from.line + 1, added$2)
|
4693 |
-
}
|
4694 |
-
|
4695 |
-
signalLater(doc, "change", doc, change)
|
4696 |
-
}
|
4697 |
-
|
4698 |
-
// Call f for all linked documents.
|
4699 |
-
function linkedDocs(doc, f, sharedHistOnly) {
|
4700 |
-
function propagate(doc, skip, sharedHist) {
|
4701 |
-
if (doc.linked) { for (var i = 0; i < doc.linked.length; ++i) {
|
4702 |
-
var rel = doc.linked[i]
|
4703 |
-
if (rel.doc == skip) { continue }
|
4704 |
-
var shared = sharedHist && rel.sharedHist
|
4705 |
-
if (sharedHistOnly && !shared) { continue }
|
4706 |
-
f(rel.doc, shared)
|
4707 |
-
propagate(rel.doc, doc, shared)
|
4708 |
-
} }
|
4709 |
-
}
|
4710 |
-
propagate(doc, null, true)
|
4711 |
-
}
|
4712 |
-
|
4713 |
-
// Attach a document to an editor.
|
4714 |
-
function attachDoc(cm, doc) {
|
4715 |
-
if (doc.cm) { throw new Error("This document is already in use.") }
|
4716 |
-
cm.doc = doc
|
4717 |
-
doc.cm = cm
|
4718 |
-
estimateLineHeights(cm)
|
4719 |
-
loadMode(cm)
|
4720 |
-
setDirectionClass(cm)
|
4721 |
-
if (!cm.options.lineWrapping) { findMaxLine(cm) }
|
4722 |
-
cm.options.mode = doc.modeOption
|
4723 |
-
regChange(cm)
|
4724 |
-
}
|
4725 |
-
|
4726 |
-
function setDirectionClass(cm) {
|
4727 |
-
;(cm.doc.direction == "rtl" ? addClass : rmClass)(cm.display.lineDiv, "CodeMirror-rtl")
|
4728 |
-
}
|
4729 |
-
|
4730 |
-
function directionChanged(cm) {
|
4731 |
-
runInOp(cm, function () {
|
4732 |
-
setDirectionClass(cm)
|
4733 |
-
regChange(cm)
|
4734 |
-
})
|
4735 |
-
}
|
4736 |
-
|
4737 |
-
function History(startGen) {
|
4738 |
-
// Arrays of change events and selections. Doing something adds an
|
4739 |
-
// event to done and clears undo. Undoing moves events from done
|
4740 |
-
// to undone, redoing moves them in the other direction.
|
4741 |
-
this.done = []; this.undone = []
|
4742 |
-
this.undoDepth = Infinity
|
4743 |
-
// Used to track when changes can be merged into a single undo
|
4744 |
-
// event
|
4745 |
-
this.lastModTime = this.lastSelTime = 0
|
4746 |
-
this.lastOp = this.lastSelOp = null
|
4747 |
-
this.lastOrigin = this.lastSelOrigin = null
|
4748 |
-
// Used by the isClean() method
|
4749 |
-
this.generation = this.maxGeneration = startGen || 1
|
4750 |
-
}
|
4751 |
-
|
4752 |
-
// Create a history change event from an updateDoc-style change
|
4753 |
-
// object.
|
4754 |
-
function historyChangeFromChange(doc, change) {
|
4755 |
-
var histChange = {from: copyPos(change.from), to: changeEnd(change), text: getBetween(doc, change.from, change.to)}
|
4756 |
-
attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1)
|
4757 |
-
linkedDocs(doc, function (doc) { return attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1); }, true)
|
4758 |
-
return histChange
|
4759 |
-
}
|
4760 |
-
|
4761 |
-
// Pop all selection events off the end of a history array. Stop at
|
4762 |
-
// a change event.
|
4763 |
-
function clearSelectionEvents(array) {
|
4764 |
-
while (array.length) {
|
4765 |
-
var last = lst(array)
|
4766 |
-
if (last.ranges) { array.pop() }
|
4767 |
-
else { break }
|
4768 |
-
}
|
4769 |
-
}
|
4770 |
-
|
4771 |
-
// Find the top change event in the history. Pop off selection
|
4772 |
-
// events that are in the way.
|
4773 |
-
function lastChangeEvent(hist, force) {
|
4774 |
-
if (force) {
|
4775 |
-
clearSelectionEvents(hist.done)
|
4776 |
-
return lst(hist.done)
|
4777 |
-
} else if (hist.done.length && !lst(hist.done).ranges) {
|
4778 |
-
return lst(hist.done)
|
4779 |
-
} else if (hist.done.length > 1 && !hist.done[hist.done.length - 2].ranges) {
|
4780 |
-
hist.done.pop()
|
4781 |
-
return lst(hist.done)
|
4782 |
-
}
|
4783 |
-
}
|
4784 |
-
|
4785 |
-
// Register a change in the history. Merges changes that are within
|
4786 |
-
// a single operation, or are close together with an origin that
|
4787 |
-
// allows merging (starting with "+") into a single event.
|
4788 |
-
function addChangeToHistory(doc, change, selAfter, opId) {
|
4789 |
-
var hist = doc.history
|
4790 |
-
hist.undone.length = 0
|
4791 |
-
var time = +new Date, cur
|
4792 |
-
var last
|
4793 |
-
|
4794 |
-
if ((hist.lastOp == opId ||
|
4795 |
-
hist.lastOrigin == change.origin && change.origin &&
|
4796 |
-
((change.origin.charAt(0) == "+" && hist.lastModTime > time - (doc.cm ? doc.cm.options.historyEventDelay : 500)) ||
|
4797 |
-
change.origin.charAt(0) == "*")) &&
|
4798 |
-
(cur = lastChangeEvent(hist, hist.lastOp == opId))) {
|
4799 |
-
// Merge this change into the last event
|
4800 |
-
last = lst(cur.changes)
|
4801 |
-
if (cmp(change.from, change.to) == 0 && cmp(change.from, last.to) == 0) {
|
4802 |
-
// Optimized case for simple insertion -- don't want to add
|
4803 |
-
// new changesets for every character typed
|
4804 |
-
last.to = changeEnd(change)
|
4805 |
-
} else {
|
4806 |
-
// Add new sub-event
|
4807 |
-
cur.changes.push(historyChangeFromChange(doc, change))
|
4808 |
-
}
|
4809 |
-
} else {
|
4810 |
-
// Can not be merged, start a new event.
|
4811 |
-
var before = lst(hist.done)
|
4812 |
-
if (!before || !before.ranges)
|
4813 |
-
{ pushSelectionToHistory(doc.sel, hist.done) }
|
4814 |
-
cur = {changes: [historyChangeFromChange(doc, change)],
|
4815 |
-
generation: hist.generation}
|
4816 |
-
hist.done.push(cur)
|
4817 |
-
while (hist.done.length > hist.undoDepth) {
|
4818 |
-
hist.done.shift()
|
4819 |
-
if (!hist.done[0].ranges) { hist.done.shift() }
|
4820 |
-
}
|
4821 |
-
}
|
4822 |
-
hist.done.push(selAfter)
|
4823 |
-
hist.generation = ++hist.maxGeneration
|
4824 |
-
hist.lastModTime = hist.lastSelTime = time
|
4825 |
-
hist.lastOp = hist.lastSelOp = opId
|
4826 |
-
hist.lastOrigin = hist.lastSelOrigin = change.origin
|
4827 |
-
|
4828 |
-
if (!last) { signal(doc, "historyAdded") }
|
4829 |
-
}
|
4830 |
-
|
4831 |
-
function selectionEventCanBeMerged(doc, origin, prev, sel) {
|
4832 |
-
var ch = origin.charAt(0)
|
4833 |
-
return ch == "*" ||
|
4834 |
-
ch == "+" &&
|
4835 |
-
prev.ranges.length == sel.ranges.length &&
|
4836 |
-
prev.somethingSelected() == sel.somethingSelected() &&
|
4837 |
-
new Date - doc.history.lastSelTime <= (doc.cm ? doc.cm.options.historyEventDelay : 500)
|
4838 |
-
}
|
4839 |
-
|
4840 |
-
// Called whenever the selection changes, sets the new selection as
|
4841 |
-
// the pending selection in the history, and pushes the old pending
|
4842 |
-
// selection into the 'done' array when it was significantly
|
4843 |
-
// different (in number of selected ranges, emptiness, or time).
|
4844 |
-
function addSelectionToHistory(doc, sel, opId, options) {
|
4845 |
-
var hist = doc.history, origin = options && options.origin
|
4846 |
-
|
4847 |
-
// A new event is started when the previous origin does not match
|
4848 |
-
// the current, or the origins don't allow matching. Origins
|
4849 |
-
// starting with * are always merged, those starting with + are
|
4850 |
-
// merged when similar and close together in time.
|
4851 |
-
if (opId == hist.lastSelOp ||
|
4852 |
-
(origin && hist.lastSelOrigin == origin &&
|
4853 |
-
(hist.lastModTime == hist.lastSelTime && hist.lastOrigin == origin ||
|
4854 |
-
selectionEventCanBeMerged(doc, origin, lst(hist.done), sel))))
|
4855 |
-
{ hist.done[hist.done.length - 1] = sel }
|
4856 |
-
else
|
4857 |
-
{ pushSelectionToHistory(sel, hist.done) }
|
4858 |
-
|
4859 |
-
hist.lastSelTime = +new Date
|
4860 |
-
hist.lastSelOrigin = origin
|
4861 |
-
hist.lastSelOp = opId
|
4862 |
-
if (options && options.clearRedo !== false)
|
4863 |
-
{ clearSelectionEvents(hist.undone) }
|
4864 |
-
}
|
4865 |
-
|
4866 |
-
function pushSelectionToHistory(sel, dest) {
|
4867 |
-
var top = lst(dest)
|
4868 |
-
if (!(top && top.ranges && top.equals(sel)))
|
4869 |
-
{ dest.push(sel) }
|
4870 |
-
}
|
4871 |
-
|
4872 |
-
// Used to store marked span information in the history.
|
4873 |
-
function attachLocalSpans(doc, change, from, to) {
|
4874 |
-
var existing = change["spans_" + doc.id], n = 0
|
4875 |
-
doc.iter(Math.max(doc.first, from), Math.min(doc.first + doc.size, to), function (line) {
|
4876 |
-
if (line.markedSpans)
|
4877 |
-
{ (existing || (existing = change["spans_" + doc.id] = {}))[n] = line.markedSpans }
|
4878 |
-
++n
|
4879 |
-
})
|
4880 |
-
}
|
4881 |
-
|
4882 |
-
// When un/re-doing restores text containing marked spans, those
|
4883 |
-
// that have been explicitly cleared should not be restored.
|
4884 |
-
function removeClearedSpans(spans) {
|
4885 |
-
if (!spans) { return null }
|
4886 |
-
var out
|
4887 |
-
for (var i = 0; i < spans.length; ++i) {
|
4888 |
-
if (spans[i].marker.explicitlyCleared) { if (!out) { out = spans.slice(0, i) } }
|
4889 |
-
else if (out) { out.push(spans[i]) }
|
4890 |
-
}
|
4891 |
-
return !out ? spans : out.length ? out : null
|
4892 |
-
}
|
4893 |
-
|
4894 |
-
// Retrieve and filter the old marked spans stored in a change event.
|
4895 |
-
function getOldSpans(doc, change) {
|
4896 |
-
var found = change["spans_" + doc.id]
|
4897 |
-
if (!found) { return null }
|
4898 |
-
var nw = []
|
4899 |
-
for (var i = 0; i < change.text.length; ++i)
|
4900 |
-
{ nw.push(removeClearedSpans(found[i])) }
|
4901 |
-
return nw
|
4902 |
-
}
|
4903 |
-
|
4904 |
-
// Used for un/re-doing changes from the history. Combines the
|
4905 |
-
// result of computing the existing spans with the set of spans that
|
4906 |
-
// existed in the history (so that deleting around a span and then
|
4907 |
-
// undoing brings back the span).
|
4908 |
-
function mergeOldSpans(doc, change) {
|
4909 |
-
var old = getOldSpans(doc, change)
|
4910 |
-
var stretched = stretchSpansOverChange(doc, change)
|
4911 |
-
if (!old) { return stretched }
|
4912 |
-
if (!stretched) { return old }
|
4913 |
-
|
4914 |
-
for (var i = 0; i < old.length; ++i) {
|
4915 |
-
var oldCur = old[i], stretchCur = stretched[i]
|
4916 |
-
if (oldCur && stretchCur) {
|
4917 |
-
spans: for (var j = 0; j < stretchCur.length; ++j) {
|
4918 |
-
var span = stretchCur[j]
|
4919 |
-
for (var k = 0; k < oldCur.length; ++k)
|
4920 |
-
{ if (oldCur[k].marker == span.marker) { continue spans } }
|
4921 |
-
oldCur.push(span)
|
4922 |
-
}
|
4923 |
-
} else if (stretchCur) {
|
4924 |
-
old[i] = stretchCur
|
4925 |
-
}
|
4926 |
-
}
|
4927 |
-
return old
|
4928 |
-
}
|
4929 |
-
|
4930 |
-
// Used both to provide a JSON-safe object in .getHistory, and, when
|
4931 |
-
// detaching a document, to split the history in two
|
4932 |
-
function copyHistoryArray(events, newGroup, instantiateSel) {
|
4933 |
-
var copy = []
|
4934 |
-
for (var i = 0; i < events.length; ++i) {
|
4935 |
-
var event = events[i]
|
4936 |
-
if (event.ranges) {
|
4937 |
-
copy.push(instantiateSel ? Selection.prototype.deepCopy.call(event) : event)
|
4938 |
-
continue
|
4939 |
-
}
|
4940 |
-
var changes = event.changes, newChanges = []
|
4941 |
-
copy.push({changes: newChanges})
|
4942 |
-
for (var j = 0; j < changes.length; ++j) {
|
4943 |
-
var change = changes[j], m = (void 0)
|
4944 |
-
newChanges.push({from: change.from, to: change.to, text: change.text})
|
4945 |
-
if (newGroup) { for (var prop in change) { if (m = prop.match(/^spans_(\d+)$/)) {
|
4946 |
-
if (indexOf(newGroup, Number(m[1])) > -1) {
|
4947 |
-
lst(newChanges)[prop] = change[prop]
|
4948 |
-
delete change[prop]
|
4949 |
-
}
|
4950 |
-
} } }
|
4951 |
-
}
|
4952 |
-
}
|
4953 |
-
return copy
|
4954 |
-
}
|
4955 |
-
|
4956 |
-
// The 'scroll' parameter given to many of these indicated whether
|
4957 |
-
// the new cursor position should be scrolled into view after
|
4958 |
-
// modifying the selection.
|
4959 |
-
|
4960 |
-
// If shift is held or the extend flag is set, extends a range to
|
4961 |
-
// include a given position (and optionally a second position).
|
4962 |
-
// Otherwise, simply returns the range between the given positions.
|
4963 |
-
// Used for cursor motion and such.
|
4964 |
-
function extendRange(range, head, other, extend) {
|
4965 |
-
if (extend) {
|
4966 |
-
var anchor = range.anchor
|
4967 |
-
if (other) {
|
4968 |
-
var posBefore = cmp(head, anchor) < 0
|
4969 |
-
if (posBefore != (cmp(other, anchor) < 0)) {
|
4970 |
-
anchor = head
|
4971 |
-
head = other
|
4972 |
-
} else if (posBefore != (cmp(head, other) < 0)) {
|
4973 |
-
head = other
|
4974 |
-
}
|
4975 |
-
}
|
4976 |
-
return new Range(anchor, head)
|
4977 |
-
} else {
|
4978 |
-
return new Range(other || head, head)
|
4979 |
-
}
|
4980 |
-
}
|
4981 |
-
|
4982 |
-
// Extend the primary selection range, discard the rest.
|
4983 |
-
function extendSelection(doc, head, other, options, extend) {
|
4984 |
-
if (extend == null) { extend = doc.cm && (doc.cm.display.shift || doc.extend) }
|
4985 |
-
setSelection(doc, new Selection([extendRange(doc.sel.primary(), head, other, extend)], 0), options)
|
4986 |
-
}
|
4987 |
-
|
4988 |
-
// Extend all selections (pos is an array of selections with length
|
4989 |
-
// equal the number of selections)
|
4990 |
-
function extendSelections(doc, heads, options) {
|
4991 |
-
var out = []
|
4992 |
-
var extend = doc.cm && (doc.cm.display.shift || doc.extend)
|
4993 |
-
for (var i = 0; i < doc.sel.ranges.length; i++)
|
4994 |
-
{ out[i] = extendRange(doc.sel.ranges[i], heads[i], null, extend) }
|
4995 |
-
var newSel = normalizeSelection(out, doc.sel.primIndex)
|
4996 |
-
setSelection(doc, newSel, options)
|
4997 |
-
}
|
4998 |
-
|
4999 |
-
// Updates a single range in the selection.
|
5000 |
-
function replaceOneSelection(doc, i, range, options) {
|
5001 |
-
var ranges = doc.sel.ranges.slice(0)
|
5002 |
-
ranges[i] = range
|
5003 |
-
setSelection(doc, normalizeSelection(ranges, doc.sel.primIndex), options)
|
5004 |
-
}
|
5005 |
-
|
5006 |
-
// Reset the selection to a single range.
|
5007 |
-
function setSimpleSelection(doc, anchor, head, options) {
|
5008 |
-
setSelection(doc, simpleSelection(anchor, head), options)
|
5009 |
-
}
|
5010 |
-
|
5011 |
-
// Give beforeSelectionChange handlers a change to influence a
|
5012 |
-
// selection update.
|
5013 |
-
function filterSelectionChange(doc, sel, options) {
|
5014 |
-
var obj = {
|
5015 |
-
ranges: sel.ranges,
|
5016 |
-
update: function(ranges) {
|
5017 |
-
var this$1 = this;
|
5018 |
-
|
5019 |
-
this.ranges = []
|
5020 |
-
for (var i = 0; i < ranges.length; i++)
|
5021 |
-
{ this$1.ranges[i] = new Range(clipPos(doc, ranges[i].anchor),
|
5022 |
-
clipPos(doc, ranges[i].head)) }
|
5023 |
-
},
|
5024 |
-
origin: options && options.origin
|
5025 |
-
}
|
5026 |
-
signal(doc, "beforeSelectionChange", doc, obj)
|
5027 |
-
if (doc.cm) { signal(doc.cm, "beforeSelectionChange", doc.cm, obj) }
|
5028 |
-
if (obj.ranges != sel.ranges) { return normalizeSelection(obj.ranges, obj.ranges.length - 1) }
|
5029 |
-
else { return sel }
|
5030 |
-
}
|
5031 |
-
|
5032 |
-
function setSelectionReplaceHistory(doc, sel, options) {
|
5033 |
-
var done = doc.history.done, last = lst(done)
|
5034 |
-
if (last && last.ranges) {
|
5035 |
-
done[done.length - 1] = sel
|
5036 |
-
setSelectionNoUndo(doc, sel, options)
|
5037 |
-
} else {
|
5038 |
-
setSelection(doc, sel, options)
|
5039 |
-
}
|
5040 |
-
}
|
5041 |
-
|
5042 |
-
// Set a new selection.
|
5043 |
-
function setSelection(doc, sel, options) {
|
5044 |
-
setSelectionNoUndo(doc, sel, options)
|
5045 |
-
addSelectionToHistory(doc, doc.sel, doc.cm ? doc.cm.curOp.id : NaN, options)
|
5046 |
-
}
|
5047 |
-
|
5048 |
-
function setSelectionNoUndo(doc, sel, options) {
|
5049 |
-
if (hasHandler(doc, "beforeSelectionChange") || doc.cm && hasHandler(doc.cm, "beforeSelectionChange"))
|
5050 |
-
{ sel = filterSelectionChange(doc, sel, options) }
|
5051 |
-
|
5052 |
-
var bias = options && options.bias ||
|
5053 |
-
(cmp(sel.primary().head, doc.sel.primary().head) < 0 ? -1 : 1)
|
5054 |
-
setSelectionInner(doc, skipAtomicInSelection(doc, sel, bias, true))
|
5055 |
-
|
5056 |
-
if (!(options && options.scroll === false) && doc.cm)
|
5057 |
-
{ ensureCursorVisible(doc.cm) }
|
5058 |
-
}
|
5059 |
-
|
5060 |
-
function setSelectionInner(doc, sel) {
|
5061 |
-
if (sel.equals(doc.sel)) { return }
|
5062 |
-
|
5063 |
-
doc.sel = sel
|
5064 |
-
|
5065 |
-
if (doc.cm) {
|
5066 |
-
doc.cm.curOp.updateInput = doc.cm.curOp.selectionChanged = true
|
5067 |
-
signalCursorActivity(doc.cm)
|
5068 |
-
}
|
5069 |
-
signalLater(doc, "cursorActivity", doc)
|
5070 |
-
}
|
5071 |
-
|
5072 |
-
// Verify that the selection does not partially select any atomic
|
5073 |
-
// marked ranges.
|
5074 |
-
function reCheckSelection(doc) {
|
5075 |
-
setSelectionInner(doc, skipAtomicInSelection(doc, doc.sel, null, false))
|
5076 |
-
}
|
5077 |
-
|
5078 |
-
// Return a selection that does not partially select any atomic
|
5079 |
-
// ranges.
|
5080 |
-
function skipAtomicInSelection(doc, sel, bias, mayClear) {
|
5081 |
-
var out
|
5082 |
-
for (var i = 0; i < sel.ranges.length; i++) {
|
5083 |
-
var range = sel.ranges[i]
|
5084 |
-
var old = sel.ranges.length == doc.sel.ranges.length && doc.sel.ranges[i]
|
5085 |
-
var newAnchor = skipAtomic(doc, range.anchor, old && old.anchor, bias, mayClear)
|
5086 |
-
var newHead = skipAtomic(doc, range.head, old && old.head, bias, mayClear)
|
5087 |
-
if (out || newAnchor != range.anchor || newHead != range.head) {
|
5088 |
-
if (!out) { out = sel.ranges.slice(0, i) }
|
5089 |
-
out[i] = new Range(newAnchor, newHead)
|
5090 |
-
}
|
5091 |
-
}
|
5092 |
-
return out ? normalizeSelection(out, sel.primIndex) : sel
|
5093 |
-
}
|
5094 |
-
|
5095 |
-
function skipAtomicInner(doc, pos, oldPos, dir, mayClear) {
|
5096 |
-
var line = getLine(doc, pos.line)
|
5097 |
-
if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) {
|
5098 |
-
var sp = line.markedSpans[i], m = sp.marker
|
5099 |
-
if ((sp.from == null || (m.inclusiveLeft ? sp.from <= pos.ch : sp.from < pos.ch)) &&
|
5100 |
-
(sp.to == null || (m.inclusiveRight ? sp.to >= pos.ch : sp.to > pos.ch))) {
|
5101 |
-
if (mayClear) {
|
5102 |
-
signal(m, "beforeCursorEnter")
|
5103 |
-
if (m.explicitlyCleared) {
|
5104 |
-
if (!line.markedSpans) { break }
|
5105 |
-
else {--i; continue}
|
5106 |
-
}
|
5107 |
-
}
|
5108 |
-
if (!m.atomic) { continue }
|
5109 |
-
|
5110 |
-
if (oldPos) {
|
5111 |
-
var near = m.find(dir < 0 ? 1 : -1), diff = (void 0)
|
5112 |
-
if (dir < 0 ? m.inclusiveRight : m.inclusiveLeft)
|
5113 |
-
{ near = movePos(doc, near, -dir, near && near.line == pos.line ? line : null) }
|
5114 |
-
if (near && near.line == pos.line && (diff = cmp(near, oldPos)) && (dir < 0 ? diff < 0 : diff > 0))
|
5115 |
-
{ return skipAtomicInner(doc, near, pos, dir, mayClear) }
|
5116 |
-
}
|
5117 |
-
|
5118 |
-
var far = m.find(dir < 0 ? -1 : 1)
|
5119 |
-
if (dir < 0 ? m.inclusiveLeft : m.inclusiveRight)
|
5120 |
-
{ far = movePos(doc, far, dir, far.line == pos.line ? line : null) }
|
5121 |
-
return far ? skipAtomicInner(doc, far, pos, dir, mayClear) : null
|
5122 |
-
}
|
5123 |
-
} }
|
5124 |
-
return pos
|
5125 |
-
}
|
5126 |
-
|
5127 |
-
// Ensure a given position is not inside an atomic range.
|
5128 |
-
function skipAtomic(doc, pos, oldPos, bias, mayClear) {
|
5129 |
-
var dir = bias || 1
|
5130 |
-
var found = skipAtomicInner(doc, pos, oldPos, dir, mayClear) ||
|
5131 |
-
(!mayClear && skipAtomicInner(doc, pos, oldPos, dir, true)) ||
|
5132 |
-
skipAtomicInner(doc, pos, oldPos, -dir, mayClear) ||
|
5133 |
-
(!mayClear && skipAtomicInner(doc, pos, oldPos, -dir, true))
|
5134 |
-
if (!found) {
|
5135 |
-
doc.cantEdit = true
|
5136 |
-
return Pos(doc.first, 0)
|
5137 |
-
}
|
5138 |
-
return found
|
5139 |
-
}
|
5140 |
-
|
5141 |
-
function movePos(doc, pos, dir, line) {
|
5142 |
-
if (dir < 0 && pos.ch == 0) {
|
5143 |
-
if (pos.line > doc.first) { return clipPos(doc, Pos(pos.line - 1)) }
|
5144 |
-
else { return null }
|
5145 |
-
} else if (dir > 0 && pos.ch == (line || getLine(doc, pos.line)).text.length) {
|
5146 |
-
if (pos.line < doc.first + doc.size - 1) { return Pos(pos.line + 1, 0) }
|
5147 |
-
else { return null }
|
5148 |
-
} else {
|
5149 |
-
return new Pos(pos.line, pos.ch + dir)
|
5150 |
-
}
|
5151 |
-
}
|
5152 |
-
|
5153 |
-
function selectAll(cm) {
|
5154 |
-
cm.setSelection(Pos(cm.firstLine(), 0), Pos(cm.lastLine()), sel_dontScroll)
|
5155 |
-
}
|
5156 |
-
|
5157 |
-
// UPDATING
|
5158 |
-
|
5159 |
-
// Allow "beforeChange" event handlers to influence a change
|
5160 |
-
function filterChange(doc, change, update) {
|
5161 |
-
var obj = {
|
5162 |
-
canceled: false,
|
5163 |
-
from: change.from,
|
5164 |
-
to: change.to,
|
5165 |
-
text: change.text,
|
5166 |
-
origin: change.origin,
|
5167 |
-
cancel: function () { return obj.canceled = true; }
|
5168 |
-
}
|
5169 |
-
if (update) { obj.update = function (from, to, text, origin) {
|
5170 |
-
if (from) { obj.from = clipPos(doc, from) }
|
5171 |
-
if (to) { obj.to = clipPos(doc, to) }
|
5172 |
-
if (text) { obj.text = text }
|
5173 |
-
if (origin !== undefined) { obj.origin = origin }
|
5174 |
-
} }
|
5175 |
-
signal(doc, "beforeChange", doc, obj)
|
5176 |
-
if (doc.cm) { signal(doc.cm, "beforeChange", doc.cm, obj) }
|
5177 |
-
|
5178 |
-
if (obj.canceled) { return null }
|
5179 |
-
return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin}
|
5180 |
-
}
|
5181 |
-
|
5182 |
-
// Apply a change to a document, and add it to the document's
|
5183 |
-
// history, and propagating it to all linked documents.
|
5184 |
-
function makeChange(doc, change, ignoreReadOnly) {
|
5185 |
-
if (doc.cm) {
|
5186 |
-
if (!doc.cm.curOp) { return operation(doc.cm, makeChange)(doc, change, ignoreReadOnly) }
|
5187 |
-
if (doc.cm.state.suppressEdits) { return }
|
5188 |
-
}
|
5189 |
-
|
5190 |
-
if (hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")) {
|
5191 |
-
change = filterChange(doc, change, true)
|
5192 |
-
if (!change) { return }
|
5193 |
-
}
|
5194 |
-
|
5195 |
-
// Possibly split or suppress the update based on the presence
|
5196 |
-
// of read-only spans in its range.
|
5197 |
-
var split = sawReadOnlySpans && !ignoreReadOnly && removeReadOnlyRanges(doc, change.from, change.to)
|
5198 |
-
if (split) {
|
5199 |
-
for (var i = split.length - 1; i >= 0; --i)
|
5200 |
-
{ makeChangeInner(doc, {from: split[i].from, to: split[i].to, text: i ? [""] : change.text, origin: change.origin}) }
|
5201 |
-
} else {
|
5202 |
-
makeChangeInner(doc, change)
|
5203 |
-
}
|
5204 |
-
}
|
5205 |
-
|
5206 |
-
function makeChangeInner(doc, change) {
|
5207 |
-
if (change.text.length == 1 && change.text[0] == "" && cmp(change.from, change.to) == 0) { return }
|
5208 |
-
var selAfter = computeSelAfterChange(doc, change)
|
5209 |
-
addChangeToHistory(doc, change, selAfter, doc.cm ? doc.cm.curOp.id : NaN)
|
5210 |
-
|
5211 |
-
makeChangeSingleDoc(doc, change, selAfter, stretchSpansOverChange(doc, change))
|
5212 |
-
var rebased = []
|
5213 |
-
|
5214 |
-
linkedDocs(doc, function (doc, sharedHist) {
|
5215 |
-
if (!sharedHist && indexOf(rebased, doc.history) == -1) {
|
5216 |
-
rebaseHist(doc.history, change)
|
5217 |
-
rebased.push(doc.history)
|
5218 |
-
}
|
5219 |
-
makeChangeSingleDoc(doc, change, null, stretchSpansOverChange(doc, change))
|
5220 |
-
})
|
5221 |
-
}
|
5222 |
-
|
5223 |
-
// Revert a change stored in a document's history.
|
5224 |
-
function makeChangeFromHistory(doc, type, allowSelectionOnly) {
|
5225 |
-
var suppress = doc.cm && doc.cm.state.suppressEdits
|
5226 |
-
if (suppress && !allowSelectionOnly) { return }
|
5227 |
-
|
5228 |
-
var hist = doc.history, event, selAfter = doc.sel
|
5229 |
-
var source = type == "undo" ? hist.done : hist.undone, dest = type == "undo" ? hist.undone : hist.done
|
5230 |
-
|
5231 |
-
// Verify that there is a useable event (so that ctrl-z won't
|
5232 |
-
// needlessly clear selection events)
|
5233 |
-
var i = 0
|
5234 |
-
for (; i < source.length; i++) {
|
5235 |
-
event = source[i]
|
5236 |
-
if (allowSelectionOnly ? event.ranges && !event.equals(doc.sel) : !event.ranges)
|
5237 |
-
{ break }
|
5238 |
-
}
|
5239 |
-
if (i == source.length) { return }
|
5240 |
-
hist.lastOrigin = hist.lastSelOrigin = null
|
5241 |
-
|
5242 |
-
for (;;) {
|
5243 |
-
event = source.pop()
|
5244 |
-
if (event.ranges) {
|
5245 |
-
pushSelectionToHistory(event, dest)
|
5246 |
-
if (allowSelectionOnly && !event.equals(doc.sel)) {
|
5247 |
-
setSelection(doc, event, {clearRedo: false})
|
5248 |
-
return
|
5249 |
-
}
|
5250 |
-
selAfter = event
|
5251 |
-
} else if (suppress) {
|
5252 |
-
source.push(event)
|
5253 |
-
return
|
5254 |
-
} else { break }
|
5255 |
-
}
|
5256 |
-
|
5257 |
-
// Build up a reverse change object to add to the opposite history
|
5258 |
-
// stack (redo when undoing, and vice versa).
|
5259 |
-
var antiChanges = []
|
5260 |
-
pushSelectionToHistory(selAfter, dest)
|
5261 |
-
dest.push({changes: antiChanges, generation: hist.generation})
|
5262 |
-
hist.generation = event.generation || ++hist.maxGeneration
|
5263 |
-
|
5264 |
-
var filter = hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")
|
5265 |
-
|
5266 |
-
var loop = function ( i ) {
|
5267 |
-
var change = event.changes[i]
|
5268 |
-
change.origin = type
|
5269 |
-
if (filter && !filterChange(doc, change, false)) {
|
5270 |
-
source.length = 0
|
5271 |
-
return {}
|
5272 |
-
}
|
5273 |
-
|
5274 |
-
antiChanges.push(historyChangeFromChange(doc, change))
|
5275 |
-
|
5276 |
-
var after = i ? computeSelAfterChange(doc, change) : lst(source)
|
5277 |
-
makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change))
|
5278 |
-
if (!i && doc.cm) { doc.cm.scrollIntoView({from: change.from, to: changeEnd(change)}) }
|
5279 |
-
var rebased = []
|
5280 |
-
|
5281 |
-
// Propagate to the linked documents
|
5282 |
-
linkedDocs(doc, function (doc, sharedHist) {
|
5283 |
-
if (!sharedHist && indexOf(rebased, doc.history) == -1) {
|
5284 |
-
rebaseHist(doc.history, change)
|
5285 |
-
rebased.push(doc.history)
|
5286 |
-
}
|
5287 |
-
makeChangeSingleDoc(doc, change, null, mergeOldSpans(doc, change))
|
5288 |
-
})
|
5289 |
-
};
|
5290 |
-
|
5291 |
-
for (var i$1 = event.changes.length - 1; i$1 >= 0; --i$1) {
|
5292 |
-
var returned = loop( i$1 );
|
5293 |
-
|
5294 |
-
if ( returned ) return returned.v;
|
5295 |
-
}
|
5296 |
-
}
|
5297 |
-
|
5298 |
-
// Sub-views need their line numbers shifted when text is added
|
5299 |
-
// above or below them in the parent document.
|
5300 |
-
function shiftDoc(doc, distance) {
|
5301 |
-
if (distance == 0) { return }
|
5302 |
-
doc.first += distance
|
5303 |
-
doc.sel = new Selection(map(doc.sel.ranges, function (range) { return new Range(
|
5304 |
-
Pos(range.anchor.line + distance, range.anchor.ch),
|
5305 |
-
Pos(range.head.line + distance, range.head.ch)
|
5306 |
-
); }), doc.sel.primIndex)
|
5307 |
-
if (doc.cm) {
|
5308 |
-
regChange(doc.cm, doc.first, doc.first - distance, distance)
|
5309 |
-
for (var d = doc.cm.display, l = d.viewFrom; l < d.viewTo; l++)
|
5310 |
-
{ regLineChange(doc.cm, l, "gutter") }
|
5311 |
-
}
|
5312 |
-
}
|
5313 |
-
|
5314 |
-
// More lower-level change function, handling only a single document
|
5315 |
-
// (not linked ones).
|
5316 |
-
function makeChangeSingleDoc(doc, change, selAfter, spans) {
|
5317 |
-
if (doc.cm && !doc.cm.curOp)
|
5318 |
-
{ return operation(doc.cm, makeChangeSingleDoc)(doc, change, selAfter, spans) }
|
5319 |
-
|
5320 |
-
if (change.to.line < doc.first) {
|
5321 |
-
shiftDoc(doc, change.text.length - 1 - (change.to.line - change.from.line))
|
5322 |
-
return
|
5323 |
-
}
|
5324 |
-
if (change.from.line > doc.lastLine()) { return }
|
5325 |
-
|
5326 |
-
// Clip the change to the size of this doc
|
5327 |
-
if (change.from.line < doc.first) {
|
5328 |
-
var shift = change.text.length - 1 - (doc.first - change.from.line)
|
5329 |
-
shiftDoc(doc, shift)
|
5330 |
-
change = {from: Pos(doc.first, 0), to: Pos(change.to.line + shift, change.to.ch),
|
5331 |
-
text: [lst(change.text)], origin: change.origin}
|
5332 |
-
}
|
5333 |
-
var last = doc.lastLine()
|
5334 |
-
if (change.to.line > last) {
|
5335 |
-
change = {from: change.from, to: Pos(last, getLine(doc, last).text.length),
|
5336 |
-
text: [change.text[0]], origin: change.origin}
|
5337 |
-
}
|
5338 |
-
|
5339 |
-
change.removed = getBetween(doc, change.from, change.to)
|
5340 |
-
|
5341 |
-
if (!selAfter) { selAfter = computeSelAfterChange(doc, change) }
|
5342 |
-
if (doc.cm) { makeChangeSingleDocInEditor(doc.cm, change, spans) }
|
5343 |
-
else { updateDoc(doc, change, spans) }
|
5344 |
-
setSelectionNoUndo(doc, selAfter, sel_dontScroll)
|
5345 |
-
}
|
5346 |
-
|
5347 |
-
// Handle the interaction of a change to a document with the editor
|
5348 |
-
// that this document is part of.
|
5349 |
-
function makeChangeSingleDocInEditor(cm, change, spans) {
|
5350 |
-
var doc = cm.doc, display = cm.display, from = change.from, to = change.to
|
5351 |
-
|
5352 |
-
var recomputeMaxLength = false, checkWidthStart = from.line
|
5353 |
-
if (!cm.options.lineWrapping) {
|
5354 |
-
checkWidthStart = lineNo(visualLine(getLine(doc, from.line)))
|
5355 |
-
doc.iter(checkWidthStart, to.line + 1, function (line) {
|
5356 |
-
if (line == display.maxLine) {
|
5357 |
-
recomputeMaxLength = true
|
5358 |
-
return true
|
5359 |
-
}
|
5360 |
-
})
|
5361 |
-
}
|
5362 |
-
|
5363 |
-
if (doc.sel.contains(change.from, change.to) > -1)
|
5364 |
-
{ signalCursorActivity(cm) }
|
5365 |
-
|
5366 |
-
updateDoc(doc, change, spans, estimateHeight(cm))
|
5367 |
-
|
5368 |
-
if (!cm.options.lineWrapping) {
|
5369 |
-
doc.iter(checkWidthStart, from.line + change.text.length, function (line) {
|
5370 |
-
var len = lineLength(line)
|
5371 |
-
if (len > display.maxLineLength) {
|
5372 |
-
display.maxLine = line
|
5373 |
-
display.maxLineLength = len
|
5374 |
-
display.maxLineChanged = true
|
5375 |
-
recomputeMaxLength = false
|
5376 |
-
}
|
5377 |
-
})
|
5378 |
-
if (recomputeMaxLength) { cm.curOp.updateMaxLine = true }
|
5379 |
-
}
|
5380 |
-
|
5381 |
-
retreatFrontier(doc, from.line)
|
5382 |
-
startWorker(cm, 400)
|
5383 |
-
|
5384 |
-
var lendiff = change.text.length - (to.line - from.line) - 1
|
5385 |
-
// Remember that these lines changed, for updating the display
|
5386 |
-
if (change.full)
|
5387 |
-
{ regChange(cm) }
|
5388 |
-
else if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change))
|
5389 |
-
{ regLineChange(cm, from.line, "text") }
|
5390 |
-
else
|
5391 |
-
{ regChange(cm, from.line, to.line + 1, lendiff) }
|
5392 |
-
|
5393 |
-
var changesHandler = hasHandler(cm, "changes"), changeHandler = hasHandler(cm, "change")
|
5394 |
-
if (changeHandler || changesHandler) {
|
5395 |
-
var obj = {
|
5396 |
-
from: from, to: to,
|
5397 |
-
text: change.text,
|
5398 |
-
removed: change.removed,
|
5399 |
-
origin: change.origin
|
5400 |
-
}
|
5401 |
-
if (changeHandler) { signalLater(cm, "change", cm, obj) }
|
5402 |
-
if (changesHandler) { (cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj) }
|
5403 |
-
}
|
5404 |
-
cm.display.selForContextMenu = null
|
5405 |
-
}
|
5406 |
-
|
5407 |
-
function replaceRange(doc, code, from, to, origin) {
|
5408 |
-
if (!to) { to = from }
|
5409 |
-
if (cmp(to, from) < 0) { var assign;
|
5410 |
-
(assign = [to, from], from = assign[0], to = assign[1], assign) }
|
5411 |
-
if (typeof code == "string") { code = doc.splitLines(code) }
|
5412 |
-
makeChange(doc, {from: from, to: to, text: code, origin: origin})
|
5413 |
-
}
|
5414 |
-
|
5415 |
-
// Rebasing/resetting history to deal with externally-sourced changes
|
5416 |
-
|
5417 |
-
function rebaseHistSelSingle(pos, from, to, diff) {
|
5418 |
-
if (to < pos.line) {
|
5419 |
-
pos.line += diff
|
5420 |
-
} else if (from < pos.line) {
|
5421 |
-
pos.line = from
|
5422 |
-
pos.ch = 0
|
5423 |
-
}
|
5424 |
-
}
|
5425 |
-
|
5426 |
-
// Tries to rebase an array of history events given a change in the
|
5427 |
-
// document. If the change touches the same lines as the event, the
|
5428 |
-
// event, and everything 'behind' it, is discarded. If the change is
|
5429 |
-
// before the event, the event's positions are updated. Uses a
|
5430 |
-
// copy-on-write scheme for the positions, to avoid having to
|
5431 |
-
// reallocate them all on every rebase, but also avoid problems with
|
5432 |
-
// shared position objects being unsafely updated.
|
5433 |
-
function rebaseHistArray(array, from, to, diff) {
|
5434 |
-
for (var i = 0; i < array.length; ++i) {
|
5435 |
-
var sub = array[i], ok = true
|
5436 |
-
if (sub.ranges) {
|
5437 |
-
if (!sub.copied) { sub = array[i] = sub.deepCopy(); sub.copied = true }
|
5438 |
-
for (var j = 0; j < sub.ranges.length; j++) {
|
5439 |
-
rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff)
|
5440 |
-
rebaseHistSelSingle(sub.ranges[j].head, from, to, diff)
|
5441 |
-
}
|
5442 |
-
continue
|
5443 |
-
}
|
5444 |
-
for (var j$1 = 0; j$1 < sub.changes.length; ++j$1) {
|
5445 |
-
var cur = sub.changes[j$1]
|
5446 |
-
if (to < cur.from.line) {
|
5447 |
-
cur.from = Pos(cur.from.line + diff, cur.from.ch)
|
5448 |
-
cur.to = Pos(cur.to.line + diff, cur.to.ch)
|
5449 |
-
} else if (from <= cur.to.line) {
|
5450 |
-
ok = false
|
5451 |
-
break
|
5452 |
-
}
|
5453 |
-
}
|
5454 |
-
if (!ok) {
|
5455 |
-
array.splice(0, i + 1)
|
5456 |
-
i = 0
|
5457 |
-
}
|
5458 |
-
}
|
5459 |
-
}
|
5460 |
-
|
5461 |
-
function rebaseHist(hist, change) {
|
5462 |
-
var from = change.from.line, to = change.to.line, diff = change.text.length - (to - from) - 1
|
5463 |
-
rebaseHistArray(hist.done, from, to, diff)
|
5464 |
-
rebaseHistArray(hist.undone, from, to, diff)
|
5465 |
-
}
|
5466 |
-
|
5467 |
-
// Utility for applying a change to a line by handle or number,
|
5468 |
-
// returning the number and optionally registering the line as
|
5469 |
-
// changed.
|
5470 |
-
function changeLine(doc, handle, changeType, op) {
|
5471 |
-
var no = handle, line = handle
|
5472 |
-
if (typeof handle == "number") { line = getLine(doc, clipLine(doc, handle)) }
|
5473 |
-
else { no = lineNo(handle) }
|
5474 |
-
if (no == null) { return null }
|
5475 |
-
if (op(line, no) && doc.cm) { regLineChange(doc.cm, no, changeType) }
|
5476 |
-
return line
|
5477 |
-
}
|
5478 |
-
|
5479 |
-
// The document is represented as a BTree consisting of leaves, with
|
5480 |
-
// chunk of lines in them, and branches, with up to ten leaves or
|
5481 |
-
// other branch nodes below them. The top node is always a branch
|
5482 |
-
// node, and is the document object itself (meaning it has
|
5483 |
-
// additional methods and properties).
|
5484 |
-
//
|
5485 |
-
// All nodes have parent links. The tree is used both to go from
|
5486 |
-
// line numbers to line objects, and to go from objects to numbers.
|
5487 |
-
// It also indexes by height, and is used to convert between height
|
5488 |
-
// and line object, and to find the total height of the document.
|
5489 |
-
//
|
5490 |
-
// See also http://marijnhaverbeke.nl/blog/codemirror-line-tree.html
|
5491 |
-
|
5492 |
-
function LeafChunk(lines) {
|
5493 |
-
var this$1 = this;
|
5494 |
-
|
5495 |
-
this.lines = lines
|
5496 |
-
this.parent = null
|
5497 |
-
var height = 0
|
5498 |
-
for (var i = 0; i < lines.length; ++i) {
|
5499 |
-
lines[i].parent = this$1
|
5500 |
-
height += lines[i].height
|
5501 |
-
}
|
5502 |
-
this.height = height
|
5503 |
-
}
|
5504 |
-
|
5505 |
-
LeafChunk.prototype = {
|
5506 |
-
chunkSize: function chunkSize() { return this.lines.length },
|
5507 |
-
|
5508 |
-
// Remove the n lines at offset 'at'.
|
5509 |
-
removeInner: function removeInner(at, n) {
|
5510 |
-
var this$1 = this;
|
5511 |
-
|
5512 |
-
for (var i = at, e = at + n; i < e; ++i) {
|
5513 |
-
var line = this$1.lines[i]
|
5514 |
-
this$1.height -= line.height
|
5515 |
-
cleanUpLine(line)
|
5516 |
-
signalLater(line, "delete")
|
5517 |
-
}
|
5518 |
-
this.lines.splice(at, n)
|
5519 |
-
},
|
5520 |
-
|
5521 |
-
// Helper used to collapse a small branch into a single leaf.
|
5522 |
-
collapse: function collapse(lines) {
|
5523 |
-
lines.push.apply(lines, this.lines)
|
5524 |
-
},
|
5525 |
-
|
5526 |
-
// Insert the given array of lines at offset 'at', count them as
|
5527 |
-
// having the given height.
|
5528 |
-
insertInner: function insertInner(at, lines, height) {
|
5529 |
-
var this$1 = this;
|
5530 |
-
|
5531 |
-
this.height += height
|
5532 |
-
this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at))
|
5533 |
-
for (var i = 0; i < lines.length; ++i) { lines[i].parent = this$1 }
|
5534 |
-
},
|
5535 |
-
|
5536 |
-
// Used to iterate over a part of the tree.
|
5537 |
-
iterN: function iterN(at, n, op) {
|
5538 |
-
var this$1 = this;
|
5539 |
-
|
5540 |
-
for (var e = at + n; at < e; ++at)
|
5541 |
-
{ if (op(this$1.lines[at])) { return true } }
|
5542 |
-
}
|
5543 |
-
}
|
5544 |
-
|
5545 |
-
function BranchChunk(children) {
|
5546 |
-
var this$1 = this;
|
5547 |
-
|
5548 |
-
this.children = children
|
5549 |
-
var size = 0, height = 0
|
5550 |
-
for (var i = 0; i < children.length; ++i) {
|
5551 |
-
var ch = children[i]
|
5552 |
-
size += ch.chunkSize(); height += ch.height
|
5553 |
-
ch.parent = this$1
|
5554 |
-
}
|
5555 |
-
this.size = size
|
5556 |
-
this.height = height
|
5557 |
-
this.parent = null
|
5558 |
-
}
|
5559 |
-
|
5560 |
-
BranchChunk.prototype = {
|
5561 |
-
chunkSize: function chunkSize() { return this.size },
|
5562 |
-
|
5563 |
-
removeInner: function removeInner(at, n) {
|
5564 |
-
var this$1 = this;
|
5565 |
-
|
5566 |
-
this.size -= n
|
5567 |
-
for (var i = 0; i < this.children.length; ++i) {
|
5568 |
-
var child = this$1.children[i], sz = child.chunkSize()
|
5569 |
-
if (at < sz) {
|
5570 |
-
var rm = Math.min(n, sz - at), oldHeight = child.height
|
5571 |
-
child.removeInner(at, rm)
|
5572 |
-
this$1.height -= oldHeight - child.height
|
5573 |
-
if (sz == rm) { this$1.children.splice(i--, 1); child.parent = null }
|
5574 |
-
if ((n -= rm) == 0) { break }
|
5575 |
-
at = 0
|
5576 |
-
} else { at -= sz }
|
5577 |
-
}
|
5578 |
-
// If the result is smaller than 25 lines, ensure that it is a
|
5579 |
-
// single leaf node.
|
5580 |
-
if (this.size - n < 25 &&
|
5581 |
-
(this.children.length > 1 || !(this.children[0] instanceof LeafChunk))) {
|
5582 |
-
var lines = []
|
5583 |
-
this.collapse(lines)
|
5584 |
-
this.children = [new LeafChunk(lines)]
|
5585 |
-
this.children[0].parent = this
|
5586 |
-
}
|
5587 |
-
},
|
5588 |
-
|
5589 |
-
collapse: function collapse(lines) {
|
5590 |
-
var this$1 = this;
|
5591 |
-
|
5592 |
-
for (var i = 0; i < this.children.length; ++i) { this$1.children[i].collapse(lines) }
|
5593 |
-
},
|
5594 |
-
|
5595 |
-
insertInner: function insertInner(at, lines, height) {
|
5596 |
-
var this$1 = this;
|
5597 |
-
|
5598 |
-
this.size += lines.length
|
5599 |
-
this.height += height
|
5600 |
-
for (var i = 0; i < this.children.length; ++i) {
|
5601 |
-
var child = this$1.children[i], sz = child.chunkSize()
|
5602 |
-
if (at <= sz) {
|
5603 |
-
child.insertInner(at, lines, height)
|
5604 |
-
if (child.lines && child.lines.length > 50) {
|
5605 |
-
// To avoid memory thrashing when child.lines is huge (e.g. first view of a large file), it's never spliced.
|
5606 |
-
// Instead, small slices are taken. They're taken in order because sequential memory accesses are fastest.
|
5607 |
-
var remaining = child.lines.length % 25 + 25
|
5608 |
-
for (var pos = remaining; pos < child.lines.length;) {
|
5609 |
-
var leaf = new LeafChunk(child.lines.slice(pos, pos += 25))
|
5610 |
-
child.height -= leaf.height
|
5611 |
-
this$1.children.splice(++i, 0, leaf)
|
5612 |
-
leaf.parent = this$1
|
5613 |
-
}
|
5614 |
-
child.lines = child.lines.slice(0, remaining)
|
5615 |
-
this$1.maybeSpill()
|
5616 |
-
}
|
5617 |
-
break
|
5618 |
-
}
|
5619 |
-
at -= sz
|
5620 |
-
}
|
5621 |
-
},
|
5622 |
-
|
5623 |
-
// When a node has grown, check whether it should be split.
|
5624 |
-
maybeSpill: function maybeSpill() {
|
5625 |
-
if (this.children.length <= 10) { return }
|
5626 |
-
var me = this
|
5627 |
-
do {
|
5628 |
-
var spilled = me.children.splice(me.children.length - 5, 5)
|
5629 |
-
var sibling = new BranchChunk(spilled)
|
5630 |
-
if (!me.parent) { // Become the parent node
|
5631 |
-
var copy = new BranchChunk(me.children)
|
5632 |
-
copy.parent = me
|
5633 |
-
me.children = [copy, sibling]
|
5634 |
-
me = copy
|
5635 |
-
} else {
|
5636 |
-
me.size -= sibling.size
|
5637 |
-
me.height -= sibling.height
|
5638 |
-
var myIndex = indexOf(me.parent.children, me)
|
5639 |
-
me.parent.children.splice(myIndex + 1, 0, sibling)
|
5640 |
-
}
|
5641 |
-
sibling.parent = me.parent
|
5642 |
-
} while (me.children.length > 10)
|
5643 |
-
me.parent.maybeSpill()
|
5644 |
-
},
|
5645 |
-
|
5646 |
-
iterN: function iterN(at, n, op) {
|
5647 |
-
var this$1 = this;
|
5648 |
-
|
5649 |
-
for (var i = 0; i < this.children.length; ++i) {
|
5650 |
-
var child = this$1.children[i], sz = child.chunkSize()
|
5651 |
-
if (at < sz) {
|
5652 |
-
var used = Math.min(n, sz - at)
|
5653 |
-
if (child.iterN(at, used, op)) { return true }
|
5654 |
-
if ((n -= used) == 0) { break }
|
5655 |
-
at = 0
|
5656 |
-
} else { at -= sz }
|
5657 |
-
}
|
5658 |
-
}
|
5659 |
-
}
|
5660 |
-
|
5661 |
-
// Line widgets are block elements displayed above or below a line.
|
5662 |
-
|
5663 |
-
var LineWidget = function(doc, node, options) {
|
5664 |
-
var this$1 = this;
|
5665 |
-
|
5666 |
-
if (options) { for (var opt in options) { if (options.hasOwnProperty(opt))
|
5667 |
-
{ this$1[opt] = options[opt] } } }
|
5668 |
-
this.doc = doc
|
5669 |
-
this.node = node
|
5670 |
-
};
|
5671 |
-
|
5672 |
-
LineWidget.prototype.clear = function () {
|
5673 |
-
var this$1 = this;
|
5674 |
-
|
5675 |
-
var cm = this.doc.cm, ws = this.line.widgets, line = this.line, no = lineNo(line)
|
5676 |
-
if (no == null || !ws) { return }
|
5677 |
-
for (var i = 0; i < ws.length; ++i) { if (ws[i] == this$1) { ws.splice(i--, 1) } }
|
5678 |
-
if (!ws.length) { line.widgets = null }
|
5679 |
-
var height = widgetHeight(this)
|
5680 |
-
updateLineHeight(line, Math.max(0, line.height - height))
|
5681 |
-
if (cm) {
|
5682 |
-
runInOp(cm, function () {
|
5683 |
-
adjustScrollWhenAboveVisible(cm, line, -height)
|
5684 |
-
regLineChange(cm, no, "widget")
|
5685 |
-
})
|
5686 |
-
signalLater(cm, "lineWidgetCleared", cm, this, no)
|
5687 |
-
}
|
5688 |
-
};
|
5689 |
-
|
5690 |
-
LineWidget.prototype.changed = function () {
|
5691 |
-
var this$1 = this;
|
5692 |
-
|
5693 |
-
var oldH = this.height, cm = this.doc.cm, line = this.line
|
5694 |
-
this.height = null
|
5695 |
-
var diff = widgetHeight(this) - oldH
|
5696 |
-
if (!diff) { return }
|
5697 |
-
updateLineHeight(line, line.height + diff)
|
5698 |
-
if (cm) {
|
5699 |
-
runInOp(cm, function () {
|
5700 |
-
cm.curOp.forceUpdate = true
|
5701 |
-
adjustScrollWhenAboveVisible(cm, line, diff)
|
5702 |
-
signalLater(cm, "lineWidgetChanged", cm, this$1, lineNo(line))
|
5703 |
-
})
|
5704 |
-
}
|
5705 |
-
};
|
5706 |
-
eventMixin(LineWidget)
|
5707 |
-
|
5708 |
-
function adjustScrollWhenAboveVisible(cm, line, diff) {
|
5709 |
-
if (heightAtLine(line) < ((cm.curOp && cm.curOp.scrollTop) || cm.doc.scrollTop))
|
5710 |
-
{ addToScrollTop(cm, diff) }
|
5711 |
-
}
|
5712 |
-
|
5713 |
-
function addLineWidget(doc, handle, node, options) {
|
5714 |
-
var widget = new LineWidget(doc, node, options)
|
5715 |
-
var cm = doc.cm
|
5716 |
-
if (cm && widget.noHScroll) { cm.display.alignWidgets = true }
|
5717 |
-
changeLine(doc, handle, "widget", function (line) {
|
5718 |
-
var widgets = line.widgets || (line.widgets = [])
|
5719 |
-
if (widget.insertAt == null) { widgets.push(widget) }
|
5720 |
-
else { widgets.splice(Math.min(widgets.length - 1, Math.max(0, widget.insertAt)), 0, widget) }
|
5721 |
-
widget.line = line
|
5722 |
-
if (cm && !lineIsHidden(doc, line)) {
|
5723 |
-
var aboveVisible = heightAtLine(line) < doc.scrollTop
|
5724 |
-
updateLineHeight(line, line.height + widgetHeight(widget))
|
5725 |
-
if (aboveVisible) { addToScrollTop(cm, widget.height) }
|
5726 |
-
cm.curOp.forceUpdate = true
|
5727 |
-
}
|
5728 |
-
return true
|
5729 |
-
})
|
5730 |
-
if (cm) { signalLater(cm, "lineWidgetAdded", cm, widget, typeof handle == "number" ? handle : lineNo(handle)) }
|
5731 |
-
return widget
|
5732 |
-
}
|
5733 |
-
|
5734 |
-
// TEXTMARKERS
|
5735 |
-
|
5736 |
-
// Created with markText and setBookmark methods. A TextMarker is a
|
5737 |
-
// handle that can be used to clear or find a marked position in the
|
5738 |
-
// document. Line objects hold arrays (markedSpans) containing
|
5739 |
-
// {from, to, marker} object pointing to such marker objects, and
|
5740 |
-
// indicating that such a marker is present on that line. Multiple
|
5741 |
-
// lines may point to the same marker when it spans across lines.
|
5742 |
-
// The spans will have null for their from/to properties when the
|
5743 |
-
// marker continues beyond the start/end of the line. Markers have
|
5744 |
-
// links back to the lines they currently touch.
|
5745 |
-
|
5746 |
-
// Collapsed markers have unique ids, in order to be able to order
|
5747 |
-
// them, which is needed for uniquely determining an outer marker
|
5748 |
-
// when they overlap (they may nest, but not partially overlap).
|
5749 |
-
var nextMarkerId = 0
|
5750 |
-
|
5751 |
-
var TextMarker = function(doc, type) {
|
5752 |
-
this.lines = []
|
5753 |
-
this.type = type
|
5754 |
-
this.doc = doc
|
5755 |
-
this.id = ++nextMarkerId
|
5756 |
-
};
|
5757 |
-
|
5758 |
-
// Clear the marker.
|
5759 |
-
TextMarker.prototype.clear = function () {
|
5760 |
-
var this$1 = this;
|
5761 |
-
|
5762 |
-
if (this.explicitlyCleared) { return }
|
5763 |
-
var cm = this.doc.cm, withOp = cm && !cm.curOp
|
5764 |
-
if (withOp) { startOperation(cm) }
|
5765 |
-
if (hasHandler(this, "clear")) {
|
5766 |
-
var found = this.find()
|
5767 |
-
if (found) { signalLater(this, "clear", found.from, found.to) }
|
5768 |
-
}
|
5769 |
-
var min = null, max = null
|
5770 |
-
for (var i = 0; i < this.lines.length; ++i) {
|
5771 |
-
var line = this$1.lines[i]
|
5772 |
-
var span = getMarkedSpanFor(line.markedSpans, this$1)
|
5773 |
-
if (cm && !this$1.collapsed) { regLineChange(cm, lineNo(line), "text") }
|
5774 |
-
else if (cm) {
|
5775 |
-
if (span.to != null) { max = lineNo(line) }
|
5776 |
-
if (span.from != null) { min = lineNo(line) }
|
5777 |
-
}
|
5778 |
-
line.markedSpans = removeMarkedSpan(line.markedSpans, span)
|
5779 |
-
if (span.from == null && this$1.collapsed && !lineIsHidden(this$1.doc, line) && cm)
|
5780 |
-
{ updateLineHeight(line, textHeight(cm.display)) }
|
5781 |
-
}
|
5782 |
-
if (cm && this.collapsed && !cm.options.lineWrapping) { for (var i$1 = 0; i$1 < this.lines.length; ++i$1) {
|
5783 |
-
var visual = visualLine(this$1.lines[i$1]), len = lineLength(visual)
|
5784 |
-
if (len > cm.display.maxLineLength) {
|
5785 |
-
cm.display.maxLine = visual
|
5786 |
-
cm.display.maxLineLength = len
|
5787 |
-
cm.display.maxLineChanged = true
|
5788 |
-
}
|
5789 |
-
} }
|
5790 |
-
|
5791 |
-
if (min != null && cm && this.collapsed) { regChange(cm, min, max + 1) }
|
5792 |
-
this.lines.length = 0
|
5793 |
-
this.explicitlyCleared = true
|
5794 |
-
if (this.atomic && this.doc.cantEdit) {
|
5795 |
-
this.doc.cantEdit = false
|
5796 |
-
if (cm) { reCheckSelection(cm.doc) }
|
5797 |
-
}
|
5798 |
-
if (cm) { signalLater(cm, "markerCleared", cm, this, min, max) }
|
5799 |
-
if (withOp) { endOperation(cm) }
|
5800 |
-
if (this.parent) { this.parent.clear() }
|
5801 |
-
};
|
5802 |
-
|
5803 |
-
// Find the position of the marker in the document. Returns a {from,
|
5804 |
-
// to} object by default. Side can be passed to get a specific side
|
5805 |
-
// -- 0 (both), -1 (left), or 1 (right). When lineObj is true, the
|
5806 |
-
// Pos objects returned contain a line object, rather than a line
|
5807 |
-
// number (used to prevent looking up the same line twice).
|
5808 |
-
TextMarker.prototype.find = function (side, lineObj) {
|
5809 |
-
var this$1 = this;
|
5810 |
-
|
5811 |
-
if (side == null && this.type == "bookmark") { side = 1 }
|
5812 |
-
var from, to
|
5813 |
-
for (var i = 0; i < this.lines.length; ++i) {
|
5814 |
-
var line = this$1.lines[i]
|
5815 |
-
var span = getMarkedSpanFor(line.markedSpans, this$1)
|
5816 |
-
if (span.from != null) {
|
5817 |
-
from = Pos(lineObj ? line : lineNo(line), span.from)
|
5818 |
-
if (side == -1) { return from }
|
5819 |
-
}
|
5820 |
-
if (span.to != null) {
|
5821 |
-
to = Pos(lineObj ? line : lineNo(line), span.to)
|
5822 |
-
if (side == 1) { return to }
|
5823 |
-
}
|
5824 |
-
}
|
5825 |
-
return from && {from: from, to: to}
|
5826 |
-
};
|
5827 |
-
|
5828 |
-
// Signals that the marker's widget changed, and surrounding layout
|
5829 |
-
// should be recomputed.
|
5830 |
-
TextMarker.prototype.changed = function () {
|
5831 |
-
var this$1 = this;
|
5832 |
-
|
5833 |
-
var pos = this.find(-1, true), widget = this, cm = this.doc.cm
|
5834 |
-
if (!pos || !cm) { return }
|
5835 |
-
runInOp(cm, function () {
|
5836 |
-
var line = pos.line, lineN = lineNo(pos.line)
|
5837 |
-
var view = findViewForLine(cm, lineN)
|
5838 |
-
if (view) {
|
5839 |
-
clearLineMeasurementCacheFor(view)
|
5840 |
-
cm.curOp.selectionChanged = cm.curOp.forceUpdate = true
|
5841 |
-
}
|
5842 |
-
cm.curOp.updateMaxLine = true
|
5843 |
-
if (!lineIsHidden(widget.doc, line) && widget.height != null) {
|
5844 |
-
var oldHeight = widget.height
|
5845 |
-
widget.height = null
|
5846 |
-
var dHeight = widgetHeight(widget) - oldHeight
|
5847 |
-
if (dHeight)
|
5848 |
-
{ updateLineHeight(line, line.height + dHeight) }
|
5849 |
-
}
|
5850 |
-
signalLater(cm, "markerChanged", cm, this$1)
|
5851 |
-
})
|
5852 |
-
};
|
5853 |
-
|
5854 |
-
TextMarker.prototype.attachLine = function (line) {
|
5855 |
-
if (!this.lines.length && this.doc.cm) {
|
5856 |
-
var op = this.doc.cm.curOp
|
5857 |
-
if (!op.maybeHiddenMarkers || indexOf(op.maybeHiddenMarkers, this) == -1)
|
5858 |
-
{ (op.maybeUnhiddenMarkers || (op.maybeUnhiddenMarkers = [])).push(this) }
|
5859 |
-
}
|
5860 |
-
this.lines.push(line)
|
5861 |
-
};
|
5862 |
-
|
5863 |
-
TextMarker.prototype.detachLine = function (line) {
|
5864 |
-
this.lines.splice(indexOf(this.lines, line), 1)
|
5865 |
-
if (!this.lines.length && this.doc.cm) {
|
5866 |
-
var op = this.doc.cm.curOp
|
5867 |
-
;(op.maybeHiddenMarkers || (op.maybeHiddenMarkers = [])).push(this)
|
5868 |
-
}
|
5869 |
-
};
|
5870 |
-
eventMixin(TextMarker)
|
5871 |
-
|
5872 |
-
// Create a marker, wire it up to the right lines, and
|
5873 |
-
function markText(doc, from, to, options, type) {
|
5874 |
-
// Shared markers (across linked documents) are handled separately
|
5875 |
-
// (markTextShared will call out to this again, once per
|
5876 |
-
// document).
|
5877 |
-
if (options && options.shared) { return markTextShared(doc, from, to, options, type) }
|
5878 |
-
// Ensure we are in an operation.
|
5879 |
-
if (doc.cm && !doc.cm.curOp) { return operation(doc.cm, markText)(doc, from, to, options, type) }
|
5880 |
-
|
5881 |
-
var marker = new TextMarker(doc, type), diff = cmp(from, to)
|
5882 |
-
if (options) { copyObj(options, marker, false) }
|
5883 |
-
// Don't connect empty markers unless clearWhenEmpty is false
|
5884 |
-
if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false)
|
5885 |
-
{ return marker }
|
5886 |
-
if (marker.replacedWith) {
|
5887 |
-
// Showing up as a widget implies collapsed (widget replaces text)
|
5888 |
-
marker.collapsed = true
|
5889 |
-
marker.widgetNode = eltP("span", [marker.replacedWith], "CodeMirror-widget")
|
5890 |
-
if (!options.handleMouseEvents) { marker.widgetNode.setAttribute("cm-ignore-events", "true") }
|
5891 |
-
if (options.insertLeft) { marker.widgetNode.insertLeft = true }
|
5892 |
-
}
|
5893 |
-
if (marker.collapsed) {
|
5894 |
-
if (conflictingCollapsedRange(doc, from.line, from, to, marker) ||
|
5895 |
-
from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker))
|
5896 |
-
{ throw new Error("Inserting collapsed marker partially overlapping an existing one") }
|
5897 |
-
seeCollapsedSpans()
|
5898 |
-
}
|
5899 |
-
|
5900 |
-
if (marker.addToHistory)
|
5901 |
-
{ addChangeToHistory(doc, {from: from, to: to, origin: "markText"}, doc.sel, NaN) }
|
5902 |
-
|
5903 |
-
var curLine = from.line, cm = doc.cm, updateMaxLine
|
5904 |
-
doc.iter(curLine, to.line + 1, function (line) {
|
5905 |
-
if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine)
|
5906 |
-
{ updateMaxLine = true }
|
5907 |
-
if (marker.collapsed && curLine != from.line) { updateLineHeight(line, 0) }
|
5908 |
-
addMarkedSpan(line, new MarkedSpan(marker,
|
5909 |
-
curLine == from.line ? from.ch : null,
|
5910 |
-
curLine == to.line ? to.ch : null))
|
5911 |
-
++curLine
|
5912 |
-
})
|
5913 |
-
// lineIsHidden depends on the presence of the spans, so needs a second pass
|
5914 |
-
if (marker.collapsed) { doc.iter(from.line, to.line + 1, function (line) {
|
5915 |
-
if (lineIsHidden(doc, line)) { updateLineHeight(line, 0) }
|
5916 |
-
}) }
|
5917 |
-
|
5918 |
-
if (marker.clearOnEnter) { on(marker, "beforeCursorEnter", function () { return marker.clear(); }) }
|
5919 |
-
|
5920 |
-
if (marker.readOnly) {
|
5921 |
-
seeReadOnlySpans()
|
5922 |
-
if (doc.history.done.length || doc.history.undone.length)
|
5923 |
-
{ doc.clearHistory() }
|
5924 |
-
}
|
5925 |
-
if (marker.collapsed) {
|
5926 |
-
marker.id = ++nextMarkerId
|
5927 |
-
marker.atomic = true
|
5928 |
-
}
|
5929 |
-
if (cm) {
|
5930 |
-
// Sync editor state
|
5931 |
-
if (updateMaxLine) { cm.curOp.updateMaxLine = true }
|
5932 |
-
if (marker.collapsed)
|
5933 |
-
{ regChange(cm, from.line, to.line + 1) }
|
5934 |
-
else if (marker.className || marker.title || marker.startStyle || marker.endStyle || marker.css)
|
5935 |
-
{ for (var i = from.line; i <= to.line; i++) { regLineChange(cm, i, "text") } }
|
5936 |
-
if (marker.atomic) { reCheckSelection(cm.doc) }
|
5937 |
-
signalLater(cm, "markerAdded", cm, marker)
|
5938 |
-
}
|
5939 |
-
return marker
|
5940 |
-
}
|
5941 |
-
|
5942 |
-
// SHARED TEXTMARKERS
|
5943 |
-
|
5944 |
-
// A shared marker spans multiple linked documents. It is
|
5945 |
-
// implemented as a meta-marker-object controlling multiple normal
|
5946 |
-
// markers.
|
5947 |
-
var SharedTextMarker = function(markers, primary) {
|
5948 |
-
var this$1 = this;
|
5949 |
-
|
5950 |
-
this.markers = markers
|
5951 |
-
this.primary = primary
|
5952 |
-
for (var i = 0; i < markers.length; ++i)
|
5953 |
-
{ markers[i].parent = this$1 }
|
5954 |
-
};
|
5955 |
-
|
5956 |
-
SharedTextMarker.prototype.clear = function () {
|
5957 |
-
var this$1 = this;
|
5958 |
-
|
5959 |
-
if (this.explicitlyCleared) { return }
|
5960 |
-
this.explicitlyCleared = true
|
5961 |
-
for (var i = 0; i < this.markers.length; ++i)
|
5962 |
-
{ this$1.markers[i].clear() }
|
5963 |
-
signalLater(this, "clear")
|
5964 |
-
};
|
5965 |
-
|
5966 |
-
SharedTextMarker.prototype.find = function (side, lineObj) {
|
5967 |
-
return this.primary.find(side, lineObj)
|
5968 |
-
};
|
5969 |
-
eventMixin(SharedTextMarker)
|
5970 |
-
|
5971 |
-
function markTextShared(doc, from, to, options, type) {
|
5972 |
-
options = copyObj(options)
|
5973 |
-
options.shared = false
|
5974 |
-
var markers = [markText(doc, from, to, options, type)], primary = markers[0]
|
5975 |
-
var widget = options.widgetNode
|
5976 |
-
linkedDocs(doc, function (doc) {
|
5977 |
-
if (widget) { options.widgetNode = widget.cloneNode(true) }
|
5978 |
-
markers.push(markText(doc, clipPos(doc, from), clipPos(doc, to), options, type))
|
5979 |
-
for (var i = 0; i < doc.linked.length; ++i)
|
5980 |
-
{ if (doc.linked[i].isParent) { return } }
|
5981 |
-
primary = lst(markers)
|
5982 |
-
})
|
5983 |
-
return new SharedTextMarker(markers, primary)
|
5984 |
-
}
|
5985 |
-
|
5986 |
-
function findSharedMarkers(doc) {
|
5987 |
-
return doc.findMarks(Pos(doc.first, 0), doc.clipPos(Pos(doc.lastLine())), function (m) { return m.parent; })
|
5988 |
-
}
|
5989 |
-
|
5990 |
-
function copySharedMarkers(doc, markers) {
|
5991 |
-
for (var i = 0; i < markers.length; i++) {
|
5992 |
-
var marker = markers[i], pos = marker.find()
|
5993 |
-
var mFrom = doc.clipPos(pos.from), mTo = doc.clipPos(pos.to)
|
5994 |
-
if (cmp(mFrom, mTo)) {
|
5995 |
-
var subMark = markText(doc, mFrom, mTo, marker.primary, marker.primary.type)
|
5996 |
-
marker.markers.push(subMark)
|
5997 |
-
subMark.parent = marker
|
5998 |
-
}
|
5999 |
-
}
|
6000 |
-
}
|
6001 |
-
|
6002 |
-
function detachSharedMarkers(markers) {
|
6003 |
-
var loop = function ( i ) {
|
6004 |
-
var marker = markers[i], linked = [marker.primary.doc]
|
6005 |
-
linkedDocs(marker.primary.doc, function (d) { return linked.push(d); })
|
6006 |
-
for (var j = 0; j < marker.markers.length; j++) {
|
6007 |
-
var subMarker = marker.markers[j]
|
6008 |
-
if (indexOf(linked, subMarker.doc) == -1) {
|
6009 |
-
subMarker.parent = null
|
6010 |
-
marker.markers.splice(j--, 1)
|
6011 |
-
}
|
6012 |
-
}
|
6013 |
-
};
|
6014 |
-
|
6015 |
-
for (var i = 0; i < markers.length; i++) loop( i );
|
6016 |
-
}
|
6017 |
-
|
6018 |
-
var nextDocId = 0
|
6019 |
-
var Doc = function(text, mode, firstLine, lineSep, direction) {
|
6020 |
-
if (!(this instanceof Doc)) { return new Doc(text, mode, firstLine, lineSep, direction) }
|
6021 |
-
if (firstLine == null) { firstLine = 0 }
|
6022 |
-
|
6023 |
-
BranchChunk.call(this, [new LeafChunk([new Line("", null)])])
|
6024 |
-
this.first = firstLine
|
6025 |
-
this.scrollTop = this.scrollLeft = 0
|
6026 |
-
this.cantEdit = false
|
6027 |
-
this.cleanGeneration = 1
|
6028 |
-
this.modeFrontier = this.highlightFrontier = firstLine
|
6029 |
-
var start = Pos(firstLine, 0)
|
6030 |
-
this.sel = simpleSelection(start)
|
6031 |
-
this.history = new History(null)
|
6032 |
-
this.id = ++nextDocId
|
6033 |
-
this.modeOption = mode
|
6034 |
-
this.lineSep = lineSep
|
6035 |
-
this.direction = (direction == "rtl") ? "rtl" : "ltr"
|
6036 |
-
this.extend = false
|
6037 |
-
|
6038 |
-
if (typeof text == "string") { text = this.splitLines(text) }
|
6039 |
-
updateDoc(this, {from: start, to: start, text: text})
|
6040 |
-
setSelection(this, simpleSelection(start), sel_dontScroll)
|
6041 |
-
}
|
6042 |
-
|
6043 |
-
Doc.prototype = createObj(BranchChunk.prototype, {
|
6044 |
-
constructor: Doc,
|
6045 |
-
// Iterate over the document. Supports two forms -- with only one
|
6046 |
-
// argument, it calls that for each line in the document. With
|
6047 |
-
// three, it iterates over the range given by the first two (with
|
6048 |
-
// the second being non-inclusive).
|
6049 |
-
iter: function(from, to, op) {
|
6050 |
-
if (op) { this.iterN(from - this.first, to - from, op) }
|
6051 |
-
else { this.iterN(this.first, this.first + this.size, from) }
|
6052 |
-
},
|
6053 |
-
|
6054 |
-
// Non-public interface for adding and removing lines.
|
6055 |
-
insert: function(at, lines) {
|
6056 |
-
var height = 0
|
6057 |
-
for (var i = 0; i < lines.length; ++i) { height += lines[i].height }
|
6058 |
-
this.insertInner(at - this.first, lines, height)
|
6059 |
-
},
|
6060 |
-
remove: function(at, n) { this.removeInner(at - this.first, n) },
|
6061 |
-
|
6062 |
-
// From here, the methods are part of the public interface. Most
|
6063 |
-
// are also available from CodeMirror (editor) instances.
|
6064 |
-
|
6065 |
-
getValue: function(lineSep) {
|
6066 |
-
var lines = getLines(this, this.first, this.first + this.size)
|
6067 |
-
if (lineSep === false) { return lines }
|
6068 |
-
return lines.join(lineSep || this.lineSeparator())
|
6069 |
-
},
|
6070 |
-
setValue: docMethodOp(function(code) {
|
6071 |
-
var top = Pos(this.first, 0), last = this.first + this.size - 1
|
6072 |
-
makeChange(this, {from: top, to: Pos(last, getLine(this, last).text.length),
|
6073 |
-
text: this.splitLines(code), origin: "setValue", full: true}, true)
|
6074 |
-
if (this.cm) { scrollToCoords(this.cm, 0, 0) }
|
6075 |
-
setSelection(this, simpleSelection(top), sel_dontScroll)
|
6076 |
-
}),
|
6077 |
-
replaceRange: function(code, from, to, origin) {
|
6078 |
-
from = clipPos(this, from)
|
6079 |
-
to = to ? clipPos(this, to) : from
|
6080 |
-
replaceRange(this, code, from, to, origin)
|
6081 |
-
},
|
6082 |
-
getRange: function(from, to, lineSep) {
|
6083 |
-
var lines = getBetween(this, clipPos(this, from), clipPos(this, to))
|
6084 |
-
if (lineSep === false) { return lines }
|
6085 |
-
return lines.join(lineSep || this.lineSeparator())
|
6086 |
-
},
|
6087 |
-
|
6088 |
-
getLine: function(line) {var l = this.getLineHandle(line); return l && l.text},
|
6089 |
-
|
6090 |
-
getLineHandle: function(line) {if (isLine(this, line)) { return getLine(this, line) }},
|
6091 |
-
getLineNumber: function(line) {return lineNo(line)},
|
6092 |
-
|
6093 |
-
getLineHandleVisualStart: function(line) {
|
6094 |
-
if (typeof line == "number") { line = getLine(this, line) }
|
6095 |
-
return visualLine(line)
|
6096 |
-
},
|
6097 |
-
|
6098 |
-
lineCount: function() {return this.size},
|
6099 |
-
firstLine: function() {return this.first},
|
6100 |
-
lastLine: function() {return this.first + this.size - 1},
|
6101 |
-
|
6102 |
-
clipPos: function(pos) {return clipPos(this, pos)},
|
6103 |
-
|
6104 |
-
getCursor: function(start) {
|
6105 |
-
var range = this.sel.primary(), pos
|
6106 |
-
if (start == null || start == "head") { pos = range.head }
|
6107 |
-
else if (start == "anchor") { pos = range.anchor }
|
6108 |
-
else if (start == "end" || start == "to" || start === false) { pos = range.to() }
|
6109 |
-
else { pos = range.from() }
|
6110 |
-
return pos
|
6111 |
-
},
|
6112 |
-
listSelections: function() { return this.sel.ranges },
|
6113 |
-
somethingSelected: function() {return this.sel.somethingSelected()},
|
6114 |
-
|
6115 |
-
setCursor: docMethodOp(function(line, ch, options) {
|
6116 |
-
setSimpleSelection(this, clipPos(this, typeof line == "number" ? Pos(line, ch || 0) : line), null, options)
|
6117 |
-
}),
|
6118 |
-
setSelection: docMethodOp(function(anchor, head, options) {
|
6119 |
-
setSimpleSelection(this, clipPos(this, anchor), clipPos(this, head || anchor), options)
|
6120 |
-
}),
|
6121 |
-
extendSelection: docMethodOp(function(head, other, options) {
|
6122 |
-
extendSelection(this, clipPos(this, head), other && clipPos(this, other), options)
|
6123 |
-
}),
|
6124 |
-
extendSelections: docMethodOp(function(heads, options) {
|
6125 |
-
extendSelections(this, clipPosArray(this, heads), options)
|
6126 |
-
}),
|
6127 |
-
extendSelectionsBy: docMethodOp(function(f, options) {
|
6128 |
-
var heads = map(this.sel.ranges, f)
|
6129 |
-
extendSelections(this, clipPosArray(this, heads), options)
|
6130 |
-
}),
|
6131 |
-
setSelections: docMethodOp(function(ranges, primary, options) {
|
6132 |
-
var this$1 = this;
|
6133 |
-
|
6134 |
-
if (!ranges.length) { return }
|
6135 |
-
var out = []
|
6136 |
-
for (var i = 0; i < ranges.length; i++)
|
6137 |
-
{ out[i] = new Range(clipPos(this$1, ranges[i].anchor),
|
6138 |
-
clipPos(this$1, ranges[i].head)) }
|
6139 |
-
if (primary == null) { primary = Math.min(ranges.length - 1, this.sel.primIndex) }
|
6140 |
-
setSelection(this, normalizeSelection(out, primary), options)
|
6141 |
-
}),
|
6142 |
-
addSelection: docMethodOp(function(anchor, head, options) {
|
6143 |
-
var ranges = this.sel.ranges.slice(0)
|
6144 |
-
ranges.push(new Range(clipPos(this, anchor), clipPos(this, head || anchor)))
|
6145 |
-
setSelection(this, normalizeSelection(ranges, ranges.length - 1), options)
|
6146 |
-
}),
|
6147 |
-
|
6148 |
-
getSelection: function(lineSep) {
|
6149 |
-
var this$1 = this;
|
6150 |
-
|
6151 |
-
var ranges = this.sel.ranges, lines
|
6152 |
-
for (var i = 0; i < ranges.length; i++) {
|
6153 |
-
var sel = getBetween(this$1, ranges[i].from(), ranges[i].to())
|
6154 |
-
lines = lines ? lines.concat(sel) : sel
|
6155 |
-
}
|
6156 |
-
if (lineSep === false) { return lines }
|
6157 |
-
else { return lines.join(lineSep || this.lineSeparator()) }
|
6158 |
-
},
|
6159 |
-
getSelections: function(lineSep) {
|
6160 |
-
var this$1 = this;
|
6161 |
-
|
6162 |
-
var parts = [], ranges = this.sel.ranges
|
6163 |
-
for (var i = 0; i < ranges.length; i++) {
|
6164 |
-
var sel = getBetween(this$1, ranges[i].from(), ranges[i].to())
|
6165 |
-
if (lineSep !== false) { sel = sel.join(lineSep || this$1.lineSeparator()) }
|
6166 |
-
parts[i] = sel
|
6167 |
-
}
|
6168 |
-
return parts
|
6169 |
-
},
|
6170 |
-
replaceSelection: function(code, collapse, origin) {
|
6171 |
-
var dup = []
|
6172 |
-
for (var i = 0; i < this.sel.ranges.length; i++)
|
6173 |
-
{ dup[i] = code }
|
6174 |
-
this.replaceSelections(dup, collapse, origin || "+input")
|
6175 |
-
},
|
6176 |
-
replaceSelections: docMethodOp(function(code, collapse, origin) {
|
6177 |
-
var this$1 = this;
|
6178 |
-
|
6179 |
-
var changes = [], sel = this.sel
|
6180 |
-
for (var i = 0; i < sel.ranges.length; i++) {
|
6181 |
-
var range = sel.ranges[i]
|
6182 |
-
changes[i] = {from: range.from(), to: range.to(), text: this$1.splitLines(code[i]), origin: origin}
|
6183 |
-
}
|
6184 |
-
var newSel = collapse && collapse != "end" && computeReplacedSel(this, changes, collapse)
|
6185 |
-
for (var i$1 = changes.length - 1; i$1 >= 0; i$1--)
|
6186 |
-
{ makeChange(this$1, changes[i$1]) }
|
6187 |
-
if (newSel) { setSelectionReplaceHistory(this, newSel) }
|
6188 |
-
else if (this.cm) { ensureCursorVisible(this.cm) }
|
6189 |
-
}),
|
6190 |
-
undo: docMethodOp(function() {makeChangeFromHistory(this, "undo")}),
|
6191 |
-
redo: docMethodOp(function() {makeChangeFromHistory(this, "redo")}),
|
6192 |
-
undoSelection: docMethodOp(function() {makeChangeFromHistory(this, "undo", true)}),
|
6193 |
-
redoSelection: docMethodOp(function() {makeChangeFromHistory(this, "redo", true)}),
|
6194 |
-
|
6195 |
-
setExtending: function(val) {this.extend = val},
|
6196 |
-
getExtending: function() {return this.extend},
|
6197 |
-
|
6198 |
-
historySize: function() {
|
6199 |
-
var hist = this.history, done = 0, undone = 0
|
6200 |
-
for (var i = 0; i < hist.done.length; i++) { if (!hist.done[i].ranges) { ++done } }
|
6201 |
-
for (var i$1 = 0; i$1 < hist.undone.length; i$1++) { if (!hist.undone[i$1].ranges) { ++undone } }
|
6202 |
-
return {undo: done, redo: undone}
|
6203 |
-
},
|
6204 |
-
clearHistory: function() {this.history = new History(this.history.maxGeneration)},
|
6205 |
-
|
6206 |
-
markClean: function() {
|
6207 |
-
this.cleanGeneration = this.changeGeneration(true)
|
6208 |
-
},
|
6209 |
-
changeGeneration: function(forceSplit) {
|
6210 |
-
if (forceSplit)
|
6211 |
-
{ this.history.lastOp = this.history.lastSelOp = this.history.lastOrigin = null }
|
6212 |
-
return this.history.generation
|
6213 |
-
},
|
6214 |
-
isClean: function (gen) {
|
6215 |
-
return this.history.generation == (gen || this.cleanGeneration)
|
6216 |
-
},
|
6217 |
-
|
6218 |
-
getHistory: function() {
|
6219 |
-
return {done: copyHistoryArray(this.history.done),
|
6220 |
-
undone: copyHistoryArray(this.history.undone)}
|
6221 |
-
},
|
6222 |
-
setHistory: function(histData) {
|
6223 |
-
var hist = this.history = new History(this.history.maxGeneration)
|
6224 |
-
hist.done = copyHistoryArray(histData.done.slice(0), null, true)
|
6225 |
-
hist.undone = copyHistoryArray(histData.undone.slice(0), null, true)
|
6226 |
-
},
|
6227 |
-
|
6228 |
-
setGutterMarker: docMethodOp(function(line, gutterID, value) {
|
6229 |
-
return changeLine(this, line, "gutter", function (line) {
|
6230 |
-
var markers = line.gutterMarkers || (line.gutterMarkers = {})
|
6231 |
-
markers[gutterID] = value
|
6232 |
-
if (!value && isEmpty(markers)) { line.gutterMarkers = null }
|
6233 |
-
return true
|
6234 |
-
})
|
6235 |
-
}),
|
6236 |
-
|
6237 |
-
clearGutter: docMethodOp(function(gutterID) {
|
6238 |
-
var this$1 = this;
|
6239 |
-
|
6240 |
-
this.iter(function (line) {
|
6241 |
-
if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
|
6242 |
-
changeLine(this$1, line, "gutter", function () {
|
6243 |
-
line.gutterMarkers[gutterID] = null
|
6244 |
-
if (isEmpty(line.gutterMarkers)) { line.gutterMarkers = null }
|
6245 |
-
return true
|
6246 |
-
})
|
6247 |
-
}
|
6248 |
-
})
|
6249 |
-
}),
|
6250 |
-
|
6251 |
-
lineInfo: function(line) {
|
6252 |
-
var n
|
6253 |
-
if (typeof line == "number") {
|
6254 |
-
if (!isLine(this, line)) { return null }
|
6255 |
-
n = line
|
6256 |
-
line = getLine(this, line)
|
6257 |
-
if (!line) { return null }
|
6258 |
-
} else {
|
6259 |
-
n = lineNo(line)
|
6260 |
-
if (n == null) { return null }
|
6261 |
-
}
|
6262 |
-
return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers,
|
6263 |
-
textClass: line.textClass, bgClass: line.bgClass, wrapClass: line.wrapClass,
|
6264 |
-
widgets: line.widgets}
|
6265 |
-
},
|
6266 |
-
|
6267 |
-
addLineClass: docMethodOp(function(handle, where, cls) {
|
6268 |
-
return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) {
|
6269 |
-
var prop = where == "text" ? "textClass"
|
6270 |
-
: where == "background" ? "bgClass"
|
6271 |
-
: where == "gutter" ? "gutterClass" : "wrapClass"
|
6272 |
-
if (!line[prop]) { line[prop] = cls }
|
6273 |
-
else if (classTest(cls).test(line[prop])) { return false }
|
6274 |
-
else { line[prop] += " " + cls }
|
6275 |
-
return true
|
6276 |
-
})
|
6277 |
-
}),
|
6278 |
-
removeLineClass: docMethodOp(function(handle, where, cls) {
|
6279 |
-
return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) {
|
6280 |
-
var prop = where == "text" ? "textClass"
|
6281 |
-
: where == "background" ? "bgClass"
|
6282 |
-
: where == "gutter" ? "gutterClass" : "wrapClass"
|
6283 |
-
var cur = line[prop]
|
6284 |
-
if (!cur) { return false }
|
6285 |
-
else if (cls == null) { line[prop] = null }
|
6286 |
-
else {
|
6287 |
-
var found = cur.match(classTest(cls))
|
6288 |
-
if (!found) { return false }
|
6289 |
-
var end = found.index + found[0].length
|
6290 |
-
line[prop] = cur.slice(0, found.index) + (!found.index || end == cur.length ? "" : " ") + cur.slice(end) || null
|
6291 |
-
}
|
6292 |
-
return true
|
6293 |
-
})
|
6294 |
-
}),
|
6295 |
-
|
6296 |
-
addLineWidget: docMethodOp(function(handle, node, options) {
|
6297 |
-
return addLineWidget(this, handle, node, options)
|
6298 |
-
}),
|
6299 |
-
removeLineWidget: function(widget) { widget.clear() },
|
6300 |
-
|
6301 |
-
markText: function(from, to, options) {
|
6302 |
-
return markText(this, clipPos(this, from), clipPos(this, to), options, options && options.type || "range")
|
6303 |
-
},
|
6304 |
-
setBookmark: function(pos, options) {
|
6305 |
-
var realOpts = {replacedWith: options && (options.nodeType == null ? options.widget : options),
|
6306 |
-
insertLeft: options && options.insertLeft,
|
6307 |
-
clearWhenEmpty: false, shared: options && options.shared,
|
6308 |
-
handleMouseEvents: options && options.handleMouseEvents}
|
6309 |
-
pos = clipPos(this, pos)
|
6310 |
-
return markText(this, pos, pos, realOpts, "bookmark")
|
6311 |
-
},
|
6312 |
-
findMarksAt: function(pos) {
|
6313 |
-
pos = clipPos(this, pos)
|
6314 |
-
var markers = [], spans = getLine(this, pos.line).markedSpans
|
6315 |
-
if (spans) { for (var i = 0; i < spans.length; ++i) {
|
6316 |
-
var span = spans[i]
|
6317 |
-
if ((span.from == null || span.from <= pos.ch) &&
|
6318 |
-
(span.to == null || span.to >= pos.ch))
|
6319 |
-
{ markers.push(span.marker.parent || span.marker) }
|
6320 |
-
} }
|
6321 |
-
return markers
|
6322 |
-
},
|
6323 |
-
findMarks: function(from, to, filter) {
|
6324 |
-
from = clipPos(this, from); to = clipPos(this, to)
|
6325 |
-
var found = [], lineNo = from.line
|
6326 |
-
this.iter(from.line, to.line + 1, function (line) {
|
6327 |
-
var spans = line.markedSpans
|
6328 |
-
if (spans) { for (var i = 0; i < spans.length; i++) {
|
6329 |
-
var span = spans[i]
|
6330 |
-
if (!(span.to != null && lineNo == from.line && from.ch >= span.to ||
|
6331 |
-
span.from == null && lineNo != from.line ||
|
6332 |
-
span.from != null && lineNo == to.line && span.from >= to.ch) &&
|
6333 |
-
(!filter || filter(span.marker)))
|
6334 |
-
{ found.push(span.marker.parent || span.marker) }
|
6335 |
-
} }
|
6336 |
-
++lineNo
|
6337 |
-
})
|
6338 |
-
return found
|
6339 |
-
},
|
6340 |
-
getAllMarks: function() {
|
6341 |
-
var markers = []
|
6342 |
-
this.iter(function (line) {
|
6343 |
-
var sps = line.markedSpans
|
6344 |
-
if (sps) { for (var i = 0; i < sps.length; ++i)
|
6345 |
-
{ if (sps[i].from != null) { markers.push(sps[i].marker) } } }
|
6346 |
-
})
|
6347 |
-
return markers
|
6348 |
-
},
|
6349 |
-
|
6350 |
-
posFromIndex: function(off) {
|
6351 |
-
var ch, lineNo = this.first, sepSize = this.lineSeparator().length
|
6352 |
-
this.iter(function (line) {
|
6353 |
-
var sz = line.text.length + sepSize
|
6354 |
-
if (sz > off) { ch = off; return true }
|
6355 |
-
off -= sz
|
6356 |
-
++lineNo
|
6357 |
-
})
|
6358 |
-
return clipPos(this, Pos(lineNo, ch))
|
6359 |
-
},
|
6360 |
-
indexFromPos: function (coords) {
|
6361 |
-
coords = clipPos(this, coords)
|
6362 |
-
var index = coords.ch
|
6363 |
-
if (coords.line < this.first || coords.ch < 0) { return 0 }
|
6364 |
-
var sepSize = this.lineSeparator().length
|
6365 |
-
this.iter(this.first, coords.line, function (line) { // iter aborts when callback returns a truthy value
|
6366 |
-
index += line.text.length + sepSize
|
6367 |
-
})
|
6368 |
-
return index
|
6369 |
-
},
|
6370 |
-
|
6371 |
-
copy: function(copyHistory) {
|
6372 |
-
var doc = new Doc(getLines(this, this.first, this.first + this.size),
|
6373 |
-
this.modeOption, this.first, this.lineSep, this.direction)
|
6374 |
-
doc.scrollTop = this.scrollTop; doc.scrollLeft = this.scrollLeft
|
6375 |
-
doc.sel = this.sel
|
6376 |
-
doc.extend = false
|
6377 |
-
if (copyHistory) {
|
6378 |
-
doc.history.undoDepth = this.history.undoDepth
|
6379 |
-
doc.setHistory(this.getHistory())
|
6380 |
-
}
|
6381 |
-
return doc
|
6382 |
-
},
|
6383 |
-
|
6384 |
-
linkedDoc: function(options) {
|
6385 |
-
if (!options) { options = {} }
|
6386 |
-
var from = this.first, to = this.first + this.size
|
6387 |
-
if (options.from != null && options.from > from) { from = options.from }
|
6388 |
-
if (options.to != null && options.to < to) { to = options.to }
|
6389 |
-
var copy = new Doc(getLines(this, from, to), options.mode || this.modeOption, from, this.lineSep, this.direction)
|
6390 |
-
if (options.sharedHist) { copy.history = this.history
|
6391 |
-
; }(this.linked || (this.linked = [])).push({doc: copy, sharedHist: options.sharedHist})
|
6392 |
-
copy.linked = [{doc: this, isParent: true, sharedHist: options.sharedHist}]
|
6393 |
-
copySharedMarkers(copy, findSharedMarkers(this))
|
6394 |
-
return copy
|
6395 |
-
},
|
6396 |
-
unlinkDoc: function(other) {
|
6397 |
-
var this$1 = this;
|
6398 |
-
|
6399 |
-
if (other instanceof CodeMirror) { other = other.doc }
|
6400 |
-
if (this.linked) { for (var i = 0; i < this.linked.length; ++i) {
|
6401 |
-
var link = this$1.linked[i]
|
6402 |
-
if (link.doc != other) { continue }
|
6403 |
-
this$1.linked.splice(i, 1)
|
6404 |
-
other.unlinkDoc(this$1)
|
6405 |
-
detachSharedMarkers(findSharedMarkers(this$1))
|
6406 |
-
break
|
6407 |
-
} }
|
6408 |
-
// If the histories were shared, split them again
|
6409 |
-
if (other.history == this.history) {
|
6410 |
-
var splitIds = [other.id]
|
6411 |
-
linkedDocs(other, function (doc) { return splitIds.push(doc.id); }, true)
|
6412 |
-
other.history = new History(null)
|
6413 |
-
other.history.done = copyHistoryArray(this.history.done, splitIds)
|
6414 |
-
other.history.undone = copyHistoryArray(this.history.undone, splitIds)
|
6415 |
-
}
|
6416 |
-
},
|
6417 |
-
iterLinkedDocs: function(f) {linkedDocs(this, f)},
|
6418 |
-
|
6419 |
-
getMode: function() {return this.mode},
|
6420 |
-
getEditor: function() {return this.cm},
|
6421 |
-
|
6422 |
-
splitLines: function(str) {
|
6423 |
-
if (this.lineSep) { return str.split(this.lineSep) }
|
6424 |
-
return splitLinesAuto(str)
|
6425 |
-
},
|
6426 |
-
lineSeparator: function() { return this.lineSep || "\n" },
|
6427 |
-
|
6428 |
-
setDirection: docMethodOp(function (dir) {
|
6429 |
-
if (dir != "rtl") { dir = "ltr" }
|
6430 |
-
if (dir == this.direction) { return }
|
6431 |
-
this.direction = dir
|
6432 |
-
this.iter(function (line) { return line.order = null; })
|
6433 |
-
if (this.cm) { directionChanged(this.cm) }
|
6434 |
-
})
|
6435 |
-
})
|
6436 |
-
|
6437 |
-
// Public alias.
|
6438 |
-
Doc.prototype.eachLine = Doc.prototype.iter
|
6439 |
-
|
6440 |
-
// Kludge to work around strange IE behavior where it'll sometimes
|
6441 |
-
// re-fire a series of drag-related events right after the drop (#1551)
|
6442 |
-
var lastDrop = 0
|
6443 |
-
|
6444 |
-
function onDrop(e) {
|
6445 |
-
var cm = this
|
6446 |
-
clearDragCursor(cm)
|
6447 |
-
if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e))
|
6448 |
-
{ return }
|
6449 |
-
e_preventDefault(e)
|
6450 |
-
if (ie) { lastDrop = +new Date }
|
6451 |
-
var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files
|
6452 |
-
if (!pos || cm.isReadOnly()) { return }
|
6453 |
-
// Might be a file drop, in which case we simply extract the text
|
6454 |
-
// and insert it.
|
6455 |
-
if (files && files.length && window.FileReader && window.File) {
|
6456 |
-
var n = files.length, text = Array(n), read = 0
|
6457 |
-
var loadFile = function (file, i) {
|
6458 |
-
if (cm.options.allowDropFileTypes &&
|
6459 |
-
indexOf(cm.options.allowDropFileTypes, file.type) == -1)
|
6460 |
-
{ return }
|
6461 |
-
|
6462 |
-
var reader = new FileReader
|
6463 |
-
reader.onload = operation(cm, function () {
|
6464 |
-
var content = reader.result
|
6465 |
-
if (/[\x00-\x08\x0e-\x1f]{2}/.test(content)) { content = "" }
|
6466 |
-
text[i] = content
|
6467 |
-
if (++read == n) {
|
6468 |
-
pos = clipPos(cm.doc, pos)
|
6469 |
-
var change = {from: pos, to: pos,
|
6470 |
-
text: cm.doc.splitLines(text.join(cm.doc.lineSeparator())),
|
6471 |
-
origin: "paste"}
|
6472 |
-
makeChange(cm.doc, change)
|
6473 |
-
setSelectionReplaceHistory(cm.doc, simpleSelection(pos, changeEnd(change)))
|
6474 |
-
}
|
6475 |
-
})
|
6476 |
-
reader.readAsText(file)
|
6477 |
-
}
|
6478 |
-
for (var i = 0; i < n; ++i) { loadFile(files[i], i) }
|
6479 |
-
} else { // Normal drop
|
6480 |
-
// Don't do a replace if the drop happened inside of the selected text.
|
6481 |
-
if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) {
|
6482 |
-
cm.state.draggingText(e)
|
6483 |
-
// Ensure the editor is re-focused
|
6484 |
-
setTimeout(function () { return cm.display.input.focus(); }, 20)
|
6485 |
-
return
|
6486 |
-
}
|
6487 |
-
try {
|
6488 |
-
var text$1 = e.dataTransfer.getData("Text")
|
6489 |
-
if (text$1) {
|
6490 |
-
var selected
|
6491 |
-
if (cm.state.draggingText && !cm.state.draggingText.copy)
|
6492 |
-
{ selected = cm.listSelections() }
|
6493 |
-
setSelectionNoUndo(cm.doc, simpleSelection(pos, pos))
|
6494 |
-
if (selected) { for (var i$1 = 0; i$1 < selected.length; ++i$1)
|
6495 |
-
{ replaceRange(cm.doc, "", selected[i$1].anchor, selected[i$1].head, "drag") } }
|
6496 |
-
cm.replaceSelection(text$1, "around", "paste")
|
6497 |
-
cm.display.input.focus()
|
6498 |
-
}
|
6499 |
-
}
|
6500 |
-
catch(e){}
|
6501 |
-
}
|
6502 |
-
}
|
6503 |
-
|
6504 |
-
function onDragStart(cm, e) {
|
6505 |
-
if (ie && (!cm.state.draggingText || +new Date - lastDrop < 100)) { e_stop(e); return }
|
6506 |
-
if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) { return }
|
6507 |
-
|
6508 |
-
e.dataTransfer.setData("Text", cm.getSelection())
|
6509 |
-
e.dataTransfer.effectAllowed = "copyMove"
|
6510 |
-
|
6511 |
-
// Use dummy image instead of default browsers image.
|
6512 |
-
// Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.
|
6513 |
-
if (e.dataTransfer.setDragImage && !safari) {
|
6514 |
-
var img = elt("img", null, null, "position: fixed; left: 0; top: 0;")
|
6515 |
-
img.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
|
6516 |
-
if (presto) {
|
6517 |
-
img.width = img.height = 1
|
6518 |
-
cm.display.wrapper.appendChild(img)
|
6519 |
-
// Force a relayout, or Opera won't use our image for some obscure reason
|
6520 |
-
img._top = img.offsetTop
|
6521 |
-
}
|
6522 |
-
e.dataTransfer.setDragImage(img, 0, 0)
|
6523 |
-
if (presto) { img.parentNode.removeChild(img) }
|
6524 |
-
}
|
6525 |
-
}
|
6526 |
-
|
6527 |
-
function onDragOver(cm, e) {
|
6528 |
-
var pos = posFromMouse(cm, e)
|
6529 |
-
if (!pos) { return }
|
6530 |
-
var frag = document.createDocumentFragment()
|
6531 |
-
drawSelectionCursor(cm, pos, frag)
|
6532 |
-
if (!cm.display.dragCursor) {
|
6533 |
-
cm.display.dragCursor = elt("div", null, "CodeMirror-cursors CodeMirror-dragcursors")
|
6534 |
-
cm.display.lineSpace.insertBefore(cm.display.dragCursor, cm.display.cursorDiv)
|
6535 |
-
}
|
6536 |
-
removeChildrenAndAdd(cm.display.dragCursor, frag)
|
6537 |
-
}
|
6538 |
-
|
6539 |
-
function clearDragCursor(cm) {
|
6540 |
-
if (cm.display.dragCursor) {
|
6541 |
-
cm.display.lineSpace.removeChild(cm.display.dragCursor)
|
6542 |
-
cm.display.dragCursor = null
|
6543 |
-
}
|
6544 |
-
}
|
6545 |
-
|
6546 |
-
// These must be handled carefully, because naively registering a
|
6547 |
-
// handler for each editor will cause the editors to never be
|
6548 |
-
// garbage collected.
|
6549 |
-
|
6550 |
-
function forEachCodeMirror(f) {
|
6551 |
-
if (!document.getElementsByClassName) { return }
|
6552 |
-
var byClass = document.getElementsByClassName("CodeMirror")
|
6553 |
-
for (var i = 0; i < byClass.length; i++) {
|
6554 |
-
var cm = byClass[i].CodeMirror
|
6555 |
-
if (cm) { f(cm) }
|
6556 |
-
}
|
6557 |
-
}
|
6558 |
-
|
6559 |
-
var globalsRegistered = false
|
6560 |
-
function ensureGlobalHandlers() {
|
6561 |
-
if (globalsRegistered) { return }
|
6562 |
-
registerGlobalHandlers()
|
6563 |
-
globalsRegistered = true
|
6564 |
-
}
|
6565 |
-
function registerGlobalHandlers() {
|
6566 |
-
// When the window resizes, we need to refresh active editors.
|
6567 |
-
var resizeTimer
|
6568 |
-
on(window, "resize", function () {
|
6569 |
-
if (resizeTimer == null) { resizeTimer = setTimeout(function () {
|
6570 |
-
resizeTimer = null
|
6571 |
-
forEachCodeMirror(onResize)
|
6572 |
-
}, 100) }
|
6573 |
-
})
|
6574 |
-
// When the window loses focus, we want to show the editor as blurred
|
6575 |
-
on(window, "blur", function () { return forEachCodeMirror(onBlur); })
|
6576 |
-
}
|
6577 |
-
// Called when the window resizes
|
6578 |
-
function onResize(cm) {
|
6579 |
-
var d = cm.display
|
6580 |
-
if (d.lastWrapHeight == d.wrapper.clientHeight && d.lastWrapWidth == d.wrapper.clientWidth)
|
6581 |
-
{ return }
|
6582 |
-
// Might be a text scaling operation, clear size caches.
|
6583 |
-
d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null
|
6584 |
-
d.scrollbarsClipped = false
|
6585 |
-
cm.setSize()
|
6586 |
-
}
|
6587 |
-
|
6588 |
-
var keyNames = {
|
6589 |
-
3: "Pause", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
|
6590 |
-
19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
|
6591 |
-
36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
|
6592 |
-
46: "Delete", 59: ";", 61: "=", 91: "Mod", 92: "Mod", 93: "Mod",
|
6593 |
-
106: "*", 107: "=", 109: "-", 110: ".", 111: "/", 127: "Delete", 145: "ScrollLock",
|
6594 |
-
173: "-", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
|
6595 |
-
221: "]", 222: "'", 63232: "Up", 63233: "Down", 63234: "Left", 63235: "Right", 63272: "Delete",
|
6596 |
-
63273: "Home", 63275: "End", 63276: "PageUp", 63277: "PageDown", 63302: "Insert"
|
6597 |
-
}
|
6598 |
-
|
6599 |
-
// Number keys
|
6600 |
-
for (var i = 0; i < 10; i++) { keyNames[i + 48] = keyNames[i + 96] = String(i) }
|
6601 |
-
// Alphabetic keys
|
6602 |
-
for (var i$1 = 65; i$1 <= 90; i$1++) { keyNames[i$1] = String.fromCharCode(i$1) }
|
6603 |
-
// Function keys
|
6604 |
-
for (var i$2 = 1; i$2 <= 12; i$2++) { keyNames[i$2 + 111] = keyNames[i$2 + 63235] = "F" + i$2 }
|
6605 |
-
|
6606 |
-
var keyMap = {}
|
6607 |
-
|
6608 |
-
keyMap.basic = {
|
6609 |
-
"Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
|
6610 |
-
"End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
|
6611 |
-
"Delete": "delCharAfter", "Backspace": "delCharBefore", "Shift-Backspace": "delCharBefore",
|
6612 |
-
"Tab": "defaultTab", "Shift-Tab": "indentAuto",
|
6613 |
-
"Enter": "newlineAndIndent", "Insert": "toggleOverwrite",
|
6614 |
-
"Esc": "singleSelection"
|
6615 |
-
}
|
6616 |
-
// Note that the save and find-related commands aren't defined by
|
6617 |
-
// default. User code or addons can define them. Unknown commands
|
6618 |
-
// are simply ignored.
|
6619 |
-
keyMap.pcDefault = {
|
6620 |
-
"Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
|
6621 |
-
"Ctrl-Home": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Up": "goLineUp", "Ctrl-Down": "goLineDown",
|
6622 |
-
"Ctrl-Left": "goGroupLeft", "Ctrl-Right": "goGroupRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
|
6623 |
-
"Ctrl-Backspace": "delGroupBefore", "Ctrl-Delete": "delGroupAfter", "Ctrl-S": "save", "Ctrl-F": "find",
|
6624 |
-
"Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
|
6625 |
-
"Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
|
6626 |
-
"Ctrl-U": "undoSelection", "Shift-Ctrl-U": "redoSelection", "Alt-U": "redoSelection",
|
6627 |
-
fallthrough: "basic"
|
6628 |
-
}
|
6629 |
-
// Very basic readline/emacs-style bindings, which are standard on Mac.
|
6630 |
-
keyMap.emacsy = {
|
6631 |
-
"Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
|
6632 |
-
"Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
|
6633 |
-
"Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore",
|
6634 |
-
"Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars",
|
6635 |
-
"Ctrl-O": "openLine"
|
6636 |
-
}
|
6637 |
-
keyMap.macDefault = {
|
6638 |
-
"Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
|
6639 |
-
"Cmd-Home": "goDocStart", "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goGroupLeft",
|
6640 |
-
"Alt-Right": "goGroupRight", "Cmd-Left": "goLineLeft", "Cmd-Right": "goLineRight", "Alt-Backspace": "delGroupBefore",
|
6641 |
-
"Ctrl-Alt-Backspace": "delGroupAfter", "Alt-Delete": "delGroupAfter", "Cmd-S": "save", "Cmd-F": "find",
|
6642 |
-
"Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
|
6643 |
-
"Cmd-[": "indentLess", "Cmd-]": "indentMore", "Cmd-Backspace": "delWrappedLineLeft", "Cmd-Delete": "delWrappedLineRight",
|
6644 |
-
"Cmd-U": "undoSelection", "Shift-Cmd-U": "redoSelection", "Ctrl-Up": "goDocStart", "Ctrl-Down": "goDocEnd",
|
6645 |
-
fallthrough: ["basic", "emacsy"]
|
6646 |
-
}
|
6647 |
-
keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault
|
6648 |
-
|
6649 |
-
// KEYMAP DISPATCH
|
6650 |
-
|
6651 |
-
function normalizeKeyName(name) {
|
6652 |
-
var parts = name.split(/-(?!$)/)
|
6653 |
-
name = parts[parts.length - 1]
|
6654 |
-
var alt, ctrl, shift, cmd
|
6655 |
-
for (var i = 0; i < parts.length - 1; i++) {
|
6656 |
-
var mod = parts[i]
|
6657 |
-
if (/^(cmd|meta|m)$/i.test(mod)) { cmd = true }
|
6658 |
-
else if (/^a(lt)?$/i.test(mod)) { alt = true }
|
6659 |
-
else if (/^(c|ctrl|control)$/i.test(mod)) { ctrl = true }
|
6660 |
-
else if (/^s(hift)?$/i.test(mod)) { shift = true }
|
6661 |
-
else { throw new Error("Unrecognized modifier name: " + mod) }
|
6662 |
-
}
|
6663 |
-
if (alt) { name = "Alt-" + name }
|
6664 |
-
if (ctrl) { name = "Ctrl-" + name }
|
6665 |
-
if (cmd) { name = "Cmd-" + name }
|
6666 |
-
if (shift) { name = "Shift-" + name }
|
6667 |
-
return name
|
6668 |
-
}
|
6669 |
-
|
6670 |
-
// This is a kludge to keep keymaps mostly working as raw objects
|
6671 |
-
// (backwards compatibility) while at the same time support features
|
6672 |
-
// like normalization and multi-stroke key bindings. It compiles a
|
6673 |
-
// new normalized keymap, and then updates the old object to reflect
|
6674 |
-
// this.
|
6675 |
-
function normalizeKeyMap(keymap) {
|
6676 |
-
var copy = {}
|
6677 |
-
for (var keyname in keymap) { if (keymap.hasOwnProperty(keyname)) {
|
6678 |
-
var value = keymap[keyname]
|
6679 |
-
if (/^(name|fallthrough|(de|at)tach)$/.test(keyname)) { continue }
|
6680 |
-
if (value == "...") { delete keymap[keyname]; continue }
|
6681 |
-
|
6682 |
-
var keys = map(keyname.split(" "), normalizeKeyName)
|
6683 |
-
for (var i = 0; i < keys.length; i++) {
|
6684 |
-
var val = (void 0), name = (void 0)
|
6685 |
-
if (i == keys.length - 1) {
|
6686 |
-
name = keys.join(" ")
|
6687 |
-
val = value
|
6688 |
-
} else {
|
6689 |
-
name = keys.slice(0, i + 1).join(" ")
|
6690 |
-
val = "..."
|
6691 |
-
}
|
6692 |
-
var prev = copy[name]
|
6693 |
-
if (!prev) { copy[name] = val }
|
6694 |
-
else if (prev != val) { throw new Error("Inconsistent bindings for " + name) }
|
6695 |
-
}
|
6696 |
-
delete keymap[keyname]
|
6697 |
-
} }
|
6698 |
-
for (var prop in copy) { keymap[prop] = copy[prop] }
|
6699 |
-
return keymap
|
6700 |
-
}
|
6701 |
-
|
6702 |
-
function lookupKey(key, map, handle, context) {
|
6703 |
-
map = getKeyMap(map)
|
6704 |
-
var found = map.call ? map.call(key, context) : map[key]
|
6705 |
-
if (found === false) { return "nothing" }
|
6706 |
-
if (found === "...") { return "multi" }
|
6707 |
-
if (found != null && handle(found)) { return "handled" }
|
6708 |
-
|
6709 |
-
if (map.fallthrough) {
|
6710 |
-
if (Object.prototype.toString.call(map.fallthrough) != "[object Array]")
|
6711 |
-
{ return lookupKey(key, map.fallthrough, handle, context) }
|
6712 |
-
for (var i = 0; i < map.fallthrough.length; i++) {
|
6713 |
-
var result = lookupKey(key, map.fallthrough[i], handle, context)
|
6714 |
-
if (result) { return result }
|
6715 |
-
}
|
6716 |
-
}
|
6717 |
-
}
|
6718 |
-
|
6719 |
-
// Modifier key presses don't count as 'real' key presses for the
|
6720 |
-
// purpose of keymap fallthrough.
|
6721 |
-
function isModifierKey(value) {
|
6722 |
-
var name = typeof value == "string" ? value : keyNames[value.keyCode]
|
6723 |
-
return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod"
|
6724 |
-
}
|
6725 |
-
|
6726 |
-
function addModifierNames(name, event, noShift) {
|
6727 |
-
var base = name
|
6728 |
-
if (event.altKey && base != "Alt") { name = "Alt-" + name }
|
6729 |
-
if ((flipCtrlCmd ? event.metaKey : event.ctrlKey) && base != "Ctrl") { name = "Ctrl-" + name }
|
6730 |
-
if ((flipCtrlCmd ? event.ctrlKey : event.metaKey) && base != "Cmd") { name = "Cmd-" + name }
|
6731 |
-
if (!noShift && event.shiftKey && base != "Shift") { name = "Shift-" + name }
|
6732 |
-
return name
|
6733 |
-
}
|
6734 |
-
|
6735 |
-
// Look up the name of a key as indicated by an event object.
|
6736 |
-
function keyName(event, noShift) {
|
6737 |
-
if (presto && event.keyCode == 34 && event["char"]) { return false }
|
6738 |
-
var name = keyNames[event.keyCode]
|
6739 |
-
if (name == null || event.altGraphKey) { return false }
|
6740 |
-
// Ctrl-ScrollLock has keyCode 3, same as Ctrl-Pause,
|
6741 |
-
// so we'll use event.code when available (Chrome 48+, FF 38+, Safari 10.1+)
|
6742 |
-
if (event.keyCode == 3 && event.code) { name = event.code }
|
6743 |
-
return addModifierNames(name, event, noShift)
|
6744 |
-
}
|
6745 |
-
|
6746 |
-
function getKeyMap(val) {
|
6747 |
-
return typeof val == "string" ? keyMap[val] : val
|
6748 |
-
}
|
6749 |
-
|
6750 |
-
// Helper for deleting text near the selection(s), used to implement
|
6751 |
-
// backspace, delete, and similar functionality.
|
6752 |
-
function deleteNearSelection(cm, compute) {
|
6753 |
-
var ranges = cm.doc.sel.ranges, kill = []
|
6754 |
-
// Build up a set of ranges to kill first, merging overlapping
|
6755 |
-
// ranges.
|
6756 |
-
for (var i = 0; i < ranges.length; i++) {
|
6757 |
-
var toKill = compute(ranges[i])
|
6758 |
-
while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) {
|
6759 |
-
var replaced = kill.pop()
|
6760 |
-
if (cmp(replaced.from, toKill.from) < 0) {
|
6761 |
-
toKill.from = replaced.from
|
6762 |
-
break
|
6763 |
-
}
|
6764 |
-
}
|
6765 |
-
kill.push(toKill)
|
6766 |
-
}
|
6767 |
-
// Next, remove those actual ranges.
|
6768 |
-
runInOp(cm, function () {
|
6769 |
-
for (var i = kill.length - 1; i >= 0; i--)
|
6770 |
-
{ replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete") }
|
6771 |
-
ensureCursorVisible(cm)
|
6772 |
-
})
|
6773 |
-
}
|
6774 |
-
|
6775 |
-
function moveCharLogically(line, ch, dir) {
|
6776 |
-
var target = skipExtendingChars(line.text, ch + dir, dir)
|
6777 |
-
return target < 0 || target > line.text.length ? null : target
|
6778 |
-
}
|
6779 |
-
|
6780 |
-
function moveLogically(line, start, dir) {
|
6781 |
-
var ch = moveCharLogically(line, start.ch, dir)
|
6782 |
-
return ch == null ? null : new Pos(start.line, ch, dir < 0 ? "after" : "before")
|
6783 |
-
}
|
6784 |
-
|
6785 |
-
function endOfLine(visually, cm, lineObj, lineNo, dir) {
|
6786 |
-
if (visually) {
|
6787 |
-
var order = getOrder(lineObj, cm.doc.direction)
|
6788 |
-
if (order) {
|
6789 |
-
var part = dir < 0 ? lst(order) : order[0]
|
6790 |
-
var moveInStorageOrder = (dir < 0) == (part.level == 1)
|
6791 |
-
var sticky = moveInStorageOrder ? "after" : "before"
|
6792 |
-
var ch
|
6793 |
-
// With a wrapped rtl chunk (possibly spanning multiple bidi parts),
|
6794 |
-
// it could be that the last bidi part is not on the last visual line,
|
6795 |
-
// since visual lines contain content order-consecutive chunks.
|
6796 |
-
// Thus, in rtl, we are looking for the first (content-order) character
|
6797 |
-
// in the rtl chunk that is on the last line (that is, the same line
|
6798 |
-
// as the last (content-order) character).
|
6799 |
-
if (part.level > 0 || cm.doc.direction == "rtl") {
|
6800 |
-
var prep = prepareMeasureForLine(cm, lineObj)
|
6801 |
-
ch = dir < 0 ? lineObj.text.length - 1 : 0
|
6802 |
-
var targetTop = measureCharPrepared(cm, prep, ch).top
|
6803 |
-
ch = findFirst(function (ch) { return measureCharPrepared(cm, prep, ch).top == targetTop; }, (dir < 0) == (part.level == 1) ? part.from : part.to - 1, ch)
|
6804 |
-
if (sticky == "before") { ch = moveCharLogically(lineObj, ch, 1) }
|
6805 |
-
} else { ch = dir < 0 ? part.to : part.from }
|
6806 |
-
return new Pos(lineNo, ch, sticky)
|
6807 |
-
}
|
6808 |
-
}
|
6809 |
-
return new Pos(lineNo, dir < 0 ? lineObj.text.length : 0, dir < 0 ? "before" : "after")
|
6810 |
-
}
|
6811 |
-
|
6812 |
-
function moveVisually(cm, line, start, dir) {
|
6813 |
-
var bidi = getOrder(line, cm.doc.direction)
|
6814 |
-
if (!bidi) { return moveLogically(line, start, dir) }
|
6815 |
-
if (start.ch >= line.text.length) {
|
6816 |
-
start.ch = line.text.length
|
6817 |
-
start.sticky = "before"
|
6818 |
-
} else if (start.ch <= 0) {
|
6819 |
-
start.ch = 0
|
6820 |
-
start.sticky = "after"
|
6821 |
-
}
|
6822 |
-
var partPos = getBidiPartAt(bidi, start.ch, start.sticky), part = bidi[partPos]
|
6823 |
-
if (cm.doc.direction == "ltr" && part.level % 2 == 0 && (dir > 0 ? part.to > start.ch : part.from < start.ch)) {
|
6824 |
-
// Case 1: We move within an ltr part in an ltr editor. Even with wrapped lines,
|
6825 |
-
// nothing interesting happens.
|
6826 |
-
return moveLogically(line, start, dir)
|
6827 |
-
}
|
6828 |
-
|
6829 |
-
var mv = function (pos, dir) { return moveCharLogically(line, pos instanceof Pos ? pos.ch : pos, dir); }
|
6830 |
-
var prep
|
6831 |
-
var getWrappedLineExtent = function (ch) {
|
6832 |
-
if (!cm.options.lineWrapping) { return {begin: 0, end: line.text.length} }
|
6833 |
-
prep = prep || prepareMeasureForLine(cm, line)
|
6834 |
-
return wrappedLineExtentChar(cm, line, prep, ch)
|
6835 |
-
}
|
6836 |
-
var wrappedLineExtent = getWrappedLineExtent(start.sticky == "before" ? mv(start, -1) : start.ch)
|
6837 |
-
|
6838 |
-
if (cm.doc.direction == "rtl" || part.level == 1) {
|
6839 |
-
var moveInStorageOrder = (part.level == 1) == (dir < 0)
|
6840 |
-
var ch = mv(start, moveInStorageOrder ? 1 : -1)
|
6841 |
-
if (ch != null && (!moveInStorageOrder ? ch >= part.from && ch >= wrappedLineExtent.begin : ch <= part.to && ch <= wrappedLineExtent.end)) {
|
6842 |
-
// Case 2: We move within an rtl part or in an rtl editor on the same visual line
|
6843 |
-
var sticky = moveInStorageOrder ? "before" : "after"
|
6844 |
-
return new Pos(start.line, ch, sticky)
|
6845 |
-
}
|
6846 |
-
}
|
6847 |
-
|
6848 |
-
// Case 3: Could not move within this bidi part in this visual line, so leave
|
6849 |
-
// the current bidi part
|
6850 |
-
|
6851 |
-
var searchInVisualLine = function (partPos, dir, wrappedLineExtent) {
|
6852 |
-
var getRes = function (ch, moveInStorageOrder) { return moveInStorageOrder
|
6853 |
-
? new Pos(start.line, mv(ch, 1), "before")
|
6854 |
-
: new Pos(start.line, ch, "after"); }
|
6855 |
-
|
6856 |
-
for (; partPos >= 0 && partPos < bidi.length; partPos += dir) {
|
6857 |
-
var part = bidi[partPos]
|
6858 |
-
var moveInStorageOrder = (dir > 0) == (part.level != 1)
|
6859 |
-
var ch = moveInStorageOrder ? wrappedLineExtent.begin : mv(wrappedLineExtent.end, -1)
|
6860 |
-
if (part.from <= ch && ch < part.to) { return getRes(ch, moveInStorageOrder) }
|
6861 |
-
ch = moveInStorageOrder ? part.from : mv(part.to, -1)
|
6862 |
-
if (wrappedLineExtent.begin <= ch && ch < wrappedLineExtent.end) { return getRes(ch, moveInStorageOrder) }
|
6863 |
-
}
|
6864 |
-
}
|
6865 |
-
|
6866 |
-
// Case 3a: Look for other bidi parts on the same visual line
|
6867 |
-
var res = searchInVisualLine(partPos + dir, dir, wrappedLineExtent)
|
6868 |
-
if (res) { return res }
|
6869 |
-
|
6870 |
-
// Case 3b: Look for other bidi parts on the next visual line
|
6871 |
-
var nextCh = dir > 0 ? wrappedLineExtent.end : mv(wrappedLineExtent.begin, -1)
|
6872 |
-
if (nextCh != null && !(dir > 0 && nextCh == line.text.length)) {
|
6873 |
-
res = searchInVisualLine(dir > 0 ? 0 : bidi.length - 1, dir, getWrappedLineExtent(nextCh))
|
6874 |
-
if (res) { return res }
|
6875 |
-
}
|
6876 |
-
|
6877 |
-
// Case 4: Nowhere to move
|
6878 |
-
return null
|
6879 |
-
}
|
6880 |
-
|
6881 |
-
// Commands are parameter-less actions that can be performed on an
|
6882 |
-
// editor, mostly used for keybindings.
|
6883 |
-
var commands = {
|
6884 |
-
selectAll: selectAll,
|
6885 |
-
singleSelection: function (cm) { return cm.setSelection(cm.getCursor("anchor"), cm.getCursor("head"), sel_dontScroll); },
|
6886 |
-
killLine: function (cm) { return deleteNearSelection(cm, function (range) {
|
6887 |
-
if (range.empty()) {
|
6888 |
-
var len = getLine(cm.doc, range.head.line).text.length
|
6889 |
-
if (range.head.ch == len && range.head.line < cm.lastLine())
|
6890 |
-
{ return {from: range.head, to: Pos(range.head.line + 1, 0)} }
|
6891 |
-
else
|
6892 |
-
{ return {from: range.head, to: Pos(range.head.line, len)} }
|
6893 |
-
} else {
|
6894 |
-
return {from: range.from(), to: range.to()}
|
6895 |
-
}
|
6896 |
-
}); },
|
6897 |
-
deleteLine: function (cm) { return deleteNearSelection(cm, function (range) { return ({
|
6898 |
-
from: Pos(range.from().line, 0),
|
6899 |
-
to: clipPos(cm.doc, Pos(range.to().line + 1, 0))
|
6900 |
-
}); }); },
|
6901 |
-
delLineLeft: function (cm) { return deleteNearSelection(cm, function (range) { return ({
|
6902 |
-
from: Pos(range.from().line, 0), to: range.from()
|
6903 |
-
}); }); },
|
6904 |
-
delWrappedLineLeft: function (cm) { return deleteNearSelection(cm, function (range) {
|
6905 |
-
var top = cm.charCoords(range.head, "div").top + 5
|
6906 |
-
var leftPos = cm.coordsChar({left: 0, top: top}, "div")
|
6907 |
-
return {from: leftPos, to: range.from()}
|
6908 |
-
}); },
|
6909 |
-
delWrappedLineRight: function (cm) { return deleteNearSelection(cm, function (range) {
|
6910 |
-
var top = cm.charCoords(range.head, "div").top + 5
|
6911 |
-
var rightPos = cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div")
|
6912 |
-
return {from: range.from(), to: rightPos }
|
6913 |
-
}); },
|
6914 |
-
undo: function (cm) { return cm.undo(); },
|
6915 |
-
redo: function (cm) { return cm.redo(); },
|
6916 |
-
undoSelection: function (cm) { return cm.undoSelection(); },
|
6917 |
-
redoSelection: function (cm) { return cm.redoSelection(); },
|
6918 |
-
goDocStart: function (cm) { return cm.extendSelection(Pos(cm.firstLine(), 0)); },
|
6919 |
-
goDocEnd: function (cm) { return cm.extendSelection(Pos(cm.lastLine())); },
|
6920 |
-
goLineStart: function (cm) { return cm.extendSelectionsBy(function (range) { return lineStart(cm, range.head.line); },
|
6921 |
-
{origin: "+move", bias: 1}
|
6922 |
-
); },
|
6923 |
-
goLineStartSmart: function (cm) { return cm.extendSelectionsBy(function (range) { return lineStartSmart(cm, range.head); },
|
6924 |
-
{origin: "+move", bias: 1}
|
6925 |
-
); },
|
6926 |
-
goLineEnd: function (cm) { return cm.extendSelectionsBy(function (range) { return lineEnd(cm, range.head.line); },
|
6927 |
-
{origin: "+move", bias: -1}
|
6928 |
-
); },
|
6929 |
-
goLineRight: function (cm) { return cm.extendSelectionsBy(function (range) {
|
6930 |
-
var top = cm.cursorCoords(range.head, "div").top + 5
|
6931 |
-
return cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div")
|
6932 |
-
}, sel_move); },
|
6933 |
-
goLineLeft: function (cm) { return cm.extendSelectionsBy(function (range) {
|
6934 |
-
var top = cm.cursorCoords(range.head, "div").top + 5
|
6935 |
-
return cm.coordsChar({left: 0, top: top}, "div")
|
6936 |
-
}, sel_move); },
|
6937 |
-
goLineLeftSmart: function (cm) { return cm.extendSelectionsBy(function (range) {
|
6938 |
-
var top = cm.cursorCoords(range.head, "div").top + 5
|
6939 |
-
var pos = cm.coordsChar({left: 0, top: top}, "div")
|
6940 |
-
if (pos.ch < cm.getLine(pos.line).search(/\S/)) { return lineStartSmart(cm, range.head) }
|
6941 |
-
return pos
|
6942 |
-
}, sel_move); },
|
6943 |
-
goLineUp: function (cm) { return cm.moveV(-1, "line"); },
|
6944 |
-
goLineDown: function (cm) { return cm.moveV(1, "line"); },
|
6945 |
-
goPageUp: function (cm) { return cm.moveV(-1, "page"); },
|
6946 |
-
goPageDown: function (cm) { return cm.moveV(1, "page"); },
|
6947 |
-
goCharLeft: function (cm) { return cm.moveH(-1, "char"); },
|
6948 |
-
goCharRight: function (cm) { return cm.moveH(1, "char"); },
|
6949 |
-
goColumnLeft: function (cm) { return cm.moveH(-1, "column"); },
|
6950 |
-
goColumnRight: function (cm) { return cm.moveH(1, "column"); },
|
6951 |
-
goWordLeft: function (cm) { return cm.moveH(-1, "word"); },
|
6952 |
-
goGroupRight: function (cm) { return cm.moveH(1, "group"); },
|
6953 |
-
goGroupLeft: function (cm) { return cm.moveH(-1, "group"); },
|
6954 |
-
goWordRight: function (cm) { return cm.moveH(1, "word"); },
|
6955 |
-
delCharBefore: function (cm) { return cm.deleteH(-1, "char"); },
|
6956 |
-
delCharAfter: function (cm) { return cm.deleteH(1, "char"); },
|
6957 |
-
delWordBefore: function (cm) { return cm.deleteH(-1, "word"); },
|
6958 |
-
delWordAfter: function (cm) { return cm.deleteH(1, "word"); },
|
6959 |
-
delGroupBefore: function (cm) { return cm.deleteH(-1, "group"); },
|
6960 |
-
delGroupAfter: function (cm) { return cm.deleteH(1, "group"); },
|
6961 |
-
indentAuto: function (cm) { return cm.indentSelection("smart"); },
|
6962 |
-
indentMore: function (cm) { return cm.indentSelection("add"); },
|
6963 |
-
indentLess: function (cm) { return cm.indentSelection("subtract"); },
|
6964 |
-
insertTab: function (cm) { return cm.replaceSelection("\t"); },
|
6965 |
-
insertSoftTab: function (cm) {
|
6966 |
-
var spaces = [], ranges = cm.listSelections(), tabSize = cm.options.tabSize
|
6967 |
-
for (var i = 0; i < ranges.length; i++) {
|
6968 |
-
var pos = ranges[i].from()
|
6969 |
-
var col = countColumn(cm.getLine(pos.line), pos.ch, tabSize)
|
6970 |
-
spaces.push(spaceStr(tabSize - col % tabSize))
|
6971 |
-
}
|
6972 |
-
cm.replaceSelections(spaces)
|
6973 |
-
},
|
6974 |
-
defaultTab: function (cm) {
|
6975 |
-
if (cm.somethingSelected()) { cm.indentSelection("add") }
|
6976 |
-
else { cm.execCommand("insertTab") }
|
6977 |
-
},
|
6978 |
-
// Swap the two chars left and right of each selection's head.
|
6979 |
-
// Move cursor behind the two swapped characters afterwards.
|
6980 |
-
//
|
6981 |
-
// Doesn't consider line feeds a character.
|
6982 |
-
// Doesn't scan more than one line above to find a character.
|
6983 |
-
// Doesn't do anything on an empty line.
|
6984 |
-
// Doesn't do anything with non-empty selections.
|
6985 |
-
transposeChars: function (cm) { return runInOp(cm, function () {
|
6986 |
-
var ranges = cm.listSelections(), newSel = []
|
6987 |
-
for (var i = 0; i < ranges.length; i++) {
|
6988 |
-
if (!ranges[i].empty()) { continue }
|
6989 |
-
var cur = ranges[i].head, line = getLine(cm.doc, cur.line).text
|
6990 |
-
if (line) {
|
6991 |
-
if (cur.ch == line.length) { cur = new Pos(cur.line, cur.ch - 1) }
|
6992 |
-
if (cur.ch > 0) {
|
6993 |
-
cur = new Pos(cur.line, cur.ch + 1)
|
6994 |
-
cm.replaceRange(line.charAt(cur.ch - 1) + line.charAt(cur.ch - 2),
|
6995 |
-
Pos(cur.line, cur.ch - 2), cur, "+transpose")
|
6996 |
-
} else if (cur.line > cm.doc.first) {
|
6997 |
-
var prev = getLine(cm.doc, cur.line - 1).text
|
6998 |
-
if (prev) {
|
6999 |
-
cur = new Pos(cur.line, 1)
|
7000 |
-
cm.replaceRange(line.charAt(0) + cm.doc.lineSeparator() +
|
7001 |
-
prev.charAt(prev.length - 1),
|
7002 |
-
Pos(cur.line - 1, prev.length - 1), cur, "+transpose")
|
7003 |
-
}
|
7004 |
-
}
|
7005 |
-
}
|
7006 |
-
newSel.push(new Range(cur, cur))
|
7007 |
-
}
|
7008 |
-
cm.setSelections(newSel)
|
7009 |
-
}); },
|
7010 |
-
newlineAndIndent: function (cm) { return runInOp(cm, function () {
|
7011 |
-
var sels = cm.listSelections()
|
7012 |
-
for (var i = sels.length - 1; i >= 0; i--)
|
7013 |
-
{ cm.replaceRange(cm.doc.lineSeparator(), sels[i].anchor, sels[i].head, "+input") }
|
7014 |
-
sels = cm.listSelections()
|
7015 |
-
for (var i$1 = 0; i$1 < sels.length; i$1++)
|
7016 |
-
{ cm.indentLine(sels[i$1].from().line, null, true) }
|
7017 |
-
ensureCursorVisible(cm)
|
7018 |
-
}); },
|
7019 |
-
openLine: function (cm) { return cm.replaceSelection("\n", "start"); },
|
7020 |
-
toggleOverwrite: function (cm) { return cm.toggleOverwrite(); }
|
7021 |
-
}
|
7022 |
-
|
7023 |
-
|
7024 |
-
function lineStart(cm, lineN) {
|
7025 |
-
var line = getLine(cm.doc, lineN)
|
7026 |
-
var visual = visualLine(line)
|
7027 |
-
if (visual != line) { lineN = lineNo(visual) }
|
7028 |
-
return endOfLine(true, cm, visual, lineN, 1)
|
7029 |
-
}
|
7030 |
-
function lineEnd(cm, lineN) {
|
7031 |
-
var line = getLine(cm.doc, lineN)
|
7032 |
-
var visual = visualLineEnd(line)
|
7033 |
-
if (visual != line) { lineN = lineNo(visual) }
|
7034 |
-
return endOfLine(true, cm, line, lineN, -1)
|
7035 |
-
}
|
7036 |
-
function lineStartSmart(cm, pos) {
|
7037 |
-
var start = lineStart(cm, pos.line)
|
7038 |
-
var line = getLine(cm.doc, start.line)
|
7039 |
-
var order = getOrder(line, cm.doc.direction)
|
7040 |
-
if (!order || order[0].level == 0) {
|
7041 |
-
var firstNonWS = Math.max(0, line.text.search(/\S/))
|
7042 |
-
var inWS = pos.line == start.line && pos.ch <= firstNonWS && pos.ch
|
7043 |
-
return Pos(start.line, inWS ? 0 : firstNonWS, start.sticky)
|
7044 |
-
}
|
7045 |
-
return start
|
7046 |
-
}
|
7047 |
-
|
7048 |
-
// Run a handler that was bound to a key.
|
7049 |
-
function doHandleBinding(cm, bound, dropShift) {
|
7050 |
-
if (typeof bound == "string") {
|
7051 |
-
bound = commands[bound]
|
7052 |
-
if (!bound) { return false }
|
7053 |
-
}
|
7054 |
-
// Ensure previous input has been read, so that the handler sees a
|
7055 |
-
// consistent view of the document
|
7056 |
-
cm.display.input.ensurePolled()
|
7057 |
-
var prevShift = cm.display.shift, done = false
|
7058 |
-
try {
|
7059 |
-
if (cm.isReadOnly()) { cm.state.suppressEdits = true }
|
7060 |
-
if (dropShift) { cm.display.shift = false }
|
7061 |
-
done = bound(cm) != Pass
|
7062 |
-
} finally {
|
7063 |
-
cm.display.shift = prevShift
|
7064 |
-
cm.state.suppressEdits = false
|
7065 |
-
}
|
7066 |
-
return done
|
7067 |
-
}
|
7068 |
-
|
7069 |
-
function lookupKeyForEditor(cm, name, handle) {
|
7070 |
-
for (var i = 0; i < cm.state.keyMaps.length; i++) {
|
7071 |
-
var result = lookupKey(name, cm.state.keyMaps[i], handle, cm)
|
7072 |
-
if (result) { return result }
|
7073 |
-
}
|
7074 |
-
return (cm.options.extraKeys && lookupKey(name, cm.options.extraKeys, handle, cm))
|
7075 |
-
|| lookupKey(name, cm.options.keyMap, handle, cm)
|
7076 |
-
}
|
7077 |
-
|
7078 |
-
// Note that, despite the name, this function is also used to check
|
7079 |
-
// for bound mouse clicks.
|
7080 |
-
|
7081 |
-
var stopSeq = new Delayed
|
7082 |
-
|
7083 |
-
function dispatchKey(cm, name, e, handle) {
|
7084 |
-
var seq = cm.state.keySeq
|
7085 |
-
if (seq) {
|
7086 |
-
if (isModifierKey(name)) { return "handled" }
|
7087 |
-
if (/\'$/.test(name))
|
7088 |
-
{ cm.state.keySeq = null }
|
7089 |
-
else
|
7090 |
-
{ stopSeq.set(50, function () {
|
7091 |
-
if (cm.state.keySeq == seq) {
|
7092 |
-
cm.state.keySeq = null
|
7093 |
-
cm.display.input.reset()
|
7094 |
-
}
|
7095 |
-
}) }
|
7096 |
-
if (dispatchKeyInner(cm, seq + " " + name, e, handle)) { return true }
|
7097 |
-
}
|
7098 |
-
return dispatchKeyInner(cm, name, e, handle)
|
7099 |
-
}
|
7100 |
-
|
7101 |
-
function dispatchKeyInner(cm, name, e, handle) {
|
7102 |
-
var result = lookupKeyForEditor(cm, name, handle)
|
7103 |
-
|
7104 |
-
if (result == "multi")
|
7105 |
-
{ cm.state.keySeq = name }
|
7106 |
-
if (result == "handled")
|
7107 |
-
{ signalLater(cm, "keyHandled", cm, name, e) }
|
7108 |
-
|
7109 |
-
if (result == "handled" || result == "multi") {
|
7110 |
-
e_preventDefault(e)
|
7111 |
-
restartBlink(cm)
|
7112 |
-
}
|
7113 |
-
|
7114 |
-
return !!result
|
7115 |
-
}
|
7116 |
-
|
7117 |
-
// Handle a key from the keydown event.
|
7118 |
-
function handleKeyBinding(cm, e) {
|
7119 |
-
var name = keyName(e, true)
|
7120 |
-
if (!name) { return false }
|
7121 |
-
|
7122 |
-
if (e.shiftKey && !cm.state.keySeq) {
|
7123 |
-
// First try to resolve full name (including 'Shift-'). Failing
|
7124 |
-
// that, see if there is a cursor-motion command (starting with
|
7125 |
-
// 'go') bound to the keyname without 'Shift-'.
|
7126 |
-
return dispatchKey(cm, "Shift-" + name, e, function (b) { return doHandleBinding(cm, b, true); })
|
7127 |
-
|| dispatchKey(cm, name, e, function (b) {
|
7128 |
-
if (typeof b == "string" ? /^go[A-Z]/.test(b) : b.motion)
|
7129 |
-
{ return doHandleBinding(cm, b) }
|
7130 |
-
})
|
7131 |
-
} else {
|
7132 |
-
return dispatchKey(cm, name, e, function (b) { return doHandleBinding(cm, b); })
|
7133 |
-
}
|
7134 |
-
}
|
7135 |
-
|
7136 |
-
// Handle a key from the keypress event
|
7137 |
-
function handleCharBinding(cm, e, ch) {
|
7138 |
-
return dispatchKey(cm, "'" + ch + "'", e, function (b) { return doHandleBinding(cm, b, true); })
|
7139 |
-
}
|
7140 |
-
|
7141 |
-
var lastStoppedKey = null
|
7142 |
-
function onKeyDown(e) {
|
7143 |
-
var cm = this
|
7144 |
-
cm.curOp.focus = activeElt()
|
7145 |
-
if (signalDOMEvent(cm, e)) { return }
|
7146 |
-
// IE does strange things with escape.
|
7147 |
-
if (ie && ie_version < 11 && e.keyCode == 27) { e.returnValue = false }
|
7148 |
-
var code = e.keyCode
|
7149 |
-
cm.display.shift = code == 16 || e.shiftKey
|
7150 |
-
var handled = handleKeyBinding(cm, e)
|
7151 |
-
if (presto) {
|
7152 |
-
lastStoppedKey = handled ? code : null
|
7153 |
-
// Opera has no cut event... we try to at least catch the key combo
|
7154 |
-
if (!handled && code == 88 && !hasCopyEvent && (mac ? e.metaKey : e.ctrlKey))
|
7155 |
-
{ cm.replaceSelection("", null, "cut") }
|
7156 |
-
}
|
7157 |
-
|
7158 |
-
// Turn mouse into crosshair when Alt is held on Mac.
|
7159 |
-
if (code == 18 && !/\bCodeMirror-crosshair\b/.test(cm.display.lineDiv.className))
|
7160 |
-
{ showCrossHair(cm) }
|
7161 |
-
}
|
7162 |
-
|
7163 |
-
function showCrossHair(cm) {
|
7164 |
-
var lineDiv = cm.display.lineDiv
|
7165 |
-
addClass(lineDiv, "CodeMirror-crosshair")
|
7166 |
-
|
7167 |
-
function up(e) {
|
7168 |
-
if (e.keyCode == 18 || !e.altKey) {
|
7169 |
-
rmClass(lineDiv, "CodeMirror-crosshair")
|
7170 |
-
off(document, "keyup", up)
|
7171 |
-
off(document, "mouseover", up)
|
7172 |
-
}
|
7173 |
-
}
|
7174 |
-
on(document, "keyup", up)
|
7175 |
-
on(document, "mouseover", up)
|
7176 |
-
}
|
7177 |
-
|
7178 |
-
function onKeyUp(e) {
|
7179 |
-
if (e.keyCode == 16) { this.doc.sel.shift = false }
|
7180 |
-
signalDOMEvent(this, e)
|
7181 |
-
}
|
7182 |
-
|
7183 |
-
function onKeyPress(e) {
|
7184 |
-
var cm = this
|
7185 |
-
if (eventInWidget(cm.display, e) || signalDOMEvent(cm, e) || e.ctrlKey && !e.altKey || mac && e.metaKey) { return }
|
7186 |
-
var keyCode = e.keyCode, charCode = e.charCode
|
7187 |
-
if (presto && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return}
|
7188 |
-
if ((presto && (!e.which || e.which < 10)) && handleKeyBinding(cm, e)) { return }
|
7189 |
-
var ch = String.fromCharCode(charCode == null ? keyCode : charCode)
|
7190 |
-
// Some browsers fire keypress events for backspace
|
7191 |
-
if (ch == "\x08") { return }
|
7192 |
-
if (handleCharBinding(cm, e, ch)) { return }
|
7193 |
-
cm.display.input.onKeyPress(e)
|
7194 |
-
}
|
7195 |
-
|
7196 |
-
var DOUBLECLICK_DELAY = 400
|
7197 |
-
|
7198 |
-
var PastClick = function(time, pos, button) {
|
7199 |
-
this.time = time
|
7200 |
-
this.pos = pos
|
7201 |
-
this.button = button
|
7202 |
-
};
|
7203 |
-
|
7204 |
-
PastClick.prototype.compare = function (time, pos, button) {
|
7205 |
-
return this.time + DOUBLECLICK_DELAY > time &&
|
7206 |
-
cmp(pos, this.pos) == 0 && button == this.button
|
7207 |
-
};
|
7208 |
-
|
7209 |
-
var lastClick;
|
7210 |
-
var lastDoubleClick;
|
7211 |
-
function clickRepeat(pos, button) {
|
7212 |
-
var now = +new Date
|
7213 |
-
if (lastDoubleClick && lastDoubleClick.compare(now, pos, button)) {
|
7214 |
-
lastClick = lastDoubleClick = null
|
7215 |
-
return "triple"
|
7216 |
-
} else if (lastClick && lastClick.compare(now, pos, button)) {
|
7217 |
-
lastDoubleClick = new PastClick(now, pos, button)
|
7218 |
-
lastClick = null
|
7219 |
-
return "double"
|
7220 |
-
} else {
|
7221 |
-
lastClick = new PastClick(now, pos, button)
|
7222 |
-
lastDoubleClick = null
|
7223 |
-
return "single"
|
7224 |
-
}
|
7225 |
-
}
|
7226 |
-
|
7227 |
-
// A mouse down can be a single click, double click, triple click,
|
7228 |
-
// start of selection drag, start of text drag, new cursor
|
7229 |
-
// (ctrl-click), rectangle drag (alt-drag), or xwin
|
7230 |
-
// middle-click-paste. Or it might be a click on something we should
|
7231 |
-
// not interfere with, such as a scrollbar or widget.
|
7232 |
-
function onMouseDown(e) {
|
7233 |
-
var cm = this, display = cm.display
|
7234 |
-
if (signalDOMEvent(cm, e) || display.activeTouch && display.input.supportsTouch()) { return }
|
7235 |
-
display.input.ensurePolled()
|
7236 |
-
display.shift = e.shiftKey
|
7237 |
-
|
7238 |
-
if (eventInWidget(display, e)) {
|
7239 |
-
if (!webkit) {
|
7240 |
-
// Briefly turn off draggability, to allow widgets to do
|
7241 |
-
// normal dragging things.
|
7242 |
-
display.scroller.draggable = false
|
7243 |
-
setTimeout(function () { return display.scroller.draggable = true; }, 100)
|
7244 |
-
}
|
7245 |
-
return
|
7246 |
-
}
|
7247 |
-
if (clickInGutter(cm, e)) { return }
|
7248 |
-
var pos = posFromMouse(cm, e), button = e_button(e), repeat = pos ? clickRepeat(pos, button) : "single"
|
7249 |
-
window.focus()
|
7250 |
-
|
7251 |
-
// #3261: make sure, that we're not starting a second selection
|
7252 |
-
if (button == 1 && cm.state.selectingText)
|
7253 |
-
{ cm.state.selectingText(e) }
|
7254 |
-
|
7255 |
-
if (pos && handleMappedButton(cm, button, pos, repeat, e)) { return }
|
7256 |
-
|
7257 |
-
if (button == 1) {
|
7258 |
-
if (pos) { leftButtonDown(cm, pos, repeat, e) }
|
7259 |
-
else if (e_target(e) == display.scroller) { e_preventDefault(e) }
|
7260 |
-
} else if (button == 2) {
|
7261 |
-
if (pos) { extendSelection(cm.doc, pos) }
|
7262 |
-
setTimeout(function () { return display.input.focus(); }, 20)
|
7263 |
-
} else if (button == 3) {
|
7264 |
-
if (captureRightClick) { onContextMenu(cm, e) }
|
7265 |
-
else { delayBlurEvent(cm) }
|
7266 |
-
}
|
7267 |
-
}
|
7268 |
-
|
7269 |
-
function handleMappedButton(cm, button, pos, repeat, event) {
|
7270 |
-
var name = "Click"
|
7271 |
-
if (repeat == "double") { name = "Double" + name }
|
7272 |
-
else if (repeat == "triple") { name = "Triple" + name }
|
7273 |
-
name = (button == 1 ? "Left" : button == 2 ? "Middle" : "Right") + name
|
7274 |
-
|
7275 |
-
return dispatchKey(cm, addModifierNames(name, event), event, function (bound) {
|
7276 |
-
if (typeof bound == "string") { bound = commands[bound] }
|
7277 |
-
if (!bound) { return false }
|
7278 |
-
var done = false
|
7279 |
-
try {
|
7280 |
-
if (cm.isReadOnly()) { cm.state.suppressEdits = true }
|
7281 |
-
done = bound(cm, pos) != Pass
|
7282 |
-
} finally {
|
7283 |
-
cm.state.suppressEdits = false
|
7284 |
-
}
|
7285 |
-
return done
|
7286 |
-
})
|
7287 |
-
}
|
7288 |
-
|
7289 |
-
function configureMouse(cm, repeat, event) {
|
7290 |
-
var option = cm.getOption("configureMouse")
|
7291 |
-
var value = option ? option(cm, repeat, event) : {}
|
7292 |
-
if (value.unit == null) {
|
7293 |
-
var rect = chromeOS ? event.shiftKey && event.metaKey : event.altKey
|
7294 |
-
value.unit = rect ? "rectangle" : repeat == "single" ? "char" : repeat == "double" ? "word" : "line"
|
7295 |
-
}
|
7296 |
-
if (value.extend == null || cm.doc.extend) { value.extend = cm.doc.extend || event.shiftKey }
|
7297 |
-
if (value.addNew == null) { value.addNew = mac ? event.metaKey : event.ctrlKey }
|
7298 |
-
if (value.moveOnDrag == null) { value.moveOnDrag = !(mac ? event.altKey : event.ctrlKey) }
|
7299 |
-
return value
|
7300 |
-
}
|
7301 |
-
|
7302 |
-
function leftButtonDown(cm, pos, repeat, event) {
|
7303 |
-
if (ie) { setTimeout(bind(ensureFocus, cm), 0) }
|
7304 |
-
else { cm.curOp.focus = activeElt() }
|
7305 |
-
|
7306 |
-
var behavior = configureMouse(cm, repeat, event)
|
7307 |
-
|
7308 |
-
var sel = cm.doc.sel, contained
|
7309 |
-
if (cm.options.dragDrop && dragAndDrop && !cm.isReadOnly() &&
|
7310 |
-
repeat == "single" && (contained = sel.contains(pos)) > -1 &&
|
7311 |
-
(cmp((contained = sel.ranges[contained]).from(), pos) < 0 || pos.xRel > 0) &&
|
7312 |
-
(cmp(contained.to(), pos) > 0 || pos.xRel < 0))
|
7313 |
-
{ leftButtonStartDrag(cm, event, pos, behavior) }
|
7314 |
-
else
|
7315 |
-
{ leftButtonSelect(cm, event, pos, behavior) }
|
7316 |
-
}
|
7317 |
-
|
7318 |
-
// Start a text drag. When it ends, see if any dragging actually
|
7319 |
-
// happen, and treat as a click if it didn't.
|
7320 |
-
function leftButtonStartDrag(cm, event, pos, behavior) {
|
7321 |
-
var display = cm.display, moved = false
|
7322 |
-
var dragEnd = operation(cm, function (e) {
|
7323 |
-
if (webkit) { display.scroller.draggable = false }
|
7324 |
-
cm.state.draggingText = false
|
7325 |
-
off(display.wrapper.ownerDocument, "mouseup", dragEnd)
|
7326 |
-
off(display.wrapper.ownerDocument, "mousemove", mouseMove)
|
7327 |
-
off(display.scroller, "dragstart", dragStart)
|
7328 |
-
off(display.scroller, "drop", dragEnd)
|
7329 |
-
if (!moved) {
|
7330 |
-
e_preventDefault(e)
|
7331 |
-
if (!behavior.addNew)
|
7332 |
-
{ extendSelection(cm.doc, pos, null, null, behavior.extend) }
|
7333 |
-
// Work around unexplainable focus problem in IE9 (#2127) and Chrome (#3081)
|
7334 |
-
if (webkit || ie && ie_version == 9)
|
7335 |
-
{ setTimeout(function () {display.wrapper.ownerDocument.body.focus(); display.input.focus()}, 20) }
|
7336 |
-
else
|
7337 |
-
{ display.input.focus() }
|
7338 |
-
}
|
7339 |
-
})
|
7340 |
-
var mouseMove = function(e2) {
|
7341 |
-
moved = moved || Math.abs(event.clientX - e2.clientX) + Math.abs(event.clientY - e2.clientY) >= 10
|
7342 |
-
}
|
7343 |
-
var dragStart = function () { return moved = true; }
|
7344 |
-
// Let the drag handler handle this.
|
7345 |
-
if (webkit) { display.scroller.draggable = true }
|
7346 |
-
cm.state.draggingText = dragEnd
|
7347 |
-
dragEnd.copy = !behavior.moveOnDrag
|
7348 |
-
// IE's approach to draggable
|
7349 |
-
if (display.scroller.dragDrop) { display.scroller.dragDrop() }
|
7350 |
-
on(display.wrapper.ownerDocument, "mouseup", dragEnd)
|
7351 |
-
on(display.wrapper.ownerDocument, "mousemove", mouseMove)
|
7352 |
-
on(display.scroller, "dragstart", dragStart)
|
7353 |
-
on(display.scroller, "drop", dragEnd)
|
7354 |
-
|
7355 |
-
delayBlurEvent(cm)
|
7356 |
-
setTimeout(function () { return display.input.focus(); }, 20)
|
7357 |
-
}
|
7358 |
-
|
7359 |
-
function rangeForUnit(cm, pos, unit) {
|
7360 |
-
if (unit == "char") { return new Range(pos, pos) }
|
7361 |
-
if (unit == "word") { return cm.findWordAt(pos) }
|
7362 |
-
if (unit == "line") { return new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0))) }
|
7363 |
-
var result = unit(cm, pos)
|
7364 |
-
return new Range(result.from, result.to)
|
7365 |
-
}
|
7366 |
-
|
7367 |
-
// Normal selection, as opposed to text dragging.
|
7368 |
-
function leftButtonSelect(cm, event, start, behavior) {
|
7369 |
-
var display = cm.display, doc = cm.doc
|
7370 |
-
e_preventDefault(event)
|
7371 |
-
|
7372 |
-
var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges
|
7373 |
-
if (behavior.addNew && !behavior.extend) {
|
7374 |
-
ourIndex = doc.sel.contains(start)
|
7375 |
-
if (ourIndex > -1)
|
7376 |
-
{ ourRange = ranges[ourIndex] }
|
7377 |
-
else
|
7378 |
-
{ ourRange = new Range(start, start) }
|
7379 |
-
} else {
|
7380 |
-
ourRange = doc.sel.primary()
|
7381 |
-
ourIndex = doc.sel.primIndex
|
7382 |
-
}
|
7383 |
-
|
7384 |
-
if (behavior.unit == "rectangle") {
|
7385 |
-
if (!behavior.addNew) { ourRange = new Range(start, start) }
|
7386 |
-
start = posFromMouse(cm, event, true, true)
|
7387 |
-
ourIndex = -1
|
7388 |
-
} else {
|
7389 |
-
var range = rangeForUnit(cm, start, behavior.unit)
|
7390 |
-
if (behavior.extend)
|
7391 |
-
{ ourRange = extendRange(ourRange, range.anchor, range.head, behavior.extend) }
|
7392 |
-
else
|
7393 |
-
{ ourRange = range }
|
7394 |
-
}
|
7395 |
-
|
7396 |
-
if (!behavior.addNew) {
|
7397 |
-
ourIndex = 0
|
7398 |
-
setSelection(doc, new Selection([ourRange], 0), sel_mouse)
|
7399 |
-
startSel = doc.sel
|
7400 |
-
} else if (ourIndex == -1) {
|
7401 |
-
ourIndex = ranges.length
|
7402 |
-
setSelection(doc, normalizeSelection(ranges.concat([ourRange]), ourIndex),
|
7403 |
-
{scroll: false, origin: "*mouse"})
|
7404 |
-
} else if (ranges.length > 1 && ranges[ourIndex].empty() && behavior.unit == "char" && !behavior.extend) {
|
7405 |
-
setSelection(doc, normalizeSelection(ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0),
|
7406 |
-
{scroll: false, origin: "*mouse"})
|
7407 |
-
startSel = doc.sel
|
7408 |
-
} else {
|
7409 |
-
replaceOneSelection(doc, ourIndex, ourRange, sel_mouse)
|
7410 |
-
}
|
7411 |
-
|
7412 |
-
var lastPos = start
|
7413 |
-
function extendTo(pos) {
|
7414 |
-
if (cmp(lastPos, pos) == 0) { return }
|
7415 |
-
lastPos = pos
|
7416 |
-
|
7417 |
-
if (behavior.unit == "rectangle") {
|
7418 |
-
var ranges = [], tabSize = cm.options.tabSize
|
7419 |
-
var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize)
|
7420 |
-
var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize)
|
7421 |
-
var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol)
|
7422 |
-
for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line));
|
7423 |
-
line <= end; line++) {
|
7424 |
-
var text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize)
|
7425 |
-
if (left == right)
|
7426 |
-
{ ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos))) }
|
7427 |
-
else if (text.length > leftPos)
|
7428 |
-
{ ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize)))) }
|
7429 |
-
}
|
7430 |
-
if (!ranges.length) { ranges.push(new Range(start, start)) }
|
7431 |
-
setSelection(doc, normalizeSelection(startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex),
|
7432 |
-
{origin: "*mouse", scroll: false})
|
7433 |
-
cm.scrollIntoView(pos)
|
7434 |
-
} else {
|
7435 |
-
var oldRange = ourRange
|
7436 |
-
var range = rangeForUnit(cm, pos, behavior.unit)
|
7437 |
-
var anchor = oldRange.anchor, head
|
7438 |
-
if (cmp(range.anchor, anchor) > 0) {
|
7439 |
-
head = range.head
|
7440 |
-
anchor = minPos(oldRange.from(), range.anchor)
|
7441 |
-
} else {
|
7442 |
-
head = range.anchor
|
7443 |
-
anchor = maxPos(oldRange.to(), range.head)
|
7444 |
-
}
|
7445 |
-
var ranges$1 = startSel.ranges.slice(0)
|
7446 |
-
ranges$1[ourIndex] = bidiSimplify(cm, new Range(clipPos(doc, anchor), head))
|
7447 |
-
setSelection(doc, normalizeSelection(ranges$1, ourIndex), sel_mouse)
|
7448 |
-
}
|
7449 |
-
}
|
7450 |
-
|
7451 |
-
var editorSize = display.wrapper.getBoundingClientRect()
|
7452 |
-
// Used to ensure timeout re-tries don't fire when another extend
|
7453 |
-
// happened in the meantime (clearTimeout isn't reliable -- at
|
7454 |
-
// least on Chrome, the timeouts still happen even when cleared,
|
7455 |
-
// if the clear happens after their scheduled firing time).
|
7456 |
-
var counter = 0
|
7457 |
-
|
7458 |
-
function extend(e) {
|
7459 |
-
var curCount = ++counter
|
7460 |
-
var cur = posFromMouse(cm, e, true, behavior.unit == "rectangle")
|
7461 |
-
if (!cur) { return }
|
7462 |
-
if (cmp(cur, lastPos) != 0) {
|
7463 |
-
cm.curOp.focus = activeElt()
|
7464 |
-
extendTo(cur)
|
7465 |
-
var visible = visibleLines(display, doc)
|
7466 |
-
if (cur.line >= visible.to || cur.line < visible.from)
|
7467 |
-
{ setTimeout(operation(cm, function () {if (counter == curCount) { extend(e) }}), 150) }
|
7468 |
-
} else {
|
7469 |
-
var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0
|
7470 |
-
if (outside) { setTimeout(operation(cm, function () {
|
7471 |
-
if (counter != curCount) { return }
|
7472 |
-
display.scroller.scrollTop += outside
|
7473 |
-
extend(e)
|
7474 |
-
}), 50) }
|
7475 |
-
}
|
7476 |
-
}
|
7477 |
-
|
7478 |
-
function done(e) {
|
7479 |
-
cm.state.selectingText = false
|
7480 |
-
counter = Infinity
|
7481 |
-
e_preventDefault(e)
|
7482 |
-
display.input.focus()
|
7483 |
-
off(display.wrapper.ownerDocument, "mousemove", move)
|
7484 |
-
off(display.wrapper.ownerDocument, "mouseup", up)
|
7485 |
-
doc.history.lastSelOrigin = null
|
7486 |
-
}
|
7487 |
-
|
7488 |
-
var move = operation(cm, function (e) {
|
7489 |
-
if (e.buttons === 0 || !e_button(e)) { done(e) }
|
7490 |
-
else { extend(e) }
|
7491 |
-
})
|
7492 |
-
var up = operation(cm, done)
|
7493 |
-
cm.state.selectingText = up
|
7494 |
-
on(display.wrapper.ownerDocument, "mousemove", move)
|
7495 |
-
on(display.wrapper.ownerDocument, "mouseup", up)
|
7496 |
-
}
|
7497 |
-
|
7498 |
-
// Used when mouse-selecting to adjust the anchor to the proper side
|
7499 |
-
// of a bidi jump depending on the visual position of the head.
|
7500 |
-
function bidiSimplify(cm, range) {
|
7501 |
-
var anchor = range.anchor;
|
7502 |
-
var head = range.head;
|
7503 |
-
var anchorLine = getLine(cm.doc, anchor.line)
|
7504 |
-
if (cmp(anchor, head) == 0 && anchor.sticky == head.sticky) { return range }
|
7505 |
-
var order = getOrder(anchorLine)
|
7506 |
-
if (!order) { return range }
|
7507 |
-
var index = getBidiPartAt(order, anchor.ch, anchor.sticky), part = order[index]
|
7508 |
-
if (part.from != anchor.ch && part.to != anchor.ch) { return range }
|
7509 |
-
var boundary = index + ((part.from == anchor.ch) == (part.level != 1) ? 0 : 1)
|
7510 |
-
if (boundary == 0 || boundary == order.length) { return range }
|
7511 |
-
|
7512 |
-
// Compute the relative visual position of the head compared to the
|
7513 |
-
// anchor (<0 is to the left, >0 to the right)
|
7514 |
-
var leftSide
|
7515 |
-
if (head.line != anchor.line) {
|
7516 |
-
leftSide = (head.line - anchor.line) * (cm.doc.direction == "ltr" ? 1 : -1) > 0
|
7517 |
-
} else {
|
7518 |
-
var headIndex = getBidiPartAt(order, head.ch, head.sticky)
|
7519 |
-
var dir = headIndex - index || (head.ch - anchor.ch) * (part.level == 1 ? -1 : 1)
|
7520 |
-
if (headIndex == boundary - 1 || headIndex == boundary)
|
7521 |
-
{ leftSide = dir < 0 }
|
7522 |
-
else
|
7523 |
-
{ leftSide = dir > 0 }
|
7524 |
-
}
|
7525 |
-
|
7526 |
-
var usePart = order[boundary + (leftSide ? -1 : 0)]
|
7527 |
-
var from = leftSide == (usePart.level == 1)
|
7528 |
-
var ch = from ? usePart.from : usePart.to, sticky = from ? "after" : "before"
|
7529 |
-
return anchor.ch == ch && anchor.sticky == sticky ? range : new Range(new Pos(anchor.line, ch, sticky), head)
|
7530 |
-
}
|
7531 |
-
|
7532 |
-
|
7533 |
-
// Determines whether an event happened in the gutter, and fires the
|
7534 |
-
// handlers for the corresponding event.
|
7535 |
-
function gutterEvent(cm, e, type, prevent) {
|
7536 |
-
var mX, mY
|
7537 |
-
if (e.touches) {
|
7538 |
-
mX = e.touches[0].clientX
|
7539 |
-
mY = e.touches[0].clientY
|
7540 |
-
} else {
|
7541 |
-
try { mX = e.clientX; mY = e.clientY }
|
7542 |
-
catch(e) { return false }
|
7543 |
-
}
|
7544 |
-
if (mX >= Math.floor(cm.display.gutters.getBoundingClientRect().right)) { return false }
|
7545 |
-
if (prevent) { e_preventDefault(e) }
|
7546 |
-
|
7547 |
-
var display = cm.display
|
7548 |
-
var lineBox = display.lineDiv.getBoundingClientRect()
|
7549 |
-
|
7550 |
-
if (mY > lineBox.bottom || !hasHandler(cm, type)) { return e_defaultPrevented(e) }
|
7551 |
-
mY -= lineBox.top - display.viewOffset
|
7552 |
-
|
7553 |
-
for (var i = 0; i < cm.options.gutters.length; ++i) {
|
7554 |
-
var g = display.gutters.childNodes[i]
|
7555 |
-
if (g && g.getBoundingClientRect().right >= mX) {
|
7556 |
-
var line = lineAtHeight(cm.doc, mY)
|
7557 |
-
var gutter = cm.options.gutters[i]
|
7558 |
-
signal(cm, type, cm, line, gutter, e)
|
7559 |
-
return e_defaultPrevented(e)
|
7560 |
-
}
|
7561 |
-
}
|
7562 |
-
}
|
7563 |
-
|
7564 |
-
function clickInGutter(cm, e) {
|
7565 |
-
return gutterEvent(cm, e, "gutterClick", true)
|
7566 |
-
}
|
7567 |
-
|
7568 |
-
// CONTEXT MENU HANDLING
|
7569 |
-
|
7570 |
-
// To make the context menu work, we need to briefly unhide the
|
7571 |
-
// textarea (making it as unobtrusive as possible) to let the
|
7572 |
-
// right-click take effect on it.
|
7573 |
-
function onContextMenu(cm, e) {
|
7574 |
-
if (eventInWidget(cm.display, e) || contextMenuInGutter(cm, e)) { return }
|
7575 |
-
if (signalDOMEvent(cm, e, "contextmenu")) { return }
|
7576 |
-
cm.display.input.onContextMenu(e)
|
7577 |
-
}
|
7578 |
-
|
7579 |
-
function contextMenuInGutter(cm, e) {
|
7580 |
-
if (!hasHandler(cm, "gutterContextMenu")) { return false }
|
7581 |
-
return gutterEvent(cm, e, "gutterContextMenu", false)
|
7582 |
-
}
|
7583 |
-
|
7584 |
-
function themeChanged(cm) {
|
7585 |
-
cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") +
|
7586 |
-
cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-")
|
7587 |
-
clearCaches(cm)
|
7588 |
-
}
|
7589 |
-
|
7590 |
-
var Init = {toString: function(){return "CodeMirror.Init"}}
|
7591 |
-
|
7592 |
-
var defaults = {}
|
7593 |
-
var optionHandlers = {}
|
7594 |
-
|
7595 |
-
function defineOptions(CodeMirror) {
|
7596 |
-
var optionHandlers = CodeMirror.optionHandlers
|
7597 |
-
|
7598 |
-
function option(name, deflt, handle, notOnInit) {
|
7599 |
-
CodeMirror.defaults[name] = deflt
|
7600 |
-
if (handle) { optionHandlers[name] =
|
7601 |
-
notOnInit ? function (cm, val, old) {if (old != Init) { handle(cm, val, old) }} : handle }
|
7602 |
-
}
|
7603 |
-
|
7604 |
-
CodeMirror.defineOption = option
|
7605 |
-
|
7606 |
-
// Passed to option handlers when there is no old value.
|
7607 |
-
CodeMirror.Init = Init
|
7608 |
-
|
7609 |
-
// These two are, on init, called from the constructor because they
|
7610 |
-
// have to be initialized before the editor can start at all.
|
7611 |
-
option("value", "", function (cm, val) { return cm.setValue(val); }, true)
|
7612 |
-
option("mode", null, function (cm, val) {
|
7613 |
-
cm.doc.modeOption = val
|
7614 |
-
loadMode(cm)
|
7615 |
-
}, true)
|
7616 |
-
|
7617 |
-
option("indentUnit", 2, loadMode, true)
|
7618 |
-
option("indentWithTabs", false)
|
7619 |
-
option("smartIndent", true)
|
7620 |
-
option("tabSize", 4, function (cm) {
|
7621 |
-
resetModeState(cm)
|
7622 |
-
clearCaches(cm)
|
7623 |
-
regChange(cm)
|
7624 |
-
}, true)
|
7625 |
-
|
7626 |
-
option("lineSeparator", null, function (cm, val) {
|
7627 |
-
cm.doc.lineSep = val
|
7628 |
-
if (!val) { return }
|
7629 |
-
var newBreaks = [], lineNo = cm.doc.first
|
7630 |
-
cm.doc.iter(function (line) {
|
7631 |
-
for (var pos = 0;;) {
|
7632 |
-
var found = line.text.indexOf(val, pos)
|
7633 |
-
if (found == -1) { break }
|
7634 |
-
pos = found + val.length
|
7635 |
-
newBreaks.push(Pos(lineNo, found))
|
7636 |
-
}
|
7637 |
-
lineNo++
|
7638 |
-
})
|
7639 |
-
for (var i = newBreaks.length - 1; i >= 0; i--)
|
7640 |
-
{ replaceRange(cm.doc, val, newBreaks[i], Pos(newBreaks[i].line, newBreaks[i].ch + val.length)) }
|
7641 |
-
})
|
7642 |
-
option("specialChars", /[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200f\u2028\u2029\ufeff]/g, function (cm, val, old) {
|
7643 |
-
cm.state.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g")
|
7644 |
-
if (old != Init) { cm.refresh() }
|
7645 |
-
})
|
7646 |
-
option("specialCharPlaceholder", defaultSpecialCharPlaceholder, function (cm) { return cm.refresh(); }, true)
|
7647 |
-
option("electricChars", true)
|
7648 |
-
option("inputStyle", mobile ? "contenteditable" : "textarea", function () {
|
7649 |
-
throw new Error("inputStyle can not (yet) be changed in a running editor") // FIXME
|
7650 |
-
}, true)
|
7651 |
-
option("spellcheck", false, function (cm, val) { return cm.getInputField().spellcheck = val; }, true)
|
7652 |
-
option("rtlMoveVisually", !windows)
|
7653 |
-
option("wholeLineUpdateBefore", true)
|
7654 |
-
|
7655 |
-
option("theme", "default", function (cm) {
|
7656 |
-
themeChanged(cm)
|
7657 |
-
guttersChanged(cm)
|
7658 |
-
}, true)
|
7659 |
-
option("keyMap", "default", function (cm, val, old) {
|
7660 |
-
var next = getKeyMap(val)
|
7661 |
-
var prev = old != Init && getKeyMap(old)
|
7662 |
-
if (prev && prev.detach) { prev.detach(cm, next) }
|
7663 |
-
if (next.attach) { next.attach(cm, prev || null) }
|
7664 |
-
})
|
7665 |
-
option("extraKeys", null)
|
7666 |
-
option("configureMouse", null)
|
7667 |
-
|
7668 |
-
option("lineWrapping", false, wrappingChanged, true)
|
7669 |
-
option("gutters", [], function (cm) {
|
7670 |
-
setGuttersForLineNumbers(cm.options)
|
7671 |
-
guttersChanged(cm)
|
7672 |
-
}, true)
|
7673 |
-
option("fixedGutter", true, function (cm, val) {
|
7674 |
-
cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0"
|
7675 |
-
cm.refresh()
|
7676 |
-
}, true)
|
7677 |
-
option("coverGutterNextToScrollbar", false, function (cm) { return updateScrollbars(cm); }, true)
|
7678 |
-
option("scrollbarStyle", "native", function (cm) {
|
7679 |
-
initScrollbars(cm)
|
7680 |
-
updateScrollbars(cm)
|
7681 |
-
cm.display.scrollbars.setScrollTop(cm.doc.scrollTop)
|
7682 |
-
cm.display.scrollbars.setScrollLeft(cm.doc.scrollLeft)
|
7683 |
-
}, true)
|
7684 |
-
option("lineNumbers", false, function (cm) {
|
7685 |
-
setGuttersForLineNumbers(cm.options)
|
7686 |
-
guttersChanged(cm)
|
7687 |
-
}, true)
|
7688 |
-
option("firstLineNumber", 1, guttersChanged, true)
|
7689 |
-
option("lineNumberFormatter", function (integer) { return integer; }, guttersChanged, true)
|
7690 |
-
option("showCursorWhenSelecting", false, updateSelection, true)
|
7691 |
-
|
7692 |
-
option("resetSelectionOnContextMenu", true)
|
7693 |
-
option("lineWiseCopyCut", true)
|
7694 |
-
option("pasteLinesPerSelection", true)
|
7695 |
-
|
7696 |
-
option("readOnly", false, function (cm, val) {
|
7697 |
-
if (val == "nocursor") {
|
7698 |
-
onBlur(cm)
|
7699 |
-
cm.display.input.blur()
|
7700 |
-
}
|
7701 |
-
cm.display.input.readOnlyChanged(val)
|
7702 |
-
})
|
7703 |
-
option("disableInput", false, function (cm, val) {if (!val) { cm.display.input.reset() }}, true)
|
7704 |
-
option("dragDrop", true, dragDropChanged)
|
7705 |
-
option("allowDropFileTypes", null)
|
7706 |
-
|
7707 |
-
option("cursorBlinkRate", 530)
|
7708 |
-
option("cursorScrollMargin", 0)
|
7709 |
-
option("cursorHeight", 1, updateSelection, true)
|
7710 |
-
option("singleCursorHeightPerLine", true, updateSelection, true)
|
7711 |
-
option("workTime", 100)
|
7712 |
-
option("workDelay", 100)
|
7713 |
-
option("flattenSpans", true, resetModeState, true)
|
7714 |
-
option("addModeClass", false, resetModeState, true)
|
7715 |
-
option("pollInterval", 100)
|
7716 |
-
option("undoDepth", 200, function (cm, val) { return cm.doc.history.undoDepth = val; })
|
7717 |
-
option("historyEventDelay", 1250)
|
7718 |
-
option("viewportMargin", 10, function (cm) { return cm.refresh(); }, true)
|
7719 |
-
option("maxHighlightLength", 10000, resetModeState, true)
|
7720 |
-
option("moveInputWithCursor", true, function (cm, val) {
|
7721 |
-
if (!val) { cm.display.input.resetPosition() }
|
7722 |
-
})
|
7723 |
-
|
7724 |
-
option("tabindex", null, function (cm, val) { return cm.display.input.getField().tabIndex = val || ""; })
|
7725 |
-
option("autofocus", null)
|
7726 |
-
option("direction", "ltr", function (cm, val) { return cm.doc.setDirection(val); }, true)
|
7727 |
-
}
|
7728 |
-
|
7729 |
-
function guttersChanged(cm) {
|
7730 |
-
updateGutters(cm)
|
7731 |
-
regChange(cm)
|
7732 |
-
alignHorizontally(cm)
|
7733 |
-
}
|
7734 |
-
|
7735 |
-
function dragDropChanged(cm, value, old) {
|
7736 |
-
var wasOn = old && old != Init
|
7737 |
-
if (!value != !wasOn) {
|
7738 |
-
var funcs = cm.display.dragFunctions
|
7739 |
-
var toggle = value ? on : off
|
7740 |
-
toggle(cm.display.scroller, "dragstart", funcs.start)
|
7741 |
-
toggle(cm.display.scroller, "dragenter", funcs.enter)
|
7742 |
-
toggle(cm.display.scroller, "dragover", funcs.over)
|
7743 |
-
toggle(cm.display.scroller, "dragleave", funcs.leave)
|
7744 |
-
toggle(cm.display.scroller, "drop", funcs.drop)
|
7745 |
-
}
|
7746 |
-
}
|
7747 |
-
|
7748 |
-
function wrappingChanged(cm) {
|
7749 |
-
if (cm.options.lineWrapping) {
|
7750 |
-
addClass(cm.display.wrapper, "CodeMirror-wrap")
|
7751 |
-
cm.display.sizer.style.minWidth = ""
|
7752 |
-
cm.display.sizerWidth = null
|
7753 |
-
} else {
|
7754 |
-
rmClass(cm.display.wrapper, "CodeMirror-wrap")
|
7755 |
-
findMaxLine(cm)
|
7756 |
-
}
|
7757 |
-
estimateLineHeights(cm)
|
7758 |
-
regChange(cm)
|
7759 |
-
clearCaches(cm)
|
7760 |
-
setTimeout(function () { return updateScrollbars(cm); }, 100)
|
7761 |
-
}
|
7762 |
-
|
7763 |
-
// A CodeMirror instance represents an editor. This is the object
|
7764 |
-
// that user code is usually dealing with.
|
7765 |
-
|
7766 |
-
function CodeMirror(place, options) {
|
7767 |
-
var this$1 = this;
|
7768 |
-
|
7769 |
-
if (!(this instanceof CodeMirror)) { return new CodeMirror(place, options) }
|
7770 |
-
|
7771 |
-
this.options = options = options ? copyObj(options) : {}
|
7772 |
-
// Determine effective options based on given values and defaults.
|
7773 |
-
copyObj(defaults, options, false)
|
7774 |
-
setGuttersForLineNumbers(options)
|
7775 |
-
|
7776 |
-
var doc = options.value
|
7777 |
-
if (typeof doc == "string") { doc = new Doc(doc, options.mode, null, options.lineSeparator, options.direction) }
|
7778 |
-
this.doc = doc
|
7779 |
-
|
7780 |
-
var input = new CodeMirror.inputStyles[options.inputStyle](this)
|
7781 |
-
var display = this.display = new Display(place, doc, input)
|
7782 |
-
display.wrapper.CodeMirror = this
|
7783 |
-
updateGutters(this)
|
7784 |
-
themeChanged(this)
|
7785 |
-
if (options.lineWrapping)
|
7786 |
-
{ this.display.wrapper.className += " CodeMirror-wrap" }
|
7787 |
-
initScrollbars(this)
|
7788 |
-
|
7789 |
-
this.state = {
|
7790 |
-
keyMaps: [], // stores maps added by addKeyMap
|
7791 |
-
overlays: [], // highlighting overlays, as added by addOverlay
|
7792 |
-
modeGen: 0, // bumped when mode/overlay changes, used to invalidate highlighting info
|
7793 |
-
overwrite: false,
|
7794 |
-
delayingBlurEvent: false,
|
7795 |
-
focused: false,
|
7796 |
-
suppressEdits: false, // used to disable editing during key handlers when in readOnly mode
|
7797 |
-
pasteIncoming: false, cutIncoming: false, // help recognize paste/cut edits in input.poll
|
7798 |
-
selectingText: false,
|
7799 |
-
draggingText: false,
|
7800 |
-
highlight: new Delayed(), // stores highlight worker timeout
|
7801 |
-
keySeq: null, // Unfinished key sequence
|
7802 |
-
specialChars: null
|
7803 |
-
}
|
7804 |
-
|
7805 |
-
if (options.autofocus && !mobile) { display.input.focus() }
|
7806 |
-
|
7807 |
-
// Override magic textarea content restore that IE sometimes does
|
7808 |
-
// on our hidden textarea on reload
|
7809 |
-
if (ie && ie_version < 11) { setTimeout(function () { return this$1.display.input.reset(true); }, 20) }
|
7810 |
-
|
7811 |
-
registerEventHandlers(this)
|
7812 |
-
ensureGlobalHandlers()
|
7813 |
-
|
7814 |
-
startOperation(this)
|
7815 |
-
this.curOp.forceUpdate = true
|
7816 |
-
attachDoc(this, doc)
|
7817 |
-
|
7818 |
-
if ((options.autofocus && !mobile) || this.hasFocus())
|
7819 |
-
{ setTimeout(bind(onFocus, this), 20) }
|
7820 |
-
else
|
7821 |
-
{ onBlur(this) }
|
7822 |
-
|
7823 |
-
for (var opt in optionHandlers) { if (optionHandlers.hasOwnProperty(opt))
|
7824 |
-
{ optionHandlers[opt](this$1, options[opt], Init) } }
|
7825 |
-
maybeUpdateLineNumberWidth(this)
|
7826 |
-
if (options.finishInit) { options.finishInit(this) }
|
7827 |
-
for (var i = 0; i < initHooks.length; ++i) { initHooks[i](this$1) }
|
7828 |
-
endOperation(this)
|
7829 |
-
// Suppress optimizelegibility in Webkit, since it breaks text
|
7830 |
-
// measuring on line wrapping boundaries.
|
7831 |
-
if (webkit && options.lineWrapping &&
|
7832 |
-
getComputedStyle(display.lineDiv).textRendering == "optimizelegibility")
|
7833 |
-
{ display.lineDiv.style.textRendering = "auto" }
|
7834 |
-
}
|
7835 |
-
|
7836 |
-
// The default configuration options.
|
7837 |
-
CodeMirror.defaults = defaults
|
7838 |
-
// Functions to run when options are changed.
|
7839 |
-
CodeMirror.optionHandlers = optionHandlers
|
7840 |
-
|
7841 |
-
// Attach the necessary event handlers when initializing the editor
|
7842 |
-
function registerEventHandlers(cm) {
|
7843 |
-
var d = cm.display
|
7844 |
-
on(d.scroller, "mousedown", operation(cm, onMouseDown))
|
7845 |
-
// Older IE's will not fire a second mousedown for a double click
|
7846 |
-
if (ie && ie_version < 11)
|
7847 |
-
{ on(d.scroller, "dblclick", operation(cm, function (e) {
|
7848 |
-
if (signalDOMEvent(cm, e)) { return }
|
7849 |
-
var pos = posFromMouse(cm, e)
|
7850 |
-
if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) { return }
|
7851 |
-
e_preventDefault(e)
|
7852 |
-
var word = cm.findWordAt(pos)
|
7853 |
-
extendSelection(cm.doc, word.anchor, word.head)
|
7854 |
-
})) }
|
7855 |
-
else
|
7856 |
-
{ on(d.scroller, "dblclick", function (e) { return signalDOMEvent(cm, e) || e_preventDefault(e); }) }
|
7857 |
-
// Some browsers fire contextmenu *after* opening the menu, at
|
7858 |
-
// which point we can't mess with it anymore. Context menu is
|
7859 |
-
// handled in onMouseDown for these browsers.
|
7860 |
-
if (!captureRightClick) { on(d.scroller, "contextmenu", function (e) { return onContextMenu(cm, e); }) }
|
7861 |
-
|
7862 |
-
// Used to suppress mouse event handling when a touch happens
|
7863 |
-
var touchFinished, prevTouch = {end: 0}
|
7864 |
-
function finishTouch() {
|
7865 |
-
if (d.activeTouch) {
|
7866 |
-
touchFinished = setTimeout(function () { return d.activeTouch = null; }, 1000)
|
7867 |
-
prevTouch = d.activeTouch
|
7868 |
-
prevTouch.end = +new Date
|
7869 |
-
}
|
7870 |
-
}
|
7871 |
-
function isMouseLikeTouchEvent(e) {
|
7872 |
-
if (e.touches.length != 1) { return false }
|
7873 |
-
var touch = e.touches[0]
|
7874 |
-
return touch.radiusX <= 1 && touch.radiusY <= 1
|
7875 |
-
}
|
7876 |
-
function farAway(touch, other) {
|
7877 |
-
if (other.left == null) { return true }
|
7878 |
-
var dx = other.left - touch.left, dy = other.top - touch.top
|
7879 |
-
return dx * dx + dy * dy > 20 * 20
|
7880 |
-
}
|
7881 |
-
on(d.scroller, "touchstart", function (e) {
|
7882 |
-
if (!signalDOMEvent(cm, e) && !isMouseLikeTouchEvent(e) && !clickInGutter(cm, e)) {
|
7883 |
-
d.input.ensurePolled()
|
7884 |
-
clearTimeout(touchFinished)
|
7885 |
-
var now = +new Date
|
7886 |
-
d.activeTouch = {start: now, moved: false,
|
7887 |
-
prev: now - prevTouch.end <= 300 ? prevTouch : null}
|
7888 |
-
if (e.touches.length == 1) {
|
7889 |
-
d.activeTouch.left = e.touches[0].pageX
|
7890 |
-
d.activeTouch.top = e.touches[0].pageY
|
7891 |
-
}
|
7892 |
-
}
|
7893 |
-
})
|
7894 |
-
on(d.scroller, "touchmove", function () {
|
7895 |
-
if (d.activeTouch) { d.activeTouch.moved = true }
|
7896 |
-
})
|
7897 |
-
on(d.scroller, "touchend", function (e) {
|
7898 |
-
var touch = d.activeTouch
|
7899 |
-
if (touch && !eventInWidget(d, e) && touch.left != null &&
|
7900 |
-
!touch.moved && new Date - touch.start < 300) {
|
7901 |
-
var pos = cm.coordsChar(d.activeTouch, "page"), range
|
7902 |
-
if (!touch.prev || farAway(touch, touch.prev)) // Single tap
|
7903 |
-
{ range = new Range(pos, pos) }
|
7904 |
-
else if (!touch.prev.prev || farAway(touch, touch.prev.prev)) // Double tap
|
7905 |
-
{ range = cm.findWordAt(pos) }
|
7906 |
-
else // Triple tap
|
7907 |
-
{ range = new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0))) }
|
7908 |
-
cm.setSelection(range.anchor, range.head)
|
7909 |
-
cm.focus()
|
7910 |
-
e_preventDefault(e)
|
7911 |
-
}
|
7912 |
-
finishTouch()
|
7913 |
-
})
|
7914 |
-
on(d.scroller, "touchcancel", finishTouch)
|
7915 |
-
|
7916 |
-
// Sync scrolling between fake scrollbars and real scrollable
|
7917 |
-
// area, ensure viewport is updated when scrolling.
|
7918 |
-
on(d.scroller, "scroll", function () {
|
7919 |
-
if (d.scroller.clientHeight) {
|
7920 |
-
updateScrollTop(cm, d.scroller.scrollTop)
|
7921 |
-
setScrollLeft(cm, d.scroller.scrollLeft, true)
|
7922 |
-
signal(cm, "scroll", cm)
|
7923 |
-
}
|
7924 |
-
})
|
7925 |
-
|
7926 |
-
// Listen to wheel events in order to try and update the viewport on time.
|
7927 |
-
on(d.scroller, "mousewheel", function (e) { return onScrollWheel(cm, e); })
|
7928 |
-
on(d.scroller, "DOMMouseScroll", function (e) { return onScrollWheel(cm, e); })
|
7929 |
-
|
7930 |
-
// Prevent wrapper from ever scrolling
|
7931 |
-
on(d.wrapper, "scroll", function () { return d.wrapper.scrollTop = d.wrapper.scrollLeft = 0; })
|
7932 |
-
|
7933 |
-
d.dragFunctions = {
|
7934 |
-
enter: function (e) {if (!signalDOMEvent(cm, e)) { e_stop(e) }},
|
7935 |
-
over: function (e) {if (!signalDOMEvent(cm, e)) { onDragOver(cm, e); e_stop(e) }},
|
7936 |
-
start: function (e) { return onDragStart(cm, e); },
|
7937 |
-
drop: operation(cm, onDrop),
|
7938 |
-
leave: function (e) {if (!signalDOMEvent(cm, e)) { clearDragCursor(cm) }}
|
7939 |
-
}
|
7940 |
-
|
7941 |
-
var inp = d.input.getField()
|
7942 |
-
on(inp, "keyup", function (e) { return onKeyUp.call(cm, e); })
|
7943 |
-
on(inp, "keydown", operation(cm, onKeyDown))
|
7944 |
-
on(inp, "keypress", operation(cm, onKeyPress))
|
7945 |
-
on(inp, "focus", function (e) { return onFocus(cm, e); })
|
7946 |
-
on(inp, "blur", function (e) { return onBlur(cm, e); })
|
7947 |
-
}
|
7948 |
-
|
7949 |
-
var initHooks = []
|
7950 |
-
CodeMirror.defineInitHook = function (f) { return initHooks.push(f); }
|
7951 |
-
|
7952 |
-
// Indent the given line. The how parameter can be "smart",
|
7953 |
-
// "add"/null, "subtract", or "prev". When aggressive is false
|
7954 |
-
// (typically set to true for forced single-line indents), empty
|
7955 |
-
// lines are not indented, and places where the mode returns Pass
|
7956 |
-
// are left alone.
|
7957 |
-
function indentLine(cm, n, how, aggressive) {
|
7958 |
-
var doc = cm.doc, state
|
7959 |
-
if (how == null) { how = "add" }
|
7960 |
-
if (how == "smart") {
|
7961 |
-
// Fall back to "prev" when the mode doesn't have an indentation
|
7962 |
-
// method.
|
7963 |
-
if (!doc.mode.indent) { how = "prev" }
|
7964 |
-
else { state = getContextBefore(cm, n).state }
|
7965 |
-
}
|
7966 |
-
|
7967 |
-
var tabSize = cm.options.tabSize
|
7968 |
-
var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize)
|
7969 |
-
if (line.stateAfter) { line.stateAfter = null }
|
7970 |
-
var curSpaceString = line.text.match(/^\s*/)[0], indentation
|
7971 |
-
if (!aggressive && !/\S/.test(line.text)) {
|
7972 |
-
indentation = 0
|
7973 |
-
how = "not"
|
7974 |
-
} else if (how == "smart") {
|
7975 |
-
indentation = doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text)
|
7976 |
-
if (indentation == Pass || indentation > 150) {
|
7977 |
-
if (!aggressive) { return }
|
7978 |
-
how = "prev"
|
7979 |
-
}
|
7980 |
-
}
|
7981 |
-
if (how == "prev") {
|
7982 |
-
if (n > doc.first) { indentation = countColumn(getLine(doc, n-1).text, null, tabSize) }
|
7983 |
-
else { indentation = 0 }
|
7984 |
-
} else if (how == "add") {
|
7985 |
-
indentation = curSpace + cm.options.indentUnit
|
7986 |
-
} else if (how == "subtract") {
|
7987 |
-
indentation = curSpace - cm.options.indentUnit
|
7988 |
-
} else if (typeof how == "number") {
|
7989 |
-
indentation = curSpace + how
|
7990 |
-
}
|
7991 |
-
indentation = Math.max(0, indentation)
|
7992 |
-
|
7993 |
-
var indentString = "", pos = 0
|
7994 |
-
if (cm.options.indentWithTabs)
|
7995 |
-
{ for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t"} }
|
7996 |
-
if (pos < indentation) { indentString += spaceStr(indentation - pos) }
|
7997 |
-
|
7998 |
-
if (indentString != curSpaceString) {
|
7999 |
-
replaceRange(doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input")
|
8000 |
-
line.stateAfter = null
|
8001 |
-
return true
|
8002 |
-
} else {
|
8003 |
-
// Ensure that, if the cursor was in the whitespace at the start
|
8004 |
-
// of the line, it is moved to the end of that space.
|
8005 |
-
for (var i$1 = 0; i$1 < doc.sel.ranges.length; i$1++) {
|
8006 |
-
var range = doc.sel.ranges[i$1]
|
8007 |
-
if (range.head.line == n && range.head.ch < curSpaceString.length) {
|
8008 |
-
var pos$1 = Pos(n, curSpaceString.length)
|
8009 |
-
replaceOneSelection(doc, i$1, new Range(pos$1, pos$1))
|
8010 |
-
break
|
8011 |
-
}
|
8012 |
-
}
|
8013 |
-
}
|
8014 |
-
}
|
8015 |
-
|
8016 |
-
// This will be set to a {lineWise: bool, text: [string]} object, so
|
8017 |
-
// that, when pasting, we know what kind of selections the copied
|
8018 |
-
// text was made out of.
|
8019 |
-
var lastCopied = null
|
8020 |
-
|
8021 |
-
function setLastCopied(newLastCopied) {
|
8022 |
-
lastCopied = newLastCopied
|
8023 |
-
}
|
8024 |
-
|
8025 |
-
function applyTextInput(cm, inserted, deleted, sel, origin) {
|
8026 |
-
var doc = cm.doc
|
8027 |
-
cm.display.shift = false
|
8028 |
-
if (!sel) { sel = doc.sel }
|
8029 |
-
|
8030 |
-
var paste = cm.state.pasteIncoming || origin == "paste"
|
8031 |
-
var textLines = splitLinesAuto(inserted), multiPaste = null
|
8032 |
-
// When pasting N lines into N selections, insert one line per selection
|
8033 |
-
if (paste && sel.ranges.length > 1) {
|
8034 |
-
if (lastCopied && lastCopied.text.join("\n") == inserted) {
|
8035 |
-
if (sel.ranges.length % lastCopied.text.length == 0) {
|
8036 |
-
multiPaste = []
|
8037 |
-
for (var i = 0; i < lastCopied.text.length; i++)
|
8038 |
-
{ multiPaste.push(doc.splitLines(lastCopied.text[i])) }
|
8039 |
-
}
|
8040 |
-
} else if (textLines.length == sel.ranges.length && cm.options.pasteLinesPerSelection) {
|
8041 |
-
multiPaste = map(textLines, function (l) { return [l]; })
|
8042 |
-
}
|
8043 |
-
}
|
8044 |
-
|
8045 |
-
var updateInput
|
8046 |
-
// Normal behavior is to insert the new text into every selection
|
8047 |
-
for (var i$1 = sel.ranges.length - 1; i$1 >= 0; i$1--) {
|
8048 |
-
var range = sel.ranges[i$1]
|
8049 |
-
var from = range.from(), to = range.to()
|
8050 |
-
if (range.empty()) {
|
8051 |
-
if (deleted && deleted > 0) // Handle deletion
|
8052 |
-
{ from = Pos(from.line, from.ch - deleted) }
|
8053 |
-
else if (cm.state.overwrite && !paste) // Handle overwrite
|
8054 |
-
{ to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length)) }
|
8055 |
-
else if (lastCopied && lastCopied.lineWise && lastCopied.text.join("\n") == inserted)
|
8056 |
-
{ from = to = Pos(from.line, 0) }
|
8057 |
-
}
|
8058 |
-
updateInput = cm.curOp.updateInput
|
8059 |
-
var changeEvent = {from: from, to: to, text: multiPaste ? multiPaste[i$1 % multiPaste.length] : textLines,
|
8060 |
-
origin: origin || (paste ? "paste" : cm.state.cutIncoming ? "cut" : "+input")}
|
8061 |
-
makeChange(cm.doc, changeEvent)
|
8062 |
-
signalLater(cm, "inputRead", cm, changeEvent)
|
8063 |
-
}
|
8064 |
-
if (inserted && !paste)
|
8065 |
-
{ triggerElectric(cm, inserted) }
|
8066 |
-
|
8067 |
-
ensureCursorVisible(cm)
|
8068 |
-
cm.curOp.updateInput = updateInput
|
8069 |
-
cm.curOp.typing = true
|
8070 |
-
cm.state.pasteIncoming = cm.state.cutIncoming = false
|
8071 |
-
}
|
8072 |
-
|
8073 |
-
function handlePaste(e, cm) {
|
8074 |
-
var pasted = e.clipboardData && e.clipboardData.getData("Text")
|
8075 |
-
if (pasted) {
|
8076 |
-
e.preventDefault()
|
8077 |
-
if (!cm.isReadOnly() && !cm.options.disableInput)
|
8078 |
-
{ runInOp(cm, function () { return applyTextInput(cm, pasted, 0, null, "paste"); }) }
|
8079 |
-
return true
|
8080 |
-
}
|
8081 |
-
}
|
8082 |
-
|
8083 |
-
function triggerElectric(cm, inserted) {
|
8084 |
-
// When an 'electric' character is inserted, immediately trigger a reindent
|
8085 |
-
if (!cm.options.electricChars || !cm.options.smartIndent) { return }
|
8086 |
-
var sel = cm.doc.sel
|
8087 |
-
|
8088 |
-
for (var i = sel.ranges.length - 1; i >= 0; i--) {
|
8089 |
-
var range = sel.ranges[i]
|
8090 |
-
if (range.head.ch > 100 || (i && sel.ranges[i - 1].head.line == range.head.line)) { continue }
|
8091 |
-
var mode = cm.getModeAt(range.head)
|
8092 |
-
var indented = false
|
8093 |
-
if (mode.electricChars) {
|
8094 |
-
for (var j = 0; j < mode.electricChars.length; j++)
|
8095 |
-
{ if (inserted.indexOf(mode.electricChars.charAt(j)) > -1) {
|
8096 |
-
indented = indentLine(cm, range.head.line, "smart")
|
8097 |
-
break
|
8098 |
-
} }
|
8099 |
-
} else if (mode.electricInput) {
|
8100 |
-
if (mode.electricInput.test(getLine(cm.doc, range.head.line).text.slice(0, range.head.ch)))
|
8101 |
-
{ indented = indentLine(cm, range.head.line, "smart") }
|
8102 |
-
}
|
8103 |
-
if (indented) { signalLater(cm, "electricInput", cm, range.head.line) }
|
8104 |
-
}
|
8105 |
-
}
|
8106 |
-
|
8107 |
-
function copyableRanges(cm) {
|
8108 |
-
var text = [], ranges = []
|
8109 |
-
for (var i = 0; i < cm.doc.sel.ranges.length; i++) {
|
8110 |
-
var line = cm.doc.sel.ranges[i].head.line
|
8111 |
-
var lineRange = {anchor: Pos(line, 0), head: Pos(line + 1, 0)}
|
8112 |
-
ranges.push(lineRange)
|
8113 |
-
text.push(cm.getRange(lineRange.anchor, lineRange.head))
|
8114 |
-
}
|
8115 |
-
return {text: text, ranges: ranges}
|
8116 |
-
}
|
8117 |
-
|
8118 |
-
function disableBrowserMagic(field, spellcheck) {
|
8119 |
-
field.setAttribute("autocorrect", "off")
|
8120 |
-
field.setAttribute("autocapitalize", "off")
|
8121 |
-
field.setAttribute("spellcheck", !!spellcheck)
|
8122 |
-
}
|
8123 |
-
|
8124 |
-
function hiddenTextarea() {
|
8125 |
-
var te = elt("textarea", null, null, "position: absolute; bottom: -1em; padding: 0; width: 1px; height: 1em; outline: none")
|
8126 |
-
var div = elt("div", [te], null, "overflow: hidden; position: relative; width: 3px; height: 0px;")
|
8127 |
-
// The textarea is kept positioned near the cursor to prevent the
|
8128 |
-
// fact that it'll be scrolled into view on input from scrolling
|
8129 |
-
// our fake cursor out of view. On webkit, when wrap=off, paste is
|
8130 |
-
// very slow. So make the area wide instead.
|
8131 |
-
if (webkit) { te.style.width = "1000px" }
|
8132 |
-
else { te.setAttribute("wrap", "off") }
|
8133 |
-
// If border: 0; -- iOS fails to open keyboard (issue #1287)
|
8134 |
-
if (ios) { te.style.border = "1px solid black" }
|
8135 |
-
disableBrowserMagic(te)
|
8136 |
-
return div
|
8137 |
-
}
|
8138 |
-
|
8139 |
-
// The publicly visible API. Note that methodOp(f) means
|
8140 |
-
// 'wrap f in an operation, performed on its `this` parameter'.
|
8141 |
-
|
8142 |
-
// This is not the complete set of editor methods. Most of the
|
8143 |
-
// methods defined on the Doc type are also injected into
|
8144 |
-
// CodeMirror.prototype, for backwards compatibility and
|
8145 |
-
// convenience.
|
8146 |
-
|
8147 |
-
function addEditorMethods(CodeMirror) {
|
8148 |
-
var optionHandlers = CodeMirror.optionHandlers
|
8149 |
-
|
8150 |
-
var helpers = CodeMirror.helpers = {}
|
8151 |
-
|
8152 |
-
CodeMirror.prototype = {
|
8153 |
-
constructor: CodeMirror,
|
8154 |
-
focus: function(){window.focus(); this.display.input.focus()},
|
8155 |
-
|
8156 |
-
setOption: function(option, value) {
|
8157 |
-
var options = this.options, old = options[option]
|
8158 |
-
if (options[option] == value && option != "mode") { return }
|
8159 |
-
options[option] = value
|
8160 |
-
if (optionHandlers.hasOwnProperty(option))
|
8161 |
-
{ operation(this, optionHandlers[option])(this, value, old) }
|
8162 |
-
signal(this, "optionChange", this, option)
|
8163 |
-
},
|
8164 |
-
|
8165 |
-
getOption: function(option) {return this.options[option]},
|
8166 |
-
getDoc: function() {return this.doc},
|
8167 |
-
|
8168 |
-
addKeyMap: function(map, bottom) {
|
8169 |
-
this.state.keyMaps[bottom ? "push" : "unshift"](getKeyMap(map))
|
8170 |
-
},
|
8171 |
-
removeKeyMap: function(map) {
|
8172 |
-
var maps = this.state.keyMaps
|
8173 |
-
for (var i = 0; i < maps.length; ++i)
|
8174 |
-
{ if (maps[i] == map || maps[i].name == map) {
|
8175 |
-
maps.splice(i, 1)
|
8176 |
-
return true
|
8177 |
-
} }
|
8178 |
-
},
|
8179 |
-
|
8180 |
-
addOverlay: methodOp(function(spec, options) {
|
8181 |
-
var mode = spec.token ? spec : CodeMirror.getMode(this.options, spec)
|
8182 |
-
if (mode.startState) { throw new Error("Overlays may not be stateful.") }
|
8183 |
-
insertSorted(this.state.overlays,
|
8184 |
-
{mode: mode, modeSpec: spec, opaque: options && options.opaque,
|
8185 |
-
priority: (options && options.priority) || 0},
|
8186 |
-
function (overlay) { return overlay.priority; })
|
8187 |
-
this.state.modeGen++
|
8188 |
-
regChange(this)
|
8189 |
-
}),
|
8190 |
-
removeOverlay: methodOp(function(spec) {
|
8191 |
-
var this$1 = this;
|
8192 |
-
|
8193 |
-
var overlays = this.state.overlays
|
8194 |
-
for (var i = 0; i < overlays.length; ++i) {
|
8195 |
-
var cur = overlays[i].modeSpec
|
8196 |
-
if (cur == spec || typeof spec == "string" && cur.name == spec) {
|
8197 |
-
overlays.splice(i, 1)
|
8198 |
-
this$1.state.modeGen++
|
8199 |
-
regChange(this$1)
|
8200 |
-
return
|
8201 |
-
}
|
8202 |
-
}
|
8203 |
-
}),
|
8204 |
-
|
8205 |
-
indentLine: methodOp(function(n, dir, aggressive) {
|
8206 |
-
if (typeof dir != "string" && typeof dir != "number") {
|
8207 |
-
if (dir == null) { dir = this.options.smartIndent ? "smart" : "prev" }
|
8208 |
-
else { dir = dir ? "add" : "subtract" }
|
8209 |
-
}
|
8210 |
-
if (isLine(this.doc, n)) { indentLine(this, n, dir, aggressive) }
|
8211 |
-
}),
|
8212 |
-
indentSelection: methodOp(function(how) {
|
8213 |
-
var this$1 = this;
|
8214 |
-
|
8215 |
-
var ranges = this.doc.sel.ranges, end = -1
|
8216 |
-
for (var i = 0; i < ranges.length; i++) {
|
8217 |
-
var range = ranges[i]
|
8218 |
-
if (!range.empty()) {
|
8219 |
-
var from = range.from(), to = range.to()
|
8220 |
-
var start = Math.max(end, from.line)
|
8221 |
-
end = Math.min(this$1.lastLine(), to.line - (to.ch ? 0 : 1)) + 1
|
8222 |
-
for (var j = start; j < end; ++j)
|
8223 |
-
{ indentLine(this$1, j, how) }
|
8224 |
-
var newRanges = this$1.doc.sel.ranges
|
8225 |
-
if (from.ch == 0 && ranges.length == newRanges.length && newRanges[i].from().ch > 0)
|
8226 |
-
{ replaceOneSelection(this$1.doc, i, new Range(from, newRanges[i].to()), sel_dontScroll) }
|
8227 |
-
} else if (range.head.line > end) {
|
8228 |
-
indentLine(this$1, range.head.line, how, true)
|
8229 |
-
end = range.head.line
|
8230 |
-
if (i == this$1.doc.sel.primIndex) { ensureCursorVisible(this$1) }
|
8231 |
-
}
|
8232 |
-
}
|
8233 |
-
}),
|
8234 |
-
|
8235 |
-
// Fetch the parser token for a given character. Useful for hacks
|
8236 |
-
// that want to inspect the mode state (say, for completion).
|
8237 |
-
getTokenAt: function(pos, precise) {
|
8238 |
-
return takeToken(this, pos, precise)
|
8239 |
-
},
|
8240 |
-
|
8241 |
-
getLineTokens: function(line, precise) {
|
8242 |
-
return takeToken(this, Pos(line), precise, true)
|
8243 |
-
},
|
8244 |
-
|
8245 |
-
getTokenTypeAt: function(pos) {
|
8246 |
-
pos = clipPos(this.doc, pos)
|
8247 |
-
var styles = getLineStyles(this, getLine(this.doc, pos.line))
|
8248 |
-
var before = 0, after = (styles.length - 1) / 2, ch = pos.ch
|
8249 |
-
var type
|
8250 |
-
if (ch == 0) { type = styles[2] }
|
8251 |
-
else { for (;;) {
|
8252 |
-
var mid = (before + after) >> 1
|
8253 |
-
if ((mid ? styles[mid * 2 - 1] : 0) >= ch) { after = mid }
|
8254 |
-
else if (styles[mid * 2 + 1] < ch) { before = mid + 1 }
|
8255 |
-
else { type = styles[mid * 2 + 2]; break }
|
8256 |
-
} }
|
8257 |
-
var cut = type ? type.indexOf("overlay ") : -1
|
8258 |
-
return cut < 0 ? type : cut == 0 ? null : type.slice(0, cut - 1)
|
8259 |
-
},
|
8260 |
-
|
8261 |
-
getModeAt: function(pos) {
|
8262 |
-
var mode = this.doc.mode
|
8263 |
-
if (!mode.innerMode) { return mode }
|
8264 |
-
return CodeMirror.innerMode(mode, this.getTokenAt(pos).state).mode
|
8265 |
-
},
|
8266 |
-
|
8267 |
-
getHelper: function(pos, type) {
|
8268 |
-
return this.getHelpers(pos, type)[0]
|
8269 |
-
},
|
8270 |
-
|
8271 |
-
getHelpers: function(pos, type) {
|
8272 |
-
var this$1 = this;
|
8273 |
-
|
8274 |
-
var found = []
|
8275 |
-
if (!helpers.hasOwnProperty(type)) { return found }
|
8276 |
-
var help = helpers[type], mode = this.getModeAt(pos)
|
8277 |
-
if (typeof mode[type] == "string") {
|
8278 |
-
if (help[mode[type]]) { found.push(help[mode[type]]) }
|
8279 |
-
} else if (mode[type]) {
|
8280 |
-
for (var i = 0; i < mode[type].length; i++) {
|
8281 |
-
var val = help[mode[type][i]]
|
8282 |
-
if (val) { found.push(val) }
|
8283 |
-
}
|
8284 |
-
} else if (mode.helperType && help[mode.helperType]) {
|
8285 |
-
found.push(help[mode.helperType])
|
8286 |
-
} else if (help[mode.name]) {
|
8287 |
-
found.push(help[mode.name])
|
8288 |
-
}
|
8289 |
-
for (var i$1 = 0; i$1 < help._global.length; i$1++) {
|
8290 |
-
var cur = help._global[i$1]
|
8291 |
-
if (cur.pred(mode, this$1) && indexOf(found, cur.val) == -1)
|
8292 |
-
{ found.push(cur.val) }
|
8293 |
-
}
|
8294 |
-
return found
|
8295 |
-
},
|
8296 |
-
|
8297 |
-
getStateAfter: function(line, precise) {
|
8298 |
-
var doc = this.doc
|
8299 |
-
line = clipLine(doc, line == null ? doc.first + doc.size - 1: line)
|
8300 |
-
return getContextBefore(this, line + 1, precise).state
|
8301 |
-
},
|
8302 |
-
|
8303 |
-
cursorCoords: function(start, mode) {
|
8304 |
-
var pos, range = this.doc.sel.primary()
|
8305 |
-
if (start == null) { pos = range.head }
|
8306 |
-
else if (typeof start == "object") { pos = clipPos(this.doc, start) }
|
8307 |
-
else { pos = start ? range.from() : range.to() }
|
8308 |
-
return cursorCoords(this, pos, mode || "page")
|
8309 |
-
},
|
8310 |
-
|
8311 |
-
charCoords: function(pos, mode) {
|
8312 |
-
return charCoords(this, clipPos(this.doc, pos), mode || "page")
|
8313 |
-
},
|
8314 |
-
|
8315 |
-
coordsChar: function(coords, mode) {
|
8316 |
-
coords = fromCoordSystem(this, coords, mode || "page")
|
8317 |
-
return coordsChar(this, coords.left, coords.top)
|
8318 |
-
},
|
8319 |
-
|
8320 |
-
lineAtHeight: function(height, mode) {
|
8321 |
-
height = fromCoordSystem(this, {top: height, left: 0}, mode || "page").top
|
8322 |
-
return lineAtHeight(this.doc, height + this.display.viewOffset)
|
8323 |
-
},
|
8324 |
-
heightAtLine: function(line, mode, includeWidgets) {
|
8325 |
-
var end = false, lineObj
|
8326 |
-
if (typeof line == "number") {
|
8327 |
-
var last = this.doc.first + this.doc.size - 1
|
8328 |
-
if (line < this.doc.first) { line = this.doc.first }
|
8329 |
-
else if (line > last) { line = last; end = true }
|
8330 |
-
lineObj = getLine(this.doc, line)
|
8331 |
-
} else {
|
8332 |
-
lineObj = line
|
8333 |
-
}
|
8334 |
-
return intoCoordSystem(this, lineObj, {top: 0, left: 0}, mode || "page", includeWidgets || end).top +
|
8335 |
-
(end ? this.doc.height - heightAtLine(lineObj) : 0)
|
8336 |
-
},
|
8337 |
-
|
8338 |
-
defaultTextHeight: function() { return textHeight(this.display) },
|
8339 |
-
defaultCharWidth: function() { return charWidth(this.display) },
|
8340 |
-
|
8341 |
-
getViewport: function() { return {from: this.display.viewFrom, to: this.display.viewTo}},
|
8342 |
-
|
8343 |
-
addWidget: function(pos, node, scroll, vert, horiz) {
|
8344 |
-
var display = this.display
|
8345 |
-
pos = cursorCoords(this, clipPos(this.doc, pos))
|
8346 |
-
var top = pos.bottom, left = pos.left
|
8347 |
-
node.style.position = "absolute"
|
8348 |
-
node.setAttribute("cm-ignore-events", "true")
|
8349 |
-
this.display.input.setUneditable(node)
|
8350 |
-
display.sizer.appendChild(node)
|
8351 |
-
if (vert == "over") {
|
8352 |
-
top = pos.top
|
8353 |
-
} else if (vert == "above" || vert == "near") {
|
8354 |
-
var vspace = Math.max(display.wrapper.clientHeight, this.doc.height),
|
8355 |
-
hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth)
|
8356 |
-
// Default to positioning above (if specified and possible); otherwise default to positioning below
|
8357 |
-
if ((vert == 'above' || pos.bottom + node.offsetHeight > vspace) && pos.top > node.offsetHeight)
|
8358 |
-
{ top = pos.top - node.offsetHeight }
|
8359 |
-
else if (pos.bottom + node.offsetHeight <= vspace)
|
8360 |
-
{ top = pos.bottom }
|
8361 |
-
if (left + node.offsetWidth > hspace)
|
8362 |
-
{ left = hspace - node.offsetWidth }
|
8363 |
-
}
|
8364 |
-
node.style.top = top + "px"
|
8365 |
-
node.style.left = node.style.right = ""
|
8366 |
-
if (horiz == "right") {
|
8367 |
-
left = display.sizer.clientWidth - node.offsetWidth
|
8368 |
-
node.style.right = "0px"
|
8369 |
-
} else {
|
8370 |
-
if (horiz == "left") { left = 0 }
|
8371 |
-
else if (horiz == "middle") { left = (display.sizer.clientWidth - node.offsetWidth) / 2 }
|
8372 |
-
node.style.left = left + "px"
|
8373 |
-
}
|
8374 |
-
if (scroll)
|
8375 |
-
{ scrollIntoView(this, {left: left, top: top, right: left + node.offsetWidth, bottom: top + node.offsetHeight}) }
|
8376 |
-
},
|
8377 |
-
|
8378 |
-
triggerOnKeyDown: methodOp(onKeyDown),
|
8379 |
-
triggerOnKeyPress: methodOp(onKeyPress),
|
8380 |
-
triggerOnKeyUp: onKeyUp,
|
8381 |
-
triggerOnMouseDown: methodOp(onMouseDown),
|
8382 |
-
|
8383 |
-
execCommand: function(cmd) {
|
8384 |
-
if (commands.hasOwnProperty(cmd))
|
8385 |
-
{ return commands[cmd].call(null, this) }
|
8386 |
-
},
|
8387 |
-
|
8388 |
-
triggerElectric: methodOp(function(text) { triggerElectric(this, text) }),
|
8389 |
-
|
8390 |
-
findPosH: function(from, amount, unit, visually) {
|
8391 |
-
var this$1 = this;
|
8392 |
-
|
8393 |
-
var dir = 1
|
8394 |
-
if (amount < 0) { dir = -1; amount = -amount }
|
8395 |
-
var cur = clipPos(this.doc, from)
|
8396 |
-
for (var i = 0; i < amount; ++i) {
|
8397 |
-
cur = findPosH(this$1.doc, cur, dir, unit, visually)
|
8398 |
-
if (cur.hitSide) { break }
|
8399 |
-
}
|
8400 |
-
return cur
|
8401 |
-
},
|
8402 |
-
|
8403 |
-
moveH: methodOp(function(dir, unit) {
|
8404 |
-
var this$1 = this;
|
8405 |
-
|
8406 |
-
this.extendSelectionsBy(function (range) {
|
8407 |
-
if (this$1.display.shift || this$1.doc.extend || range.empty())
|
8408 |
-
{ return findPosH(this$1.doc, range.head, dir, unit, this$1.options.rtlMoveVisually) }
|
8409 |
-
else
|
8410 |
-
{ return dir < 0 ? range.from() : range.to() }
|
8411 |
-
}, sel_move)
|
8412 |
-
}),
|
8413 |
-
|
8414 |
-
deleteH: methodOp(function(dir, unit) {
|
8415 |
-
var sel = this.doc.sel, doc = this.doc
|
8416 |
-
if (sel.somethingSelected())
|
8417 |
-
{ doc.replaceSelection("", null, "+delete") }
|
8418 |
-
else
|
8419 |
-
{ deleteNearSelection(this, function (range) {
|
8420 |
-
var other = findPosH(doc, range.head, dir, unit, false)
|
8421 |
-
return dir < 0 ? {from: other, to: range.head} : {from: range.head, to: other}
|
8422 |
-
}) }
|
8423 |
-
}),
|
8424 |
-
|
8425 |
-
findPosV: function(from, amount, unit, goalColumn) {
|
8426 |
-
var this$1 = this;
|
8427 |
-
|
8428 |
-
var dir = 1, x = goalColumn
|
8429 |
-
if (amount < 0) { dir = -1; amount = -amount }
|
8430 |
-
var cur = clipPos(this.doc, from)
|
8431 |
-
for (var i = 0; i < amount; ++i) {
|
8432 |
-
var coords = cursorCoords(this$1, cur, "div")
|
8433 |
-
if (x == null) { x = coords.left }
|
8434 |
-
else { coords.left = x }
|
8435 |
-
cur = findPosV(this$1, coords, dir, unit)
|
8436 |
-
if (cur.hitSide) { break }
|
8437 |
-
}
|
8438 |
-
return cur
|
8439 |
-
},
|
8440 |
-
|
8441 |
-
moveV: methodOp(function(dir, unit) {
|
8442 |
-
var this$1 = this;
|
8443 |
-
|
8444 |
-
var doc = this.doc, goals = []
|
8445 |
-
var collapse = !this.display.shift && !doc.extend && doc.sel.somethingSelected()
|
8446 |
-
doc.extendSelectionsBy(function (range) {
|
8447 |
-
if (collapse)
|
8448 |
-
{ return dir < 0 ? range.from() : range.to() }
|
8449 |
-
var headPos = cursorCoords(this$1, range.head, "div")
|
8450 |
-
if (range.goalColumn != null) { headPos.left = range.goalColumn }
|
8451 |
-
goals.push(headPos.left)
|
8452 |
-
var pos = findPosV(this$1, headPos, dir, unit)
|
8453 |
-
if (unit == "page" && range == doc.sel.primary())
|
8454 |
-
{ addToScrollTop(this$1, charCoords(this$1, pos, "div").top - headPos.top) }
|
8455 |
-
return pos
|
8456 |
-
}, sel_move)
|
8457 |
-
if (goals.length) { for (var i = 0; i < doc.sel.ranges.length; i++)
|
8458 |
-
{ doc.sel.ranges[i].goalColumn = goals[i] } }
|
8459 |
-
}),
|
8460 |
-
|
8461 |
-
// Find the word at the given position (as returned by coordsChar).
|
8462 |
-
findWordAt: function(pos) {
|
8463 |
-
var doc = this.doc, line = getLine(doc, pos.line).text
|
8464 |
-
var start = pos.ch, end = pos.ch
|
8465 |
-
if (line) {
|
8466 |
-
var helper = this.getHelper(pos, "wordChars")
|
8467 |
-
if ((pos.sticky == "before" || end == line.length) && start) { --start; } else { ++end }
|
8468 |
-
var startChar = line.charAt(start)
|
8469 |
-
var check = isWordChar(startChar, helper)
|
8470 |
-
? function (ch) { return isWordChar(ch, helper); }
|
8471 |
-
: /\s/.test(startChar) ? function (ch) { return /\s/.test(ch); }
|
8472 |
-
: function (ch) { return (!/\s/.test(ch) && !isWordChar(ch)); }
|
8473 |
-
while (start > 0 && check(line.charAt(start - 1))) { --start }
|
8474 |
-
while (end < line.length && check(line.charAt(end))) { ++end }
|
8475 |
-
}
|
8476 |
-
return new Range(Pos(pos.line, start), Pos(pos.line, end))
|
8477 |
-
},
|
8478 |
-
|
8479 |
-
toggleOverwrite: function(value) {
|
8480 |
-
if (value != null && value == this.state.overwrite) { return }
|
8481 |
-
if (this.state.overwrite = !this.state.overwrite)
|
8482 |
-
{ addClass(this.display.cursorDiv, "CodeMirror-overwrite") }
|
8483 |
-
else
|
8484 |
-
{ rmClass(this.display.cursorDiv, "CodeMirror-overwrite") }
|
8485 |
-
|
8486 |
-
signal(this, "overwriteToggle", this, this.state.overwrite)
|
8487 |
-
},
|
8488 |
-
hasFocus: function() { return this.display.input.getField() == activeElt() },
|
8489 |
-
isReadOnly: function() { return !!(this.options.readOnly || this.doc.cantEdit) },
|
8490 |
-
|
8491 |
-
scrollTo: methodOp(function (x, y) { scrollToCoords(this, x, y) }),
|
8492 |
-
getScrollInfo: function() {
|
8493 |
-
var scroller = this.display.scroller
|
8494 |
-
return {left: scroller.scrollLeft, top: scroller.scrollTop,
|
8495 |
-
height: scroller.scrollHeight - scrollGap(this) - this.display.barHeight,
|
8496 |
-
width: scroller.scrollWidth - scrollGap(this) - this.display.barWidth,
|
8497 |
-
clientHeight: displayHeight(this), clientWidth: displayWidth(this)}
|
8498 |
-
},
|
8499 |
-
|
8500 |
-
scrollIntoView: methodOp(function(range, margin) {
|
8501 |
-
if (range == null) {
|
8502 |
-
range = {from: this.doc.sel.primary().head, to: null}
|
8503 |
-
if (margin == null) { margin = this.options.cursorScrollMargin }
|
8504 |
-
} else if (typeof range == "number") {
|
8505 |
-
range = {from: Pos(range, 0), to: null}
|
8506 |
-
} else if (range.from == null) {
|
8507 |
-
range = {from: range, to: null}
|
8508 |
-
}
|
8509 |
-
if (!range.to) { range.to = range.from }
|
8510 |
-
range.margin = margin || 0
|
8511 |
-
|
8512 |
-
if (range.from.line != null) {
|
8513 |
-
scrollToRange(this, range)
|
8514 |
-
} else {
|
8515 |
-
scrollToCoordsRange(this, range.from, range.to, range.margin)
|
8516 |
-
}
|
8517 |
-
}),
|
8518 |
-
|
8519 |
-
setSize: methodOp(function(width, height) {
|
8520 |
-
var this$1 = this;
|
8521 |
-
|
8522 |
-
var interpret = function (val) { return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val; }
|
8523 |
-
if (width != null) { this.display.wrapper.style.width = interpret(width) }
|
8524 |
-
if (height != null) { this.display.wrapper.style.height = interpret(height) }
|
8525 |
-
if (this.options.lineWrapping) { clearLineMeasurementCache(this) }
|
8526 |
-
var lineNo = this.display.viewFrom
|
8527 |
-
this.doc.iter(lineNo, this.display.viewTo, function (line) {
|
8528 |
-
if (line.widgets) { for (var i = 0; i < line.widgets.length; i++)
|
8529 |
-
{ if (line.widgets[i].noHScroll) { regLineChange(this$1, lineNo, "widget"); break } } }
|
8530 |
-
++lineNo
|
8531 |
-
})
|
8532 |
-
this.curOp.forceUpdate = true
|
8533 |
-
signal(this, "refresh", this)
|
8534 |
-
}),
|
8535 |
-
|
8536 |
-
operation: function(f){return runInOp(this, f)},
|
8537 |
-
startOperation: function(){return startOperation(this)},
|
8538 |
-
endOperation: function(){return endOperation(this)},
|
8539 |
-
|
8540 |
-
refresh: methodOp(function() {
|
8541 |
-
var oldHeight = this.display.cachedTextHeight
|
8542 |
-
regChange(this)
|
8543 |
-
this.curOp.forceUpdate = true
|
8544 |
-
clearCaches(this)
|
8545 |
-
scrollToCoords(this, this.doc.scrollLeft, this.doc.scrollTop)
|
8546 |
-
updateGutterSpace(this)
|
8547 |
-
if (oldHeight == null || Math.abs(oldHeight - textHeight(this.display)) > .5)
|
8548 |
-
{ estimateLineHeights(this) }
|
8549 |
-
signal(this, "refresh", this)
|
8550 |
-
}),
|
8551 |
-
|
8552 |
-
swapDoc: methodOp(function(doc) {
|
8553 |
-
var old = this.doc
|
8554 |
-
old.cm = null
|
8555 |
-
attachDoc(this, doc)
|
8556 |
-
clearCaches(this)
|
8557 |
-
this.display.input.reset()
|
8558 |
-
scrollToCoords(this, doc.scrollLeft, doc.scrollTop)
|
8559 |
-
this.curOp.forceScroll = true
|
8560 |
-
signalLater(this, "swapDoc", this, old)
|
8561 |
-
return old
|
8562 |
-
}),
|
8563 |
-
|
8564 |
-
getInputField: function(){return this.display.input.getField()},
|
8565 |
-
getWrapperElement: function(){return this.display.wrapper},
|
8566 |
-
getScrollerElement: function(){return this.display.scroller},
|
8567 |
-
getGutterElement: function(){return this.display.gutters}
|
8568 |
-
}
|
8569 |
-
eventMixin(CodeMirror)
|
8570 |
-
|
8571 |
-
CodeMirror.registerHelper = function(type, name, value) {
|
8572 |
-
if (!helpers.hasOwnProperty(type)) { helpers[type] = CodeMirror[type] = {_global: []} }
|
8573 |
-
helpers[type][name] = value
|
8574 |
-
}
|
8575 |
-
CodeMirror.registerGlobalHelper = function(type, name, predicate, value) {
|
8576 |
-
CodeMirror.registerHelper(type, name, value)
|
8577 |
-
helpers[type]._global.push({pred: predicate, val: value})
|
8578 |
-
}
|
8579 |
-
}
|
8580 |
-
|
8581 |
-
// Used for horizontal relative motion. Dir is -1 or 1 (left or
|
8582 |
-
// right), unit can be "char", "column" (like char, but doesn't
|
8583 |
-
// cross line boundaries), "word" (across next word), or "group" (to
|
8584 |
-
// the start of next group of word or non-word-non-whitespace
|
8585 |
-
// chars). The visually param controls whether, in right-to-left
|
8586 |
-
// text, direction 1 means to move towards the next index in the
|
8587 |
-
// string, or towards the character to the right of the current
|
8588 |
-
// position. The resulting position will have a hitSide=true
|
8589 |
-
// property if it reached the end of the document.
|
8590 |
-
function findPosH(doc, pos, dir, unit, visually) {
|
8591 |
-
var oldPos = pos
|
8592 |
-
var origDir = dir
|
8593 |
-
var lineObj = getLine(doc, pos.line)
|
8594 |
-
function findNextLine() {
|
8595 |
-
var l = pos.line + dir
|
8596 |
-
if (l < doc.first || l >= doc.first + doc.size) { return false }
|
8597 |
-
pos = new Pos(l, pos.ch, pos.sticky)
|
8598 |
-
return lineObj = getLine(doc, l)
|
8599 |
-
}
|
8600 |
-
function moveOnce(boundToLine) {
|
8601 |
-
var next
|
8602 |
-
if (visually) {
|
8603 |
-
next = moveVisually(doc.cm, lineObj, pos, dir)
|
8604 |
-
} else {
|
8605 |
-
next = moveLogically(lineObj, pos, dir)
|
8606 |
-
}
|
8607 |
-
if (next == null) {
|
8608 |
-
if (!boundToLine && findNextLine())
|
8609 |
-
{ pos = endOfLine(visually, doc.cm, lineObj, pos.line, dir) }
|
8610 |
-
else
|
8611 |
-
{ return false }
|
8612 |
-
} else {
|
8613 |
-
pos = next
|
8614 |
-
}
|
8615 |
-
return true
|
8616 |
-
}
|
8617 |
-
|
8618 |
-
if (unit == "char") {
|
8619 |
-
moveOnce()
|
8620 |
-
} else if (unit == "column") {
|
8621 |
-
moveOnce(true)
|
8622 |
-
} else if (unit == "word" || unit == "group") {
|
8623 |
-
var sawType = null, group = unit == "group"
|
8624 |
-
var helper = doc.cm && doc.cm.getHelper(pos, "wordChars")
|
8625 |
-
for (var first = true;; first = false) {
|
8626 |
-
if (dir < 0 && !moveOnce(!first)) { break }
|
8627 |
-
var cur = lineObj.text.charAt(pos.ch) || "\n"
|
8628 |
-
var type = isWordChar(cur, helper) ? "w"
|
8629 |
-
: group && cur == "\n" ? "n"
|
8630 |
-
: !group || /\s/.test(cur) ? null
|
8631 |
-
: "p"
|
8632 |
-
if (group && !first && !type) { type = "s" }
|
8633 |
-
if (sawType && sawType != type) {
|
8634 |
-
if (dir < 0) {dir = 1; moveOnce(); pos.sticky = "after"}
|
8635 |
-
break
|
8636 |
-
}
|
8637 |
-
|
8638 |
-
if (type) { sawType = type }
|
8639 |
-
if (dir > 0 && !moveOnce(!first)) { break }
|
8640 |
-
}
|
8641 |
-
}
|
8642 |
-
var result = skipAtomic(doc, pos, oldPos, origDir, true)
|
8643 |
-
if (equalCursorPos(oldPos, result)) { result.hitSide = true }
|
8644 |
-
return result
|
8645 |
-
}
|
8646 |
-
|
8647 |
-
// For relative vertical movement. Dir may be -1 or 1. Unit can be
|
8648 |
-
// "page" or "line". The resulting position will have a hitSide=true
|
8649 |
-
// property if it reached the end of the document.
|
8650 |
-
function findPosV(cm, pos, dir, unit) {
|
8651 |
-
var doc = cm.doc, x = pos.left, y
|
8652 |
-
if (unit == "page") {
|
8653 |
-
var pageSize = Math.min(cm.display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight)
|
8654 |
-
var moveAmount = Math.max(pageSize - .5 * textHeight(cm.display), 3)
|
8655 |
-
y = (dir > 0 ? pos.bottom : pos.top) + dir * moveAmount
|
8656 |
-
|
8657 |
-
} else if (unit == "line") {
|
8658 |
-
y = dir > 0 ? pos.bottom + 3 : pos.top - 3
|
8659 |
-
}
|
8660 |
-
var target
|
8661 |
-
for (;;) {
|
8662 |
-
target = coordsChar(cm, x, y)
|
8663 |
-
if (!target.outside) { break }
|
8664 |
-
if (dir < 0 ? y <= 0 : y >= doc.height) { target.hitSide = true; break }
|
8665 |
-
y += dir * 5
|
8666 |
-
}
|
8667 |
-
return target
|
8668 |
-
}
|
8669 |
-
|
8670 |
-
// CONTENTEDITABLE INPUT STYLE
|
8671 |
-
|
8672 |
-
var ContentEditableInput = function(cm) {
|
8673 |
-
this.cm = cm
|
8674 |
-
this.lastAnchorNode = this.lastAnchorOffset = this.lastFocusNode = this.lastFocusOffset = null
|
8675 |
-
this.polling = new Delayed()
|
8676 |
-
this.composing = null
|
8677 |
-
this.gracePeriod = false
|
8678 |
-
this.readDOMTimeout = null
|
8679 |
-
};
|
8680 |
-
|
8681 |
-
ContentEditableInput.prototype.init = function (display) {
|
8682 |
-
var this$1 = this;
|
8683 |
-
|
8684 |
-
var input = this, cm = input.cm
|
8685 |
-
var div = input.div = display.lineDiv
|
8686 |
-
disableBrowserMagic(div, cm.options.spellcheck)
|
8687 |
-
|
8688 |
-
on(div, "paste", function (e) {
|
8689 |
-
if (signalDOMEvent(cm, e) || handlePaste(e, cm)) { return }
|
8690 |
-
// IE doesn't fire input events, so we schedule a read for the pasted content in this way
|
8691 |
-
if (ie_version <= 11) { setTimeout(operation(cm, function () { return this$1.updateFromDOM(); }), 20) }
|
8692 |
-
})
|
8693 |
-
|
8694 |
-
on(div, "compositionstart", function (e) {
|
8695 |
-
this$1.composing = {data: e.data, done: false}
|
8696 |
-
})
|
8697 |
-
on(div, "compositionupdate", function (e) {
|
8698 |
-
if (!this$1.composing) { this$1.composing = {data: e.data, done: false} }
|
8699 |
-
})
|
8700 |
-
on(div, "compositionend", function (e) {
|
8701 |
-
if (this$1.composing) {
|
8702 |
-
if (e.data != this$1.composing.data) { this$1.readFromDOMSoon() }
|
8703 |
-
this$1.composing.done = true
|
8704 |
-
}
|
8705 |
-
})
|
8706 |
-
|
8707 |
-
on(div, "touchstart", function () { return input.forceCompositionEnd(); })
|
8708 |
-
|
8709 |
-
on(div, "input", function () {
|
8710 |
-
if (!this$1.composing) { this$1.readFromDOMSoon() }
|
8711 |
-
})
|
8712 |
-
|
8713 |
-
function onCopyCut(e) {
|
8714 |
-
if (signalDOMEvent(cm, e)) { return }
|
8715 |
-
if (cm.somethingSelected()) {
|
8716 |
-
setLastCopied({lineWise: false, text: cm.getSelections()})
|
8717 |
-
if (e.type == "cut") { cm.replaceSelection("", null, "cut") }
|
8718 |
-
} else if (!cm.options.lineWiseCopyCut) {
|
8719 |
-
return
|
8720 |
-
} else {
|
8721 |
-
var ranges = copyableRanges(cm)
|
8722 |
-
setLastCopied({lineWise: true, text: ranges.text})
|
8723 |
-
if (e.type == "cut") {
|
8724 |
-
cm.operation(function () {
|
8725 |
-
cm.setSelections(ranges.ranges, 0, sel_dontScroll)
|
8726 |
-
cm.replaceSelection("", null, "cut")
|
8727 |
-
})
|
8728 |
-
}
|
8729 |
-
}
|
8730 |
-
if (e.clipboardData) {
|
8731 |
-
e.clipboardData.clearData()
|
8732 |
-
var content = lastCopied.text.join("\n")
|
8733 |
-
// iOS exposes the clipboard API, but seems to discard content inserted into it
|
8734 |
-
e.clipboardData.setData("Text", content)
|
8735 |
-
if (e.clipboardData.getData("Text") == content) {
|
8736 |
-
e.preventDefault()
|
8737 |
-
return
|
8738 |
-
}
|
8739 |
-
}
|
8740 |
-
// Old-fashioned briefly-focus-a-textarea hack
|
8741 |
-
var kludge = hiddenTextarea(), te = kludge.firstChild
|
8742 |
-
cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild)
|
8743 |
-
te.value = lastCopied.text.join("\n")
|
8744 |
-
var hadFocus = document.activeElement
|
8745 |
-
selectInput(te)
|
8746 |
-
setTimeout(function () {
|
8747 |
-
cm.display.lineSpace.removeChild(kludge)
|
8748 |
-
hadFocus.focus()
|
8749 |
-
if (hadFocus == div) { input.showPrimarySelection() }
|
8750 |
-
}, 50)
|
8751 |
-
}
|
8752 |
-
on(div, "copy", onCopyCut)
|
8753 |
-
on(div, "cut", onCopyCut)
|
8754 |
-
};
|
8755 |
-
|
8756 |
-
ContentEditableInput.prototype.prepareSelection = function () {
|
8757 |
-
var result = prepareSelection(this.cm, false)
|
8758 |
-
result.focus = this.cm.state.focused
|
8759 |
-
return result
|
8760 |
-
};
|
8761 |
-
|
8762 |
-
ContentEditableInput.prototype.showSelection = function (info, takeFocus) {
|
8763 |
-
if (!info || !this.cm.display.view.length) { return }
|
8764 |
-
if (info.focus || takeFocus) { this.showPrimarySelection() }
|
8765 |
-
this.showMultipleSelections(info)
|
8766 |
-
};
|
8767 |
-
|
8768 |
-
ContentEditableInput.prototype.getSelection = function () {
|
8769 |
-
return this.cm.display.wrapper.ownerDocument.getSelection()
|
8770 |
-
};
|
8771 |
-
|
8772 |
-
ContentEditableInput.prototype.showPrimarySelection = function () {
|
8773 |
-
var sel = this.getSelection(), cm = this.cm, prim = cm.doc.sel.primary()
|
8774 |
-
var from = prim.from(), to = prim.to()
|
8775 |
-
|
8776 |
-
if (cm.display.viewTo == cm.display.viewFrom || from.line >= cm.display.viewTo || to.line < cm.display.viewFrom) {
|
8777 |
-
sel.removeAllRanges()
|
8778 |
-
return
|
8779 |
-
}
|
8780 |
-
|
8781 |
-
var curAnchor = domToPos(cm, sel.anchorNode, sel.anchorOffset)
|
8782 |
-
var curFocus = domToPos(cm, sel.focusNode, sel.focusOffset)
|
8783 |
-
if (curAnchor && !curAnchor.bad && curFocus && !curFocus.bad &&
|
8784 |
-
cmp(minPos(curAnchor, curFocus), from) == 0 &&
|
8785 |
-
cmp(maxPos(curAnchor, curFocus), to) == 0)
|
8786 |
-
{ return }
|
8787 |
-
|
8788 |
-
var view = cm.display.view
|
8789 |
-
var start = (from.line >= cm.display.viewFrom && posToDOM(cm, from)) ||
|
8790 |
-
{node: view[0].measure.map[2], offset: 0}
|
8791 |
-
var end = to.line < cm.display.viewTo && posToDOM(cm, to)
|
8792 |
-
if (!end) {
|
8793 |
-
var measure = view[view.length - 1].measure
|
8794 |
-
var map = measure.maps ? measure.maps[measure.maps.length - 1] : measure.map
|
8795 |
-
end = {node: map[map.length - 1], offset: map[map.length - 2] - map[map.length - 3]}
|
8796 |
-
}
|
8797 |
-
|
8798 |
-
if (!start || !end) {
|
8799 |
-
sel.removeAllRanges()
|
8800 |
-
return
|
8801 |
-
}
|
8802 |
-
|
8803 |
-
var old = sel.rangeCount && sel.getRangeAt(0), rng
|
8804 |
-
try { rng = range(start.node, start.offset, end.offset, end.node) }
|
8805 |
-
catch(e) {} // Our model of the DOM might be outdated, in which case the range we try to set can be impossible
|
8806 |
-
if (rng) {
|
8807 |
-
if (!gecko && cm.state.focused) {
|
8808 |
-
sel.collapse(start.node, start.offset)
|
8809 |
-
if (!rng.collapsed) {
|
8810 |
-
sel.removeAllRanges()
|
8811 |
-
sel.addRange(rng)
|
8812 |
-
}
|
8813 |
-
} else {
|
8814 |
-
sel.removeAllRanges()
|
8815 |
-
sel.addRange(rng)
|
8816 |
-
}
|
8817 |
-
if (old && sel.anchorNode == null) { sel.addRange(old) }
|
8818 |
-
else if (gecko) { this.startGracePeriod() }
|
8819 |
-
}
|
8820 |
-
this.rememberSelection()
|
8821 |
-
};
|
8822 |
-
|
8823 |
-
ContentEditableInput.prototype.startGracePeriod = function () {
|
8824 |
-
var this$1 = this;
|
8825 |
-
|
8826 |
-
clearTimeout(this.gracePeriod)
|
8827 |
-
this.gracePeriod = setTimeout(function () {
|
8828 |
-
this$1.gracePeriod = false
|
8829 |
-
if (this$1.selectionChanged())
|
8830 |
-
{ this$1.cm.operation(function () { return this$1.cm.curOp.selectionChanged = true; }) }
|
8831 |
-
}, 20)
|
8832 |
-
};
|
8833 |
-
|
8834 |
-
ContentEditableInput.prototype.showMultipleSelections = function (info) {
|
8835 |
-
removeChildrenAndAdd(this.cm.display.cursorDiv, info.cursors)
|
8836 |
-
removeChildrenAndAdd(this.cm.display.selectionDiv, info.selection)
|
8837 |
-
};
|
8838 |
-
|
8839 |
-
ContentEditableInput.prototype.rememberSelection = function () {
|
8840 |
-
var sel = this.getSelection()
|
8841 |
-
this.lastAnchorNode = sel.anchorNode; this.lastAnchorOffset = sel.anchorOffset
|
8842 |
-
this.lastFocusNode = sel.focusNode; this.lastFocusOffset = sel.focusOffset
|
8843 |
-
};
|
8844 |
-
|
8845 |
-
ContentEditableInput.prototype.selectionInEditor = function () {
|
8846 |
-
var sel = this.getSelection()
|
8847 |
-
if (!sel.rangeCount) { return false }
|
8848 |
-
var node = sel.getRangeAt(0).commonAncestorContainer
|
8849 |
-
return contains(this.div, node)
|
8850 |
-
};
|
8851 |
-
|
8852 |
-
ContentEditableInput.prototype.focus = function () {
|
8853 |
-
if (this.cm.options.readOnly != "nocursor") {
|
8854 |
-
if (!this.selectionInEditor())
|
8855 |
-
{ this.showSelection(this.prepareSelection(), true) }
|
8856 |
-
this.div.focus()
|
8857 |
-
}
|
8858 |
-
};
|
8859 |
-
ContentEditableInput.prototype.blur = function () { this.div.blur() };
|
8860 |
-
ContentEditableInput.prototype.getField = function () { return this.div };
|
8861 |
-
|
8862 |
-
ContentEditableInput.prototype.supportsTouch = function () { return true };
|
8863 |
-
|
8864 |
-
ContentEditableInput.prototype.receivedFocus = function () {
|
8865 |
-
var input = this
|
8866 |
-
if (this.selectionInEditor())
|
8867 |
-
{ this.pollSelection() }
|
8868 |
-
else
|
8869 |
-
{ runInOp(this.cm, function () { return input.cm.curOp.selectionChanged = true; }) }
|
8870 |
-
|
8871 |
-
function poll() {
|
8872 |
-
if (input.cm.state.focused) {
|
8873 |
-
input.pollSelection()
|
8874 |
-
input.polling.set(input.cm.options.pollInterval, poll)
|
8875 |
-
}
|
8876 |
-
}
|
8877 |
-
this.polling.set(this.cm.options.pollInterval, poll)
|
8878 |
-
};
|
8879 |
-
|
8880 |
-
ContentEditableInput.prototype.selectionChanged = function () {
|
8881 |
-
var sel = this.getSelection()
|
8882 |
-
return sel.anchorNode != this.lastAnchorNode || sel.anchorOffset != this.lastAnchorOffset ||
|
8883 |
-
sel.focusNode != this.lastFocusNode || sel.focusOffset != this.lastFocusOffset
|
8884 |
-
};
|
8885 |
-
|
8886 |
-
ContentEditableInput.prototype.pollSelection = function () {
|
8887 |
-
if (this.readDOMTimeout != null || this.gracePeriod || !this.selectionChanged()) { return }
|
8888 |
-
var sel = this.getSelection(), cm = this.cm
|
8889 |
-
// On Android Chrome (version 56, at least), backspacing into an
|
8890 |
-
// uneditable block element will put the cursor in that element,
|
8891 |
-
// and then, because it's not editable, hide the virtual keyboard.
|
8892 |
-
// Because Android doesn't allow us to actually detect backspace
|
8893 |
-
// presses in a sane way, this code checks for when that happens
|
8894 |
-
// and simulates a backspace press in this case.
|
8895 |
-
if (android && chrome && this.cm.options.gutters.length && isInGutter(sel.anchorNode)) {
|
8896 |
-
this.cm.triggerOnKeyDown({type: "keydown", keyCode: 8, preventDefault: Math.abs})
|
8897 |
-
this.blur()
|
8898 |
-
this.focus()
|
8899 |
-
return
|
8900 |
-
}
|
8901 |
-
if (this.composing) { return }
|
8902 |
-
this.rememberSelection()
|
8903 |
-
var anchor = domToPos(cm, sel.anchorNode, sel.anchorOffset)
|
8904 |
-
var head = domToPos(cm, sel.focusNode, sel.focusOffset)
|
8905 |
-
if (anchor && head) { runInOp(cm, function () {
|
8906 |
-
setSelection(cm.doc, simpleSelection(anchor, head), sel_dontScroll)
|
8907 |
-
if (anchor.bad || head.bad) { cm.curOp.selectionChanged = true }
|
8908 |
-
}) }
|
8909 |
-
};
|
8910 |
-
|
8911 |
-
ContentEditableInput.prototype.pollContent = function () {
|
8912 |
-
if (this.readDOMTimeout != null) {
|
8913 |
-
clearTimeout(this.readDOMTimeout)
|
8914 |
-
this.readDOMTimeout = null
|
8915 |
-
}
|
8916 |
-
|
8917 |
-
var cm = this.cm, display = cm.display, sel = cm.doc.sel.primary()
|
8918 |
-
var from = sel.from(), to = sel.to()
|
8919 |
-
if (from.ch == 0 && from.line > cm.firstLine())
|
8920 |
-
{ from = Pos(from.line - 1, getLine(cm.doc, from.line - 1).length) }
|
8921 |
-
if (to.ch == getLine(cm.doc, to.line).text.length && to.line < cm.lastLine())
|
8922 |
-
{ to = Pos(to.line + 1, 0) }
|
8923 |
-
if (from.line < display.viewFrom || to.line > display.viewTo - 1) { return false }
|
8924 |
-
|
8925 |
-
var fromIndex, fromLine, fromNode
|
8926 |
-
if (from.line == display.viewFrom || (fromIndex = findViewIndex(cm, from.line)) == 0) {
|
8927 |
-
fromLine = lineNo(display.view[0].line)
|
8928 |
-
fromNode = display.view[0].node
|
8929 |
-
} else {
|
8930 |
-
fromLine = lineNo(display.view[fromIndex].line)
|
8931 |
-
fromNode = display.view[fromIndex - 1].node.nextSibling
|
8932 |
-
}
|
8933 |
-
var toIndex = findViewIndex(cm, to.line)
|
8934 |
-
var toLine, toNode
|
8935 |
-
if (toIndex == display.view.length - 1) {
|
8936 |
-
toLine = display.viewTo - 1
|
8937 |
-
toNode = display.lineDiv.lastChild
|
8938 |
-
} else {
|
8939 |
-
toLine = lineNo(display.view[toIndex + 1].line) - 1
|
8940 |
-
toNode = display.view[toIndex + 1].node.previousSibling
|
8941 |
-
}
|
8942 |
-
|
8943 |
-
if (!fromNode) { return false }
|
8944 |
-
var newText = cm.doc.splitLines(domTextBetween(cm, fromNode, toNode, fromLine, toLine))
|
8945 |
-
var oldText = getBetween(cm.doc, Pos(fromLine, 0), Pos(toLine, getLine(cm.doc, toLine).text.length))
|
8946 |
-
while (newText.length > 1 && oldText.length > 1) {
|
8947 |
-
if (lst(newText) == lst(oldText)) { newText.pop(); oldText.pop(); toLine-- }
|
8948 |
-
else if (newText[0] == oldText[0]) { newText.shift(); oldText.shift(); fromLine++ }
|
8949 |
-
else { break }
|
8950 |
-
}
|
8951 |
-
|
8952 |
-
var cutFront = 0, cutEnd = 0
|
8953 |
-
var newTop = newText[0], oldTop = oldText[0], maxCutFront = Math.min(newTop.length, oldTop.length)
|
8954 |
-
while (cutFront < maxCutFront && newTop.charCodeAt(cutFront) == oldTop.charCodeAt(cutFront))
|
8955 |
-
{ ++cutFront }
|
8956 |
-
var newBot = lst(newText), oldBot = lst(oldText)
|
8957 |
-
var maxCutEnd = Math.min(newBot.length - (newText.length == 1 ? cutFront : 0),
|
8958 |
-
oldBot.length - (oldText.length == 1 ? cutFront : 0))
|
8959 |
-
while (cutEnd < maxCutEnd &&
|
8960 |
-
newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1))
|
8961 |
-
{ ++cutEnd }
|
8962 |
-
// Try to move start of change to start of selection if ambiguous
|
8963 |
-
if (newText.length == 1 && oldText.length == 1 && fromLine == from.line) {
|
8964 |
-
while (cutFront && cutFront > from.ch &&
|
8965 |
-
newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1)) {
|
8966 |
-
cutFront--
|
8967 |
-
cutEnd++
|
8968 |
-
}
|
8969 |
-
}
|
8970 |
-
|
8971 |
-
newText[newText.length - 1] = newBot.slice(0, newBot.length - cutEnd).replace(/^\u200b+/, "")
|
8972 |
-
newText[0] = newText[0].slice(cutFront).replace(/\u200b+$/, "")
|
8973 |
-
|
8974 |
-
var chFrom = Pos(fromLine, cutFront)
|
8975 |
-
var chTo = Pos(toLine, oldText.length ? lst(oldText).length - cutEnd : 0)
|
8976 |
-
if (newText.length > 1 || newText[0] || cmp(chFrom, chTo)) {
|
8977 |
-
replaceRange(cm.doc, newText, chFrom, chTo, "+input")
|
8978 |
-
return true
|
8979 |
-
}
|
8980 |
-
};
|
8981 |
-
|
8982 |
-
ContentEditableInput.prototype.ensurePolled = function () {
|
8983 |
-
this.forceCompositionEnd()
|
8984 |
-
};
|
8985 |
-
ContentEditableInput.prototype.reset = function () {
|
8986 |
-
this.forceCompositionEnd()
|
8987 |
-
};
|
8988 |
-
ContentEditableInput.prototype.forceCompositionEnd = function () {
|
8989 |
-
if (!this.composing) { return }
|
8990 |
-
clearTimeout(this.readDOMTimeout)
|
8991 |
-
this.composing = null
|
8992 |
-
this.updateFromDOM()
|
8993 |
-
this.div.blur()
|
8994 |
-
this.div.focus()
|
8995 |
-
};
|
8996 |
-
ContentEditableInput.prototype.readFromDOMSoon = function () {
|
8997 |
-
var this$1 = this;
|
8998 |
-
|
8999 |
-
if (this.readDOMTimeout != null) { return }
|
9000 |
-
this.readDOMTimeout = setTimeout(function () {
|
9001 |
-
this$1.readDOMTimeout = null
|
9002 |
-
if (this$1.composing) {
|
9003 |
-
if (this$1.composing.done) { this$1.composing = null }
|
9004 |
-
else { return }
|
9005 |
-
}
|
9006 |
-
this$1.updateFromDOM()
|
9007 |
-
}, 80)
|
9008 |
-
};
|
9009 |
-
|
9010 |
-
ContentEditableInput.prototype.updateFromDOM = function () {
|
9011 |
-
var this$1 = this;
|
9012 |
-
|
9013 |
-
if (this.cm.isReadOnly() || !this.pollContent())
|
9014 |
-
{ runInOp(this.cm, function () { return regChange(this$1.cm); }) }
|
9015 |
-
};
|
9016 |
-
|
9017 |
-
ContentEditableInput.prototype.setUneditable = function (node) {
|
9018 |
-
node.contentEditable = "false"
|
9019 |
-
};
|
9020 |
-
|
9021 |
-
ContentEditableInput.prototype.onKeyPress = function (e) {
|
9022 |
-
if (e.charCode == 0 || this.composing) { return }
|
9023 |
-
e.preventDefault()
|
9024 |
-
if (!this.cm.isReadOnly())
|
9025 |
-
{ operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0) }
|
9026 |
-
};
|
9027 |
-
|
9028 |
-
ContentEditableInput.prototype.readOnlyChanged = function (val) {
|
9029 |
-
this.div.contentEditable = String(val != "nocursor")
|
9030 |
-
};
|
9031 |
-
|
9032 |
-
ContentEditableInput.prototype.onContextMenu = function () {};
|
9033 |
-
ContentEditableInput.prototype.resetPosition = function () {};
|
9034 |
-
|
9035 |
-
ContentEditableInput.prototype.needsContentAttribute = true
|
9036 |
-
|
9037 |
-
function posToDOM(cm, pos) {
|
9038 |
-
var view = findViewForLine(cm, pos.line)
|
9039 |
-
if (!view || view.hidden) { return null }
|
9040 |
-
var line = getLine(cm.doc, pos.line)
|
9041 |
-
var info = mapFromLineView(view, line, pos.line)
|
9042 |
-
|
9043 |
-
var order = getOrder(line, cm.doc.direction), side = "left"
|
9044 |
-
if (order) {
|
9045 |
-
var partPos = getBidiPartAt(order, pos.ch)
|
9046 |
-
side = partPos % 2 ? "right" : "left"
|
9047 |
-
}
|
9048 |
-
var result = nodeAndOffsetInLineMap(info.map, pos.ch, side)
|
9049 |
-
result.offset = result.collapse == "right" ? result.end : result.start
|
9050 |
-
return result
|
9051 |
-
}
|
9052 |
-
|
9053 |
-
function isInGutter(node) {
|
9054 |
-
for (var scan = node; scan; scan = scan.parentNode)
|
9055 |
-
{ if (/CodeMirror-gutter-wrapper/.test(scan.className)) { return true } }
|
9056 |
-
return false
|
9057 |
-
}
|
9058 |
-
|
9059 |
-
function badPos(pos, bad) { if (bad) { pos.bad = true; } return pos }
|
9060 |
-
|
9061 |
-
function domTextBetween(cm, from, to, fromLine, toLine) {
|
9062 |
-
var text = "", closing = false, lineSep = cm.doc.lineSeparator(), extraLinebreak = false
|
9063 |
-
function recognizeMarker(id) { return function (marker) { return marker.id == id; } }
|
9064 |
-
function close() {
|
9065 |
-
if (closing) {
|
9066 |
-
text += lineSep
|
9067 |
-
if (extraLinebreak) { text += lineSep }
|
9068 |
-
closing = extraLinebreak = false
|
9069 |
-
}
|
9070 |
-
}
|
9071 |
-
function addText(str) {
|
9072 |
-
if (str) {
|
9073 |
-
close()
|
9074 |
-
text += str
|
9075 |
-
}
|
9076 |
-
}
|
9077 |
-
function walk(node) {
|
9078 |
-
if (node.nodeType == 1) {
|
9079 |
-
var cmText = node.getAttribute("cm-text")
|
9080 |
-
if (cmText) {
|
9081 |
-
addText(cmText)
|
9082 |
-
return
|
9083 |
-
}
|
9084 |
-
var markerID = node.getAttribute("cm-marker"), range
|
9085 |
-
if (markerID) {
|
9086 |
-
var found = cm.findMarks(Pos(fromLine, 0), Pos(toLine + 1, 0), recognizeMarker(+markerID))
|
9087 |
-
if (found.length && (range = found[0].find(0)))
|
9088 |
-
{ addText(getBetween(cm.doc, range.from, range.to).join(lineSep)) }
|
9089 |
-
return
|
9090 |
-
}
|
9091 |
-
if (node.getAttribute("contenteditable") == "false") { return }
|
9092 |
-
var isBlock = /^(pre|div|p|li|table|br)$/i.test(node.nodeName)
|
9093 |
-
if (!/^br$/i.test(node.nodeName) && node.textContent.length == 0) { return }
|
9094 |
-
|
9095 |
-
if (isBlock) { close() }
|
9096 |
-
for (var i = 0; i < node.childNodes.length; i++)
|
9097 |
-
{ walk(node.childNodes[i]) }
|
9098 |
-
|
9099 |
-
if (/^(pre|p)$/i.test(node.nodeName)) { extraLinebreak = true }
|
9100 |
-
if (isBlock) { closing = true }
|
9101 |
-
} else if (node.nodeType == 3) {
|
9102 |
-
addText(node.nodeValue.replace(/\u200b/g, "").replace(/\u00a0/g, " "))
|
9103 |
-
}
|
9104 |
-
}
|
9105 |
-
for (;;) {
|
9106 |
-
walk(from)
|
9107 |
-
if (from == to) { break }
|
9108 |
-
from = from.nextSibling
|
9109 |
-
extraLinebreak = false
|
9110 |
-
}
|
9111 |
-
return text
|
9112 |
-
}
|
9113 |
-
|
9114 |
-
function domToPos(cm, node, offset) {
|
9115 |
-
var lineNode
|
9116 |
-
if (node == cm.display.lineDiv) {
|
9117 |
-
lineNode = cm.display.lineDiv.childNodes[offset]
|
9118 |
-
if (!lineNode) { return badPos(cm.clipPos(Pos(cm.display.viewTo - 1)), true) }
|
9119 |
-
node = null; offset = 0
|
9120 |
-
} else {
|
9121 |
-
for (lineNode = node;; lineNode = lineNode.parentNode) {
|
9122 |
-
if (!lineNode || lineNode == cm.display.lineDiv) { return null }
|
9123 |
-
if (lineNode.parentNode && lineNode.parentNode == cm.display.lineDiv) { break }
|
9124 |
-
}
|
9125 |
-
}
|
9126 |
-
for (var i = 0; i < cm.display.view.length; i++) {
|
9127 |
-
var lineView = cm.display.view[i]
|
9128 |
-
if (lineView.node == lineNode)
|
9129 |
-
{ return locateNodeInLineView(lineView, node, offset) }
|
9130 |
-
}
|
9131 |
-
}
|
9132 |
-
|
9133 |
-
function locateNodeInLineView(lineView, node, offset) {
|
9134 |
-
var wrapper = lineView.text.firstChild, bad = false
|
9135 |
-
if (!node || !contains(wrapper, node)) { return badPos(Pos(lineNo(lineView.line), 0), true) }
|
9136 |
-
if (node == wrapper) {
|
9137 |
-
bad = true
|
9138 |
-
node = wrapper.childNodes[offset]
|
9139 |
-
offset = 0
|
9140 |
-
if (!node) {
|
9141 |
-
var line = lineView.rest ? lst(lineView.rest) : lineView.line
|
9142 |
-
return badPos(Pos(lineNo(line), line.text.length), bad)
|
9143 |
-
}
|
9144 |
-
}
|
9145 |
-
|
9146 |
-
var textNode = node.nodeType == 3 ? node : null, topNode = node
|
9147 |
-
if (!textNode && node.childNodes.length == 1 && node.firstChild.nodeType == 3) {
|
9148 |
-
textNode = node.firstChild
|
9149 |
-
if (offset) { offset = textNode.nodeValue.length }
|
9150 |
-
}
|
9151 |
-
while (topNode.parentNode != wrapper) { topNode = topNode.parentNode }
|
9152 |
-
var measure = lineView.measure, maps = measure.maps
|
9153 |
-
|
9154 |
-
function find(textNode, topNode, offset) {
|
9155 |
-
for (var i = -1; i < (maps ? maps.length : 0); i++) {
|
9156 |
-
var map = i < 0 ? measure.map : maps[i]
|
9157 |
-
for (var j = 0; j < map.length; j += 3) {
|
9158 |
-
var curNode = map[j + 2]
|
9159 |
-
if (curNode == textNode || curNode == topNode) {
|
9160 |
-
var line = lineNo(i < 0 ? lineView.line : lineView.rest[i])
|
9161 |
-
var ch = map[j] + offset
|
9162 |
-
if (offset < 0 || curNode != textNode) { ch = map[j + (offset ? 1 : 0)] }
|
9163 |
-
return Pos(line, ch)
|
9164 |
-
}
|
9165 |
-
}
|
9166 |
-
}
|
9167 |
-
}
|
9168 |
-
var found = find(textNode, topNode, offset)
|
9169 |
-
if (found) { return badPos(found, bad) }
|
9170 |
-
|
9171 |
-
// FIXME this is all really shaky. might handle the few cases it needs to handle, but likely to cause problems
|
9172 |
-
for (var after = topNode.nextSibling, dist = textNode ? textNode.nodeValue.length - offset : 0; after; after = after.nextSibling) {
|
9173 |
-
found = find(after, after.firstChild, 0)
|
9174 |
-
if (found)
|
9175 |
-
{ return badPos(Pos(found.line, found.ch - dist), bad) }
|
9176 |
-
else
|
9177 |
-
{ dist += after.textContent.length }
|
9178 |
-
}
|
9179 |
-
for (var before = topNode.previousSibling, dist$1 = offset; before; before = before.previousSibling) {
|
9180 |
-
found = find(before, before.firstChild, -1)
|
9181 |
-
if (found)
|
9182 |
-
{ return badPos(Pos(found.line, found.ch + dist$1), bad) }
|
9183 |
-
else
|
9184 |
-
{ dist$1 += before.textContent.length }
|
9185 |
-
}
|
9186 |
-
}
|
9187 |
-
|
9188 |
-
// TEXTAREA INPUT STYLE
|
9189 |
-
|
9190 |
-
var TextareaInput = function(cm) {
|
9191 |
-
this.cm = cm
|
9192 |
-
// See input.poll and input.reset
|
9193 |
-
this.prevInput = ""
|
9194 |
-
|
9195 |
-
// Flag that indicates whether we expect input to appear real soon
|
9196 |
-
// now (after some event like 'keypress' or 'input') and are
|
9197 |
-
// polling intensively.
|
9198 |
-
this.pollingFast = false
|
9199 |
-
// Self-resetting timeout for the poller
|
9200 |
-
this.polling = new Delayed()
|
9201 |
-
// Used to work around IE issue with selection being forgotten when focus moves away from textarea
|
9202 |
-
this.hasSelection = false
|
9203 |
-
this.composing = null
|
9204 |
-
};
|
9205 |
-
|
9206 |
-
TextareaInput.prototype.init = function (display) {
|
9207 |
-
var this$1 = this;
|
9208 |
-
|
9209 |
-
var input = this, cm = this.cm
|
9210 |
-
this.createField(display)
|
9211 |
-
var te = this.textarea
|
9212 |
-
|
9213 |
-
display.wrapper.insertBefore(this.wrapper, display.wrapper.firstChild)
|
9214 |
-
|
9215 |
-
// Needed to hide big blue blinking cursor on Mobile Safari (doesn't seem to work in iOS 8 anymore)
|
9216 |
-
if (ios) { te.style.width = "0px" }
|
9217 |
-
|
9218 |
-
on(te, "input", function () {
|
9219 |
-
if (ie && ie_version >= 9 && this$1.hasSelection) { this$1.hasSelection = null }
|
9220 |
-
input.poll()
|
9221 |
-
})
|
9222 |
-
|
9223 |
-
on(te, "paste", function (e) {
|
9224 |
-
if (signalDOMEvent(cm, e) || handlePaste(e, cm)) { return }
|
9225 |
-
|
9226 |
-
cm.state.pasteIncoming = true
|
9227 |
-
input.fastPoll()
|
9228 |
-
})
|
9229 |
-
|
9230 |
-
function prepareCopyCut(e) {
|
9231 |
-
if (signalDOMEvent(cm, e)) { return }
|
9232 |
-
if (cm.somethingSelected()) {
|
9233 |
-
setLastCopied({lineWise: false, text: cm.getSelections()})
|
9234 |
-
} else if (!cm.options.lineWiseCopyCut) {
|
9235 |
-
return
|
9236 |
-
} else {
|
9237 |
-
var ranges = copyableRanges(cm)
|
9238 |
-
setLastCopied({lineWise: true, text: ranges.text})
|
9239 |
-
if (e.type == "cut") {
|
9240 |
-
cm.setSelections(ranges.ranges, null, sel_dontScroll)
|
9241 |
-
} else {
|
9242 |
-
input.prevInput = ""
|
9243 |
-
te.value = ranges.text.join("\n")
|
9244 |
-
selectInput(te)
|
9245 |
-
}
|
9246 |
-
}
|
9247 |
-
if (e.type == "cut") { cm.state.cutIncoming = true }
|
9248 |
-
}
|
9249 |
-
on(te, "cut", prepareCopyCut)
|
9250 |
-
on(te, "copy", prepareCopyCut)
|
9251 |
-
|
9252 |
-
on(display.scroller, "paste", function (e) {
|
9253 |
-
if (eventInWidget(display, e) || signalDOMEvent(cm, e)) { return }
|
9254 |
-
cm.state.pasteIncoming = true
|
9255 |
-
input.focus()
|
9256 |
-
})
|
9257 |
-
|
9258 |
-
// Prevent normal selection in the editor (we handle our own)
|
9259 |
-
on(display.lineSpace, "selectstart", function (e) {
|
9260 |
-
if (!eventInWidget(display, e)) { e_preventDefault(e) }
|
9261 |
-
})
|
9262 |
-
|
9263 |
-
on(te, "compositionstart", function () {
|
9264 |
-
var start = cm.getCursor("from")
|
9265 |
-
if (input.composing) { input.composing.range.clear() }
|
9266 |
-
input.composing = {
|
9267 |
-
start: start,
|
9268 |
-
range: cm.markText(start, cm.getCursor("to"), {className: "CodeMirror-composing"})
|
9269 |
-
}
|
9270 |
-
})
|
9271 |
-
on(te, "compositionend", function () {
|
9272 |
-
if (input.composing) {
|
9273 |
-
input.poll()
|
9274 |
-
input.composing.range.clear()
|
9275 |
-
input.composing = null
|
9276 |
-
}
|
9277 |
-
})
|
9278 |
-
};
|
9279 |
-
|
9280 |
-
TextareaInput.prototype.createField = function (_display) {
|
9281 |
-
// Wraps and hides input textarea
|
9282 |
-
this.wrapper = hiddenTextarea()
|
9283 |
-
// The semihidden textarea that is focused when the editor is
|
9284 |
-
// focused, and receives input.
|
9285 |
-
this.textarea = this.wrapper.firstChild
|
9286 |
-
};
|
9287 |
-
|
9288 |
-
TextareaInput.prototype.prepareSelection = function () {
|
9289 |
-
// Redraw the selection and/or cursor
|
9290 |
-
var cm = this.cm, display = cm.display, doc = cm.doc
|
9291 |
-
var result = prepareSelection(cm)
|
9292 |
-
|
9293 |
-
// Move the hidden textarea near the cursor to prevent scrolling artifacts
|
9294 |
-
if (cm.options.moveInputWithCursor) {
|
9295 |
-
var headPos = cursorCoords(cm, doc.sel.primary().head, "div")
|
9296 |
-
var wrapOff = display.wrapper.getBoundingClientRect(), lineOff = display.lineDiv.getBoundingClientRect()
|
9297 |
-
result.teTop = Math.max(0, Math.min(display.wrapper.clientHeight - 10,
|
9298 |
-
headPos.top + lineOff.top - wrapOff.top))
|
9299 |
-
result.teLeft = Math.max(0, Math.min(display.wrapper.clientWidth - 10,
|
9300 |
-
headPos.left + lineOff.left - wrapOff.left))
|
9301 |
-
}
|
9302 |
-
|
9303 |
-
return result
|
9304 |
-
};
|
9305 |
-
|
9306 |
-
TextareaInput.prototype.showSelection = function (drawn) {
|
9307 |
-
var cm = this.cm, display = cm.display
|
9308 |
-
removeChildrenAndAdd(display.cursorDiv, drawn.cursors)
|
9309 |
-
removeChildrenAndAdd(display.selectionDiv, drawn.selection)
|
9310 |
-
if (drawn.teTop != null) {
|
9311 |
-
this.wrapper.style.top = drawn.teTop + "px"
|
9312 |
-
this.wrapper.style.left = drawn.teLeft + "px"
|
9313 |
-
}
|
9314 |
-
};
|
9315 |
-
|
9316 |
-
// Reset the input to correspond to the selection (or to be empty,
|
9317 |
-
// when not typing and nothing is selected)
|
9318 |
-
TextareaInput.prototype.reset = function (typing) {
|
9319 |
-
if (this.contextMenuPending || this.composing) { return }
|
9320 |
-
var cm = this.cm
|
9321 |
-
if (cm.somethingSelected()) {
|
9322 |
-
this.prevInput = ""
|
9323 |
-
var content = cm.getSelection()
|
9324 |
-
this.textarea.value = content
|
9325 |
-
if (cm.state.focused) { selectInput(this.textarea) }
|
9326 |
-
if (ie && ie_version >= 9) { this.hasSelection = content }
|
9327 |
-
} else if (!typing) {
|
9328 |
-
this.prevInput = this.textarea.value = ""
|
9329 |
-
if (ie && ie_version >= 9) { this.hasSelection = null }
|
9330 |
-
}
|
9331 |
-
};
|
9332 |
-
|
9333 |
-
TextareaInput.prototype.getField = function () { return this.textarea };
|
9334 |
-
|
9335 |
-
TextareaInput.prototype.supportsTouch = function () { return false };
|
9336 |
-
|
9337 |
-
TextareaInput.prototype.focus = function () {
|
9338 |
-
if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt() != this.textarea)) {
|
9339 |
-
try { this.textarea.focus() }
|
9340 |
-
catch (e) {} // IE8 will throw if the textarea is display: none or not in DOM
|
9341 |
-
}
|
9342 |
-
};
|
9343 |
-
|
9344 |
-
TextareaInput.prototype.blur = function () { this.textarea.blur() };
|
9345 |
-
|
9346 |
-
TextareaInput.prototype.resetPosition = function () {
|
9347 |
-
this.wrapper.style.top = this.wrapper.style.left = 0
|
9348 |
-
};
|
9349 |
-
|
9350 |
-
TextareaInput.prototype.receivedFocus = function () { this.slowPoll() };
|
9351 |
-
|
9352 |
-
// Poll for input changes, using the normal rate of polling. This
|
9353 |
-
// runs as long as the editor is focused.
|
9354 |
-
TextareaInput.prototype.slowPoll = function () {
|
9355 |
-
var this$1 = this;
|
9356 |
-
|
9357 |
-
if (this.pollingFast) { return }
|
9358 |
-
this.polling.set(this.cm.options.pollInterval, function () {
|
9359 |
-
this$1.poll()
|
9360 |
-
if (this$1.cm.state.focused) { this$1.slowPoll() }
|
9361 |
-
})
|
9362 |
-
};
|
9363 |
-
|
9364 |
-
// When an event has just come in that is likely to add or change
|
9365 |
-
// something in the input textarea, we poll faster, to ensure that
|
9366 |
-
// the change appears on the screen quickly.
|
9367 |
-
TextareaInput.prototype.fastPoll = function () {
|
9368 |
-
var missed = false, input = this
|
9369 |
-
input.pollingFast = true
|
9370 |
-
function p() {
|
9371 |
-
var changed = input.poll()
|
9372 |
-
if (!changed && !missed) {missed = true; input.polling.set(60, p)}
|
9373 |
-
else {input.pollingFast = false; input.slowPoll()}
|
9374 |
-
}
|
9375 |
-
input.polling.set(20, p)
|
9376 |
-
};
|
9377 |
-
|
9378 |
-
// Read input from the textarea, and update the document to match.
|
9379 |
-
// When something is selected, it is present in the textarea, and
|
9380 |
-
// selected (unless it is huge, in which case a placeholder is
|
9381 |
-
// used). When nothing is selected, the cursor sits after previously
|
9382 |
-
// seen text (can be empty), which is stored in prevInput (we must
|
9383 |
-
// not reset the textarea when typing, because that breaks IME).
|
9384 |
-
TextareaInput.prototype.poll = function () {
|
9385 |
-
var this$1 = this;
|
9386 |
-
|
9387 |
-
var cm = this.cm, input = this.textarea, prevInput = this.prevInput
|
9388 |
-
// Since this is called a *lot*, try to bail out as cheaply as
|
9389 |
-
// possible when it is clear that nothing happened. hasSelection
|
9390 |
-
// will be the case when there is a lot of text in the textarea,
|
9391 |
-
// in which case reading its value would be expensive.
|
9392 |
-
if (this.contextMenuPending || !cm.state.focused ||
|
9393 |
-
(hasSelection(input) && !prevInput && !this.composing) ||
|
9394 |
-
cm.isReadOnly() || cm.options.disableInput || cm.state.keySeq)
|
9395 |
-
{ return false }
|
9396 |
-
|
9397 |
-
var text = input.value
|
9398 |
-
// If nothing changed, bail.
|
9399 |
-
if (text == prevInput && !cm.somethingSelected()) { return false }
|
9400 |
-
// Work around nonsensical selection resetting in IE9/10, and
|
9401 |
-
// inexplicable appearance of private area unicode characters on
|
9402 |
-
// some key combos in Mac (#2689).
|
9403 |
-
if (ie && ie_version >= 9 && this.hasSelection === text ||
|
9404 |
-
mac && /[\uf700-\uf7ff]/.test(text)) {
|
9405 |
-
cm.display.input.reset()
|
9406 |
-
return false
|
9407 |
-
}
|
9408 |
-
|
9409 |
-
if (cm.doc.sel == cm.display.selForContextMenu) {
|
9410 |
-
var first = text.charCodeAt(0)
|
9411 |
-
if (first == 0x200b && !prevInput) { prevInput = "\u200b" }
|
9412 |
-
if (first == 0x21da) { this.reset(); return this.cm.execCommand("undo") }
|
9413 |
-
}
|
9414 |
-
// Find the part of the input that is actually new
|
9415 |
-
var same = 0, l = Math.min(prevInput.length, text.length)
|
9416 |
-
while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) { ++same }
|
9417 |
-
|
9418 |
-
runInOp(cm, function () {
|
9419 |
-
applyTextInput(cm, text.slice(same), prevInput.length - same,
|
9420 |
-
null, this$1.composing ? "*compose" : null)
|
9421 |
-
|
9422 |
-
// Don't leave long text in the textarea, since it makes further polling slow
|
9423 |
-
if (text.length > 1000 || text.indexOf("\n") > -1) { input.value = this$1.prevInput = "" }
|
9424 |
-
else { this$1.prevInput = text }
|
9425 |
-
|
9426 |
-
if (this$1.composing) {
|
9427 |
-
this$1.composing.range.clear()
|
9428 |
-
this$1.composing.range = cm.markText(this$1.composing.start, cm.getCursor("to"),
|
9429 |
-
{className: "CodeMirror-composing"})
|
9430 |
-
}
|
9431 |
-
})
|
9432 |
-
return true
|
9433 |
-
};
|
9434 |
-
|
9435 |
-
TextareaInput.prototype.ensurePolled = function () {
|
9436 |
-
if (this.pollingFast && this.poll()) { this.pollingFast = false }
|
9437 |
-
};
|
9438 |
-
|
9439 |
-
TextareaInput.prototype.onKeyPress = function () {
|
9440 |
-
if (ie && ie_version >= 9) { this.hasSelection = null }
|
9441 |
-
this.fastPoll()
|
9442 |
-
};
|
9443 |
-
|
9444 |
-
TextareaInput.prototype.onContextMenu = function (e) {
|
9445 |
-
var input = this, cm = input.cm, display = cm.display, te = input.textarea
|
9446 |
-
var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop
|
9447 |
-
if (!pos || presto) { return } // Opera is difficult.
|
9448 |
-
|
9449 |
-
// Reset the current text selection only if the click is done outside of the selection
|
9450 |
-
// and 'resetSelectionOnContextMenu' option is true.
|
9451 |
-
var reset = cm.options.resetSelectionOnContextMenu
|
9452 |
-
if (reset && cm.doc.sel.contains(pos) == -1)
|
9453 |
-
{ operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll) }
|
9454 |
-
|
9455 |
-
var oldCSS = te.style.cssText, oldWrapperCSS = input.wrapper.style.cssText
|
9456 |
-
input.wrapper.style.cssText = "position: absolute"
|
9457 |
-
var wrapperBox = input.wrapper.getBoundingClientRect()
|
9458 |
-
te.style.cssText = "position: absolute; width: 30px; height: 30px;\n top: " + (e.clientY - wrapperBox.top - 5) + "px; left: " + (e.clientX - wrapperBox.left - 5) + "px;\n z-index: 1000; background: " + (ie ? "rgba(255, 255, 255, .05)" : "transparent") + ";\n outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);"
|
9459 |
-
var oldScrollY
|
9460 |
-
if (webkit) { oldScrollY = window.scrollY } // Work around Chrome issue (#2712)
|
9461 |
-
display.input.focus()
|
9462 |
-
if (webkit) { window.scrollTo(null, oldScrollY) }
|
9463 |
-
display.input.reset()
|
9464 |
-
// Adds "Select all" to context menu in FF
|
9465 |
-
if (!cm.somethingSelected()) { te.value = input.prevInput = " " }
|
9466 |
-
input.contextMenuPending = true
|
9467 |
-
display.selForContextMenu = cm.doc.sel
|
9468 |
-
clearTimeout(display.detectingSelectAll)
|
9469 |
-
|
9470 |
-
// Select-all will be greyed out if there's nothing to select, so
|
9471 |
-
// this adds a zero-width space so that we can later check whether
|
9472 |
-
// it got selected.
|
9473 |
-
function prepareSelectAllHack() {
|
9474 |
-
if (te.selectionStart != null) {
|
9475 |
-
var selected = cm.somethingSelected()
|
9476 |
-
var extval = "\u200b" + (selected ? te.value : "")
|
9477 |
-
te.value = "\u21da" // Used to catch context-menu undo
|
9478 |
-
te.value = extval
|
9479 |
-
input.prevInput = selected ? "" : "\u200b"
|
9480 |
-
te.selectionStart = 1; te.selectionEnd = extval.length
|
9481 |
-
// Re-set this, in case some other handler touched the
|
9482 |
-
// selection in the meantime.
|
9483 |
-
display.selForContextMenu = cm.doc.sel
|
9484 |
-
}
|
9485 |
-
}
|
9486 |
-
function rehide() {
|
9487 |
-
input.contextMenuPending = false
|
9488 |
-
input.wrapper.style.cssText = oldWrapperCSS
|
9489 |
-
te.style.cssText = oldCSS
|
9490 |
-
if (ie && ie_version < 9) { display.scrollbars.setScrollTop(display.scroller.scrollTop = scrollPos) }
|
9491 |
-
|
9492 |
-
// Try to detect the user choosing select-all
|
9493 |
-
if (te.selectionStart != null) {
|
9494 |
-
if (!ie || (ie && ie_version < 9)) { prepareSelectAllHack() }
|
9495 |
-
var i = 0, poll = function () {
|
9496 |
-
if (display.selForContextMenu == cm.doc.sel && te.selectionStart == 0 &&
|
9497 |
-
te.selectionEnd > 0 && input.prevInput == "\u200b") {
|
9498 |
-
operation(cm, selectAll)(cm)
|
9499 |
-
} else if (i++ < 10) {
|
9500 |
-
display.detectingSelectAll = setTimeout(poll, 500)
|
9501 |
-
} else {
|
9502 |
-
display.selForContextMenu = null
|
9503 |
-
display.input.reset()
|
9504 |
-
}
|
9505 |
-
}
|
9506 |
-
display.detectingSelectAll = setTimeout(poll, 200)
|
9507 |
-
}
|
9508 |
-
}
|
9509 |
-
|
9510 |
-
if (ie && ie_version >= 9) { prepareSelectAllHack() }
|
9511 |
-
if (captureRightClick) {
|
9512 |
-
e_stop(e)
|
9513 |
-
var mouseup = function () {
|
9514 |
-
off(window, "mouseup", mouseup)
|
9515 |
-
setTimeout(rehide, 20)
|
9516 |
-
}
|
9517 |
-
on(window, "mouseup", mouseup)
|
9518 |
-
} else {
|
9519 |
-
setTimeout(rehide, 50)
|
9520 |
-
}
|
9521 |
-
};
|
9522 |
-
|
9523 |
-
TextareaInput.prototype.readOnlyChanged = function (val) {
|
9524 |
-
if (!val) { this.reset() }
|
9525 |
-
this.textarea.disabled = val == "nocursor"
|
9526 |
-
};
|
9527 |
-
|
9528 |
-
TextareaInput.prototype.setUneditable = function () {};
|
9529 |
-
|
9530 |
-
TextareaInput.prototype.needsContentAttribute = false
|
9531 |
-
|
9532 |
-
function fromTextArea(textarea, options) {
|
9533 |
-
options = options ? copyObj(options) : {}
|
9534 |
-
options.value = textarea.value
|
9535 |
-
if (!options.tabindex && textarea.tabIndex)
|
9536 |
-
{ options.tabindex = textarea.tabIndex }
|
9537 |
-
if (!options.placeholder && textarea.placeholder)
|
9538 |
-
{ options.placeholder = textarea.placeholder }
|
9539 |
-
// Set autofocus to true if this textarea is focused, or if it has
|
9540 |
-
// autofocus and no other element is focused.
|
9541 |
-
if (options.autofocus == null) {
|
9542 |
-
var hasFocus = activeElt()
|
9543 |
-
options.autofocus = hasFocus == textarea ||
|
9544 |
-
textarea.getAttribute("autofocus") != null && hasFocus == document.body
|
9545 |
-
}
|
9546 |
-
|
9547 |
-
function save() {textarea.value = cm.getValue()}
|
9548 |
-
|
9549 |
-
var realSubmit
|
9550 |
-
if (textarea.form) {
|
9551 |
-
on(textarea.form, "submit", save)
|
9552 |
-
// Deplorable hack to make the submit method do the right thing.
|
9553 |
-
if (!options.leaveSubmitMethodAlone) {
|
9554 |
-
var form = textarea.form
|
9555 |
-
realSubmit = form.submit
|
9556 |
-
try {
|
9557 |
-
var wrappedSubmit = form.submit = function () {
|
9558 |
-
save()
|
9559 |
-
form.submit = realSubmit
|
9560 |
-
form.submit()
|
9561 |
-
form.submit = wrappedSubmit
|
9562 |
-
}
|
9563 |
-
} catch(e) {}
|
9564 |
-
}
|
9565 |
-
}
|
9566 |
-
|
9567 |
-
options.finishInit = function (cm) {
|
9568 |
-
cm.save = save
|
9569 |
-
cm.getTextArea = function () { return textarea; }
|
9570 |
-
cm.toTextArea = function () {
|
9571 |
-
cm.toTextArea = isNaN // Prevent this from being ran twice
|
9572 |
-
save()
|
9573 |
-
textarea.parentNode.removeChild(cm.getWrapperElement())
|
9574 |
-
textarea.style.display = ""
|
9575 |
-
if (textarea.form) {
|
9576 |
-
off(textarea.form, "submit", save)
|
9577 |
-
if (typeof textarea.form.submit == "function")
|
9578 |
-
{ textarea.form.submit = realSubmit }
|
9579 |
-
}
|
9580 |
-
}
|
9581 |
-
}
|
9582 |
-
|
9583 |
-
textarea.style.display = "none"
|
9584 |
-
var cm = CodeMirror(function (node) { return textarea.parentNode.insertBefore(node, textarea.nextSibling); },
|
9585 |
-
options)
|
9586 |
-
return cm
|
9587 |
-
}
|
9588 |
-
|
9589 |
-
function addLegacyProps(CodeMirror) {
|
9590 |
-
CodeMirror.off = off
|
9591 |
-
CodeMirror.on = on
|
9592 |
-
CodeMirror.wheelEventPixels = wheelEventPixels
|
9593 |
-
CodeMirror.Doc = Doc
|
9594 |
-
CodeMirror.splitLines = splitLinesAuto
|
9595 |
-
CodeMirror.countColumn = countColumn
|
9596 |
-
CodeMirror.findColumn = findColumn
|
9597 |
-
CodeMirror.isWordChar = isWordCharBasic
|
9598 |
-
CodeMirror.Pass = Pass
|
9599 |
-
CodeMirror.signal = signal
|
9600 |
-
CodeMirror.Line = Line
|
9601 |
-
CodeMirror.changeEnd = changeEnd
|
9602 |
-
CodeMirror.scrollbarModel = scrollbarModel
|
9603 |
-
CodeMirror.Pos = Pos
|
9604 |
-
CodeMirror.cmpPos = cmp
|
9605 |
-
CodeMirror.modes = modes
|
9606 |
-
CodeMirror.mimeModes = mimeModes
|
9607 |
-
CodeMirror.resolveMode = resolveMode
|
9608 |
-
CodeMirror.getMode = getMode
|
9609 |
-
CodeMirror.modeExtensions = modeExtensions
|
9610 |
-
CodeMirror.extendMode = extendMode
|
9611 |
-
CodeMirror.copyState = copyState
|
9612 |
-
CodeMirror.startState = startState
|
9613 |
-
CodeMirror.innerMode = innerMode
|
9614 |
-
CodeMirror.commands = commands
|
9615 |
-
CodeMirror.keyMap = keyMap
|
9616 |
-
CodeMirror.keyName = keyName
|
9617 |
-
CodeMirror.isModifierKey = isModifierKey
|
9618 |
-
CodeMirror.lookupKey = lookupKey
|
9619 |
-
CodeMirror.normalizeKeyMap = normalizeKeyMap
|
9620 |
-
CodeMirror.StringStream = StringStream
|
9621 |
-
CodeMirror.SharedTextMarker = SharedTextMarker
|
9622 |
-
CodeMirror.TextMarker = TextMarker
|
9623 |
-
CodeMirror.LineWidget = LineWidget
|
9624 |
-
CodeMirror.e_preventDefault = e_preventDefault
|
9625 |
-
CodeMirror.e_stopPropagation = e_stopPropagation
|
9626 |
-
CodeMirror.e_stop = e_stop
|
9627 |
-
CodeMirror.addClass = addClass
|
9628 |
-
CodeMirror.contains = contains
|
9629 |
-
CodeMirror.rmClass = rmClass
|
9630 |
-
CodeMirror.keyNames = keyNames
|
9631 |
-
}
|
9632 |
-
|
9633 |
-
// EDITOR CONSTRUCTOR
|
9634 |
-
|
9635 |
-
defineOptions(CodeMirror)
|
9636 |
-
|
9637 |
-
addEditorMethods(CodeMirror)
|
9638 |
-
|
9639 |
-
// Set up methods on CodeMirror's prototype to redirect to the editor's document.
|
9640 |
-
var dontDelegate = "iter insert remove copy getEditor constructor".split(" ")
|
9641 |
-
for (var prop in Doc.prototype) { if (Doc.prototype.hasOwnProperty(prop) && indexOf(dontDelegate, prop) < 0)
|
9642 |
-
{ CodeMirror.prototype[prop] = (function(method) {
|
9643 |
-
return function() {return method.apply(this.doc, arguments)}
|
9644 |
-
})(Doc.prototype[prop]) } }
|
9645 |
-
|
9646 |
-
eventMixin(Doc)
|
9647 |
-
|
9648 |
-
// INPUT HANDLING
|
9649 |
-
|
9650 |
-
CodeMirror.inputStyles = {"textarea": TextareaInput, "contenteditable": ContentEditableInput}
|
9651 |
-
|
9652 |
-
// MODE DEFINITION AND QUERYING
|
9653 |
-
|
9654 |
-
// Extra arguments are stored as the mode's dependencies, which is
|
9655 |
-
// used by (legacy) mechanisms like loadmode.js to automatically
|
9656 |
-
// load a mode. (Preferred mechanism is the require/define calls.)
|
9657 |
-
CodeMirror.defineMode = function(name/*, mode, …*/) {
|
9658 |
-
if (!CodeMirror.defaults.mode && name != "null") { CodeMirror.defaults.mode = name }
|
9659 |
-
defineMode.apply(this, arguments)
|
9660 |
-
}
|
9661 |
-
|
9662 |
-
CodeMirror.defineMIME = defineMIME
|
9663 |
-
|
9664 |
-
// Minimal default mode.
|
9665 |
-
CodeMirror.defineMode("null", function () { return ({token: function (stream) { return stream.skipToEnd(); }}); })
|
9666 |
-
CodeMirror.defineMIME("text/plain", "null")
|
9667 |
-
|
9668 |
-
// EXTENSIONS
|
9669 |
-
|
9670 |
-
CodeMirror.defineExtension = function (name, func) {
|
9671 |
-
CodeMirror.prototype[name] = func
|
9672 |
-
}
|
9673 |
-
CodeMirror.defineDocExtension = function (name, func) {
|
9674 |
-
Doc.prototype[name] = func
|
9675 |
-
}
|
9676 |
-
|
9677 |
-
CodeMirror.fromTextArea = fromTextArea
|
9678 |
-
|
9679 |
-
addLegacyProps(CodeMirror)
|
9680 |
-
|
9681 |
-
CodeMirror.version = "5.38.0"
|
9682 |
-
|
9683 |
-
return CodeMirror;
|
9684 |
-
|
1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
3 |
+
|
4 |
+
// This is CodeMirror (http://codemirror.net), a code editor
|
5 |
+
// implemented in JavaScript on top of the browser's DOM.
|
6 |
+
//
|
7 |
+
// You can find some technical background for some of the code below
|
8 |
+
// at http://marijnhaverbeke.nl/blog/#cm-internals .
|
9 |
+
|
10 |
+
(function (global, factory) {
|
11 |
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
12 |
+
typeof define === 'function' && define.amd ? define(factory) :
|
13 |
+
(global.CodeMirror = factory());
|
14 |
+
}(this, (function () { 'use strict';
|
15 |
+
|
16 |
+
// Kludges for bugs and behavior differences that can't be feature
|
17 |
+
// detected are enabled based on userAgent etc sniffing.
|
18 |
+
var userAgent = navigator.userAgent
|
19 |
+
var platform = navigator.platform
|
20 |
+
|
21 |
+
var gecko = /gecko\/\d/i.test(userAgent)
|
22 |
+
var ie_upto10 = /MSIE \d/.test(userAgent)
|
23 |
+
var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(userAgent)
|
24 |
+
var edge = /Edge\/(\d+)/.exec(userAgent)
|
25 |
+
var ie = ie_upto10 || ie_11up || edge
|
26 |
+
var ie_version = ie && (ie_upto10 ? document.documentMode || 6 : +(edge || ie_11up)[1])
|
27 |
+
var webkit = !edge && /WebKit\//.test(userAgent)
|
28 |
+
var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(userAgent)
|
29 |
+
var chrome = !edge && /Chrome\//.test(userAgent)
|
30 |
+
var presto = /Opera\//.test(userAgent)
|
31 |
+
var safari = /Apple Computer/.test(navigator.vendor)
|
32 |
+
var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(userAgent)
|
33 |
+
var phantom = /PhantomJS/.test(userAgent)
|
34 |
+
|
35 |
+
var ios = !edge && /AppleWebKit/.test(userAgent) && /Mobile\/\w+/.test(userAgent)
|
36 |
+
var android = /Android/.test(userAgent)
|
37 |
+
// This is woefully incomplete. Suggestions for alternative methods welcome.
|
38 |
+
var mobile = ios || android || /webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(userAgent)
|
39 |
+
var mac = ios || /Mac/.test(platform)
|
40 |
+
var chromeOS = /\bCrOS\b/.test(userAgent)
|
41 |
+
var windows = /win/i.test(platform)
|
42 |
+
|
43 |
+
var presto_version = presto && userAgent.match(/Version\/(\d*\.\d*)/)
|
44 |
+
if (presto_version) { presto_version = Number(presto_version[1]) }
|
45 |
+
if (presto_version && presto_version >= 15) { presto = false; webkit = true }
|
46 |
+
// Some browsers use the wrong event properties to signal cmd/ctrl on OS X
|
47 |
+
var flipCtrlCmd = mac && (qtwebkit || presto && (presto_version == null || presto_version < 12.11))
|
48 |
+
var captureRightClick = gecko || (ie && ie_version >= 9)
|
49 |
+
|
50 |
+
function classTest(cls) { return new RegExp("(^|\\s)" + cls + "(?:$|\\s)\\s*") }
|
51 |
+
|
52 |
+
var rmClass = function(node, cls) {
|
53 |
+
var current = node.className
|
54 |
+
var match = classTest(cls).exec(current)
|
55 |
+
if (match) {
|
56 |
+
var after = current.slice(match.index + match[0].length)
|
57 |
+
node.className = current.slice(0, match.index) + (after ? match[1] + after : "")
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
+
function removeChildren(e) {
|
62 |
+
for (var count = e.childNodes.length; count > 0; --count)
|
63 |
+
{ e.removeChild(e.firstChild) }
|
64 |
+
return e
|
65 |
+
}
|
66 |
+
|
67 |
+
function removeChildrenAndAdd(parent, e) {
|
68 |
+
return removeChildren(parent).appendChild(e)
|
69 |
+
}
|
70 |
+
|
71 |
+
function elt(tag, content, className, style) {
|
72 |
+
var e = document.createElement(tag)
|
73 |
+
if (className) { e.className = className }
|
74 |
+
if (style) { e.style.cssText = style }
|
75 |
+
if (typeof content == "string") { e.appendChild(document.createTextNode(content)) }
|
76 |
+
else if (content) { for (var i = 0; i < content.length; ++i) { e.appendChild(content[i]) } }
|
77 |
+
return e
|
78 |
+
}
|
79 |
+
// wrapper for elt, which removes the elt from the accessibility tree
|
80 |
+
function eltP(tag, content, className, style) {
|
81 |
+
var e = elt(tag, content, className, style)
|
82 |
+
e.setAttribute("role", "presentation")
|
83 |
+
return e
|
84 |
+
}
|
85 |
+
|
86 |
+
var range
|
87 |
+
if (document.createRange) { range = function(node, start, end, endNode) {
|
88 |
+
var r = document.createRange()
|
89 |
+
r.setEnd(endNode || node, end)
|
90 |
+
r.setStart(node, start)
|
91 |
+
return r
|
92 |
+
} }
|
93 |
+
else { range = function(node, start, end) {
|
94 |
+
var r = document.body.createTextRange()
|
95 |
+
try { r.moveToElementText(node.parentNode) }
|
96 |
+
catch(e) { return r }
|
97 |
+
r.collapse(true)
|
98 |
+
r.moveEnd("character", end)
|
99 |
+
r.moveStart("character", start)
|
100 |
+
return r
|
101 |
+
} }
|
102 |
+
|
103 |
+
function contains(parent, child) {
|
104 |
+
if (child.nodeType == 3) // Android browser always returns false when child is a textnode
|
105 |
+
{ child = child.parentNode }
|
106 |
+
if (parent.contains)
|
107 |
+
{ return parent.contains(child) }
|
108 |
+
do {
|
109 |
+
if (child.nodeType == 11) { child = child.host }
|
110 |
+
if (child == parent) { return true }
|
111 |
+
} while (child = child.parentNode)
|
112 |
+
}
|
113 |
+
|
114 |
+
function activeElt() {
|
115 |
+
// IE and Edge may throw an "Unspecified Error" when accessing document.activeElement.
|
116 |
+
// IE < 10 will throw when accessed while the page is loading or in an iframe.
|
117 |
+
// IE > 9 and Edge will throw when accessed in an iframe if document.body is unavailable.
|
118 |
+
var activeElement
|
119 |
+
try {
|
120 |
+
activeElement = document.activeElement
|
121 |
+
} catch(e) {
|
122 |
+
activeElement = document.body || null
|
123 |
+
}
|
124 |
+
while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot.activeElement)
|
125 |
+
{ activeElement = activeElement.shadowRoot.activeElement }
|
126 |
+
return activeElement
|
127 |
+
}
|
128 |
+
|
129 |
+
function addClass(node, cls) {
|
130 |
+
var current = node.className
|
131 |
+
if (!classTest(cls).test(current)) { node.className += (current ? " " : "") + cls }
|
132 |
+
}
|
133 |
+
function joinClasses(a, b) {
|
134 |
+
var as = a.split(" ")
|
135 |
+
for (var i = 0; i < as.length; i++)
|
136 |
+
{ if (as[i] && !classTest(as[i]).test(b)) { b += " " + as[i] } }
|
137 |
+
return b
|
138 |
+
}
|
139 |
+
|
140 |
+
var selectInput = function(node) { node.select() }
|
141 |
+
if (ios) // Mobile Safari apparently has a bug where select() is broken.
|
142 |
+
{ selectInput = function(node) { node.selectionStart = 0; node.selectionEnd = node.value.length } }
|
143 |
+
else if (ie) // Suppress mysterious IE10 errors
|
144 |
+
{ selectInput = function(node) { try { node.select() } catch(_e) {} } }
|
145 |
+
|
146 |
+
function bind(f) {
|
147 |
+
var args = Array.prototype.slice.call(arguments, 1)
|
148 |
+
return function(){return f.apply(null, args)}
|
149 |
+
}
|
150 |
+
|
151 |
+
function copyObj(obj, target, overwrite) {
|
152 |
+
if (!target) { target = {} }
|
153 |
+
for (var prop in obj)
|
154 |
+
{ if (obj.hasOwnProperty(prop) && (overwrite !== false || !target.hasOwnProperty(prop)))
|
155 |
+
{ target[prop] = obj[prop] } }
|
156 |
+
return target
|
157 |
+
}
|
158 |
+
|
159 |
+
// Counts the column offset in a string, taking tabs into account.
|
160 |
+
// Used mostly to find indentation.
|
161 |
+
function countColumn(string, end, tabSize, startIndex, startValue) {
|
162 |
+
if (end == null) {
|
163 |
+
end = string.search(/[^\s\u00a0]/)
|
164 |
+
if (end == -1) { end = string.length }
|
165 |
+
}
|
166 |
+
for (var i = startIndex || 0, n = startValue || 0;;) {
|
167 |
+
var nextTab = string.indexOf("\t", i)
|
168 |
+
if (nextTab < 0 || nextTab >= end)
|
169 |
+
{ return n + (end - i) }
|
170 |
+
n += nextTab - i
|
171 |
+
n += tabSize - (n % tabSize)
|
172 |
+
i = nextTab + 1
|
173 |
+
}
|
174 |
+
}
|
175 |
+
|
176 |
+
var Delayed = function() {this.id = null};
|
177 |
+
Delayed.prototype.set = function (ms, f) {
|
178 |
+
clearTimeout(this.id)
|
179 |
+
this.id = setTimeout(f, ms)
|
180 |
+
};
|
181 |
+
|
182 |
+
function indexOf(array, elt) {
|
183 |
+
for (var i = 0; i < array.length; ++i)
|
184 |
+
{ if (array[i] == elt) { return i } }
|
185 |
+
return -1
|
186 |
+
}
|
187 |
+
|
188 |
+
// Number of pixels added to scroller and sizer to hide scrollbar
|
189 |
+
var scrollerGap = 30
|
190 |
+
|
191 |
+
// Returned or thrown by various protocols to signal 'I'm not
|
192 |
+
// handling this'.
|
193 |
+
var Pass = {toString: function(){return "CodeMirror.Pass"}}
|
194 |
+
|
195 |
+
// Reused option objects for setSelection & friends
|
196 |
+
var sel_dontScroll = {scroll: false};
|
197 |
+
var sel_mouse = {origin: "*mouse"};
|
198 |
+
var sel_move = {origin: "+move"};
|
199 |
+
// The inverse of countColumn -- find the offset that corresponds to
|
200 |
+
// a particular column.
|
201 |
+
function findColumn(string, goal, tabSize) {
|
202 |
+
for (var pos = 0, col = 0;;) {
|
203 |
+
var nextTab = string.indexOf("\t", pos)
|
204 |
+
if (nextTab == -1) { nextTab = string.length }
|
205 |
+
var skipped = nextTab - pos
|
206 |
+
if (nextTab == string.length || col + skipped >= goal)
|
207 |
+
{ return pos + Math.min(skipped, goal - col) }
|
208 |
+
col += nextTab - pos
|
209 |
+
col += tabSize - (col % tabSize)
|
210 |
+
pos = nextTab + 1
|
211 |
+
if (col >= goal) { return pos }
|
212 |
+
}
|
213 |
+
}
|
214 |
+
|
215 |
+
var spaceStrs = [""]
|
216 |
+
function spaceStr(n) {
|
217 |
+
while (spaceStrs.length <= n)
|
218 |
+
{ spaceStrs.push(lst(spaceStrs) + " ") }
|
219 |
+
return spaceStrs[n]
|
220 |
+
}
|
221 |
+
|
222 |
+
function lst(arr) { return arr[arr.length-1] }
|
223 |
+
|
224 |
+
function map(array, f) {
|
225 |
+
var out = []
|
226 |
+
for (var i = 0; i < array.length; i++) { out[i] = f(array[i], i) }
|
227 |
+
return out
|
228 |
+
}
|
229 |
+
|
230 |
+
function insertSorted(array, value, score) {
|
231 |
+
var pos = 0, priority = score(value)
|
232 |
+
while (pos < array.length && score(array[pos]) <= priority) { pos++ }
|
233 |
+
array.splice(pos, 0, value)
|
234 |
+
}
|
235 |
+
|
236 |
+
function nothing() {}
|
237 |
+
|
238 |
+
function createObj(base, props) {
|
239 |
+
var inst
|
240 |
+
if (Object.create) {
|
241 |
+
inst = Object.create(base)
|
242 |
+
} else {
|
243 |
+
nothing.prototype = base
|
244 |
+
inst = new nothing()
|
245 |
+
}
|
246 |
+
if (props) { copyObj(props, inst) }
|
247 |
+
return inst
|
248 |
+
}
|
249 |
+
|
250 |
+
var nonASCIISingleCaseWordChar = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/
|
251 |
+
function isWordCharBasic(ch) {
|
252 |
+
return /\w/.test(ch) || ch > "\x80" &&
|
253 |
+
(ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch))
|
254 |
+
}
|
255 |
+
function isWordChar(ch, helper) {
|
256 |
+
if (!helper) { return isWordCharBasic(ch) }
|
257 |
+
if (helper.source.indexOf("\\w") > -1 && isWordCharBasic(ch)) { return true }
|
258 |
+
return helper.test(ch)
|
259 |
+
}
|
260 |
+
|
261 |
+
function isEmpty(obj) {
|
262 |
+
for (var n in obj) { if (obj.hasOwnProperty(n) && obj[n]) { return false } }
|
263 |
+
return true
|
264 |
+
}
|
265 |
+
|
266 |
+
// Extending unicode characters. A series of a non-extending char +
|
267 |
+
// any number of extending chars is treated as a single unit as far
|
268 |
+
// as editing and measuring is concerned. This is not fully correct,
|
269 |
+
// since some scripts/fonts/browsers also treat other configurations
|
270 |
+
// of code points as a group.
|
271 |
+
var extendingChars = /[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/
|
272 |
+
function isExtendingChar(ch) { return ch.charCodeAt(0) >= 768 && extendingChars.test(ch) }
|
273 |
+
|
274 |
+
// Returns a number from the range [`0`; `str.length`] unless `pos` is outside that range.
|
275 |
+
function skipExtendingChars(str, pos, dir) {
|
276 |
+
while ((dir < 0 ? pos > 0 : pos < str.length) && isExtendingChar(str.charAt(pos))) { pos += dir }
|
277 |
+
return pos
|
278 |
+
}
|
279 |
+
|
280 |
+
// Returns the value from the range [`from`; `to`] that satisfies
|
281 |
+
// `pred` and is closest to `from`. Assumes that at least `to`
|
282 |
+
// satisfies `pred`. Supports `from` being greater than `to`.
|
283 |
+
function findFirst(pred, from, to) {
|
284 |
+
// At any point we are certain `to` satisfies `pred`, don't know
|
285 |
+
// whether `from` does.
|
286 |
+
var dir = from > to ? -1 : 1
|
287 |
+
for (;;) {
|
288 |
+
if (from == to) { return from }
|
289 |
+
var midF = (from + to) / 2, mid = dir < 0 ? Math.ceil(midF) : Math.floor(midF)
|
290 |
+
if (mid == from) { return pred(mid) ? from : to }
|
291 |
+
if (pred(mid)) { to = mid }
|
292 |
+
else { from = mid + dir }
|
293 |
+
}
|
294 |
+
}
|
295 |
+
|
296 |
+
// The display handles the DOM integration, both for input reading
|
297 |
+
// and content drawing. It holds references to DOM nodes and
|
298 |
+
// display-related state.
|
299 |
+
|
300 |
+
function Display(place, doc, input) {
|
301 |
+
var d = this
|
302 |
+
this.input = input
|
303 |
+
|
304 |
+
// Covers bottom-right square when both scrollbars are present.
|
305 |
+
d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler")
|
306 |
+
d.scrollbarFiller.setAttribute("cm-not-content", "true")
|
307 |
+
// Covers bottom of gutter when coverGutterNextToScrollbar is on
|
308 |
+
// and h scrollbar is present.
|
309 |
+
d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler")
|
310 |
+
d.gutterFiller.setAttribute("cm-not-content", "true")
|
311 |
+
// Will contain the actual code, positioned to cover the viewport.
|
312 |
+
d.lineDiv = eltP("div", null, "CodeMirror-code")
|
313 |
+
// Elements are added to these to represent selection and cursors.
|
314 |
+
d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1")
|
315 |
+
d.cursorDiv = elt("div", null, "CodeMirror-cursors")
|
316 |
+
// A visibility: hidden element used to find the size of things.
|
317 |
+
d.measure = elt("div", null, "CodeMirror-measure")
|
318 |
+
// When lines outside of the viewport are measured, they are drawn in this.
|
319 |
+
d.lineMeasure = elt("div", null, "CodeMirror-measure")
|
320 |
+
// Wraps everything that needs to exist inside the vertically-padded coordinate system
|
321 |
+
d.lineSpace = eltP("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv],
|
322 |
+
null, "position: relative; outline: none")
|
323 |
+
var lines = eltP("div", [d.lineSpace], "CodeMirror-lines")
|
324 |
+
// Moved around its parent to cover visible view.
|
325 |
+
d.mover = elt("div", [lines], null, "position: relative")
|
326 |
+
// Set to the height of the document, allowing scrolling.
|
327 |
+
d.sizer = elt("div", [d.mover], "CodeMirror-sizer")
|
328 |
+
d.sizerWidth = null
|
329 |
+
// Behavior of elts with overflow: auto and padding is
|
330 |
+
// inconsistent across browsers. This is used to ensure the
|
331 |
+
// scrollable area is big enough.
|
332 |
+
d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerGap + "px; width: 1px;")
|
333 |
+
// Will contain the gutters, if any.
|
334 |
+
d.gutters = elt("div", null, "CodeMirror-gutters")
|
335 |
+
d.lineGutter = null
|
336 |
+
// Actual scrollable element.
|
337 |
+
d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll")
|
338 |
+
d.scroller.setAttribute("tabIndex", "-1")
|
339 |
+
// The element in which the editor lives.
|
340 |
+
d.wrapper = elt("div", [d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror")
|
341 |
+
|
342 |
+
// Work around IE7 z-index bug (not perfect, hence IE7 not really being supported)
|
343 |
+
if (ie && ie_version < 8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0 }
|
344 |
+
if (!webkit && !(gecko && mobile)) { d.scroller.draggable = true }
|
345 |
+
|
346 |
+
if (place) {
|
347 |
+
if (place.appendChild) { place.appendChild(d.wrapper) }
|
348 |
+
else { place(d.wrapper) }
|
349 |
+
}
|
350 |
+
|
351 |
+
// Current rendered range (may be bigger than the view window).
|
352 |
+
d.viewFrom = d.viewTo = doc.first
|
353 |
+
d.reportedViewFrom = d.reportedViewTo = doc.first
|
354 |
+
// Information about the rendered lines.
|
355 |
+
d.view = []
|
356 |
+
d.renderedView = null
|
357 |
+
// Holds info about a single rendered line when it was rendered
|
358 |
+
// for measurement, while not in view.
|
359 |
+
d.externalMeasured = null
|
360 |
+
// Empty space (in pixels) above the view
|
361 |
+
d.viewOffset = 0
|
362 |
+
d.lastWrapHeight = d.lastWrapWidth = 0
|
363 |
+
d.updateLineNumbers = null
|
364 |
+
|
365 |
+
d.nativeBarWidth = d.barHeight = d.barWidth = 0
|
366 |
+
d.scrollbarsClipped = false
|
367 |
+
|
368 |
+
// Used to only resize the line number gutter when necessary (when
|
369 |
+
// the amount of lines crosses a boundary that makes its width change)
|
370 |
+
d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null
|
371 |
+
// Set to true when a non-horizontal-scrolling line widget is
|
372 |
+
// added. As an optimization, line widget aligning is skipped when
|
373 |
+
// this is false.
|
374 |
+
d.alignWidgets = false
|
375 |
+
|
376 |
+
d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null
|
377 |
+
|
378 |
+
// Tracks the maximum line length so that the horizontal scrollbar
|
379 |
+
// can be kept static when scrolling.
|
380 |
+
d.maxLine = null
|
381 |
+
d.maxLineLength = 0
|
382 |
+
d.maxLineChanged = false
|
383 |
+
|
384 |
+
// Used for measuring wheel scrolling granularity
|
385 |
+
d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null
|
386 |
+
|
387 |
+
// True when shift is held down.
|
388 |
+
d.shift = false
|
389 |
+
|
390 |
+
// Used to track whether anything happened since the context menu
|
391 |
+
// was opened.
|
392 |
+
d.selForContextMenu = null
|
393 |
+
|
394 |
+
d.activeTouch = null
|
395 |
+
|
396 |
+
input.init(d)
|
397 |
+
}
|
398 |
+
|
399 |
+
// Find the line object corresponding to the given line number.
|
400 |
+
function getLine(doc, n) {
|
401 |
+
n -= doc.first
|
402 |
+
if (n < 0 || n >= doc.size) { throw new Error("There is no line " + (n + doc.first) + " in the document.") }
|
403 |
+
var chunk = doc
|
404 |
+
while (!chunk.lines) {
|
405 |
+
for (var i = 0;; ++i) {
|
406 |
+
var child = chunk.children[i], sz = child.chunkSize()
|
407 |
+
if (n < sz) { chunk = child; break }
|
408 |
+
n -= sz
|
409 |
+
}
|
410 |
+
}
|
411 |
+
return chunk.lines[n]
|
412 |
+
}
|
413 |
+
|
414 |
+
// Get the part of a document between two positions, as an array of
|
415 |
+
// strings.
|
416 |
+
function getBetween(doc, start, end) {
|
417 |
+
var out = [], n = start.line
|
418 |
+
doc.iter(start.line, end.line + 1, function (line) {
|
419 |
+
var text = line.text
|
420 |
+
if (n == end.line) { text = text.slice(0, end.ch) }
|
421 |
+
if (n == start.line) { text = text.slice(start.ch) }
|
422 |
+
out.push(text)
|
423 |
+
++n
|
424 |
+
})
|
425 |
+
return out
|
426 |
+
}
|
427 |
+
// Get the lines between from and to, as array of strings.
|
428 |
+
function getLines(doc, from, to) {
|
429 |
+
var out = []
|
430 |
+
doc.iter(from, to, function (line) { out.push(line.text) }) // iter aborts when callback returns truthy value
|
431 |
+
return out
|
432 |
+
}
|
433 |
+
|
434 |
+
// Update the height of a line, propagating the height change
|
435 |
+
// upwards to parent nodes.
|
436 |
+
function updateLineHeight(line, height) {
|
437 |
+
var diff = height - line.height
|
438 |
+
if (diff) { for (var n = line; n; n = n.parent) { n.height += diff } }
|
439 |
+
}
|
440 |
+
|
441 |
+
// Given a line object, find its line number by walking up through
|
442 |
+
// its parent links.
|
443 |
+
function lineNo(line) {
|
444 |
+
if (line.parent == null) { return null }
|
445 |
+
var cur = line.parent, no = indexOf(cur.lines, line)
|
446 |
+
for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
|
447 |
+
for (var i = 0;; ++i) {
|
448 |
+
if (chunk.children[i] == cur) { break }
|
449 |
+
no += chunk.children[i].chunkSize()
|
450 |
+
}
|
451 |
+
}
|
452 |
+
return no + cur.first
|
453 |
+
}
|
454 |
+
|
455 |
+
// Find the line at the given vertical position, using the height
|
456 |
+
// information in the document tree.
|
457 |
+
function lineAtHeight(chunk, h) {
|
458 |
+
var n = chunk.first
|
459 |
+
outer: do {
|
460 |
+
for (var i$1 = 0; i$1 < chunk.children.length; ++i$1) {
|
461 |
+
var child = chunk.children[i$1], ch = child.height
|
462 |
+
if (h < ch) { chunk = child; continue outer }
|
463 |
+
h -= ch
|
464 |
+
n += child.chunkSize()
|
465 |
+
}
|
466 |
+
return n
|
467 |
+
} while (!chunk.lines)
|
468 |
+
var i = 0
|
469 |
+
for (; i < chunk.lines.length; ++i) {
|
470 |
+
var line = chunk.lines[i], lh = line.height
|
471 |
+
if (h < lh) { break }
|
472 |
+
h -= lh
|
473 |
+
}
|
474 |
+
return n + i
|
475 |
+
}
|
476 |
+
|
477 |
+
function isLine(doc, l) {return l >= doc.first && l < doc.first + doc.size}
|
478 |
+
|
479 |
+
function lineNumberFor(options, i) {
|
480 |
+
return String(options.lineNumberFormatter(i + options.firstLineNumber))
|
481 |
+
}
|
482 |
+
|
483 |
+
// A Pos instance represents a position within the text.
|
484 |
+
function Pos(line, ch, sticky) {
|
485 |
+
if ( sticky === void 0 ) sticky = null;
|
486 |
+
|
487 |
+
if (!(this instanceof Pos)) { return new Pos(line, ch, sticky) }
|
488 |
+
this.line = line
|
489 |
+
this.ch = ch
|
490 |
+
this.sticky = sticky
|
491 |
+
}
|
492 |
+
|
493 |
+
// Compare two positions, return 0 if they are the same, a negative
|
494 |
+
// number when a is less, and a positive number otherwise.
|
495 |
+
function cmp(a, b) { return a.line - b.line || a.ch - b.ch }
|
496 |
+
|
497 |
+
function equalCursorPos(a, b) { return a.sticky == b.sticky && cmp(a, b) == 0 }
|
498 |
+
|
499 |
+
function copyPos(x) {return Pos(x.line, x.ch)}
|
500 |
+
function maxPos(a, b) { return cmp(a, b) < 0 ? b : a }
|
501 |
+
function minPos(a, b) { return cmp(a, b) < 0 ? a : b }
|
502 |
+
|
503 |
+
// Most of the external API clips given positions to make sure they
|
504 |
+
// actually exist within the document.
|
505 |
+
function clipLine(doc, n) {return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1))}
|
506 |
+
function clipPos(doc, pos) {
|
507 |
+
if (pos.line < doc.first) { return Pos(doc.first, 0) }
|
508 |
+
var last = doc.first + doc.size - 1
|
509 |
+
if (pos.line > last) { return Pos(last, getLine(doc, last).text.length) }
|
510 |
+
return clipToLen(pos, getLine(doc, pos.line).text.length)
|
511 |
+
}
|
512 |
+
function clipToLen(pos, linelen) {
|
513 |
+
var ch = pos.ch
|
514 |
+
if (ch == null || ch > linelen) { return Pos(pos.line, linelen) }
|
515 |
+
else if (ch < 0) { return Pos(pos.line, 0) }
|
516 |
+
else { return pos }
|
517 |
+
}
|
518 |
+
function clipPosArray(doc, array) {
|
519 |
+
var out = []
|
520 |
+
for (var i = 0; i < array.length; i++) { out[i] = clipPos(doc, array[i]) }
|
521 |
+
return out
|
522 |
+
}
|
523 |
+
|
524 |
+
// Optimize some code when these features are not used.
|
525 |
+
var sawReadOnlySpans = false;
|
526 |
+
var sawCollapsedSpans = false;
|
527 |
+
function seeReadOnlySpans() {
|
528 |
+
sawReadOnlySpans = true
|
529 |
+
}
|
530 |
+
|
531 |
+
function seeCollapsedSpans() {
|
532 |
+
sawCollapsedSpans = true
|
533 |
+
}
|
534 |
+
|
535 |
+
// TEXTMARKER SPANS
|
536 |
+
|
537 |
+
function MarkedSpan(marker, from, to) {
|
538 |
+
this.marker = marker
|
539 |
+
this.from = from; this.to = to
|
540 |
+
}
|
541 |
+
|
542 |
+
// Search an array of spans for a span matching the given marker.
|
543 |
+
function getMarkedSpanFor(spans, marker) {
|
544 |
+
if (spans) { for (var i = 0; i < spans.length; ++i) {
|
545 |
+
var span = spans[i]
|
546 |
+
if (span.marker == marker) { return span }
|
547 |
+
} }
|
548 |
+
}
|
549 |
+
// Remove a span from an array, returning undefined if no spans are
|
550 |
+
// left (we don't store arrays for lines without spans).
|
551 |
+
function removeMarkedSpan(spans, span) {
|
552 |
+
var r
|
553 |
+
for (var i = 0; i < spans.length; ++i)
|
554 |
+
{ if (spans[i] != span) { (r || (r = [])).push(spans[i]) } }
|
555 |
+
return r
|
556 |
+
}
|
557 |
+
// Add a span to a line.
|
558 |
+
function addMarkedSpan(line, span) {
|
559 |
+
line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span]
|
560 |
+
span.marker.attachLine(line)
|
561 |
+
}
|
562 |
+
|
563 |
+
// Used for the algorithm that adjusts markers for a change in the
|
564 |
+
// document. These functions cut an array of spans at a given
|
565 |
+
// character position, returning an array of remaining chunks (or
|
566 |
+
// undefined if nothing remains).
|
567 |
+
function markedSpansBefore(old, startCh, isInsert) {
|
568 |
+
var nw
|
569 |
+
if (old) { for (var i = 0; i < old.length; ++i) {
|
570 |
+
var span = old[i], marker = span.marker
|
571 |
+
var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh)
|
572 |
+
if (startsBefore || span.from == startCh && marker.type == "bookmark" && (!isInsert || !span.marker.insertLeft)) {
|
573 |
+
var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh)
|
574 |
+
;(nw || (nw = [])).push(new MarkedSpan(marker, span.from, endsAfter ? null : span.to))
|
575 |
+
}
|
576 |
+
} }
|
577 |
+
return nw
|
578 |
+
}
|
579 |
+
function markedSpansAfter(old, endCh, isInsert) {
|
580 |
+
var nw
|
581 |
+
if (old) { for (var i = 0; i < old.length; ++i) {
|
582 |
+
var span = old[i], marker = span.marker
|
583 |
+
var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh)
|
584 |
+
if (endsAfter || span.from == endCh && marker.type == "bookmark" && (!isInsert || span.marker.insertLeft)) {
|
585 |
+
var startsBefore = span.from == null || (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|