Completed
Push — master ( 07f885...3f46f1 )
by
unknown
02:28
created

editor-modules.php ➔ lasso_editor_text_toolbar()   F

Complexity

Conditions 11
Paths 385

Size

Total Lines 94
Code Lines 64

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 64
nc 385
nop 0
dl 0
loc 94
rs 3.8181
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 16 and the first side effect is on line 15.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/**
4
 * These functions are then localized and then appended with JS in enter-editor.js
5
 *  All are protectd under a capability and logged in check using a filterable function lasso_user_can()
6
 *
7
 * @since 1.0
8
 */
9
10
/**
11
 * Add the editor controls to any singular post object
12
 *
13
 * @since 1.0
14
 */
15
add_action( 'wp_footer', 'lasso_editor_controls' );
16
function lasso_editor_controls() {
17
18
	global $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
19
20
	if ( lasso_user_can('edit_posts') ) {
21
22
		$status = get_post_status( get_the_ID() );
23
24
		// let users add custom css classes
25
		$custom_classes = apply_filters( 'lasso_control_classes', '' );
26
27
		$post_access_class   = '';
28
		$post_new_disabled   = lasso_editor_get_option( 'post_adding_disabled', 'lasso_editor' );
0 ignored issues
show
Documentation introduced by
'post_adding_disabled' is of type string, but the function expects a object<unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'lasso_editor' is of type string, but the function expects a object<unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
29
		$post_settings_disabled = lasso_editor_get_option( 'post_settings_disabled', 'lasso_editor' );
0 ignored issues
show
Documentation introduced by
'post_settings_disabled' is of type string, but the function expects a object<unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'lasso_editor' is of type string, but the function expects a object<unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
30
		$shortcodify_disabled = lasso_editor_get_option( 'shortcodify_disabled', 'lasso_editor' );
0 ignored issues
show
Documentation introduced by
'shortcodify_disabled' is of type string, but the function expects a object<unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'lasso_editor' is of type string, but the function expects a object<unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
31
32
33
		// CSS class if adding new post objects is disabled
34
		if ( 'on' == $post_new_disabled ) { $post_access_class = 'lasso--post-new-disabled'; }
35
36
		// CSS class if adjust settings is disabled
37
		if ( 'on' == $post_settings_disabled ) { $post_access_class = 'lasso--post-settings-disabled'; }
38
39
		// CSS class if adding new post objects AND settings are disabled
40
		if ( 'on' == $post_new_disabled && 'on' == $post_settings_disabled ) { $post_access_class = 'lasso--post-all-disabled'; }
41
42
		// CSS class if shortcodify or (Aesop Shortcode Conversion) is disabled
43
		$sc_saving_class = 'on' == $shortcodify_disabled ? 'shortcodify-disabled' : 'shortcodify-enabled';
44
45
		// user is capable
46
		$is_capable = is_singular() && lasso_user_can('edit_post');
47
		
48
		$mobile_style = wp_is_mobile() ? 'style="top:40px;"' : null;
49
50
		?><div id="lasso--controls" class="lasso-post-status--<?php echo sanitize_html_class( $status );?> <?php echo sanitize_html_class( $custom_classes );?>" data-post-id="<?php echo get_the_ID();?>" >
51
52
			<ul class="lasso--controls__center lasso-editor-controls lasso-editor-controls--wrap <?php echo $post_access_class;?> "  <?php echo $mobile_style ?> >
53
54
				<?php do_action( 'lasso_editor_controls_before' );
55
56
				if ( $is_capable ) { ?>
57
58
					<li id="lasso--edit" title="<?php esc_attr_e( 'Edit Post', 'lasso' );?>"><a href="#" class="lasso--button__primary"></a></li>
59
60
					<?php if ( 'off' == $post_settings_disabled || empty( $post_settings_disabled ) ) { ?>
61
						<li id="lasso--post-settings" title="<?php esc_attr_e( 'Post Settings', 'lasso' );?>"><a href="#" class="lasso--button__primary"></a></li>
62
					<?php }
63
64
				} ?>
65
66
				<li id="lasso--post-all" title="<?php esc_attr_e( 'All Posts', 'lasso' );?>"><a href="#" class="lasso--button__primary"></a></li>
67
68
				<?php if ( $is_capable && wp_revisions_enabled( $post ) ) { ?>
69
					<li id="lasso--post-revisions" title="<?php esc_attr_e( 'Revisions', 'lasso' );?>"><a href="#" class="lasso--button__primary"></a></li>
70
				<?php } ?>
71
72
				<?php if ( ( 'off' == $post_new_disabled || empty( $post_new_disabled ) && lasso_user_can('publish_posts') ) ) { ?>
73
					<li id="lasso--post-new" title="<?php esc_attr_e( 'Add Post', 'lasso' );?>"><a href="#" class="lasso--button__primary"></a></li>
74
				<?php } ?>
75
76
				<?php do_action( 'lasso_editor_controls_after' );?>
77
78
			</ul>
79
80
			<?php if ( is_singular() ) { ?>
81
82
				<div class="lasso--controls__right">
83
84
					<a href="#" title="<?php esc_attr_e( 'Save Post', 'lasso' );?>" id="lasso--save" class="lasso-save-post lasso--button <?php echo $sc_saving_class;?>"></a>
85
86
					<?php if ( 'draft' == $status && ( lasso_user_can('publish_posts') || lasso_user_can('publish_pages') )  ) { ?>
87
						<a href="#" title="<?php esc_attr_e( 'Publish Post', 'lasso' );?>" id="lasso--publish" class="lasso-publish-post lasso--button <?php echo $sc_saving_class;?>"></a>
88
					<?php } ?>
89
90
				</div>
91
92
			<?php } ?>
93
94
		</div>
95
96
	<?php }
97
}
98
99
/**
100
 * Draw the side panel that houses the component settings
101
 * This is opened when the settings icon is clicked on a single component
102
 * JS detects the type and will fill in the necessary options for the shortcode based on  lasso_editor_options_blob() at the end of this file
103
 *
104
 * @since 1.0
105
 */
106
function lasso_editor_component_sidebar() {
107
108
	ob_start();
109
110
	if ( !lasso_user_can() )
111
		return;
112
113
	// let users add custom css classes
114
	$custom_classes = apply_filters( 'lasso_sidebar_classes', '' );
115
	?>
116
	<div id="lasso--sidebar" class="<?php echo sanitize_html_class( $custom_classes );?>" >
117
		<div class="lasso--sidebar__inner">
118
			<div id="lasso--component__settings"></div>
119
		</div>
120
	</div>
121
122
	<?php return ob_get_clean();
123
}
124
125
/**
126
 * Draw the main toolbar used to edit the text
127
 *
128
 * @since 1.0
129
 */
130
function lasso_editor_text_toolbar() {
131
132
	ob_start();
133
134
	if ( !lasso_user_can() )
135
		return;
136
	
137
	$is_mobile = wp_is_mobile();
138
139
	// check for lasso story engine and add a class doniting this
140
	$ase_status = class_exists( 'Aesop_Core' ) || defined( 'LASSO_CUSTOM' ) ? 'ase-active' : 'ase-not-active';
141
142
	// let users add custom css classes
143
	$custom_classes = apply_filters( 'lasso_toolbar_classes', '' );
144
145
	// are toolbar headings enabled
146
	$toolbar_headings      = lasso_editor_get_option( 'toolbar_headings', 'lasso_editor' );
0 ignored issues
show
Documentation introduced by
'toolbar_headings' is of type string, but the function expects a object<unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'lasso_editor' is of type string, but the function expects a object<unknown>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
147
148
	$toolbar_class  = $toolbar_headings ? 'toolbar-extended' : false;
149
    $mobile_class = $is_mobile ? 'lasso-mobile' : false;
150
	
151
	$mobile_style =$is_mobile ? 'style="top:40px;"' : null;
152
153
154
	?>
155
	<div class="lasso--toolbar_wrap lasso-editor-controls--wrap <?php echo $toolbar_class.' '.$mobile_class.' '.$ase_status.' '.sanitize_html_class( $custom_classes );?>" <?php echo $mobile_style ?>>
156
		<ul class="lasso--toolbar__inner lasso-editor-controls">
157
			<?php do_action( 'lasso_toolbar_components_before' );?>
158
		    <li id="lasso-toolbar--bold" title="<?php esc_attr_e( 'Bold', 'lasso' );?>"></li>
159
		    <li id="lasso-toolbar--underline" title="<?php esc_attr_e( 'Underline', 'lasso' );?>"></li>
160
		    <li id="lasso-toolbar--italic" title="<?php esc_attr_e( 'Italicize', 'lasso' );?>"></li>
161
		    <li id="lasso-toolbar--strike" title="<?php esc_attr_e( 'Strikethrough', 'lasso' );?>"></li>
162
		    <?php if ( $toolbar_headings ): ?>
163
		    <li id="lasso-toolbar--h2" title="<?php esc_attr_e( 'H2 Heading', 'lasso' );?>"></li>
164
		    <li id="lasso-toolbar--h3" title="<?php esc_attr_e( 'H3 Heading', 'lasso' );?>"></li>
165
			<?php endif; ?>
166
		    <li id="lasso-toolbar--link" title="<?php esc_attr_e( 'Anchor Link', 'lasso' );?>">
167
		    	<div id="lasso-toolbar--link__wrap" <?php echo $mobile_style ?> >
168
		    		<div id="lasso-toolbar--link__inner" contenteditable="true" placeholder="<?php esc_attr_e( 'http://url.com', 'lasso' );?>"></div>
169
		    		<a href="#" title="<?php esc_attr_e( 'Create Link', 'lasso' );?>" class="lasso-toolbar--link__control" id="lasso-toolbar--link__create" ></a>
170
					<!--input class="styled-checkbox" type="checkbox" /-->
171
                    <!--label>Styled Check Box</label-->
172
		    	</div>
173
		    </li>
174
		    <?php do_action( 'lasso_toolbar_components_after' );?>
175
		    <li id="lasso-toolbar--html" title="<?php esc_attr_e( 'Insert HTML', 'lasso' );?>">
176
		    	<div id="lasso-toolbar--html__wrap" <?php echo $mobile_style ?>>
177
		    		<div id="lasso-toolbar--html__inner" contenteditable="true" placeholder="<?php esc_attr_e( 'Enter HTML to insert', 'lasso' );?>"></div>
178
		    		<div id="lasso-toolbar--html__footer">
179
		    			<ul class="lasso-toolbar--html-snips">
180
		    				<?php if ( !$toolbar_headings ): ?>
181
		    				<li id="lasso-html--h2" title="<?php esc_attr_e( 'H2 Heading', 'lasso' );?>">
182
		    				<li id="lasso-html--h3" title="<?php esc_attr_e( 'H3 Heading', 'lasso' );?>">
183
		    				<?php endif; ?>
184
		    				<li id="lasso-html--ul" title="<?php esc_attr_e( 'Unordered List', 'lasso' );?>">
185
		    				<li id="lasso-html--ol" title="<?php esc_attr_e( 'Ordered List', 'lasso' );?>">
186
		    			</ul>
187
		    			<a class="lasso-toolbar--html__control lasso-toolbar--html__cancel" href="#"><?php _e( 'Cancel', 'lasso' );?></a>
188
		    			<a href="#" title="<?php esc_attr_e( 'Insert HTML', 'lasso' );?>" class="lasso-toolbar--html__control" id="lasso-toolbar--html__insert" ><?php _e( 'Insert', 'lasso' );?></a>
189
		    		</div>
190
		    	</div>
191
		    </li>
192
		    <li id="lasso-toolbar--components" title="<?php esc_attr_e( 'Insert Component', 'lasso' );?>">
193
			    <ul id="lasso-toolbar--components__list" style="display:none;">
194
			    	<?php if ( 'ase-active' == $ase_status ): ?>
195
						<li data-type="image" title="<?php esc_attr_e( 'Image', 'lasso' );?>" class="lasso-toolbar--component__image"></li>
196
						<li data-type="character" title="<?php esc_attr_e( 'Character', 'lasso' );?>" class="lasso-toolbar--component__character"></li>
197
						<li data-type="quote" title="<?php esc_attr_e( 'Quote', 'lasso' );?>"  class="lasso-toolbar--component__quote"></li>
198
						<li data-type="content" title="<?php esc_attr_e( 'Content', 'lasso' );?>"  class="lasso-toolbar--component__content"></li>
199
						<li data-type="chapter" title="<?php esc_attr_e( 'Chapter', 'lasso' );?>"  class="lasso-toolbar--component__chapter"></li>
200
						<li data-type="parallax" title="<?php esc_attr_e( 'Parallax', 'lasso' );?>"  class="lasso-toolbar--component__parallax"></li>
201
						<li data-type="audio" title="<?php esc_attr_e( 'Audio', 'lasso' );?>"  class="lasso-toolbar--component__audio"></li>
202
						<li data-type="video" title="<?php esc_attr_e( 'Video', 'lasso' );?>"  class="lasso-toolbar--component__video"></li>
203
						<li data-type="map" title="<?php esc_attr_e( 'Map', 'lasso' );?>"  class="lasso-toolbar--component__map"></li>
204
						<li data-type="timeline_stop" title="<?php esc_attr_e( 'Timeline', 'lasso' );?>"  class="lasso-toolbar--component__timeline"></li>
205
						<li data-type="document" title="<?php esc_attr_e( 'Document', 'lasso' );?>"  class="lasso-toolbar--component__document"></li>
206
						<li data-type="collection" title="<?php esc_attr_e( 'Collection', 'lasso' );?>"  class="lasso-toolbar--component__collection"></li>
207
						<li data-type="gallery" title="<?php esc_attr_e( 'Gallery', 'lasso' );?>"  class="lasso-toolbar--component__gallery"></li>
208
						<?php if ( class_exists ('Aesop_GalleryPop') ) { ?>
209
						     <li data-type="gallery" title="<?php esc_attr_e( 'Gallery Pop', 'lasso' );?>"  class="lasso-toolbar--component__gallerypop"></li>
210
						<?php }?>
211
					<?php else: ?>
212
						<li data-type="wpimg" title="<?php esc_attr_e( 'WordPress Image', 'lasso' );?>" class="image lasso-toolbar--component__image"></li>
213
						<li data-type="wpquote" title="<?php esc_attr_e( 'WordPress Quote', 'lasso' );?>" class="quote lasso-toolbar--component__quote"></li>
214
						<!--li data-type="wpvideo" title="<?php esc_attr_e( 'WordPress Video', 'lasso' );?>" class="video lasso-toolbar--component__video"></li-->
215
					<?php endif; ?>
216
					<?php do_action( 'lasso_toolbar_components' );?>
217
			    </ul>
218
			</li>
219
		</ul>
220
	</div>
221
222
	<?php return ob_get_clean();
223
}
224
225
/**
226
 * Draw the controls used for teh component settings within each component
227
 *
228
 * @since 1.0
229
 */
230
function lasso_editor_settings_toolbar() {
231
232
	$delete_nonce = wp_create_nonce( 'lasso-delete-nonce' );
233
234
	ob_start();
235
236
	if ( !lasso_user_can() )
237
		return;
238
239
	// let users add custom css classes
240
	$custom_classes = apply_filters( 'lasso_component_classes', '' );
241
242
	?>
243
	<ul class="lasso-component--controls <?php echo sanitize_html_class( $custom_classes );?>" contenteditable="false">
244
		<li class="lasso-drag" title="<?php esc_attr_e( 'Move', 'lasso' );?>"></li>
245
		<li id="lasso-component--settings__trigger" class="lasso-settings" title="<?php esc_attr_e( 'Settings', 'lasso' );?>"></li>
246
		<li class="lasso-clone" title="<?php esc_attr_e( 'Clone', 'lasso' );?>"></li>
247
		<li class="lasso-delete" data-postid="<?php echo get_the_ID();?>" data-nonce="<?php echo $delete_nonce;?>" title="<?php esc_attr_e( 'Delete', 'lasso' );?>"></li>
248
	</ul>
249
250
	<?php return ob_get_clean();
251
}
252
253
/**
254
 * Draws the controls used for changing the featured image
255
 *   These controls are appended based on the class set in the define
256
 *
257
 * @since 1.0
258
 */
259
function lasso_editor_image_controls() {
260
261
	ob_start();
262
263
	if ( !lasso_user_can() )
264
		return;
265
266
	// has post thumbnail
267
	$has_thumbnail = has_post_thumbnail( get_the_ID() ) ? 'class="lasso--featImg--has-thumb"' : false;
268
269
	?>
270
	<ul id="lasso--featImgControls" <?php echo $has_thumbnail;?>>
271
		<li id="lasso--featImgUpload"><a title="<?php esc_attr_e( 'Replace Image', 'lasso' );?>" href="#"><i class="lasso-icon-image"></i></a></li>
272
		<li id="lasso--featImgDelete"><a title="<?php esc_attr_e( 'Delete Image', 'lasso' );?>" href="#"><i class="lasso-icon-bin2"></i></a></li>
273
		<li id="lasso--featImgSave"><a href="#"><?php esc_attr_e( 'save', 'lasso' );?></a></li>
274
	</ul>
275
276
	<?php return ob_get_clean();
277
}
278
279
280
/**
281
 * Used to house post settings like scheduling, slugs and draft status
282
 * Note: the "add new" will use the same object as the currently shown. For example, if the user
283
 * is currently on a post, and clicks add new, then it'll add a new post. If the user is on a
284
 * post type like "dog", then it will create a new post type called "dog"
285
 *
286
 * @since 1.0
287
 */
288
function lasso_editor_component_modal() {
289
290
	ob_start();
291
292
	if ( !lasso_user_can() )
293
		return;
294
295
	global $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
296
297
	$postid = get_the_ID();
298
299
	$status = get_post_status( $postid );
300
	$nonce = wp_create_nonce( 'lasso-update-post-settings' );
301
302
	// let users add custom css classes
303
	$custom_classes = apply_filters( 'lasso_modal_settings_classes', '' );
304
305
	// objects categories
306
	$categories 		= lasso_get_post_objects( $postid, 'category' );
307
	$tags 				= lasso_get_post_objects( $postid, 'tag' );
308
309
	// modal tabs
310
	$tabs  				= lasso_modal_addons('tab');
311
	$content 			= lasso_modal_addons('content');
312
313
	// are we singular
314
	$is_singular 		= is_singular();
315
	$is_singular_class 	= $is_singular ? 'lasso--postsettings__2col' : 'lasso--postsettings__1col';
316
	$has_thumb_class    = has_post_thumbnail() ? 'has-thumbnail' : 'no-thumbnail';
317
	$theme_supports     = current_theme_supports('post-thumbnails');
318
	$default_image 		= LASSO_URL.'/admin/assets/img/empty-img.png';
319
320
?>
321
	<div id="lasso--post-settings__modal" class="lasso--modal lassoShowAnimate <?php echo sanitize_html_class( $custom_classes );?>">
322
		<div class="lasso--modal__inner">
323
324
			<?php if( $tabs ) { echo $tabs; } ?>
0 ignored issues
show
Bug Best Practice introduced by
The expression $tabs of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
325
326
			<div class="lasso--modal__content modal__content--core visible" data-addon-content="core">
327
				<form id="lasso--postsettings__form" enctype="multipart/form-data" class="lasso--post-form <?php echo $is_singular_class.' '.$has_thumb_class;?>" >
328
329
					<?php if ( $is_singular && $theme_supports ) : ?>
330
					<div class="lasso--postsettings__left">
331
						<label><?php _e( 'Featured Image', 'lasso' );?><span class="lasso-util--help lasso-util--help-top" data-tooltip="<?php esc_attr_e( 'Change the featured image for this post.', 'lasso' );?>"><i class="lasso-icon-help"></i></span></label>
332
						<div class="lasso--post-thumb" data-default-thumb="<?php echo esc_url( $default_image );?>">
333
334
							<div id="lasso--post-thumb__controls" class="lasso--post-thumb__controls">
335
								<i id="lasso--post-thumb__add" title="<?php _e('Change Featured Image','lasso');?>" class="dashicons dashicons-edit"></i>
336
								<i id="lasso--post-thumb__delete" title="<?php _e('Delete Featured Image','lasso');?>" class="dashicons dashicons-no-alt"></i>
337
								<i id="lasso--save-status" class="lasso-icon lasso-icon-spinner6 not-visible"></i>
338
							</div>
339
340
							<?php echo has_post_thumbnail() ? get_the_post_thumbnail( $post->ID, 'medium' ) : '<img src="'.$default_image.'">'; ?>
341
342
						</div>
343
						<div id="lasso--featImgSave"><a href="#" class="not-visible">Save</a></div>
344
345
					</div>
346
					<?php endif; ?>
347
348
					<div class="lasso--postsettings__right">
349
350
						<?php if( lasso_user_can('publish_posts') || lasso_user_can('publish_pages') ): ?>
351
						<div class="lasso--postsettings__option story-status-option">
352
							<label><?php _e( 'Status', 'lasso' );?><span class="lasso-util--help lasso-util--help-top" data-tooltip="<?php esc_attr_e( 'Change the status of the post to draft or publish.', 'lasso' );?>"><i class="lasso-icon-help"></i></span></label>
353
							<ul class="story-status story-status-<?php echo sanitize_html_class( $status );?>">
354
								<li id="lasso--status-draft"><?php _e( 'Draft', 'lasso' );?></li>
355
								<li id="lasso--status-publish"><?php _e( 'Publish', 'lasso' );?></li>
356
							</ul>
357
							<div class="lasso--slider_wrap">
358
								<div id="lasso--slider"></div>
359
							</div>
360
						</div>
361
						<?php endif; ?>
362
363
						<?php if ( 'publish' == $status ): ?>
364
						<div class="lasso--postsettings__option story-slug-option">
365
							<label><?php _e( 'Post URL', 'lasso' );?><span class="lasso-util--help lasso-util--help-top" data-tooltip="<?php esc_attr_e( 'Change the URL (slug) of this post.', 'lasso' );?>"><i class="lasso-icon-help"></i></span></label>
366
							<input class="lasso--modal__trigger-footer" type="text" name="story_slug" value="<?php echo isset( $post ) ? esc_attr( $post->post_name ) : false;?>">
367
						</div>
368
						<?php endif; ?>
369
370
					</div>
371
372
					<div class="lasso--postsettings__middle">
373
374
						<div class="lasso--postsettings__option story-categories-option">
375
							<label><?php _e( 'Categories', 'lasso' );?><span class="lasso-util--help lasso-util--help-top" data-tooltip="<?php esc_attr_e( 'Type a category name and press enter.', 'lasso' );?>"><i class="lasso-icon-help"></i></span></label>
376
							<input id="lasso--cat-select" class="lasso--modal__trigger-footer" type="hidden" name="story_cats" value="<?php echo $categories;?>">
377
						</div>
378
379
						<div class="lasso--postsettings__option story-tags-option">
380
							<label><?php _e( 'Tags', 'lasso' );?><span class="lasso-util--help lasso-util--help-top" data-tooltip="<?php esc_attr_e( 'Type a tag name and press enter.', 'lasso' );?>"><i class="lasso-icon-help"></i></span></label>
381
							<input id="lasso--tag-select" class="lasso--modal__trigger-footer" type="hidden" name="story_tags" value="<?php echo $tags;?>">
382
						</div>
383
384
					</div>
385
386
					<?php do_action( 'lasso_modal_post_form' ); // action ?>
387
388
					<div class="lasso--postsettings__footer" style="display:none;">
389
						<a href="#" class="lasso--postsettings-cancel"><?php _e( 'Cancel', 'lasso' );?></a>
390
						<input type="hidden" name="status" value="">
391
						<input type="hidden" name="categories" value="">
392
						<input type="hidden" name="postid" value="<?php echo get_the_ID();?>">
393
						<input type="hidden" name="action" value="process_update-object_post">
394
						<input type="hidden" name="nonce" value="<?php echo $nonce;?>">
395
						<?php do_action( 'lasso_modal_post_form_footer' ); // action ?>
396
						<input type="submit" value="<?php esc_attr_e( 'Save', 'lasso' );?>">
397
					</div>
398
399
				</form>
400
			</div>
401
402
			<?php if( $tabs ) { echo $content; } ?>
0 ignored issues
show
Bug Best Practice introduced by
The expression $tabs of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
403
404
		</div>
405
406
	</div>
407
	<div id="lasso--modal__overlay"></div>
408
409
	<?php return ob_get_clean();
410
}
411
412
/**
413
 * Used to house the form for creating a new post within amodal
414
 *
415
 * @since 1.0
416
 */
417
function lasso_editor_newpost_modal() {
418
419
	global $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
420
421
	ob_start();
422
423
	if ( !lasso_user_can('edit_posts') )
424
		return;
425
426
	$status = get_post_status( get_the_ID() );
0 ignored issues
show
Unused Code introduced by
$status is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
427
428
	$nonce = wp_create_nonce( 'lasso-editor-new-post' );
429
430
	// let users add custom css classes
431
	$custom_classes = apply_filters( 'lasso_modal_post_classes', '' );
432
433
	// return the post type
434
	$type = get_post_type( get_the_ID() );
435
436
	?>
437
	<div id="lasso--post-new__modal" class="lasso--modal lasso--modal__med lassoShowAnimate <?php echo sanitize_html_class( $custom_classes );?>">
438
		<div class="lasso--modal__inner">
439
440
			<form id="lasso--postnew__form" enctype="multipart/form-data" class="lasso--post-form">
441
442
				<div class="lasso--postsettings__option story-slug-option lasso--last-option">
443
					<label><?php esc_attr_e( 'New <span>post</span> title', 'lasso' );?><span class="lasso-util--help lasso-util--help-top" data-tooltip="<?php esc_attr_e( 'Specify title for new post, then save to edit.', 'lasso' );?>"><i class="lasso-icon-help"></i></span></label>
444
					<input class="lasso--modal__trigger-footer" type="text" required name="story_title" value="" placeholder="<?php esc_attr_e( 'Grump Wizards Make Toxic Brew', 'lasso' );?>">
445
						<div class="lasso--select-wrap" style="width:90px">
446
						<select id="lasso--select-type" name="story_type">
447
448
							<?php
449
								$types = lasso_post_types();
450
451
								if ( !empty( $types ) ) {
452
453
									foreach( $types as $type ) {
454
455
										$type = preg_replace( '/s\b/','', $type );
456
457
										printf( '<option value="%s">%s</option>', lcfirst( esc_attr( $type ) ) , ucfirst( esc_attr( $type ) ) );
458
									}
459
460
								}
461
							?>
462
463
						</select>
464
					</div>
465
				</div>
466
467
				<div class="lasso--postsettings__footer" style="display:none;">
468
					<a href="#" class="lasso--postsettings-cancel"><?php _e( 'Cancel', 'lasso' );?></a>
469
					<input type="hidden" name="action" value="process_new-object_post">
470
					<input type="hidden" name="object" value="post">
471
					<input type="hidden" name="nonce" value="<?php echo $nonce;?>">
472
					<input type="submit" value="<?php esc_attr_e( 'Create', 'lasso' );?>">
473
				</div>
474
475
			</form>
476
477
		</div>
478
	</div>
479
	<div id="lasso--modal__overlay"></div>
480
481
	<?php return ob_get_clean();
482
}
483
484
/**
485
 * Used to house the all posts pop-up
486
 *
487
 * @since 0.9.3
488
 */
489
function lasso_editor_allpost_modal() {
490
491
	global $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
492
493
	ob_start();
494
495
	// post status
496
	$status = get_post_status( get_the_ID() );
0 ignored issues
show
Unused Code introduced by
$status is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
497
498
	// let users add custom css classes
499
	$custom_classes = apply_filters( 'lasso_modal_all_post_classes', '' );
500
501
	?>
502
	<div id="lasso--all-posts__modal" class="lasso--modal lasso--modal__full lassoShowAnimate <?php echo sanitize_html_class( $custom_classes );?>">
503
		<div class="lasso--modal__inner">
504
505
			<div class="lasso--post-filtering not-visible">
506
				<div class="lasso--search__results">
507
					<span id="lasso--results-found"></span><?php _e('results found','lasso');?>
508
				</div>
509
				<div class="lasso--search">
510
					<i id="lasso--search__toggle" class="dashicons dashicons-search"></i>
511
					<input id="lasso--search-field" type="text" placeholder="search...">
512
				</div>
513
			</div>
514
515
			<ul class="lasso--post-object-list">
516
				<?php
517
518
				$post_types = lasso_post_types_names();
519
520
				if ( ! empty( $post_types ) ) {
521
					$first = 'active';
522
					foreach( $post_types as $name => $label ) {
523
						printf( '<li class="%1s lasso--show-objects" data-post-type="%2s">%3s</li>', esc_attr( $first), esc_attr( $name ), esc_attr( $label ) );
524
						$first = '';
525
					}
526
527
				}
528
529
				do_action('lasso_modal_post_objects');?>
530
531
			</ul>
532
			<div id="lasso--loading" class="lasso--loading"><div class="lasso--loader"></div></div>
533
534
			<ul id="lasso--post-list" class="lasso--post-list"></ul>
535
536
		</div>
537
	</div>
538
	<div id="lasso--modal__overlay"></div>
539
540
	<?php return ob_get_clean();
541
}
542
543 View Code Duplication
function lasso_editor_wpimg_edit() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
544
545
	ob_start();
546
547
	if ( !lasso_user_can() )
548
		return;
549
550
	// let users add custom css classes
551
	$custom_classes = apply_filters( 'lasso_wpimg_classes', '' );
552
553
	?>
554
	<ul class="lasso-component--controls <?php echo sanitize_html_class( $custom_classes );?>" contenteditable="false">
555
		<li class="lasso-drag" title="<?php esc_attr_e( 'Move', 'lasso' );?>"></li>
556
		<li id="lasso--wpimg-edit" class="lasso-settings" title="<?php esc_attr_e( 'Settings', 'lasso' );?>"></li>
557
		<li class="lasso-clone" title="<?php esc_attr_e( 'Clone', 'lasso' );?>"></li>
558
		<li class="lasso-delete" title="<?php esc_attr_e( 'Delete', 'lasso' );?>"></li>
559
	</ul>
560
561
	<?php return ob_get_clean();
562
}
563
564 View Code Duplication
function lasso_editor_wpvideo_edit() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
565
566
	ob_start();
567
568
	if ( !lasso_user_can() )
569
		return;
570
571
	// let users add custom css classes
572
	$custom_classes = apply_filters( 'lasso_wpimg_classes', '' );
573
574
	?>
575
	<ul class="lasso-component--controls <?php echo sanitize_html_class( $custom_classes );?>" contenteditable="false">
576
		<li class="lasso-drag" title="<?php esc_attr_e( 'Move', 'lasso' );?>"></li>
577
		<li id="lasso--wpvideo-edit" class="lasso-settings" title="<?php esc_attr_e( 'Settings', 'lasso' );?>"></li>
578
		<li class="lasso-clone" title="<?php esc_attr_e( 'Clone', 'lasso' );?>"></li>
579
		<li class="lasso-delete" title="<?php esc_attr_e( 'Delete', 'lasso' );?>"></li>
580
	</ul>
581
582
	<?php return ob_get_clean();
583
}
584
585
/**
586
 * Used to house the hidden input fields for actions and process saving for the map component
587
 *
588
 * @since 1.0
589
 */
590
function lasso_map_form_footer() {
591
592
	$nonce = wp_create_nonce( 'lasso-process-map' );
593
594
	ob_start();
595
596
	?>
597
	<div class="lasso--map-form__footer">
598
		<input type="hidden" name="postid" value="<?php echo get_the_ID();?>">
599
		<input type="hidden" name="nonce" value="<?php echo $nonce;?>">
600
		<input type="hidden" name="action" value="process_map_save">
601
		<input type="submit" class="lasso--map-form__submit" value="<?php esc_attr_e( 'Save Locations', 'lasso' );?>">
602
	</div>
603
604
	<?php return ob_get_clean();
605
606
}
607
608
/**
609
 * Some things aren't real-time updatable so we need to append a message in certain areas on certain actions
610
 *
611
 * @since 1.0
612
 */
613
function lasso_editor_refresh_message() {
614
615
	ob_start();
616
617
	?>
618
	<div id="lasso--pagerefresh" class="visible">
619
		<?php _e( 'Save this post and refesh the page to see these changes.', 'lasso' );?>
620
	</div>
621
622
	<?php return ob_get_clean();
623
}
624
625
/**
626
 * Draw out the settings field based on the shortcodes array with options foudn in Lasso Story Engine
627
 *  This was mostly backported from lasso story engine and modified to allow for non lasso shortcodes and components
628
 *
629
 * @since 1.0
630
 */
631
function lasso_editor_options_blob() {
632
633
	$codes   = function_exists( 'aesop_shortcodes' ) ? aesop_shortcodes() : apply_filters( 'lasso_custom_options', '' );
634
	$galleries  = function_exists( 'lasso_editor_galleries_exist' ) && lasso_editor_galleries_exist() ? 'has-galleries' : 'creating-gallery';
635
636
	$nonce = wp_create_nonce( 'lasso_gallery' );
637
638
	$blob = array();
639
640
	if ( empty( $codes ) )
641
		return;
642
643
	foreach ( $codes as $slug => $shortcode ) {
644
		$return = '';
645
		// Shortcode has atts
646
647
		if ( count( $shortcode['atts'] ) && $shortcode['atts'] ) {
648
649
			foreach ( $shortcode['atts'] as $attr_name => $attr_info ) {
650
651
652
				$prefix = isset( $attr_info['prefix'] ) ? sprintf( '<span class="lasso-option-prefix">%s</span>', $attr_info['prefix'] ) : null;
653
654
				$return .= '<form id="lasso--component-settings-form" class="'.$galleries.'" method="post">';
655
				$return .= '<p data-option="'.$attr_name.'" class="lasso-option lasso-'.$slug.'-'.$attr_name.'">';
656
				$return .= '<label for="lasso-generator-attr-' . $attr_name . '">' . $attr_info['desc'] . '</label>';
657
				$return .= '<small class="lasso-option-desc">'.$attr_info['tip'].'</small>';
658
				// Select
659
660
				if ( isset( $attr_info['values'] ) ) {
661
662
					$return .= '<select name="' . $attr_name . '" id="lasso-generator-attr-' . $attr_name . '" class="lasso-generator-attr">';
663
664
					$i=0;
665
666
					foreach ( $attr_info['values'] as $attr_value ) {
667
						$attr_value_selected = $attr_info['default'] == $attr_value ? ' selected="selected"' : '';
668
669
						$return .= '<option value="'.$attr_info['values'][$i]['value'].'" ' . $attr_value_selected . '>'.$attr_info['values'][$i]['name'].'</option>';
670
671
						$i++;
672
					}
673
674
					$return .= '</select>';
675
676
				} else {
677
678
					$attr_field_type = isset( $attr_info['type'] ) ? $attr_info['type'] : 'text';
679
680
					// image upload
681
					if ( 'media_upload' == $attr_info['type'] ) {
682
683
						$return .= '<input type="' . $attr_field_type . '" name="' . $attr_name . '" value="'.$attr_info['default'].'" id="lasso-generator-attr-' . $attr_name . '" class="lasso-generator-attr lasso-generator-attr-'.$attr_field_type.'" />';
684
						$return .= '<a href="#" id="lasso-upload-img" class="lasso-option-button" /></a>';
685
686
					} elseif ( 'color' == $attr_info['type'] ) {
687
688
						$return .= '<input type="color" name="' . $attr_name . '" value="'.$attr_info['default'].'" id="lasso-generator-attr-' . $attr_name . '" class="lasso-generator-attr lasso-generator-attr-'.$attr_field_type.'" />';
689
690
					} elseif ( 'text_area' == $attr_info['type'] ) {
691
692
						$return .= '<textarea name="' . $attr_name . '" id="lasso-generator-attr-' . $attr_name . '" class="lasso-generator-attr lasso-generator-attr-'.$attr_field_type.'" placeholder="'.$attr_info['default'].'" /></textarea>'.$prefix.'';
693
694
					} else {
695
						$return .= '<input type="' . $attr_field_type . '" name="' . $attr_name . '" value="'.$attr_info['default'].'" id="lasso-generator-attr-' . $attr_name . '" class="lasso-generator-attr lasso-generator-attr-'.$attr_field_type.'" />'.$prefix.'';
696
					}
697
				}
698
				$return .= '</p>';
699
700
			}
701
		}
702
703
		///////////////////////////
704
		// START GALLERY AND MAP FRONT END STUFFS
705
		///////////////////////////
706
		if ( isset( $shortcode['front'] ) && true == $shortcode['front'] ) {
707
708
			if ( 'gallery' == $shortcode['front_type'] ) {
709
710
				$return .= lasso_gallery_editor_module();
711
712
			}
713
		}
714
		///////////////////////////
715
		// END GALLERY AND MAP FRONT END STUFFS
716
		///////////////////////////
717
718
		// Single shortcode (not closed)
719
		if ( 'single' == $shortcode['type'] ) {
720
721
			$return .= '<input type="hidden" name="lasso-generator-content" id="lasso-generator-content" value="false" />';
722
723
		} else {
724
725
			$return .= '<p data-option="content" class="lasso-option lasso-c-comp-text"><label>' . __( 'Content', 'lasso' ) . '</label><textarea type="text" name="lasso-generator-content" id="lasso-generator-content" value="' . $shortcode['content'] . '" /></textarea></p>';
726
		}
727
728
		$return .= '<p class="lasso-buttoninsert-wrap"><a href="#" class="lasso-generator-cancel" id="lasso--sidebar__close">Cancel
729
</a><input type="submit" id="lasso-generator-insert" value="Save Settings"></p>';
730
		$return .= '<input class="component_type" type="hidden" name="component_type" value="">';
731
		$return .= '<input type="hidden" name="unique" value="">';
732
		$return .= '<input type="hidden" name="nonce" id="lasso-generator-nonce" value="'.$nonce.'" />';
733
		$return .= '</form>';
734
735
		$blob[$slug] = $return;
736
	}
737
738
	return $blob;
739
}
740
741
/**
742
 * Revisions modal
743
 *
744
 * @since 0.9.8
745
 *
746
 * @return string
747
 */
748
function lasso_editor_revision_modal() {
749
750
	ob_start();
751
	?>
752
		<div id="lasso--revision__modal" class="lasso--modal lassoShowAnimate ">
753
754
			<div class="lasso--modal__inner">
755
				<div id="lasso--loading" class="lasso--loading"><div class="lasso--loader"></div></div>
756
				<div id="lasso--hide" style="display:none;" class="lasso--post-form">
757
					<i class="lasso-icon lasso-icon-move"></i>
758
					<label><?php _e( 'Revisions', 'lasso' );?><span class="lasso-util--help lasso-util--help-top" data-tooltip="<?php esc_attr_e( 'Use the slider to view the revision live on the page.', 'lasso' );?>"><i class="lasso-icon-help"></i></span></label>
759
					<div class="lasso--slider_wrap">
760
						<div id="lasso--slider"></div>
761
					</div>
762
					<ul id="lasso--revision-list"></ul>
763
					<div class="lasso--btn-group lasso--btn-group-small">
764
						<a href="#" class="lasso--btn-secondary" id="lasso--close-modal">Cancel</a>
765
						<a href="#" class="lasso--btn-primary" id="lasso--select-revision">Select</a>
766
					</div>
767
				</div>
768
769
			</div>
770
		</div>
771
	<?php
772
	return ob_get_clean();
773
}
774