Completed
Push — master ( e528e5...1c19be )
by
unknown
01:47
created

editor-modules.php ➔ lasso_editor_component_modal()   F

Complexity

Conditions 16
Paths 513

Size

Total Lines 138
Code Lines 72

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 16
eloc 72
nc 513
nop 0
dl 0
loc 138
rs 2.9814
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
		$is_mobile = wp_is_mobile();
48
		
49
		$mobile_style = $is_mobile ? 'style="bottom:0px;"' : null;
50
		
51
52
		?><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();?>" >
53
54
			<ul class="lasso--controls__center lasso-editor-controls lasso-editor-controls--wrap <?php echo $post_access_class;?> "  <?php echo $mobile_style ?> >
55
56
				<?php do_action( 'lasso_editor_controls_before' );
57
58
				if ( $is_capable ) { ?>
59
60
					<li id="lasso--edit" title="<?php esc_attr_e( 'Edit Post', 'lasso' );?>"><a href="#" class="lasso--button__primary"></a></li>
61
62
					<?php if ( 'off' == $post_settings_disabled || empty( $post_settings_disabled ) ) { ?>
63
						<li id="lasso--post-settings" title="<?php esc_attr_e( 'Post Settings', 'lasso' );?>"><a href="#" class="lasso--button__primary"></a></li>
64
					<?php }
65
66
				} ?>
67
68
				<li id="lasso--post-all" title="<?php esc_attr_e( 'All Posts', 'lasso' );?>"><a href="#" class="lasso--button__primary"></a></li>
69
70
				<?php if ( $is_capable && wp_revisions_enabled( $post ) ) { ?>
71
					<li id="lasso--post-revisions" title="<?php esc_attr_e( 'Revisions', 'lasso' );?>"><a href="#" class="lasso--button__primary"></a></li>
72
				<?php } ?>
73
74
				<?php if ( ( 'off' == $post_new_disabled || empty( $post_new_disabled ) && lasso_user_can('publish_posts') ) ) { ?>
75
					<li id="lasso--post-new" title="<?php esc_attr_e( 'Add Post', 'lasso' );?>"><a href="#" class="lasso--button__primary"></a></li>
76
				<?php } ?>
77
78
				<?php do_action( 'lasso_editor_controls_after' );?>
79
80
			</ul>
81
82 View Code Duplication
			<?php if ( is_singular() && !$is_mobile ) { ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
83
84
				<div class="lasso--controls__right" data-posttype="<?php echo get_post_type( get_the_ID() );?>" data-status="<?php echo $status;?>">
85
86
					<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>
87
88
					<?php if ( 'draft' == $status && ( lasso_user_can('publish_posts') || lasso_user_can('publish_pages') )  ) { ?>
89
						<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>
90
					<?php } ?>
91
92
				</div>
93
94
			<?php } ?>
95
96
		</div>
97
98
	<?php }
99
}
100
101
/**
102
 * Draw the side panel that houses the component settings
103
 * This is opened when the settings icon is clicked on a single component
104
 * 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
105
 *
106
 * @since 1.0
107
 */
108
function lasso_editor_component_sidebar() {
109
110
	ob_start();
111
112
	if ( !lasso_user_can() )
113
		return;
114
115
	// let users add custom css classes
116
	$custom_classes = apply_filters( 'lasso_sidebar_classes', '' );
117
	?>
118
	<div id="lasso--sidebar" class="<?php echo sanitize_html_class( $custom_classes );?>" >
119
		<div class="lasso--sidebar__inner">
120
			<div id="lasso--component__settings"></div>
121
		</div>
122
	</div>
123
124
	<?php return ob_get_clean();
125
}
126
127
/**
128
 * Draw the main toolbar used to edit the text
129
 *
130
 * @since 1.0
131
 */
132
function lasso_editor_text_toolbar() {
133
134
	ob_start();
135
136
	if ( !lasso_user_can() )
137
		return;
138
	
139
	$is_mobile = wp_is_mobile();
140
141
	// check for lasso story engine and add a class doniting this
142
	$ase_status = class_exists( 'Aesop_Core' ) || defined( 'LASSO_CUSTOM' ) ? 'ase-active' : 'ase-not-active';
143
144
	// let users add custom css classes
145
	$custom_classes = apply_filters( 'lasso_toolbar_classes', '' );
146
147
	// are toolbar headings enabled
148
	$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...
149
	$toolbar_headings_h4      = lasso_editor_get_option( 'toolbar_headings_h4', 'lasso_editor' );
0 ignored issues
show
Documentation introduced by
'toolbar_headings_h4' 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...
150
151
	$toolbar_class  = $toolbar_headings ? 'toolbar-extended' : false;
152
	
153
	// mobile styles
154
    $mobile_class = $is_mobile ? 'lasso-mobile' : false;
155
	$mobile_style =$is_mobile ? 'style="bottom:0px;"' : null;
156
	
157
	//show color
158
	$show_color = lasso_editor_get_option('toolbar_show_color', 'lasso_editor');
0 ignored issues
show
Documentation introduced by
'toolbar_show_color' 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...
159
	
160
	//show alignment
161
	$show_align = lasso_editor_get_option('toolbar_show_alignment', 'lasso_editor');
0 ignored issues
show
Documentation introduced by
'toolbar_show_alignment' 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...
162
	
163
	$status = get_post_status( get_the_ID() );
164
165
166
	?>
167
	<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 ?>>
168
		<ul class="lasso--toolbar__inner lasso-editor-controls" <?php if ($is_mobile) {echo 'style="float:left;"';}?>>
169
			<?php do_action( 'lasso_toolbar_components_before' );?>
170
		    <li id="lasso-toolbar--bold" title="<?php esc_attr_e( 'Bold', 'lasso' );?>"></li>
171
		    <li id="lasso-toolbar--underline" title="<?php esc_attr_e( 'Underline', 'lasso' );?>"></li>
172
		    <li id="lasso-toolbar--italic" title="<?php esc_attr_e( 'Italicize', 'lasso' );?>"></li>
173
		    <li id="lasso-toolbar--strike" title="<?php esc_attr_e( 'Strikethrough', 'lasso' );?>"></li>
174
		    <?php if ( $toolbar_headings ): ?>
175
		    <li id="lasso-toolbar--h2" title="<?php esc_attr_e( 'H2 Heading', 'lasso' );?>"></li>
176
		    <li id="lasso-toolbar--h3" title="<?php esc_attr_e( 'H3 Heading', 'lasso' );?>"></li>
177
			<?php endif; ?>
178 View Code Duplication
			<?php if ( $toolbar_headings_h4 ): ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
179
		    <li id="lasso-toolbar--h4" title="<?php esc_attr_e( 'H4 Heading', 'lasso' );?>"></li>
180
		    <li id="lasso-toolbar--h5" title="<?php esc_attr_e( 'H5 Heading', 'lasso' );?>"></li>
181
			<li id="lasso-toolbar--h6" title="<?php esc_attr_e( 'H6 Heading', 'lasso' );?>"></li>
182
			<?php endif; ?>
183
			
184
			<?php if ( $show_color ): ?>
185
		    <li id="lasso-toolbar--color-set" title="<?php esc_attr_e( 'Set Text Color', 'lasso' );?>"></li>
186
		    <li id="lasso-toolbar--color-pick" title="<?php esc_attr_e( 'Choose Color', 'lasso' );?>"></li>
187
			<?php endif; ?>
188
					
189
		    <li id="lasso-toolbar--components" title="<?php esc_attr_e( 'Insert Component', 'lasso' );?>">
190
			    <ul id="lasso-toolbar--components__list" style="display:none;">
191
			    	<?php if ( 'ase-active' == $ase_status ): ?>
192
						<li data-type="image" title="<?php esc_attr_e( 'Image', 'lasso' );?>" class="lasso-toolbar--component__image"></li>
193
						<li data-type="character" title="<?php esc_attr_e( 'Character', 'lasso' );?>" class="lasso-toolbar--component__character"></li>
194
						<li data-type="quote" title="<?php esc_attr_e( 'Quote', 'lasso' );?>"  class="lasso-toolbar--component__quote"></li>
195
						<li data-type="content" title="<?php esc_attr_e( 'Content', 'lasso' );?>"  class="lasso-toolbar--component__content"></li>
196
						<li data-type="chapter" title="<?php esc_attr_e( 'Chapter', 'lasso' );?>"  class="lasso-toolbar--component__chapter"></li>
197
						<li data-type="parallax" title="<?php esc_attr_e( 'Parallax', 'lasso' );?>"  class="lasso-toolbar--component__parallax"></li>
198
						<li data-type="audio" title="<?php esc_attr_e( 'Audio', 'lasso' );?>"  class="lasso-toolbar--component__audio"></li>
199
						<li data-type="video" title="<?php esc_attr_e( 'Video', 'lasso' );?>"  class="lasso-toolbar--component__video"></li>
200
						<li data-type="map" title="<?php esc_attr_e( 'Map', 'lasso' );?>"  class="lasso-toolbar--component__map"></li>
201
						<li data-type="timeline_stop" title="<?php esc_attr_e( 'Timeline', 'lasso' );?>"  class="lasso-toolbar--component__timeline"></li>
202
						<li data-type="document" title="<?php esc_attr_e( 'Document', 'lasso' );?>"  class="lasso-toolbar--component__document"></li>
203
						<li data-type="collection" title="<?php esc_attr_e( 'Collection', 'lasso' );?>"  class="lasso-toolbar--component__collection"></li>
204
						<li data-type="gallery" title="<?php esc_attr_e( 'Gallery', 'lasso' );?>"  class="lasso-toolbar--component__gallery"></li>
205
						<?php if ( class_exists ('Aesop_GalleryPop') ) { ?>
206
						     <li data-type="gallery" title="<?php esc_attr_e( 'Gallery Pop', 'lasso' );?>"  class="lasso-toolbar--component__gallerypop"></li>
207
						<?php }?>
208 View Code Duplication
					<?php else: ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
209
						<li data-type="wpimg" title="<?php esc_attr_e( 'WordPress Image', 'lasso' );?>" class="image lasso-toolbar--component__image"></li>
210
						<li data-type="wpquote" title="<?php esc_attr_e( 'WordPress Quote', 'lasso' );?>" class="quote lasso-toolbar--component__quote"></li>
211
						<!--li data-type="wpvideo" title="<?php esc_attr_e( 'WordPress Video', 'lasso' );?>" class="video lasso-toolbar--component__video"></li-->
212
					<?php endif; ?>
213
					<?php do_action( 'lasso_toolbar_components' );?>
214
			    </ul>
215
			</li>
216
			<li id="lasso-toolbar--link" title="<?php esc_attr_e( 'Anchor Link', 'lasso' );?>">
217
		    	<div id="lasso-toolbar--link__wrap" <?php echo $mobile_style ?> >
218
		    		<div id="lasso-toolbar--link__inner" contenteditable="true" placeholder="<?php esc_attr_e( 'http://url.com', 'lasso' );?>"></div>
219
		    		<a href="#" title="<?php esc_attr_e( 'Create Link', 'lasso' );?>" class="lasso-toolbar--link__control" id="lasso-toolbar--link__create" ></a>
220
					<input class="styled-checkbox" type="checkbox" id="aesop-toolbar--link_newtab" checked/>
221
                    <label for="aesop-toolbar--link_newtab">Open in Another Tab</label>
222
		    	</div>
223
		    </li>
224
		    <?php do_action( 'lasso_toolbar_components_after' );?>
225
		    <li id="lasso-toolbar--html" title="<?php esc_attr_e( 'Insert HTML', 'lasso' );?>">
226
		    	<div id="lasso-toolbar--html__wrap" <?php echo $mobile_style ?>>
227
		    		<div id="lasso-toolbar--html__inner" contenteditable="true" placeholder="<?php esc_attr_e( 'Enter HTML to insert', 'lasso' );?>"></div>
228
		    		<div id="lasso-toolbar--html__footer">
229
		    			<ul class="lasso-toolbar--html-snips">
230
		    				<?php if ( !$toolbar_headings ): ?>
231
		    				<li id="lasso-html--h2" title="<?php esc_attr_e( 'H2 Heading', 'lasso' );?>">
232
		    				<li id="lasso-html--h3" title="<?php esc_attr_e( 'H3 Heading', 'lasso' );?>">
233
		    				<?php endif; ?>
234
		    				<li id="lasso-html--ul" title="<?php esc_attr_e( 'Unordered List', 'lasso' );?>">
235
		    				<li id="lasso-html--ol" title="<?php esc_attr_e( 'Ordered List', 'lasso' );?>">
236
		    			</ul>
237
		    			<a class="lasso-toolbar--html__control lasso-toolbar--html__cancel" href="#"><?php _e( 'Cancel', 'lasso' );?></a>
238
		    			<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>
239
		    		</div>
240
		    	</div>
241
		    </li>
242 View Code Duplication
			<?php if ( $show_align ): ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
243
		    <li id="lasso-toolbar--left-align" title="<?php esc_attr_e( 'Text Left Align', 'lasso' );?>"></li>
244
		    <li id="lasso-toolbar--center-align" title="<?php esc_attr_e( 'Text Center Align', 'lasso' );?>"></li>
245
			<li id="lasso-toolbar--right-align" title="<?php esc_attr_e( 'Text Right Align', 'lasso' );?>"></li>
246
			<?php endif; ?>
247
		</ul>
248 View Code Duplication
		<?php if ( is_singular() && $is_mobile ) { ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
249
250
				<div class="lasso--controls__right" data-posttype="<?php echo get_post_type( get_the_ID() );?>" data-status="<?php echo $status;?>" style="position:static;bottom:0px;right;0px;left:auto;">
251
252
					<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>
0 ignored issues
show
Bug introduced by
The variable $sc_saving_class does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
253
254
					<?php if ( 'draft' == $status && ( lasso_user_can('publish_posts') || lasso_user_can('publish_pages') )  ) { ?>
255
						<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>
256
					<?php } ?>
257
258
				</div>
259
260
		<?php } ?>
261
	</div>
262
263
	<?php return ob_get_clean();
264
}
265
266
/**
267
 * Draw the controls used for teh component settings within each component
268
 *
269
 * @since 1.0
270
 */
271
function lasso_editor_settings_toolbar() {
272
273
	$delete_nonce = wp_create_nonce( 'lasso-delete-nonce' );
274
275
	ob_start();
276
277
	if ( !lasso_user_can() )
278
		return;
279
280
	// let users add custom css classes
281
	$custom_classes = apply_filters( 'lasso_component_classes', '' );
282
283
	?>
284
	<ul class="lasso-component--controls <?php echo sanitize_html_class( $custom_classes );?>" contenteditable="false">
285
		<li class="lasso-drag" title="<?php esc_attr_e( 'Move', 'lasso' );?>"></li>
286
		<li id="lasso-component--settings__trigger" class="lasso-settings" title="<?php esc_attr_e( 'Settings', 'lasso' );?>"></li>
287
		<li class="lasso-clone" title="<?php esc_attr_e( 'Clone', 'lasso' );?>"></li>
288
		<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>
289
	</ul>
290
291
	<?php return ob_get_clean();
292
}
293
294
/**
295
 * Draws the controls used for changing the featured image
296
 *   These controls are appended based on the class set in the define
297
 *
298
 * @since 1.0
299
 */
300
function lasso_editor_image_controls() {
301
302
	ob_start();
303
304
	if ( !lasso_user_can() )
305
		return;
306
307
	// has post thumbnail
308
	$has_thumbnail = has_post_thumbnail( get_the_ID() ) ? 'class="lasso--featImg--has-thumb"' : false;
309
310
	?>
311
	<ul id="lasso--featImgControls" <?php echo $has_thumbnail;?>>
312
		<li id="lasso--featImgUpload"><a title="<?php esc_attr_e( 'Replace Image', 'lasso' );?>" href="#"><i class="lasso-icon-image"></i></a></li>
313
		<li id="lasso--featImgDelete"><a title="<?php esc_attr_e( 'Delete Image', 'lasso' );?>" href="#"><i class="lasso-icon-bin2"></i></a></li>
314
		<li id="lasso--featImgSave"><a href="#"><?php esc_attr_e( 'save', 'lasso' );?></a></li>
315
	</ul>
316
317
	<?php return ob_get_clean();
318
}
319
320
321
/**
322
 * Used to house post settings like scheduling, slugs and draft status
323
 * Note: the "add new" will use the same object as the currently shown. For example, if the user
324
 * is currently on a post, and clicks add new, then it'll add a new post. If the user is on a
325
 * post type like "dog", then it will create a new post type called "dog"
326
 *
327
 * @since 1.0
328
 */
329
function lasso_editor_component_modal() {
330
331
	ob_start();
332
333
	if ( !lasso_user_can() )
334
		return;
335
336
	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...
337
338
	$postid = get_the_ID();
339
340
	$status = get_post_status( $postid );
341
	$nonce = wp_create_nonce( 'lasso-update-post-settings' );
342
343
	// let users add custom css classes
344
	$custom_classes = apply_filters( 'lasso_modal_settings_classes', '' );
345
346
	// objects categories
347
	$categories 		= lasso_get_post_objects( $postid, 'category' );
348
	$tags 				= lasso_get_post_objects( $postid, 'tag' );
349
350
	// modal tabs
351
	$tabs  				= lasso_modal_addons('tab');
352
	$content 			= lasso_modal_addons('content');
353
354
	// are we singular
355
	$is_singular 		= is_singular();
356
	$is_singular_class 	= $is_singular ? 'lasso--postsettings__2col' : 'lasso--postsettings__1col';
357
	$has_thumb_class    = has_post_thumbnail() ? 'has-thumbnail' : 'no-thumbnail';
358
	$theme_supports     = current_theme_supports('post-thumbnails');
359
	$default_image 		= LASSO_URL.'/admin/assets/img/empty-img.png';
360
361
?>
362
	<div id="lasso--post-settings__modal" class="lasso--modal lassoShowAnimate <?php echo sanitize_html_class( $custom_classes );?>">
363
		<div class="lasso--modal__inner">
364
365
			<?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...
366
367
			<div class="lasso--modal__content modal__content--core visible" data-addon-content="core">
368
				<form id="lasso--postsettings__form" enctype="multipart/form-data" class="lasso--post-form <?php echo $is_singular_class.' '.$has_thumb_class;?>" >
369
370
					<?php if ( $is_singular && $theme_supports ) : ?>
371
					<div class="lasso--postsettings__left">
372
						<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>
373
						<div class="lasso--post-thumb" data-default-thumb="<?php echo esc_url( $default_image );?>">
374
375
							<div id="lasso--post-thumb__controls" class="lasso--post-thumb__controls">
376
								<i id="lasso--post-thumb__add" title="<?php _e('Change Featured Image','lasso');?>" class="dashicons dashicons-edit"></i>
377
								<i id="lasso--post-thumb__delete" title="<?php _e('Delete Featured Image','lasso');?>" class="dashicons dashicons-no-alt"></i>
378
								<i id="lasso--save-status" class="lasso-icon lasso-icon-spinner6 not-visible"></i>
379
							</div>
380
381
							<?php echo has_post_thumbnail() ? get_the_post_thumbnail( $post->ID, 'medium' ) : '<img src="'.$default_image.'">'; ?>
382
383
						</div>
384
						<div id="lasso--featImgSave"><a href="#" class="not-visible">Save</a></div>
385
386
					</div>
387
					<?php endif; ?>
388
389
					<div class="lasso--postsettings__right">
390
391
						<?php if( lasso_user_can('publish_posts') || lasso_user_can('publish_pages') ): ?>
392
						<div class="lasso--postsettings__option story-status-option">
393
							<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>
394
							<ul class="story-status story-status-<?php echo sanitize_html_class( $status );?>">
395
								<li id="lasso--status-draft"><?php _e( 'Draft', 'lasso' );?></li>
396
								<li id="lasso--status-publish"><?php _e( 'Publish', 'lasso' );?></li>
397
							</ul>
398
							<div class="lasso--slider_wrap">
399
								<div id="lasso--slider"></div>
400
							</div>
401
						</div>
402
						<?php endif; ?>
403
404
						<?php if ( 'publish' == $status ): ?>
405
						<div class="lasso--postsettings__option story-slug-option">
406
							<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>
407
							<input class="lasso--modal__trigger-footer" type="text" name="story_slug" value="<?php echo isset( $post ) ? esc_attr( $post->post_name ) : false;?>">
408
						</div>
409
						<?php endif; ?>
410
411
					</div>
412
413
					<div class="lasso--postsettings__middle">
414
415
						<div class="lasso--postsettings__option story-categories-option">
416
							<label style="width:120px;"><?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>
417
							<input id="lasso--cat-select" class="lasso--modal__trigger-footer" type="hidden" name="story_cats" value="<?php echo $categories;?>">
418
						</div>
419
420
						<div class="lasso--postsettings__option story-tags-option">
421
							<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>
422
							<input id="lasso--tag-select" class="lasso--modal__trigger-footer" type="hidden" name="story_tags" value="<?php echo $tags;?>">
423
						</div>
424
425
					</div>
426
					<div style="max-height:300px;overflow-y: scroll;">
427
                    <?php
428
							$allcats = explode(",",lasso_get_objects('category'));
429
							$currcats = explode(",",$categories);
430
							foreach ( $allcats  as $category ) {
431
								if (empty($category)) continue;
432
							   $checked ="";
433
							   if (  in_array( $category, $currcats ) ) {
434
									$checked = 'checked="checked"';
435
									
436
							   }
437
							   echo '<label><input type="checkbox" '.$checked.' name="categories" id="'.$category.'" >'.$category.'</label>';
438
							}
439
					?>
440
					</div>
441
442
					<?php do_action( 'lasso_modal_post_form' ); // action ?>
443
444
					<div class="lasso--postsettings__footer" >
445
						<a href="#" class="lasso--postsettings-cancel"><?php _e( 'Cancel', 'lasso' );?></a>
446
						<input type="hidden" name="status" value="">
447
						<input type="hidden" name="categories" value="">
448
						<input type="hidden" name="postid" value="<?php echo get_the_ID();?>">
449
						<input type="hidden" name="action" value="process_update-object_post">
450
						<input type="hidden" name="nonce" value="<?php echo $nonce;?>">
451
						<?php do_action( 'lasso_modal_post_form_footer' ); // action ?>
452
						<input type="submit" value="<?php esc_attr_e( 'Save', 'lasso' );?>">
453
					</div>
454
455
				</form>
456
			</div>
457
458
			<?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...
459
460
		</div>
461
462
	</div>
463
	<div id="lasso--modal__overlay"></div>
464
465
	<?php return ob_get_clean();
466
}
467
468
/**
469
 * Used to house the form for creating a new post within amodal
470
 *
471
 * @since 1.0
472
 */
473
function lasso_editor_newpost_modal() {
474
475
	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...
476
477
	ob_start();
478
479
	if ( !lasso_user_can('edit_posts') )
480
		return;
481
482
	$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...
483
484
	$nonce = wp_create_nonce( 'lasso-editor-new-post' );
485
486
	// let users add custom css classes
487
	$custom_classes = apply_filters( 'lasso_modal_post_classes', '' );
488
489
	// return the post type
490
	$type = get_post_type( get_the_ID() );
491
492
	if (wp_is_mobile()) {
493
		$mobile_style = 'style="top:140px !important;"';
494
	}
495
	?>
496
	<div id="lasso--post-new__modal" class="lasso--modal lasso--modal__med lassoShowAnimate <?php echo sanitize_html_class( $custom_classes );?>" <?php echo $mobile_style;?>">
0 ignored issues
show
Bug introduced by
The variable $mobile_style does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
497
		<div class="lasso--modal__inner">
498
499
			<form id="lasso--postnew__form" enctype="multipart/form-data" class="lasso--post-form">
500
501
				<div class="lasso--postsettings__option story-slug-option lasso--last-option">
502
					<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>
503
					<input class="lasso--modal__trigger-footer" type="text" required name="story_title" value="" placeholder="<?php esc_attr_e( 'Grump Wizards Make Toxic Brew', 'lasso' );?>">
504
						<div class="lasso--select-wrap" style="width:90px">
505
						<select id="lasso--select-type" name="story_type">
506
507
							<?php
508
								$types = lasso_post_types();
509
510
								if ( !empty( $types ) ) {
511
512
									foreach( $types as $type ) {
513
514
										$type = preg_replace( '/s\b/','', $type );
515
516
										printf( '<option value="%s">%s</option>', lcfirst( esc_attr( $type ) ) , ucfirst( esc_attr( $type ) ) );
517
									}
518
519
								}
520
							?>
521
522
						</select>
523
					</div>
524
				</div>
525
526
				<div class="lasso--postsettings__footer" style="<?php if (!wp_is_mobile()) {echo 'display:none;';} ?>">
527
					<a href="#" class="lasso--postsettings-cancel"><?php _e( 'Cancel', 'lasso' );?></a>
528
					<input type="hidden" name="action" value="process_new-object_post">
529
					<input type="hidden" name="object" value="post">
530
					<input type="hidden" name="nonce" value="<?php echo $nonce;?>">
531
					<input type="submit" value="<?php esc_attr_e( 'Create', 'lasso' );?>">
532
				</div>
533
534
			</form>
535
536
		</div>
537
	</div>
538
	<div id="lasso--modal__overlay"></div>
539
540
	<?php return ob_get_clean();
541
}
542
543
/**
544
 * Used to house the all posts pop-up
545
 *
546
 * @since 0.9.3
547
 */
548
function lasso_editor_allpost_modal() {
549
550
	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...
551
	
552
	global $wp_post_types;
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...
553
    $labels = &$wp_post_types['post']->labels;
554
    $labels->name = 'Articles';
555
556
	ob_start();
557
558
	// post status
559
	$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...
560
561
	// let users add custom css classes
562
	$custom_classes = apply_filters( 'lasso_modal_all_post_classes', '' );
563
564
	?>
565
	<div id="lasso--all-posts__modal" class="lasso--modal lasso--modal__full lassoShowAnimate <?php echo sanitize_html_class( $custom_classes );?>" style="max-height:100%">
566
		<div class="lasso--modal__inner">
567
568
			<div class="lasso--post-filtering not-visible">
569
				<div class="lasso--search__results">
570
					<span id="lasso--results-found"></span><?php _e('results found','lasso');?>
571
				</div>
572
				<div class="lasso--search">
573
					<i id="lasso--search__toggle" class="dashicons dashicons-search"></i>
574
					<input id="lasso--search-field" type="text" placeholder="search...">
575
				</div>
576
			</div>
577
578
			<ul class="lasso--post-object-list">
579
				<?php
580
581
				$post_types = lasso_post_types_names();
582
				$rest_bases = lasso_post_types_rest_base();
583
584
				if ( ! empty( $post_types ) ) {
585
					$first = 'active';
586
					foreach( $post_types as $name => $label ) {
587
						printf( '<li class="%1s lasso--show-objects" data-post-type="%2s">%3s</li>', esc_attr( $first), esc_attr( $rest_bases[$name] ), esc_attr( $label ) );
588
						$first = '';
589
					}
590
591
				}
592
593
				do_action('lasso_modal_post_objects');?>
594
595
			</ul>
596
			<div id="lasso--loading" class="lasso--loading"><div class="lasso--loader"></div></div>
597
598
			<ul id="lasso--post-list" class="lasso--post-list"></ul>
599
600
		</div>
601
	</div>
602
	<div id="lasso--modal__overlay"></div>
603
604
	<?php return ob_get_clean();
605
}
606
607 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...
608
609
	ob_start();
610
611
	if ( !lasso_user_can() )
612
		return;
613
614
	// let users add custom css classes
615
	$custom_classes = apply_filters( 'lasso_wpimg_classes', '' );
616
617
	?>
618
	<ul class="lasso-component--controls <?php echo sanitize_html_class( $custom_classes );?>" contenteditable="false">
619
		<li class="lasso-drag" title="<?php esc_attr_e( 'Move', 'lasso' );?>"></li>
620
		<li id="lasso--wpimg-edit" class="lasso-settings" title="<?php esc_attr_e( 'Settings', 'lasso' );?>"></li>
621
		<li class="lasso-clone" title="<?php esc_attr_e( 'Clone', 'lasso' );?>"></li>
622
		<li class="lasso-delete" title="<?php esc_attr_e( 'Delete', 'lasso' );?>"></li>
623
	</ul>
624
625
	<?php return ob_get_clean();
626
}
627
628 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...
629
630
	ob_start();
631
632
	if ( !lasso_user_can() )
633
		return;
634
635
	// let users add custom css classes
636
	$custom_classes = apply_filters( 'lasso_wpimg_classes', '' );
637
638
	?>
639
	<ul class="lasso-component--controls <?php echo sanitize_html_class( $custom_classes );?>" contenteditable="false">
640
		<li class="lasso-drag" title="<?php esc_attr_e( 'Move', 'lasso' );?>"></li>
641
		<li id="lasso--wpvideo-edit" class="lasso-settings" title="<?php esc_attr_e( 'Settings', 'lasso' );?>"></li>
642
		<li class="lasso-clone" title="<?php esc_attr_e( 'Clone', 'lasso' );?>"></li>
643
		<li class="lasso-delete" title="<?php esc_attr_e( 'Delete', 'lasso' );?>"></li>
644
	</ul>
645
646
	<?php return ob_get_clean();
647
}
648
649
/**
650
 * Used to house the hidden input fields for actions and process saving for the map component
651
 *
652
 * @since 1.0
653
 */
654
function lasso_map_form_footer() {
655
656
	$nonce = wp_create_nonce( 'lasso-process-map' );
657
658
	ob_start();
659
660
	?>
661
	<div class="lasso--map-form__footer">
662
		<input type="hidden" name="postid" value="<?php echo get_the_ID();?>">
663
		<input type="hidden" name="nonce" value="<?php echo $nonce;?>">
664
		<input type="hidden" name="action" value="process_map_save">
665
		<input type="submit" class="lasso--map-form__submit" value="<?php esc_attr_e( 'Save Locations', 'lasso' );?>">
666
	</div>
667
668
	<?php return ob_get_clean();
669
670
}
671
672
/**
673
 * Some things aren't real-time updatable so we need to append a message in certain areas on certain actions
674
 *
675
 * @since 1.0
676
 */
677
function lasso_editor_refresh_message() {
678
679
	ob_start();
680
681
	?>
682
	<div id="lasso--pagerefresh" class="visible">
683
		<?php _e( 'Save this post and refesh the page to see these changes.', 'lasso' );?>
684
	</div>
685
686
	<?php return ob_get_clean();
687
}
688
689
/**
690
 * Draw out the settings field based on the shortcodes array with options foudn in Lasso Story Engine
691
 *  This was mostly backported from lasso story engine and modified to allow for non lasso shortcodes and components
692
 *
693
 * @since 1.0
694
 */
695
function lasso_editor_options_blob() {
696
697
	$codes   = function_exists( 'aesop_shortcodes' ) ? aesop_shortcodes() : apply_filters( 'lasso_custom_options', '' );
698
	$galleries  = function_exists( 'lasso_editor_galleries_exist' ) && lasso_editor_galleries_exist() ? 'has-galleries' : 'creating-gallery';
699
700
	$nonce = wp_create_nonce( 'lasso_gallery' );
701
702
	$blob = array();
703
704
	if ( empty( $codes ) )
705
		return;
706
707
	foreach ( $codes as $slug => $shortcode ) {
708
		$return = '';
709
		// Shortcode has atts
710
711
		if ( count( $shortcode['atts'] ) && $shortcode['atts'] ) {
712
713
			foreach ( $shortcode['atts'] as $attr_name => $attr_info ) {
714
715
716
				$prefix = isset( $attr_info['prefix'] ) ? sprintf( '<span class="lasso-option-prefix">%s</span>', $attr_info['prefix'] ) : null;
717
718
				$return .= '<form id="lasso--component-settings-form" class="'.$galleries.'" method="post">';
719
				$return .= '<p data-option="'.$attr_name.'" class="lasso-option lasso-'.$slug.'-'.$attr_name.'">';
720
				$return .= '<label for="lasso-generator-attr-' . $attr_name . '">' . $attr_info['desc'] . '</label>';
721
				$return .= '<small class="lasso-option-desc">'.$attr_info['tip'].'</small>';
722
				// Select
723
724
				if ( isset( $attr_info['values'] ) ) {
725
726
					$return .= '<select name="' . $attr_name . '" id="lasso-generator-attr-' . $attr_name . '" class="lasso-generator-attr">';
727
728
					$i=0;
729
730
					foreach ( $attr_info['values'] as $attr_value ) {
731
						$attr_value_selected = $attr_info['default'] == $attr_value ? ' selected="selected"' : '';
732
733
						$return .= '<option value="'.$attr_info['values'][$i]['value'].'" ' . $attr_value_selected . '>'.$attr_info['values'][$i]['name'].'</option>';
734
735
						$i++;
736
					}
737
738
					$return .= '</select>';
739
740
				} else {
741
742
					$attr_field_type = isset( $attr_info['type'] ) ? $attr_info['type'] : 'text';
743
744
					// image upload
745
					if ( 'media_upload' == $attr_info['type'] ) {
746
747
						$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.'" />';
748
						$return .= '<a href="#" id="lasso-upload-img" class="lasso-option-button" /></a>';
749
750
					} elseif ( 'color' == $attr_info['type'] ) {
751
752
						$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.'" />';
753
754
					} elseif ( 'text_area' == $attr_info['type'] ) {
755
756
						$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.'';
757
758
					} else {
759
						$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.'';
760
					}
761
				}
762
				$return .= '</p>';
763
764
			}
765
		}
766
767
		///////////////////////////
768
		// START GALLERY AND MAP FRONT END STUFFS
769
		///////////////////////////
770
		if ( isset( $shortcode['front'] ) && true == $shortcode['front'] ) {
771
772
			if ( 'gallery' == $shortcode['front_type'] ) {
773
774
				$return .= lasso_gallery_editor_module();
775
776
			}
777
		}
778
		///////////////////////////
779
		// END GALLERY AND MAP FRONT END STUFFS
780
		///////////////////////////
781
782
		// Single shortcode (not closed)
783
		if ( 'single' == $shortcode['type'] ) {
784
785
			$return .= '<input type="hidden" name="lasso-generator-content" id="lasso-generator-content" value="false" />';
786
787
		} else {
788
789
			$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>';
790
		}
791
792
		$return .= '<p class="lasso-buttoninsert-wrap"><a href="#" class="lasso-generator-cancel" id="lasso--sidebar__close">Cancel
793
</a><input type="submit" id="lasso-generator-insert" value="Save Settings"></p>';
794
		$return .= '<input class="component_type" type="hidden" name="component_type" value="">';
795
		$return .= '<input type="hidden" name="unique" value="">';
796
		$return .= '<input type="hidden" name="nonce" id="lasso-generator-nonce" value="'.$nonce.'" />';
797
		$return .= '</form>';
798
799
		$blob[$slug] = $return;
800
	}
801
802
	return $blob;
803
}
804
805
/**
806
 * Revisions modal
807
 *
808
 * @since 0.9.8
809
 *
810
 * @return string
811
 */
812
function lasso_editor_revision_modal() {
813
814
	ob_start();
815
	?>
816
		<div id="lasso--revision__modal" class="lasso--modal lassoShowAnimate ">
817
818
			<div class="lasso--modal__inner">
819
				<div id="lasso--loading" class="lasso--loading"><div class="lasso--loader"></div></div>
820
				<div id="lasso--hide" style="display:none;" class="lasso--post-form">
821
					<i class="lasso-icon lasso-icon-move"></i>
822
					<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>
823
					<div class="lasso--slider_wrap">
824
						<div id="lasso--slider"></div>
825
					</div>
826
					<ul id="lasso--revision-list"></ul>
827
					<div class="lasso--btn-group lasso--btn-group-small">
828
						<a href="#" class="lasso--btn-secondary" id="lasso--close-modal">Cancel</a>
829
						<a href="#" class="lasso--btn-primary" id="lasso--select-revision">Select</a>
830
					</div>
831
				</div>
832
833
			</div>
834
		</div>
835
	<?php
836
	return ob_get_clean();
837
}
838