PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / trunk
Pods – Custom Content Types and Fields vtrunk
trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / ui / admin / shortcode.php
pods / ui / admin Last commit date
callouts 4 months ago upgrade 4 months ago widgets 4 months ago components-admin.php 1 month ago help-addons-row.php 4 months ago help-addons.php 4 months ago help.php 4 months ago postbox-header.php 4 months ago settings-reset.php 4 months ago settings-settings.php 4 months ago settings-tools.php 4 months ago settings.php 4 months ago setup-add.php 4 months ago setup-edit.php 4 months ago shortcode.php 4 months ago view.php 4 months ago
shortcode.php
537 lines
1 <?php
2
3 // Don't load directly.
4 if ( ! defined( 'ABSPATH' ) ) {
5 die( '-1' );
6 }
7
8 // phpcs:ignoreFile WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
9 ?>
10 <script type="text/javascript">
11 var pods_shortcode_first = true;
12
13 jQuery( function ( $ ) {
14 $( '#pods_insert_shortcode' ).on( 'click', function ( e ) {
15 var form = $( '#pods_shortcode_form_element' ), use_case = $( '#pods_use_case_selector' ).val(),
16 pod_select = $( '#pod_select' ).val(), slug = $( '#pod_slug' ).val(),
17 orderby = $( '#pod_orderby' ).val(), limit = $( '#pod_limit' ).val(), where = $( '#pod_where' ).val(),
18 template = '', pods_page = '', template_custom = $( '#pod_template_custom' ).val(),
19 field = $( '#pod_field' ).val(), fields = $( '#pod_fields' ).val(), label = $( '#pod_label' ).val(),
20 thank_you = $( '#pod_thank_you' ).val(), view = $( '#pod_view' ).val(),
21 cache_mode = $( '#pod_cache_mode' ).val(), expires = $( '#pod_expires' ).val();
22 template = $( '#pod_template' ).val();
23
24 <?php if ( class_exists( 'Pods_Pages' ) ) { ?>
25 pods_page = $( '#pods_page' ).val();
26 <?php } ?>
27
28 // Slash and burn
29 pod_select = ( pod_select + '' ).replace( /\\"/g, '\\$&' ).replace( /\u0000/g, '\\0' );
30 slug = ( slug + '' ).replace( /\\"/g, '\\$&' ).replace( /\u0000/g, '\\0' );
31 orderby = ( orderby + '' ).replace( /\\"/g, '\\$&' ).replace( /\u0000/g, '\\0' );
32 limit = ( limit + '' ).replace( /\\"/g, '\\$&' ).replace( /\u0000/g, '\\0' );
33 where = ( where + '' ).replace( /\\"/g, '\\$&' ).replace( /\u0000/g, '\\0' );
34 template = ( template + '' ).replace( /\\"/g, '\\$&' ).replace( /\u0000/g, '\\0' );
35 pods_page = ( pods_page + '' ).replace( /\\"/g, '\\$&' ).replace( /\u0000/g, '\\0' );
36 field = ( field + '' ).replace( /\\"/g, '\\$&' ).replace( /\u0000/g, '\\0' );
37 fields = ( fields + '' ).replace( /\\"/g, '\\$&' ).replace( /\u0000/g, '\\0' );
38 label = ( label + '' ).replace( /\\"/g, '\\$&' ).replace( /\u0000/g, '\\0' );
39 thank_you = ( thank_you + '' ).replace( /\\"/g, '\\$&' ).replace( /\u0000/g, '\\0' );
40 view = ( view + '' ).replace( /\\"/g, '\\$&' ).replace( /\u0000/g, '\\0' );
41 cache_mode = ( cache_mode + '' ).replace( /\\"/g, '\\$&' ).replace( /\u0000/g, '\\0' );
42 expires = ( expires + '' ).replace( /\\"/g, '\\$&' ).replace( /\u0000/g, '\\0' );
43
44 // Validate the form
45 var errors = [];
46
47 switch ( use_case ) {
48 case 'single':
49 if ( !pod_select || !pod_select.length ) {
50 errors.push( "Pod" );
51 }
52 if ( !slug || !slug.length ) {
53 errors.push( "Slug or ID" );
54 }
55 if ( ( !template || !template.length ) && ( !template_custom || !template_custom.length) ) {
56 errors.push( "Template" );
57 }
58 break;
59
60 case 'list':
61 if ( !pod_select || !pod_select.length ) {
62 errors.push( "Pod" );
63 }
64 if ( ( !template || !template.length ) && ( !template_custom || !template_custom.length) ) {
65 errors.push( "Template" );
66 }
67 break;
68
69 case 'field':
70 if ( !pod_select || !pod_select.length ) {
71 errors.push( "Pod" );
72 }
73 if ( !slug || !slug.length ) {
74 errors.push( "ID or Slug" );
75 }
76 if ( !field || !field.length ) {
77 errors.push( "Field" );
78 }
79 break;
80
81 case 'field-current':
82 if ( !field || !field.length ) {
83 errors.push( "Field" );
84 }
85 break;
86
87 case 'form':
88 if ( !pod_select || !pod_select.length ) {
89 errors.push( "Pod" );
90 }
91 break;
92
93 case 'view':
94 if ( !view || !view.length ) {
95 errors.push( "File to include" );
96 }
97 break;
98
99 case 'page':
100 if ( !pods_page || !pods_page.length ) {
101 errors.push( "Pod Page" );
102 }
103 break;
104 }
105
106 if ( errors.length ) {
107 alert( "The following fields are required:\n" + errors.join( "\n" ) );
108
109 e.preventDefault();
110
111 return false;
112 }
113
114 var shortcode = '[pods';
115
116 if ( 'single' == use_case ) {
117 if ( pod_select.length ) {
118 shortcode += ' name="' + pod_select + '"';
119 }
120
121 if ( slug.length ) {
122 shortcode += ' slug="' + slug + '"';
123 }
124
125 if ( template.length ) {
126 shortcode += ' template="' + template + '"';
127 }
128 }
129 else {
130 if ( 'list' == use_case ) {
131 if ( pod_select.length ) {
132 shortcode += ' name="' + pod_select + '"';
133 }
134
135 if ( orderby.length ) {
136 shortcode += ' orderby="' + orderby + '"';
137 }
138
139 if ( limit.length ) {
140 shortcode += ' limit="' + limit + '"';
141 }
142
143 if ( where.length ) {
144 shortcode += ' where="' + where + '"';
145 }
146
147 if ( template.length ) {
148 shortcode += ' template="' + template + '"';
149 }
150
151 }
152 else {
153 if ( 'field' == use_case ) {
154 if ( pod_select.length ) {
155 shortcode += ' name="' + pod_select + '"';
156 }
157
158 if ( slug.length ) {
159 shortcode += ' slug="' + slug + '"';
160 }
161
162 if ( field.length ) {
163 shortcode += ' field="' + field + '"';
164 }
165
166 }
167 else {
168 if ( 'field-current' == use_case ) {
169 if ( field.length ) {
170 shortcode += ' field="' + field + '"';
171 }
172
173 }
174 else {
175 if ( 'form' == use_case ) {
176 // Make shortcode into [pods-form]
177 shortcode += '-form';
178
179 if ( pod_select.length ) {
180 shortcode += ' name="' + pod_select + '"';
181 }
182
183 if ( slug.length ) {
184 shortcode += ' slug="' + slug + '"';
185 }
186
187 if ( fields.length ) {
188 shortcode += ' fields="' + fields + '"';
189 }
190
191 if ( label.length ) {
192 shortcode += ' label="' + label + '"';
193 }
194
195 if ( thank_you.length ) {
196 shortcode += ' thank_you="' + thank_you + '"';
197 }
198
199 }
200 else {
201 if ( 'view' == use_case ) {
202 if ( view.length ) {
203 shortcode += ' view="' + view + '"';
204 }
205
206 if ( cache_mode.length && 'none' != cache_mode ) {
207 shortcode += ' cache_mode="' + cache_mode + '"';
208
209 if ( expires.length ) {
210 shortcode += ' expires="' + expires + '"';
211 }
212 }
213 }
214 else {
215 if ( 'page' == use_case ) {
216 if ( pods_page.length ) {
217 shortcode += ' pods_page="' + pods_page + '"';
218 }
219 }
220 }
221 }
222 }
223 }
224 }
225 }
226
227 shortcode += ']';
228
229 if ( ( 'single' == use_case || 'list' == use_case ) && template_custom && template_custom.length ) {
230 shortcode += '<br />' + template_custom.replace( /\n/g, '<br />' ) + '<br />[/pods]';
231 }
232
233 window.send_to_editor( shortcode );
234
235 e.preventDefault();
236 } );
237
238 $( '#pod_cache_mode' ).on( 'change', function () {
239 var $this = $( this );
240
241 if ( 'none' === $this.val() ) {
242 $( this ).closest( '.pods-section' ).addClass( 'hide' );
243 }
244 else {
245 $( this ).closest( '.pods-section' ).removeClass( 'hide' );
246 }
247 } );
248
249 var $useCaseSelector = $( '#pods_use_case_selector' );
250
251 $useCaseSelector.on( 'change', function () {
252 var val = $( this ).val();
253
254 $( '.pods-section' ).addClass( 'hide' );
255
256 switch ( val ) {
257 case 'single':
258 $( '#pod_select, #pod_slug, #pod_template, #pod_template_custom, #pods_insert_shortcode' ).each( function () {
259 $( this ).closest( '.pods-section' ).removeClass( 'hide' );
260 } );
261 break;
262
263 case 'list':
264 $( '#pod_select, #pod_limit, #pod_orderby, #pod_where, #pod_template, #pod_template_custom, #pod_cache_mode, #pod_expires, #pods_insert_shortcode' ).each( function () {
265 $( this ).closest( '.pods-section' ).removeClass( 'hide' );
266 } );
267 break;
268
269 case 'field':
270 $( '#pod_select, #pod_slug, #pod_field, #pods_insert_shortcode' ).each( function () {
271 $( this ).closest( '.pods-section' ).removeClass( 'hide' );
272 } );
273 break;
274
275 case 'field-current':
276 $( '#pod_field, #pods_insert_shortcode' ).each( function () {
277 $( this ).closest( '.pods-section' ).removeClass( 'hide' );
278 } );
279 break;
280
281 case 'form':
282 $( '#pod_select, #pod_slug, #pod_fields, #pod_label, #pod_thank_you, #pods_insert_shortcode' ).each( function () {
283 $( this ).closest( '.pods-section' ).removeClass( 'hide' );
284 } );
285 break;
286
287 case 'view':
288 $( '#pod_view, #pod_cache_mode, #pod_expires, #pods_insert_shortcode' ).each( function () {
289 $( this ).closest( '.pods-section' ).removeClass( 'hide' );
290 } );
291 break;
292
293 <?php if ( class_exists( 'Pods_Pages' ) ) { ?>
294 case 'page':
295 $( '#pods_page, #pods_insert_shortcode' ).each( function () {
296 $( this ).closest( '.pods-section' ).removeClass( 'hide' );
297 } );
298 break;
299 <?php } ?>
300 }
301
302 // Fix for TB ajaxContent not picking up the height on the first open
303 if ( pods_shortcode_first ) {
304 $( '#TB_ajaxContent' ).css( {width : 'auto', height : '91%'} );
305
306 pods_shortcode_first = false;
307 }
308 } );
309 } );
310 </script>
311
312 <style type="text/css">
313 .pods-shortcode h3.popup-header {
314 font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", sans-serif;
315 font-weight: normal;
316 color: #5a5a5a;
317 font-size: 1.8em;
318 background: url(<?php echo esc_url( PODS_URL ); ?>ui/images/icon32.png) top left no-repeat;
319 padding: 8px 0 5px 36px;
320 margin-top: 0;
321 }
322
323 .pods-shortcode div.pods-section, div.pods-select, div.pods-header {
324 padding: 15px 15px 0 15px;
325 }
326
327 .pods-shortcode div.pods-section.hide {
328 display: none;
329 }
330
331 .pods-shortcode .pods-section label {
332 display: inline-block;
333 width: 120px;
334 font-weight: bold;
335 }
336
337 a#pods_insert_shortcode {
338 color: white !important;
339 }
340
341 .pods-shortcode strong.red {
342 color: red;
343 }
344 </style>
345
346 <div id="pods_shortcode_form" style="display: none;">
347 <div class="wrap pods-shortcode">
348 <div>
349 <div class="pods-header">
350 <h3 class="popup-header"><?php esc_html_e( 'Pods Embed', 'pods' ); ?></h3>
351 </div>
352
353 <form id="pods_shortcode_form_element">
354 <div class="pods-select">
355 <label for="pods_use_case_selector"><?php esc_html_e( 'What would you like to do?', 'pods' ); ?></label>
356
357 <select id="pods_use_case_selector">
358 <option value="single"><?php esc_html_e( 'Display a single Pod item', 'pods' ); ?></option>
359 <option value="list"><?php esc_html_e( 'List multiple Pod items', 'pods' ); ?></option>
360 <option value="field"><?php esc_html_e( 'Display a field from a single Pod item', 'pods' ); ?></option>
361 <option value="field-current" SELECTED><?php esc_html_e( 'Display a field from this item', 'pods' ); ?></option>
362 <option value="form"><?php esc_html_e( 'Display a form for creating and editing Pod items', 'pods' ); ?></option>
363 <option value="view"><?php esc_html_e( 'Include a file from a theme, with caching options', 'pods' ); ?></option>
364 <?php if ( class_exists( 'Pods_Pages' ) ) { ?>
365 <option value="page"><?php esc_html_e( 'Embed content from a Pods Page', 'pods' ); ?></option>
366 <?php } ?>
367 </select>
368 </div>
369
370 <div class="pods-section hide">
371 <?php
372 $api = pods_api();
373 $all_pods = $api->load_pods( array( 'names' => true ) );
374 $pod_count = count( $all_pods );
375 ?>
376 <label for="pod_select"><?php esc_html_e( 'Choose a Pod', 'pods' ); ?></label>
377
378 <?php
379 if ( $pod_count > 0 ) {
380 ?>
381 <select id="pod_select" name="pod_select">
382 <?php foreach ( $all_pods as $pod_name => $pod_label ) { ?>
383 <option value="<?php echo esc_attr( $pod_name ); ?>">
384 <?php echo esc_html( $pod_label . ' (' . $pod_name . ')' ); ?>
385 </option>
386 <?php } ?>
387 </select>
388 <?php
389 } else {
390 ?>
391 <strong class="red" id="pod_select"><?php esc_html_e( 'None Found', 'pods' ); ?></strong> <?php } ?>
392 </div>
393
394 <?php if ( class_exists( 'Pods_Templates' ) ) { ?>
395 <div class="pods-section hide">
396 <?php
397 $templates = $api->load_templates();
398 $template_count = count( $templates );
399 ?>
400 <label for="pod_template"><?php esc_html_e( 'Template', 'pods' ); ?></label>
401
402 <select id="pod_template" name="pod_template">
403 <option value="" SELECTED>- <?php esc_html_e( 'Custom Template', 'pods' ); ?> -</option>
404
405 <?php foreach ( $templates as $tmpl ) { ?>
406 <option value="<?php echo esc_attr( $tmpl['name'] ); ?>">
407 <?php echo esc_html( $tmpl['name'] ); ?>
408 </option>
409 <?php } ?>
410 </select>
411 </div>
412 <?php
413 } else {
414 ?>
415 <div class="pods-section hide">
416 <label for="pod_template"><?php esc_html_e( 'Template', 'pods' ); ?></label>
417
418 <input type="text" id="pod_template" name="pod_template" />
419 </div>
420 <?php
421 }//end if
422 ?>
423
424 <div class="pods-section hide">
425 <label for="pod_template_custom"><?php esc_html_e( 'Custom Template', 'pods' ); ?></label>
426
427 <textarea name="pod_template_custom" id="pod_template_custom" cols="10" rows="10" class="widefat"></textarea>
428 </div>
429
430 <?php if ( class_exists( 'Pods_Pages' ) ) { ?>
431 <div class="pods-section hide">
432 <?php
433 $pages = $api->load_pages();
434 $page_count = count( $pages );
435 ?>
436 <label for="pods_page"><?php esc_html_e( 'Pods Page', 'pods' ); ?></label>
437
438 <select id="pods_page" name="pods_page">
439 <?php foreach ( $pages as $page ) { ?>
440 <option value="<?php echo esc_attr( $page['name'] ); ?>">
441 <?php echo esc_html( $page['name'] ); ?>
442 </option>
443 <?php } ?>
444 </select>
445 </div>
446 <?php } ?>
447
448 <div class="pods-section hide">
449 <label for="pod_slug"><?php esc_html_e( 'ID or Slug', 'pods' ); ?></label>
450
451 <input type="text" id="pod_slug" name="pod_slug" />
452 </div>
453
454 <div class="pods-section hide">
455 <label for="pod_limit"><?php esc_html_e( 'Limit', 'pods' ); ?></label>
456
457 <input type="text" id="pod_limit" name="pod_limit" />
458 </div>
459
460 <div class="pods-section hide">
461 <label for="pod_orderby"><?php esc_html_e( 'Order By', 'pods' ); ?></label>
462
463 <input type="text" id="pod_orderby" name="pod_orderby" />
464 </div>
465
466 <div class="pods-section hide">
467 <label for="pod_where"><?php esc_html_e( 'Where', 'pods' ); ?></label>
468
469 <input type="text" name="pod_where" id="pod_where" />
470 </div>
471
472 <div class="pods-section">
473 <label for="pod_field"><?php esc_html_e( 'Field', 'pods' ); ?></label>
474
475 <input type="text" name="pod_field" id="pod_field" />
476 </div>
477
478 <div class="pods-section hide">
479 <label for="pod_fields"><?php esc_html_e( 'Fields (comma-separated)', 'pods' ); ?></label>
480
481 <input type="text" id="pod_fields" name="pod_fields" />
482 </div>
483
484 <div class="pods-section hide">
485 <label for="pod_label"><?php esc_html_e( 'Submit Label', 'pods' ); ?></label>
486
487 <input type="text" id="pod_label" name="pod_label" />
488 </div>
489
490 <div class="pods-section hide">
491 <label for="pod_thank_you"><?php esc_html_e( 'Thank You URL upon submission', 'pods' ); ?></label>
492
493 <input type="text" id="pod_thank_you" name="pod_thank_you" />
494 </div>
495
496 <div class="pods-section hide">
497 <label for="pod_view"><?php esc_html_e( 'File to include', 'pods' ); ?></label>
498
499 <input type="text" name="pod_view" id="pod_view" />
500 </div>
501
502 <div class="pods-section hide">
503 <label for="pod_cache_mode"><?php esc_html_e( 'Cache Type', 'pods' ); ?></label>
504
505 <?php
506 $cache_modes = array(
507 'none' => __( 'Disable Caching', 'pods' ),
508 'cache' => __( 'Object Cache', 'pods' ),
509 'transient' => __( 'Transient', 'pods' ),
510 'site-transient' => __( 'Site Transient', 'pods' ),
511 );
512
513 $default_cache_mode = apply_filters( 'pods_shortcode_default_cache_mode', 'none' );
514 ?>
515 <select id="pod_cache_mode" name="pod_cache_mode">
516 <?php foreach ( $cache_modes as $cache_mode_option => $cache_mode_label ) : ?>
517 <option value="<?php echo esc_attr( $cache_mode_option ); ?>"<?php selected( $default_cache_mode, $cache_mode_option ); ?>>
518 <?php echo esc_html( $cache_mode_label ); ?>
519 </option>
520 <?php endforeach; ?>
521 </select>
522 </div>
523
524 <div class="pods-section hide">
525 <label for="pod_expires"><?php esc_html_e( 'Cache Expiration (in seconds)', 'pods' ); ?></label>
526
527 <input type="text" name="pod_expires" id="pod_expires" value="<?php echo( 60 * 5 ); ?>" />
528 </div>
529
530 <div class="pods-section" style="text-align: right;">
531 <a class="button-primary" id="pods_insert_shortcode" href="#insert-shortcode"><?php esc_html_e( 'Insert', 'pods' ); ?></a>
532 </div>
533 </form>
534 </div>
535 </div>
536 </div>
537