1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Grab an option from our settings |
5
|
|
|
* |
6
|
|
|
* If we're on multsite we'll grab the site option which is stored in the main blogs site option tables, otherwise |
7
|
|
|
* we'll grab the option which is stored on the single blogs option tables |
8
|
|
|
* |
9
|
|
|
* @param unknown $option string name of the option |
10
|
|
|
* @param unknown $section string name of the section |
11
|
|
|
* @param unknown $default string/int default option value |
12
|
|
|
* @return the option value |
13
|
|
|
* @since 1.0 |
14
|
|
|
*/ |
15
|
|
|
if( !function_exists('lasso_editor_get_option')): |
16
|
|
|
function lasso_editor_get_option( $option, $section, $default = '' ) { |
17
|
|
|
|
18
|
|
|
if ( empty( $option ) ) |
19
|
|
|
return; |
20
|
|
|
|
21
|
|
|
if ( function_exists( 'is_multisite' ) && is_multisite() ) { |
22
|
|
|
|
23
|
|
|
$options = get_site_option( $section ); |
24
|
|
|
|
25
|
|
|
} else { |
26
|
|
|
|
27
|
|
|
$options = get_option( $section ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
$options = apply_filters( 'editus_filter_options', $options ); |
31
|
|
|
|
32
|
|
|
if ( isset( $options[$option] ) ) { |
33
|
|
|
return $options[$option]; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
return $default; |
37
|
|
|
} |
38
|
|
|
endif; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Check to see if any Aesop galleries exist |
42
|
|
|
* |
43
|
|
|
* @since 1.0 |
44
|
|
|
*/ |
45
|
|
|
function lasso_editor_galleries_exist() { |
46
|
|
|
|
47
|
|
|
$q = new wp_query( array( 'post_type' => 'ai_galleries', 'post_status' => 'publish' ) ); |
48
|
|
|
|
49
|
|
|
if ( $q->have_posts() ) |
50
|
|
|
return true; |
51
|
|
|
else |
52
|
|
|
return false; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Return a CSS class of an automatically supported theme |
57
|
|
|
* |
58
|
|
|
* @since 0.8.6 |
59
|
|
|
* @return a css class if the theme is supported, false if nothing |
60
|
|
|
*/ |
61
|
|
|
function lasso_get_supported_theme_class() { |
62
|
|
|
|
63
|
|
|
$name = wp_get_theme()->get('Name'); |
64
|
|
|
$slug = lasso_clean_string( $name ); |
65
|
|
|
|
66
|
|
|
switch ( $slug ) { |
67
|
|
|
case 'aesop-story-theme': // aesop |
68
|
|
|
$out = '.aesop-entry-content'; |
69
|
|
|
break; |
70
|
|
|
case 'jorgen': // aesop |
71
|
|
|
$out = '.jorgen-entry-content'; |
72
|
|
|
break; |
73
|
|
|
case 'novella': // aesop |
74
|
|
|
$out = '.novella-entry-content'; |
75
|
|
|
break; |
76
|
|
|
case 'genji': // aesop |
77
|
|
|
$out = '.genji-entry-content'; |
78
|
|
|
break; |
79
|
|
|
case 'kerouac': // aesop |
80
|
|
|
$out = '.kerouac-entry-content'; |
81
|
|
|
break; |
82
|
|
|
case 'zealot': // aesop |
83
|
|
|
$out = '.zealot-entry-content'; |
84
|
|
|
break; |
85
|
|
|
case 'fable': // aesop |
86
|
|
|
$out = '.fable--entry-content'; |
87
|
|
|
break; |
88
|
|
|
case 'canvas': // wootheme..err...Automattic |
89
|
|
|
$out = '.entry'; |
90
|
|
|
break; |
91
|
|
|
case 'kleo': // |
92
|
|
|
$out = '.article-content'; |
93
|
|
|
break; |
94
|
|
|
//case 'exposure': // |
95
|
|
|
// $out = '.entry-content'; |
96
|
|
|
// break; |
97
|
|
|
//case 'lore': // |
98
|
|
|
// $out = '.entry-content'; |
99
|
|
|
// break; |
100
|
|
|
//case 'worldview': // upthemes |
101
|
|
|
// $out = '.entry-content'; |
102
|
|
|
// break; |
103
|
|
|
//case 'genesis': // genesis |
104
|
|
|
// $out = '.entry-content'; |
105
|
|
|
// break; |
106
|
|
|
//case 'camera': // array.is |
107
|
|
|
// $out = '.entry-content'; |
108
|
|
|
// break; |
109
|
|
|
case 'longform': |
110
|
|
|
$out = '.entry-content-wrapper'; |
111
|
|
|
break; |
112
|
|
|
|
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return apply_filters('lasso_content_class', !empty( $out ) ? $out : false); |
116
|
|
|
//return !empty( $out ) ? $out : false; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
function lasso_get_supported_theme_title_class() { |
120
|
|
|
|
121
|
|
|
$name = wp_get_theme()->get('Name'); |
122
|
|
|
$slug = lasso_clean_string( $name ); |
123
|
|
|
|
124
|
|
|
switch ( $slug ) { |
125
|
|
|
|
126
|
|
|
case 'aesop-story-theme': // aesop |
127
|
|
|
$out = '.aesop-entry-title'; |
128
|
|
|
break; |
129
|
|
|
case 'jorgen': // aesop |
130
|
|
|
$out = '.jorgen-entry-title'; |
131
|
|
|
break; |
132
|
|
|
case 'genji': // aesop |
133
|
|
|
$out = '.genji-entry-title'; |
134
|
|
|
break; |
135
|
|
|
case 'kerouac': // aesop |
136
|
|
|
$out = '.kerouac-entry-title'; |
137
|
|
|
break; |
138
|
|
|
case 'zealot': // aesop |
139
|
|
|
$out = '.zealot-entry-title'; |
140
|
|
|
break; |
141
|
|
|
case 'fable': // aesop |
142
|
|
|
$out = '.fable--entry-title'; |
143
|
|
|
break; |
144
|
|
|
case 'kleo': // |
145
|
|
|
$out = '.page-title'; |
146
|
|
|
break; |
147
|
|
|
case 'longform': // |
148
|
|
|
$out = '.entry-title'; |
149
|
|
|
break; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
return apply_filters('lasso_title_class', !empty( $out ) ? $out : false); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
//since 0.9.9.6 |
156
|
|
|
function lasso_get_supported_theme_featured_image_class() { |
157
|
|
|
|
158
|
|
|
$name = wp_get_theme()->get('Name'); |
159
|
|
|
$slug = lasso_clean_string( $name ); |
|
|
|
|
160
|
|
|
|
161
|
|
|
return apply_filters('lasso_featured_image_class', !empty( $out ) ? $out : false); |
|
|
|
|
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Return a string of classes with items that Editus will remove when entering the editor |
167
|
|
|
* so that we don't save them as HTML |
168
|
|
|
* |
169
|
|
|
* @since 0.8.7 |
170
|
|
|
* @return string of comma separated classes |
171
|
|
|
*/ |
172
|
|
|
function lasso_supported_no_save(){ |
173
|
|
|
|
174
|
|
|
return apply_filters('lasso_dont_save', '.lasso--ignore,.sharedaddy,.us_wrapper,.meta,.edit-link,.ssba,.addtoany_share_save_container,.mashsb-container,.heateor_sss_sharing_container,.nc_socialPanel,.jp-relatedposts,.fb-comments,.adsbygoogle,.swp_social_panel'); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Generic sanitization, useful for sanitization of arrays. |
179
|
|
|
* |
180
|
|
|
* @since 0.9.2 |
181
|
|
|
* |
182
|
|
|
* @param array|object|string $data Data to sanatize. |
183
|
|
|
* |
184
|
|
|
* @return array|mixed|object|string|void |
185
|
|
|
*/ |
186
|
|
|
function lasso_sanitize_data( $data ) { |
187
|
|
|
return \lasso\sanatize::do_sanitize( $data ); |
188
|
|
|
|
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Return a comma delimited list of categories for a specific post object |
193
|
|
|
* |
194
|
|
|
* @since 0.9.3 |
195
|
|
|
* @return string of comma delimited category slugs |
196
|
|
|
*/ |
197
|
|
|
function lasso_get_post_objects( $postid = '', $taxonomy = 'category') { |
198
|
|
|
|
199
|
|
|
if ( empty( $postid ) ) |
200
|
|
|
$postid = get_the_ID(); |
201
|
|
|
|
202
|
|
|
$objects = 'category' == $taxonomy ? get_the_category( $postid ) : get_the_tags( $postid ); |
203
|
|
|
|
204
|
|
|
if ( empty( $objects) ) |
205
|
|
|
return; |
206
|
|
|
|
207
|
|
|
$out = ''; |
208
|
|
|
foreach( $objects as $object ) { |
209
|
|
|
//$out .= $object->slug.', '; |
210
|
|
|
$out .= $object->name.','; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
return rtrim($out, ', '); |
214
|
|
|
|
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Return an array of categories for autocomplete |
219
|
|
|
* |
220
|
|
|
* @since 0.9.3 |
221
|
|
|
* @return array all categoiries |
222
|
|
|
*/ |
223
|
|
|
function lasso_get_objects( $taxonomy = 'category' ) { |
224
|
|
|
|
225
|
|
|
$objects = 'category' == $taxonomy ? get_categories(array('hide_empty' => 0)) : get_tags(array('hide_empty' => 0)); |
226
|
|
|
|
227
|
|
|
if ( empty( $objects) ) |
228
|
|
|
return; |
229
|
|
|
|
230
|
|
|
$out = ""; |
231
|
|
|
foreach( $objects as $object ) { |
232
|
|
|
$out .= $object->name.','; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
return $out; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Get allowed post types for the post chooser modal. |
241
|
|
|
* |
242
|
|
|
* |
243
|
|
|
* @since 0.9.4 |
244
|
|
|
*/ |
245
|
|
|
function lasso_post_types_names() { |
246
|
|
|
$post_types = get_post_types( array( |
247
|
|
|
'public' => true, |
248
|
|
|
), 'objects' ); |
249
|
|
|
$post_types = array_combine( array_keys( $post_types ), wp_list_pluck( $post_types, 'label' ) ); |
250
|
|
|
unset( $post_types[ 'attachment' ] ); |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Set which post types are allowed |
254
|
|
|
* |
255
|
|
|
* @since 0.9.4 |
256
|
|
|
* |
257
|
|
|
* @param array $allowed_post_types Array of names (not labels) of allowed post types. Must be registered. |
258
|
|
|
*/ |
259
|
|
|
$allowed_post_types = lasso_editor_get_option( 'allowed_post_types', 'lasso_editor', array( 'post', 'page') ); |
|
|
|
|
260
|
|
|
$allowed_post_types = apply_filters( 'lasso_allowed_post_types', $allowed_post_types ); |
261
|
|
|
if (!current_user_can('edit_pages')) { |
262
|
|
|
$allowed_post_types = array_diff($allowed_post_types,array('page')); |
263
|
|
|
} |
264
|
|
|
foreach( $post_types as $name => $label ) { |
265
|
|
|
if ( ! in_array( $name, $allowed_post_types ) ) { |
266
|
|
|
unset( $post_types[ $name ] ); |
267
|
|
|
} |
268
|
|
|
} |
269
|
|
|
return $post_types; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
|
273
|
|
|
function lasso_post_types() { |
274
|
|
|
$post_types = get_post_types( array( |
275
|
|
|
'public' => true, |
276
|
|
|
), 'names' ); |
277
|
|
|
unset( $post_types[ 'attachment' ] ); |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* Set which post types are allowed |
281
|
|
|
* |
282
|
|
|
* @since 0.9.4 |
283
|
|
|
* |
284
|
|
|
* @param array $allowed_post_types Array of names (not labels) of allowed post types. Must be registered. |
285
|
|
|
*/ |
286
|
|
|
$allowed_post_types = lasso_editor_get_option( 'allowed_post_types', 'lasso_editor', array( 'post') ); |
|
|
|
|
287
|
|
|
$allowed_post_types = apply_filters( 'lasso_allowed_post_types', $allowed_post_types ); |
288
|
|
|
foreach( $post_types as $name => $label ) { |
289
|
|
|
if ( ! in_array( $name, $allowed_post_types ) ) { |
290
|
|
|
unset( $post_types[ $name ] ); |
291
|
|
|
} |
292
|
|
|
} |
293
|
|
|
return $post_types; |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
function lasso_post_types_rest_base() { |
297
|
|
|
global $wp_post_types; |
298
|
|
|
$post_types = lasso_post_types(); |
299
|
|
|
$rest_base = array(); |
300
|
|
|
foreach ( $post_types as $post_type) { |
301
|
|
|
$rest_base[$post_type] = $wp_post_types[$post_type]->rest_base; |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
return $rest_base; |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
//////////////////// |
308
|
|
|
// INTERNAL |
309
|
|
|
//////////////////// |
310
|
|
|
/** |
311
|
|
|
* Used internally as a callback to build a tab or content area for modal addons |
312
|
|
|
* |
313
|
|
|
* @param $tab object |
314
|
|
|
* @param $type string tab or content |
315
|
|
|
* @uses lasso_modal_addons() |
316
|
|
|
* @since 0.9.4 |
317
|
|
|
*/ |
318
|
|
|
function lasso_modal_addons_content( $tab = '', $type ){ |
319
|
|
|
|
320
|
|
|
$name = lasso_clean_string( $tab['name'] ); |
321
|
|
|
|
322
|
|
|
if ( 'tab' == $type ) { |
323
|
|
|
|
324
|
|
|
$out = sprintf( '<li data-addon-name="%s">%s</li>', $name, $tab['name'] ); |
325
|
|
|
|
326
|
|
|
} else if ( 'content' == $type ){ |
327
|
|
|
|
328
|
|
|
$content = isset( $tab['content'] ) && is_callable( $tab['content'] ) ? call_user_func( $tab['content'] ) : false; |
329
|
|
|
$options = isset( $tab['options'] ) && is_callable( $tab['options'] ) ? call_user_func( $tab['options'] ) : false; |
330
|
|
|
|
331
|
|
|
$out = sprintf( '<div class="lasso--modal__content not-visible" data-addon-content="%s"> |
332
|
|
|
%s%s |
333
|
|
|
</div>', $name, $content, lasso_option_form( $name, $options ) ); |
334
|
|
|
|
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
return $out; |
|
|
|
|
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* Helper function to clean a string and replace spaces with dash |
342
|
|
|
* |
343
|
|
|
* @param $string string content |
344
|
|
|
* @since 0.9.4 |
345
|
|
|
* |
346
|
|
|
* @return void|string |
347
|
|
|
*/ |
348
|
|
|
function lasso_clean_string( $string = '' ) { |
349
|
|
|
|
350
|
|
|
if ( empty( $string ) ) |
351
|
|
|
return; |
352
|
|
|
|
353
|
|
|
return sanitize_text_field( strtolower( preg_replace('/[\s_]/', '-', $string ) ) ); |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* Helper function to switch - to _ after having. |
358
|
|
|
* |
359
|
|
|
* This is the evil twin of lasso_clean_string() and may or may not make your data forever unclean. |
360
|
|
|
* |
361
|
|
|
* @param $string string content |
362
|
|
|
* @since 0.9.5 |
363
|
|
|
* |
364
|
|
|
* @return void|string |
365
|
|
|
*/ |
366
|
|
|
function lasso_unclean_string( $string = '' ) { |
367
|
|
|
|
368
|
|
|
if ( empty( $string ) ) { |
369
|
|
|
return; |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
return sanitize_text_field( strtolower( str_replace( '-', '_', $string ) ) ); |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
|
376
|
|
|
//////////////////// |
377
|
|
|
// PLUGGABLE |
378
|
|
|
//////////////////// |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* Check if the user is logged in and has the correctly passed capability |
382
|
|
|
* |
383
|
|
|
* @param unknown $action string a capability such as edit_posts or publish_posts |
384
|
|
|
* @param unknown $postid int the id of the post object to check against |
385
|
|
|
* @since 0.9.9.7 added filter 'lasso_user_can_filter' |
386
|
|
|
*/ |
387
|
|
|
if ( !function_exists( 'lasso_user_can' ) ): |
388
|
|
|
function lasso_user_can( $action = '', $postid = 0 ) { |
389
|
|
|
$result = false; |
390
|
|
|
if ( empty( $action ) ) |
391
|
|
|
$action = 'edit_posts'; |
392
|
|
|
|
393
|
|
|
if ( empty( $postid ) && $action != 'edit_posts' && $action != 'publish_posts' && $action != 'delete_posts') |
394
|
|
|
$postid = get_the_ID(); |
395
|
|
|
|
396
|
|
|
if ( is_user_logged_in() && current_user_can( $action, $postid ) ) { |
397
|
|
|
// check against post types: |
398
|
|
|
$allowed_post_types = lasso_editor_get_option( 'allowed_post_types', 'lasso_editor', array( 'post', 'page') ); |
|
|
|
|
399
|
|
|
|
400
|
|
|
if (!current_user_can('edit_pages')) { |
401
|
|
|
$allowed_post_types = array_diff($allowed_post_types,array('page')); |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
if (!empty($allowed_post_types) && !empty($postid)) { |
405
|
|
|
$type = get_post_type( $postid ); |
406
|
|
|
$allowed_post_types = apply_filters( 'lasso_allowed_post_types', $allowed_post_types ); |
407
|
|
|
|
408
|
|
|
if ( in_array( $type, $allowed_post_types ) ) { |
409
|
|
|
$result = true; |
410
|
|
|
} |
411
|
|
|
} else { |
412
|
|
|
//we are not checking against a post, return true |
413
|
|
|
$result = true; |
414
|
|
|
} |
415
|
|
|
} else { |
416
|
|
|
$result = false; |
417
|
|
|
} |
418
|
|
|
//if ( function_exists( 'is_gutenberg_page' ) && has_blocks() ) return false; |
419
|
|
|
|
420
|
|
|
return apply_filters( 'lasso_user_can_filter', $result, $action, $postid); |
421
|
|
|
} |
422
|
|
|
endif; |
423
|
|
|
|
424
|
|
|
/** |
425
|
|
|
* Empty state message thats shown when no data available |
426
|
|
|
* |
427
|
|
|
* @since 0.9.5 |
428
|
|
|
*/ |
429
|
|
|
if ( !function_exists('lasso_editor_empty_results') ): |
430
|
|
|
|
431
|
|
|
function lasso_editor_empty_results( $type = 'posts' ){ |
432
|
|
|
|
433
|
|
|
if ( 'posts' == $type ) { |
434
|
|
|
|
435
|
|
|
$string = apply_filters('lasso_empty_state_message', __('No posts to show', 'lasso') ); |
436
|
|
|
$icon = 'lasso-icon-file-text2'; |
437
|
|
|
$button = false; |
438
|
|
|
|
439
|
|
|
} elseif ( 'revision' == $type ) { |
440
|
|
|
|
441
|
|
|
$string = apply_filters('lasso_empty_state_message', __('No revisions found', 'lasso') ); |
442
|
|
|
$icon = 'lasso-icon-history'; |
443
|
|
|
$button = sprintf('<a href="#" class="lasso--btn-secondary" id="lasso--close-modal">%s</a>', __('Close','lasso') ); |
444
|
|
|
|
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
return sprintf('<div id="lasso--empty-state" class="lasso--empty-state"><i class="lasso--empty-state-icon lasso-icon %s"></i><p>%s</p>%s</div>', $icon, $string, $button ); |
|
|
|
|
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
endif; |
451
|
|
|
|
452
|
|
|
|
453
|
|
|
|
454
|
|
|
|
455
|
|
|
|
456
|
|
|
|
457
|
|
|
|
458
|
|
|
|
459
|
|
|
|
460
|
|
|
|
461
|
|
|
|
462
|
|
|
|
463
|
|
|
|
464
|
|
|
|
465
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.