Completed
Push — master ( 48e484...cedfdf )
by
unknown
03:10
created

editor-modules.php ➔ lasso_editor_text_toolbar()   C

Complexity

Conditions 8
Paths 65

Size

Total Lines 84
Code Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
cc 8
eloc 55
c 2
b 1
f 1
nc 65
nop 0
dl 0
loc 84
rs 5.8442

How to fix   Long Method   

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
		?><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();?>" >
49
50
			<ul class="lasso--controls__center lasso-editor-controls lasso-editor-controls--wrap <?php echo $post_access_class;?> ">
51
52
				<?php do_action( 'lasso_editor_controls_before' );
53
54
				if ( $is_capable ) { ?>
55
56
					<li id="lasso--edit" title="<?php esc_attr_e( 'Edit Post', 'lasso' );?>"><a href="#" class="lasso--button__primary"></a></li>
57
58
					<?php if ( 'off' == $post_settings_disabled || empty( $post_settings_disabled ) ) { ?>
59
						<li id="lasso--post-settings" title="<?php esc_attr_e( 'Post Settings', 'lasso' );?>"><a href="#" class="lasso--button__primary"></a></li>
60
					<?php }
61
62
				} ?>
63
64
				<li id="lasso--post-all" title="<?php esc_attr_e( 'All Posts', 'lasso' );?>"><a href="#" class="lasso--button__primary"></a></li>
65
66
				<?php if ( $is_capable && wp_revisions_enabled( $post ) ) { ?>
67
					<li id="lasso--post-revisions" title="<?php esc_attr_e( 'Revisions', 'lasso' );?>"><a href="#" class="lasso--button__primary"></a></li>
68
				<?php } ?>
69
70
				<?php if ( ( 'off' == $post_new_disabled || empty( $post_new_disabled ) && lasso_user_can('publish_posts') ) ) { ?>
71
					<li id="lasso--post-new" title="<?php esc_attr_e( 'Add Post', 'lasso' );?>"><a href="#" class="lasso--button__primary"></a></li>
72
				<?php } ?>
73
74
				<?php do_action( 'lasso_editor_controls_after' );?>
75
76
			</ul>
77
78
			<?php if ( is_singular() ) { ?>
79
80
				<div class="lasso--controls__right">
81
82
					<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>
83
84
					<?php if ( 'draft' == $status && ( lasso_user_can('publish_posts') || lasso_user_can('publish_pages') )  ) { ?>
85
						<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>
86
					<?php } ?>
87
88
				</div>
89
90
			<?php } ?>
91
92
		</div>
93
94
	<?php }
95
}
96
97
/**
98
 * Draw the side panel that houses the component settings
99
 * This is opened when the settings icon is clicked on a single component
100
 * 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
101
 *
102
 * @since 1.0
103
 */
104
function lasso_editor_component_sidebar() {
105
106
	ob_start();
107
108
	if ( !lasso_user_can() )
109
		return;
110
111
	// let users add custom css classes
112
	$custom_classes = apply_filters( 'lasso_sidebar_classes', '' );
113
	?>
114
	<div id="lasso--sidebar" class="<?php echo sanitize_html_class( $custom_classes );?>" >
115
		<div class="lasso--sidebar__inner">
116
			<div id="lasso--component__settings"></div>
117
		</div>
118
	</div>
119
120
	<?php return ob_get_clean();
121
}
122
123
/**
124
 * Draw the main toolbar used to edit the text
125
 *
126
 * @since 1.0
127
 */
128
function lasso_editor_text_toolbar() {
129
130
	ob_start();
131
132
	if ( !lasso_user_can() )
133
		return;
134
135
	// check for lasso story engine and add a class doniting this
136
	$ase_status = class_exists( 'Aesop_Core' ) || defined( 'LASSO_CUSTOM' ) ? 'ase-active' : 'ase-not-active';
137
138
	// let users add custom css classes
139
	$custom_classes = apply_filters( 'lasso_toolbar_classes', '' );
140
141
	// are toolbar headings enabled
142
	$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...
143
144
	$toolbar_class  = $toolbar_headings ? 'toolbar-extended' : false;
145
146
	?>
147
	<div class="lasso--toolbar_wrap lasso-editor-controls--wrap <?php echo $toolbar_class.' '.$ase_status.' '.sanitize_html_class( $custom_classes );?>">
148
		<ul class="lasso--toolbar__inner lasso-editor-controls">
149
			<?php do_action( 'lasso_toolbar_components_before' );?>
150
		    <li id="lasso-toolbar--bold" title="<?php esc_attr_e( 'Bold', 'lasso' );?>"></li>
151
		    <li id="lasso-toolbar--underline" title="<?php esc_attr_e( 'Underline', 'lasso' );?>"></li>
152
		    <li id="lasso-toolbar--italic" title="<?php esc_attr_e( 'Italicize', 'lasso' );?>"></li>
153
		    <li id="lasso-toolbar--strike" title="<?php esc_attr_e( 'Strikethrough', 'lasso' );?>"></li>
154
		    <?php if ( $toolbar_headings ): ?>
155
		    <li id="lasso-toolbar--h2" title="<?php esc_attr_e( 'H2 Heading', 'lasso' );?>"></li>
156
		    <li id="lasso-toolbar--h3" title="<?php esc_attr_e( 'H3 Heading', 'lasso' );?>"></li>
157
			<?php endif; ?>
158
		    <li id="lasso-toolbar--link" title="<?php esc_attr_e( 'Anchor Link', 'lasso' );?>">
159
		    	<div id="lasso-toolbar--link__wrap">
160
		    		<div id="lasso-toolbar--link__inner" contenteditable="true" placeholder="<?php esc_attr_e( 'http://url.com', 'lasso' );?>"></div>
161
		    		<a href="#" title="<?php esc_attr_e( 'Create Link', 'lasso' );?>" class="lasso-toolbar--link__control" id="lasso-toolbar--link__create" ></a>
162
					<input type="checkbox" />
163
                    <label>Styled Check Box</label>
164
		    	</div>
165
		    </li>
166
		    <?php do_action( 'lasso_toolbar_components_after' );?>
167
		    <li id="lasso-toolbar--html" title="<?php esc_attr_e( 'Insert HTML', 'lasso' );?>">
168
		    	<div id="lasso-toolbar--html__wrap">
169
		    		<div id="lasso-toolbar--html__inner" contenteditable="true" placeholder="<?php esc_attr_e( 'Enter HTML to insert', 'lasso' );?>"></div>
170
		    		<div id="lasso-toolbar--html__footer">
171
		    			<ul class="lasso-toolbar--html-snips">
172
		    				<?php if ( !$toolbar_headings ): ?>
173
		    				<li id="lasso-html--h2" title="<?php esc_attr_e( 'H2 Heading', 'lasso' );?>">
174
		    				<li id="lasso-html--h3" title="<?php esc_attr_e( 'H3 Heading', 'lasso' );?>">
175
		    				<?php endif; ?>
176
		    				<li id="lasso-html--ul" title="<?php esc_attr_e( 'Unordered List', 'lasso' );?>">
177
		    				<li id="lasso-html--ol" title="<?php esc_attr_e( 'Ordered List', 'lasso' );?>">
178
		    			</ul>
179
		    			<a class="lasso-toolbar--html__control lasso-toolbar--html__cancel" href="#"><?php _e( 'Cancel', 'lasso' );?></a>
180
		    			<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>
181
		    		</div>
182
		    	</div>
183
		    </li>
184
		    <li id="lasso-toolbar--components" title="<?php esc_attr_e( 'Insert Component', 'lasso' );?>">
185
			    <ul id="lasso-toolbar--components__list">
186
			    	<?php if ( 'ase-active' == $ase_status ): ?>
187
						<li data-type="image" title="<?php esc_attr_e( 'Image', 'lasso' );?>" class="lasso-toolbar--component__image"></li>
188
						<li data-type="character" title="<?php esc_attr_e( 'Character', 'lasso' );?>" class="lasso-toolbar--component__character"></li>
189
						<li data-type="quote" title="<?php esc_attr_e( 'Quote', 'lasso' );?>"  class="lasso-toolbar--component__quote"></li>
190
						<li data-type="content" title="<?php esc_attr_e( 'Content', 'lasso' );?>"  class="lasso-toolbar--component__content"></li>
191
						<li data-type="chapter" title="<?php esc_attr_e( 'Chapter', 'lasso' );?>"  class="lasso-toolbar--component__chapter"></li>
192
						<li data-type="parallax" title="<?php esc_attr_e( 'Parallax', 'lasso' );?>"  class="lasso-toolbar--component__parallax"></li>
193
						<li data-type="audio" title="<?php esc_attr_e( 'Audio', 'lasso' );?>"  class="lasso-toolbar--component__audio"></li>
194
						<li data-type="video" title="<?php esc_attr_e( 'Video', 'lasso' );?>"  class="lasso-toolbar--component__video"></li>
195
						<li data-type="map" title="<?php esc_attr_e( 'Map', 'lasso' );?>"  class="lasso-toolbar--component__map"></li>
196
						<li data-type="timeline_stop" title="<?php esc_attr_e( 'Timeline', 'lasso' );?>"  class="lasso-toolbar--component__timeline"></li>
197
						<li data-type="document" title="<?php esc_attr_e( 'Document', 'lasso' );?>"  class="lasso-toolbar--component__document"></li>
198
						<li data-type="collection" title="<?php esc_attr_e( 'Collection', 'lasso' );?>"  class="lasso-toolbar--component__collection"></li>
199
						<li data-type="gallery" title="<?php esc_attr_e( 'Gallery', 'lasso' );?>"  class="lasso-toolbar--component__gallery"></li>
200
					<?php else: ?>
201
						<li data-type="wpimg" title="<?php esc_attr_e( 'WordPress Image', 'lasso' );?>" class="image lasso-toolbar--component__image"></li>
202
						<li data-type="wpquote" title="<?php esc_attr_e( 'WordPress Quote', 'lasso' );?>" class="quote lasso-toolbar--component__quote"></li>
203
					<?php endif; ?>
204
					<?php do_action( 'lasso_toolbar_components' );?>
205
			    </ul>
206
			</li>
207
		</ul>
208
	</div>
209
210
	<?php return ob_get_clean();
211
}
212
213
/**
214
 * Draw the controls used for teh component settings within each component
215
 *
216
 * @since 1.0
217
 */
218
function lasso_editor_settings_toolbar() {
219
220
	$delete_nonce = wp_create_nonce( 'lasso-delete-nonce' );
221
222
	ob_start();
223
224
	if ( !lasso_user_can() )
225
		return;
226
227
	// let users add custom css classes
228
	$custom_classes = apply_filters( 'lasso_component_classes', '' );
229
230
	?>
231
	<ul class="lasso-component--controls <?php echo sanitize_html_class( $custom_classes );?>" contenteditable="false">
232
		<li class="lasso-drag" title="<?php esc_attr_e( 'Move', 'lasso' );?>"></li>
233
		<li id="lasso-component--settings__trigger" class="lasso-settings" title="<?php esc_attr_e( 'Settings', 'lasso' );?>"></li>
234
		<li class="lasso-clone" title="<?php esc_attr_e( 'Clone', 'lasso' );?>"></li>
235
		<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>
236
	</ul>
237
238
	<?php return ob_get_clean();
239
}
240
241
/**
242
 * Draws the controls used for changing the featured image
243
 *   These controls are appended based on the class set in the define
244
 *
245
 * @since 1.0
246
 */
247
function lasso_editor_image_controls() {
248
249
	ob_start();
250
251
	if ( !lasso_user_can() )
252
		return;
253
254
	// has post thumbnail
255
	$has_thumbnail = has_post_thumbnail( get_the_ID() ) ? 'class="lasso--featImg--has-thumb"' : false;
256
257
	?>
258
	<ul id="lasso--featImgControls" <?php echo $has_thumbnail;?>>
259
		<li id="lasso--featImgUpload"><a title="<?php esc_attr_e( 'Replace Image', 'lasso' );?>" href="#"><i class="lasso-icon-image"></i></a></li>
260
		<li id="lasso--featImgDelete"><a title="<?php esc_attr_e( 'Delete Image', 'lasso' );?>" href="#"><i class="lasso-icon-bin2"></i></a></li>
261
		<li id="lasso--featImgSave"><a href="#"><?php esc_attr_e( 'save', 'lasso' );?></a></li>
262
	</ul>
263
264
	<?php return ob_get_clean();
265
}
266
267
268
/**
269
 * Used to house post settings like scheduling, slugs and draft status
270
 * Note: the "add new" will use the same object as the currently shown. For example, if the user
271
 * is currently on a post, and clicks add new, then it'll add a new post. If the user is on a
272
 * post type like "dog", then it will create a new post type called "dog"
273
 *
274
 * @since 1.0
275
 */
276
function lasso_editor_component_modal() {
277
278
	ob_start();
279
280
	if ( !lasso_user_can() )
281
		return;
282
283
	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...
284
285
	$postid = get_the_ID();
286
287
	$status = get_post_status( $postid );
288
	$nonce = wp_create_nonce( 'lasso-update-post-settings' );
289
290
	// let users add custom css classes
291
	$custom_classes = apply_filters( 'lasso_modal_settings_classes', '' );
292
293
	// objects categories
294
	$categories 		= lasso_get_post_objects( $postid, 'category' );
295
	$tags 				= lasso_get_post_objects( $postid, 'tag' );
296
297
	// modal tabs
298
	$tabs  				= lasso_modal_addons('tab');
299
	$content 			= lasso_modal_addons('content');
300
301
	// are we singular
302
	$is_singular 		= is_singular();
303
	$is_singular_class 	= $is_singular ? 'lasso--postsettings__2col' : 'lasso--postsettings__1col';
304
	$has_thumb_class    = has_post_thumbnail() ? 'has-thumbnail' : 'no-thumbnail';
305
	$theme_supports     = current_theme_supports('post-thumbnails');
306
	$default_image 		= LASSO_URL.'/admin/assets/img/empty-img.png';
307
308
?>
309
	<div id="lasso--post-settings__modal" class="lasso--modal lassoShowAnimate <?php echo sanitize_html_class( $custom_classes );?>">
310
		<div class="lasso--modal__inner">
311
312
			<?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...
313
314
			<div class="lasso--modal__content modal__content--core visible" data-addon-content="core">
315
				<form id="lasso--postsettings__form" enctype="multipart/form-data" class="lasso--post-form <?php echo $is_singular_class.' '.$has_thumb_class;?>" >
316
317
					<?php if ( $is_singular && $theme_supports ) : ?>
318
					<div class="lasso--postsettings__left">
319
						<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>
320
						<div class="lasso--post-thumb" data-default-thumb="<?php echo esc_url( $default_image );?>">
321
322
							<div id="lasso--post-thumb__controls" class="lasso--post-thumb__controls">
323
								<i id="lasso--post-thumb__add" title="<?php _e('Change Featured Image','lasso');?>" class="dashicons dashicons-edit"></i>
324
								<i id="lasso--post-thumb__delete" title="<?php _e('Delete Featured Image','lasso');?>" class="dashicons dashicons-no-alt"></i>
325
								<i id="lasso--save-status" class="lasso-icon lasso-icon-spinner6 not-visible"></i>
326
							</div>
327
328
							<?php echo has_post_thumbnail() ? get_the_post_thumbnail( $post->ID, 'medium' ) : '<img src="'.$default_image.'">'; ?>
329
330
						</div>
331
						<div id="lasso--featImgSave"><a href="#" class="not-visible">Save</a></div>
332
333
					</div>
334
					<?php endif; ?>
335
336
					<div class="lasso--postsettings__right">
337
338
						<?php if( lasso_user_can('publish_posts') || lasso_user_can('publish_pages') ): ?>
339
						<div class="lasso--postsettings__option story-status-option">
340
							<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>
341
							<ul class="story-status story-status-<?php echo sanitize_html_class( $status );?>">
342
								<li id="lasso--status-draft"><?php _e( 'Draft', 'lasso' );?></li>
343
								<li id="lasso--status-publish"><?php _e( 'Publish', 'lasso' );?></li>
344
							</ul>
345
							<div class="lasso--slider_wrap">
346
								<div id="lasso--slider"></div>
347
							</div>
348
						</div>
349
						<?php endif; ?>
350
351
						<?php if ( 'publish' == $status ): ?>
352
						<div class="lasso--postsettings__option story-slug-option">
353
							<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>
354
							<input class="lasso--modal__trigger-footer" type="text" name="story_slug" value="<?php echo isset( $post ) ? esc_attr( $post->post_name ) : false;?>">
355
						</div>
356
						<?php endif; ?>
357
358
					</div>
359
360
					<div class="lasso--postsettings__middle">
361
362
						<div class="lasso--postsettings__option story-categories-option">
363
							<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>
364
							<input id="lasso--cat-select" class="lasso--modal__trigger-footer" type="hidden" name="story_cats" value="<?php echo $categories;?>">
365
						</div>
366
367
						<div class="lasso--postsettings__option story-tags-option">
368
							<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>
369
							<input id="lasso--tag-select" class="lasso--modal__trigger-footer" type="hidden" name="story_tags" value="<?php echo $tags;?>">
370
						</div>
371
372
					</div>
373
374
					<?php do_action( 'lasso_modal_post_form' ); // action ?>
375
376
					<div class="lasso--postsettings__footer" style="display:none;">
377
						<a href="#" class="lasso--postsettings-cancel"><?php _e( 'Cancel', 'lasso' );?></a>
378
						<input type="hidden" name="status" value="">
379
						<input type="hidden" name="categories" value="">
380
						<input type="hidden" name="postid" value="<?php echo get_the_ID();?>">
381
						<input type="hidden" name="action" value="process_update-object_post">
382
						<input type="hidden" name="nonce" value="<?php echo $nonce;?>">
383
						<?php do_action( 'lasso_modal_post_form_footer' ); // action ?>
384
						<input type="submit" value="<?php esc_attr_e( 'Save', 'lasso' );?>">
385
					</div>
386
387
				</form>
388
			</div>
389
390
			<?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...
391
392
		</div>
393
394
	</div>
395
	<div id="lasso--modal__overlay"></div>
396
397
	<?php return ob_get_clean();
398
}
399
400
/**
401
 * Used to house the form for creating a new post within amodal
402
 *
403
 * @since 1.0
404
 */
405
function lasso_editor_newpost_modal() {
406
407
	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...
408
409
	ob_start();
410
411
	if ( !lasso_user_can('edit_posts') )
412
		return;
413
414
	$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...
415
416
	$nonce = wp_create_nonce( 'lasso-editor-new-post' );
417
418
	// let users add custom css classes
419
	$custom_classes = apply_filters( 'lasso_modal_post_classes', '' );
420
421
	// return the post type
422
	$type = get_post_type( get_the_ID() );
423
424
	?>
425
	<div id="lasso--post-new__modal" class="lasso--modal lasso--modal__med lassoShowAnimate <?php echo sanitize_html_class( $custom_classes );?>">
426
		<div class="lasso--modal__inner">
427
428
			<form id="lasso--postnew__form" enctype="multipart/form-data" class="lasso--post-form">
429
430
				<div class="lasso--postsettings__option story-slug-option lasso--last-option">
431
					<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>
432
					<input class="lasso--modal__trigger-footer" type="text" required name="story_title" value="" placeholder="<?php esc_attr_e( 'Grump Wizards Make Toxic Brew', 'lasso' );?>">
433
						<div class="lasso--select-wrap" style="width:90px">
434
						<select id="lasso--select-type" name="story_type">
435
436
							<?php
437
								$types = lasso_post_types();
438
439
								if ( !empty( $types ) ) {
440
441
									foreach( $types as $type ) {
442
443
										$type = preg_replace( '/s\b/','', $type );
444
445
										printf( '<option value="%s">%s</option>', lcfirst( esc_attr( $type ) ) , ucfirst( esc_attr( $type ) ) );
446
									}
447
448
								}
449
							?>
450
451
						</select>
452
					</div>
453
				</div>
454
455
				<div class="lasso--postsettings__footer" style="display:none;">
456
					<a href="#" class="lasso--postsettings-cancel"><?php _e( 'Cancel', 'lasso' );?></a>
457
					<input type="hidden" name="action" value="process_new-object_post">
458
					<input type="hidden" name="object" value="post">
459
					<input type="hidden" name="nonce" value="<?php echo $nonce;?>">
460
					<input type="submit" value="<?php esc_attr_e( 'Create', 'lasso' );?>">
461
				</div>
462
463
			</form>
464
465
		</div>
466
	</div>
467
	<div id="lasso--modal__overlay"></div>
468
469
	<?php return ob_get_clean();
470
}
471
472
/**
473
 * Used to house the all posts pop-up
474
 *
475
 * @since 0.9.3
476
 */
477
function lasso_editor_allpost_modal() {
478
479
	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...
480
481
	ob_start();
482
483
	// post status
484
	$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...
485
486
	// let users add custom css classes
487
	$custom_classes = apply_filters( 'lasso_modal_all_post_classes', '' );
488
489
	?>
490
	<div id="lasso--all-posts__modal" class="lasso--modal lasso--modal__full lassoShowAnimate <?php echo sanitize_html_class( $custom_classes );?>">
491
		<div class="lasso--modal__inner">
492
493
			<div class="lasso--post-filtering not-visible">
494
				<div class="lasso--search__results">
495
					<span id="lasso--results-found"></span><?php _e('results found','lasso');?>
496
				</div>
497
				<div class="lasso--search">
498
					<i id="lasso--search__toggle" class="dashicons dashicons-search"></i>
499
					<input id="lasso--search-field" type="text" placeholder="search...">
500
				</div>
501
			</div>
502
503
			<ul class="lasso--post-object-list">
504
				<?php
505
506
				$post_types = lasso_post_types_names();
507
508
				if ( ! empty( $post_types ) ) {
509
					$first = 'active';
510
					foreach( $post_types as $name => $label ) {
511
						printf( '<li class="%1s lasso--show-objects" data-post-type="%2s">%3s</li>', esc_attr( $first), esc_attr( $name ), esc_attr( $label ) );
512
						$first = '';
513
					}
514
515
				}
516
517
				do_action('lasso_modal_post_objects');?>
518
519
			</ul>
520
			<div id="lasso--loading" class="lasso--loading"><div class="lasso--loader"></div></div>
521
522
			<ul id="lasso--post-list" class="lasso--post-list"></ul>
523
524
		</div>
525
	</div>
526
	<div id="lasso--modal__overlay"></div>
527
528
	<?php return ob_get_clean();
529
}
530
531
function lasso_editor_wpimg_edit() {
532
533
	ob_start();
534
535
	if ( !lasso_user_can() )
536
		return;
537
538
	// let users add custom css classes
539
	$custom_classes = apply_filters( 'lasso_wpimg_classes', '' );
540
541
	?>
542
	<ul class="lasso-component--controls <?php echo sanitize_html_class( $custom_classes );?>" contenteditable="false">
543
		<li class="lasso-drag" title="<?php esc_attr_e( 'Move', 'lasso' );?>"></li>
544
		<li id="lasso--wpimg-edit" class="lasso-settings" title="<?php esc_attr_e( 'Settings', 'lasso' );?>"></li>
545
		<li class="lasso-clone" title="<?php esc_attr_e( 'Clone', 'lasso' );?>"></li>
546
		<li class="lasso-delete" title="<?php esc_attr_e( 'Delete', 'lasso' );?>"></li>
547
	</ul>
548
549
	<?php return ob_get_clean();
550
}
551
552
/**
553
 * Used to house the hidden input fields for actions and process saving for the map component
554
 *
555
 * @since 1.0
556
 */
557
function lasso_map_form_footer() {
558
559
	$nonce = wp_create_nonce( 'lasso-process-map' );
560
561
	ob_start();
562
563
	?>
564
	<div class="lasso--map-form__footer">
565
		<input type="hidden" name="postid" value="<?php echo get_the_ID();?>">
566
		<input type="hidden" name="nonce" value="<?php echo $nonce;?>">
567
		<input type="hidden" name="action" value="process_map_save">
568
		<input type="submit" class="lasso--map-form__submit" value="<?php esc_attr_e( 'Save Locations', 'lasso' );?>">
569
	</div>
570
571
	<?php return ob_get_clean();
572
573
}
574
575
/**
576
 * Some things aren't real-time updatable so we need to append a message in certain areas on certain actions
577
 *
578
 * @since 1.0
579
 */
580
function lasso_editor_refresh_message() {
581
582
	ob_start();
583
584
	?>
585
	<div id="lasso--pagerefresh" class="visible">
586
		<?php _e( 'Save this post and refesh the page to see these changes.', 'lasso' );?>
587
	</div>
588
589
	<?php return ob_get_clean();
590
}
591
592
/**
593
 * Draw out the settings field based on the shortcodes array with options foudn in Lasso Story Engine
594
 *  This was mostly backported from lasso story engine and modified to allow for non lasso shortcodes and components
595
 *
596
 * @since 1.0
597
 */
598
function lasso_editor_options_blob() {
599
600
	$codes   = function_exists( 'aesop_shortcodes' ) ? aesop_shortcodes() : apply_filters( 'lasso_custom_options', '' );
601
	$galleries  = function_exists( 'lasso_editor_galleries_exist' ) && lasso_editor_galleries_exist() ? 'has-galleries' : 'creating-gallery';
602
603
	$nonce = wp_create_nonce( 'lasso_gallery' );
604
605
	$blob = array();
606
607
	if ( empty( $codes ) )
608
		return;
609
610
	foreach ( $codes as $slug => $shortcode ) {
611
		$return = '';
612
		// Shortcode has atts
613
614
		if ( count( $shortcode['atts'] ) && $shortcode['atts'] ) {
615
616
			foreach ( $shortcode['atts'] as $attr_name => $attr_info ) {
617
618
619
				$prefix = isset( $attr_info['prefix'] ) ? sprintf( '<span class="lasso-option-prefix">%s</span>', $attr_info['prefix'] ) : null;
620
621
				$return .= '<form id="lasso--component-settings-form" class="'.$galleries.'" method="post">';
622
				$return .= '<p data-option="'.$attr_name.'" class="lasso-option lasso-'.$slug.'-'.$attr_name.'">';
623
				$return .= '<label for="lasso-generator-attr-' . $attr_name . '">' . $attr_info['desc'] . '</label>';
624
				$return .= '<small class="lasso-option-desc">'.$attr_info['tip'].'</small>';
625
				// Select
626
627
				if ( isset( $attr_info['values'] ) ) {
628
629
					$return .= '<select name="' . $attr_name . '" id="lasso-generator-attr-' . $attr_name . '" class="lasso-generator-attr">';
630
631
					$i=0;
632
633
					foreach ( $attr_info['values'] as $attr_value ) {
634
						$attr_value_selected = $attr_info['default'] == $attr_value ? ' selected="selected"' : '';
635
636
						$return .= '<option value="'.$attr_info['values'][$i]['value'].'" ' . $attr_value_selected . '>'.$attr_info['values'][$i]['name'].'</option>';
637
638
						$i++;
639
					}
640
641
					$return .= '</select>';
642
643
				} else {
644
645
					$attr_field_type = isset( $attr_info['type'] ) ? $attr_info['type'] : 'text';
646
647
					// image upload
648
					if ( 'media_upload' == $attr_info['type'] ) {
649
650
						$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.'" />';
651
						$return .= '<a href="#" id="lasso-upload-img" class="lasso-option-button" /></a>';
652
653
					} elseif ( 'color' == $attr_info['type'] ) {
654
655
						$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.'" />';
656
657
					} elseif ( 'text_area' == $attr_info['type'] ) {
658
659
						$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.'';
660
661
					} else {
662
						$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.'';
663
					}
664
				}
665
				$return .= '</p>';
666
667
			}
668
		}
669
670
		///////////////////////////
671
		// START GALLERY AND MAP FRONT END STUFFS
672
		///////////////////////////
673
		if ( isset( $shortcode['front'] ) && true == $shortcode['front'] ) {
674
675
			if ( 'gallery' == $shortcode['front_type'] ) {
676
677
				$return .= lasso_gallery_editor_module();
678
679
			}
680
		}
681
		///////////////////////////
682
		// END GALLERY AND MAP FRONT END STUFFS
683
		///////////////////////////
684
685
		// Single shortcode (not closed)
686
		if ( 'single' == $shortcode['type'] ) {
687
688
			$return .= '<input type="hidden" name="lasso-generator-content" id="lasso-generator-content" value="false" />';
689
690
		} else {
691
692
			$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>';
693
		}
694
695
		$return .= '<p class="lasso-buttoninsert-wrap"><a href="#" class="lasso-generator-cancel" id="lasso--sidebar__close">Cancel
696
</a><input type="submit" id="lasso-generator-insert" value="Save Settings"></p>';
697
		$return .= '<input class="component_type" type="hidden" name="component_type" value="">';
698
		$return .= '<input type="hidden" name="unique" value="">';
699
		$return .= '<input type="hidden" name="nonce" id="lasso-generator-nonce" value="'.$nonce.'" />';
700
		$return .= '</form>';
701
702
		$blob[$slug] = $return;
703
	}
704
705
	return $blob;
706
}
707
708
/**
709
 * Revisions modal
710
 *
711
 * @since 0.9.8
712
 *
713
 * @return string
714
 */
715
function lasso_editor_revision_modal() {
716
717
	ob_start();
718
	?>
719
		<div id="lasso--revision__modal" class="lasso--modal lassoShowAnimate ">
720
721
			<div class="lasso--modal__inner">
722
				<div id="lasso--loading" class="lasso--loading"><div class="lasso--loader"></div></div>
723
				<div id="lasso--hide" style="display:none;" class="lasso--post-form">
724
					<i class="lasso-icon lasso-icon-move"></i>
725
					<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>
726
					<div class="lasso--slider_wrap">
727
						<div id="lasso--slider"></div>
728
					</div>
729
					<ul id="lasso--revision-list"></ul>
730
					<div class="lasso--btn-group lasso--btn-group-small">
731
						<a href="#" class="lasso--btn-secondary" id="lasso--close-modal">Cancel</a>
732
						<a href="#" class="lasso--btn-primary" id="lasso--select-revision">Select</a>
733
					</div>
734
				</div>
735
736
			</div>
737
		</div>
738
	<?php
739
	return ob_get_clean();
740
}
741