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