Completed
Push — master ( 13652e...8e57b5 )
by
unknown
01:51
created

components.php ➔ lasso_editor_components()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 79
Code Lines 57

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 57
nc 1
nop 0
dl 0
loc 79
rs 8.8701
c 0
b 0
f 0

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 15 and the first side effect is on line 123.

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
 * The functions in this file register the components that will be shown in the component drop-up menu
4
 * and are filterable and pluggable
5
 *
6
 */
7
8
/**
9
 * Build an array of components that will be shown in the
10
 * component drop-up menu on click
11
 *
12
 * @return array of components
13
 * @since 1.0
14
 */
15
function lasso_editor_components() {
16
17
	$array = array(
18
		'quote' => array(
19
			'name'    => __('Quote','lasso'),
20
			'content' => lasso_quote_component(),
21
		),
22
		'image' => array(
23
			'name'    => __('Image','lasso'),
24
			'content' => lasso_image_component(),
25
		),
26
		'parallax' => array(
27
			'name'    => __('Parallax','lasso'),
28
			'content' => lasso_parallax_component(),
29
		),
30
		'audio' => array(
31
			'name'    => __('Audio','lasso'),
32
			'content' => lasso_audio_component(),
33
		),
34
		'content' => array(
35
			'name'    => __('Content','lasso'),
36
			'content' => lasso_content_component(),
37
		),
38
		'character' => array(
39
			'name'    => __('Character','lasso'),
40
			'content' => lasso_character_component(),
41
		),
42
		'collection' => array(
43
			'name'    => __('Collection','lasso'),
44
			'content' => lasso_collections_component(),
45
		),
46
		'document' => array(
47
			'name'    => __('Document','lasso'),
48
			'content' => lasso_document_component(),
49
		),
50
		'gallery' => array(
51
			'name'    => __('Gallery','lasso'),
52
			'content' => lasso_gallery_component(),
53
		),
54
		'chapter' => array(
55
			'name'    => __('Chapter','lasso'),
56
			'content' => lasso_heading_component(),
57
		),
58
		'map' => array(
59
			'name'    => __('Map','lasso'),
60
			'content' => lasso_map_component(),
61
		),
62
		'timeline_stop' => array(
63
			'name'    => __('Timeline','lasso'),
64
			'content' => lasso_timeline_component(),
65
		),
66
		'video' => array(
67
			'name'    => __('Video','lasso'),
68
			'content' => lasso_video_component(),
69
		),
70
		'wpimg' => array(
71
			'name'    => __('WordPress Image','lasso'),
72
			'content' => lasso_wp_image(),
73
		),
74
		'wpquote' => array(
75
			'name'    => __('WordPress Quote','lasso'),
76
			'content' => lasso_wp_quote(),
77
		),
78
		'gallery_pop' => array(
79
			'name'    => __('Gallery Pop','lasso'),
80
			'content' => lasso_gallery_pop_component(),
81
		),
82
		'events' => array(
83
			'name'    => __('Events','lasso'),
84
			'content' => lasso_event_component(),
85
		),
86
		'wpvideo' => array(
87
			'name'    => __('WordPress Image','lasso'),
88
			'content' => lasso_wp_video(),
89
		),
90
	);
91
92
	return apply_filters( 'lasso_components', $array );
93
}
94
95
/**
96
 * Here each of the components content is being registered and retrieved above
97
 *
98
 * Notes:  - these functions are pluggable
99
 *     - custom modules must have data-component-type="whatever"
100
 *   - custom modules must have all options as data-attributes if utilizing settings panel
101
 *
102
 * 1.  Quote
103
 * 2.  Image
104
 * 3. Parallax
105
 * 4. Audio
106
 * 5. Content
107
 * 6. Character
108
 * 7. Collections
109
 * 8. Document
110
 * 9. Gallery
111
 * 10. Heading
112
 * 11. Map
113
 * 12. Timeline
114
 * 13. Video
115
 */
116
117
// 1
118
if ( !function_exists( 'lasso_quote_component' ) ):
119
	function lasso_quote_component() {
120
121
		return do_shortcode( '[aesop_quote quote="The Universe is made of stories, not of atoms."]' );
122
	}
123
endif;
124
125
// 2
126
if ( !function_exists( 'lasso_image_component' ) ):
127
	function lasso_image_component() {
128
129
		return do_shortcode( '[aesop_image img="'.LASSO_URL.'/public/assets/img/empty-img.png" align="center" imgwidth="800px"]' );
130
	}
131
endif;
132
133
// 3
134
if ( !function_exists( 'lasso_parallax_component' ) ):
135
	function lasso_parallax_component() {
136
137
		return do_shortcode( '[aesop_parallax img="'.LASSO_URL.'/public/assets/img/empty-img.png"]' );
138
	}
139
endif;
140
141
// 4
142
if ( !function_exists( 'lasso_audio_component' ) ):
143
	function lasso_audio_component() {
144
145
		return do_shortcode( '[aesop_audio src="http://users.skynet.be/fa046054/home/P22/track06.mp3"]' );
146
147
	}
148
endif;
149
150
// 5
151
if ( !function_exists( 'lasso_content_component' ) ):
152
	function lasso_content_component() {
153
154
		return do_shortcode( '[aesop_content]Start typing here...[/aesop_content]' );
155
	}
156
endif;
157
158
// 6
159
if ( !function_exists( 'lasso_character_component' ) ):
160
	function lasso_character_component() {
161
162
		return do_shortcode( '[aesop_character img="'.LASSO_URL.'/public/assets/img/empty-img.png" name="Joes Apartment" width="150px"]' );
163
164
	}
165
endif;
166
167
// 7
168
if ( !function_exists( 'lasso_collections_component' ) ):
169
	function lasso_collections_component() {
170
171
		return do_shortcode( '[aesop_collection]' );
172
	}
173
endif;
174
175
// 8
176
if ( !function_exists( 'lasso_document_component' ) ):
177
	function lasso_document_component() {
178
179
		return do_shortcode( '[aesop_document src="'.LASSO_URL.'/public/assets/img/empty-img.png" ]' );
180
181
	}
182
endif;
183
184
// 9
185
if ( !function_exists( 'lasso_gallery_component' ) ):
186
	function lasso_gallery_component() {
187
188
		return do_shortcode( '[aesop_gallery]' );
189
190
	}
191
endif;
192
193
// 10
194
if ( !function_exists( 'lasso_heading_component' ) ):
195
	function lasso_heading_component() {
196
197
		return do_shortcode( '[aesop_chapter title="Chapter One" img="'.LASSO_URL.'/public/assets/img/empty-img.png" full="on"]' );
198
	}
199
endif;
200
201
// 11
202
if ( !function_exists( 'lasso_map_component' ) ):
203
	function lasso_map_component() {
204
205
		return '<form id="lasso--map-form" class="aesop-component aesop-map-component lasso--map-drag-holder" enctype="multipart/form-data">
206
				'.lasso_map_form_footer().'
207
				'.do_shortcode( '[aesop_map sticky="off"]' ).'
208
			</form>';
209
210
	}
211
endif;
212
213
// 12
214
if ( !function_exists( 'lasso_timeline_component' ) ):
215
	function lasso_timeline_component() {
216
217
		return do_shortcode( '[aesop_timeline_stop num="Title" title="2014"]' );
218
219
	}
220
endif;
221
222
// 13
223
if ( !function_exists( 'lasso_video_component' ) ):
224
	function lasso_video_component() {
225
226
		return do_shortcode( '[aesop_video src="vimeo" id="59940289" width="100%" align="center"]' );
227
228
	}
229
endif;
230
231
// 14 - since 0.9.1
232
if ( !function_exists('lasso_wp_image') ):
233
234
	function lasso_wp_image(){
235
		return '<div data-component-type="wpimg" class="lasso--wpimg__wrap lasso-component"><img class="wp-image-0" src="'.LASSO_URL.'/public/assets/img/empty-img.png"></div>';
236
	}
237
238
endif;
239
240
// 15 - since 0.9.2
241
if ( !function_exists('lasso_wp_quote') ):
242
243
	function lasso_wp_quote(){
244
		return '<blockquote data-component-type="wpquote" class="lasso--wpquote lasso-component"><p>The universe is made of stories.</p></blockquote>';
245
	}
246
247
endif;
248
249
// 16 gallery pop added but not fully supported as of 0.9.9.11 
250
251
if ( !function_exists( 'lasso_gallery_pop_component' ) ):
252
	function lasso_gallery_pop_component() {
253
		return do_shortcode( '[aesop_gallery_pop]' );
254
	}
255
endif;
256
257
// 17 - work in progress
258
259
if ( !function_exists( 'lasso_event_component' ) ):
260
	function lasso_event_component() {
261
		$id = editus_get_one_id('aesop_events');
262
		file_put_contents(WP_PLUGIN_DIR."/file1.txt", $id);
263
		return do_shortcode( '[aesop_events id = "993"]' );
264
		if ($id ==-1) {
0 ignored issues
show
Unused Code introduced by
if ($id == -1) { ret...d = "' . $id . '"]'); } does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
265
			return do_shortcode( '[aesop_events]' );
266
		} else {
267
			return do_shortcode( '[aesop_events id = "'.$id.'"]' );
268
		}
269
	}
270
endif;
271
272
// 18 - work in progress
273
if ( !function_exists('lasso_wp_video') ):
274
275
	function lasso_wp_video(){
276
		return '<div data-component-type="wpvideo" class="lasso--wpvideo__wrap lasso-component"><video class="wp-video-0"></video>';
277
	}
278
279
endif;
280
281
// helper function to retrieve one id for default option
282
function editus_get_one_id($type)
283
{
284
	$args = array( 'posts_per_page' => 1, 'post_type' => $type );
285
	$posts = get_posts( $args );
286
	if ( $posts ) {
287
		foreach ( $posts as $post ) {
288
			return $post->ID;
289
		}
290
	}
291
	return -1;
292
}
293
294
295